[英]how do i exclude specific variables from a glm in R?
I have 50 variables.我有 50 个变量。 This is how I use them all in my glm.
这就是我在我的 glm 中使用它们的方式。
var = glm(Stuff ~ ., data=mydata, family=binomial)
But I want to exclude 2 of them.但我想排除其中的 2 个。 So how do I exclude 2 in specific?
那么如何具体排除 2 呢? 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.您还可以使用
paste
函数创建一个字符串,该字符串表示具有感兴趣项的公式(子集到您想要的一组预测变量),然后使用as.formula
将其转换为公式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.