Learn R Programming

sparsebnUtils (version 0.0.8)

sparsebnData: sparsebnData class

Description

This class stores data that may contain interventions on some or all of the observations. It also allows for the degenerate case with no interventions, i.e. purely observational data.

Usage

sparsebnData(x, ...)

is.sparsebnData(x)

# S3 method for data.frame sparsebnData(x, type, levels = NULL, ivn = NULL, ...)

# S3 method for matrix sparsebnData(x, type, levels = NULL, ivn = NULL, ...)

# S3 method for sparsebnData print(x, n = 5L, ...)

# S3 method for sparsebnData summary(object, n = 5L, ...)

# S3 method for sparsebnData plot(x, ...)

Arguments

x

a data.frame or matrix object.

...

(optional) additional arguments.

type

either 'discrete' or 'continuous'.

levels

(optional) list of levels for each node. If omitted, levels will be automatically detected from unique.

ivn

(optional) list of interventions for each observation. If omitted, data is assumed to be purely observational.

n

(optional) number of rows from data matrix to print.

object

an object of type sparsebnData

Slots

data

(data.frame) Dataset.

type

(character) Type of data: Either "continuous", "discrete", or "mixed".

levels

(list) List of levels for each column in data.

ivn

(list) List of columns under intervention for each row in data.

Details

The structure of a sparsebnData object is very simple: It contains a data.frame object, a type identifier (i.e. discrete or continuous), a list of factor levels, and a list of interventions.

  • The levels list should be the same size as the number of nodes and consist of names of the different levels for each node. Each level should be coded to be from 0...\(k\)-1 where \(k\) is the number of levels for a particular variable (see below for more).

  • The ivn list should be the same size as the number of rows in the dataset, and each component indicates which column(s) in the dataset is (are) under intervention. If an observation has no interventions, then the corresponding component is NULL. Thus, if the data is purely observational, this list should contain only NULL values.

Presently, only levels coded as 0,1,...,\(k\)-1 are supported (\(k\) = the number of levels for a variable). Future releases are planned to support more general factor levels. The level 0 corresponds to the baseline level or measurement.

Also inherits from list.

Examples

Run this code
# NOT RUN {
### Generate a random continuous dataset
mat <- matrix(rnorm(1000), nrow = 20)
dat <- sparsebnData(mat, type = "continuous") # purely observational data with continuous variables

### Discrete data
mat <- rbind(c(0,2,0),
             c(1,1,0),
             c(1,0,3),
             c(0,1,0))
dat.levels <- list(c(0,1), c(0,1,2), c(0,1,2,3))
dat <- sparsebnData(mat,
                    type = "discrete",
                    levels = dat.levels) # purely observational data with discrete variables

dat.ivn <- list(c(1),   # first observation was intervened at node 1
                c(1),   # second observation was intervened at node 1
                c(2,3), # third observation was intervened at nodes 2 and 3
                c(1,3)) # fourth observation was intervened at nodes 1 and 3
dat <- sparsebnData(mat,
                    type = "discrete",
                    levels = dat.levels,
                    ivn = dat.ivn) # specify intervention rows

# }

Run the code above in your browser using DataLab