sparsebnData: sparsebnData class

Description Usage Arguments Details Slots Methods Examples

View source: R/s3-generics.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
sparsebnData(x, ...)

is.sparsebnData(x)

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

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

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

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

## S3 method for class '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

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.

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.

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.

Methods

print num.samples is.obs count.levels count.interventions as.data.frame

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
### 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

itsrainingdata/sparsebnUtils documentation built on April 2, 2018, 8:27 p.m.