R-Code; Data; Data Simulation and R-Code
# getting started ####
## Do Not Change
library(pastecs)
library(foreign)
library(lmerTest)
library(lme4)
library(Hmisc)
library(psych)
library(lmtest)
library(lmerTest)
library(pbkrtest)
library(MuMIn)
library(sandwich)
library(sizeMat)
library(MatchIt)
library(lm.beta)
library(data.table)
options(scipen=100, digits=12)
options(max.print = 5000)
# Importing data
setwd("") # Set the Working Directory for the CSV file
D<-read.csv("Longitudinal LMs Data.csv", # Make sure you appropriately change the location
header = T, # Tells r the rist row is the variable names
sep = ",") # Tells r that the seperating character in the dataset is a ,
# Creating a long dataset for the longitudinal analysis ####
names(D)
L<-reshape(D, varying =c("Y1", "Y2", "Y3", "Y4", "Y5", "Y6", "Y7", "Y8", "Y9", "Y10", "Y11", "Y12"), v.names = "Y", timevar = "Wave", direction = "long")
# Estimating the association between X1-X5 and t with a Random Intercept model without the error terms include ####
RI<-lmer(Y~Wave+ X1_n+X2_n+X3_n+X4_n+X5_n + (1|id), data = L)
findbars(Y~Wave+ X1_n+X2_n+X3_n+X4_n+X5_n + (1|id)) # Identifying Random Effects
summary(RI)
# Estimating the association between X1-X5 and t with a Random Slope (no random intercept) model without the error terms include ####
RS<-lmer(Y~Wave+ X1_n+X2_n+X3_n+X4_n+X5_n + (0+Wave|id), data = L)
findbars(Y~Wave+ X1_n+X2_n+X3_n+X4_n+X5_n + (0+Wave|id)) # Identifying Random Effects
summary(RS)
# Estimating the association between X1-X5 and t with a Random Intercept and Slope model without the error terms include ####
RIS<-lmer(Y~Wave+ X1_n+X2_n+X3_n+X4_n+X5_n + (1+Wave|id), data = L)
findbars(Y~Wave+ X1_n+X2_n+X3_n+X4_n+X5_n + (1+Wave|id)) # Identifying Random Effects
summary(RIS)