###################
### Coordinate representation of a CoDa Cube
if (FALSE) {
### example from Fa\v cevicov\'a (2019)
data(employment2)
CZE <- employment2[which(employment2$Country == 'CZE'), ]
# pivot coordinates
cubeCoord(CZE, "Sex", 'Contract', "Age", 'Value')
# coordinates with given SBP
r <- t(c(1,-1))
c <- t(c(1,-1))
s <- rbind(c(1,-1,-1), c(0,1,-1))
cubeCoord(CZE, "Sex", 'Contract', "Age", 'Value', r,c,s)
}
###################
### Analysis of a sample of CoDa Cubes
if (FALSE) {
### example from Fa\v cevicov\'a (2019)
data(employment2)
### Compositional tables approach,
### analysis of the relative structure.
### An example from Facevi\v cov\'a (2019)
# pivot coordinates
cubeCoordWrapper(employment2, 'Country', 'Sex', 'Contract', 'Age', 'Value',
test=TRUE)
# coordinates with given SBP (defined in the paper)
r <- t(c(1,-1))
c <- t(c(1,-1))
s <- rbind(c(1,-1,-1), c(0,1,-1))
res <- cubeCoordWrapper(employment2, 'Country', 'Sex', 'Contract',
"Age", 'Value', r,c,s, test=TRUE)
### Classical approach,
### generalized linear mixed effect model.
library(lme4)
employment2$y <- round(employment2$Value*1000)
glmer(y~Sex*Age*Contract+(1|Country),data=employment2,family=poisson)
### other relations within cube (in the log-ratio form)
### e.g. ratio between women and man in the group FT, 15to24
### and ratio between age groups 15to24 and 55plus
# transformation matrix
T <- rbind(c(1,rep(0,5), -1, rep(0,5)), c(rep(c(1/4,0,-1/4), 4)))
T %*% t(res$Contrast.matrix) %*%res$Bootstrap[,1]
}
Run the code above in your browser using DataLab