0

I have a loglinear model that I know how to run using glm but I would like to know how to run it using lme4 Example dataset:

library(MASS)
UCBAdf <- as.data.frame(UCBAdmissions)

Fit loglinear model using glm

glmFitT <- glm(Freq ~ Admit * Dept * Gender, family=poisson(link="log"), data=UCBAdf)

Output from glm:

Call:
glm(formula = Freq ~ Admit * Dept * Gender, family = poisson(link = "log"), 
    data = UCBAdf)

Deviance Residuals: 
 [1]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0

Coefficients:
                                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)                       6.23832    0.04419 141.157  < 2e-16 ***
AdmitRejected                    -0.49212    0.07175  -6.859 6.94e-12 ***
DeptB                            -0.37186    0.06918  -5.375 7.65e-08 ***
DeptC                            -1.45083    0.10142 -14.305  < 2e-16 ***
DeptD                            -1.31107    0.09591 -13.669  < 2e-16 ***
DeptE                            -2.26803    0.14430 -15.718  < 2e-16 ***
DeptF                            -3.14728    0.21773 -14.455  < 2e-16 ***
GenderFemale                     -1.74969    0.11484 -15.235  < 2e-16 ***
AdmitRejected:DeptB              -0.04163    0.11319  -0.368  0.71304    
AdmitRejected:DeptC               1.02764    0.13550   7.584 3.34e-14 ***
AdmitRejected:DeptD               1.19608    0.12641   9.462  < 2e-16 ***
AdmitRejected:DeptE               1.44908    0.17681   8.196 2.49e-16 ***
AdmitRejected:DeptF               3.26187    0.23120  14.109  < 2e-16 ***
AdmitRejected:GenderFemale       -1.05208    0.26271  -4.005 6.21e-05 ***
DeptB:GenderFemale               -1.28357    0.27358  -4.692 2.71e-06 ***
DeptC:GenderFemale                2.27046    0.16270  13.954  < 2e-16 ***
DeptD:GenderFemale                1.69763    0.16754  10.133  < 2e-16 ***
DeptE:GenderFemale                2.32269    0.20663  11.241  < 2e-16 ***
DeptF:GenderFemale                1.83670    0.31672   5.799 6.66e-09 ***
AdmitRejected:DeptB:GenderFemale  0.83205    0.51039   1.630  0.10306    
AdmitRejected:DeptC:GenderFemale  1.17700    0.29956   3.929 8.53e-05 ***
AdmitRejected:DeptD:GenderFemale  0.97009    0.30262   3.206  0.00135 ** 
AdmitRejected:DeptE:GenderFemale  1.25226    0.33032   3.791  0.00015 ***
AdmitRejected:DeptF:GenderFemale  0.86318    0.40267   2.144  0.03206 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for poisson family taken to be 1)

    Null deviance: 2.6501e+03  on 23  degrees of freedom
Residual deviance: 2.8866e-14  on  0  degrees of freedom
AIC: 207.06

Number of Fisher Scoring iterations: 3

How to run the equivalent model in lme4? Thank you!

cliu
  • 933
  • 6
  • 13
  • 1
    you can't run this model in lme4 because it doesn't have any random effects. – George Savva Oct 24 '21 at 20:06
  • 1
    If you work really hard you could try to fit the equivalent model (by adding a fake grouping variable and fixing its variance), but can you give us more detail about what you're trying to do? Running an exactly equivalent model is hard. You could do it in `glmmTMB` ... or you could do something sensible like making `Dept` into a random variable ... – Ben Bolker Oct 25 '21 at 01:13
  • @BenBolker Thank you Ben for the comment. I am actually trying to do a power analysis on loglinear model but don't know how to. I came across the ```simr``` package https://cran.r-project.org/web/packages/simr/index.html but it requires ```lme4``` object. So what I am trying to do here is to convert the ```glm``` model to a ```lme4``` one. If there are some alternatives, I will appreciate any pointers! – cliu Oct 25 '21 at 01:57
  • 1
    It looks like the `simglm` package might be able to do simulation-based power analysis for `glm()` as well as `glmer()` ? – Ben Bolker Oct 25 '21 at 12:52
  • Thank you @BenBolker. I will check it out! – cliu Oct 25 '21 at 13:20
  • 1
    I’m voting to close this question because comment exchange clarifies that user is really after simulation-based power analysis for a GLM – Ben Bolker Nov 25 '21 at 02:37

0 Answers0