if (FALSE) {
#----------------------------------------------------------------------------
# Linear model
# Example 1a: Dominance analysis, 'mpg' predicted by 'cyl', 'disp', and 'hp'
dominance.manual(cor(mtcars[, c("mpg", "cyl", "disp", "hp")]))
# Example 1b: Equivalent results using the dominance() function
mod <- lm(mpg ~ cyl + disp + hp, data = mtcars)
dominance(mod)
# Example 1c: Dominance analysis, 'hp' predicted by 'mpg', 'cyl', and 'disp'
dominance.manual(cor(mtcars[, c("mpg", "cyl", "disp", "hp")]), out = "hp")
# Example 1d: Write results into a text file
dominance.manual(cor(mtcars[, c("mpg", "cyl", "disp", "hp")]),
write = "Dominance_Manual.txt")
#----------------------------------------------------------------------------
# Example 2: Structural equation modeling
library(lavaan)
#.............
# Latent variables
# Model specification
model <- '# Measurement model
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + y2 + y3 + y4
dem65 =~ y5 + y6 + y7 + y8
# regressions
ind60 ~ dem60 + dem65'
# Model estimation
fit <- sem(model, data = PoliticalDemocracy)
# Model-implied correlation matrix of the latent variables
fit.cor <- lavInspect(fit, what = "cor.lv")
# Dominance analysis
dominance.manual(fit.cor)
#.............
# Example 3: Latent and manifest variables
# Model specification, convert manifest to latent variable
model <- '# Measurement model
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + y2 + y3 + y4
# Manifest as latent variable
ly5 =~ 1*y5
y5 ~~ 0*y5
# Regressions
ind60 ~ dem60 + ly5'
# Model estimation
fit <- sem(model, data = PoliticalDemocracy)
# Model-implied correlation matrix of the latent variables
fit.cor <- lavInspect(fit, what = "cor.lv")
# Dominance analysis
dominance.manual(fit.cor)
#----------------------------------------------------------------------------
# Example 4: Multilevel modeling
# Model specification
model <- 'level: 1
fw =~ y1 + y2 + y3
# Manifest as latent variables
lx1 =~ 1*x1
lx2 =~ 1*x2
lx3 =~ 1*x3
x1 ~~ 0*x1
x2 ~~ 0*x2
x3 ~~ 0*x3
# Regression
fw ~ lx1 + lx2 + lx3
level: 2
fb =~ y1 + y2 + y3
# Manifest as latent variables
lw1 =~ 1*w1
lw2 =~ 1*w2
# Regression
fb ~ lw1 + lw2'
# Model estimation
fit <- sem(model, data = Demo.twolevel, cluster = "cluster")
# Model-implied correlation matrix of the latent variables
fit.cor <- lavInspect(fit, what = "cor.lv")
# Dominance analysis Within
dominance.manual(fit.cor$within)
# Dominance analysis Between
dominance.manual(fit.cor$cluster)
#----------------------------------------------------------------------------
# Example 5: Mplus
#
# In Mplus, the model-impied correlation matrix of the latent variables
# can be requested by OUTPUT: TECH4 and imported into R by using the
# MplusAuomtation package, for example:
library(MplusAutomation)
# Read Mplus output
output <- readModels()
# Extract model-implied correlation matrix of the latent variables
fit.cor <- output$tech4$latCorEst
}
Run the code above in your browser using DataLab