If you have no full dataset, but you do have a sample covariance matrix, you can still fit your model. If you wish to add a mean structure, you need to provide a mean vector too. Importantly, if only sample statistics are provided, you must specify the number of observations that were used to compute the sample moments. The following example illustrates the use of a sample covariance matrix as input. First, we read in the lower half of the covariance matrix (including the diagonal):
Warning: 'getCov' is deprecated.
Use 'lav_getcov' instead.
See help("Deprecated")
The getCov() function makes it easy to create a full covariance matrix (including variable names) if you only have the lower-half elements (perhaps pasted from a textbook or a paper). Note that the lower-half elements are written between two single quotes. Therefore, you have some additional flexibility. You can add comments, and blank lines. If the numbers are separated by a comma, or a semi-colon, that is fine too. For more information about getCov(), see the online manual page.
Next, we can specify our model, estimate it, and request a summary of the results:
If the estimator is ML (the default), then the sample variance-covariance matrix will be rescaled by a factor (N-1)/N. The reasoning is the following: the elements in a sample variance-covariance matrix have (usually) been divided by N-1. But the (normal-based) ML estimator would divide the elements by N. Therefore, we need to rescale. If you don’t want this to happen (for example in a simulation study), you can provide the argument sample.cov.rescale = FALSE.
Multiple groups
If you have multiple groups, the sample.cov argument must be a list containing the sample variance-covariance matrix of each group as a separate element in the list. If a mean structure is needed, the sample.mean argument must be a list containing the sample means of each group. Finally, the sample.nobs argument can be either a list or an integer vector containing the number of observations for each group.