[Traminer-users] Script for computing z-values for transition probabilities

Robbie Aert, van r.c.m.vanaert at tilburguniversity.edu
Sun Mar 3 12:55:17 CET 2013


Dear TraMineR users,

In collaboration with Bertolt Meyer, I wrote a script for computing
z-values for transition probabilities within the TraMineR package. The
formulas described in the book by Bakeman and Gottman (2009, p. 108-111)
were used as starting point for the newly developed function. The output
that can be obtained with this function is similar to the output of the
seqtrate() function; the only difference is that the transition
probabilities are now replaced by z-values.

Below and attached to this email you can find the script.

Best greetings,
Robbie van Aert

Reference:

Bakeman, R., & Gottman, J.M. (1997). Observing interaction: An introduction
to sequential analysis (2nd ed.) Cambridge, UK: Cambridge University Press.

################################################ Script
################################################

seqtrate.z <- function(seq_obj) {
  matrix <- as.matrix(seq_obj)                            # reformat to
matrix #
  tr <- table(c(matrix[,-ncol(matrix)]), c(matrix[,-1]))
  transi <- tr[c(3:14), c(3:14)]

  ### Number of loops are number of rows in matrix.
  n_loops <- nrow(transi)

  ### Empty arrays in which the data is going to be stored.
  res.Xg <- array(NA, dim = c(nrow(transi), ncol(transi)))
  res.Xt <- array(NA, dim = c(nrow(transi), ncol(transi)))
  res.Xgt <- array(NA, dim = c(nrow(transi), ncol(transi)))
  res.Mgt <- array(NA, dim = c(nrow(transi), ncol(transi)))
  res.Pg <- array(NA, dim = c(nrow(transi), ncol(transi)))
  res.Pt <- array(NA, dim = c(nrow(transi), ncol(transi)))

  ### Loops that are used for filling the arrays.
  for (i in 1:n_loops) {
    for (k in 1:n_loops) {
            ####################################
      res.Xg[i,k] <- sum(transi[i, ])
        # Xg = sum observations in Gth row          #
      res.Xt[i,k] <- sum(transi[ ,k])
        # Xt = sum observations in Tth column     #
      res.Xgt[i,k] <- transi[i,k]
           # Xgt = observed freq                              #
      res.Mgt[i,k] <- ((res.Xg[i,k] * res.Xt[i,k]) / sum(transi))
 # Mgt = expected freq based on data       #
      res.Pg[i,k] <- res.Xg[i,k] / sum(transi)
     # Pg = Xg divided by total N                     #
      res.Pt[i,k] <- res.Xt[i,k] / sum(transi)
       # Pt = Xt divided by total N                      #
    }
                  ####################################
  }
  ### Formula for z-values.
  res.Zgt <- round((res.Xgt - res.Mgt) / (sqrt(res.Mgt*(1 - res.Pg)*(1 -
res.Pt))),3)

  ### Assign column and row names to matrix.
  column <- colnames(tr.rates)
  colnames(res.Zgt) <- column
  row <- rownames(tr.rates)
  rownames(res.Zgt) <- row

  return(res.Zgt)
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/traminer-users/attachments/20130303/2a273784/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Function seqtrate.z().R
Type: application/octet-stream
Size: 2475 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/traminer-users/attachments/20130303/2a273784/attachment.obj>


More information about the Traminer-users mailing list