Learn R Programming

catnet (version 1.09.4)

cnSamples-method: Samples from Network

Description

Generates samples from of a catNetwork object.

Usage

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

Arguments

object
a catNetwork
numsamples
an integer, the number of samples to be generated
perturbations
a vector, node perturbations
output
a character, the output format. Can be a data.frame or matrix.
as.index
a logical, the output categorical format.

Value

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

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 parents. While the non-zero values in the perturbation vector are carried on unchanged to the output.

See Also

cnPredict

Examples

Run this code
cnet <- cnRandomCatnet(numnodes=10, maxParents=3, numCategories=3)
  ## generate a sample of size 100 from cnet
  psamples <- cnSamples(object=cnet, numsamples=100, output="frame", as.index=FALSE)
  ## perturbed sample
  nsamples <- 20
  perturbations <- rbinom(10, 2, 0.4)
  ## generate a perturbed sample of size 100 from cnet
  psamples <- cnSamples(object=cnet, numsamples=nsamples, perturbations, as.index=TRUE)

Run the code above in your browser using DataLab