0

如何获得所有其他变量的组均值(使用多元回归)?我看到了一个这样做的分析,并试图为一组不同的数据生成类似的东西。

例如,使用 car pacakge 中的 Prestige 数据集:

library(car)
df<-Prestige
df$Group<-ifelse(df$women>.25,"High","Low") #this is a useless variable for regression, but I put this in because the real data i'm working with has multiple categorical variables, which makes it more confusing (I know how to get the means when there are only continuous vars)
reg<-lm(income~education+women+prestige+census+factor(type)+factor(Group),data=df)
summary(reg)

给我以下输出

Call:
lm(formula = income ~ education + women + prestige + census + 
factor(type) + factor(Group), data = df)

Residuals:
Min      1Q  Median      3Q     Max 
-7743.7  -947.9  -331.8   744.8 14307.5 

Coefficients:
                   Estimate Std. Error t value Pr(>|t|)    
(Intercept)       -33.79732 3056.02530  -0.011 0.991201    
education         130.75186  290.21943   0.451 0.653414    
women             -52.78426   10.00398  -5.276 9.03e-07 ***
prestige          139.42427   36.59482   3.810 0.000254 ***
census              0.04043    0.23694   0.171 0.864892    
factor(type)prof  534.53024 1810.15685   0.295 0.768449    
factor(type)wc    368.17807 1181.93287   0.312 0.756137    
factor(Group)Low  367.09089 1274.25821   0.288 0.773946    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2646 on 90 degrees of freedom
  (4 observations deleted due to missingness)
Multiple R-squared:  0.6366,    Adjusted R-squared:  0.6084 
F-statistic: 22.53 on 7 and 90 DF,  p-value: < 2.2e-16Coefficients: 

我知道 368.17807 是 type==wc 和参考组(type==bc)之间的平均值之间的差异,但是我如何获得实际的平均值呢?这应该与仅计算每种类型的所有观察值的平均值不同,可以通过以下方式找到

aggregate(income~type,data=df,FUN=mean)
4

0 回答 0