## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## 
## Attaching package: 'table1'
## 
## 
## The following objects are masked from 'package:base':
## 
##     units, units<-
## 
## 
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
## 
## Loading required package: lme4
## 
## Loading required package: Matrix
## 
## 
## Attaching package: 'Matrix'
## 
## 
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
## 
## 
## 
## Attaching package: 'lmerTest'
## 
## 
## The following object is masked from 'package:lme4':
## 
##     lmer
## 
## 
## The following object is masked from 'package:stats':
## 
##     step
## 
## 
## Loading required package: carData
## 
## 
## Attaching package: 'car'
## 
## 
## The following object is masked from 'package:dplyr':
## 
##     recode
## 
## 
## The following object is masked from 'package:purrr':
## 
##     some
## 
## 
## # Attaching packages: easystats 0.7.0
## ✔ bayestestR  0.13.1   ✔ correlation 0.8.4 
## ✔ datawizard  0.9.0    ✔ effectsize  0.8.6 
## ✔ insight     0.19.7   ✔ modelbased  0.8.6 
## ✔ performance 0.10.8   ✔ parameters  0.21.3
## ✔ report      0.5.8    ✔ see         0.8.1 
## 
## 
## 
## Attaching package: 'janitor'
## 
## 
## The following object is masked from 'package:insight':
## 
##     clean_names
## 
## 
## The following objects are masked from 'package:datawizard':
## 
##     remove_empty, remove_empty_rows
## 
## 
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
## 
## 
## 
## Attaching package: 'modelsummary'
## 
## 
## The following object is masked from 'package:parameters':
## 
##     supported_models
## 
## 
## The following object is masked from 'package:insight':
## 
##     supported_models
## 
## 
## 
## ************
## Welcome to faux. For support and examples visit:
## https://debruine.github.io/faux/
## - Get and set global package options with: faux_options()
## ************

Exercise 1

Adjust the parameters, simulate your clustered data and present the results of the three models using the modelsummary package. Interpret the three models and compare the estimations with each of the six parameters you use in order to create your dataset. Is there one single model that is superior to all the rest in terms of estimating the parameters? If so which is it? If not, Which model works best for what purpose? In your answer, please pay attention to the estimated Intraclass Correlation Coefficient (ICC) of your multilevel model. What does the ICC mean? How much does it deviate from what you would expect?

### Stimulating Data
obs_per_cluster <-  20
n_cluster <-  5
# Fixed intercept
alpha_0 <-  1  
# Fixed slope
beta_0 <- .5  
# Residuals st.dev (level 1) 
sig  <-  1
# Random intercept st.dev (level 2) 
sig_u <-  .5
# Random slope st.dev (level 2)
sig_v <-  .25
# Independent random effects
cor <-  0

# Create a dataset that can be reproduced
set.seed(888)  
# step 1: create the units 
df<- add_random(
    cluster = n_cluster,  # first the clusters
    obs = obs_per_cluster # second, the observations
    )

# Print the result 
# try to figure out what just happened
df |> 
  print(n = 15)
## # A tibble: 100 × 2
##    cluster  obs  
##    <chr>    <chr>
##  1 cluster1 obs01
##  2 cluster1 obs02
##  3 cluster1 obs03
##  4 cluster1 obs04
##  5 cluster1 obs05
##  6 cluster1 obs06
##  7 cluster1 obs07
##  8 cluster1 obs08
##  9 cluster1 obs09
## 10 cluster1 obs10
## 11 cluster1 obs11
## 12 cluster1 obs12
## 13 cluster1 obs13
## 14 cluster1 obs14
## 15 cluster1 obs15
## # ℹ 85 more rows
# step 2: Add anything at level 2
# Here we have random intercept/slope 
df <- df |>
  add_ranef(
    "cluster",
    u_i = sig_u,
    v_i = sig_v,
    .cors = cor
    ) |> mutate(
      a_i = alpha_0 + u_i, 
      b_i = beta_0  + v_i
    )

# Print the result 
# try to figure out what just happened
df |> 
  print(n = 15)
## # A tibble: 100 × 6
##    cluster  obs     u_i    v_i   a_i   b_i
##    <chr>    <chr> <dbl>  <dbl> <dbl> <dbl>
##  1 cluster1 obs01 0.976 0.0628  1.98 0.563
##  2 cluster1 obs02 0.976 0.0628  1.98 0.563
##  3 cluster1 obs03 0.976 0.0628  1.98 0.563
##  4 cluster1 obs04 0.976 0.0628  1.98 0.563
##  5 cluster1 obs05 0.976 0.0628  1.98 0.563
##  6 cluster1 obs06 0.976 0.0628  1.98 0.563
##  7 cluster1 obs07 0.976 0.0628  1.98 0.563
##  8 cluster1 obs08 0.976 0.0628  1.98 0.563
##  9 cluster1 obs09 0.976 0.0628  1.98 0.563
## 10 cluster1 obs10 0.976 0.0628  1.98 0.563
## 11 cluster1 obs11 0.976 0.0628  1.98 0.563
## 12 cluster1 obs12 0.976 0.0628  1.98 0.563
## 13 cluster1 obs13 0.976 0.0628  1.98 0.563
## 14 cluster1 obs14 0.976 0.0628  1.98 0.563
## 15 cluster1 obs15 0.976 0.0628  1.98 0.563
## # ℹ 85 more rows
# step 3: add anything at level 1
df <- df |>
  mutate(
    x       = rnorm(n_cluster * obs_per_cluster),
    epsilon = rnorm(n_cluster * obs_per_cluster, 0, sig),
    y = a_i + b_i * x + epsilon
    )

# Print the result 
# try to figure out what just happened
df |> 
  print(n = 20)
## # A tibble: 100 × 9
##    cluster  obs     u_i    v_i   a_i   b_i       x  epsilon     y
##    <chr>    <chr> <dbl>  <dbl> <dbl> <dbl>   <dbl>    <dbl> <dbl>
##  1 cluster1 obs01 0.976 0.0628  1.98 0.563  0.317  -0.00411 2.15 
##  2 cluster1 obs02 0.976 0.0628  1.98 0.563  1.36    2.47    5.21 
##  3 cluster1 obs03 0.976 0.0628  1.98 0.563  0.956  -1.16    1.35 
##  4 cluster1 obs04 0.976 0.0628  1.98 0.563  0.406  -0.774   1.43 
##  5 cluster1 obs05 0.976 0.0628  1.98 0.563 -0.501   0.190   1.88 
##  6 cluster1 obs06 0.976 0.0628  1.98 0.563 -1.14   -0.559   0.772
##  7 cluster1 obs07 0.976 0.0628  1.98 0.563  1.18   -0.883   1.76 
##  8 cluster1 obs08 0.976 0.0628  1.98 0.563 -0.191   0.647   2.52 
##  9 cluster1 obs09 0.976 0.0628  1.98 0.563 -2.19   -0.0519  0.690
## 10 cluster1 obs10 0.976 0.0628  1.98 0.563 -0.338   1.06    2.85 
## 11 cluster1 obs11 0.976 0.0628  1.98 0.563 -0.0519 -0.352   1.59 
## 12 cluster1 obs12 0.976 0.0628  1.98 0.563 -0.280   0.979   2.80 
## 13 cluster1 obs13 0.976 0.0628  1.98 0.563 -0.749   1.05    2.60 
## 14 cluster1 obs14 0.976 0.0628  1.98 0.563  0.777   0.0651  2.48 
## 15 cluster1 obs15 0.976 0.0628  1.98 0.563 -0.223   0.0971  1.95 
## 16 cluster1 obs16 0.976 0.0628  1.98 0.563 -0.142   0.617   2.51 
## 17 cluster1 obs17 0.976 0.0628  1.98 0.563 -0.173   0.100   1.98 
## 18 cluster1 obs18 0.976 0.0628  1.98 0.563  2.97   -0.0398  3.61 
## 19 cluster1 obs19 0.976 0.0628  1.98 0.563  0.235  -0.990   1.12 
## 20 cluster1 obs20 0.976 0.0628  1.98 0.563  0.328  -0.725   1.44 
## # ℹ 80 more rows
# For the models, we really only need 
# the cluster id, the y and the x
df  <- df |> select(cluster, x, y)

# Print the result 
# try to figure out what just happened
df |> 
  print(n = 20)
## # A tibble: 100 × 3
##    cluster        x     y
##    <chr>      <dbl> <dbl>
##  1 cluster1  0.317  2.15 
##  2 cluster1  1.36   5.21 
##  3 cluster1  0.956  1.35 
##  4 cluster1  0.406  1.43 
##  5 cluster1 -0.501  1.88 
##  6 cluster1 -1.14   0.772
##  7 cluster1  1.18   1.76 
##  8 cluster1 -0.191  2.52 
##  9 cluster1 -2.19   0.690
## 10 cluster1 -0.338  2.85 
## 11 cluster1 -0.0519 1.59 
## 12 cluster1 -0.280  2.80 
## 13 cluster1 -0.749  2.60 
## 14 cluster1  0.777  2.48 
## 15 cluster1 -0.223  1.95 
## 16 cluster1 -0.142  2.51 
## 17 cluster1 -0.173  1.98 
## 18 cluster1  2.97   3.61 
## 19 cluster1  0.235  1.12 
## 20 cluster1  0.328  1.44 
## # ℹ 80 more rows
## Models
complete_pooling <- lm(y ~ x, data = df)
summary(complete_pooling)
## 
## Call:
## lm(formula = y ~ x, data = df)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.42332 -0.66351 -0.00546  0.76224  3.02368 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   1.6884     0.1077   15.68  < 2e-16 ***
## x             0.3640     0.1058    3.44 0.000857 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.077 on 98 degrees of freedom
## Multiple R-squared:  0.1077, Adjusted R-squared:  0.09861 
## F-statistic: 11.83 on 1 and 98 DF,  p-value: 0.0008574
no_pooling <- lm(y ~ x + cluster, data = df)
summary(no_pooling)
## 
## Call:
## lm(formula = y ~ x + cluster, data = df)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.99046 -0.76671 -0.05493  0.54916  2.60660 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      2.08577    0.21813   9.562 1.57e-15 ***
## x                0.37857    0.09659   3.919 0.000168 ***
## clustercluster2 -0.21382    0.30840  -0.693 0.489807    
## clustercluster3 -1.09690    0.30878  -3.552 0.000599 ***
## clustercluster4 -0.85577    0.30801  -2.778 0.006596 ** 
## clustercluster5  0.18069    0.30965   0.584 0.560939    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.974 on 94 degrees of freedom
## Multiple R-squared:  0.2999, Adjusted R-squared:  0.2627 
## F-statistic: 8.054 on 5 and 94 DF,  p-value: 2.345e-06
no_pooling_int <- lm(y ~ x + cluster + x * cluster, data = df)
summary(no_pooling_int)
## 
## Call:
## lm(formula = y ~ x + cluster + x * cluster, data = df)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.9770 -0.7102 -0.0059  0.6895  2.4317 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)        2.06771    0.22113   9.351 6.41e-15 ***
## x                  0.52088    0.21450   2.428 0.017156 *  
## clustercluster2   -0.18817    0.31164  -0.604 0.547488    
## clustercluster3   -1.08376    0.31242  -3.469 0.000804 ***
## clustercluster4   -0.80552    0.31342  -2.570 0.011810 *  
## clustercluster5    0.17650    0.31453   0.561 0.576092    
## x:clustercluster2  0.06551    0.30285   0.216 0.829223    
## x:clustercluster3 -0.19094    0.31538  -0.605 0.546416    
## x:clustercluster4 -0.34748    0.30608  -1.135 0.259275    
## x:clustercluster5 -0.25128    0.30152  -0.833 0.406839    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9814 on 90 degrees of freedom
## Multiple R-squared:  0.3194, Adjusted R-squared:  0.2514 
## F-statistic: 4.693 on 9 and 90 DF,  p-value: 4.092e-05
multilevel_model <- lmer(y ~ x + (1 | cluster), data = df, REML = F)
summary(multilevel_model)
## Linear mixed model fit by maximum likelihood . t-tests use Satterthwaite's
##   method [lmerModLmerTest]
## Formula: y ~ x + (1 | cluster)
##    Data: df
## 
##      AIC      BIC   logLik deviance df.resid 
##    293.7    304.1   -142.9    285.7       96 
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.96768 -0.75765 -0.05529  0.59639  2.77270 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  cluster  (Intercept) 0.1980   0.4450  
##  Residual             0.9386   0.9688  
## Number of obs: 100, groups:  cluster, 5
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)  1.68858    0.22134  4.99852   7.629 0.000616 ***
## x            0.37574    0.09591 95.64520   3.918 0.000168 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##   (Intr)
## x 0.005
multilevel_model_x <- lmer(y ~ x + (x | cluster), data = df)
## boundary (singular) fit: see help('isSingular')
summary(multilevel_model_x)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: y ~ x + (x | cluster)
##    Data: df
## 
## REML criterion at convergence: 289.3
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.94127 -0.79241 -0.00156  0.59986  2.68249 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr
##  cluster  (Intercept) 0.262893 0.51273      
##           x           0.004295 0.06554  1.00
##  Residual             0.944161 0.97168      
## Number of obs: 100, groups:  cluster, 5
## 
## Fixed effects:
##             Estimate Std. Error      df t value Pr(>|t|)   
## (Intercept)   1.6901     0.2490  3.9956   6.786  0.00247 **
## x             0.3730     0.1006 19.2617   3.708  0.00146 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##   (Intr)
## x 0.273 
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
modelsummary(
  list(
    "Complete pooling" = complete_pooling,
    "No pooling" = no_pooling,
    "No pooling + interaction" = no_pooling_int,
    "Multilevel model" = multilevel_model,
    "Multilevel model + random slopes" = multilevel_model_x
    ),
  stars = TRUE
  )
Complete pooling No pooling No pooling + interaction Multilevel model Multilevel model + random slopes
(Intercept) 1.688*** 2.086*** 2.068*** 1.689*** 1.690***
(0.108) (0.218) (0.221) (0.221) (0.249)
x 0.364*** 0.379*** 0.521* 0.376*** 0.373***
(0.106) (0.097) (0.214) (0.096) (0.101)
clustercluster2 −0.214 −0.188
(0.308) (0.312)
clustercluster3 −1.097*** −1.084***
(0.309) (0.312)
clustercluster4 −0.856** −0.806*
(0.308) (0.313)
clustercluster5 0.181 0.176
(0.310) (0.315)
x × clustercluster2 0.066
(0.303)
x × clustercluster3 −0.191
(0.315)
x × clustercluster4 −0.347
(0.306)
x × clustercluster5 −0.251
(0.302)
SD (Intercept cluster) 0.445 0.513
SD (x cluster) 0.066
Cor (Intercept~x cluster) 1.000
SD (Observations) 0.969 0.972
Num.Obs. 100 100 100 100 100
R2 0.108 0.300 0.319
R2 Adj. 0.099 0.263 0.251
R2 Marg. 0.115 0.134
R2 Cond. 0.269
AIC 302.6 286.3 291.5 297.7 301.3
BIC 310.4 304.6 320.2 308.1 316.9
ICC 0.2
Log.Lik. −148.291 −136.161 −134.750
RMSE 1.07 0.94 0.93 0.95 0.95
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001

The complete pooling model assumes one slope for all clusters, while the no pooling model has a separate slope for each cluster. ICC is a measure of between-cluster variation (as a proportion of the total variation). A higher ICC suggests more variability between clusters and thus a higher clustering effect.

Exercise 2

Use your models to create a caterpillar plot for the intercepts and lattice and/or spaghetti plots to show the features of your multilevel models. Describe and discuss the plots: what new light do they shed? What are the advantages or disadvantages of presenting the models using these plots?

# First, we need the list of clusters
clusters <- df |> 
  pull(cluster) |> 
  unique()

# Now let's fit our multilevel model
mdl_multilevel <- lmer(y ~ x + (x | cluster), df) 
## boundary (singular) fit: see help('isSingular')
# predictions of y for each cluster at x = 0
predict_y <- mdl_multilevel |> 
  ranef() |> 
  # Used the broom.mixed::augment function 
  # to calculate the confidence intervals
  augment() |> 
  # convert to a tibble
  as_tibble() |> 
  # Include only the random intercept
  filter(variable == "(Intercept)") |> 
  # Now we order the results by ascending estimates
  arrange(estimate) |> 
  mutate(cluster = fct_inorder(level)) 

# Finally, let's plot our caterpillar!
predict_y |>
  ggplot(aes(xmin = (estimate - 1.96 * std.error), xmax = (estimate + 1.96 * std.error), y = cluster, x = estimate)) + 
    geom_pointrange() + 
    labs(x = "Estimate of the intercept (Y_hat when X=0)", y = NULL)

# Spagetti - Random intercept
predictions(mdl_multilevel) |>  
  ggplot(aes(x = x, y = y, color = cluster)) + 
  geom_point() + 
  geom_line(aes(x, y = estimate))

# Lattice 
predictions(mdl_multilevel) |>  
  ggplot(aes(x = x, y = y, color = cluster)) + 
  geom_point() + 
  geom_line(aes(x, y = estimate))+
  facet_wrap(~cluster)

# Random slope and intercept
predict_y_2 <- mdl_multilevel |> 
  ranef() |> 
  # Used the broom.mixed::augment function 
  # to calculate the confidence intervals
  augment() |> 
  # convert to a tibble
  as_tibble() |> 
  # Include random intercept and slope
  filter(variable == "x") |> 
  # Now we order the results by ascending estimates
  arrange(estimate) |> 
  mutate(cluster = fct_inorder(level))

# Plot caterpillar
predict_y_2 |>
  ggplot(aes(xmin = (estimate - 1.96 * std.error), xmax = (estimate + 1.96 * std.error), y = cluster, x = estimate)) + 
    geom_pointrange() + 
    labs(x = "Estimate of the intercept and slope (Y_hat when X=0)", y = NULL)

The caterpillar plot shows the variability between the clusters. The dots represent the estimated random intercept for a cluster. The length reflects the uncertainty of the estimation. The spaghetti plot shows the individual-level variability within a cluster. Advantages: Visualizing Individual Estimates: Caterpillar plots allow for a visual representation of individual estimates for each level of a random effect in a mixed effects model. This can be valuable for understanding the variability across different clusters or groups.Comparing Confidence Intervals: The plot includes confidence intervals for each estimate, making it easy to compare the precision of estimates across different levels. This helps assess the uncertainty associated with each parameter.Identifying Outliers: Outliers or extreme values in the estimates are easily identified in a caterpillar plot. This can be important for detecting clusters or groups that deviate significantly from the overall pattern. Interpretability: Caterpillar plots provide a concise and interpretable summary of random effects. Researchers and practitioners can quickly grasp the distribution of effects across different levels. Useful for Presentations: In presentations or reports, caterpillar plots offer a visually appealing way to communicate complex information about random effects and their variability.Disadvantages: Limited for Large Datasets: For large datasets with numerous levels, caterpillar plots can become crowded and challenging to interpret. In such cases, alternative visualization methods may be more appropriate. Sensitivity to Scaling: Caterpillar plots can be sensitive to the scaling of the random effects. Choosing appropriate scales for the y-axis is crucial for accurate interpretation.Complexity in Hierarchical Structures: In hierarchical structures with multiple levels, interpreting the caterpillar plot may become more complex, especially if there are interactions or correlations between random effects. Not Suitable for Fixed Effects: Caterpillar plots are typically used for random effects in mixed effects models. They may not be suitable for presenting fixed effects, which are better represented using standard coefficient plots.

Exercise 3

Create a table1 and use GGally::ggpairs to explore your data.

radon_mn <- read_rds("https://bit.ly/BMLR-Radon") |> 
  filter(state == "MN") |>
  # drop counties without measurements
  mutate(county = fct_drop(county))

label(radon_mn$radon)<- "Radon"
label(radon_mn$log.radon) <- "Log Radon"
label(radon_mn$first_floor) <- "First floor" 
label(radon_mn$county_index)<- "County index"
label(radon_mn$fullfips)<- "full fips"
label(radon_mn$u)<- "U"
caption = "Table 1"

radon_mn$first_floor <- factor(radon_mn$first_floor,
                               levels = c(0, 1),
                               labels = c("Basement", "First floor"))



table1(~ radon + log.radon + first_floor + county_index + fullfips + u  | county, overall=F, caption = caption, data = radon_mn)
## Warning in .table1.internal(x = x, labels = labels, groupspan = groupspan, :
## Table has 85 columns. Are you sure this is what you want?
Table 1
AITKIN
(N=4)
ANOKA
(N=52)
BECKER
(N=3)
BELTRAMI
(N=7)
BENTON
(N=4)
BIG STONE
(N=3)
BLUE EARTH
(N=14)
BROWN
(N=4)
CARLTON
(N=10)
CARVER
(N=6)
CASS
(N=5)
CHIPPEWA
(N=4)
CHISAGO
(N=6)
CLAY
(N=14)
CLEARWATER
(N=4)
COOK
(N=2)
COTTONWOOD
(N=4)
CROW WING
(N=12)
DAKOTA
(N=63)
DODGE
(N=3)
DOUGLAS
(N=9)
FARIBAULT
(N=6)
FILLMORE
(N=2)
FREEBORN
(N=9)
GOODHUE
(N=14)
HENNEPIN
(N=105)
HOUSTON
(N=6)
HUBBARD
(N=5)
ISANTI
(N=3)
ITASCA
(N=11)
JACKSON
(N=5)
KANABEC
(N=4)
KANDIYOHI
(N=4)
KITTSON
(N=3)
KOOCHICHING
(N=7)
LAC QUI PARLE
(N=2)
LAKE
(N=9)
LAKE OF THE WOODS
(N=4)
LE SUEUR
(N=5)
LINCOLN
(N=4)
LYON
(N=8)
MAHNOMEN
(N=1)
MARSHALL
(N=9)
MARTIN
(N=7)
MCLEOD
(N=13)
MEEKER
(N=5)
MILLE LACS
(N=2)
MORRISON
(N=9)
MOWER
(N=13)
MURRAY
(N=1)
NICOLLET
(N=4)
NOBLES
(N=3)
NORMAN
(N=3)
OLMSTED
(N=23)
OTTER TAIL
(N=8)
PENNINGTON
(N=3)
PINE
(N=6)
PIPESTONE
(N=4)
POLK
(N=4)
POPE
(N=2)
RAMSEY
(N=32)
REDWOOD
(N=5)
RENVILLE
(N=3)
RICE
(N=11)
ROCK
(N=2)
ROSEAU
(N=14)
SCOTT
(N=13)
SHERBURNE
(N=8)
SIBLEY
(N=4)
ST LOUIS
(N=116)
STEARNS
(N=25)
STEELE
(N=10)
STEVENS
(N=2)
SWIFT
(N=4)
TODD
(N=3)
TRAVERSE
(N=4)
WABASHA
(N=7)
WADENA
(N=5)
WASECA
(N=4)
WASHINGTON
(N=46)
WATONWAN
(N=3)
WILKIN
(N=1)
WINONA
(N=13)
WRIGHT
(N=13)
YELLOW MEDICINE
(N=2)
Radon
Mean (SD) 2.08 (0.789) 2.96 (2.03) 3.33 (1.85) 4.03 (2.05) 3.78 (1.89) 4.93 (2.30) 7.65 (3.71) 5.83 (3.34) 2.95 (1.55) 7.25 (6.07) 4.46 (2.04) 7.13 (3.94) 3.68 (2.70) 8.89 (7.53) 3.13 (1.62) 2.05 (0.919) 5.10 (4.89) 3.10 (1.88) 4.71 (3.55) 6.10 (0.964) 5.50 (1.74) 2.75 (1.89) 2.85 (0.495) 9.54 (9.31) 8.75 (10.5) 4.58 (3.52) 5.25 (2.84) 2.68 (1.55) 2.93 (0.702) 3.02 (2.30) 8.94 (5.25) 4.03 (2.71) 8.60 (3.87) 4.10 (3.02) 1.60 (0.640) 13.7 (3.32) 1.94 (2.05) 5.15 (3.35) 5.68 (3.84) 9.88 (5.87) 6.86 (2.48) 3.90 (NA) 9.88 (16.2) 4.29 (3.58) 5.79 (6.96) 3.74 (2.06) 3.10 (3.68) 3.10 (1.12) 7.09 (6.23) 12.1 (NA) 9.70 (4.83) 7.10 (2.29) 3.77 (3.75) 4.33 (3.04) 5.21 (4.48) 3.27 (2.78) 2.12 (1.14) 6.88 (4.73) 5.10 (3.83) 3.60 (0.283) 3.64 (2.29) 8.54 (7.35) 4.63 (2.20) 6.94 (4.55) 5.00 (4.81) 4.33 (3.06) 7.51 (7.46) 3.16 (1.19) 3.83 (1.61) 3.07 (3.70) 4.93 (3.23) 5.61 (2.95) 6.25 (2.47) 2.93 (1.39) 4.97 (2.51) 8.23 (7.55) 6.94 (3.75) 3.26 (1.67) 3.08 (4.18) 4.73 (3.96) 9.90 (4.06) 9.30 (NA) 6.12 (4.13) 5.80 (3.75) 3.30 (0.566)
Median [Min, Max] 2.20 [1.00, 2.90] 2.25 [0.200, 8.10] 4.30 [1.20, 4.50] 4.60 [0.400, 6.30] 2.90 [2.70, 6.60] 5.00 [2.60, 7.20] 6.85 [1.80, 14.3] 5.35 [2.50, 10.1] 2.80 [0.800, 5.60] 7.15 [0, 14.7] 4.00 [1.90, 7.40] 8.55 [1.40, 10.0] 3.25 [0.800, 8.10] 7.85 [0.900, 26.6] 3.40 [0.900, 4.80] 2.05 [1.40, 2.70] 4.65 [0, 11.1] 2.70 [0.900, 6.70] 4.30 [0.500, 21.2] 5.70 [5.40, 7.20] 5.50 [2.70, 7.80] 2.85 [0.100, 5.20] 2.85 [2.50, 3.20] 6.30 [2.20, 32.6] 5.25 [2.60, 43.5] 3.90 [0.400, 23.6] 4.20 [2.20, 9.00] 2.80 [0.800, 4.60] 3.00 [2.20, 3.60] 2.50 [1.10, 9.40] 8.40 [2.90, 15.3] 3.20 [1.80, 7.90] 9.00 [4.10, 12.3] 4.50 [0.900, 6.90] 1.40 [1.00, 2.80] 13.7 [11.3, 16.0] 1.30 [0.500, 7.10] 3.80 [2.90, 10.1] 4.20 [3.30, 12.5] 9.25 [3.50, 17.5] 6.15 [4.60, 12.0] 3.90 [3.90, 3.90] 1.50 [0.900, 48.2] 4.10 [0.500, 9.20] 2.80 [0, 25.4] 3.20 [2.10, 7.20] 3.10 [0.500, 5.70] 3.00 [1.40, 4.90] 6.40 [1.10, 24.0] 12.1 [12.1, 12.1] 9.45 [4.20, 15.7] 6.20 [5.40, 9.70] 1.60 [1.60, 8.10] 3.20 [0.600, 11.2] 3.50 [1.10, 12.6] 3.70 [0.300, 5.80] 1.70 [1.20, 4.10] 6.85 [1.70, 12.1] 4.70 [1.40, 9.60] 3.60 [3.40, 3.80] 3.30 [0.700, 10.1] 7.40 [1.90, 20.7] 5.80 [2.10, 6.00] 5.60 [2.40, 19.0] 5.00 [1.60, 8.40] 3.60 [1.10, 11.4] 4.30 [1.20, 25.2] 2.95 [1.60, 5.10] 4.40 [1.50, 5.00] 2.00 [0.200, 32.2] 5.00 [1.00, 14.5] 4.75 [1.50, 10.6] 6.25 [4.50, 8.00] 2.70 [1.50, 4.80] 6.00 [2.10, 6.80] 5.35 [2.90, 19.3] 8.40 [1.10, 11.5] 3.20 [0.700, 4.80] 1.30 [0.400, 9.30] 3.75 [0.800, 20.4] 10.2 [5.70, 13.8] 9.30 [9.30, 9.30] 4.70 [0.500, 11.8] 5.10 [2.10, 15.9] 3.30 [2.90, 3.70]
Log Radon
Mean (SD) 0.660 (0.459) 0.833 (0.770) 1.05 (0.750) 1.14 (0.968) 1.25 (0.424) 1.51 (0.516) 1.91 (0.553) 1.63 (0.608) 0.931 (0.615) 1.20 (1.90) 1.40 (0.504) 1.73 (0.936) 1.04 (0.845) 1.78 (1.01) 0.978 (0.740) 0.665 (0.464) 0.734 (2.12) 0.941 (0.669) 1.29 (0.752) 1.80 (0.153) 1.65 (0.351) 0.517 (1.47) 1.04 (0.175) 1.94 (0.807) 1.85 (0.711) 1.29 (0.710) 1.53 (0.552) 0.809 (0.714) 1.06 (0.249) 0.926 (0.584) 2.02 (0.689) 1.24 (0.632) 2.06 (0.510) 1.11 (1.07) 0.407 (0.375) 2.60 (0.246) 0.322 (0.826) 1.51 (0.561) 1.60 (0.528) 2.14 (0.674) 1.88 (0.323) 1.36 (NA) 1.20 (1.50) 0.938 (1.26) 1.07 (1.40) 1.21 (0.492) 0.524 (1.72) 1.07 (0.389) 1.59 (0.940) 2.49 (NA) 2.17 (0.557) 1.93 (0.306) 1.01 (0.936) 1.21 (0.761) 1.35 (0.828) 0.621 (1.60) 0.642 (0.494) 1.68 (0.884) 1.36 (0.891) 1.28 (0.0786) 1.09 (0.668) 1.84 (0.902) 1.43 (0.597) 1.78 (0.565) 1.30 (1.17) 1.25 (0.681) 1.58 (0.972) 1.09 (0.376) 1.24 (0.566) 0.768 (0.800) 1.38 (0.702) 1.58 (0.599) 1.79 (0.407) 0.987 (0.484) 1.48 (0.645) 1.83 (0.830) 1.72 (0.837) 0.997 (0.790) 0.435 (1.34) 1.25 (0.797) 2.23 (0.449) 2.23 (NA) 1.46 (1.04) 1.59 (0.599) 1.19 (0.172)
Median [Min, Max] 0.788 [0, 1.06] 0.811 [-1.61, 2.09] 1.46 [0.182, 1.50] 1.53 [-0.916, 1.84] 1.06 [0.993, 1.89] 1.61 [0.956, 1.97] 1.92 [0.588, 2.66] 1.64 [0.916, 2.31] 1.01 [-0.223, 1.72] 1.90 [-2.30, 2.69] 1.39 [0.642, 2.00] 2.14 [0.336, 2.30] 1.11 [-0.223, 2.09] 2.05 [-0.105, 3.28] 1.22 [-0.105, 1.57] 0.665 [0.336, 0.993] 1.42 [-2.30, 2.41] 0.991 [-0.105, 1.90] 1.46 [-0.693, 3.05] 1.74 [1.69, 1.97] 1.70 [0.993, 2.05] 1.03 [-2.30, 1.65] 1.04 [0.916, 1.16] 1.84 [0.788, 3.48] 1.66 [0.956, 3.77] 1.36 [-0.916, 3.16] 1.42 [0.788, 2.20] 1.03 [-0.223, 1.53] 1.10 [0.788, 1.28] 0.916 [0.0953, 2.24] 2.13 [1.06, 2.73] 1.15 [0.588, 2.07] 2.16 [1.41, 2.51] 1.50 [-0.105, 1.93] 0.336 [0, 1.03] 2.60 [2.42, 2.77] 0.262 [-0.693, 1.96] 1.33 [1.06, 2.31] 1.44 [1.19, 2.53] 2.21 [1.25, 2.86] 1.81 [1.53, 2.48] 1.36 [1.36, 1.36] 0.405 [-0.105, 3.88] 1.41 [-0.693, 2.22] 1.03 [-2.30, 3.23] 1.16 [0.742, 1.97] 0.524 [-0.693, 1.74] 1.10 [0.336, 1.59] 1.86 [0.0953, 3.18] 2.49 [2.49, 2.49] 2.24 [1.44, 2.75] 1.82 [1.69, 2.27] 0.470 [0.470, 2.09] 1.16 [-0.511, 2.42] 1.25 [0.0953, 2.53] 1.31 [-1.20, 1.76] 0.524 [0.182, 1.41] 1.85 [0.531, 2.49] 1.42 [0.336, 2.26] 1.28 [1.22, 1.34] 1.19 [-0.357, 2.31] 2.00 [0.642, 3.03] 1.76 [0.742, 1.79] 1.72 [0.875, 2.94] 1.30 [0.470, 2.13] 1.28 [0.0953, 2.43] 1.46 [0.182, 3.23] 1.08 [0.470, 1.63] 1.48 [0.405, 1.61] 0.693 [-1.61, 3.47] 1.61 [0, 2.67] 1.56 [0.405, 2.36] 1.79 [1.50, 2.08] 0.987 [0.405, 1.57] 1.79 [0.742, 1.92] 1.64 [1.06, 2.96] 2.13 [0.0953, 2.44] 1.16 [-0.357, 1.57] 0.213 [-0.916, 2.23] 1.32 [-0.223, 3.02] 2.32 [1.74, 2.62] 2.23 [2.23, 2.23] 1.55 [-0.693, 2.47] 1.63 [0.742, 2.77] 1.19 [1.06, 1.31]
first_floor
Basement 3 (75.0%) 49 (94.2%) 1 (33.3%) 3 (42.9%) 3 (75.0%) 3 (100%) 12 (85.7%) 2 (50.0%) 9 (90.0%) 3 (50.0%) 5 (100%) 4 (100%) 6 (100%) 10 (71.4%) 2 (50.0%) 2 (100%) 1 (25.0%) 9 (75.0%) 59 (93.7%) 3 (100%) 8 (88.9%) 5 (83.3%) 1 (50.0%) 7 (77.8%) 12 (85.7%) 94 (89.5%) 4 (66.7%) 2 (40.0%) 3 (100%) 11 (100%) 5 (100%) 4 (100%) 4 (100%) 1 (33.3%) 3 (42.9%) 1 (50.0%) 8 (88.9%) 2 (50.0%) 4 (80.0%) 3 (75.0%) 7 (87.5%) 1 (100%) 4 (44.4%) 6 (85.7%) 9 (69.2%) 5 (100%) 1 (50.0%) 8 (88.9%) 11 (84.6%) 1 (100%) 4 (100%) 3 (100%) 2 (66.7%) 20 (87.0%) 5 (62.5%) 1 (33.3%) 5 (83.3%) 3 (75.0%) 2 (50.0%) 2 (100%) 29 (90.6%) 4 (80.0%) 2 (66.7%) 10 (90.9%) 2 (100%) 6 (42.9%) 9 (69.2%) 8 (100%) 4 (100%) 100 (86.2%) 21 (84.0%) 10 (100%) 2 (100%) 4 (100%) 2 (66.7%) 3 (75.0%) 6 (85.7%) 3 (60.0%) 3 (75.0%) 41 (89.1%) 1 (33.3%) 1 (100%) 10 (76.9%) 12 (92.3%) 2 (100%)
First floor 1 (25.0%) 3 (5.8%) 2 (66.7%) 4 (57.1%) 1 (25.0%) 0 (0%) 2 (14.3%) 2 (50.0%) 1 (10.0%) 3 (50.0%) 0 (0%) 0 (0%) 0 (0%) 4 (28.6%) 2 (50.0%) 0 (0%) 3 (75.0%) 3 (25.0%) 4 (6.3%) 0 (0%) 1 (11.1%) 1 (16.7%) 1 (50.0%) 2 (22.2%) 2 (14.3%) 11 (10.5%) 2 (33.3%) 3 (60.0%) 0 (0%) 0 (0%) 0 (0%) 0 (0%) 0 (0%) 2 (66.7%) 4 (57.1%) 1 (50.0%) 1 (11.1%) 2 (50.0%) 1 (20.0%) 1 (25.0%) 1 (12.5%) 0 (0%) 5 (55.6%) 1 (14.3%) 4 (30.8%) 0 (0%) 1 (50.0%) 1 (11.1%) 2 (15.4%) 0 (0%) 0 (0%) 0 (0%) 1 (33.3%) 3 (13.0%) 3 (37.5%) 2 (66.7%) 1 (16.7%) 1 (25.0%) 2 (50.0%) 0 (0%) 3 (9.4%) 1 (20.0%) 1 (33.3%) 1 (9.1%) 0 (0%) 8 (57.1%) 4 (30.8%) 0 (0%) 0 (0%) 16 (13.8%) 4 (16.0%) 0 (0%) 0 (0%) 0 (0%) 1 (33.3%) 1 (25.0%) 1 (14.3%) 2 (40.0%) 1 (25.0%) 5 (10.9%) 2 (66.7%) 0 (0%) 3 (23.1%) 1 (7.7%) 0 (0%)
County index
Mean (SD) 4.00 (0) 8.00 (0) 22.0 (0) 24.0 (0) 26.0 (0) 29.0 (0) 33.0 (0) 41.0 (0) 54.0 (0) 57.0 (0) 58.0 (0) 64.0 (0) 65.0 (0) 69.0 (0) 71.0 (0) 77.0 (0) 79.0 (0) 81.0 (0) 84.0 (0) 95.0 (0) 96.0 (0) 107 (0) 109 (0) 117 (0) 124 (0) 141 (0) 146 (0) 149 (0) 154 (0) 155 (0) 156 (0) 163 (0) 164 (0) 167 (0) 169 (0) 176 (0) 182 (0) 183 (0) 186 (0) 191 (0) 198 (0) 201 (NA) 205 (0) 206 (0) 213 (0) 214 (0) 220 (0) 230 (0) 233 (0) 234 (NA) 239 (0) 241 (0) 244 (0) 249 (0) 254 (0) 260 (0) 269 (0) 270 (0) 273 (0) 274 (0) 282 (0) 288 (0) 289 (0) 291 (0) 294 (0) 296 (0) 306 (0) 310 (0) 312 (0) 323 (0) 329 (0) 330 (0) 332 (0) 340 (0) 347 (0) 350 (0) 359 (0) 360 (0) 365 (0) 366 (0) 367 (0) 375 (NA) 377 (0) 381 (0) 384 (0)
Median [Min, Max] 4.00 [4.00, 4.00] 8.00 [8.00, 8.00] 22.0 [22.0, 22.0] 24.0 [24.0, 24.0] 26.0 [26.0, 26.0] 29.0 [29.0, 29.0] 33.0 [33.0, 33.0] 41.0 [41.0, 41.0] 54.0 [54.0, 54.0] 57.0 [57.0, 57.0] 58.0 [58.0, 58.0] 64.0 [64.0, 64.0] 65.0 [65.0, 65.0] 69.0 [69.0, 69.0] 71.0 [71.0, 71.0] 77.0 [77.0, 77.0] 79.0 [79.0, 79.0] 81.0 [81.0, 81.0] 84.0 [84.0, 84.0] 95.0 [95.0, 95.0] 96.0 [96.0, 96.0] 107 [107, 107] 109 [109, 109] 117 [117, 117] 124 [124, 124] 141 [141, 141] 146 [146, 146] 149 [149, 149] 154 [154, 154] 155 [155, 155] 156 [156, 156] 163 [163, 163] 164 [164, 164] 167 [167, 167] 169 [169, 169] 176 [176, 176] 182 [182, 182] 183 [183, 183] 186 [186, 186] 191 [191, 191] 198 [198, 198] 201 [201, 201] 205 [205, 205] 206 [206, 206] 213 [213, 213] 214 [214, 214] 220 [220, 220] 230 [230, 230] 233 [233, 233] 234 [234, 234] 239 [239, 239] 241 [241, 241] 244 [244, 244] 249 [249, 249] 254 [254, 254] 260 [260, 260] 269 [269, 269] 270 [270, 270] 273 [273, 273] 274 [274, 274] 282 [282, 282] 288 [288, 288] 289 [289, 289] 291 [291, 291] 294 [294, 294] 296 [296, 296] 306 [306, 306] 310 [310, 310] 312 [312, 312] 323 [323, 323] 329 [329, 329] 330 [330, 330] 332 [332, 332] 340 [340, 340] 347 [347, 347] 350 [350, 350] 359 [359, 359] 360 [360, 360] 365 [365, 365] 366 [366, 366] 367 [367, 367] 375 [375, 375] 377 [377, 377] 381 [381, 381] 384 [384, 384]
full fips
Mean (SD) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27000 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (NA) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (NA) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27100 (0) 27200 (0) 27200 (0) 27200 (0) 27200 (0) 27200 (0) 27200 (0) 27200 (0) 27200 (0) 27200 (NA) 27200 (0) 27200 (0) 27200 (0)
Median [Min, Max] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27000 [27000, 27000] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27100 [27100, 27100] 27200 [27200, 27200] 27200 [27200, 27200] 27200 [27200, 27200] 27200 [27200, 27200] 27200 [27200, 27200] 27200 [27200, 27200] 27200 [27200, 27200] 27200 [27200, 27200] 27200 [27200, 27200] 27200 [27200, 27200] 27200 [27200, 27200] 27200 [27200, 27200]
U
Mean (SD) -0.689 (0) -0.847 (0) -0.113 (0) -0.593 (0) -0.143 (0) 0.387 (0) 0.272 (0) 0.278 (0) -0.332 (0) 0.0959 (0) -0.608 (0) 0.274 (0) -0.735 (0) 0.344 (0) -0.0599 (0) -0.505 (0) 0.340 (0) -0.633 (0) -0.0241 (0) 0.264 (0) 0.156 (0) 0.295 (0) 0.415 (0) 0.224 (0) 0.197 (0) -0.0965 (0) 0.504 (0) -0.401 (0) -0.752 (0) -0.663 (0) 0.309 (0) -0.0534 (0) 0.110 (0) -0.00780 (0) -0.882 (0) 0.311 (0) -0.692 (0) -0.682 (0) 0.194 (0) 0.445 (0) 0.395 (0) 0.150 (NA) 0.0138 (0) 0.166 (0) 0.140 (0) 0.0240 (0) -0.210 (0) -0.0932 (0) 0.261 (0) 0.399 (NA) 0.248 (0) 0.405 (0) 0.265 (0) 0.243 (0) -0.205 (0) -0.0740 (0) -0.163 (0) 0.479 (0) 0.266 (0) 0.281 (0) -0.418 (0) 0.366 (0) 0.381 (0) 0.193 (0) 0.528 (0) -0.212 (0) 0.0631 (0) -0.683 (0) 0.237 (0) -0.475 (0) 0.116 (0) 0.270 (0) 0.471 (0) 0.316 (0) -0.0468 (0) 0.498 (0) 0.150 (0) -0.672 (0) 0.212 (0) -0.147 (0) 0.183 (0) 0.236 (NA) 0.463 (0) -0.0900 (0) 0.355 (0)
Median [Min, Max] -0.689 [-0.689, -0.689] -0.847 [-0.847, -0.847] -0.113 [-0.113, -0.113] -0.593 [-0.593, -0.593] -0.143 [-0.143, -0.143] 0.387 [0.387, 0.387] 0.272 [0.272, 0.272] 0.278 [0.278, 0.278] -0.332 [-0.332, -0.332] 0.0959 [0.0959, 0.0959] -0.608 [-0.608, -0.608] 0.274 [0.274, 0.274] -0.735 [-0.735, -0.735] 0.344 [0.344, 0.344] -0.0599 [-0.0599, -0.0599] -0.505 [-0.505, -0.505] 0.340 [0.340, 0.340] -0.633 [-0.633, -0.633] -0.0241 [-0.0241, -0.0241] 0.264 [0.264, 0.264] 0.156 [0.156, 0.156] 0.295 [0.295, 0.295] 0.415 [0.415, 0.415] 0.224 [0.224, 0.224] 0.197 [0.197, 0.197] -0.0965 [-0.0965, -0.0965] 0.504 [0.504, 0.504] -0.401 [-0.401, -0.401] -0.752 [-0.752, -0.752] -0.663 [-0.663, -0.663] 0.309 [0.309, 0.309] -0.0534 [-0.0534, -0.0534] 0.110 [0.110, 0.110] -0.00780 [-0.00780, -0.00780] -0.882 [-0.882, -0.882] 0.311 [0.311, 0.311] -0.692 [-0.692, -0.692] -0.682 [-0.682, -0.682] 0.194 [0.194, 0.194] 0.445 [0.445, 0.445] 0.395 [0.395, 0.395] 0.150 [0.150, 0.150] 0.0138 [0.0138, 0.0138] 0.166 [0.166, 0.166] 0.140 [0.140, 0.140] 0.0240 [0.0240, 0.0240] -0.210 [-0.210, -0.210] -0.0932 [-0.0932, -0.0932] 0.261 [0.261, 0.261] 0.399 [0.399, 0.399] 0.248 [0.248, 0.248] 0.405 [0.405, 0.405] 0.265 [0.265, 0.265] 0.243 [0.243, 0.243] -0.205 [-0.205, -0.205] -0.0740 [-0.0740, -0.0740] -0.163 [-0.163, -0.163] 0.479 [0.479, 0.479] 0.266 [0.266, 0.266] 0.281 [0.281, 0.281] -0.418 [-0.418, -0.418] 0.366 [0.366, 0.366] 0.381 [0.381, 0.381] 0.193 [0.193, 0.193] 0.528 [0.528, 0.528] -0.212 [-0.212, -0.212] 0.0631 [0.0631, 0.0631] -0.683 [-0.683, -0.683] 0.237 [0.237, 0.237] -0.475 [-0.475, -0.475] 0.116 [0.116, 0.116] 0.270 [0.270, 0.270] 0.471 [0.471, 0.471] 0.316 [0.316, 0.316] -0.0468 [-0.0468, -0.0468] 0.498 [0.498, 0.498] 0.150 [0.150, 0.150] -0.672 [-0.672, -0.672] 0.212 [0.212, 0.212] -0.147 [-0.147, -0.147] 0.183 [0.183, 0.183] 0.236 [0.236, 0.236] 0.463 [0.463, 0.463] -0.0900 [-0.0900, -0.0900] 0.355 [0.355, 0.355]
radon_mn |>
  ggpairs(c("radon", "log.radon", "first_floor", "county_index", "fullfips", "u"), 
          mapping = ggplot2::aes(color = "county"), 
          title = "County", 
          columnLabels = c("Radon", "log radon", "First floor", "County index", "fullfips", "u"),
          proportions = "auto", legend = c(2,2))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Exercise 4

Replicate the figures below and explain why the counties with fewer measurements have more variable estimates and larger higher standard errors. What is the main advantage and disadvantage of no-pooling analysis, as illustrated in the plot on the left compared with the multilevel model? Explain.

radon_mn_count <- radon_mn |>
  count(county, name = "n.obs")

# No pooling
no_pooling <- lm(log.radon ~ 0 + county, data = radon_mn)
summary(no_pooling)
## 
## Call:
## lm(formula = log.radon ~ 0 + county, data = radon_mn)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.5062 -0.4440  0.0306  0.4864  2.7037 
## 
## Coefficients:
##                         Estimate Std. Error t value Pr(>|t|)    
## countyAITKIN             0.66041    0.39918   1.654 0.098420 .  
## countyANOKA              0.83325    0.11071   7.526 1.35e-13 ***
## countyBECKER             1.04834    0.46093   2.274 0.023196 *  
## countyBELTRAMI           1.14099    0.30175   3.781 0.000167 ***
## countyBENTON             1.25244    0.39918   3.138 0.001764 ** 
## countyBIG STONE          1.51301    0.46093   3.283 0.001072 ** 
## countyBLUE EARTH         1.90923    0.21337   8.948  < 2e-16 ***
## countyBROWN              1.62931    0.39918   4.082 4.90e-05 ***
## countyCARLTON            0.93098    0.25246   3.688 0.000241 ***
## countyCARVER             1.20364    0.32593   3.693 0.000236 ***
## countyCASS               1.40113    0.35704   3.924 9.41e-05 ***
## countyCHIPPEWA           1.73025    0.39918   4.335 1.64e-05 ***
## countyCHISAGO            1.03872    0.32593   3.187 0.001491 ** 
## countyCLAY               1.78252    0.21337   8.354 2.74e-16 ***
## countyCLEARWATER         0.97770    0.39918   2.449 0.014519 *  
## countyCOOK               0.66486    0.56452   1.178 0.239237    
## countyCOTTONWOOD         0.73439    0.39918   1.840 0.066159 .  
## countyCROW WING          0.94141    0.23047   4.085 4.84e-05 ***
## countyDAKOTA             1.29256    0.10058  12.851  < 2e-16 ***
## countyDODGE              1.80032    0.46093   3.906 0.000102 ***
## countyDOUGLAS            1.65393    0.26612   6.215 8.10e-10 ***
## countyFARIBAULT          0.51670    0.32593   1.585 0.113272    
## countyFILLMORE           1.03972    0.56452   1.842 0.065865 .  
## countyFREEBORN           1.94150    0.26612   7.296 6.92e-13 ***
## countyGOODHUE            1.84779    0.21337   8.660  < 2e-16 ***
## countyHENNEPIN           1.28510    0.07791  16.494  < 2e-16 ***
## countyHOUSTON            1.53318    0.32593   4.704 2.98e-06 ***
## countyHUBBARD            0.80927    0.35704   2.267 0.023669 *  
## countyISANTI             1.05600    0.46093   2.291 0.022211 *  
## countyITASCA             0.92576    0.24071   3.846 0.000129 ***
## countyJACKSON            2.02057    0.35704   5.659 2.09e-08 ***
## countyKANABEC            1.23629    0.39918   3.097 0.002020 ** 
## countyKANDIYOHI          2.06187    0.39918   5.165 3.00e-07 ***
## countyKITTSON            1.11008    0.46093   2.408 0.016241 *  
## countyKOOCHICHING        0.40746    0.30175   1.350 0.177278    
## countyLAC QUI PARLE      2.59870    0.56452   4.603 4.81e-06 ***
## countyLAKE               0.32203    0.26612   1.210 0.226587    
## countyLAKE OF THE WOODS  1.50745    0.39918   3.776 0.000170 ***
## countyLE SUEUR           1.60396    0.35704   4.492 8.03e-06 ***
## countyLINCOLN            2.13567    0.39918   5.350 1.14e-07 ***
## countyLYON               1.87708    0.28226   6.650 5.29e-11 ***
## countyMAHNOMEN           1.36098    0.79836   1.705 0.088619 .  
## countyMARSHALL           1.20194    0.26612   4.517 7.19e-06 ***
## countyMARTIN             0.93805    0.30175   3.109 0.001943 ** 
## countyMCLEOD             1.07371    0.22142   4.849 1.48e-06 ***
## countyMEEKER             1.21461    0.35704   3.402 0.000701 ***
## countyMILLE LACS         0.52366    0.56452   0.928 0.353877    
## countyMORRISON           1.06806    0.26612   4.013 6.52e-05 ***
## countyMOWER              1.59126    0.22142   7.186 1.48e-12 ***
## countyMURRAY             2.49321    0.79836   3.123 0.001853 ** 
## countyNICOLLET           2.16504    0.39918   5.424 7.65e-08 ***
## countyNOBLES             1.92769    0.46093   4.182 3.19e-05 ***
## countyNORMAN             1.01062    0.46093   2.193 0.028614 *  
## countyOLMSTED            1.21277    0.16647   7.285 7.44e-13 ***
## countyOTTER TAIL         1.34779    0.28226   4.775 2.12e-06 ***
## countyPENNINGTON         0.62074    0.46093   1.347 0.178441    
## countyPINE               0.64209    0.32593   1.970 0.049163 *  
## countyPIPESTONE          1.68079    0.39918   4.211 2.82e-05 ***
## countyPOLK               1.36151    0.39918   3.411 0.000679 ***
## countyPOPE               1.27939    0.56452   2.266 0.023688 *  
## countyRAMSEY             1.09118    0.14113   7.732 3.05e-14 ***
## countyREDWOOD            1.83890    0.35704   5.150 3.24e-07 ***
## countyRENVILLE           1.43052    0.46093   3.104 0.001977 ** 
## countyRICE               1.78233    0.24071   7.404 3.23e-13 ***
## countyROCK               1.29912    0.56452   2.301 0.021623 *  
## countyROSEAU             1.25400    0.21337   5.877 6.03e-09 ***
## countySCOTT              1.58142    0.22142   7.142 2.00e-12 ***
## countySHERBURNE          1.09002    0.28226   3.862 0.000121 ***
## countySIBLEY             1.24245    0.39918   3.113 0.001918 ** 
## countyST LOUIS           0.76825    0.07413  10.364  < 2e-16 ***
## countySTEARNS            1.37656    0.15967   8.621  < 2e-16 ***
## countySTEELE             1.57990    0.25246   6.258 6.23e-10 ***
## countySTEVENS            1.79176    0.56452   3.174 0.001559 ** 
## countySWIFT              0.98704    0.39918   2.473 0.013609 *  
## countyTODD               1.48354    0.46093   3.219 0.001338 ** 
## countyTRAVERSE           1.82830    0.39918   4.580 5.35e-06 ***
## countyWABASHA            1.71875    0.30175   5.696 1.70e-08 ***
## countyWADENA             0.99747    0.35704   2.794 0.005329 ** 
## countyWASECA             0.43475    0.39918   1.089 0.276422    
## countyWASHINGTON         1.25120    0.11771  10.629  < 2e-16 ***
## countyWATONWAN           2.22917    0.46093   4.836 1.58e-06 ***
## countyWILKIN             2.23001    0.79836   2.793 0.005338 ** 
## countyWINONA             1.45664    0.22142   6.579 8.38e-11 ***
## countyWRIGHT             1.58993    0.22142   7.180 1.54e-12 ***
## countyYELLOW MEDICINE    1.18652    0.56452   2.102 0.035869 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7984 on 834 degrees of freedom
## Multiple R-squared:  0.7403, Adjusted R-squared:  0.7138 
## F-statistic: 27.97 on 85 and 834 DF,  p-value: < 2.2e-16
# Multilevel
multilevel_model <- lmer(log.radon ~ 1 + (1 | county), data = radon_mn)
summary(multilevel_model)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: log.radon ~ 1 + (1 | county)
##    Data: radon_mn
## 
## REML criterion at convergence: 2259.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.4661 -0.5734  0.0441  0.6432  3.3516 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  county   (Intercept) 0.09581  0.3095  
##  Residual             0.63662  0.7979  
## Number of obs: 919, groups:  county, 85
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)  1.31258    0.04891 71.48752   26.84   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Use here the two models - first the fixed effects (no pooling)
# model, and then the multilevel (partial pooling) model.
no_pooling |> 
  predictions(newdata = datagrid(county = unique))|>
  as_tibble() |> inner_join(radon_mn_count, by = "county") |>
  select(county, estimate, conf.low, conf.high, n.obs) |> 
  ggplot(
    aes(
      x    = county, 
      y    = estimate, 
      ymin = conf.low, 
      ymax = conf.high,
      )
    ) +
  geom_pointrange(
    position = position_jitter(width = .5, height = 0)
    ) +
  labs(
    title = "No pooling (fixed effects)",
    x     = "Number of observations",
    y     = "Estimated Log Radon Level in the county"
  )

multilevel_model |> 
  predictions(newdata = datagrid(county = unique)) |> 
  as_tibble() |> inner_join(radon_mn_count, by = "county") |> 
  select(county, estimate, conf.low, conf.high, n.obs) |> 
  ggplot(
    aes(
      x    = county, 
      y    = estimate, 
      ymin = conf.low, 
      ymax = conf.high,
      )
    ) + 
  geom_pointrange(
    position = position_jitter(width = .5, height = 0)
    ) +
  labs(
    title = "No pooling (fixed effects)",
    x     = "Number of observations",
    y     = "Estimated Log Radon Level in the county"
  )

Smaller sample sizes result in increased uncertainty in estimating county-level effects, leading to larger standard errors. Furthermore, the estimates of counties with smaller a smaller sample size are more sensitive to random fluctuations in the observed data. Small changes can lead to more significant variations in the estimated effect. In the no pooling analysis the absence of shared information across counties amplifies the impact of limited data, leading to more variable estimates and larger standard of errors for counties with fewer measurements. In contrast to multilevel models, where information is shared among counties, providing more stable estimates even for those with limited data. Advantage for no-pooling analysis allows individualized estimates for each county, capturing local variability.

Exercise 5

In this exercise, you will replicate a set of models as shown below. This illustration is based on the ideas shown in figure 12.4 in the book. Please replicate this illustration with a twist: for example, you may choose a different set of counties than the one shown below or the one shown in the book, or you may try something different. Please explain the graphs. What do the dashed red and black lines show? What is the blue line? What determines whether the blue line would be more similar to the red line or the black line? How is this figure compare to the one shown in chapter 12 of the book?

# Fit the model (you will need to fit all three models)
complete_pooling <- lm(log.radon ~ first_floor, data = radon_mn)
summary(complete_pooling)
## 
## Call:
## lm(formula = log.radon ~ first_floor, data = radon_mn)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.6293 -0.5383  0.0342  0.5603  2.5486 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             1.32674    0.02972  44.640   <2e-16 ***
## first_floorFirst floor -0.61339    0.07284  -8.421   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8226 on 917 degrees of freedom
## Multiple R-squared:  0.07178,    Adjusted R-squared:  0.07077 
## F-statistic: 70.91 on 1 and 917 DF,  p-value: < 2.2e-16
no_pooling <- lm(log.radon ~ first_floor + county, data = radon_mn)
summary(no_pooling)
## 
## Call:
## lm(formula = log.radon ~ first_floor + county, data = radon_mn)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -3.14595 -0.45405  0.00065  0.45376  2.65987 
## 
## Coefficients:
##                         Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              0.84054    0.37866   2.220  0.02670 *  
## first_floorFirst floor  -0.72054    0.07352  -9.800  < 2e-16 ***
## countyANOKA              0.03428    0.39274   0.087  0.93047    
## countyBECKER             0.68816    0.57854   1.189  0.23459    
## countyBELTRAMI           0.71218    0.47470   1.500  0.13392    
## countyBENTON             0.59203    0.53487   1.107  0.26867    
## countyBIG STONE          0.67247    0.57802   1.163  0.24500    
## countyBLUE EARTH         1.17162    0.42892   2.732  0.00644 ** 
## countyBROWN              1.14904    0.53519   2.147  0.03208 *  
## countyCARLTON            0.16250    0.44764   0.363  0.71669    
## countyCARVER             0.72336    0.48861   1.480  0.13913    
## countyCASS               0.56059    0.50775   1.104  0.26988    
## countyCHIPPEWA           0.88971    0.53519   1.662  0.09680 .  
## countyCHISAGO            0.19818    0.48861   0.406  0.68514    
## countyCLAY               1.14784    0.42886   2.677  0.00759 ** 
## countyCLEARWATER         0.49743    0.53519   0.929  0.35292    
## countyCOOK              -0.17568    0.65534  -0.268  0.78871    
## countyCOTTONWOOD         0.43426    0.53613   0.810  0.41818    
## countyCROW WING          0.28101    0.43672   0.643  0.52011    
## countyDAKOTA             0.49777    0.39027   1.275  0.20251    
## countyDODGE              0.95977    0.57802   1.660  0.09720 .  
## countyDOUGLAS            0.89345    0.45467   1.965  0.04974 *  
## countyFARIBAULT         -0.20375    0.48831  -0.417  0.67660    
## countyFILLMORE           0.55945    0.65534   0.854  0.39353    
## countyFREEBORN           1.26108    0.45456   2.774  0.00566 ** 
## countyGOODHUE            1.11018    0.42892   2.588  0.00981 ** 
## countyHENNEPIN           0.52004    0.38549   1.349  0.17770    
## countyHOUSTON            0.93282    0.48831   1.910  0.05644 .  
## countyHUBBARD            0.40105    0.50807   0.789  0.43013    
## countyISANTI             0.21546    0.57802   0.373  0.70942    
## countyITASCA             0.08522    0.44204   0.193  0.84718    
## countyJACKSON            1.18003    0.50775   2.324  0.02036 *  
## countyKANABEC            0.39575    0.53519   0.739  0.45983    
## countyKANDIYOHI          1.22133    0.53519   2.282  0.02274 *  
## countyKITTSON            0.74990    0.57854   1.296  0.19527    
## countyKOOCHICHING       -0.02134    0.47470  -0.045  0.96415    
## countyLAC QUI PARLE      2.11842    0.65534   3.233  0.00128 ** 
## countyLAKE              -0.43845    0.45467  -0.964  0.33516    
## countyLAKE OF THE WOODS  1.02717    0.53519   1.919  0.05529 .  
## countyLE SUEUR           0.90752    0.50743   1.788  0.07407 .  
## countyLINCOLN            1.47526    0.53487   2.758  0.00594 ** 
## countyLYON               1.12661    0.46330   2.432  0.01524 *  
## countyMAHNOMEN           0.52044    0.84590   0.615  0.53856    
## countyMARSHALL           0.76170    0.45511   1.674  0.09457 .  
## countyMARTIN             0.20045    0.47418   0.423  0.67261    
## countyMCLEOD             0.45487    0.43252   1.052  0.29325    
## countyMEEKER             0.37407    0.50775   0.737  0.46150    
## countyMILLE LACS         0.04339    0.65534   0.066  0.94723    
## countyMORRISON           0.30758    0.45467   0.676  0.49892    
## countyMOWER              0.86157    0.43256   1.992  0.04672 *  
## countyMURRAY             1.65266    0.84590   1.954  0.05107 .  
## countyNICOLLET           1.32450    0.53519   2.475  0.01353 *  
## countyNOBLES             1.08715    0.57802   1.881  0.06034 .  
## countyNORMAN             0.41026    0.57776   0.710  0.47784    
## countyOLMSTED            0.46621    0.40987   1.137  0.25567    
## countyOTTER TAIL         0.77745    0.46330   1.678  0.09371 .  
## countyPENNINGTON         0.26056    0.57854   0.450  0.65256    
## countyPINE              -0.07836    0.48831  -0.160  0.87255    
## countyPIPESTONE          1.02038    0.53487   1.908  0.05677 .  
## countyPOLK               0.88124    0.53519   1.647  0.10002    
## countyPOPE               0.43885    0.65534   0.670  0.50327    
## countyRAMSEY             0.31819    0.40132   0.793  0.42809    
## countyREDWOOD            1.14247    0.50743   2.251  0.02462 *  
## countyRENVILLE           0.83016    0.57776   1.437  0.15113    
## countyRICE               1.00729    0.44181   2.280  0.02286 *  
## countyROCK               0.45858    0.65534   0.700  0.48427    
## countyROSEAU             0.82520    0.42950   1.921  0.05503 .  
## countySCOTT              0.96258    0.43252   2.226  0.02631 *  
## countySHERBURNE          0.24948    0.46357   0.538  0.59060    
## countySIBLEY             0.40191    0.53519   0.751  0.45288    
## countyST LOUIS           0.02709    0.38476   0.070  0.94388    
## countySTEARNS            0.65130    0.40740   1.599  0.11027    
## countySTEELE             0.73936    0.44788   1.651  0.09916 .  
## countySTEVENS            0.95122    0.65534   1.451  0.14702    
## countySWIFT              0.14650    0.53519   0.274  0.78436    
## countyTODD               0.88318    0.57776   1.529  0.12674    
## countyTRAVERSE           1.16790    0.53487   2.184  0.02928 *  
## countyWABASHA            0.98114    0.47418   2.069  0.03884 *  
## countyWADENA             0.44515    0.50754   0.877  0.38070    
## countyWASECA            -0.22566    0.53487  -0.422  0.67321    
## countyWASHINGTON         0.48898    0.39445   1.240  0.21545    
## countyWATONWAN           1.86899    0.57854   3.231  0.00128 ** 
## countyWILKIN             1.38947    0.84590   1.643  0.10084    
## countyWINONA             0.78238    0.43250   1.809  0.07082 .  
## countyWRIGHT             0.80481    0.43269   1.860  0.06323 .  
## countyYELLOW MEDICINE    0.34598    0.65534   0.528  0.59768    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7564 on 833 degrees of freedom
## Multiple R-squared:  0.287,  Adjusted R-squared:  0.2142 
## F-statistic: 3.945 on 85 and 833 DF,  p-value: < 2.2e-16
mdl_multilevel <- lmer(log.radon ~ first_floor + (first_floor|county), data = radon_mn)
summary(mdl_multilevel)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: log.radon ~ first_floor + (first_floor | county)
##    Data: radon_mn
## 
## REML criterion at convergence: 2168.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.4044 -0.6224  0.0138  0.6123  3.5682 
## 
## Random effects:
##  Groups   Name                   Variance Std.Dev. Corr 
##  county   (Intercept)            0.1216   0.3487        
##           first_floorFirst floor 0.1181   0.3436   -0.34
##  Residual                        0.5567   0.7462        
## Number of obs: 919, groups:  county, 85
## 
## Fixed effects:
##                        Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)             1.46277    0.05387 71.66151  27.155  < 2e-16 ***
## first_floorFirst floor -0.68110    0.08758 39.44290  -7.777 1.75e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## frst_flrFrf -0.381
# Collect the predictions
# Complete pooling
pred_complete <- complete_pooling |>
  predictions(
    newdata = datagrid(
      first_floor = c("Basement", "First floor")
    )
  ) |> 
  select(first_floor, estimate, conf.low, conf.high) |> 
  as_tibble( ) 

# No pooling
pred_no <- no_pooling |>
  predictions(
    newdata = datagrid(
      first_floor = c("Basement", "First floor"),
      county = c("CLAY", "RICE", "SCOTT")
    )
  ) |> 
  select(county, first_floor, estimate, conf.low, conf.high) |> 
  as_tibble( ) 

# Multilevel
pred_multi <- mdl_multilevel |>
  predictions(
    newdata = datagrid(
      first_floor = c("Basement", "First floor"),
      county = c("CLAY", "RICE", "SCOTT")
    )
  ) |> 
  select(county, first_floor, estimate, conf.low, conf.high) |> 
  as_tibble( ) 

# Plot
radon_mn |> 
  filter(county %in% c("CLAY", "RICE", "SCOTT")) |>
  ggplot(aes(x = first_floor, y = log.radon)) +
  geom_point() + 
  geom_line(data = pred_multi, aes(x = first_floor, y = estimate, group = county), color = "black")  + 
  geom_line(data = pred_no, aes(x = first_floor, y = estimate, group = county), color = "blue")  + 
  geom_line(data = pred_complete, aes(x = first_floor, y = estimate, group = FALSE), color = "red")  +
  facet_wrap(~county) +
  labs(x     = "",
    y     = "Estimated Log Radon Level in the county"
    )

The dashed red line is the complete pooling model. The model assumes there is no difference in radon levels between the counties hence why it is high. Blue line represents the predictions from the no-pooling model. This model assumes that there is a difference between the counties, and that the presence or absence of a basement is not the only factor that affects the radon levels. The black line represents predictions from the multilevel model. This model is a compromise of the previous 2 models. Whether the blue line is more similar to the red line or the black line in the plot depends on the magnitude of the variation in radon levels between counties. If the variation in radon levels between counties is large, then the blue line will be more similar to the red line. If the variation in radon levels between counties is small, then the blue line will be more similar to the black line.The figure in the book only Clay county is represented. Both graphs confirm the multilevel model’s accuracy in predicting radon levels in Clay County. Unlike the complete pooling and no pooling models, the multilevel model captures the variation in radon levels between counties. Consistent with observed data, the multilevel model predicts higher radon levels in Clay County basements compared to first floors.

Exercise 6

In this exercise you are going to add a fixed effect at the county level (level 2). This illustration is based on figure 12.6 in the book, and it shows the estimated county level coefficients, plotted vs. county level uranium levels, along with estimated multilevel regression line at level 2. After replicating this graph, please explain it briefly.

# The simple linear model for the general relationship between 
# Radon measurements and county level uranium
md.lm <- lm(log.radon ~ u , data = radon_mn)
summary(md.lm)
## 
## Call:
## lm(formula = log.radon ~ u, data = radon_mn)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.8816 -0.4887  0.0666  0.5582  2.5413 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.32367    0.02835    46.7   <2e-16 ***
## u            0.75203    0.07303    10.3   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8083 on 917 degrees of freedom
## Multiple R-squared:  0.1037, Adjusted R-squared:  0.1027 
## F-statistic:   106 on 1 and 917 DF,  p-value: < 2.2e-16
# The multilevel model for the radon as a function of level-2 uranium
md.lvl12 <- lmer(log.radon ~ u +  (1|county), data = radon_mn)
summary(md.lvl12)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: log.radon ~ u + (1 | county)
##    Data: radon_mn
## 
## REML criterion at convergence: 2219.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.7634 -0.5881  0.0552  0.6675  3.2999 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  county   (Intercept) 0.01405  0.1186  
##  Residual             0.64037  0.8002  
## Number of obs: 919, groups:  county, 85
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)  1.33305    0.03397 45.84421  39.242  < 2e-16 ***
## u            0.71912    0.08777 43.63556   8.193 2.27e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##   (Intr)
## u 0.197
# Predictions for the linear model
pred.lm <- predictions(
  md.lm,
  )

# predictions for the multilevel model
# stratified by the level of uranium
pred.lvl12 <- predictions(
  md.lvl12,
  by = "u"
)

pred.lvl12 |>
  ggplot(aes(x = u, xend = u, y = conf.low, yend = conf.high)) +
  geom_segment() +
  geom_point(aes(y = estimate)) +
  geom_line(
    data = pred.lm,
    aes(x = u, y = estimate),
    ) +
  labs(x = "uranium (county level)",
       y = "County level coefficients")

The multilevel model more accurately predicts county level log radon levels than the simple linear model, especially for higher uranium levels. This is because the multilevel model accounts for the variation in radon levels between counties.

Exercise 7

Using the simulation techniques in questions 1 and 2, generate a synthetic dataset that would be similar to the radon data, in the sense that if you fitted the three models to your simulated dataset, you would get similar parameter estimations to the ones you got when fitting your models to the real Radon dataset. Explore your synthetic data using similar visualisations, and comment on similarities or differences between the Radon dataset and your simulated dataset.

obs_per_cluster <-  16
n_cluster <-  60
# Fixed intercept
alpha_0 <-  1.5

# Fixed slope
beta_0 <- -0.6

# Residuals st.dev (level 1) 
sig  <-  0.7

# Random intercept st.dev (level 2) 
sig_u <-  0.35

# Random slope st.dev (level 2)
sig_v <-  0.35

# Independent random effects
cor <-  -0.3
# Create a dataset that can be reproduced

# Create a dataset that can be reproduced
set.seed(888)  
# step 1: create the units 
sf <- add_random(
  cluster = n_cluster,  # first the clusters
  obs = obs_per_cluster # second, the observations
) 

# Print the result 
# try to figure out what just happened
sf |> 
  print(n = 15)
## # A tibble: 960 × 2
##    cluster   obs  
##    <chr>     <chr>
##  1 cluster01 obs01
##  2 cluster01 obs02
##  3 cluster01 obs03
##  4 cluster01 obs04
##  5 cluster01 obs05
##  6 cluster01 obs06
##  7 cluster01 obs07
##  8 cluster01 obs08
##  9 cluster01 obs09
## 10 cluster01 obs10
## 11 cluster01 obs11
## 12 cluster01 obs12
## 13 cluster01 obs13
## 14 cluster01 obs14
## 15 cluster01 obs15
## # ℹ 945 more rows
# step 2: Add anything at level 2
# Here we have random intercept/slope 
sf <- sf |>
  add_ranef(
    "cluster",
    u_i = sig_u,
    v_i = sig_v,
    .cors = cor
  ) |> mutate(
    a_i = alpha_0 + u_i, 
    b_i = beta_0  + v_i
  )

# Print the result 
# try to figure out what just happened
sf |> 
  print(n = 15)
## # A tibble: 960 × 6
##    cluster   obs     u_i    v_i   a_i   b_i
##    <chr>     <chr> <dbl>  <dbl> <dbl> <dbl>
##  1 cluster01 obs01 0.645 -0.456  2.14 -1.06
##  2 cluster01 obs02 0.645 -0.456  2.14 -1.06
##  3 cluster01 obs03 0.645 -0.456  2.14 -1.06
##  4 cluster01 obs04 0.645 -0.456  2.14 -1.06
##  5 cluster01 obs05 0.645 -0.456  2.14 -1.06
##  6 cluster01 obs06 0.645 -0.456  2.14 -1.06
##  7 cluster01 obs07 0.645 -0.456  2.14 -1.06
##  8 cluster01 obs08 0.645 -0.456  2.14 -1.06
##  9 cluster01 obs09 0.645 -0.456  2.14 -1.06
## 10 cluster01 obs10 0.645 -0.456  2.14 -1.06
## 11 cluster01 obs11 0.645 -0.456  2.14 -1.06
## 12 cluster01 obs12 0.645 -0.456  2.14 -1.06
## 13 cluster01 obs13 0.645 -0.456  2.14 -1.06
## 14 cluster01 obs14 0.645 -0.456  2.14 -1.06
## 15 cluster01 obs15 0.645 -0.456  2.14 -1.06
## # ℹ 945 more rows
# step 3: add anything at level 1
sf <- sf |>
  mutate(
    x       = rnorm(n_cluster * obs_per_cluster),
    epsilon = rnorm(n_cluster * obs_per_cluster, 0, sig),
    y = a_i + b_i * x + epsilon
  )


# Print the result 
# try to figure out what just happened
sf |> 
  print(n = 20)
## # A tibble: 960 × 9
##    cluster   obs     u_i    v_i   a_i   b_i        x  epsilon     y
##    <chr>     <chr> <dbl>  <dbl> <dbl> <dbl>    <dbl>    <dbl> <dbl>
##  1 cluster01 obs01 0.645 -0.456  2.14 -1.06 -0.352    0.324   2.84 
##  2 cluster01 obs02 0.645 -0.456  2.14 -1.06  0.979    0.308   1.42 
##  3 cluster01 obs03 0.645 -0.456  2.14 -1.06  1.05    -0.218   0.819
##  4 cluster01 obs04 0.645 -0.456  2.14 -1.06  0.0651  -0.927   1.15 
##  5 cluster01 obs05 0.645 -0.456  2.14 -1.06  0.0971  -1.04    1.00 
##  6 cluster01 obs06 0.645 -0.456  2.14 -1.06  0.617    0.170   1.66 
##  7 cluster01 obs07 0.645 -0.456  2.14 -1.06  0.100   -1.35    0.692
##  8 cluster01 obs08 0.645 -0.456  2.14 -1.06 -0.0398   0.635   2.82 
##  9 cluster01 obs09 0.645 -0.456  2.14 -1.06 -0.990   -0.650   2.54 
## 10 cluster01 obs10 0.645 -0.456  2.14 -1.06 -0.725    0.0320  2.94 
## 11 cluster01 obs11 0.645 -0.456  2.14 -1.06  0.583   -0.883   0.646
## 12 cluster01 obs12 0.645 -0.456  2.14 -1.06 -0.00827  0.00774 2.16 
## 13 cluster01 obs13 0.645 -0.456  2.14 -1.06  0.247   -0.828   1.06 
## 14 cluster01 obs14 0.645 -0.456  2.14 -1.06 -1.01     0.0976  3.31 
## 15 cluster01 obs15 0.645 -0.456  2.14 -1.06  1.65     1.42    1.82 
## 16 cluster01 obs16 0.645 -0.456  2.14 -1.06  1.52     0.835   1.37 
## 17 cluster02 obs01 0.432 -0.440  1.93 -1.04 -1.40     0.972   4.36 
## 18 cluster02 obs02 0.432 -0.440  1.93 -1.04 -1.17     0.00388 3.15 
## 19 cluster02 obs03 0.432 -0.440  1.93 -1.04 -0.669    0.905   3.53 
## 20 cluster02 obs04 0.432 -0.440  1.93 -1.04 -0.849   -0.241   2.57 
## # ℹ 940 more rows
# For the models, we really only need 
# the cluster id, the y and the x

sf  <- sf |> select(cluster, x, y)

# Print the result 
# try to figure out what just happened
sf |> 
  print(n = 20)
## # A tibble: 960 × 3
##    cluster          x     y
##    <chr>        <dbl> <dbl>
##  1 cluster01 -0.352   2.84 
##  2 cluster01  0.979   1.42 
##  3 cluster01  1.05    0.819
##  4 cluster01  0.0651  1.15 
##  5 cluster01  0.0971  1.00 
##  6 cluster01  0.617   1.66 
##  7 cluster01  0.100   0.692
##  8 cluster01 -0.0398  2.82 
##  9 cluster01 -0.990   2.54 
## 10 cluster01 -0.725   2.94 
## 11 cluster01  0.583   0.646
## 12 cluster01 -0.00827 2.16 
## 13 cluster01  0.247   1.06 
## 14 cluster01 -1.01    3.31 
## 15 cluster01  1.65    1.82 
## 16 cluster01  1.52    1.37 
## 17 cluster02 -1.40    4.36 
## 18 cluster02 -1.17    3.15 
## 19 cluster02 -0.669   3.53 
## 20 cluster02 -0.849   2.57 
## # ℹ 940 more rows
# simulation parameter
#3 complete pooling
comple_pooling <- lm (y~x, data=sf)
modelsummary(comple_pooling)
 (1)
(Intercept) 1.489
(0.027)
x −0.570
(0.028)
Num.Obs. 960
R2 0.299
R2 Adj. 0.298
AIC 2408.3
BIC 2422.9
Log.Lik. −1201.168
RMSE 0.85
## no pooling
no_pooling <-lm(y~ x+ cluster, data=sf)
modelsummary(no_pooling)
 (1)
(Intercept) 1.904
(0.195)
x −0.581
(0.027)
clustercluster02 0.066
(0.276)
clustercluster03 −0.808
(0.276)
clustercluster04 −0.134
(0.275)
clustercluster05 −0.238
(0.275)
clustercluster06 −0.093
(0.275)
clustercluster07 0.483
(0.276)
clustercluster08 −0.795
(0.276)
clustercluster09 −0.345
(0.275)
clustercluster10 −0.443
(0.276)
clustercluster11 −0.511
(0.276)
clustercluster12 −0.911
(0.275)
clustercluster13 −0.472
(0.276)
clustercluster14 −0.563
(0.276)
clustercluster15 −0.287
(0.275)
clustercluster16 0.061
(0.276)
clustercluster17 −0.756
(0.276)
clustercluster18 −0.536
(0.275)
clustercluster19 0.288
(0.276)
clustercluster20 −0.326
(0.276)
clustercluster21 −0.026
(0.276)
clustercluster22 −0.145
(0.276)
clustercluster23 −0.439
(0.276)
clustercluster24 −0.819
(0.276)
clustercluster25 −0.015
(0.275)
clustercluster26 −0.565
(0.275)
clustercluster27 −0.402
(0.276)
clustercluster28 −1.745
(0.276)
clustercluster29 −0.380
(0.275)
clustercluster30 −0.725
(0.276)
clustercluster31 −0.853
(0.275)
clustercluster32 −0.322
(0.275)
clustercluster33 −0.810
(0.276)
clustercluster34 −0.566
(0.276)
clustercluster35 −0.206
(0.276)
clustercluster36 −0.264
(0.275)
clustercluster37 −0.258
(0.275)
clustercluster38 −0.788
(0.276)
clustercluster39 −0.281
(0.276)
clustercluster40 −0.909
(0.276)
clustercluster41 −0.449
(0.275)
clustercluster42 −0.268
(0.275)
clustercluster43 0.250
(0.275)
clustercluster44 −0.522
(0.276)
clustercluster45 −0.229
(0.276)
clustercluster46 −0.414
(0.275)
clustercluster47 0.320
(0.275)
clustercluster48 −1.035
(0.275)
clustercluster49 −0.658
(0.275)
clustercluster50 −0.509
(0.276)
clustercluster51 −0.417
(0.275)
clustercluster52 −0.955
(0.275)
clustercluster53 0.040
(0.276)
clustercluster54 −0.148
(0.276)
clustercluster55 −0.380
(0.276)
clustercluster56 −0.467
(0.276)
clustercluster57 −0.720
(0.276)
clustercluster58 −0.815
(0.276)
clustercluster59 −0.705
(0.275)
clustercluster60 0.040
(0.276)
Num.Obs. 960
R2 0.443
R2 Adj. 0.405
AIC 2305.8
BIC 2607.6
Log.Lik. −1090.921
RMSE 0.75
# no pooling + interaction
no_pooling_inter <-lm(y~ x+ cluster + x:cluster, data=sf)
modelsummary(no_pooling)
 (1)
(Intercept) 1.904
(0.195)
x −0.581
(0.027)
clustercluster02 0.066
(0.276)
clustercluster03 −0.808
(0.276)
clustercluster04 −0.134
(0.275)
clustercluster05 −0.238
(0.275)
clustercluster06 −0.093
(0.275)
clustercluster07 0.483
(0.276)
clustercluster08 −0.795
(0.276)
clustercluster09 −0.345
(0.275)
clustercluster10 −0.443
(0.276)
clustercluster11 −0.511
(0.276)
clustercluster12 −0.911
(0.275)
clustercluster13 −0.472
(0.276)
clustercluster14 −0.563
(0.276)
clustercluster15 −0.287
(0.275)
clustercluster16 0.061
(0.276)
clustercluster17 −0.756
(0.276)
clustercluster18 −0.536
(0.275)
clustercluster19 0.288
(0.276)
clustercluster20 −0.326
(0.276)
clustercluster21 −0.026
(0.276)
clustercluster22 −0.145
(0.276)
clustercluster23 −0.439
(0.276)
clustercluster24 −0.819
(0.276)
clustercluster25 −0.015
(0.275)
clustercluster26 −0.565
(0.275)
clustercluster27 −0.402
(0.276)
clustercluster28 −1.745
(0.276)
clustercluster29 −0.380
(0.275)
clustercluster30 −0.725
(0.276)
clustercluster31 −0.853
(0.275)
clustercluster32 −0.322
(0.275)
clustercluster33 −0.810
(0.276)
clustercluster34 −0.566
(0.276)
clustercluster35 −0.206
(0.276)
clustercluster36 −0.264
(0.275)
clustercluster37 −0.258
(0.275)
clustercluster38 −0.788
(0.276)
clustercluster39 −0.281
(0.276)
clustercluster40 −0.909
(0.276)
clustercluster41 −0.449
(0.275)
clustercluster42 −0.268
(0.275)
clustercluster43 0.250
(0.275)
clustercluster44 −0.522
(0.276)
clustercluster45 −0.229
(0.276)
clustercluster46 −0.414
(0.275)
clustercluster47 0.320
(0.275)
clustercluster48 −1.035
(0.275)
clustercluster49 −0.658
(0.275)
clustercluster50 −0.509
(0.276)
clustercluster51 −0.417
(0.275)
clustercluster52 −0.955
(0.275)
clustercluster53 0.040
(0.276)
clustercluster54 −0.148
(0.276)
clustercluster55 −0.380
(0.276)
clustercluster56 −0.467
(0.276)
clustercluster57 −0.720
(0.276)
clustercluster58 −0.815
(0.276)
clustercluster59 −0.705
(0.275)
clustercluster60 0.040
(0.276)
Num.Obs. 960
R2 0.443
R2 Adj. 0.405
AIC 2305.8
BIC 2607.6
Log.Lik. −1090.921
RMSE 0.75
##3 Multilevel model
Multi_inter<- lmer(y~x +(1| cluster), data=sf)
modelsummary(Multi_inter)
 (1)
(Intercept) 1.489
(0.050)
x −0.578
(0.027)
SD (Intercept cluster) 0.334
SD (Observations) 0.779
Num.Obs. 960
R2 Marg. 0.304
R2 Cond. 0.412
AIC 2342.6
BIC 2362.1
ICC 0.2
RMSE 0.76
# multilevel model + randoms slopes
Multi_slope<- lmer(y~x +(x| cluster), data=sf)
modelsummary(Multi_slope)
 (1)
(Intercept) 1.484
(0.049)
x −0.575
(0.054)
SD (Intercept cluster) 0.333
SD (x cluster) 0.365
Cor (Intercept~x cluster) −0.431
SD (Observations) 0.698
Num.Obs. 960
R2 Marg. 0.301
R2 Cond. 0.529
AIC 2228.3
BIC 2257.5
ICC 0.3
RMSE 0.66
# Create a list of models
model_list <- list(
  "Complete Pooling" = comple_pooling,
  "No Pooling" = no_pooling,
  "No Pooling + Interactions" = no_pooling_inter,
  "Multilevel model" = Multi_inter,
  "Multilevem model + random  slopes" = Multi_slope
)
modelsummary(model_list)
Complete Pooling No Pooling  No Pooling + Interactions Multilevel model Multilevem model + random slopes
(Intercept) 1.489 1.904 1.927 1.489 1.484
(0.027) (0.195) (0.182) (0.050) (0.049)
x −0.570 −0.581 −0.679 −0.578 −0.575
(0.028) (0.027) (0.225) (0.027) (0.054)
clustercluster02 0.066 0.016
(0.276) (0.253)
clustercluster03 −0.808 −1.012
(0.276) (0.263)
clustercluster04 −0.134 −0.148
(0.275) (0.253)
clustercluster05 −0.238 −0.038
(0.275) (0.261)
clustercluster06 −0.093 −0.026
(0.275) (0.266)
clustercluster07 0.483 0.381
(0.276) (0.253)
clustercluster08 −0.795 −0.815
(0.276) (0.252)
clustercluster09 −0.345 −0.375
(0.275) (0.252)
clustercluster10 −0.443 −0.382
(0.276) (0.253)
clustercluster11 −0.511 −0.537
(0.276) (0.252)
clustercluster12 −0.911 −0.935
(0.275) (0.252)
clustercluster13 −0.472 −0.454
(0.276) (0.253)
clustercluster14 −0.563 −0.583
(0.276) (0.253)
clustercluster15 −0.287 −0.319
(0.275) (0.253)
clustercluster16 0.061 0.007
(0.276) (0.257)
clustercluster17 −0.756 −0.758
(0.276) (0.253)
clustercluster18 −0.536 −0.515
(0.275) (0.253)
clustercluster19 0.288 0.166
(0.276) (0.257)
clustercluster20 −0.326 −0.347
(0.276) (0.253)
clustercluster21 −0.026 −0.155
(0.276) (0.291)
clustercluster22 −0.145 −0.131
(0.276) (0.259)
clustercluster23 −0.439 −0.541
(0.276) (0.254)
clustercluster24 −0.819 −0.829
(0.276) (0.254)
clustercluster25 −0.015 −0.044
(0.275) (0.253)
clustercluster26 −0.565 −0.574
(0.275) (0.252)
clustercluster27 −0.402 −0.439
(0.276) (0.260)
clustercluster28 −1.745 −1.516
(0.276) (0.268)
clustercluster29 −0.380 −0.422
(0.275) (0.254)
clustercluster30 −0.725 −0.894
(0.276) (0.274)
clustercluster31 −0.853 −0.880
(0.275) (0.253)
clustercluster32 −0.322 −0.304
(0.275) (0.253)
clustercluster33 −0.810 −0.890
(0.276) (0.254)
clustercluster34 −0.566 −0.554
(0.276) (0.254)
clustercluster35 −0.206 −0.224
(0.276) (0.252)
clustercluster36 −0.264 −0.248
(0.275) (0.255)
clustercluster37 −0.258 −0.431
(0.275) (0.258)
clustercluster38 −0.788 −0.435
(0.276) (0.273)
clustercluster39 −0.281 −0.485
(0.276) (0.260)
clustercluster40 −0.909 −0.832
(0.276) (0.257)
clustercluster41 −0.449 −0.474
(0.275) (0.252)
clustercluster42 −0.268 −0.380
(0.275) (0.256)
clustercluster43 0.250 0.205
(0.275) (0.256)
clustercluster44 −0.522 −0.605
(0.276) (0.252)
clustercluster45 −0.229 −0.203
(0.276) (0.259)
clustercluster46 −0.414 −0.409
(0.275) (0.263)
clustercluster47 0.320 0.288
(0.275) (0.253)
clustercluster48 −1.035 −1.215
(0.275) (0.259)
clustercluster49 −0.658 −0.678
(0.275) (0.253)
clustercluster50 −0.509 −0.526
(0.276) (0.252)
clustercluster51 −0.417 −0.491
(0.275) (0.254)
clustercluster52 −0.955 −0.787
(0.275) (0.258)
clustercluster53 0.040 0.164
(0.276) (0.269)
clustercluster54 −0.148 −0.177
(0.276) (0.254)
clustercluster55 −0.380 −1.036
(0.276) (0.318)
clustercluster56 −0.467 −0.593
(0.276) (0.269)
clustercluster57 −0.720 −0.621
(0.276) (0.276)
clustercluster58 −0.815 −0.984
(0.276) (0.263)
clustercluster59 −0.705 −0.722
(0.275) (0.253)
clustercluster60 0.040 −0.024
(0.276) (0.253)
x × clustercluster02 −0.487
(0.307)
x × clustercluster03 0.458
(0.268)
x × clustercluster04 0.023
(0.279)
x × clustercluster05 −0.795
(0.353)
x × clustercluster06 −0.098
(0.288)
x × clustercluster07 −0.903
(0.305)
x × clustercluster08 0.180
(0.322)
x × clustercluster09 0.598
(0.297)
x × clustercluster10 0.745
(0.273)
x × clustercluster11 −0.006
(0.310)
x × clustercluster12 0.344
(0.276)
x × clustercluster13 0.578
(0.278)
x × clustercluster14 0.125
(0.276)
x × clustercluster15 0.160
(0.268)
x × clustercluster16 −0.050
(0.319)
x × clustercluster17 0.475
(0.304)
x × clustercluster18 −0.273
(0.295)
x × clustercluster19 −0.347
(0.311)
x × clustercluster20 0.119
(0.264)
x × clustercluster21 0.267
(0.324)
x × clustercluster22 0.231
(0.304)
x × clustercluster23 −0.383
(0.284)
x × clustercluster24 0.203
(0.317)
x × clustercluster25 0.231
(0.311)
x × clustercluster26 −0.327
(0.289)
x × clustercluster27 0.015
(0.431)
x × clustercluster28 0.721
(0.318)
x × clustercluster29 0.227
(0.316)
x × clustercluster30 −0.304
(0.372)
x × clustercluster31 0.225
(0.381)
x × clustercluster32 −0.323
(0.275)
x × clustercluster33 −0.253
(0.293)
x × clustercluster34 0.601
(0.453)
x × clustercluster35 0.214
(0.278)
x × clustercluster36 −0.086
(0.278)
x × clustercluster37 0.729
(0.313)
x × clustercluster38 0.816
(0.301)
x × clustercluster39 −0.559
(0.324)
x × clustercluster40 0.441
(0.280)
x × clustercluster41 −0.211
(0.302)
x × clustercluster42 0.440
(0.278)
x × clustercluster43 0.211
(0.313)
x × clustercluster44 −0.927
(0.268)
x × clustercluster45 0.235
(0.274)
x × clustercluster46 0.031
(0.285)
x × clustercluster47 0.182
(0.299)
x × clustercluster48 0.640
(0.307)
x × clustercluster49 0.066
(0.277)
x × clustercluster50 0.636
(0.357)
x × clustercluster51 0.586
(0.354)
x × clustercluster52 −0.459
(0.273)
x × clustercluster53 0.389
(0.290)
x × clustercluster54 0.061
(0.298)
x × clustercluster55 0.690
(0.289)
x × clustercluster56 −0.149
(0.314)
x × clustercluster57 0.332
(0.309)
x × clustercluster58 0.396
(0.270)
x × clustercluster59 0.015
(0.266)
x × clustercluster60 −0.411
(0.286)
SD (Intercept cluster) 0.334 0.333
SD (x cluster) 0.365
Cor (Intercept~x cluster) −0.431
SD (Observations) 0.779 0.698
Num.Obs. 960 960 960 960 960
R2 0.299 0.443 0.582
R2 Adj. 0.298 0.405 0.523
R2 Marg. 0.304 0.301
R2 Cond. 0.412 0.529
AIC 2408.3 2305.8 2147.1 2342.6 2228.3
BIC 2422.9 2607.6 2736.0 2362.1 2257.5
ICC 0.2 0.3
Log.Lik. −1201.168 −1090.921 −952.562
RMSE 0.85 0.75 0.65 0.76 0.66
radon_mn_count <- sf |>
  count(cluster, name = "n.obs")

# No pooling
m.no_pool  <- lm(y ~ 0 + cluster, data = sf)
summary(no_pooling)
## 
## Call:
## lm(formula = y ~ x + cluster, data = sf)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.40191 -0.51787  0.01718  0.51241  2.47938 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       1.90358    0.19486   9.769  < 2e-16 ***
## x                -0.58105    0.02719 -21.367  < 2e-16 ***
## clustercluster02  0.06569    0.27553   0.238 0.811612    
## clustercluster03 -0.80787    0.27551  -2.932 0.003451 ** 
## clustercluster04 -0.13395    0.27544  -0.486 0.626847    
## clustercluster05 -0.23837    0.27542  -0.865 0.387016    
## clustercluster06 -0.09341    0.27549  -0.339 0.734627    
## clustercluster07  0.48294    0.27555   1.753 0.080009 .  
## clustercluster08 -0.79459    0.27552  -2.884 0.004020 ** 
## clustercluster09 -0.34505    0.27549  -1.253 0.210703    
## clustercluster10 -0.44283    0.27560  -1.607 0.108450    
## clustercluster11 -0.51051    0.27552  -1.853 0.064222 .  
## clustercluster12 -0.91098    0.27549  -3.307 0.000981 ***
## clustercluster13 -0.47159    0.27556  -1.711 0.087357 .  
## clustercluster14 -0.56283    0.27557  -2.042 0.041403 *  
## clustercluster15 -0.28736    0.27543  -1.043 0.297093    
## clustercluster16  0.06066    0.27568   0.220 0.825899    
## clustercluster17 -0.75620    0.27553  -2.744 0.006181 ** 
## clustercluster18 -0.53598    0.27544  -1.946 0.051975 .  
## clustercluster19  0.28780    0.27570   1.044 0.296828    
## clustercluster20 -0.32605    0.27557  -1.183 0.237048    
## clustercluster21 -0.02642    0.27562  -0.096 0.923664    
## clustercluster22 -0.14504    0.27578  -0.526 0.599059    
## clustercluster23 -0.43856    0.27564  -1.591 0.111945    
## clustercluster24 -0.81881    0.27559  -2.971 0.003046 ** 
## clustercluster25 -0.01520    0.27547  -0.055 0.956003    
## clustercluster26 -0.56450    0.27548  -2.049 0.040734 *  
## clustercluster27 -0.40157    0.27564  -1.457 0.145506    
## clustercluster28 -1.74468    0.27597  -6.322 4.06e-10 ***
## clustercluster29 -0.38015    0.27543  -1.380 0.167872    
## clustercluster30 -0.72461    0.27590  -2.626 0.008778 ** 
## clustercluster31 -0.85254    0.27547  -3.095 0.002030 ** 
## clustercluster32 -0.32170    0.27545  -1.168 0.243143    
## clustercluster33 -0.80971    0.27563  -2.938 0.003392 ** 
## clustercluster34 -0.56629    0.27555  -2.055 0.040153 *  
## clustercluster35 -0.20591    0.27553  -0.747 0.455061    
## clustercluster36 -0.26419    0.27542  -0.959 0.337710    
## clustercluster37 -0.25818    0.27542  -0.937 0.348796    
## clustercluster38 -0.78826    0.27620  -2.854 0.004417 ** 
## clustercluster39 -0.28116    0.27577  -1.020 0.308218    
## clustercluster40 -0.90852    0.27579  -3.294 0.001026 ** 
## clustercluster41 -0.44949    0.27550  -1.632 0.103124    
## clustercluster42 -0.26844    0.27542  -0.975 0.329995    
## clustercluster43  0.25024    0.27542   0.909 0.363817    
## clustercluster44 -0.52170    0.27554  -1.893 0.058628 .  
## clustercluster45 -0.22857    0.27590  -0.828 0.407617    
## clustercluster46 -0.41445    0.27546  -1.505 0.132788    
## clustercluster47  0.32044    0.27544   1.163 0.244995    
## clustercluster48 -1.03508    0.27542  -3.758 0.000182 ***
## clustercluster49 -0.65788    0.27545  -2.388 0.017128 *  
## clustercluster50 -0.50880    0.27550  -1.847 0.065105 .  
## clustercluster51 -0.41687    0.27544  -1.513 0.130518    
## clustercluster52 -0.95536    0.27544  -3.469 0.000548 ***
## clustercluster53  0.03954    0.27616   0.143 0.886177    
## clustercluster54 -0.14816    0.27563  -0.538 0.591023    
## clustercluster55 -0.38039    0.27635  -1.376 0.169015    
## clustercluster56 -0.46675    0.27600  -1.691 0.091157 .  
## clustercluster57 -0.72041    0.27619  -2.608 0.009249 ** 
## clustercluster58 -0.81450    0.27551  -2.956 0.003194 ** 
## clustercluster59 -0.70541    0.27546  -2.561 0.010603 *  
## clustercluster60  0.04015    0.27555   0.146 0.884186    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.779 on 899 degrees of freedom
## Multiple R-squared:  0.4425, Adjusted R-squared:  0.4053 
## F-statistic: 11.89 on 60 and 899 DF,  p-value: < 2.2e-16
m.partial_pool <- sf %>%
  lmer(y ~ 1 + (1 | cluster), data = .)


# model, and then the multilevel (partial pooling) model.
m.no_pool  |> 
  predictions(newdata = data.frame(cluster = unique(sf$cluster))) |> 
  as_tibble() |> 
  inner_join(radon_mn_count, by = "cluster") |> 
  select(cluster, estimate, conf.low, conf.high, n.obs) |> 
  ggplot(
    aes(
      x    = cluster, 
      y    = estimate, 
      ymin = conf.low, 
      ymax = conf.high
    )
  ) + 
  geom_pointrange(position = position_jitter(width = .5, height = 0)) +   labs(
    title = "No pooling (fixed effects)",
    x     = "Number of observations",
    y     = "Estimated y in the cluster"
  )

# model, and then the multilevel (partial pooling) model.
m.partial_pool  |> 
  predictions(newdata = data.frame(cluster = unique(sf$cluster))) |> 
  as_tibble() |> 
  inner_join(radon_mn_count, by = "cluster") |> 
  select(cluster, estimate, conf.low, conf.high, n.obs) |> 
  ggplot(
    aes(
      x    = cluster, 
      y    = estimate, 
      ymin = conf.low, 
      ymax = conf.high
    )
  ) + 
  geom_pointrange(position = position_jitter(width = .5, height = 0)) +  # Fix: Add 'position_jitter'
  labs(
    title = "Partial pooling (multilevel model)",
    x     = "Number of observations",
    y     = "Estimated y in the cluster"
  )

##
predict_y <- Multi_inter |> 
  ranef() |> 
  # Used the broom.mixed::augment function 
  # to calculate the confidence intervals
  augment() |> 
  # convert to a tibble
  as_tibble() |> 
  # Include only the random intercept
  filter(variable == "(Intercept)") |> 
  # Now we order the results by ascending estimates
  arrange(estimate) |> 
  mutate(cluster = fct_inorder(level)) 

# Finally, let's plot our caterpillar!
predict_y |>
  ggplot(aes(xmin = (estimate - 1.96 * std.error), xmax = (estimate + 1.96 * std.error), y = cluster, x = estimate)) + 
    geom_pointrange() + 
    labs(x = "Estimate of the intercept (Y_hat when X=0)", y = NULL)

# Spagetti - Random intercept
predictions(Multi_inter) |>  
  ggplot(aes(x = x, y = y, color = cluster)) + 
  geom_point() + 
  geom_line(aes(x, y = estimate))

# Lattice 
predictions(Multi_inter) |>  
  ggplot(aes(x = x, y = y, color = cluster)) + 
  geom_point() + 
  geom_line(aes(x, y = estimate))+
  facet_wrap(~cluster)

The associations are all negative and have similar slopes. The estimated logs differ in all models.