Subset of predictors using coefplot()

只愿长相守 提交于 2019-12-23 22:19:24

问题


I'd like to do a plot of coefficients using coefplot() that only takes into account a subset of the predictors that I'm using. For example, if you have the code

 y1 <- rnorm(1000,50,23)
 x1 <- rnorm(1000,50,2) 
 x2 <- rbinom(1000,1,prob=0.63) 
 x3 <- rpois(1000, 2) 
 fit1 <- lm(y1 ~ x1 + x2 + x3)

and then ran

 coefplot(fit1)

it would give you a plot displaying the coefficients of the intercept, x1, x2 and x3. How can I modify this so I only get the coefficients for say, x1 and x2?


回答1:


You can use the argument predictors and it will only plot the coefficients you need:

library(coefplot)
coefplot(fit1, predictors=c('x1','x2'))

Output:



来源:https://stackoverflow.com/questions/32807860/subset-of-predictors-using-coefplot

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