简体   繁体   English

如何在lm()中删除R中的特定类别预测变量?

[英]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.

相关问题 R中lm回归中预测变量的编码 - coding for predictor variables in lm regression in R 当我们使用多个分类预测器删除截距时,“lm()”的行为如何 - How `lm()` behaves when we remove intercept with multiple categorical predictors 如何表示分类预测变量 rstan? - How to represent a categorical predictor rstan? R使用glm和分类变量复制预测变量 - R duplicating predictor variables with glm and categorical variables 在R中使用`lm`时获得缩放的预测值 - Obtain scaled predictor values when using `lm` in R 线性回归[R]:如何根据分类变量的出现为同一预测变量计算多个系数 - Linear regression [R]: how to calculate multiple coefficients for the same predictor based on the occurrence of a categorical variable R lm 捕获交互项,但不是分类变量 - R lm Capture interaction terms, but not categorical variable R lm 如何选择与分类变量和连续变量之间的交互作用的对比? - How does R lm choose contrasts with interaction between a categorical and continuous variables? 与lm的R线性回归 - 如何处理具有数千个值的分类变量(如城市或邮政编码)? - R linear regression with lm - how to deal with categorical variables with thousands of values (like city or zip code)? lm()如何知道哪些预测变量是分类的? - How does lm() know which predictors are categorical?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM