Assignment 2

# Loading the relevant Libraries
suppressWarnings(suppressPackageStartupMessages(library(readxl)))
suppressWarnings(suppressPackageStartupMessages(library(tidyverse)))
suppressWarnings(suppressPackageStartupMessages(library(nlme)))
suppressWarnings(suppressPackageStartupMessages(library(lme4)))
suppressWarnings(suppressPackageStartupMessages(library(sjPlot)))

# Loading the new data file
# Note that in the new data file the dependent variable is continuous...

datafile3 <- read_excel("C:/HLMcourse/datafile3.xlsx")

Running the Model

Now we would like to test whether visiting the dentist or not, has a correlation with cognitive ability. Note that this is a correlational and not a causal hypothesis. We have a dichotomous independent variable (visited the dentist yes or no) and a continuous variable (Cognitive Function Score)

Running the model with lmer by lme4

model1 <- lmer(CognitiveFunction ~ 1 + (1|VisitDentist), data = datafile3, na.action = "na.omit")
summary(model1)
## Linear mixed model fit by REML ['lmerMod']
## Formula: CognitiveFunction ~ 1 + (1 | VisitDentist)
##    Data: datafile3
## 
## REML criterion at convergence: 467154.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.8817 -0.7142 -0.0815  0.5512 10.2954 
## 
## Random effects:
##  Groups       Name        Variance Std.Dev.
##  VisitDentist (Intercept)  8.522   2.919   
##  Residual                 62.445   7.902   
## Number of obs: 67001, groups:  VisitDentist, 2
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)   20.708      2.064   10.03

Calculation of the ICC

## [1] 0.1200783
## [1] 0.1200781

Model Summary

  CognitiveFunction
Predictors Estimates CI p
(Intercept) 20.71 16.66 – 24.75 <0.001
Random Effects
σ2 62.45
τ00 VisitDentist 8.52
ICC 0.12
N VisitDentist 2
Observations 67001
Marginal R2 / Conditional R2 0.000 / 0.120