stages {stagedtrees}R Documentation

The stages of a staged event tree

Description

Functions to get or set the stages of an object of class sevt.

Usage

stages(object)

## S3 method for class 'sevt'
stages(object)

## S3 method for class 'sevt.stgs'
print(x, ..., max = 5)

stages(object) <- value

## S3 method for class 'sevt.stgs'
x[i, ...]

## S3 replacement method for class 'sevt.stgs'
x[i, ..., fit = TRUE] <- value

## S3 method for class 'sevt.stgs'
x[[...]]

## S3 replacement method for class 'sevt.stgs'
x[[..., fit = TRUE]] <- value

Arguments

object

an object of class sevt.

x

an object of class sevt.stgs (obtained by stages(object)).

...

a path or context in the event tree.

max

integer, limit on the number of variables to print.

value

the stages replacement value.

i

index of variables in the tree.

fit

logical, if TRUE (default) the model will be re-fitted.

Details

This functions are the preferred way to access and modify directly the stages of an object of class sevt. In particular the indexing and replacing methods for the object extracted with the function stages() take care of checking the stages sanity and refit the object probabilities when needed. This is useful for manually setting some independence statements (see the Examples).

Value

For stages(): returns an object of class sevt.stgs which encode the stages of object. Objects of class sevt.stgs have dedicated method for sub-setting and replacing.

Stages indexing

Stages can be indexed, retrieved and replaced by the corresponding variables names and/or by paths or contexts.

In particular, stages(object)[[var]] extracts the stages vector corresponding to variable var (similarly to object$stages[[var]]. Alternatively stages(object)[[path]] indexes a stage via the corresponding path from root (similar to get_stage); a path is recognized as such if named or if of length > 2.

stages(object)[var, context] extracts multiple stages corresponding to a variable and eventually filtered by a specific context on the preceding variables.

Examples

# start with full model
mod <- full(Titanic)

# impose the context independence Survived indep Sex, Age | Class = 1st
stages(mod)["Survived", Class = "1st"] <- "C1"

# impose Survived indep Class | Class in (2nd 3rd)
stages(mod)["Survived", Class = "3rd"] <- stages(mod)["Survived", Class = "2nd"]

# impose Age indep Class | Sex
stages(mod)["Age", Sex = "Female"] <- "S-female"
stages(mod)["Age", Sex = "Male"] <- "S-male"

# stages of Survived
stages(mod)[["Survived"]]

# stages of Survived and Age
stages(mod)[c("Survived", "Age")]

# stages of Survived in the context Class 2nd or 3rd
stages(mod)["Survived", Class = c("2nd", "3rd")]

# check independencies
as_parentslist(mod)

[Package stagedtrees version 2.3.0 Index]