expectation-methods           package:coin           R Documentation

_E_x_t_r_a_c_t _t_h_e _E_x_p_e_c_t_a_t_i_o_n _a_n_d _C_o_v_a_r_i_a_n_c_e _o_f _L_i_n_e_a_r _S_t_a_t_i_s_t_i_c_s

_D_e_s_c_r_i_p_t_i_o_n:

     Extracts the conditional expectation and covariance  for linear
     statistics from objects inheriting from "IndependenceTest".

_U_s_a_g_e:

     expectation(object, ...)
     covariance(object, ...)

_A_r_g_u_m_e_n_t_s:

  object: an object inheriting from class 'IndependenceTest-class'.

     ...: further arguments (currently ignored).

_M_e_t_h_o_d_s:

     _e_x_p_e_c_t_a_t_i_o_n extracts the expectation of the linear  statistic of
          'object'.

     _c_o_v_a_r_i_a_n_c_e extracts the covariance of the linear  statistic of
          'object'.

_E_x_a_m_p_l_e_s:

     df <- data.frame(y = gl(3, 2), x = gl(3, 2)[sample(1:6)])

     ### Cochran-Mantel-Haenzel Test
     ct <- cmh_test(y ~ x, data = df)
      
     ### the linear statistic, i.e, the contingency table
     l <- statistic(ct, type = "linear")
     l

     ### expectation
     El <- expectation(ct)
     El

     ### covariance
     Vl <- covariance(ct)
     Vl

     ### the standardized contingency table (hard way)
     (l - El) / matrix(sqrt(diag(Vl)), ncol = nrow(El))

     ### easy way
     statistic(ct, type = "standardized")

