[R-sig-ME] Dealing with zero inflated models: How to visualize and bootstrap to calculate the CIs?
Pardis Miri
p@r|@m @end|ng |rom @t@n|ord@edu
Fri May 3 08:59:12 CEST 2019
Hi everyone,
I have five DVs (Attend, Differentiate, Synchronize, Negative Affect (NA), and Positive Affect (PA)) collected from slider bars. Zero value means that haptic pattern that a participant experienced was easy to attend, easy to differentiate, and easy to synchronize breathing with.
Zero value also means that the participant didn't feel negative at all.
As you can see in link<https://wehab.stanford.edu/wp-content/uploads/2019/05/zero_inflated_2.png> 1 and link 2<https://wehab.stanford.edu/wp-content/uploads/2019/05/zero_inflated_1.png> , the data for Attend, Differentiate, Synchronize, and NA are all zero inflated. We expected to see this: this is an indication that our intervention worked well. But, I am struggling with the following three problems.
IVs:
Bodysite: Abdomen, Lowerback, and Chest
Pattern: Vertical, Horizontal, and Diagonal
Shape: Strong Inhale, and Strong Exhale.
1. I am not sure which one of these formulas I should be using to model my data and why one should be better than the other.
### Differentiate (zero inflation) --> Boot strapping doesn't work.
```{r Differentiate}
# >> won't work with boothstrapping
# bootstrap parameter estimates --> error bootstrapping doesn't accept the glmmTBM. instead you should be using the lmer or glmer.... . n = 36 (number of participants).
# first way
fit.differentiate = glmmTMB((Differentiate/100* 35 + .5) /36 ~ Bodysite + Pattern * Strength + (1 |id), data=df.cleaned, ziformula=~1, family=beta_family(link = "logit"))
fit.attend %>%
summary()
# Alternative way
library("GLMMadaptive")
fit.differentiate = mixed_model(Differentiate ~ Bodysite + Pattern * Strength, random = ~ 1 | id, data=df.cleaned, family=zi.poisson(), zi_fixed = ~ Bodysite + Pattern * Strength, zi_random = ~ 1 | id)
fit.attend %>%
summary()
#still won't work with bootstrapping
boot.lmer = bootMer(fit.differentiate,
FUN = fixef,
nsim = 1000)
n = 1 # one hypothesis testing for now. Have to change it later.
# compute confidence intervals for all the estimates in one go.
tidy(boot.lmer,conf.int<http://conf.int>=TRUE,conf.method="perc", conf.level = 1 - (.05/n))
```
2. I don't know how to use bootstrapping to calculate the CI for inflated with zero models.
3. I don't know how to visualize the data like how I did for another DV that is not inflated with zero (see example<https://wehab.stanford.edu/wp-content/uploads/2019/05/mixed_model_vis1.png>).
```{r slop_visualization}
p = fit.lmer %>%
augment() %>%
clean_names() %>%
ggplot(data = .,
mapping = aes(x = bodysite,
y = sc_slope,
col = id,
shape = strength,
group = interaction(strength,id))) +
facet_wrap(~pattern, ncol = 5) +
geom_point(alpha = 0.2) +
geom_line(alpha = 0.5) +
geom_point(aes(y = fitted),
color = "red") +
geom_line(aes(y = fitted),
color = "red") +
xlab("") +
ylab("SC_slope")
p
ggsave("SC_slope_model.png", plot = p, width = 8, height = 6, units = "in")
```
Thank you in advance!
P
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models
mailing list