我设法从挖掘这个网站中学到的知识中删除了矩阵的第一行,但显然有一种更简单的方法可以做到这一点。这是我目前拥有的:
> prestige.income <- lm(prestige ~ log2(income), data=Prestige)
> prestige.edu <- lm(prestige ~ education, data=Prestige)
> prestige.women <- lm(prestige ~ women, data=Prestige)
> prestige.all <- lm(prestige ~ education + income + women, data=Prestige)
> comparison <- cbind(INCOME=coef(prestige.income), EDUCATION=coef(prestige.edu),
WOMEN=coef(prestige.women), ALL=coef(prestige.mod))
> comparison
INCOME EDUCATION WOMEN ALL
(Intercept) -139.85572 -10.731982 48.69299929 -110.96582409
education 14.94173 5.360878 -0.06417284 3.73050783
log2(income) -139.85572 -10.731982 48.69299929 9.31466643
women 14.94173 5.360878 -0.06417284 0.04689514
> remove <- rownames(comparison)[1]
> remove
[1] "(Intercept)"
> comp.noint <- comparison[!rownames(comparison) %in% remove, ]
> comp.noint
INCOME EDUCATION WOMEN ALL
education 14.94173 5.360878 -0.06417284 3.73050783
log2(income) -139.85572 -10.731982 48.69299929 9.31466643
women 14.94173 5.360878 -0.06417284 0.04689514
这应该是我应该做的更简单的方法/方式,但我不明白它为什么起作用:
> comparison[-1,-5]
INCOME EDUCATION WOMEN ALL
education 14.94173 5.360878 -0.06417284 3.73050783
log2(income) -139.85572 -10.731982 48.69299929 9.31466643
women 14.94173 5.360878 -0.06417284 0.04689514
有人告诉我 -1 摆脱了第一行,但实际上并没有这样做..
> comparison[-1]
[1] 14.94173191 -139.85572422 14.94173191 -10.73198197 5.36087773
[6] -10.73198197 5.36087773 48.69299929 -0.06417284 48.69299929
[11] -0.06417284 -110.96582409 3.73050783 9.31466643 0.04689514
我没有得到解释为什么 -5 会做任何事情。我知道这可能是一个非常基本的问题,但我的老师无法向我解释为什么这样做有效,我在谷歌或教科书中找不到任何东西。任何帮助都会很棒。谢谢!