https://github.com/cran/robCompositions
Tip revision: 6452e1741dd003b918a2909ee567758a96e3589e authored by Matthias Templ on 20 September 2021, 13:20:05 UTC
version 2.3.1
version 2.3.1
Tip revision: 6452e17
ilrregression.R
ilrregression <- function(X,y){
# delivers appropriate inference for regression of y on a compositional matrix X
# PF, Aug 18, 2010
#
# classical regression
d <- data.frame(y=y,X=X)
lmcla <- lm(y~.,data=d)
lmcla.sum <- summary(lmcla)
# ilr regressions:
require(robCompositions)
ilr.sum <- lmcla.sum
for (j in 1:ncol(X)){
Zj <- pivotCoord(cbind(X[,j],X[,-j]))
dj <- data.frame(y=y,Z=Zj)
res <- lm(y~.,data=dj)
res.sum <- summary(res)
if (j==1){
ilr.sum$coefficients[1:2,] <- res.sum$coefficients[1:2,]
ilr.sum$residuals <- res.sum$residuals
ilr.sum$sigma <- res.sum$sigma
ilr.sum$r.squared <- res.sum$r.squared
ilr.sum$adj.r.squared <- res.sum$adj.r.squared
ilr.sum$fstatistic <- res.sum$fstatistic
}
else{
ilr.sum$coefficients[j+1,] <- res.sum$coefficients[2,]
}
}
list(lm=lmcla.sum,ilr=ilr.sum)
}