# 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 |
The following model aimed at understanding the relationship between verbal fluency and survey wave, while considering individual differences captured by dental visitation status (hc). The main objective is to explore how verbal fluency changes over time (survey waves) and how individual characteristics influence this change. The model tests whether verbal fluency significantly varies across survey waves and whether there are significant differences in verbal fluency between individuals based on their dental visitation status. By including random effects for both intercept and slope, the model accounts for individual variability in initial levels of verbal fluency and in the relationship between verbal fluency and survey wave. This comprehensive approach allows for a deeper understanding of the factors influencing verbal expression abilities in the dataset, offering insights into both temporal changes and individual differences related to dental visitation status.
m0 <- lmer(verbalfluency ~ (1 | hc), finalcogdata)
m1 <- lmer(verbalfluency ~ wave + (1 | hc), finalcogdata)
m2 <- lmer(verbalfluency ~ wave + (1 + wave | hc), finalcogdata)
## boundary (singular) fit: see help('isSingular')
tab_model(m0, m1, m2)
| verbalfluency | verbalfluency | verbalfluency | |||||||
|---|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | CI | p | Estimates | CI | p | Estimates | CI | p |
| (Intercept) | 20.85 | 16.70 – 25.00 | <0.001 | 22.03 | 17.87 – 26.19 | <0.001 | 22.08 | 18.57 – 25.60 | <0.001 |
| wave | -0.15 | -0.20 – -0.11 | <0.001 | -0.16 | -0.26 – -0.07 | 0.001 | |||
| Random Effects | |||||||||
| σ2 | 55.90 | 55.87 | 55.87 | ||||||
| τ00 | 8.96 hc | 8.94 hc | 6.36 hc | ||||||
| τ11 | 0.00 hc.wave | ||||||||
| ρ01 | 1.00 hc | ||||||||
| ICC | 0.14 | 0.14 | |||||||
| N | 2 hc | 2 hc | 2 hc | ||||||
| Observations | 70813 | 70813 | 70813 | ||||||
| Marginal R2 / Conditional R2 | 0.000 / 0.138 | 0.001 / 0.138 | 0.001 / NA | ||||||
This new model introduces random slopes for the wave variable within the grouping variable hc, offering a more nuanced understanding of the relationship between verbal fluency, survey wave, and dental visitation status. The fixed effects analysis reveals that verbal fluency is significantly associated with both wave and the intercept, with verbal fluency decreasing by approximately 0.15 units for each unit increase in wave. Interestingly, the inclusion of random slopes for wave within hc (m2) provides additional insights into individual variability in the relationship between verbal fluency and survey wave, as indicated by the variance component ??11. The estimated variance components (??2 and ??00) suggest substantial variability in verbal fluency both within and between individuals, with a relatively higher level of variability attributed to individual differences (??00) compared to variability across different survey waves. The marginal and conditional R-squared values indicate that the model accounts for approximately 13.8% of the variance in verbal fluency, with the inclusion of random slopes slightly improving the model’s explanatory power. Overall, this enhanced model underscores the importance of considering not only fixed effects but also individual-level variability and contextual factors, such as survey wave and dental visitation status, in understanding verbal expression abilities within the dataset.