Learn R Programming

lavaSearch2 (version 1.0.0)

addLink: Add a New Link Between Two Variables in a LVM

Description

Generic interface to add links to lvm objects.

Usage

addLink(x, ...)

# S3 method for lvm addLink(x, var1, var2, covariance, allVars = vars(x), warnings = FALSE, ...)

# S3 method for lvm.reduced addLink(x, ...)

Arguments

x

a lvm model

...

additional arguments to be passed to lower levels functions.

var1

the first variable (character) or a formula describing the link to be added to the lvm

var2

the second variable (character). Only used if var1 is a character.

covariance

does the link is bidirectional. Ignored if one of the variable is exogenous.

allVars

all the existing variables.

warnings

should a warning be displayed when no link is added

Details

The argument allVars is useful for lvm.reduce object where the command vars(x) does not return all variables. The command vars(x, xlp = TRUE) must be used instead.

Examples

Run this code
# NOT RUN {
library(lava)
set.seed(10)

m <- lvm()
regression(m) <- c(y1,y2,y3)~u
regression(m) <- u~x1+x2
latent(m) <- ~u
m2 <- m

addLink(m, x1 ~ y1, covariance = FALSE)
addLink(m, y1 ~ x1, covariance = FALSE)
coef(addLink(m, y1 ~ y2, covariance = TRUE))

addLink(m2, "x1", "y1", covariance = FALSE)
addLink(m2, "y1", "x1", covariance = FALSE)
newM <- addLink(m, "y1", "y2", covariance = TRUE)
coef(newM)
# }

Run the code above in your browser using DataLab