R-Code & Data
# 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("LPSM 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("t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9", "t10", "t11", "t12"), v.names = "Treatment", timevar = "Wave", direction = "long")
# Estimating the association between X1-X5 and t with a Random Intercept model without the error terms include ####
RI<-glmer(Treatment~Wave+ X1_n+X2_n+X3_n+X4_n+X5_n + (1|id), data = L, family = binomial(link= logit))
findbars(Treatment~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<-glmer(Treatment~Wave+ X1_n+X2_n+X3_n+X4_n+X5_n + (0+Wave|id), data = L, family = binomial(link= logit))
findbars(Treatment~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<-glmer(Treatment~Wave+ X1_n+X2_n+X3_n+X4_n+X5_n + (1+Wave|id), data = L, family = binomial(link= logit))
findbars(Treatment~Wave+ X1_n+X2_n+X3_n+X4_n+X5_n + (1+Wave|id)) # Identifying Random Effects
summary(RIS)