Title: | Interpreting CoDa Regression Models |
---|---|
Description: | Provides methods for interpreting CoDa (Compositional Data) regression models along the lines of "Pairwise share ratio interpretations of compositional regression models" (Dargel and Thomas-Agnan 2024) <doi:10.1016/j.csda.2024.107945>. The new methods include variation scenarios, elasticities, elasticity differences and share ratio elasticities. These tools are independent of log-ratio transformations and allow an interpretation in the original space of shares. 'CoDaImpact' is designed to be used with the 'compositions' package and its ecosystem. |
Authors: | Lukas Dargel [aut, cre] |
Maintainer: | Lukas Dargel <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.0 |
Built: | 2025-02-28 05:17:34 UTC |
Source: | https://github.com/lukece/codaimpact |
This data set shows monthly data of the French car market between 2003 and 2015. The market is divided into 5 main segments (A to E), according to the size of the vehicle chassis. Morais et. al (2018) first used this data to compare compositional and Dirichlet models for market shares.
car_market
car_market
An object of class data.frame
with 152 rows and 10 columns.
SEG_
: Corresponds to the shares of sales in each of the five market
segments A,B,C,D and E. Where A are the smallest cars and E the largest.
The segmentation is explained in Wikipedia.
GDP
: GDP figures in millions at current prices
HOUSEHOLD_EXPENDITURE
: total household expenditure in millions at previous years prices
GAS_PRICE
: Corresponds to the gas price including VAT.
SCRAPPING_SUBSIDY
: A dummy indicating periods where the French government provided subsidies for scrapping a car.
Lukas Dargel, Christine Thomas-Agnan
The figures for GDP and household expenditure are originally provided by the The National Institute of Statistics and Economic Studies (INSEE).
The gas prices are from the OECD.
The market share of each segment of come from a simulation by Renault.
Joanna Morais, Christine Thomas-Agnan & Michel Simioni (2018) Using compositional and Dirichlet models for market share regression, Journal of Applied Statistics, 45:9, 1670-1689, DOI: 10.1080/02664763.2017.1389864
Create a linear path in the simplex by defining a direction and a step size
CoDa_path( comp_direc, comp_from, step_size = 0.01, n_steps = 100, add_opposite = FALSE, dir_from_start = FALSE )
CoDa_path( comp_direc, comp_from, step_size = 0.01, n_steps = 100, add_opposite = FALSE, dir_from_start = FALSE )
comp_direc |
A numeric vector, defining a direction in the simplex |
comp_from |
A numeric vector, an initial point in the simplex - defaults to a balanced composition, which represents the origin in the simplex |
step_size |
A numeric, indicting the step size |
n_steps |
A numeric, indicating the number of steps to be taking from |
add_opposite |
A logical, if |
dir_from_start |
A logical, if |
The function is very similar to CoDa_seq()
.
However, of drawing a line between a starting and end point it uses only a starting point and a direction.
A data.frame frame where each row corresponds to one compositional vector
Lukas Dargel
CoDa_seq
# three steps that go from the origin towards the defined direction comp_direc <- c(A =.4,B = .35, C= .25) CoDa_path(comp_direc, n_steps = 3) # we can draw the path that is defined by this direction comp_direc <- c(A =.4,B = .35, C= .25) compositions::plot.acomp(CoDa_path(comp_direc,n_steps = 10)) compositions::plot.acomp(CoDa_path(comp_direc,n_steps = 100)) compositions::plot.acomp(CoDa_path(comp_direc,add_opposite = TRUE)) # using the same direction we can draw a new path that does not go through the origin comp_direc <- c(A =.4,B = .35, C= .25) comp_from <- c(.7,.2,.1) compositions::plot.acomp(CoDa_path(comp_direc, comp_from,n_steps = 10)) compositions::plot.acomp(CoDa_path(comp_direc, comp_from,n_steps = 100)) compositions::plot.acomp(CoDa_path(comp_direc, comp_from,add_opposite = TRUE)) # the balanced composition does not define a direction by itself comp_origin <- c(A = 1/3, B = 1/3, C= 1/3) # corresponds to a zero vector in real space try(CoDa_path(comp_origin, comp_from,add_opposite = TRUE)) # with the dir_from_start option the direction is derived # from the simplex line connecting two compositions path_origin <- CoDa_path( comp_direc = comp_origin, comp_from = comp_from, add_opposite = TRUE, dir_from_start = TRUE, step_size = .1) compositions::plot.acomp(path_origin) compositions::plot.acomp(comp_origin, add = TRUE, col = "blue", pch = 19) compositions::plot.acomp(comp_from, add = TRUE, col = "red", pch = 19)
# three steps that go from the origin towards the defined direction comp_direc <- c(A =.4,B = .35, C= .25) CoDa_path(comp_direc, n_steps = 3) # we can draw the path that is defined by this direction comp_direc <- c(A =.4,B = .35, C= .25) compositions::plot.acomp(CoDa_path(comp_direc,n_steps = 10)) compositions::plot.acomp(CoDa_path(comp_direc,n_steps = 100)) compositions::plot.acomp(CoDa_path(comp_direc,add_opposite = TRUE)) # using the same direction we can draw a new path that does not go through the origin comp_direc <- c(A =.4,B = .35, C= .25) comp_from <- c(.7,.2,.1) compositions::plot.acomp(CoDa_path(comp_direc, comp_from,n_steps = 10)) compositions::plot.acomp(CoDa_path(comp_direc, comp_from,n_steps = 100)) compositions::plot.acomp(CoDa_path(comp_direc, comp_from,add_opposite = TRUE)) # the balanced composition does not define a direction by itself comp_origin <- c(A = 1/3, B = 1/3, C= 1/3) # corresponds to a zero vector in real space try(CoDa_path(comp_origin, comp_from,add_opposite = TRUE)) # with the dir_from_start option the direction is derived # from the simplex line connecting two compositions path_origin <- CoDa_path( comp_direc = comp_origin, comp_from = comp_from, add_opposite = TRUE, dir_from_start = TRUE, step_size = .1) compositions::plot.acomp(path_origin) compositions::plot.acomp(comp_origin, add = TRUE, col = "blue", pch = 19) compositions::plot.acomp(comp_from, add = TRUE, col = "red", pch = 19)
A sequence connecting two points in a simplex
CoDa_seq(comp_from, comp_to, n_steps = 100, add_opposite = FALSE)
CoDa_seq(comp_from, comp_to, n_steps = 100, add_opposite = FALSE)
comp_from |
A numeric vector, representing the initial compositions |
comp_to |
A numeric vector, representing the final compositions. |
n_steps |
An integer, indicating the number of steps used to go from comp_from to comp_to |
add_opposite |
A logical, if |
The sequence is evenly spaced and corresponds to a straight line in the simplex geometry. If no end point is provided the line will connect the initial point with the first summit of the simplex. Since exact zeros are not handled by the ilr they are replaced by a small constant.
A data.frame frame where each row corresponds to one compositional vector
Lukas Dargel
simplex_increment
# path to the first summit of the simplex start_comp <- c(A =.4,B = .35, C= .25) compositions::plot.acomp(CoDa_seq(start_comp)) compositions::plot.acomp(CoDa_seq(start_comp, add_opposite = TRUE)) # path to an edge of the simplex end_comp <- c(0,.8,.2) compositions::plot.acomp(CoDa_seq(start_comp, end_comp)) compositions::plot.acomp(CoDa_seq(start_comp, end_comp,add_opposite = TRUE))
# path to the first summit of the simplex start_comp <- c(A =.4,B = .35, C= .25) compositions::plot.acomp(CoDa_seq(start_comp)) compositions::plot.acomp(CoDa_seq(start_comp, add_opposite = TRUE)) # path to an edge of the simplex end_comp <- c(0,.8,.2) compositions::plot.acomp(CoDa_seq(start_comp, end_comp)) compositions::plot.acomp(CoDa_seq(start_comp, end_comp,add_opposite = TRUE))
These functions work as in the usual lm object.
They additionally offer the possibility use the space
argument
which transforms them into directly into clr space or in the simplex.
## S3 method for class 'lmCoDa' coef(object, space = NULL, split = FALSE, ...)
## S3 method for class 'lmCoDa' coef(object, space = NULL, split = FALSE, ...)
object |
class "lmCoDa" |
space |
a character indicating in which space the prediction should
be returned. Supported are the options |
split |
logical, if |
... |
not used |
a matrix
Lukas Dargel
Dargel and Thomas-Agnan (2024) show to compute variances and confidence intervals for parameters of CoDa models in log-ratio spaces.
Of particular interest are the clr parameters since they can be directly interpreted as differences from an average elasticity.
Another option is interpret the difference in clr parameters as these coincide with the difference in elasticities.
## S3 method for class 'lmCoDa' confint(object, parm, level = 0.95, y_ref = NULL, obs = NULL, ...)
## S3 method for class 'lmCoDa' confint(object, parm, level = 0.95, y_ref = NULL, obs = NULL, ...)
object |
class "lmCoDa" |
parm |
a character, indicating the name of one explanatory variable |
level |
a numeric, indicating the confidence level required |
y_ref |
an optional argument that indicates the reference component of
the response variable using its name or its position. |
obs |
an optional integer that indicates one observation when this argument is supplied the function return the observation dependent elasticity |
... |
passed on to confit() |
Since CoDa models are often multivariate this function only allows to
specify one explanatory variable at a time.
The output is also more complex than the usual one for "lm" classes, because
we have to indicate the component of Y and X.
With confint.lm()
it is still possible to compute the usual the confidence
intervals.
data.frame
Lukas Dargel
Dargel, Lukas and Christine Thomas-Agnan, “Pairwise share ratio interpretations of compositional regression models”, Computational Statistics & Data Analysis 195 (2024), p. 107945
## ==== Y-compositional model ==== res <- lmCoDa( ilr(cbind(left, right, extreme_right)) ~ ilr(cbind(Age_1839, Age_4064)) + ilr(cbind(Educ_BeforeHighschool, Educ_Highschool, Educ_Higher)) + unemp_rate, data = head(election, 20)) ## ---- CI for scalar X # CI for clr parameters confint(res, "unemp_rate") # CI for difference in clr parameters (coincides with difference in the semi elasticity) confint(res, "unemp_rate", y_ref = 1) ## ---- CI for compositional X # CI for clr parameters confint(res, "cbind(Age_1839, Age_4064)") # CI for difference in clr parameters (coincides with difference in the elasticity) confint(res, "cbind(Age_1839, Age_4064)", y_ref = 1)
## ==== Y-compositional model ==== res <- lmCoDa( ilr(cbind(left, right, extreme_right)) ~ ilr(cbind(Age_1839, Age_4064)) + ilr(cbind(Educ_BeforeHighschool, Educ_Highschool, Educ_Higher)) + unemp_rate, data = head(election, 20)) ## ---- CI for scalar X # CI for clr parameters confint(res, "unemp_rate") # CI for difference in clr parameters (coincides with difference in the semi elasticity) confint(res, "unemp_rate", y_ref = 1) ## ---- CI for compositional X # CI for clr parameters confint(res, "cbind(Age_1839, Age_4064)") # CI for difference in clr parameters (coincides with difference in the elasticity) confint(res, "cbind(Age_1839, Age_4064)", y_ref = 1)
The data is used by Nguyen et. al (2020) and originally disseminated by the French ministry (Ministère de l'Intérieur et des Outre-Mer). Information about the population characteristics comes from the french national statistics institute (INSEE).
election
election
An object of class data.frame
with 95 rows and 13 columns.
left
, right
, extreme_right
: Vote shares during the election grouped into three blocks
Age_1839
, Age_4064
, Age_65plus
: Share of the population falling into one of three age categories
Educ_BeforeHighschool
, Educ_Highschool
, Educ_Higher
: Share of the population having completed a certain level of education.
asset_owner_rate
: The proportion of people who own assets
income_taxpayer_rate
: The proportion of people who pay income tax
forgeigner_rate
: The proportion of foreigners
Lukas Dargel, Christine Thomas-Agnan
https://www.data.gouv.fr/fr/datasets/elections-departementales-2015-resultats-par-bureaux-de-vote
https://www.insee.fr/fr/accueil
Nguyen THA, Laurent T, Thomas-Agnan C, Ruiz-Gazen A. Analyzing the impacts of socio-economic factors on French departmental elections with CoDa methods. J Appl Stat. 2020 Dec 9;49(5):1235-1251. doi: 10.1080/02664763.2020.1858274. PMID: 35707505; PMCID: PMC9041641.
These functions work as in the usual lm object.
They additionally offer the possibility use the space
argument
which transforms them into directly into clr space or in the simplex.
## S3 method for class 'lmCoDa' fitted(object, space = NULL, ...)
## S3 method for class 'lmCoDa' fitted(object, space = NULL, ...)
object |
class "lmCoDa" |
space |
a character indicating in which space the prediction should
be returned. Supported are the options |
... |
passed on to |
matrix or vector
Lukas Dargel
This function computes elasticities and semi-elasticities for CoDa regression model. where we have to distinguish four cases:
Y and X are both compositional: this leads to an elasticity
Y is compositional and X is scalar: this leads to a semi-elasticity
Y is scalar and X is compositional: this leads to a semi-elasticity
Y and X are both scalar: this case is not implemented as it leads to constant marginal effects
Impacts(object, Xvar = NULL, obs = 1)
Impacts(object, Xvar = NULL, obs = 1)
object |
an object of class "lmCoDa" |
Xvar |
a character indicating the name of one explanatory variable |
obs |
a numeric that refers to the indicator of one observation |
The mathematical foundation for elasticity computations in CoDa model come from Morais and Thomas-Agnan (2021). Dargel and Thomas-Agnan (2024) present further results and illustrations.
a matrix
Lukas Dargel
Rodrigue Nasr
Dargel, Lukas and Christine Thomas-Agnan, “Pairwise share ratio interpretations of compositional regression models”, Computational Statistics & Data Analysis 195 (2024), p. 107945
Morais, Joanna and Christine Thomas-Agnan. "Impact of covariates in compositional models and simplicial derivatives." Austrian Journal of Statistics 50.2 (2021): 1-15.
res <- lmCoDa(YIELD ~ PRECIPITATION + ilr(TEMPERATURES), data = head(rice_yields,20)) Impacts(res, Xvar = "TEMPERATURES")
res <- lmCoDa(YIELD ~ PRECIPITATION + ilr(TEMPERATURES), data = head(rice_yields,20)) Impacts(res, Xvar = "TEMPERATURES")
This is a thin wrapper around lm()
followed by ToSimplex()
, which
allows to create a lmCoDa object in one step.
lmCoDa(formula, data, ...)
lmCoDa(formula, data, ...)
formula |
as in |
data |
as in |
... |
arguments passed on to |
an object of class "lm" and "lmCoDa" if the formula include at least one log-transformation
Lukas Dargel
lm()
, ToSimplex()
, compositions::ilr()
, compositions::alr()
# XY-compositional model res <- lmCoDa( ilr(cbind(left, right, extreme_right)) ~ ilr(cbind(Educ_BeforeHighschool, Educ_Highschool, Educ_Higher)), data = head(election, 20)) # X-compositional model res <- lmCoDa(YIELD ~ PRECIPITATION + ilr(TEMPERATURES), data = head(rice_yields, 20))
# XY-compositional model res <- lmCoDa( ilr(cbind(left, right, extreme_right)) ~ ilr(cbind(Educ_BeforeHighschool, Educ_Highschool, Educ_Higher)), data = head(election, 20)) # X-compositional model res <- lmCoDa(YIELD ~ PRECIPITATION + ilr(TEMPERATURES), data = head(rice_yields, 20))
These functions work as in the usual lm object.
They additionally offer the possibility use the space
argument
which transforms them into directly into clr space or in the simplex.
## S3 method for class 'lmCoDa' predict(object, space = NULL, ...)
## S3 method for class 'lmCoDa' predict(object, space = NULL, ...)
object |
class "lmCoDa" |
space |
a character indicating in which space the prediction should
be returned. Supported are the options |
... |
passed on to |
matrix or vector
Lukas Dargel
These functions work as in the usual lm object.
They additionally offer the possibility use the space
argument
which transforms them into directly into clr space or in the simplex.
## S3 method for class 'lmCoDa' residuals(object, space = NULL, ...)
## S3 method for class 'lmCoDa' residuals(object, space = NULL, ...)
object |
class "lmCoDa" |
space |
a character indicating in which space the prediction should
be returned. Supported are the options |
... |
passed on to |
matrix or vector
Lukas Dargel
The data is presented in Trinh et al. (2023) for studying the impact
of climate change on rice production in Vietnam.
It contains the following information:
PROVINCE
: a factor for the 63 provinces of Vietnam
REGION
: a factor with the 6 main regions
YEAR
: a numeric corresponding to the year
YIELD
: a numeric for the rice production in tons per hectare
PRECIPITATION
: a numeric for the annual precipitation in liters
TEMPERATURES
: a compositional variable represented as a matrix
whose columns correspond to the proportion of days in a year where the maximal
temperature (in Celsius degrees) falls into one of the three categories:
"LOW" (from -6, to 25.1), "MEDIUM" (from 25.1 to 35.4) and "HIGH" (from 35.4 to 45).
rice_yields
rice_yields
An object of class data.frame
with 1890 rows and 6 columns.
Lukas Dargel, Christine Thomas-Agnan
Thi-Huong Trinh, Michel Simioni, and Christine Thomas-Agnan, “Discrete and Smooth Scalar-on-Density Compositional Regression for Assessing the Impact of Climate Change on Rice Yield in Vietnam”, TSE Working Paper, n. 23-1410, February 2023.
The function converts the output of a "lm" to the "lmCoDa" class, which
offers additional tools for the interpretation of a CoDa regression models.
Most of the work is done by the transformationSummary()
function, which
has its own documentation page, but should be reserved for internal use.
ToSimplex(object)
ToSimplex(object)
object |
an object of class "lmCoDa" |
an object of class "lm" and "lmCoDa" if the formula include at least one log-transformation
Lukas Dargel
Rodrigue Nasr
# XY-compositional model res <- lm( ilr(cbind(left, right, extreme_right)) ~ ilr(cbind(Educ_BeforeHighschool, Educ_Highschool, Educ_Higher)), data = head(election, 20)) res <- ToSimplex(res) # X-compositional model res <- lm(YIELD ~ PRECIPITATION + ilr(TEMPERATURES), data = head(rice_yields, 20)) res <- ToSimplex(res)
# XY-compositional model res <- lm( ilr(cbind(left, right, extreme_right)) ~ ilr(cbind(Educ_BeforeHighschool, Educ_Highschool, Educ_Higher)), data = head(election, 20)) res <- ToSimplex(res) # X-compositional model res <- lm(YIELD ~ PRECIPITATION + ilr(TEMPERATURES), data = head(rice_yields, 20)) res <- ToSimplex(res)
This data set provides an example for the use of CoDa models in geomarketing applications. The data is simulated, but realistic in the sense that the parameters used for the simulation were estimated on a real, but confidential data set (Dargel and Thomas-Agnan 2024).
toulouse_retail
toulouse_retail
An object of class sf
(inherits from data.table
, data.frame
) with 428 rows and 6 columns.
ID_IRIS
: Identifies the geographic region.
POP
: Population number within the region
MEDIAN_INCOME
: The median income in the region
dist_km
: Distances from the region to all nine shopping malls.
visits
: The share of visitors that coming from the region and going to each of the malls.
geometry
: The geometry (polygon) of the region
The "mall_locations" and the "simulation_parameters" are given as additional attributes.
Lukas Dargel, Christine Thomas-Agnan
The figures for POP
and MEDIAN_INCOME
come from the French census data prided by INSEE.
The polygon geometry
is provided by the IGN.
The locations of the nine shopping malls around the city center are derived from online mapping services (Google Maps and OpenStreetMap).
The distances (dist_km
) are derived from location information.
The number of shopping trips (visits
) are simulated by the authors.
Lukas Dargel & Christine Thomas-Agnan (2024) “The link between multiplicative competitive interaction models and compositional data regression with a total”, Journal of Applied Statistics, DOI: 10.1080/02664763.2024.2329923
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.
VariationScenario( object, Xvar, Xdir, obs = 1, inc_size = 0.1, n_steps = 100, add_opposite = TRUE, normalize_Xdir = TRUE )
VariationScenario( object, Xvar, Xdir, obs = 1, inc_size = 0.1, n_steps = 100, add_opposite = TRUE, normalize_Xdir = TRUE )
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
|
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 |
normalize_Xdir |
a logical, if |
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.
a data.frame containing the scenario of X and the corresponding predicted values of Y
Lukas Dargel
Dargel, Lukas and Christine Thomas-Agnan, “Pairwise share ratio interpretations of compositional regression models”, Computational Statistics & Data Analysis 195 (2024), p. 107945
# ---- model with scalar response ---- res <- lmCoDa(YIELD ~ PRECIPITATION + ilr(TEMPERATURES), data = head(rice_yields,20)) VariationScenario(res, Xvar = "TEMPERATURES", Xdir = "MEDIUM", n_steps = 5) VariationScenario(res, Xvar = "PRECIPITATION", n_steps = 5) # ---- 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) VariationScenario(res, "log(unemp_rate)", n_steps = 5)
# ---- model with scalar response ---- res <- lmCoDa(YIELD ~ PRECIPITATION + ilr(TEMPERATURES), data = head(rice_yields,20)) VariationScenario(res, Xvar = "TEMPERATURES", Xdir = "MEDIUM", n_steps = 5) VariationScenario(res, Xvar = "PRECIPITATION", n_steps = 5) # ---- 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) VariationScenario(res, "log(unemp_rate)", n_steps = 5)
This function allows to evaluate how a change in an explanatory variables impacts the response variable in a CoDa regression model. The changes are calculated based from the approximate formal presented in Dargel and Thomas-Agnan (2024). Changes in the response variables are provided as data.frame and the underlying changes in the explanatory variable are given as attributes.
VariationTable( object, Xvar, Xdir, obs = 1, inc_size = 0.1, inc_rate = NULL, Ytotal = 1, normalize_Xdir = TRUE )
VariationTable( object, Xvar, Xdir, obs = 1, inc_size = 0.1, inc_rate = NULL, Ytotal = 1, normalize_Xdir = TRUE )
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
|
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 |
inc_rate |
a numeric that can be used as a parameterization of the step size |
Ytotal |
a numeric indicating the total of Y |
normalize_Xdir |
a logical, if |
data.frame
Lukas Dargel
Rodrigue Nasr
Dargel, Lukas and Christine Thomas-Agnan, “Pairwise share ratio interpretations of compositional regression models”, Computational Statistics & Data Analysis 195 (2024), p. 107945
# XY-compositional model res <- lmCoDa( ilr(cbind(left, right, extreme_right)) ~ ilr(cbind(Educ_BeforeHighschool, Educ_Highschool, Educ_Higher)), data = head(election, 20)) # Focus on changes in the education composition educ_comp <- "cbind(Educ_BeforeHighschool, Educ_Highschool, Educ_Higher)" # ... changes towards a summit towards a summit (higher share of people with lower education) VariationTable(res, educ_comp, Xdir = "Educ_BeforeHighschool") # ... same changes using a compositional vector as direction VariationTable(res, educ_comp, Xdir = c(.5,.25,.25)) # ... changes in a more general direction and for a different observation VariationTable(res, educ_comp, Xdir = c(.35,.45,.10), obs = 2)
# XY-compositional model res <- lmCoDa( ilr(cbind(left, right, extreme_right)) ~ ilr(cbind(Educ_BeforeHighschool, Educ_Highschool, Educ_Higher)), data = head(election, 20)) # Focus on changes in the education composition educ_comp <- "cbind(Educ_BeforeHighschool, Educ_Highschool, Educ_Higher)" # ... changes towards a summit towards a summit (higher share of people with lower education) VariationTable(res, educ_comp, Xdir = "Educ_BeforeHighschool") # ... same changes using a compositional vector as direction VariationTable(res, educ_comp, Xdir = c(.5,.25,.25)) # ... changes in a more general direction and for a different observation VariationTable(res, educ_comp, Xdir = c(.35,.45,.10), obs = 2)