0

I'm trying to test the difference in difference between 2 cells for control and exposed during pre-wave and post-wave.

1 - Here is the column layout of the data in spreadsheet for Cell 1 and Cell 2:

Pre-wave exposed Cell 1 | Pre-wave control Cell 1 | Post-wave exposed Cell 1 | Post-wave control Cell 1 | Pre-wave exposed Cell 2 | Pre-wave control Cell 2 | Post-wave exposed Cell 2 | Post-wave control Cell 2

2 - I then calculated the sample size for each exposed/control during pre-wave and post-wave in each KPI:

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)

3 - R then spit out the results as below:

> 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

4 - The goal is to get the significance results from the proportion variable in the model

Question: 1-Is the quote correct to describe the issue? 2-How can i fix the error: Error in model.frame.default(formula = Proportion ~ Wave * Brand, weights = N, : variable lengths differ (found for 'Wave')

Thank you so much in advance!!

  • You code is not reproducible. `fit` cannot be estimated from the code above, because Wave and Brand are length 6, while proportion is length 8 – langtang Mar 11 '22 at 15:00
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 14 '22 at 12:24

0 Answers0