[英]How to remove particular categorical predictor in R in lm()?
I am just starting out on linear modelling . 我刚刚开始线性建模。 I have the below regressor 我有以下回归
regressor=lm(Profit~R.D.Spend+Administration+Marketing.Spend+State,data=dataset)
Now three state levels. 现在是三个州级别。
> levels(dataset$State)
[1] "1" "2" "3"
Below is the output of my model , and i just need to remove state2 from it . 下面是我的模型的输出,我只需要从其中删除state2即可。 How do i go about that ? 我该怎么办?
> summary(regressor)
Call:
lm(formula = Profit ~ R.D.Spend + Administration + Marketing.Spend +
State, data = dataset)
Residuals:
Min 1Q Median 3Q Max
-33504 -4736 90 6672 17338
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.013e+04 6.885e+03 7.281 4.44e-09 ***
R.D.Spend 8.060e-01 4.641e-02 17.369 < 2e-16 ***
Administration -2.700e-02 5.223e-02 -0.517 0.608
Marketing.Spend 2.698e-02 1.714e-02 1.574 0.123
State2 1.988e+02 3.371e+03 0.059 0.953
State3 -4.189e+01 3.256e+03 -0.013 0.990
this should do it: 这应该做到这一点:
regressor<-update(regressor,~.-State2)
summary(regressor)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.