Hi,

I have a large matrix (SNPs) that I want to cycle over with logistic
regression with interaction terms. I have made a loop but I am struggling
to identify to the formula the name of the column in a way which is
meaningful to the formula. It errors becasue it is not evaluated proporly.

(below is a pilot with only 7 to 33 columns, my actual has 200,000 columns)

My attempts:


for (i in 7:33) {
  label <- colnames(n)[i]
model1 <- glm(AS~label*interaction,family=binomial("logit"),data=n)
    X <- summary(model1)$coefficients[2,1]
Y <- c(label,X)
vector <- rbind(vector,Y)
} #variable lengths differ

Error in model.frame.default(formula = AS ~ label, data = n,
drop.unused.levels = TRUE) :
  variable lengths differ (found for 'label')

#This is because it is trying to do logistic regression on a character
string

for (i in 7:33) {
  label <- eval(colnames(n)[i])
model1 <- glm(AS~label*interaction,family=binomial("logit"),data=n)
    X <- summary(model1)$coefficients[2,1]
Y <- c(label,X)
vector <- rbind(vector,Y)
} #variable lengths differ

Error in model.frame.default(formula = AS ~ label, data = n,
drop.unused.levels = TRUE) :
  variable lengths differ (found for 'label')

#same as above

for (i in 7:33) {
  label <- as.name(colnames(n)[i])
model1 <- glm(AS~label*interaction,family=binomial("logit"),data=n)
    X <- summary(model1)$coefficients[2,1]
Y <- c(label,X)
vector <- rbind(vector,Y)
}

Error in model.frame.default(formula = AS ~ label, data = n,
drop.unused.levels = TRUE) :
  invalid type (symbol) for variable 'label
#not sure what this error is

for (i in 7:33) {
  label <- eval(as.name(colnames(n)[i]))
model1 <- glm(AS~label*interaction,family=binomial("logit"),data=n)
    X <- summary(model1)$coefficients[2,1]
Y <- c(label,X)
vector <- rbind(vector,Y)
}

# Error in eval(expr, envir, enclos) : object 'B1' not found
B1 is the name of the first column - this isn't an object and that seems to
be why it is causing an error

for (i in 7:33) {
  label <- as.formula(colnames(n)[i])
model1 <- glm(AS~label*interaction,family=binomial("logit"),data=n)
    X <- summary(model1)$coefficients[2,1]
Y <- c(label,X)
vector <- rbind(vector,Y)
}
Error in eval(expr, envir, enclos) : object 'B1' not found

#same as above

for (i in 7:33) {
  label <- eval(as.formula(colnames(n)[i]))
model1 <- glm(AS~label*interaction,family=binomial("logit"),data=n)
    X <- summary(model1)$coefficients[2,1]
Y <- c(label,X)
vector <- rbind(vector,Y)
}

Error in eval(expr, envir, enclos) : object 'B1' not found
#same as above

Any help would be appreciated.

Thanks
Philip

	[[alternative HTML version deleted]]

