How to remove intercept in R

余生颓废 提交于 2019-11-26 16:35:07

问题


I need to create a probit model without the intercept. So, how can I remove the intercept from a probit model in R?


回答1:


You don't say how you are intending to fit the probit model, but if it uses R's formula notation to describe the model then you can supply either + 0 or - 1 as part of the formula to suppress the intercept:

mod <- foo(y ~ 0 + x1 + x2, data = bar)

or

mod <- foo(y ~ x1 + x2 - 1, data = bar)

(both using pseudo R code of course - substitute your modelling function and data/variables.)

If this is a model fitting by glm() then something like:

mod <- glm(y ~ x1 + x2 - 1, data = bar, family = binomial(link = "probit"))

should do it (again substituting in your data and variable names as appropriate.)




回答2:


Also, if you have an existing formula object, foo, you can remove the intercept with update like this:

foo <- y ~ x1 + x2
bar <- update(foo, ~ . -1)
# bar == y ~ x1 + x2 - 1


来源:https://stackoverflow.com/questions/14216893/how-to-remove-intercept-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!