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.

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.
    • 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;
  • Method Details

    • serializableInstance

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

      public int getSampleSize()
    • containsParameter

      public boolean containsParameter(Edge edge)
    • 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)
      Parameters:
      a - a->b
      b - a->b
      Returns:
      The coefficient for a->b.
    • getErrorCovariance

      public double getErrorCovariance(Node a, Node b)
      Parameters:
      a - a->b
      b - a->b
      Returns:
      The coefficient for a->b.
    • getParameterValue

      public double getParameterValue(Edge edge)
    • setParameterValue

      public void setParameterValue(Edge edge, double value)
    • getCoefficientRange

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

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

      public StandardizedSemIm.ParameterRange getParameterRange(Edge edge)
      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)
      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()
      Overrides:
      toString in class Object
      Returns:
      a string representation of the coefficients and variances of the model.
    • getVariableNodes

      public List<Node> getVariableNodes()
      Returns:
      the list of variable nodes of the model, in order.
    • means

      public double[] 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)
      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 sample size of the desired data set.
      latentDataSaved - True if latent variables should be included in the data set.
      Returns:
      This returns a standardized data set simulated from the model, using the reduced form method.
    • simulateDataReducedForm

      public DataSet simulateDataReducedForm(int sampleSize, boolean latentDataSaved)
    • getImplCovar

      public Matrix getImplCovar()
      Returns:
      a copy of the implied covariance matrix over all the variables.
    • getImplCovarMeas

      public Matrix getImplCovarMeas()
      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.)
    • getErrorNodes

      public List<Node> getErrorNodes()
    • getSemPm

      public SemPm getSemPm()
      Returns:
      a copy of the SEM PM.