stan4bart-generics {stan4bart}R Documentation

Generic Functions for stan4bart Model Fits

Description

Commonly expected utility functions to derive useful quantities from fitted models.

Usage

## S3 method for class 'stan4bartFit'
extract(
  object,
  type = c("ev", "ppd", "fixef", "indiv.fixef", "ranef", "indiv.ranef",
           "indiv.bart", "sigma", "Sigma", "k", "varcount", "stan",
           "trees", "callback"),
  sample = c("train", "test"),
  combine_chains = TRUE,
  sample_new_levels = TRUE,
  include_warmup = FALSE,
  ...)
  
## S3 method for class 'stan4bartFit'
fitted(
  object,
  type = c("ev", "ppd", "fixef", "indiv.fixef", "ranef", "indiv.ranef",
           "indiv.bart", "sigma", "Sigma", "k", "varcount", "stan",
           "callback"),
  sample = c("train", "test"),
  sample_new_levels = TRUE,
  ...)

## S3 method for class 'stan4bartFit'
predict(
  object, newdata, offset,
  type = c("ev", "ppd", "indiv.fixef", "indiv.ranef", "indiv.bart"),
  combine_chains = TRUE,
  sample_new_levels = TRUE,
  ...)

Arguments

object

a fitted model resulting from a call to stan4bart.

type

a character vector; one of the options listed below.

sample

one of "train" or "test", indicating if the training or test data frames should be used.

combine_chains

logical controlling if chain information should be discarded and the result returned as a matrix instead of an array.

sample_new_levels

logical; if TRUE, levels out of the training sample will have random effects drawn from their posterior predictive distribution. If FALSE, their random effects will be fixed to 0.

include_warmup

logical or "only"; when TRUE/FALSE, warmup samples will or will not be included in the result respectively. When "only", only the warmup samples will be returned.

newdata

data frame for making out of sample predictions.

offset

optional vector which will be added to test predictors.

...

not currently in use, but provided to match signatures of other generics.

Details

extract is used to obtain raw samples using the training or test data, fitted averages those samples, and predict operates on data not available at the time of fitting. Note: predict requires that the model be fit with args_bart = list(keepTrees = TRUE).

Return type

The type argument accepts:

Value

extract and predict return either arrays of dimensions equal to n.observations x n.samples x n.chains when combine_chains is FALSE, or matrices of dimensions equal to n.observations x (n.samples * n.chains) when combine_chains is TRUE.

fitted returns a vector of the appropriate length by averaging the result of a call to extract.

Author(s)

Vincent Dorie: vdorie@gmail.com.


[Package stan4bart version 0.0-8 Index]