This vignette demonstrates how to fit an ordinal regression model
with plssem using the titanic dataset.
In plssem, regression-style model syntax like
y ~ x1 + x2 is supported. When the dependent variable
(and/or predictors) are ordinal. Ordinal variables can be supplied via
the ordered argument, or by making sure they are
ordered in the dataset.
This model predicts survival as a function of age and sex.
m_linear <- "Survived ~ Age + Female"
fit_linear <- pls(
m_linear,
data = titanic,
ordered = "Survived",
boot.R = 50,
bootstrap = TRUE,
boot.parallel = "multicore",
boot.ncpus = 2
)
summary(fit_linear)
#> plssem (0.1.2) ended normally after 1 iterations
#>
#> Estimator OrdPLSc
#> Link PROBIT
#>
#> Number of observations 714
#> Number of iterations 1
#> Number of latent variables 0
#> Number of observed variables 3
#>
#> Fit Measures:
#> Chi-Square 0.000
#> Degrees of Freedom 0
#> SRMR 0.000
#> RMSEA NaN
#>
#> R-squared (latents):
#> Survived 0.347
#>
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Survived ~
#> Age -0.043 0.041 -1.054 0.292
#> Female 0.584 0.029 19.948 0.000
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> Age ~~
#> Female -0.093 0.035 -2.671 0.008
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .Survived 0.653 0.035 18.687 0.000
#> Age 1.000
#> Female 1.000Optional: evaluate predictive performance.
pls_predict(fit_linear, benchmark = "acc")
#> PlsSemPredict object
#> Available fields: $Y, $X.cont, $X.cont.pred, $X.ord, $X.ord.pred, $benchmark
#>
#> Y [714 x 3] (head)
#> Survvd Age Female
#> 1 -0.420 -0.530 -0.759
#> 2 0.743 0.571 1.317
#> 3 0.779 -0.255 1.317
#> 4 0.752 0.365 1.317
#> 5 -0.458 0.365 -0.759
#> 7 -0.515 1.673 -0.759
#>
#> X.cont [714 x 3] (head)
#> Survvd Age Female
#> 1 -0.653 -0.530 -0.759
#> 2 0.955 0.571 1.317
#> 3 0.955 -0.255 1.317
#> 4 0.955 0.365 1.317
#> 5 -0.653 0.365 -0.759
#> 7 -0.653 1.673 -0.759
#>
#> X.cont.pred [714 x 3] (head)
#> Survvd Age Female
#> 1 -0.420 -0.530 -0.759
#> 2 0.743 0.571 1.317
#> 3 0.779 -0.255 1.317
#> 4 0.752 0.365 1.317
#> 5 -0.458 0.365 -0.759
#> 7 -0.515 1.673 -0.759
#>
#> X.ord [714 x 3] (head)
#> Survvd Age Female
#> 1 1.000 -0.530 -0.759
#> 2 2.000 0.571 1.317
#> 3 2.000 -0.255 1.317
#> 4 2.000 0.365 1.317
#> 5 1.000 0.365 -0.759
#> 7 1.000 1.673 -0.759
#>
#> X.ord.pred [714 x 3] (head)
#> Survvd Age Female
#> 1 1.000 -0.530 -0.759
#> 2 2.000 0.571 1.317
#> 3 2.000 -0.255 1.317
#> 4 2.000 0.365 1.317
#> 5 1.000 0.365 -0.759
#> 7 1.000 1.673 -0.759
#>
#> Benchmark summary
#> acc: n=1, mean=0.780, median=0.780, min=0.780, max=0.780
#> variable value
#> Survived 0.780To include a non-linear (interaction) effect, add an interaction
term. With ordinal indicators and interactions, plssem
automatically switches to the Monte-Carlo ordinal PLSc estimator.
m_int <- "Survived ~ Age + Female + Age:Female"
fit_int <- pls(
m_int,
data = titanic,
ordered = "Survived",
boot.R = 50,
bootstrap = TRUE,
boot.parallel = "multicore",
boot.ncpus = 2
)
summary(fit_int)
#> plssem (0.1.2) ended normally after 106 iterations
#>
#> Estimator MCOrdPLSc
#> Link PROBIT
#>
#> Number of observations 714
#> Number of iterations 106
#> Number of latent variables 0
#> Number of observed variables 3
#>
#> Fit Measures:
#> Chi-Square NA
#> Degrees of Freedom NA
#> SRMR NA
#> RMSEA NA
#>
#> R-squared (latents):
#> Survived 0.567
#>
#>
#> Regressions:
#> Estimate Std.Error z.value P(>|z|)
#> Survived ~
#> Age -0.074 0.043 -1.712 0.087
#> Female 0.696 0.041 16.838 0.000
#> Age:Female 0.252 0.075 3.374 0.001
#>
#> Covariances:
#> Estimate Std.Error z.value P(>|z|)
#> Age ~~
#> Female -0.091 0.034 -2.662 0.008
#> Age:Female -0.007 0.013 -0.550 0.582
#> Female ~~
#> Age:Female 0.011 0.016 0.642 0.521
#>
#> Variances:
#> Estimate Std.Error z.value P(>|z|)
#> .Survived 0.433 0.083 5.209 0.000
#> Age 1.000
#> Female 1.000
#> Age:Female 1.000
pls_predict(fit_int, benchmark = "acc")
#> PlsSemPredict object
#> Available fields: $Y, $X.cont, $X.cont.pred, $X.ord, $X.ord.pred, $benchmark
#>
#> Y [714 x 4] (head)
#> Survvd Age Female Ag:Fml
#> 1 -0.364 -0.530 -0.759 0.495
#> 2 1.087 0.571 1.317 0.845
#> 3 0.874 -0.255 1.317 -0.242
#> 4 1.034 0.365 1.317 0.574
#> 5 -0.601 0.365 -0.759 -0.184
#> 7 -0.948 1.673 -0.759 -1.176
#>
#> X.cont [714 x 3] (head)
#> Survvd Age Female
#> 1 -0.645 -0.530 -0.759
#> 2 0.932 0.571 1.317
#> 3 0.932 -0.255 1.317
#> 4 0.932 0.365 1.317
#> 5 -0.645 0.365 -0.759
#> 7 -0.645 1.673 -0.759
#>
#> X.cont.pred [714 x 3] (head)
#> Survvd Age Female
#> 1 -0.364 -0.530 -0.759
#> 2 1.087 0.571 1.317
#> 3 0.874 -0.255 1.317
#> 4 1.034 0.365 1.317
#> 5 -0.601 0.365 -0.759
#> 7 -0.948 1.673 -0.759
#>
#> X.ord [714 x 3] (head)
#> Survvd Age Female
#> 1 1.000 -0.530 -0.759
#> 2 2.000 0.571 1.317
#> 3 2.000 -0.255 1.317
#> 4 2.000 0.365 1.317
#> 5 1.000 0.365 -0.759
#> 7 1.000 1.673 -0.759
#>
#> X.ord.pred [714 x 3] (head)
#> Survvd Age Female
#> 1 1.000 -0.530 -0.759
#> 2 2.000 0.571 1.317
#> 3 2.000 -0.255 1.317
#> 4 2.000 0.365 1.317
#> 5 1.000 0.365 -0.759
#> 7 1.000 1.673 -0.759
#>
#> Benchmark summary
#> acc: n=1, mean=0.780, median=0.780, min=0.780, max=0.780
#> variable value
#> Survived 0.780