Learn R Programming

stremo (version 0.2)

fit.nlminb: Fit a structural equation model using nlminb.

Description

This function tries to find the best set of parameter estimates of a structural equation model. It is very slow compared to sem in lavaan and does not handle equality constraints, multiple groups and intercepts. We made this to aid those who are learning SEM to understand the very basics of the technique. Please refer to lavaan for more serious usage.

Usage

fit.nlminb(model, sigma, n, fun = "fml")

Arguments

model
A character vector containing a model specification.
sigma
Population covariance matrix.
n
Number of observations in the dataset used to build sigma.
fun
Fitting function to be minimised by the optimiser. Should return a scalar.

Value

model
The internal representation of the model
est
The best set of parameter estimates
se
Standard errors
z
Z-values
p
P-values
chisquared
The maximum likelihood chi-squared
df
The number of degrees of freedom
n
The number of observations
pval
The significance of the chi-squared statistics
estimator
The fitting function used
sigma.hat
The model-implied covariance matrix
sigma
The population covariance matrix

Details

This function is coded to be as expressive as possible and speed has not been our aim here. Users should be able to understand at least some of what is going on internally by taking a peak at the code.

The first thing this function does is to call lavaan to get a good set of starting values for the parameters to be estimated and use lavaan's internal representation of a SEM model as a starting point. After that, the chosen function calls an optimiser, nlminb, which will try to converge to a solution given a set of parameter estimates and a population covariance matrix. Then, it will try to calculate standard errors from the Hessian matrix, z-values for each estimate and its correspondent p-values. The next step is to calculate the fit of the model to, finally, build a response.

See Also

sem in lavaan is much faster and converges to a unique solution more frequently. It can also handle a much more diverse range of models, including those with multiple groups, equality constraints, growth models and so on.

Examples

Run this code

## Not run: 
# data(albert)
# cat(albert.model)
# fit <- fit.nlminb(albert.model, albert.litho.cov, 107)
# summary(fit)
# ## End(Not run)

Run the code above in your browser using DataLab