Skip to contents

Scenarios of this type are illustrated in Dargel and Thomas-Agnan (2024). They allow to evaluate how the response variable (Y) in a CoDa model would evolve under a hypothetical scenario for linear changes in one explanatory variable (X). When the changing explanatory variable is compositional the term "linear" is understood with respect to the geometry of the simplex.

Usage

VariationScenario(
  object,
  Xvar,
  Xdir,
  obs = 1,
  inc_size = 0.1,
  n_steps = 100,
  add_opposite = TRUE,
  normalize_Xdir = TRUE
)

Arguments

object

an object of class "lmCoDa"

Xvar

a character indicating the name of the explanatory variable that changes

Xdir

either character or numeric, to indicate the direction in which Xvar should change

  • when character this should be one of the components of X, in which case the direction is the corresponding vertex of the simplex

  • when numeric this argument is coerced to a unit vector in the simplex

  • (when Xvar refers to a scalar variable this argument is ignored)

obs

a numeric indicating the observation used for the scenario

inc_size

a numeric indicating the distance between each point in the scenario of X

n_steps

a numeric indicating the number of points in the scenario

add_opposite

a logical, if TRUE the scenario also includes changes in the opposite direction

normalize_Xdir

a logical, if TRUE the direction Xdir scaled to have an Aitchison norm of 1, allowing to interpret inc_size as the Aitchison distance

Value

a data.frame containing the scenario of X and the corresponding predicted values of Y

Details

The linear scenario for X is computed with seq() in the scalar case and with CoDa_seq() in the compositional case. The corresponding changes in Y are computed with the prediction formula, where we exploit the fact that only in one variable is changing.

References

  • Dargel, Lukas and Christine Thomas-Agnan, “Pairwise share ratio interpretations of compositional regression models”, Computational Statistics & Data Analysis 195 (2024), p. 107945

Author

Lukas Dargel

Examples


# ---- model with scalar response ----
res <- lmCoDa(YIELD ~ PRECIPITATION + ilr(TEMPERATURES), data = head(rice_yields,20))
VariationScenario(res, Xvar = "TEMPERATURES", Xdir = "MEDIUM", n_steps = 5)
#>       YIELD        X.LOW     X.MEDIUM       X.HIGH
#> -5 2.781911 5.360699e-07 9.314607e-01 6.853880e-02
#> -4 2.769875 4.780533e-07 9.388784e-01 6.112112e-02
#> -3 2.757840 4.259484e-07 9.455403e-01 5.445930e-02
#> -2 2.745805 3.792293e-07 9.515136e-01 4.848607e-02
#> -1 2.733770 3.374008e-07 9.568616e-01 4.313811e-02
#> 0  2.721734 2.999999e-07 9.616435e-01 3.835625e-02
#> 1  2.709699 2.665971e-07 9.659142e-01 3.408557e-02
#> 2  2.697664 2.367965e-07 9.697243e-01 3.027543e-02
#> 3  2.685629 2.102343e-07 9.731204e-01 2.687934e-02
#> 4  2.673593 1.865784e-07 9.761450e-01 2.385483e-02
#> 5  2.661558 1.655264e-07 9.788366e-01 2.116324e-02
VariationScenario(res, Xvar = "PRECIPITATION", n_steps = 5)
#>       YIELD PRECIPITATION
#> -5 2.930587      0.620756
#> -4 2.888817      0.720756
#> -3 2.847046      0.820756
#> -2 2.805275      0.920756
#> -1 2.763505      1.020756
#> 0  2.721734      1.120756
#> 1  2.679964      1.220756
#> 2  2.638193      1.320756
#> 3  2.596423      1.420756
#> 4  2.554652      1.520756
#> 5  2.512882      1.620756


# ---- model with compositional response ----
res <- lmCoDa(ilr(cbind(left, right, extreme_right)) ~
                ilr(cbind(Age_1839, Age_4064)) +
                ilr(cbind(Educ_BeforeHighschool, Educ_Highschool, Educ_Higher)) +
                log(unemp_rate),
              data = head(election))

VariationScenario(res, Xvar ="cbind(Age_1839,Age_4064)",Xdir = "Age_1839", n_steps = 5)
#>         Y.left     Y.right Y.extreme_right X.Age_1839 X.Age_4064
#> -5 0.003036601 0.802915649     0.194047750  0.2465168  0.7534832
#> -4 0.008122066 0.768193441     0.223684493  0.2737149  0.7262851
#> -3 0.021412833 0.724436090     0.254151077  0.3027083  0.6972917
#> -2 0.054893832 0.664310871     0.280795297  0.3333632  0.6666368
#> -1 0.132743157 0.574621429     0.292635414  0.3654953  0.6345047
#> 0  0.285835440 0.442596135     0.271568425  0.3988714  0.6011286
#> 1  0.509336842 0.282110011     0.208553147  0.4332143  0.5667857
#> 2  0.727490289 0.144132683     0.128377028  0.4682111  0.5317889
#> 3  0.871899806 0.061790786     0.066309409  0.5035235  0.4964765
#> 4  0.945066907 0.023957503     0.030975590  0.5388007  0.4611993
#> 5  0.977332405 0.008862233     0.013805362  0.5736935  0.4263065
VariationScenario(res, "log(unemp_rate)", n_steps = 5)
#>        Y.left    Y.right Y.extreme_right log(unemp_rate)
#> -5 0.59371706 0.29175126      0.11453169       -2.843614
#> -4 0.53091223 0.32820682      0.14088095       -2.743614
#> -3 0.46669548 0.36295279      0.17035173       -2.643614
#> -2 0.40314639 0.39443095      0.20242267       -2.543614
#> -1 0.34228761 0.42129961      0.23641279       -2.443614
#> 0  0.28583544 0.44259613      0.27156843       -2.343614
#> 1  0.23502387 0.45782043      0.30715570       -2.243614
#> 2  0.19053546 0.46692883      0.34253570       -2.143614
#> 3  0.15253460 0.47025661      0.37720879       -2.043614
#> 4  0.12077066 0.46840298      0.41082636       -1.943614
#> 5  0.09471036 0.46211210      0.44317754       -1.843614