vp <- read.csv("/Users/pegad/Desktop/Mplus_workshop/VP_Promo.csv", na.strings = ".")
names(vp)
## [1] "Visibility1_code" "Visibility2_code" "Leadership1_code"
## [4] "Leadership2_code" "Leadership3_code" "Impact1_code"
## [7] "Timing1_code"
dim(vp)
## [1] 188 7
summary(vp)
## Visibility1_code Visibility2_code Leadership1_code Leadership2_code
## Min. :0.000 Min. :0.000 Min. :1.000 Min. :1.00
## 1st Qu.:3.000 1st Qu.:3.000 1st Qu.:4.000 1st Qu.:4.00
## Median :4.000 Median :4.000 Median :4.000 Median :4.00
## Mean :3.642 Mean :3.814 Mean :4.051 Mean :4.07
## 3rd Qu.:5.000 3rd Qu.:5.000 3rd Qu.:5.000 3rd Qu.:5.00
## Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.00
## NA's :1 NA's :10 NA's :17
## Leadership3_code Impact1_code Timing1_code
## Min. :2.000 Min. :1.000 Min. :1.000
## 1st Qu.:4.000 1st Qu.:3.000 1st Qu.:4.000
## Median :4.000 Median :3.000 Median :4.000
## Mean :4.239 Mean :3.408 Mean :4.027
## 3rd Qu.:5.000 3rd Qu.:4.000 3rd Qu.:5.000
## Max. :5.000 Max. :5.000 Max. :5.000
## NA's :12 NA's :4
summary(lm(Timing1_code ~ Impact1_code, data = vp))
##
## Call:
## lm(formula = Timing1_code ~ Impact1_code, data = vp)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.90419 -0.33924 0.09581 0.53086 1.09581
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.59903 0.17427 14.914 < 2e-16 ***
## Impact1_code 0.43505 0.04917 8.847 7.75e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6494 on 182 degrees of freedom
## (4 observations deleted due to missingness)
## Multiple R-squared: 0.3007, Adjusted R-squared: 0.2969
## F-statistic: 78.27 on 1 and 182 DF, p-value: 7.745e-16
prepareMplusData(vp, "/Users/pegad/Desktop/Mplus_workshop/R_to_Mplus.dat", inpfile = TRUE)
regression_mod <- mplusObject(TITLE = "Regression;", MODEL = "Timing1_code ON Impact1_code;",
usevariables = c("Impact1_code", "Timing1_code"), OUTPUT = "SAMPSTAT STDYX;", rdata = vp)
cat(createSyntax(regression_mod, filename = "R_to_Mplus.dat"))
## All ok
## TITLE:
## Regression;
## DATA:
## FILE = "R_to_Mplus.dat";
##
## VARIABLE:
## NAMES = Impact1_code Timing1_code;
## MISSING=.;
##
## MODEL:
## Timing1_code ON Impact1_code;
## OUTPUT:
## SAMPSTAT STDYX;
results <- mplusModeler(regression_mod, dataout = "test.dat", run = 1)
## Wrote model to: test.inp
## Wrote data to: test.dat
## Warning in prepareMplusData(df = data[i, object$usevariables], filename =
## dataout, : The file 'test.dat' currently exists and will be overwritten
##
## Running model: test.inp
## System command: cd "/Users/pegad/Desktop/Mplus_workshop" && "/Applications/Mplus/mplus" "test.inp"
## Reading model: test.out
class(results)
## [1] "mplusObject" "list"
names(results)
## [1] "TITLE" "DATA" "VARIABLE" "DEFINE"
## [5] "ANALYSIS" "MODEL" "OUTPUT" "SAVEDATA"
## [9] "PLOT" "results" "usevariables" "rdata"
## [13] "imputed"
results$results
## $input
## $title
## [1] " Regression;"
##
## $data
## $data$file
## [1] "\"test.dat\""
##
##
## $variable
## $variable$names
## [1] "Impact1_code Timing1_code"
##
## $variable$missing
## [1] "."
##
##
## $model
## [1] "" " Timing1_code ON Impact1_code;"
##
## $output
## [1] "" " SAMPSTAT STDYX;" ""
## [4] "" ""
##
## attr(,"class")
## [1] "list" "mplus.inp"
## attr(,"start.line")
## [1] 6
## attr(,"end.line")
## [1] 22
##
## $warnings
## [[1]]
## [1] "Note that only the first 8 characters of variable names are used in the output."
## [2] "Shorten variable names to avoid any confusion."
##
## [[2]]
## [1] "Data set contains cases with missing on x-variables."
## [2] "These cases were not included in the analysis."
## [3] "Number of cases with missing on x-variables: 4"
## [4] "2 WARNING(S) FOUND IN THE INPUT INSTRUCTIONS"
##
## attr(,"class")
## [1] "list" "mplus.warnings"
##
## $errors
## list()
## attr(,"class")
## [1] "list" "mplus.errors"
##
## $summaries
## Mplus.version Title AnalysisType DataType Estimator
## 1 7.4 Regression; GENERAL INDIVIDUAL ML
## Observations Parameters ChiSqM_Value ChiSqM_DF ChiSqM_PValue
## 1 184 3 0 0 0
## ChiSqBaseline_Value ChiSqBaseline_DF ChiSqBaseline_PValue LL
## 1 65.823 1 0 -180.657
## UnrestrictedLL CFI TLI AIC BIC aBIC RMSEA_Estimate
## 1 -180.657 1 1 367.314 376.959 367.457 0
## RMSEA_90CI_LB RMSEA_90CI_UB RMSEA_pLT05 SRMR AICC Filename
## 1 0 0 0 0 367.4473 test.out
##
## $parameters
## $parameters$unstandardized
## paramHeader param est se est_se pval
## 1 TIMING1_.ON IMPACT1_CO 0.435 0.049 8.896 0
## 2 Intercepts TIMING1_CO 2.599 0.173 14.996 0
## 3 Residual.Variances TIMING1_CO 0.417 0.043 9.592 0
##
## $parameters$r2
## param est se est_se pval
## 1 TIMING1_ 0.301 0.057 5.319 0
##
## $parameters$stdyx.standardized
## paramHeader param est se est_se pval
## 1 TIMING1_.ON IMPACT1_CO 0.548 0.052 10.638 0
## 2 Intercepts TIMING1_CO 3.365 0.361 9.325 0
## 3 Residual.Variances TIMING1_CO 0.699 0.057 12.368 0
##
##
## $class_counts
## list()
##
## $residuals
## list()
##
## $tech1
## list()
##
## $tech3
## list()
##
## $tech4
## list()
##
## $tech7
## list()
##
## $tech9
## list()
## attr(,"class")
## [1] "list" "mplus.tech9"
##
## $tech12
## list()
##
## $fac_score_stats
## list()
## attr(,"class")
## [1] "list" "mplus.facscorestats"
##
## $gh5
## list()
##
## attr(,"class")
## [1] "mplus.model" "list"
## attr(,"filename")
## [1] "test.out"
results$results$parameters$stdyx.standardized
## paramHeader param est se est_se pval
## 1 TIMING1_.ON IMPACT1_CO 0.548 0.052 10.638 0
## 2 Intercepts TIMING1_CO 3.365 0.361 9.325 0
## 3 Residual.Variances TIMING1_CO 0.699 0.057 12.368 0
extractModelParameters("/Users/pegad/Desktop/Mplus_workshop/test.out")
## $unstandardized
## paramHeader param est se est_se pval
## 1 TIMING1_.ON IMPACT1_CO 0.435 0.049 8.896 0
## 2 Intercepts TIMING1_CO 2.599 0.173 14.996 0
## 3 Residual.Variances TIMING1_CO 0.417 0.043 9.592 0
##
## $r2
## param est se est_se pval
## 1 TIMING1_ 0.301 0.057 5.319 0
##
## $stdyx.standardized
## paramHeader param est se est_se pval
## 1 TIMING1_.ON IMPACT1_CO 0.548 0.052 10.638 0
## 2 Intercepts TIMING1_CO 3.365 0.361 9.325 0
## 3 Residual.Variances TIMING1_CO 0.699 0.057 12.368 0
runModels("/Users/pegad/Desktop/Mplus_workshop", replaceOutfile = FALSE)
##
## Running model: CFA_break.inp
## System command: cd "/Users/pegad/Desktop/Mplus_workshop" && "/Applications/Mplus/mplus" "CFA_break.inp"
##
## Running model: CFA.inp
## System command: cd "/Users/pegad/Desktop/Mplus_workshop" && "/Applications/Mplus/mplus" "CFA.inp"
##
## Running model: Data_check.inp
## System command: cd "/Users/pegad/Desktop/Mplus_workshop" && "/Applications/Mplus/mplus" "Data_check.inp"
##
## Running model: EFA.inp
## System command: cd "/Users/pegad/Desktop/Mplus_workshop" && "/Applications/Mplus/mplus" "EFA.inp"
##
## Running model: R_to_Mplus.inp
## System command: cd "/Users/pegad/Desktop/Mplus_workshop" && "/Applications/Mplus/mplus" "R_to_Mplus.inp"
##
## Running model: Simple_regression.inp
## System command: cd "/Users/pegad/Desktop/Mplus_workshop" && "/Applications/Mplus/mplus" "Simple_regression.inp"
##
## Running model: test.inp
## System command: cd "/Users/pegad/Desktop/Mplus_workshop" && "/Applications/Mplus/mplus" "test.inp"
*** WARNING in VARIABLE command Note that only the first 8 characters of variable names are used in the output. Shorten variable names to avoid any confusion.
*** WARNING Input line exceeded 90 characters. Some input may be truncated.
*** WARNING in MODEL command All variables are uncorrelated with all other variables in the model.
THE MODEL ESTIMATION TERMINATED NORMALLY
THE STANDARD ERRORS OF THE MODEL PARAMETER ESTIMATES COULD NOT BE COMPUTED. THE MODEL MAY NOT BE IDENTIFIED. CHECK YOUR MODEL. PROBLEM INVOLVING THE FOLLOWING PARAMETER: Parameter 15, LEAD WITH VIS
1 semicolons at the end of each line
2 correct variables specified in “usevariables” command
3 datafile correctly specified and to the correct location
4 everything spelt correctly
5 naming variables in the correct order
6 missing data is coded correctly
Comments start with ! and will turn green