User Tools

Site Tools


r:path_analysis:exercise

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

r:path_analysis:exercise [2025/12/01 01:36] – created hkimscilr:path_analysis:exercise [2025/12/01 01:39] (current) hkimscil
Line 2: Line 2:
 library(lavaan) 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.f <- read.csv("http://commres.net/_media/r/active.full.csv")
 active <- read.csv("http://commres.net/_media/r/active.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) head(active.f)
Line 56: Line 23:
 # ls: letter series to measure reasoning ability # ls: letter series to measure reasoning ability
 # lt: letter set to measure reasoning ability # lt: letter set to measure reasoning ability
- 
- 
 # ept: everyday problem solving test  # 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) 
- 
- 
  
 </code> </code>
r/path_analysis/exercise.1764552975.txt.gz · Last modified: by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki