Internet click-throughs A common theme throughout this course has been the nestedness of data. During this case study, you will examine the number of users who click through on a link to a website before and after a redesign. These users are nested within trial groups. You will then examine the outputs and make a recommendation to your client. For this redesign, you will examine the web behavior of 10 people from 4 different focus groups, for a total of 40 people. You want to know if the number of clicks to different pages changed from the old to the new webpage while correcting for groups. # Load lmerTest library(lmerTest) #Fit a glmer() where clicks is predicted by webpage using group as a random-effect and the #data.frame user_groups. Be sure to use the '"poisson"' family. Save the model as glmer_out. glmer_out <- glmer(clicks ~ webpage + (1 | group), data = user_groups, family = "poisson") summary(glmer_out) Look at the regression coefficient estimate for the new webpage (compared to the old webpage). How did the update change the number of click-throughs? There was a positive, and statistically significant effect of the webpage redesign. ################################################################################################# Chlamydia by age-group and county The number of infections change through time and vary across age groups. Some possible reasons cultural, social, and policy-related factors. For small populations, the number of infections often includes zeros and may be non-normal. For data such as these, use a Poisson model. For this exercise, you will examine how chlamydia infections vary in small, Illinois counties. You will ask: Do the number of reported cases vary between people aged 15-19 compared to 20-24? Are the number of reported cases changing across time for these two age group? This data comes from the State of Illinois who provides summaries of infections such as chlamydia by age groups and counties. First, fit a Poisson glmer to the data. Then, examine the results. In the next exercise, plot the data. Warning: If you mistype the formula, you may cause R to crash. This is a pitfall of using lmer() and glmer(). # Load lmerTest library(lmerTest) #Run a glmer() with a "poisson" family, predicting count as a function of fixed effects age #(1st fixed-effect) and year (2nd fixed-effect), and include year as a random-effect grouped #by county. Use the data il_data. model_out <- glmer(count ~ age + year + (year | county), data = il_data, family = "poisson") summary(model_out) People aged 20 to 24 had fewer reported infections than those aged 15 to 19, but this difference was not significant. Did the slope estimate for year suggest the number of reported cases changing across time? No, the slope estimate for year was not significantly different from zero. This suggests no trend in the number of reported cases. # Extract out fixed effects fixef(model_out) # Extract out random effects ranef(model_out) ggplot(data = il_data_2, aes(x = year, y = count, group = county)) + geom_line() + facet_grid(age ~ . ) + stat_smooth(method = "glm", method.args = list(family = "poisson"), se = FALSE, alpha = 0.5) + theme_minimal()