Class StandardizedSemIm

java.lang.Object
edu.cmu.tetrad.sem.StandardizedSemIm
All Implemented Interfaces:
Simulator, TetradSerializable, Serializable

public class StandardizedSemIm extends Object implements Simulator
A special SEM model in which variances of variables are always 1 and means of variables are always 0. In order to ensure that means of variables are always zero, means or error terms are set to zero. (They are alway Gaussian for this model.) Connection functions are always linear. In order to ensure that variances of variables are always 1, only coefficients are allowed to change, and the error terms take up the slack. Becuase of this constraint, given settings of other freeParameters, the range of a given parameter is always bounded above and below. The user may query this range and set set the value of the coefficient to anything within this range. The SEM is initialized from a linear, gaussian SEM by calculating (or estimating) what the coefficients would be if a data set were simulated from that SEM, standardized, and reestimated with the same SEM PM. The coefficients of such an estimated SEM PM are used to initialize the standardized SEM, repeating if necessary (due to possible noise issues) to get coefficients for which all errors variances can be calculated. (Variances need to be >= 0 for Normal distributions.) This produces a set of coefficients that are viable candidates for the standardized SEM. From there, the user cannot make any change that does not also allow for a standardized SEM to be defined, with error variances taking up the slack. Thus, the standardized SEM can never go "out of bounds."

Currently we are not allowing bidirected edges in the SEM graph.

Version:
$Id: $Id
Author:
josephramsey
See Also:
  • Constructor Details

    • StandardizedSemIm

      public StandardizedSemIm(SemIm im, Parameters parameters)
      Constructs a new standardized SEM IM, initializing from the freeParameters in the given SEM IM.
      Parameters:
      im - The SEM IM that the freeParameters will be initialized from.
      parameters - a Parameters object
    • StandardizedSemIm

      public StandardizedSemIm(SemIm im, StandardizedSemIm.Initialization initialization, Parameters parameters)
      Constructs a new standardized SEM IM from the freeParameters in the given SEM IM.
      Parameters:
      im - Stop asking me for these things! The given SEM IM!!!
      initialization - CALCULATE_FROM_SEM if the initial values will be calculated from the given SEM IM;
      parameters - a Parameters object
  • Method Details

    • serializableInstance

      public static StandardizedSemIm serializableInstance()
      Generates a simple exemplar of this class to test serialization.
      Returns:
      a StandardizedSemIm object
    • getSampleSize

      public int getSampleSize()

      Getter for the field sampleSize.

      Returns:
      a int
    • containsParameter

      public boolean containsParameter(Edge edge)

      containsParameter.

      Parameters:
      edge - a Edge object
      Returns:
      a boolean
    • setEdgeCoefficient

      public boolean setEdgeCoefficient(Node a, Node b, double coef)
      Sets the coefficient for the a->b edge to the given coefficient, if within range. Otherwise does nothing.
      Parameters:
      a - a -> b
      b - a -> b
      coef - The coefficient of a -> b.
      Returns:
      true if the coefficent was set (i.e. was within range), false if not.
    • setErrorCovariance

      public boolean setErrorCovariance(Node a, Node b, double covar)
      Sets the covariance for the a<->b edge to the given covariance, if within range. Otherwise does nothing.
      Parameters:
      a - a <-> b
      b - a <-> b
      covar - The covariance of a <-> b.
      Returns:
      true if the coefficent was set (i.e. was within range), false if not.
    • getEdgeCoef

      public double getEdgeCoef(Node a, Node b)

      Getter for the field edgeCoef.

      Parameters:
      a - a->b
      b - a->b
      Returns:
      The coefficient for a->b.
    • getErrorCovariance

      public double getErrorCovariance(Node a, Node b)

      getErrorCovariance.

      Parameters:
      a - a->b
      b - a->b
      Returns:
      The coefficient for a->b.
    • getParameterValue

      public double getParameterValue(Edge edge)

      getParameterValue.

      Parameters:
      edge - a Edge object
      Returns:
      a double
    • setParameterValue

      public void setParameterValue(Edge edge, double value)

      setParameterValue.

      Parameters:
      edge - a Edge object
      value - a double
    • getCoefficientRange

      public StandardizedSemIm.ParameterRange getCoefficientRange(Node a, Node b)

      getCoefficientRange.

      Parameters:
      a - a Node object
      b - a Node object
      Returns:
      a StandardizedSemIm.ParameterRange object
    • getCovarianceRange

      public StandardizedSemIm.ParameterRange getCovarianceRange(Node a, Node b)

      getCovarianceRange.

      Parameters:
      a - a Node object
      b - a Node object
      Returns:
      a StandardizedSemIm.ParameterRange object
    • getParameterRange

      public StandardizedSemIm.ParameterRange getParameterRange(Edge edge)

      getParameterRange.

      Parameters:
      edge - a->b or a<->b.
      Returns:
      the range of the covariance parameter for a->b or a<->b.
    • getErrorVariance

      public double getErrorVariance(Node error)

      getErrorVariance.

      Parameters:
      error - The error term. A node with NodeType.ERROR.
      Returns:
      the error variance for the given error term. THIS IS NOT A PARAMETER OF THE MODEL! Its value is simply calculated from the given coefficients of the model. Returns Double.NaN if the error variance cannot be computed.
    • toString

      public String toString()

      toString.

      Overrides:
      toString in class Object
      Returns:
      a string representation of the coefficients and variances of the model.
    • getVariableNodes

      public List<Node> getVariableNodes()

      getVariableNodes.

      Returns:
      the list of variable nodes of the model, in order.
    • means

      public double[] means()

      means.

      Returns:
      For compatibility only. Returns the variable means of the model. These are always zero, since this is a standardized model. THESE ARE ALSO NOT PARAMETERS OF THE MODEL. ONLY THE COEFFICIENTS ARE PARAMETERS.
    • simulateData

      public DataSet simulateData(int sampleSize, boolean latentDataSaved)
      Simulates data from the model associated with this object.

      A convenience method, in case we want to change out mind about how to simulate. For instance, it's unclear yet whether we can allow nongaussian errors, so we don't know yet whether the reduced form method is needed.

      Specified by:
      simulateData in interface Simulator
      Parameters:
      sampleSize - the number of rows to simulate.
      latentDataSaved - if true, latent variables are saved in the data set.
      Returns:
      the simulated data set.
    • simulateDataReducedForm

      public DataSet simulateDataReducedForm(int sampleSize, boolean latentDataSaved)

      simulateDataReducedForm.

      Parameters:
      sampleSize - a int
      latentDataSaved - a boolean
      Returns:
      a DataSet object
    • getImplCovar

      public Matrix getImplCovar()

      Getter for the field implCovar.

      Returns:
      a copy of the implied covariance matrix over all the variables.
    • getImplCovarMeas

      public Matrix getImplCovarMeas()

      Getter for the field implCovarMeas.

      Returns:
      a copy of the implied covariance matrix over the measured variables only.
    • getMeasuredNodes

      public List<Node> getMeasuredNodes()
      The list of measured nodes for the semPm. (Unmodifiable.)
      Returns:
      a List object
    • getErrorNodes

      public List<Node> getErrorNodes()

      getErrorNodes.

      Returns:
      a List object
    • getSemPm

      public SemPm getSemPm()

      Getter for the field semPm.

      Returns:
      a copy of the SEM PM.