mimR-ReadingData            package:mimR            R Documentation

_C_r_e_a_t_i_o_n _o_f _g_m_D_a_t_a _o_b_j_e_c_t_s

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

     Different methods for creation of gmData objects. Depending on
     taste gmData can be taken as meaning 'graphical model data' or
     'graphical meta data'

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

     gmData(name, letter = NULL, factor = rep(FALSE,
     length(name)), vallabels=NULL, data=NULL)
     as.gmData (data, letter=NULL)
     description(x)
     "description<-"(tmp, value)
     latent(x)
     "latent<-"(tmp, value)
     vallabels(x)
     "vallabels<-"(tmp, value)
     observations(x)
     "observations<-"(tmp, value)

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

    name: ~~Describe 'name' here~~ 

  factor: ~~Describe 'factor' here~~ 

    data: a dataframe

  letter: A specification of letters which can subsequently be used as
          short hand for the variable names

       x: A gmData object

     tmp: A gmData object

   value: The value to entered into the object

vallabels: A list containing labels of the levels of the discrete
          variables (not currently used)

_D_e_t_a_i_l_s:

     A variety of data formats can be turned into gmData objects. See
     examples.

_V_a_l_u_e:

     A dataframe containing the link between the names in the dataframe
     and the names (and labels) and the coding of factors in MIM

_W_A_R_N_I_N_G:

     If only a subset of a dataframe is used, then it may be necessary
     to recode the levels of factors in the dataframe. Otherwise one
     can end up with slices of the table in MIM with no observations in
     it. The easiest way to recode the levels is to use the function
     'factor()', see examples below.

_N_o_t_e:

     Before using mimR, make sure that the MIM program is runnning.

_A_u_t_h_o_r(_s):

     Sren Hjsgaard, sorenh@agrsci.dk

_R_e_f_e_r_e_n_c_e_s:

     David Edwards, An Introduction to Graphical Modelling, Second
     Edition, Springer Verlag, 2000

_S_e_e _A_l_s_o:

     'mim.cmd'

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

     # A meta data object (without data)
     gmd.rats.nodata  <-  gmData(c("Sex","Drug","W1","W2"),
         factor=c(2,3,FALSE,FALSE),
         vallabels=list("Sex"=c("M","F"), "Drug"=c("D1","D2","D3")))

     # Note care should be taken to be consistent when specifying vallabels manually:

     #This works
     nt1  <-  gmData(c("Sex","Drug","W1","W2"),factor=c(2,3,FALSE,FALSE))
     vallabels(nt1)

     #This works
     nt12  <-  gmData(c("Sex","Drug","W1","W2"),factor=c(2,3,FALSE,FALSE), vallabels=list("Sex"=c(1,2), "Drug"=c(1,2,3)))
     vallabels(nt1)

     ## Not run: 
     #This will not work
     nt1  <-  gmData(c("Sex","Drug","W1","W2"),factor=c(2,3,FALSE,FALSE), vallabels=list("Sex"=c(1,2,3), "Drug"=c(1,2,3)))
     vallabels(nt1)

     #This will not work
     nt1  <-  gmData(c("Sex","Drug","W1","W2"),factor=c(2,3,FALSE,FALSE), vallabels=list("Sex"=c(1,2,3)))
     vallabels(nt1)

     # It is possible to specify data as sufficient statistics, when these
     # are specified as lists as follows:

     # Specify data as sufficient statistics - discrete data
     dat <- list(names=c("foo","bar","off"),levels=c(2,3,2),counts=1:12)
     v <- as.gmData(dat)

     # Specify data as sufficient statistics - continuous data
     setosa <- subset(iris, Species=="setosa")[,1:4]
     dat <- list(names=names(setosa), means=apply(setosa,2,mean),
       stddev = sqrt(diag(var(setosa))), corr=cor(setosa),n=nrow(setosa))
     v <- as.gmData(dat)

     # Reading sufficient statistics - continuous data

     suffc<-list(means=apply(mathmark,2,mean),
     stddev=apply(mathmark,2,sd), corr=cor(mathmark),n=nrow(mathmark))

     toMIM(as.gmData(suffc))
     # Reading sufficient statistics - discrete data
     # Note that data are read in the order (1 1) (1 2) (2 1) (2 2)
     suffd<-list(names=c("foo","bar"),levels=c(2,2),
     counts=c(1,2,3,4),vallabels=list(foo=c("f1","f2"),bar=c("b1","b2")))
     toMIM(as.gmData(suffd))

     # Work with sufficient statistics, e.g. the hiv data taken from the SIN
     # package
     data(hiv)
     v<-as.gmData(hiv)
     fit(mim(".",data=v))

     ## End(Not run)

     data(rats)

     #NOTE: This works, but it should not because names in 'data' is not checked for consistency with what is specified
     nt1  <-  gmData(c("Sex","Drug","W1","W2"),factor=c(2,3,FALSE,FALSE), vallabels=list("Sex"=c(1,2), "Drug"=c(1,2,3)), data=rats)
     vallabels(nt1)

     # Sending a data frame to MIM
     gm.rats <- as.gmData(rats)
     toMIM(gm.rats)

