Package 'rbc'

Title: Regression by Composition
Description: Flexible statistical modelling using a modular framework for regression, in which groups of transformations are composed together and act on probability distributions.
Authors: Daniel Farewell [aut, cre, cph] , Simon Schoenbuchner [ctb]
Maintainer: Daniel Farewell <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2024-12-07 06:58:54 UTC
Source: CRAN

Help Index


Compute Akaike Information Criterion from a regression by composition

Description

Compute Akaike Information Criterion from a regression by composition

Usage

## S3 method for class 'RegressionByComposition'
AIC(object, ..., k = 2)

Arguments

object

a RegressionByComposition object; usually the result of a call to rbc()

...

ignored

k

numeric, the penalty per parameter to be used; ‘k = 2’ is the classical AIC.


Append a flow to a CompositeFamily object

Description

Append a flow to a CompositeFamily object

Usage

append_flow(family, flow)

Arguments

family

a CompositeFamily object

flow

a Flow object

Value

a new CompositeFamily object

Examples

append_flow(Normal(0, 1), Translate)

Reduce(append_flow, list(Scale, Translate), init = Normal(0, 1))

Bernoulli distribution as a CompositeFamily

Description

Bernoulli distribution as a CompositeFamily

Usage

Bernoulli(prob = 0.5)

Arguments

prob

the probability of a success

Value

a new BinaryFamily object

Examples

dist <- Bernoulli()
dist$probability()

Extract regression coefficients from a regression by composition

Description

Extract regression coefficients from a regression by composition

Usage

## S3 method for class 'RegressionByComposition'
coef(object, ...)

Arguments

object

a RegressionByComposition object; usually the result of a call to rbc()

...

ignored


Compute fitted values from a regression by composition

Description

Compute fitted values from a regression by composition

Usage

## S3 method for class 'RegressionByComposition'
fitted(object, ...)

Arguments

object

a RegressionByComposition object; usually the result of a call to rbc()

...

further arguments passed to the R6 method $fitted() associated with the model's CompositeFamily


Extract log-likelihood from a regression by composition

Description

Extract log-likelihood from a regression by composition

Usage

## S3 method for class 'RegressionByComposition'
logLik(object, ...)

Arguments

object

a RegressionByComposition object; usually the result of a call to rbc()

...

ignored


Lognormal distribution as a CompositeFamily

Description

Lognormal distribution as a CompositeFamily

Usage

LogNormal(meanlog = 0, sdlog = 1)

Arguments

meanlog

the mean of the logarithm

sdlog

the standard deviation of the logarithm

Value

a new ContinuousFamily object

Examples

dist <- LogNormal()
log(dist$quantile(0.95))

Moebius flow

Description

Moebius flow

Usage

Moebius

Format

An object of class Flow (inherits from R6) of length 6.


Normal distribution as a CompositeFamily

Description

Normal distribution as a CompositeFamily

Usage

Normal(mean = 0, sd = 1)

Arguments

mean

the mean

sd

the standard deviation

Value

a new ContinuousFamily object

Examples

dist <- Normal()
dist$quantile(0.95)

Power flow

Description

Power flow

Usage

Power

Format

An object of class Flow (inherits from R6) of length 6.


Compute predicted values from a regression by composition

Description

Compute predicted values from a regression by composition

Usage

## S3 method for class 'RegressionByComposition'
predict(object, newdata, ...)

Arguments

object

a RegressionByComposition object; usually the result of a call to rbc()

newdata

data.frame containing new data

...

further arguments passed to the R6 method $fitted() associated with the model's CompositeFamily


Fit a regression by composition model

Description

Fit a regression by composition model

Usage

rbc(formula, init, flows, family, data, par, hessian = TRUE)

Arguments

formula

a formula object, with model components separated by '|'

init

the initial distribution

flows

a list of flows

family

(optional) an object of class 'CompositeFamily'; if supplied, 'init' and 'flows' are ignored

data

a data frame

par

a vector of starting values

hessian

logical; use Hessian matrix in model fitting?

Value

an rbc object

Examples

## Annette Dobson (1990)
## "An Introduction to Generalized Linear Models".
## Page 9: Plant Weight Data.
ctl <- c(4.17, 5.58, 5.18, 6.11, 4.50, 4.61, 5.17, 4.53, 5.33, 5.14)
trt <- c(4.81, 4.17, 4.41, 3.59, 5.87, 3.83, 6.03, 4.89, 4.32, 4.69)
dobson <- data.frame(
  weight = c(ctl, trt),
  group = gl(2, 10, 20, labels = c("Ctl", "Trt"))
)
dobson_fit <- rbc(weight ~ 1 | 1 + group,
  init = Normal(0, 1),
  flows = list(Scale, Translate),
  data = dobson
)

starr_fit <- rbc(
  height ~ 1 | 0 + I((280 + age)^(-1)) | 1 | 1,
  init = LogNormal(),
  flows = list(Power, Moebius, Scale, Translate),
  data = subset(starr, id %in% unique(id)[1:10])
)

Compute 'residuals' from a regression by composition

Description

Compute 'residuals' from a regression by composition

Usage

## S3 method for class 'RegressionByComposition'
residuals(object, ...)

Arguments

object

a RegressionByComposition object; usually the result of a call to rbc()

...

ignored

Value

a vector of probabilities of the same length as the data


Scale flow

Description

Scale flow

Usage

Scale

Format

An object of class Flow (inherits from R6) of length 6.


ScaleOdds flow

Description

ScaleOdds flow

Usage

ScaleOdds

Format

An object of class Flow (inherits from R6) of length 6.


ScaleRisk0 flow

Description

ScaleRisk0 flow

Usage

ScaleRisk0

Format

An object of class Flow (inherits from R6) of length 6.


ScaleRisk1 flow

Description

ScaleRisk1 flow

Usage

ScaleRisk1

Format

An object of class Flow (inherits from R6) of length 6.


Growth from birth to 3 years in healthy babies in the US

Description

Growth from birth to 3 years in healthy babies in the US

Usage

starr

Format

starr

A data frame with 104,798 rows and 5 columns:

id

Anonymized identifier

sex

Sex of baby

age

Age of baby, in days

height

Jittered height of baby, in cm

weight

Jittered weight of baby, in kg

...

Source

doi:10.5061/dryad.4j0zpc8jf

References

doi:10.1186/s12874-024-02145-1


Summary of a regression by composition

Description

Summary of a regression by composition

Usage

## S3 method for class 'RegressionByComposition'
summary(object, compact = FALSE, ...)

Arguments

object

a RegressionByComposition object; usually the result of a call to rbc()

compact

logical; should coefficients from all flows be compressed into a single matrix?

...

ignored


Translate flow

Description

Translate flow

Usage

Translate

Format

An object of class Flow (inherits from R6) of length 6.


TranslateRisk1 flow

Description

TranslateRisk1 flow

Usage

TranslateRisk1

Format

An object of class Flow (inherits from R6) of length 6.


Extract variance-covariance matrix from a regression by composition

Description

Extract variance-covariance matrix from a regression by composition

Usage

## S3 method for class 'RegressionByComposition'
vcov(object, ...)

Arguments

object

a RegressionByComposition object; usually the result of a call to rbc()

...

ignored