Class TsUtils

java.lang.Object
edu.cmu.tetrad.search.utils.TsUtils

public class TsUtils extends Object
Contains some utilities for doing autoregression. Should probably be improved by somebody.
Version:
$Id: $Id
Author:
josephramsey, danielmalinsky (some improvements)
  • Method Details

    • ar

      public static DataSet ar(DataSet timeSeries, int numLags)

      ar.

      Parameters:
      timeSeries - a DataSet object
      numLags - a int
      Returns:
      the VAR residuals of the given time series with the given number of lags. That is, every variable at the model lag is regressed onto every variable at previous lags, up to the given number of lags, and the residuals of these regressions for each variable are returned.
    • ar2

      public static DataSet ar2(DataSet timeSeries, int numLags)

      ar2.

      Parameters:
      timeSeries - a DataSet object
      numLags - a int
      Returns:
      a DataSet object
    • structuralVar

      public static TsUtils.VarResult structuralVar(DataSet timeSeries, int numLags) throws InterruptedException

      structuralVar.

      Parameters:
      timeSeries - a DataSet object
      numLags - a int
      Returns:
      a TsUtils.VarResult object
      Throws:
      InterruptedException - if any
    • createShiftedData

      public static DataSet createShiftedData(DataSet data, int[] shifts)

      createShiftedData.

      Parameters:
      data - a DataSet object
      shifts - an array of objects
      Returns:
      a DataSet object
    • getSelfLoopCoefs

      public static double[] getSelfLoopCoefs(DataSet timeSeries)

      getSelfLoopCoefs.

      Parameters:
      timeSeries - a DataSet object
      Returns:
      an array of objects
    • sumOfArCoefficients

      public static double sumOfArCoefficients(DataSet timeSeries, int numLags)

      sumOfArCoefficients.

      Parameters:
      timeSeries - a DataSet object
      numLags - a int
      Returns:
      a double
    • difference

      public static DataSet difference(DataSet data, int d)
      Calculates the dth difference of the given data. If d = 0, the original data is returned. If d = 1, the data (with one fewer rows) is returned, with each row subtracted from its successor. If d = 1, the same operation is applied to the result of d = 1. And so on.
      Parameters:
      data - the data to be differenced.
      d - the number of differences to take, >= 0.
      Returns:
      the differenced data.
    • createLagData

      public static DataSet createLagData(DataSet data, int numLags)
      Creates new time series dataset from the given one (fixed to deal with mixed datasets)
      Parameters:
      data - a DataSet object
      numLags - a int
      Returns:
      a DataSet object
    • createLagData

      public static DataSet createLagData(DataSet data, int numLags, Knowledge knowledge)
      Creates a new time series dataset from the given one, expanding the provided within-lag Knowledge across all time lags. If the input knowledge has k non-empty tiers, the expanded knowledge will have k * (numLags + 1) tiers, with the within-lag tier structure (including forbidden/required edges and tierForbiddenWithin flags) replicated at each lag. Cross-lag temporal ordering (no edges from later time back to earlier time) is enforced automatically by the tier structure.
      Parameters:
      data - the time series dataset
      numLags - the number of lags
      knowledge - within-lag knowledge over base variable names (no lag suffix)
      Returns:
      the lagged dataset with expanded knowledge attached
    • addIndex

      public static DataSet addIndex(DataSet data)
      Creates new time series dataset from the given one with index variable (e.g., time)
      Parameters:
      data - a DataSet object
      Returns:
      a DataSet object
    • graphToLagGraph

      public static TimeLagGraph graphToLagGraph(Graph _graph, int numLags, int extraLaggedEdges)
      Converts a directed graph into a time-lagged graph representation. The resulting graph includes lagged copies of nodes, self-lagged edges, contemporaneous edges, and probabilistically generated inter-variable lagged edges up to the specified maximum lag.
      Parameters:
      _graph - The base DAG graph to be converted. Must only contain directed edges. Throws IllegalArgumentException if the input graph is not fully directed.
      numLags - The maximum number of lags to include in the time-lagged graph.
      extraLaggedEdges - The number of extra lagged edges to include in the time-lagged graph.
      Returns:
      A time-lagged graph representation of the input graph with the specified properties. The resulting graph includes lagged nodes, self-lagged edges, and probabilistically generated lagged edges.
    • getNameNoLag

      public static String getNameNoLag(Object obj)

      getNameNoLag.

      Parameters:
      obj - a Object object
      Returns:
      a String object
    • getPrefix

      public static String getPrefix(String s)

      getPrefix.

      Parameters:
      s - a String object
      Returns:
      a String object
    • getIndex

      public static int getIndex(String s)

      getIndex.

      Parameters:
      s - a String object
      Returns:
      a int
    • getLag

      public static int getLag(String s)

      getLag.

      Parameters:
      s - a String object
      Returns:
      a int
    • getKnowledge

      public static Knowledge getKnowledge(Graph graph)

      getKnowledge.

      Parameters:
      graph - a Graph object
      Returns:
      a Knowledge object
    • allEigenvaluesAreSmallerThanOneInModulus

      public static boolean allEigenvaluesAreSmallerThanOneInModulus(Matrix mat)

      allEigenvaluesAreSmallerThanOneInModulus.

      Parameters:
      mat - a Matrix object
      Returns:
      a boolean