dataTable: Constructs a table of counts from a set of discrete...

dataTableR Documentation

Constructs a table of counts from a set of discrete observations.

Description

This constructs a table of counts in a special format useful for conditional probability tables. The rows correspond to configurations of the parent variables and the columns correspond to possible states of the child variables.

Usage

dataTable(data, parents, child, childStates)

Arguments

data

A data frame whose columns contain variables corresponding to parent and child.

parents

A vector of names for the columns in data corresponding to the parent variables.

child

The name of the child variable, should refer to a column in data.

childStates

A character vector giving names of levels for the output variables from highest to lowest.

Details

Apply the function table to generate a table of counts for the indicated variables (subsetting the table if necessary). Then reformats this into a matrix whose columns correspond to the child variable.

Value

A matrix whose columns correspond to childStates and whose rows correspond to the possible combinations of parents.

Author(s)

Russell Almond

See Also

table, calcDSllike

Examples


  skill1l <- c("High","Medium","Low") 
  skill3l <- c("High","Better","Medium","Worse","Low") 
  correctL <- c("Correct","Incorrect") 

  x <- read.csv(system.file("testFiles", "randomPinned100.csv",
                            package="CPTtools"),
              header=TRUE, as.is=TRUE)
  x[,"Skill1"] <- ordered(x[,"Skill1"],skill1l)
  x[,"Skill3"] <- ordered(x[,"Skill3"],skill3l)
  x[,"Comp.Correct"] <- ordered(x[,"Comp.Correct"],correctL)


  tab <- dataTable(x, c("Skill1","Skill3"),"Comp.Correct",correctL)
  data.frame(expand.grid(list(Skill1=skill1l,Skill3=skill3l)),tab)


ralmond/CPTtools documentation built on Dec. 27, 2024, 7:15 a.m.