Package 'RAMpath'

Title: Structural Equation Modeling Using the Reticular Action Model (RAM) Notation
Description: We rewrite of RAMpath software developed by John McArdle and Steven Boker as an R package. In addition to performing regular SEM analysis through the R package lavaan, RAMpath has unique features. First, it can generate path diagrams according to a given model. Second, it can display path tracing rules through path diagrams and decompose total effects into their respective direct and indirect effects as well as decompose variance and covariance into individual bridges. Furthermore, RAMpath can fit dynamic system models automatically based on latent change scores and generate vector field plots based upon results obtained from a bivariate dynamic system. Starting version 0.4, RAMpath can conduct power analysis for both univariate and bivariate latent change score models.
Authors: Zhiyong Zhang, Jack McArdle, Aki Hamagami, & Kevin Grimm
Maintainer: Zhiyong Zhang <[email protected]>
License: GPL-2
Version: 0.5.1
Built: 2025-02-07 05:42:26 UTC
Source: https://github.com/cran/RAMpath

Help Index


RAMpath for SEM analysis

Description

We rewrite of RAMpath software developed by John McArdle and Steven Boker as an R package. In addition to performing regular SEM analysis through the R package lavaan, RAMpath has unique features. First, it can generate path diagrams according to a given model. Second, it can display path tracing rules through path diagrams and decompose total effects into their respective direct and indirect effects as well as decompose variance and covariance into individual bridges. Furthermore, RAMpath can fit dynamic system models automatically based on latent change scores and generate vector field plots based upon results obtained from a bivariate dynamic system. Starting version 0.4, RAMpath can conduct power analysis for both univariate and bivariate latent change score models.

Details

Package: RAMpath
Type: Package
License: GPL

Author(s)

Zhiyong Zhang, Jack McArdle, Aki Hamagami, and Kevin Grimm Maintainer: Zhiyong Zhang <[email protected]>

References

Boker, S. M., McArdle, J. J. & Neale, M. C. (2002) An algorithm for the hierarchical organization of path diagrams and calculation of components of covariance between variables. Structural Equation Modeling, 9(2), 174-194

Yves Rosseel (2012). lavaan: An R Package for Structural Equation Modeling. Journal of Statistical Software, 48(2), 1-36. URL https://www.jstatsoft.org/v48/i02/.

Zhang, Z., Hamagami, F., Grimm, K. J., & McArdle, J. J. (2015). Using R package RAMpath for tracing SEM path diagrams and conducting complex longitudinal data analysis. Structural Equation Modeling, 22(1), 132-147. https://doi.org/10.1080/10705511.2014.935257


Example data set 1

Description

Three variables in the data set:

age:

hvlt: Hopkins Verbal Learning Test

ept: Everyday problem solving test

Usage

data(ex1)

Example data set 2

Description

Five variables in the data set:

edu

gender

word sets (ws1)

letter set (ls1)

letter series (lt1)

Usage

data(ex2)

Example data set 3

Description

12 variables in the data set:

X1-X6: data for variable X from time 1 to time 6.

Y1-Y6: data for variable X from time 1 to time 6.

Usage

data(ex3)

Is the input a numeric variable

Description

Check whether the input is a numeric variable

Usage

isNumeric(constant)

Arguments

constant

A variable to check

Value

TRUE or FALSE


Convert lavaan output to RAM matrices

Description

Convert lavaan output to RAM matrices

Usage

lavaan2ram(fitModel, digits = 2, zero.print = "0", ram.out = TRUE, fit = FALSE)

Arguments

fitModel

A lavaan object generated by the function lavaan, sem, or growth

digits

Digits for number print

zero.print

Format zeros in the matrix

ram.out

Whether print RAM matrices

fit

Whether print fit statistics

Value

A and Ase

A matrix and its standard errors

S and Sse

S matrix and its standard errors

fit

model fit

lavaan

The lavaan input, the same as fitModel


Generate all bridges

Description

Generate all bridges based on Boker, McArdle, & Neale (2002)

Usage

makeBridgeList(pathList, spanList)

Arguments

pathList

A path list from the function makePathList

spanList

A span list from the function makeSpanList

References

Boker, S. M., McArdle, J. J. & Neale, M. C. (2002) An algorithm for the hierarchical organization of path diagrams and calculation of components of covariance between variables. Structural Equation Modeling, 9(2), 174-194

Zhang, Z., Hamagami, F., Grimm, K. J., & McArdle, J. J. (2015). Using R package RAMpath for tracing SEM path diagrams and conducting complex longitudinal data analysis. Structural Equation Modeling, 22(1), 132-147. https://doi.org/10.1080/10705511.2014.935257


Make a list of effects

Description

Make a list of effects

Usage

makePathList(AMatrix, Ase, indirect = TRUE)

Arguments

AMatrix

A matrix from the ram matrices

Ase

Standard error matrix for A matrix from the ram matrices

indirect

Whether to generate all indirect effects

References

Boker, S. M., McArdle, J. J. & Neale, M. C. (2002) An algorithm for the hierarchical organization of path diagrams and calculation of components of covariance between variables. Structural Equation Modeling, 9(2), 174-194

Zhang, Z., Hamagami, F., Grimm, K. J., & McArdle, J. J. (2015). Using R package RAMpath for tracing SEM path diagrams and conducting complex longitudinal data analysis. Structural Equation Modeling, 22(1), 132-147. https://doi.org/10.1080/10705511.2014.935257


Make a list of spans

Description

Make a list of spans

Usage

makeSpanList(SMatrix, Sse)

Arguments

SMatrix

S matrix from the ram matrices

Sse

Standard error matrix for S matrix from the ram matrices

References

Boker, S. M., McArdle, J. J. & Neale, M. C. (2002) An algorithm for the hierarchical organization of path diagrams and calculation of components of covariance between variables. Structural Equation Modeling, 9(2), 174-194

Zhang, Z., Hamagami, F., Grimm, K. J., & McArdle, J. J. (2015). Using R package RAMpath for tracing SEM path diagrams and conducting complex longitudinal data analysis. Structural Equation Modeling, 22(1), 132-147. https://doi.org/10.1080/10705511.2014.935257


Plot the power curve for each specified parameter

Description

Plot the power curve for each specified parameter

Usage

## S3 method for class 'lcs.power'
plot(x, parameter, ...)

Arguments

x

Output from the powerLCS function or Output from the powerBLCS function

parameter

parameter to be plotted.

...

Options for the plot function.

References

Zhang, Z., & Liu, H. (2018). Sample size and measurement occasion planning for latent change score models through Monte Carlo simulation. In E. Ferrer, S. M. Boker, and K. J. Grimm (Eds.), Advances in longitudinal models for multivariate psychology: A festschrift for Jack McArdle (pp. 189-211). New York, NY: Routledge.


Plot the path diagram according to RAM path and bridges or Plot the vector field for the bivariate latent change score model

Description

Plot the path diagram according to RAM path and bridges or Plot the vector field for the bivariate latent change score model

Usage

## S3 method for class 'RAMpath'
plot(x, file, from, to, type = c("path", "bridge"), 
size = c(8, 8), node.font = c("Helvetica", 14), edge.font = c("Helvetica", 10),
rank.direction = c("LR", "TB"), digits = 2, output.type = c("graphics", "dot"),
graphics.fmt = "pdf", dot.options = NULL, ...)

## S3 method for class 'blcs'
plot(x, ylim, xlim, ninterval=10, scale=.1, length=.25, 
scatter=TRUE, n=20, alpha=.95, ...)

Arguments

x

Output from the ramPathBridge function or Output from the ramBLCS function

file

File name for the generated figures

from

from variable: path starts from this variable

to

to variable: path ends on this variable

type

path: to plot the effect path;

bridge: to plot the bridges path

size

The size of the plot in inches

node.font

The size of the text for the variables

edge.font

The size of the text on the pahts

rank.direction

LR: from left to right; TB: from top to bottom.

digits

Digits of numbers to plot

output.type

If "graphics", the default, both a ".dot" file and a graphics file will be created.

graphics.fmt

a graphics format recognized by the dot program; the default is "pdf"; graphics.fmt is also used for the extension of the graphics file that is created.

dot.options

options to be passed to the dot program, given as a character string.

ylim

Range of y data, for example, c(0,80) from 0 to 80

xlim

Range of x data, for example, c(0,80) from 0 to 80

ninterval

Number of intervals for plotting. The default is 10.

scale

Time interval to calculate vector fields.

length

The length of arrows to plot

scatter

Whether to plot the data points

n

The number of data points to be plotted

alpha

The confidence level to calculate the ellipse

...

Options for plot and arrows function.

References

Zhang, Z., Hamagami, F., Grimm, K. J., & McArdle, J. J. (2015). Using R package RAMpath for tracing SEM path diagrams and conducting complex longitudinal data analysis. Structural Equation Modeling, 22(1), 132-147. https://doi.org/10.1080/10705511.2014.935257

Examples

data(ex3)
test.blcs<-ramBLCS(ex3, 1:6, 7:12, ram.out=TRUE)
ramVF(test.blcs, c(0,80),c(0,80), length=.05, xlab='X', ylab='Y',scale=.5, ninterval=9)
plot(test.blcs, c(0,80),c(0,80), length=.05, xlab='X', ylab='Y',scale=.5, ninterval=9)

Power analysis for bivariate latent change score models

Description

Calculate power for bivariate latent change score models based on Monte Carlo simulation.

Usage

powerBLCS(N=100, T=5, R=1000, betay=0, my0=0, mys=0, varey=1, 
vary0=1, varys=1, vary0ys=0, alpha=0.05, betax=0, mx0=0, 
mxs=0, varex=1, varx0=1, varxs=1, varx0xs=0, varx0y0=0,  
varx0ys=0, vary0xs=0, varxsys=0, gammax=0, gammay=0, ...)

Arguments

N

Sample size, can be a scalar or a vector. For better performance, make sure N is at least two times of T

T

Number of times, occasions or waves of measurements, can be a scalar or a vector

R

Number of replications to run in Monte Carlo simulation. Recommended 1000 or more

betay

Population parameter values

my0

Population parameter values

mys

Population parameter values

varey

Population parameter values

vary0

Population parameter values

varys

Population parameter values

vary0ys

Population parameter values

betax

Population parameter values

mx0

Population parameter values

mxs

Population parameter values

varex

Population parameter values

varx0

Population parameter values

varxs

Population parameter values

varx0xs

Population parameter values

gammax

Population parameter values

gammay

Population parameter values

varx0y0

Population parameter values

varx0ys

Population parameter values

vary0xs

Population parameter values

varxsys

Population parameter values

alpha

Significance level

...

Options can be used for lavaan

Value

A matrix with power for each parameter.

References

Zhang, Z., & Liu, H. (2018). Sample size and measurement occasion planning for latent change score models through Monte Carlo simulation. In E. Ferrer, S. M. Boker, and K. J. Grimm (Eds.), Advances in longitudinal models for multivariate psychology: A festschrift for Jack McArdle (pp. 189-211). New York, NY: Routledge.

Examples

## Not run: 
powerBLCS(R=1000)

## End(Not run)

Power analysis for univariate latent change score models

Description

Calculate power for univariate latent change score models based on Monte Carlo simulation.

Usage

powerLCS(N=100, T=5, R=1000, betay=0, my0=0, mys=0, 
varey=1, vary0=1, varys=1, vary0ys=0, alpha=0.05, ...)

Arguments

N

Sample size, can be a scalar or a vector. For better performance, make sure N is at least two times of T

T

Number of times, occasions or waves of measurements, can be a scalar or a vector

R

Number of replications to run in Monte Carlo simulation. Recommended 1000 or more

betay

Population parameter values

my0

Population parameter values

mys

Population parameter values

varey

Population parameter values

vary0

Population parameter values

varys

Population parameter values

vary0ys

Population parameter values

alpha

Significance level

...

Options can be used for lavaan

Value

model

The lavaan model specification of the bivariate latent change score model

lavaan

The lavaan output

ram

Output in terms of RAM matrices

References

Zhang, Z., & Liu, H. (2018). Sample size and measurement occasion planning for latent change score models through Monte Carlo simulation. In E. Ferrer, S. M. Boker, and K. J. Grimm (Eds.), Advances in longitudinal models for multivariate psychology: A festschrift for Jack McArdle (pp. 189-211). New York, NY: Routledge.

Examples

## Not run: 
powerLCS(R=1000)

## End(Not run)

RAM model to lavaan model

Description

Convert RAM matrix specification to a lavaan model

Usage

ram2lavaan(model)

Arguments

model

An ram model

References

Yves Rosseel (2012). lavaan: An R Package for Structural Equation Modeling. Journal of Statistical Software, 48(2), 1-36. URL http://www.jstatsoft.org/v48/i02/.

Zhang, Z., Hamagami, F., Grimm, K. J., & McArdle, J. J. (2015). Using R package RAMpath for tracing SEM path diagrams and conducting complex longitudinal data analysis. Structural Equation Modeling, 22(1), 132-147. https://doi.org/10.1080/10705511.2014.935257


Conduct bivariate latent change score analysis

Description

Conduct bivariate latent change score analysis

Usage

ramBLCS(data, y, x, timey, timex, ram.out = FALSE, betax, 
betay, gammax, gammay, mx0, mxs, my0, mys, varex, varey, 
varx0, vary0, varxs, varys, varx0y0, varx0xs, vary0ys, 
varx0ys, vary0xs, varxsys, ...)

Arguments

data

Data

y

Indices for y variables

x

Indices for x variables

timey

Time for y variables

timex

Time for x variables

ram.out

whether print ram matrices

betax

Starting value

betay

Starting value

gammax

Starting value

gammay

Starting value

mx0

Starting value

mxs

Starting value

my0

Starting value

mys

Starting value

varex

Starting value

varey

Starting value

varx0

Starting value

vary0

Starting value

varxs

Starting value

varys

Starting value

varx0y0

Starting value

varx0xs

Starting value

vary0ys

Starting value

varx0ys

Starting value

vary0xs

Starting value

varxsys

Starting value

...

Options can be used for lavaan

Value

model

The lavaan model specification of the bivariate latent change score model

lavaan

The lavaan output

ram

Output in terms of RAM matrices

References

Zhang, Z., Hamagami, F., Grimm, K. J., & McArdle, J. J. (2015). Using R package RAMpath for tracing SEM path diagrams and conducting complex longitudinal data analysis. Structural Equation Modeling, 22(1), 132-147. https://doi.org/10.1080/10705511.2014.935257

Examples

data(ex3)
## Test the bivariate latent change score model ramBLCS

test.blcs<-ramBLCS(ex3, 7:12, 1:6, ram.out=TRUE)
summary(test.blcs$lavaan, fit=TRUE)

bridge<-ramPathBridge(test.blcs$ram, allbridge=FALSE,indirect=FALSE)
## uncomment to plot
## plot(bridge, 'blcs')


## Test the vector field plot
## test.blcs is the output of the ramBLCS function.
ramVF(test.blcs, c(0,80),c(0,80), length=.05, xlab='X', ylab='Y',scale=.5, ninterval=9)

Sobel standard error for a given effect

Description

Sobel standard error for a given effect

Usage

ramEffectSE(object, effect, path=TRUE)

Arguments

object

An RAM path bridge output

effect

The effect to calculate se for. It is in the form a > b > c.

path

se for the direct and indirect effect.


Fit a model using lavaan based on ram input

Description

Fit a model using lavaan based on ram input

Usage

ramFit(ramModel, data, type=c('ram','lavaan'), digits = 3, zero.print = "0", ...)

Arguments

ramModel

An ram model

data

data

type

ram: specify a ram model; lavaan: specify a lavaan model

digits

Digits for print

zero.print

Format of zeros

...

Options for lavaan

Value

A and Ase

A matrix and its standard error

S and Sse

S matrix and its standard error

lavaan

Original lavaan output

fit

Model fit statistics and indices

References

Yves Rosseel (2012). lavaan: An R Package for Structural Equation Modeling. Journal of Statistical Software, 48(2), 1-36. URL http://www.jstatsoft.org/v48/i02/.

Zhang, Z., Hamagami, F., Grimm, K. J., & McArdle, J. J. (2015). Using R package RAMpath for tracing SEM path diagrams and conducting complex longitudinal data analysis. Structural Equation Modeling, 22(1), 132-147. https://doi.org/10.1080/10705511.2014.935257

Examples

## Example 1. A path model
data(ex1)
m1<-'
manifest=3
label=age,hvlt,ept
arrow(2,1)=?
arrow(3,1)=?
arrow(3,2)=?
sling(1,1)=?
sling(2,2)=?
sling(3,3)=?
'

## Fit the model
res1<-ramFit(m1, ex1)

## More output from Lavaan
summary(res1$lavaan, fit=TRUE)

## Effects and variance decomposition
bridge<-ramPathBridge(res1, allbridge=TRUE, indirect=TRUE)
summary(bridge)
summary(bridge, type='bridge')

## plot the path diagram
## uncomment to plot
## plot(bridge, 'ex1')

## plot the effects from age to ept
## uncomment to plot
## plot(bridge, 'ex1effect', 'age','ept')

## plot the bridges for ept
## uncomment to plot
## plot(bridge, 'ex1bridge', 'ept','hvlt', type='bridge')

## summarize
summary(bridge)
summary(bridge, type='bridge')


## Example 2: An SEM model (MIMIC model)
data(ex2)
## Using lavaan directly for model estimation and specification
mimic<-'
R =~ ws1 + ls1 + lt1
R ~ edu + gender
'

mimic.res<-sem(mimic, data=ex2)

mimic.ram<-lavaan2ram(mimic.res)

## plot the path diagram
bridge<-ramPathBridge(mimic.ram, allbridge=FALSE, indirect=FALSE)
## uncomment to plot
## plot(bridge, 'mimic')

Flip the ram path

Description

Flip the ram path

Usage

ramFlip(input)

Arguments

input

An ram path


To be added

Description

To be added

Usage

ramIndex(input)

Arguments

input

To be added


Conduct growth curve analysis

Description

Conduct growth curve analysis

Usage

ramLCM(data, outcome, model = c("all", "no", "linear", "quadratic", "latent"), 
basis = 0:(length(outcome) - 1), predictor, equal.var = TRUE, digits = 3, 
ram.out = FALSE, ...)

Arguments

data

Data

outcome

Outcome variable indices

model

Models to fit

basis

Basis coefficients

predictor

Covariates as predictors

equal.var

Set residual variances to be equal

digits

Print digits

ram.out

Print ram matrices

...

Options can be used for lavaan

Value

model

The lavaan model specification of the bivariate latent change score model

lavaan

The lavaan output

ram

Output in terms of RAM matrices

fit

Model fit

References

Zhang, Z., Hamagami, F., Grimm, K. J., & McArdle, J. J. (2015). Using R package RAMpath for tracing SEM path diagrams and conducting complex longitudinal data analysis. Structural Equation Modeling, 22(1), 132-147. https://doi.org/10.1080/10705511.2014.935257

Examples

data(ex3)
## Example 3. Growth curve models
gcm.all<-ramLCM(ex3, 1:6, ram.out=TRUE)
## plot the path diagram
bridge<-ramPathBridge(gcm.all$ram$latent, FALSE, FALSE)
## uncomment to plot
## plot(bridge, 'latent')

##unequal variance
gcm.all<-ramLCM(ex3, 1:6, ram.out=TRUE, equal.var=FALSE)

## missing data
gcm.all<-ramLCM(ex3, c(1,2,4,6), basis=c(1,2,4,6), ram.out=TRUE)

gcm.l<-ramLCM(ex3, 1:6, model='linear', ram.out=TRUE)

## with a predictor
gcm.pred<-ramLCM(ex3, c(1,2,4,6), model='linear', basis=c(1,2,4,6), 
                 predictor=c(3,5), ram.out=TRUE)
bridge3<-ramPathBridge(gcm.pred$ram$linear)
## uncomment to plot
## plot(bridge3, 'gcmlinear')

Univariate latent change score model

Description

Univariate latent change score model

Usage

ramLCS(data, y, timey, ram.out = FALSE, betay, my0, mys, 
varey, vary0, varys, vary0ys, ...)

Arguments

data

data

y

y data

timey

time of y

ram.out

Whether print ram matrices

betay

Starting value

my0

Starting value

mys

Starting value

varey

Starting value

vary0

Starting value

varys

Starting value

vary0ys

Starting value

...

Options can be used for lavaan

Value

model

The lavaan model specification of the bivariate latent change score model

lavaan

The lavaan output

ram

Output in terms of RAM matrices

References

Zhang, Z., Hamagami, F., Grimm, K. J., & McArdle, J. J. (2015). Using R package RAMpath for tracing SEM path diagrams and conducting complex longitudinal data analysis. Structural Equation Modeling, 22(1), 132-147. https://doi.org/10.1080/10705511.2014.935257

Examples

data(ex3)
test.lcs<-ramLCS(ex3, 7:12)
summary(test.lcs$lavaan, fit=TRUE)

bridge<-ramPathBridge(test.lcs$ram, allbridge=FALSE, indirect=FALSE)
## uncomment to plot
## plot(bridge, 'lcs')

Generate ram matrices based on ram input

Description

Generate ram matrices based on ram input

Usage

ramMatrix(model)

Arguments

model

An ram model


lavaan to ram

Description

lavaan to ram matrices

Usage

ramParseLavaan(input, manifest, type = 0)

Arguments

input

lavaan input

manifest

observed variables

type

0: single headed arrow, ...


Generate path and bridges

Description

Generate path and bridges

Usage

ramPathBridge(rammatrix, allbridge = FALSE, indirect = TRUE)

Arguments

rammatrix

RAM matrices

allbridge

Generate all bridges

indirect

Generate all indirect effects


Refit a model with additional paths

Description

Generate a vector field plot based on the bivariate lcsm

Usage

ramReFit(object, add, ram.out=FALSE, ...)

Arguments

object

Output from any data analysis

add

Additional paths to be added, e.g., add='X1~~X2'.

ram.out

Whether to print the RAM matrices

...

Options for plot and arrows function.

Examples

data(ex3)
gcm.l<-ramLCM(ex3, 1:6, model='linear', ram.out=TRUE)
## Add correlated errors
ramReFit(gcm.l, add='X1~~X2')

Internal function

Description

Internal function

Usage

ramRmOne(input)

Arguments

input

Internal function


Show the model using Lavvan model syntax

Description

Show the model using Lavvan model syntax

Usage

ramShowModel(object)

Arguments

object

Output from any data analysis

References

Yves Rosseel (2012). lavaan: An R Package for Structural Equation Modeling. Journal of Statistical Software, 48(2), 1-36. URL http://www.jstatsoft.org/v48/i02/.

Zhang, Z., Hamagami, F., Grimm, K. J., & McArdle, J. J. (2015). Using R package RAMpath for tracing SEM path diagrams and conducting complex longitudinal data analysis. Structural Equation Modeling, 22(1), 132-147. https://doi.org/10.1080/10705511.2014.935257

Examples

data(ex3)
gcm.l<-ramLCM(ex3, 1:6, model='linear', ram.out=TRUE)
## Add correlated errors
ramShowModel(gcm.l)

Get the uniques paths

Description

Get the uniques paths

Usage

ramUniquePath(tPathlist)

Arguments

tPathlist

The path list.


Generate a vector field plot based on the bivariate lcsm

Description

Generate a vector field plot based on the bivariate lcsm

Usage

ramVF(ramout, ylim, xlim, ninterval=10, scale=.1, length=.25, 
scatter=TRUE, n=20, alpha=.95, ...)

Arguments

ramout

Output from the ramBLCS function

ylim

Range of y data, for example, c(0,80) from 0 to 80

xlim

Range of x data, for example, c(0,80) from 0 to 80

ninterval

Number of intervals for plotting. The default is 10.

scale

Time interval to calculate vector fields.

length

The length of arrows to plot

scatter

Whether to plot the data points

n

The number of data points to be plotted

alpha

The confidence level to calculate the ellipse

...

Options for plot and arrows function.

References

Zhang, Z., Hamagami, F., Grimm, K. J., & McArdle, J. J. (2015). Using R package RAMpath for tracing SEM path diagrams and conducting complex longitudinal data analysis. Structural Equation Modeling, 22(1), 132-147. https://doi.org/10.1080/10705511.2014.935257

Examples

data(ex3)
test.blcs<-ramBLCS(ex3, 1:6, 7:12, ram.out=TRUE)
ramVF(test.blcs, c(0,80),c(0,80), length=.05, xlab='X', ylab='Y',scale=.5, ninterval=9)

Calculate the total and individual contribution for each path and bridge

Description

Calculate the total and individual contribution for each path and bridge

Usage

## S3 method for class 'RAMpath'
summary(object, from, to, type = c("path", "bridge"), se=FALSE, ...)

Arguments

object

Output from the ramPathBridge function

from

from variable: starting from this variable

to

to variable: end on this variable

type

path: to calculate the effect; bridge: to calculate the bridges

se

Whether to generate se for direct and indirect effects.

...

Other options