感谢您的提问和回复。我有完全相同的问题,只是我有 8 个变量而不是 4 个变量,如下所示:
N_for_KPI <- c(683,538,2225,1458,294,307,922,781)
N <- c(1951,1564,5683,4507,819,862,2479,2511)
Wave <- factor(c("A","A","B","B","C","C"))
Brand <- factor(c(0,1,0,1,0,1))
data = data.frame(N_for_KPI,N)
Proportion <-N_for_KPI / N
Proportion
fit <- glm(Proportion~Wave*Brand, family=binomial, weights=N)
summary(fit)
虽然我得到了显着性结果,但我得到了一个错误:
> N_for_KPI <- c(683,538,2225,1458,294,307,922,781)
> N <- c(1951,1564,5683,4507,819,862,2479,2511)
> Wave <- factor(c("A","A","B","B","C","C"))
> Brand <- factor(c(0,1,0,1,0,1))
> Proportion <-N_for_KPI / N
> Proportion
[1] 0.3500769 0.3439898 0.3915186 0.3234968 0.3589744 0.3561485
0.3719242 0.3110315
> fit <- glm(Proportion~Wave*Brand, family=binomial, weights=N)
Error in model.frame.default(formula = Proportion ~ Wave * Brand,
weights = N, :
variable lengths differ (found for 'Wave')
> summary(fit)
Call:
glm(formula = Proportion ~ Wave * Brand, family = binomial, weights
= N)
Deviance Residuals:
[1] 0 0 0 0
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -2.9422 0.1047 -28.096 <2e-16 ***
WaveB 0.0394 0.1203 0.328 0.743
Brand1 -0.1574 0.1507 -1.045 0.296
WaveB:Brand1 -0.4487 0.1786 -2.512 0.012 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 4.5383e+01 on 3 degrees of freedom
Residual deviance: -4.9938e-13 on 0 degrees of freedom
AIC: 35.137
Number of Fisher Scoring iterations: 3
除了错误,当我更改为 N_for_KPI 和 N 的新样本大小时,显着结果没有改变
您能否帮助建议如何在该模型中拟合 8 个变量?非常感谢你!