我想知道如何将模型中的偏移量(或固定系数)放在每个不同级别的分类变量上,看看它如何影响其他变量。我不确定如何准确编码。
Call:
这给出了以下内容:
glm(formula = mpg ~ cyl + hp, data = mtcars)
Deviance Residuals:
Min 1Q Median 3Q Max
-4.818 -1.959 0.080 1.627 6.812
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 28.65012 1.58779 18.044 < 2e-16 ***
cyl6 -5.96766 1.63928 -3.640 0.00109 **
cyl8 -8.52085 2.32607 -3.663 0.00103 **
hp -0.02404 0.01541 -1.560 0.12995
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for gaussian family taken to be 9.898847)
`Null deviance: 1126.05 on 31 degrees of freedom`
Residual deviance: 277.17 on 28 degrees of freedom
AIC: 169.9
Number of Fisher Scoring iterations: 2
model2 <- glm(mpg ~ offset(I(-4 * cyl[6]))+ hp, data = mtcars)
我想将气缸设置为不同的偏移量,比如说6个气缸到-4个气缸和8个气缸到-9,所以我可以看到它对马力的作用。我在下面的代码中尝试了这个但是得到了错误,所以我不确定在分类变量中做一个多于一个的唯一值的正确方法。
[('Treeitem.padding',
{'children': [('Treeitem.indicator', {'side': 'left', 'sticky': ''}),
('Treeitem.image', {'side': 'left', 'sticky': ''}),
('Treeitem.focus',
{'children': [('Treeitem.text', {'side': 'left', 'sticky': ''})],
'side': 'left',
'sticky': ''})],
'sticky': 'nswe'})]
有人会帮我弄清楚如何正确地做到这一点吗?
答案 0 :(得分:1)
在新的R会议中:
glm(mpg ~ offset(I(-4 * (cyl == 6) + -9 * (cyl == 8))) + hp, data = mtcars)
# Call: glm(formula = mpg ~ offset(I(-4 * (cyl == 6) + -9 * (cyl == 8))) +
# hp, data = mtcars)
#
# Coefficients:
# (Intercept) hp
# 27.66881 -0.01885
#
# Degrees of Freedom: 31 Total (i.e. Null); 30 Residual
# Null Deviance: 353.8
# Residual Deviance: 302 AIC: 168.6