cnSamples: Samples from Network

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Generates samples from of a catNetwork object.

Usage

1
cnSamples(object, numsamples = 1, pert = NULL, output="frame", as.index=FALSE, naRate=0)

Arguments

object

a catNetwork

numsamples

an integer, the number of samples to be generated

pert

a vector, node pert

output

a character, the output format. Can be a data.frame or matrix.

as.index

a logical, the output categorical format

naRate

a numeric, the proportion of NAs per sample instance

Details

If the output format is "matrix" then the resulting sample matrix is in row-node format - the rows correspond to the object's nodes while the individual samples are represented by columns. If the output format is "frame", which is by default, the result is a data frame with columns representing the nodes and levels the set of categories of the respected nodes. If as.index is set to TRUE, the output sample consists of categorical indices, otherwise, and this is by default, of characters specifying the categories.

A perturbed sample is a sample having nodes with predefined, thus fixed, values. Non-perturbed nodes, the nodes which values have to be set, are designated with zeros in the perturbation vector and their values are generated conditional on the values of their pars. While the non-zero values in the perturbation vector are carried on unchanged to the output.

If naRate is positive, then floor(numnodes*naRate) NA values are randomly placed in each sample instance.

Value

A matrix or data.frame of node categories as integers or characters

Author(s)

N. Balov

See Also

cnPredict

Examples

1
2
3
4
5
6
7
8
  cnet <- cnRandomCatnet(numnodes=10, maxpars=3, numcats=3)
  ## generate a sample of size 100 from cnet
  psamples <- cnSamples(object=cnet, numsamples=100, output="frame", as.index=FALSE)
  ## perturbed sample
  nsamples <- 20
  pert <- rbinom(10, 2, 0.4)
  ## generate a perturbed sample of size 100 from cnet
  psamples <- cnSamples(object=cnet, numsamples=nsamples, pert, as.index=TRUE)

sdnet documentation built on May 2, 2019, 12:43 a.m.