Dear TraMineR users,<div><br></div><div>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.</div>

<div><br></div><div>Below and attached to this email you can find the script.</div><div><br></div><div>Best greetings,</div><div>Robbie van Aert</div><div><br></div><div>Reference:</div><div><br></div><div>Bakeman, R., & Gottman, J.M. (1997). Observing interaction: An introduction to sequential analysis (2nd ed.) Cambridge, UK: Cambridge University Press.</div>

<div><br></div><div>################################################ Script ################################################</div><div><br></div><div><div>seqtrate.z <- function(seq_obj) {</div><div>  matrix <- as.matrix(seq_obj)                            # reformat to matrix #</div>

<div>  tr <- table(c(matrix[,-ncol(matrix)]), c(matrix[,-1]))</div><div>  transi <- tr[c(3:14), c(3:14)]</div><div>  </div><div>  ### Number of loops are number of rows in matrix.</div><div>  n_loops <- nrow(transi)</div>

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

<div>  res.Xgt <- array(NA, dim = c(nrow(transi), ncol(transi)))</div><div>  res.Mgt <- array(NA, dim = c(nrow(transi), ncol(transi)))</div><div>  res.Pg <- array(NA, dim = c(nrow(transi), ncol(transi)))</div><div>

  res.Pt <- array(NA, dim = c(nrow(transi), ncol(transi)))</div><div>  </div><div>  ### Loops that are used for filling the arrays.</div><div>  for (i in 1:n_loops) {</div><div>    for (k in 1:n_loops) {                                                             ####################################</div>

<div>      res.Xg[i,k] <- sum(transi[i, ])                                               # Xg = sum observations in Gth row          #</div><div>      res.Xt[i,k] <- sum(transi[ ,k])                                               # Xt = sum observations in Tth column     #</div>

<div>      res.Xgt[i,k] <- transi[i,k]                                                      # Xgt = observed freq                              #</div><div>      res.Mgt[i,k] <- ((res.Xg[i,k] * res.Xt[i,k]) / sum(transi))            # Mgt = expected freq based on data       #</div>

<div>      res.Pg[i,k] <- res.Xg[i,k] / sum(transi)                                  # Pg = Xg divided by total N                     #</div><div>      res.Pt[i,k] <- res.Xt[i,k] / sum(transi)                                    # Pt = Xt divided by total N                      #</div>

<div>    }                                                                                         ####################################</div><div>  }</div><div>  ### Formula for z-values.</div><div>  res.Zgt <- round((res.Xgt - res.Mgt) / (sqrt(res.Mgt*(1 - res.Pg)*(1 - res.Pt))),3)</div>

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

<div>  </div><div>  return(res.Zgt)</div><div>}</div></div>