Hello all,
I am new to R.- I have been trying to do moderation analysis using structural equation modeling.
I have been reading and watching to learn more about it; but I got stuck here for days ( the error was highlighted in pink)…. If someone can kindly help me through this, it will be so great.
I copied and pasted my entire codes to help you understand better.
library(lavaan)
x<-c("gender","AGE", “a” , “b”, “c” , “PS” , “ d”, “e”, “f”, “g”)
#multiple latent variables
SUMMERMODEL<-' risk =~a+b+c
MH =~d+e
PH =~f+g '
fit2<-cfa(SUMMERMODEL, data = SUMMER_final, missing= "FIML")
summary(fit2, standardized=TRUE, fit.measures=TRUE)
#structural model
SUMMERMODEL<-'#Latent variable definitions
SUMMERMODEL<-' risk =~a+b+c
MH =~d+e
PH =~f+g
#regressions
MH~ risk+gender +age
PH ~risk +gender+age
#residual correlations
MH ~~ PH'
fit<-sem(SUMMERMODEL, data=SUMMER_final, missing= "FIML")
summary(fit,standardized=TRUE)
# moderation analysis
semdata<-data.frame(predict(fit))
-centering (IV and moderator)
riskc<-scale(semdata$risk,center=TRUE,scale=FALSE)
PSc<-scale(SUMMER_final$PS,center = TRUE,scale = FALSE)
xz<-riskc%*%c(PSc)
#REGRESSIONS
regression1<-lm(MH~ riskc + PSc+xz+gender+age, data=SUMMER_final, missing= “FIML”)
summary(regression1) : When I run this part (pink highlight), I got this error - Error in h(simpleerror(msg,call)) : error in evaluating the argument ‘object’ in selecting a method for function ‘ summary: object ‘regression1’ not found. I have been searching for how to fix this error, I have not been successful .
regression2=lm(PH~riskc+PSc+xz+gender+age, data=SUMMER_final, missing= “FIML”)
summary(regression2)
I am glad to find this group !!! Thank you very much !!!
riskc<-scale(semdata$risk,center=TRUE,scale=FALSE)
PSc<-scale(SUMMER_final$PS,center = TRUE,scale = FALSE)
xz<-riskc%*%c(PSc)
regression1<-lm(MH~ riskc + PSc+xz+gender+age, data=SUMMER_final, missing= “FIML”)
--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/4f9ed443-5808-4794-be9d-07ca9eb143e5o%40googlegroups.com.
riskc<-scale(semdata$risk,center=TRUE,scale=FALSE).
SUMMER_final$riskc <- scale(semdata$risk,center=TRUE,scale=FALSE)[ , 1]speaking of xz,xz<- riskc * PSc does not work.... how can I fix this?
Can't we use semTools::indProd() for moderation in lavaan
Error: Assigned data '...[]' must be compatible with existing data.
x Existing data has 295 rows.
x assigned data has 287 rows.
i only vectors of size 1 are recycled.--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/25ec80ec-825a-45d7-a7ae-d9ff34f68d19o%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/4d24ee81-4a0c-4dec-89ef-3b46393411f2o%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/CAJc%3DyOHG%3D1qu89Bu4St6OJ0W8yCogkhvCWOeJTcOFiOhhJSf%2BA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/CAHvhQq9CePfnFGMWL4UnPBJkH%2BjyD6KYai55MWSAw1OLTtfnXA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/CAJc%3DyOHpH1gVZ4SBXH9g8icDQJHRYjuLKwYqZWbgEFctcPXjbA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/CAHvhQq96%2BM6jMNF54OUckfbabAWCsqJ1VbfZAhorNsMrT7mnAA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/CAJc%3DyOFY-WLBDvDPDCZrTY1NWkq6AZqT6SQO00ZmDcFXL9Yn-Q%40mail.gmail.com.
I saw the message - 8 cases were deleted due to missing valuesin exogenous variable(s), while fixed. x=TRUE.-what exactly should I do ?
--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/1cab7924-982a-4abf-8104-a49d8c70d02ao%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/1cab7924-982a-4abf-8104-a49d8c70d02ao%40googlegroups.com.
library(lavaan)
x<-c("gender","AGE", “a” , “b”, “c” , “PS” , “ d”, “e”, “f”, “g”)
#multiple latent variables
SUMMERMODEL<-' risk =~a+b+c
MH =~d+e
PH =~f+g '
fit2<-cfa(SUMMERMODEL, data = SUMMER_final, missing= "FIML")
summary(fit2, standardized=TRUE, fit.measures=TRUE)
#structural model
SUMMERMODEL<-'#Latent variable definitions
SUMMERMODEL<-' risk=~a+b+c
MH=~d+e
PH=~f+g
#regressions
MH~ risk+gender +age
PH ~risk +gender+age
#residual correlations
MH ~~ PH'
fit<-sem(SUMMERMODEL, data=SUMMER_final, missing= "FIML.X")
summary(fit,standardized=TRUE)
# moderation analysis
semdata<-data.frame(predict(fit))
-centering (IV and moderator)
SUMMER_final$riskc<-scale(semdata$risk,center=TRUE,scale=FALSE)
SUMMER_final$PSc<-scale(SUMMER_final$PS,center= TRUE,scale = FALSE)
SUMMER_final$xz<- SUMMER_final$riskc*SUMMER_final$PSc
#REGRESSIONS
regression1<-lm(MH~SUMMER_final$riskc + SUMMER_final$PSc +xz+gender+age, data=SUMMER_final)
summary(regression1)
: The error says that object -regression 1- not found
regression2=lm(PH~ SUMMER_final$riskc + SUMMER_final$PSc +xz+gender+age, data=SUMMER_final)
summary(regression2)
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/CAHvhQq8XK_F-%2BTLnAQmVmSmJBgNVdBRR8O7PbJ1iyfJ1fX4n%3Dg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/CAJc%3DyOF_F%3Du9n5Tx8mddJYHgkxFwJim64G4LJ6Pu-APc20odfw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/CAHvhQq_3U7Hjfq8Mm8OsS9o44d7-j7gZhfP6UheB3%3D3xai7s6Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/CAJc%3DyOF3s0_noJvWHKdkxJ9oaQoBB99bPJ%3DwF9JELWOsB%3DQF4Q%40mail.gmail.com.
semdata<-data.frame(predict(fit), missing = "fiml.x", ) like this ??
?lavOptions#REGRESSIONS
regression1<-lm(MH~SUMMER_final$riskc + SUMMER_final$PSc +xz+gender+age, data=SUMMER_final)
summary(regression1)
: The error says that object -regression 1- not found
--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/9be2790e-81e6-4647-a57a-b58f129af5f0o%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/9be2790e-81e6-4647-a57a-b58f129af5f0o%40googlegroups.com.