Calculates partial correlations and partial significance tests.

cerror(formula., modelList, data = NULL)

Arguments

formula.

A formula specifying the two correlated variables using %~~%.

modelList

A list of structural equations.

data

A data.frame containing the data used in the list of equations.

Value

Returns a data.frame containing the (partial) correlation and associated significance test.

Details

If the variables are exogenous, then the correlated error is the raw bivariate correlation.

If the variables are endogenous, then the correlated error is the partial correlation, accounting for the influence of any predictors.

The significance of the correlated error is conducted using cor.test if the variables are exogenous. Otherwise, a t-statistic is constructed and compared to a t-distribution with N - k - 2 degrees of freedom (where N is the total number of replicates, and k is the total number of variables informing the relationship) to derive a P-value.

See also

Author

Jon Lefcheck <lefcheckj@si.edu>

Examples

# Generate example data
dat <- data.frame(x1 = runif(50),
  x2 = runif(50), y1 = runif(50),
    y2 = runif(50))

# Create list of structural equations
sem <- psem(
  lm(y1 ~ x1 + x2, dat),
  lm(y2 ~ y1 + x1, dat)
)

# Look at correlated error between x1 and x2
# (exogenous)
cerror(x1 %~~% x2, sem, dat)
#>    Response Predictor  Estimate Std.Error DF Crit.Value    P.Value 
#> df     ~~x1      ~~x2 0.2539324        NA 48   1.818915 0.07516568 

# Same as cor.test
with(dat, cor.test(x1, x2))
#> 
#> 	Pearson's product-moment correlation
#> 
#> data:  x1 and x2
#> t = 1.8189, df = 48, p-value = 0.07517
#> alternative hypothesis: true correlation is not equal to 0
#> 95 percent confidence interval:
#>  -0.02627233  0.49714138
#> sample estimates:
#>       cor 
#> 0.2539324 
#> 

# Look at correlatde error between x1 and y1
# (endogenous)
cerror(y1 %~~% x1, sem, dat)
#> Error in is.data.frame(data): object 'dat' not found

# Not the same as cor.test
# (accounts for influence of x1 and x2 on y1)
with(dat, cor.test(y1, x1))
#> 
#> 	Pearson's product-moment correlation
#> 
#> data:  y1 and x1
#> t = -0.97372, df = 48, p-value = 0.3351
#> alternative hypothesis: true correlation is not equal to 0
#> 95 percent confidence interval:
#>  -0.4019525  0.1447802
#> sample estimates:
#>        cor 
#> -0.1391762 
#> 

# Specify in psem
sem <- update(sem, x1 %~~% y1)

coefs(sem)
#> Error in is.data.frame(data): object 'dat' not found