Assignment 4

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

suppressWarnings(suppressPackageStartupMessages(library(readr)))
suppressWarnings(suppressPackageStartupMessages(library(knitr)))
suppressWarnings(suppressPackageStartupMessages(library(gt)))
suppressWarnings(suppressPackageStartupMessages(library(lme4)))
suppressWarnings(suppressPackageStartupMessages(library(sjPlot)))

# Loading the data file and presenting the variable sin a data table
finalcogdata <- read_csv("C:/HLMcourse/Assignment4/finalcogdata.csv")
## New names:
## Rows: 86444 Columns: 16
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (2): mergeid, age_group dbl (14): ...1, gender, education, language,
## yearofbirth, country, wave, rea...
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
# Create a data frame with variable names and descriptions
variables <- c("mergeid", "gender", "education", "language", "yearofbirth", 
               "country", "wave", "readingskills", "writingskills", "verbalfluency", 
               "memory", "hc", "immidiate", "delayed", "age_group")

descriptions <- c("Unique identifier for each subject",
                  "Gender of the individual (e.g., Male, Female)",
                  "Level of education attained by the individual",
                  "Primary language spoken by the individual",
                  "Year of birth of the individual",
                  "Country where the individual resides",
                  "Wave of the survey data collection",
                  "Skills in reading comprehension",
                  "Skills in writing composition",
                  "Ability to express oneself verbally",
                  "Capacity to recall information",
                  "Whether the patient visited the dentist or not",
                  "Performance on an immidiate recall task",
                  "Performance on a  delayed recall task",
                  "Age group of the individual")

variable_description <- data.frame(Variable = variables, Description = descriptions)


# Create a gt table
variable_table <- variable_description %>%
  gt() %>%
  tab_header(
    title = "Variables Descriptions"
  )

# Print the table
variable_table
Variables Descriptions
Variable Description
mergeid Unique identifier for each subject
gender Gender of the individual (e.g., Male, Female)
education Level of education attained by the individual
language Primary language spoken by the individual
yearofbirth Year of birth of the individual
country Country where the individual resides
wave Wave of the survey data collection
readingskills Skills in reading comprehension
writingskills Skills in writing composition
verbalfluency Ability to express oneself verbally
memory Capacity to recall information
hc Whether the patient visited the dentist or not
immidiate Performance on an immidiate recall task
delayed Performance on a delayed recall task
age_group Age group of the individual

Building a model with two levels

The Model2Levels is a linear mixed-effects model aimed at exploring the relationship between verbal fluency and two predictors: wave and hc, where hc signifies whether an individual visited the dentist or not. Verbal fluency serves as the dependent variable, reflecting an individual’s ability to express themselves verbally. The predictor wave denotes different survey rounds or time points during data collection, facilitating the investigation of changes in verbal fluency over time. The inclusion of hc as a random effect acknowledges potential differences in verbal fluency between individuals based on their dental visitation status. By fitting this model, one can assess the significance of the relationship between verbal fluency, time of data collection, and dental visitation status. Overall, the model provides insights into how verbal fluency varies across survey waves while considering the influence of dental visitation, #offering valuable understanding of factors affecting verbal expression abilities in the dataset.

The wave variable serves as an explanatory variable in level 1 and the hc variable serve as grouping variable in level 2

Running the model

Model2Levels = lmer( verbalfluency ~ wave + (1 | hc), data = finalcogdata)

Printing the model in a nice table

m0 <- lmer(verbalfluency ~ (1 | hc), finalcogdata)
m1 <- update(m0, . ~ .  + wave)
tab_model(m0, m1)
  verbalfluency verbalfluency
Predictors Estimates CI p Estimates CI p
(Intercept) 20.85 16.70 – 25.00 <0.001 22.03 17.87 – 26.19 <0.001
wave -0.15 -0.20 – -0.11 <0.001
Random Effects
σ2 55.90 55.87
τ00 8.96 hc 8.94 hc
ICC 0.14 0.14
N 2 hc 2 hc
Observations 70813 70813
Marginal R2 / Conditional R2 0.000 / 0.138 0.001 / 0.138

#Based on the table of the results the fixed effects analysis indicates that verbal fluency is significantly associated with the wave predictor, with verbal fluency decreasing by 0.15 units for each unit increase in wave. The random effects analysis reveals variability in verbal fluency between individuals based on whether they visited the dentist or not, with the estimated random intercept variance (??00) for the hc variable indicating this variability. The model demonstrates a reasonable fit to the data, explaining about 13.8% of the variance in verbal fluency, considering both fixed and random effects. Overall, these findings offer insights into the factors influencing verbal expression abilities, highlighting the importance of both temporal changes and individual differences related to dental visitation status.