I am trying to run a logistic regression on multiple dependent variables, 'traits', which are columns in a data frame, against a single independent variable, 'score'. I'm trying to do this as either one line of code or in a loop - but not succeeding at it!
For just doing columns 4 to 10, I've tried:
glm_output <- glm(data.matrix(myData[,4:10]) ~ myData$Sscore, na.action=na.exclude, family=binomial(link= "logit"))
I get the error message: "Error in eval(expr, envir, enclos) : for the 'binomial' family, y must be a vector of 0 and 1's or a 2 column matrix where col 1 is no. successes and col 2 is no. failures". My columns are factors, coded as 1 and 2's and it will happily do them individually. So I'm not sure why it doesn't like it.
I've also tried:
`for(i in names(myData))
{
fit <- glm(myData[,i] ~ myData$score, data=myData, na.action=na.exclude)
}
However this gives me one coefficient rather than one for every column of the data frame.
Any help would be much appreciated!
myData$Sscore ~ data.matrix(myData[,4:10])
. Could you provide myData? – m-dzfit
inside the for loop and store it in a list or data.frame. – m-dz