简体   繁体   中英

Is there a R function or package to calculate the p value of a slope in a GLMM with interactions

Consider I have a linear mixed model with two continuous variables and use contrast coding for two factors with each two categories respectively (A,B). A random effect is optional.

contrasts(data$fac1) <- c(-.5,.5)
contrasts(data$fac2) <- c(-.5,.5)

model<-lme(Y~x1+x2+x1:fac1+x2:fac1+x1:fac2+x2:fac2+fac1+fac2+fac1:fac2, random=~1|group,data)

then the output will give me the main effects for x1 and x2 and the difference between slopes for fac1 and fac2.

But how can I calculate individual p-values for say the slope of x1 fac1=="A" and fac2=="B" ?

Is there an R package or do I have to calculate them manually ?

And if yes how? -following calls to vcov() adding up respective matrix entries and call to pt() (which df to use)? Thanks!

You could try the marginaleffects package. (Disclaimer: I am the author.)

There are many vignettes on the website, including one with simple examples of mixed effects models with the lme4 package: https://vincentarelbundock.github.io/marginaleffects/articles/lme4.html

You can specify the values of covariates using the newdata argument and the datagrid function. The covariates you do not specify in datagrid will be held at their means or modes:

library(lme4)
library(marginaleffects)

mod <- glmer(am ~ mpg * hp + (1 | gear),
             data = mtcars,
             family = binomial)

marginaleffects(mod, newdata = datagrid(hp = c(100, 110), gear = 4))
#>   rowid     type term        dydx  std.error statistic   p.value
#> 1     1 response  mpg 0.077446700 0.33253683 0.2328966 0.8158417
#> 2     2 response  mpg 0.337725702 0.90506056 0.3731526 0.7090349
#> 3     1 response   hp 0.006199167 0.02647471 0.2341543 0.8148652
#> 4     2 response   hp 0.025604198 0.06770870 0.3781522 0.7053175
#>      conf.low  conf.high      mpg  hp gear
#> 1 -0.57431351 0.72920691 20.09062 100    4
#> 2 -1.43616041 2.11161181 20.09062 110    4
#> 3 -0.04569032 0.05808865 20.09062 100    4
#> 4 -0.10710242 0.15831082 20.09062 110    4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM