문제

I have 50 variables. This is how I use them all in my glm.

var = glm(Stuff ~ ., data=mydata, family=binomial)

But I want to exclude 2 of them. So how do I exclude 2 in specific? I was hoping there would be something like this:

var = glm(Stuff ~ . # notthisstuff, data=mydata, family=binomial)

thoughts?

도움이 되었습니까?

해결책

In addition to using the - like in the comments

glm(Stuff ~ . - var1 - var2, data= mydata, family=binomial)

you can also subset the data frame passed in

glm(Stuff ~ ., data=mydata[ , !(names(mydata) %in% c('var1','var2'))], family=binomial)

or

glm(Stuff ~ ., data=subset(mydata, select=c( -var1, -var2 ) ), family=binomial )

(be careful with that last one, the subset function sometimes does not work well inside of other functions)

You could also use the paste function to create a string representing the formula with the terms of interest (subsetting to the group of predictors that you want), then use as.formula to convert it to a formula.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top