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.
- Version:
- $Id: $Id
- Author:
- Frank Wimberly, Ricardo Silva, josephramsey
- 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) Constructor for SemIm. -
Method Summary
Modifier and TypeMethodDescriptionboolean
existsEdgeCoef
(Node x, Node y) existsEdgeCoef.double
getBicScore.double
getCfi()
getCfi.double
getChiSquare.Getter for the fieldedgeCoef
.double
getEdgeCoef
(Edge edge) Getter for the fieldedgeCoef
.double
getEdgeCoef
(Node x, Node y) Getter for the fieldedgeCoef
.Getter for the fielderrCovar
.double
getErrCovar
(Node x, Node y) Getter for the fielderrCovar
.double
getErrVar.Getter for the fieldfixedParameters
.Getter for the fieldfreeParameters
.double[]
getFreeParamValues.getImplCovar
(boolean recalculate) getImplCovar.getImplCovar
(List<Node> nodes) Getter for the fieldimplCovar
.getImplCovarMeas.double
getIntercept
(Node node) getIntercept.double
getMean.double[]
getMeans()
getMeans.double
getMeanStdDev
(Node node) getMeanStdDev.The list of measured nodes for the semPm.int
getNumFixedParams.int
getNumFreeParams.int
Getter for the fieldnumRandomCalls
.getParameterNames.Getter for the fieldparams
.double
getParamValue
(Node nodeA, Node nodeB) getParamValue.double
getParamValue
(Parameter parameter) getParamValue.double
getPValue.double
getPValue.double
getRmsea()
getRmsea.getSampleCovar.int
Getter for the fieldsampleSize
.double
getScore()
The value of the maximum likelihood function for the getModel the model (Bollen 107).getSemPm()
Getter for the fieldsemPm
.double
getStandardError
(Parameter parameter, int maxFreeParams) getStandardError.double
getStdDev.double
The negative of the log likelihood function for the getModel model, with the constant chopped off.double
getTValue.double[]
Getter for the fieldvariableMeans
.getVariableNode
(String name) getVariableNode.The list of measured and latent nodes for the semPm.double
getVariance
(Node node, Matrix implCovar) getVariance.void
Iterates through all freeParameters, picking values for them from the distributions that have been set for them.boolean
isCyclic()
isCyclic.boolean
isEstimated.boolean
isParameterBoundsEnforced.boolean
isSimulatedPositiveDataOnly.listUnmeasuredLatents.static SemIm
retainValues
(SemIm semIm, SemGraph graph) Constructs a new SEM IM with the given graph, retaining parameter values fromsemIm
for nodes of the same name and edges connecting nodes of the same names.static SemIm
Generates a simple exemplar of this class to test serialization.void
setCovMatrix
(ICovarianceMatrix covMatrix) Sets the sample covariance matrix for this Sem as a submatrix of the given matrix.void
setDataSet
(DataSet dataSet) Calculates the covariance matrix of the given DataSet and sets the sample covariance matrix for this model to a subset of it.void
setEdgeCoef
(Node x, Node y, double value) setEdgeCoef.void
setErrCovar
(Node x, double value) Setter for the fielderrCovar
.void
setErrCovar
(Node x, Node y, double value) Setter for the fielderrCovar
.void
setErrVar.void
setEstimated
(boolean estimated) Setter for the fieldestimated
.void
setFixedParamValue
(Parameter parameter, double value) setFixedParamValue.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.void
setIntercept
(Node node, double intercept) setIntercept.void
setMean.void
setMeanStandardDeviation
(Node node, double mean) Sets the mean associated with the given node.void
setParameterBoundsEnforced
(boolean parameterBoundsEnforced) setParameterBoundsEnforced.void
setParams
(Parameters params) Setter for the fieldparams
.void
setParamValue
(Node nodeA, Node nodeB, double value) setParamValue.void
setParamValue
(Parameter parameter, double value) setParamValue.void
setScoreType
(ScoreType scoreType) Setter for the fieldscoreType
.simulateData
(int sampleSize, boolean latentDataSaved) Simulates data from the model associated with this object.simulateDataCholesky
(int sampleSize, boolean latentDataSaved) Simulates data from this Sem using a Cholesky decomposition of the implied covariance matrix.simulateDataRecursive
(int sampleSize, boolean latentDataSaved) simulateDataRecursive.simulateDataReducedForm
(int sampleSize, boolean latentDataSaved) simulateDataReducedForm.simulateOneRecord.toString()
toString.updatedIm.
-
Constructor Details
-
SemIm
Constructs a new SEM IM from a SEM PM.- Parameters:
semPm
- aSemPm
object
-
SemIm
Constructs a new SEM IM from the given SEM PM, using the given params object to guide the choice of parameter values.- Parameters:
semPm
- aSemPm
objectparams
- aParameters
object
-
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.- Parameters:
semPm
- aSemPm
objectoldSemIm
- aSemIm
objectparameters
- aParameters
object
-
SemIm
Constructs a SEM model using the given SEM PM and sample covariance matrix.- Parameters:
semPm
- aSemPm
objectcovMatrix
- aICovarianceMatrix
object
-
SemIm
Copy constructor.- Parameters:
semIm
- aSemIm
object- Throws:
RuntimeException
- if the given SemIm cannot be serialized and deserialized correctly.
-
SemIm
public SemIm(SemPm semPm, List<Node> variableNodes, List<Node> measuredNodes, Matrix edgeCoef, double[] variableMeansStdDev) Constructor for SemIm.
-
-
Method Details
-
getParameterNames
getParameterNames.
- Returns:
- a
List
object
-
retainValues
Constructs a new SEM IM with the given graph, retaining parameter values fromsemIm
for 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.- Returns:
- a
SemIm
object
-
updatedIm
updatedIm.
-
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.- Parameters:
covMatrix
- aICovarianceMatrix
object
-
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.- Parameters:
dataSet
- aDataSet
object
-
getSemPm
Getter for the field
semPm
. -
getFreeParamValues
public double[] getFreeParamValues()getFreeParamValues.
- Specified by:
getFreeParamValues
in 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:
setFreeParamValues
in interfaceISemIm
- Parameters:
params
- an array ofinvalid reference
double
-
getParamValue
getParamValue.
Gets the value of a single free parameter, or Double.NaN if the parameter is not in this
- Specified by:
getParamValue
in interfaceISemIm
- Parameters:
parameter
- aParameter
object- Returns:
- a double
-
setParamValue
setParamValue.
Sets the value of a single free parameter to the given value.
- Specified by:
setParamValue
in interfaceISemIm
- Parameters:
parameter
- aParameter
objectvalue
- a double
-
setFixedParamValue
setFixedParamValue.
Sets the value of a single free parameter to the given value.
- Specified by:
setFixedParamValue
in interfaceISemIm
- Parameters:
parameter
- aParameter
objectvalue
- a double
-
getErrVar
getErrVar.
- Parameters:
x
- aNode
object- Returns:
- a double
-
getErrCovar
Getter for the field
errCovar
. -
getEdgeCoef
Getter for the field
edgeCoef
. -
getEdgeCoef
Getter for the field
edgeCoef
.- Parameters:
edge
- aEdge
object- Returns:
- a double
-
setErrVar
setErrVar.
-
setEdgeCoef
setEdgeCoef.
- Specified by:
setEdgeCoef
in interfaceISemIm
- Parameters:
x
- aNode
objecty
- aNode
objectvalue
- a double
-
existsEdgeCoef
existsEdgeCoef.
-
setErrCovar
Setter for the field
errCovar
.- Parameters:
x
- aNode
objectvalue
- a double
-
setErrCovar
Setter for the field
errCovar
. -
setMean
setMean.
Sets the mean associated with the given node.
-
setMeanStandardDeviation
Sets the mean associated with the given node.- Parameters:
node
- aNode
objectmean
- a double
-
setIntercept
setIntercept.
Sets the intercept. For acyclic SEMs only.
- Specified by:
setIntercept
in interfaceISemIm
- Parameters:
node
- aNode
objectintercept
- a double
-
getIntercept
getIntercept.
- Specified by:
getIntercept
in interfaceISemIm
- Parameters:
node
- aNode
object- Returns:
- a double
-
getMean
getMean.
-
getMeans
public double[] getMeans()getMeans.
- Returns:
- the means for variables in order.
-
getMeanStdDev
getMeanStdDev.
- Specified by:
getMeanStdDev
in interfaceISemIm
- Parameters:
node
- aNode
object- Returns:
- a double
-
getVariance
getVariance.
- Specified by:
getVariance
in interfaceISemIm
- Parameters:
node
- aNode
objectimplCovar
- aMatrix
object- Returns:
- a double
-
getStdDev
getStdDev.
-
getParamValue
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:
getParamValue
in interfaceISemIm
- Parameters:
nodeA
- aNode
objectnodeB
- aNode
object- Returns:
- a double
-
setParamValue
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:
setParamValue
in interfaceISemIm
- Parameters:
nodeA
- aNode
objectnodeB
- aNode
objectvalue
- a double
-
getFreeParameters
Getter for the field
freeParameters
.- Specified by:
getFreeParameters
in interfaceISemIm
- Returns:
- the (unmodifiable) list of free freeParameters in the model.
-
getNumFreeParams
public int getNumFreeParams()getNumFreeParams.
- Specified by:
getNumFreeParams
in interfaceISemIm
- Returns:
- the number of free freeParameters.
-
getFixedParameters
Getter for the field
fixedParameters
.- Specified by:
getFixedParameters
in interfaceISemIm
- Returns:
- the (unmodifiable) list of fixed freeParameters in the model.
-
getNumFixedParams
public int getNumFixedParams()getNumFixedParams.
- Returns:
- the number of free freeParameters.
-
getVariableNodes
The list of measured and latent nodes for the semPm. (Unmodifiable.)- Specified by:
getVariableNodes
in interfaceISemIm
- Returns:
- a
List
object
-
getMeasuredNodes
The list of measured nodes for the semPm. (Unmodifiable.)- Specified by:
getMeasuredNodes
in interfaceISemIm
- Returns:
- a
List
object
-
getSampleSize
public int getSampleSize()Getter for the field
sampleSize
.- Specified by:
getSampleSize
in interfaceISemIm
- Returns:
- the sample size (that is, the sample size of the CovarianceMatrix provided at construction time).
-
getEdgeCoef
Getter for the field
edgeCoef
.- 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
Getter for the field
errCovar
.- 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
getImplCovar.
- Specified by:
getImplCovar
in interfaceISemIm
- Parameters:
recalculate
- a boolean- Returns:
- a
Matrix
object
-
getImplCovarMeas
getImplCovarMeas.
- Specified by:
getImplCovarMeas
in interfaceISemIm
- Returns:
- a copy of the implied covariance matrix over the measured variables only.
-
getSampleCovar
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.- Returns:
- a double
-
getBicScore
public double getBicScore()getBicScore.
- Specified by:
getBicScore
in interfaceISemIm
- Returns:
- BIC score, calculated as chisq - dof. This is equal to getFullBicScore() up to a constant.
-
getRmsea
public double getRmsea()getRmsea.
-
getCfi
public double getCfi()getCfi.
-
getChiSquare
public double getChiSquare()getChiSquare.
- Specified by:
getChiSquare
in interfaceISemIm
- Returns:
- the chi square value for the model.
-
getPValue
public double getPValue()getPValue.
-
simulateData
Simulates data from the model associated with this object.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:
simulateData
in interfaceSimulator
- Parameters:
sampleSize
- the number of rows to simulate.latentDataSaved
- if true, latent variables are saved in the data set.- Returns:
- the simulated data set.
-
setScoreType
Setter for the field
scoreType
.- Parameters:
scoreType
- aScoreType
object
-
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.- Returns:
- a
DataSet
object
-
simulateDataRecursive
simulateDataRecursive.
- Parameters:
sampleSize
- a intlatentDataSaved
- a boolean- Returns:
- a
DataSet
object
-
simulateDataReducedForm
simulateDataReducedForm.
- Parameters:
sampleSize
- a intlatentDataSaved
- a boolean- Returns:
- a
DataSet
object
-
simulateOneRecord
simulateOneRecord.
-
initializeValues
public void initializeValues()Iterates through all freeParameters, picking values for them from the distributions that have been set for them. -
getStandardError
getStandardError.
- Specified by:
getStandardError
in interfaceISemIm
- Parameters:
parameter
- aParameter
objectmaxFreeParams
- a int- Returns:
- a double
-
listUnmeasuredLatents
listUnmeasuredLatents.
- Specified by:
listUnmeasuredLatents
in interfaceISemIm
- Returns:
- a
List
object
-
getTValue
getTValue.
-
getPValue
getPValue.
-
isParameterBoundsEnforced
public boolean isParameterBoundsEnforced()isParameterBoundsEnforced.
- Specified by:
isParameterBoundsEnforced
in interfaceISemIm
- Returns:
- a boolean
-
setParameterBoundsEnforced
public void setParameterBoundsEnforced(boolean parameterBoundsEnforced) setParameterBoundsEnforced.
- Specified by:
setParameterBoundsEnforced
in interfaceISemIm
- Parameters:
parameterBoundsEnforced
- a boolean
-
isEstimated
public boolean isEstimated()isEstimated.
- Specified by:
isEstimated
in interfaceISemIm
- Returns:
- a boolean
-
setEstimated
public void setEstimated(boolean estimated) Setter for the field
estimated
.- Parameters:
estimated
- a boolean
-
isCyclic
public boolean isCyclic()isCyclic.
-
getVariableNode
getVariableNode.
- Parameters:
name
- aString
object- Returns:
- the variable by the given name, or null if none exists.
- Throws:
NullPointerException
- if name is null.
-
toString
toString.
-
getParams
Getter for the field
params
.- Returns:
- a
Parameters
object
-
setParams
Setter for the field
params
.- Parameters:
params
- aParameters
object
-
getVariableMeans
public double[] getVariableMeans()Getter for the field
variableMeans
.- Returns:
- an array of
invalid reference
double
-
isSimulatedPositiveDataOnly
public boolean isSimulatedPositiveDataOnly()isSimulatedPositiveDataOnly.
- Specified by:
isSimulatedPositiveDataOnly
in interfaceISemIm
- Returns:
- a boolean
-
getImplCovar
Getter for the field
implCovar
. -
getNumRandomCalls
public int getNumRandomCalls()Getter for the field
numRandomCalls
.- Returns:
- a int
-