library('foreign')
library('lavaan')
library('lme4')
library('semPlot')
library(semTools)
# Read data C:\Users\brown\Desktop\DPhil\SEM analysis
mydata <- read.spss ("C:/Users/Carol/Desktop/DPhil/SEM analysis/SEM analysis april 2016 inc MLR/Main study data (AS1).sav", to.data.frame=T)
# Create numeric school variable
mydata$school[mydata$schsector=="State sector"] <- 1
mydata$school[mydata$schsector=="Independent sector"] <- 0
# scale variables
mydata$ISEImo2 <- mydata$ISEImo / 10
mydata$ISEIfa2 <- mydata$ISEIfa / 10
mydata$ TotalASExaminationPointscore <- mydata$ TotalASExaminationPointscore / 100
# 2. What is the relationship between expectations and subjective task value for an A-level student sample?
rq.2 <- '
# Measurement part
# Expectations
expectations =~ Q24 + Q26 + Q28 + Q32 + Q36
#STV model 1 (3 factor)
intrinsic =~ Q21 + Q30
attainment =~ Q25 + Q31 + Q37
utility =~ Q22 + Q34
STV =~ intrinsic + attainment + utility'
fit <- sem(rq.2, data = mydata, missing='fiml', estimator='MLR')
summary(fit, fit.measures=TRUE, standardized=TRUE)
inspect(fit,"cor.lv")
semPaths (fit, what="std",
style="lisrel",edge.color="black", fade=FALSE,
edge.width=0.5, nCharNodes=7, intercepts = FALSE)
rq.2 <- '
# Measurement part
# Expectations
expectations =~ Q24 + Q26 + Q28 + Q32 + Q36
#STV model 2 (attainment utility as a combined model)
intrinsic =~ Q21 + Q30
attainmentutility =~ Q25 + Q31 + Q37 + Q22 + Q34
STV =~ intrinsic + attainmentutility'
fit <- sem(rq.2, data = mydata, missing='fiml', estimator='MLR')
summary(fit, fit.measures=TRUE, standardized=TRUE)
inspect(fit,"cor.lv")
semPaths (fit, what="std",
style="lisrel",edge.color="black", fade=FALSE,
edge.width=0.5, nCharNodes=7, intercepts = FALSE)
#STV (excluding utility value)
rq.2 <- '
# Measurement part
# Expectations
expectations =~ Q24 + Q26 + Q28 + Q32 + Q36
#STV model 3 (excluding utility)
intrinsic =~ Q21 + Q30
attainment =~ Q25 + Q31 + Q37
STV =~ intrinsic + attainment'
fit <- sem(rq.2, data = mydata, missing='fiml', estimator='MLR')
summary(fit, fit.measures=TRUE, standardized=TRUE)
inspect(fit,"cor.lv")
semPaths (fit, what="std",
style="lisrel",edge.color="black", fade=FALSE,
edge.width=0.5, nCharNodes=7, intercepts = FALSE)
the last finds better fit statistics
report a delta CFI to test this statistically
'measurementInvariance(HS.model, data = HolzingerSwineford1939, group = "school")' however am struggling to adapt this to my project
Also can anyone advise on a good paper that indicates how to then write up the findings.