Hello, > > 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. > You have must first write the formula in full, using 'paste'. >
Try DF <- data.frame(Resp=rnorm(10), B=rnorm(10), C=rnorm(10), Interaction=rnorm(10)) #DF for(i in 2:3){ cname <- colnames(DF)[i] # # In 3 steps to be more readable Regr <- paste(cname, "Interaction", sep="*") fmlaText <- paste("Resp", Regr, sep="~") # After step 2 it's already printable print(fmlaText) # Step 3: transform it into a formula object fmla <- as.formula(fmlaText) model1 <- glm(fmla, data=DF) print(summary(model1)) } You have must first write the formula in full, using 'paste'. Hope this helps, Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/identifying-a-column-name-correctly-to-use-in-a-formula-tp4433605p4433924.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.