r:path_analysis:exercise
This is an old revision of the document!
library(lavaan)
gpadata <- read.table(file='https://advstats.psychstat.org/data/gpa.txt', header=TRUE, na.string="999", comment.char = "#")
nlsy <- read.csv("http://commres.net/_media/r/nlsy.csv")
active.f <- read.csv("http://commres.net/_media/r/active.full.csv")
active <- read.csv("http://commres.net/_media/r/active.csv")
gpa <- read.csv("http://commres.net/_media/r/gpa.csv")
mamm <- read.csv("http://commres.net/_media/r/mamm.csv")
# outcome y: whether a woman is in compliance with mammography screening recommendations (1: in compliance; 0: not in compliance)
# Predictors:
# x1: whether she has received a recommendation for screening from a physician;
# x2: her knowledge about breast cancer and mammography screening;
# x3: her perception of benefit of such a screening;
# x4: her perception of the barriers to being screened.
# National Longitudinal Surveys (NLS)
head(nlsy)
spec.mod <- '
math ~ b*HE + cp*ME
HE ~ a*ME
ab := a*b
total := a*b + cp
'
mod.fit<-sem(spec.mod, data=nlsy)
summary(mod.fit)
spec.mod2 <- '
math ~ b*HE
HE ~ a*ME
'
fit.mod2<-sem(spec.mod2, data=nlsy)
summary(fit.mod2)
head(active.f)
str(active.f)
# ACTIVE (Advanced Cognitive Training for Independent and Vital Elderly)
# age
# edu: years of edu
# group: there are four groups - control group and three other training groups (memory, reasoning, and speed)
# booster: whether received booster training
# sex: 1 Male 2 Female
# reason: reasoning ability
# ufov: useful field of view variable
# mmse: Mini-mental state examination total score
# hvlt: Hopkins Verbal Learning Test
# ws: word series to measure reasoning ability
# ls: letter series to measure reasoning ability
# lt: letter set to measure reasoning ability
# ept: everyday problem solving test
spec.mod.active <- '
hvltt1 ~ p1*age + edu
ws1 ~ p2*age + edu
ls1 ~ p3*age + edu
lt1 ~ p4*age + edu
ept1 ~ p5*age + p6*edu + p7*hvltt1 + p8*ws1 + p9*ls1 + p10*lt1
ws1~~ls1
ws1~~lt1
ls1~~lt1
hvltt1~~ls1
hvltt1~~ws1
hvltt1~~lt1
ind1 := p1*p7
total := p5 + p1*p7 + p2*p8 + p3*p9 + p4*p10
indirect := p1*p7 + p2*p8 + p3*p9 + p4*p10
'
fit.mod.active<-sem(spec.mod.active, data=active.f)
summary(fit.mod.active)
r/path_analysis/exercise.1764552975.txt.gz · Last modified: by hkimscil
