Class SemIm
- All Implemented Interfaces:
Simulator,ISemIm,Im,TetradSerializable,Serializable
Let V be the set of variables in the model. The freeParameters of the model are as follows: (a) the list of linear coefficients for all edges u-->v in the model, where u, v are in V, (b) the list of variances for all variables in V, (c) the list of all error covariances d<->e, where d an e are exogenous terms in the model (either exogenous variables or error terms for endogenous variables), and (d) the list of means for all variables in V.
It is important to note that the likelihood functions this class calculates do not depend on variable means. They depend only on edge coefficients and error covariances. Hence, variable means are treated differently from edge coefficients and error covariances in the model.
Reference: Bollen, K. A. (1989). Structural Equations with Latent Variables. New York: John Wiley and Sons.
- Author:
- Frank Wimberly, Ricardo Silva, Joseph Ramsey
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCopy constructor.Constructs a new SEM IM from a SEM PM.SemIm(SemPm semPm, ICovarianceMatrix covMatrix) Constructs a SEM model using the given SEM PM and sample covariance matrix.SemIm(SemPm semPm, SemIm oldSemIm, Parameters parameters) Constructs a new SEM IM from the given SEM PM, using the old SEM IM and params object to guide the choice of parameter values.SemIm(SemPm semPm, Parameters params) Constructs a new SEM IM from the given SEM PM, using the given params object to guide the choice of parameter values.SemIm(SemPm semPm, List<Node> variableNodes, List<Node> measuredNodes, Matrix edgeCoef, double[] variableMeansStdDev) -
Method Summary
Modifier and TypeMethodDescriptionbooleanexistsEdgeCoef(Node x, Node y) doubledoublegetCfi()doubledoublegetEdgeCoef(Edge edge) doublegetEdgeCoef(Node x, Node y) doublegetErrCovar(Node x, Node y) doubledouble[]getImplCovar(boolean recalculate) getImplCovar(List<Node> nodes) doublegetIntercept(Node node) doubledouble[]getMeans()doublegetMeanStdDev(Node node) The list of measured nodes for the semPm.intintdoublegetParamValue(Node nodeA, Node nodeB) Gets the value of a single free parameter to the given value, where the free parameter is specified by the endpoint nodes of its edge in the w graph.doublegetParamValue(Parameter parameter) Gets the value of a single free parameter, or Double.NaN if the parameter is not in thisdoubledoubledoublegetRmsea()intdoublegetScore()The value of the maximum likelihood function for the getModel the model (Bollen 107).getSemPm()doublegetStandardError(Parameter parameter, int maxFreeParams) doubledoubleThe negative of the log likelihood function for the getModel model, with the constant chopped off.doubledouble[]getVariableNode(String name) The list of measured and latent nodes for the semPm.doublegetVariance(Node node, Matrix implCovar) voidIterates through all freeParameters, picking values for them from the distributions that have been set for them.booleanisCyclic()booleanbooleanbooleanstatic SemImretainValues(SemIm semIm, SemGraph graph) Constructs a new SEM IM with the given graph, retaining parameter values fromsemImfor nodes of the same name and edges connecting nodes of the same names.static SemImGenerates a simple exemplar of this class to test serialization.voidsetCovMatrix(ICovarianceMatrix covMatrix) Sets the sample covariance matrix for this Sem as a submatrix of the given matrix.voidsetDataSet(DataSet dataSet) Calculates the covariance matrix of the given DataSet and sets the sample covariance matrix for this model to a subset of it.voidsetEdgeCoef(Node x, Node y, double value) voidsetErrCovar(Node x, double value) voidsetErrCovar(Node x, Node y, double value) voidvoidsetEstimated(boolean estimated) voidsetFixedParamValue(Parameter parameter, double value) Sets the value of a single free parameter to the given value.voidsetFreeParamValues(double[] params) Sets the values of the free freeParameters (in the order in which they appear in getFreeParameters()) to the values contained in the given array.voidsetIntercept(Node node, double intercept) Sets the intercept.voidSets the mean associated with the given node.voidsetMeanStandardDeviation(Node node, double mean) Sets the mean associated with the given node.voidsetParameterBoundsEnforced(boolean parameterBoundsEnforced) voidsetParams(Parameters params) voidsetParamValue(Node nodeA, Node nodeB, double value) Sets the value of a single free parameter to the given value, where the free parameter is specified by the endpoint nodes of its edge in the graph.voidsetParamValue(Parameter parameter, double value) Sets the value of a single free parameter to the given value.voidsetScoreType(ScoreType scoreType) simulateData(int sampleSize, boolean latentDataSaved) This simulate method uses the implied covariance metrix directly to simulate data, instead of going tier by tier.simulateDataCholesky(int sampleSize, boolean latentDataSaved) Simulates data from this Sem using a Cholesky decomposition of the implied covariance matrix.simulateDataRecursive(int sampleSize, boolean latentDataSaved) simulateDataReducedForm(int sampleSize, boolean latentDataSaved) toString()
-
Constructor Details
-
SemIm
Constructs a new SEM IM from a SEM PM. -
SemIm
Constructs a new SEM IM from the given SEM PM, using the given params object to guide the choice of parameter values. -
SemIm
Constructs a new SEM IM from the given SEM PM, using the old SEM IM and params object to guide the choice of parameter values. If old values are retained, they are gotten from the old SEM IM. -
SemIm
Constructs a SEM model using the given SEM PM and sample covariance matrix. -
SemIm
Copy constructor.- Throws:
RuntimeException- if the given SemIm cannot be serialized and deserialized correctly.
-
SemIm
-
-
Method Details
-
getParameterNames
-
retainValues
Constructs a new SEM IM with the given graph, retaining parameter values fromsemImfor nodes of the same name and edges connecting nodes of the same names.- Parameters:
semIm- The old SEM IM.graph- The graph for the new SEM IM.- Returns:
- The new SEM IM, retaining values from
semIm.
-
serializableInstance
Generates a simple exemplar of this class to test serialization. -
updatedIm
- Returns:
- a variant of the getModel model with the given covariance matrix and means. Used for updating.
-
setCovMatrix
Sets the sample covariance matrix for this Sem as a submatrix of the given matrix. The variable names used in the SemPm for this model must all appear in this CovarianceMatrix. -
setDataSet
Calculates the covariance matrix of the given DataSet and sets the sample covariance matrix for this model to a subset of it. The measured variable names used in the SemPm for this model must all appear in this data set. -
getSemPm
-
getFreeParamValues
public double[] getFreeParamValues()- Specified by:
getFreeParamValuesin interfaceISemIm- Returns:
- an array containing the getModel values for the free freeParameters, in the order in which the freeParameters appear in getFreeParameters(). That is, getFreeParamValues()[i] is the value for getFreeParameters()[i].
-
setFreeParamValues
public void setFreeParamValues(double[] params) Sets the values of the free freeParameters (in the order in which they appear in getFreeParameters()) to the values contained in the given array. That is, params[i] is the value for getFreeParameters()[i].- Specified by:
setFreeParamValuesin interfaceISemIm
-
getParamValue
Gets the value of a single free parameter, or Double.NaN if the parameter is not in this- Specified by:
getParamValuein interfaceISemIm- Throws:
IllegalArgumentException- if the given parameter is not a free parameter in this model.
-
setParamValue
Sets the value of a single free parameter to the given value.- Specified by:
setParamValuein interfaceISemIm- Throws:
IllegalArgumentException- if the given parameter is not a free parameter in this model.
-
setFixedParamValue
Sets the value of a single free parameter to the given value.- Specified by:
setFixedParamValuein interfaceISemIm- Throws:
IllegalArgumentException- if the given parameter is not a free parameter in this model.
-
getErrVar
-
getErrCovar
-
getEdgeCoef
-
getEdgeCoef
-
setErrVar
-
setEdgeCoef
- Specified by:
setEdgeCoefin interfaceISemIm
-
existsEdgeCoef
-
setErrCovar
-
setErrCovar
-
setMean
Sets the mean associated with the given node. -
setMeanStandardDeviation
Sets the mean associated with the given node. -
setIntercept
Sets the intercept. For acyclic SEMs only.- Specified by:
setInterceptin interfaceISemIm- Throws:
UnsupportedOperationException- if called on a cyclic SEM.
-
getIntercept
- Specified by:
getInterceptin interfaceISemIm- Returns:
- the intercept, for acyclic models, or Double.NaN otherwise.
- Throws:
UnsupportedOperationException- if called on a cyclic SEM.
-
getMean
-
getMeans
public double[] getMeans()- Returns:
- the means for variables in order.
-
getMeanStdDev
- Specified by:
getMeanStdDevin interfaceISemIm- Returns:
- the value of the mean associated with the given node.
-
getVariance
- Specified by:
getVariancein interfaceISemIm- Returns:
- the value of the variance associated with the given node.
-
getStdDev
-
getParamValue
Gets the value of a single free parameter to the given value, where the free parameter is specified by the endpoint nodes of its edge in the w graph. Note that coefficient freeParameters connect elements of getVariableNodes(), whereas variance and covariance freeParameters connect elements of getExogenousNodes(). (For variance freeParameters, nodeA and nodeB are the same.)- Specified by:
getParamValuein interfaceISemIm- Throws:
IllegalArgumentException- if the given parameter is not a free parameter in this model or if there is no parameter connecting nodeA with nodeB in this model.
-
setParamValue
Sets the value of a single free parameter to the given value, where the free parameter is specified by the endpoint nodes of its edge in the graph. Note that coefficient freeParameters connect elements of getVariableNodes(), whereas variance and covariance freeParameters connect elements of getExogenousNodes(). (For variance freeParameters, nodeA and nodeB are the same.)- Specified by:
setParamValuein interfaceISemIm- Throws:
IllegalArgumentException- if the given parameter is not a free parameter in this model or if there is no parameter connecting nodeA with nodeB in this model, or if value is Double.NaN.
-
getFreeParameters
- Specified by:
getFreeParametersin interfaceISemIm- Returns:
- the (unmodifiable) list of free freeParameters in the model.
-
getNumFreeParams
public int getNumFreeParams()- Specified by:
getNumFreeParamsin interfaceISemIm- Returns:
- the number of free freeParameters.
-
getFixedParameters
- Specified by:
getFixedParametersin interfaceISemIm- Returns:
- the (unmodifiable) list of fixed freeParameters in the model.
-
getNumFixedParams
public int getNumFixedParams()- Returns:
- the number of free freeParameters.
-
getVariableNodes
The list of measured and latent nodes for the semPm. (Unmodifiable.)- Specified by:
getVariableNodesin interfaceISemIm
-
getMeasuredNodes
The list of measured nodes for the semPm. (Unmodifiable.)- Specified by:
getMeasuredNodesin interfaceISemIm
-
getSampleSize
public int getSampleSize()- Specified by:
getSampleSizein interfaceISemIm- Returns:
- the sample size (that is, the sample size of the CovarianceMatrix provided at construction time).
-
getEdgeCoef
- Returns:
- a copy of the matrix of edge coefficients. Note that edgeCoefC[i][j] is the coefficient of the edge from getVariableNodes().get(i) to getVariableNodes().get(j), or 0.0 if this edge is not in the graph. The values of these may be changed, but the array itself may not.
-
getErrCovar
- Returns:
- a copy of the matrix of error covariances. Note that errCovar[i][j] is the covariance of the error term of getExoNodes().get(i) and getExoNodes().get(j), with the special case (duh!) that errCovar[i][i] is the variance of getExoNodes.get(i). The values of these may be changed, but the array itself may not.
-
getImplCovar
- Specified by:
getImplCovarin interfaceISemIm- Returns:
- a copy of the implied covariance matrix over all the variables.
-
getImplCovarMeas
- Specified by:
getImplCovarMeasin interfaceISemIm- Returns:
- a copy of the implied covariance matrix over the measured variables only.
-
getSampleCovar
- Returns:
- a copy of the sample covariance matrix, or null if no sample covar has been set.
-
getScore
public double getScore()The value of the maximum likelihood function for the getModel the model (Bollen 107). To optimize, this should be minimized. -
getTruncLL
public double getTruncLL()The negative of the log likelihood function for the getModel model, with the constant chopped off. (Bollen 134). This is an alternative, more efficient, optimization function to Fml which produces the same result when minimized. -
getBicScore
public double getBicScore()- Specified by:
getBicScorein interfaceISemIm- Returns:
- BIC score, calculated as chisq - dof. This is equal to getFullBicScore() up to a constant.
-
getRmsea
public double getRmsea() -
getCfi
public double getCfi() -
getChiSquare
public double getChiSquare()- Specified by:
getChiSquarein interfaceISemIm- Returns:
- the chi square value for the model.
-
getPValue
public double getPValue() -
simulateData
This simulate method uses the implied covariance metrix directly to simulate data, instead of going tier by tier. It should work for cyclic graphs as well as acyclic graphs.- Specified by:
simulateDatain interfaceSimulator
-
setScoreType
-
simulateDataCholesky
Simulates data from this Sem using a Cholesky decomposition of the implied covariance matrix. This method works even when the underlying graph is cyclic.- Parameters:
sampleSize- the number of rows of data to simulate.latentDataSaved- True iff data for latents should be saved.
-
simulateDataRecursive
-
simulateDataReducedForm
-
simulateOneRecord
-
initializeValues
public void initializeValues()Iterates through all freeParameters, picking values for them from the distributions that have been set for them. -
getStandardError
- Specified by:
getStandardErrorin interfaceISemIm
-
listUnmeasuredLatents
- Specified by:
listUnmeasuredLatentsin interfaceISemIm
-
getTValue
-
getPValue
-
isParameterBoundsEnforced
public boolean isParameterBoundsEnforced()- Specified by:
isParameterBoundsEnforcedin interfaceISemIm
-
setParameterBoundsEnforced
public void setParameterBoundsEnforced(boolean parameterBoundsEnforced) - Specified by:
setParameterBoundsEnforcedin interfaceISemIm
-
isEstimated
public boolean isEstimated()- Specified by:
isEstimatedin interfaceISemIm
-
setEstimated
public void setEstimated(boolean estimated) -
isCyclic
public boolean isCyclic() -
getVariableNode
- Returns:
- the variable by the given name, or null if none exists.
- Throws:
NullPointerException- if name is null.
-
toString
-
getParams
-
setParams
-
getVariableMeans
public double[] getVariableMeans() -
isSimulatedPositiveDataOnly
public boolean isSimulatedPositiveDataOnly()- Specified by:
isSimulatedPositiveDataOnlyin interfaceISemIm
-
getImplCovar
-