I run the code for all possible phylogenetic generalized linear model models. The problem I am facing is retrieving and maintaining beta ratios for each model.
I want to store the coefficients in a matrix where the columns correspond to a specific variable and the rows correspond to the formula. The problem arises because the variables are different for each model. Thus, one cannot simply compare the coefficients with the matrix.
The example below shows what the problem is:
y = rnorm(10)
inpdv = matrix(c(rnorm(10), runif(10), rpois(10, 1)), ncol = 3)
colnames(inpdv) = c("A", "B", "C")
data = cbind(y, inpdv)
model.mat = expand.grid(c(TRUE,FALSE), c(TRUE,FALSE), c(TRUE,FALSE))
names(model.mat) = colnames(inpdv)
formula = apply(model.mat, 1, function(x)
paste(colnames(model.mat)[x], collapse=" + "))
formula = paste("y", formula, sep = " ~ ")
formula[8] = paste(formula[8], 1, sep = "")
beta = matrix(NA, nrow = length(formula), ncol = 3)
for(i in 1:length(formula)){
fit = lm(formula(formula), data)
}
Therefore, I suppose that each coefficient will need to be placed in the appropriate cell, but I canβt come up with a quick and effective way to do this.
30 000 , .
:
, , y ~ a + c
a NA b
.
y ~ b + c, ββ . ,
a NA b
NA b c