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 |
Compute Akaike Information Criterion from a regression by composition
## S3 method for class 'RegressionByComposition' AIC(object, ..., k = 2)
## S3 method for class 'RegressionByComposition' AIC(object, ..., k = 2)
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
append_flow(family, flow)
append_flow(family, flow)
family |
a CompositeFamily object |
flow |
a Flow object |
a new CompositeFamily object
append_flow(Normal(0, 1), Translate) Reduce(append_flow, list(Scale, Translate), init = Normal(0, 1))
append_flow(Normal(0, 1), Translate) Reduce(append_flow, list(Scale, Translate), init = Normal(0, 1))
Bernoulli distribution as a CompositeFamily
Bernoulli(prob = 0.5)
Bernoulli(prob = 0.5)
prob |
the probability of a success |
a new BinaryFamily object
dist <- Bernoulli() dist$probability()
dist <- Bernoulli() dist$probability()
Extract regression coefficients from a regression by composition
## S3 method for class 'RegressionByComposition' coef(object, ...)
## S3 method for class 'RegressionByComposition' coef(object, ...)
object |
a RegressionByComposition object; usually the result of a call to rbc() |
... |
ignored |
Compute fitted values from a regression by composition
## S3 method for class 'RegressionByComposition' fitted(object, ...)
## S3 method for class 'RegressionByComposition' fitted(object, ...)
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
## S3 method for class 'RegressionByComposition' logLik(object, ...)
## S3 method for class 'RegressionByComposition' logLik(object, ...)
object |
a RegressionByComposition object; usually the result of a call to rbc() |
... |
ignored |
Lognormal distribution as a CompositeFamily
LogNormal(meanlog = 0, sdlog = 1)
LogNormal(meanlog = 0, sdlog = 1)
meanlog |
the mean of the logarithm |
sdlog |
the standard deviation of the logarithm |
a new ContinuousFamily object
dist <- LogNormal() log(dist$quantile(0.95))
dist <- LogNormal() log(dist$quantile(0.95))
Moebius flow
Moebius
Moebius
An object of class Flow
(inherits from R6
) of length 6.
Normal distribution as a CompositeFamily
Normal(mean = 0, sd = 1)
Normal(mean = 0, sd = 1)
mean |
the mean |
sd |
the standard deviation |
a new ContinuousFamily object
dist <- Normal() dist$quantile(0.95)
dist <- Normal() dist$quantile(0.95)
Power flow
Power
Power
An object of class Flow
(inherits from R6
) of length 6.
Compute predicted values from a regression by composition
## S3 method for class 'RegressionByComposition' predict(object, newdata, ...)
## S3 method for class 'RegressionByComposition' predict(object, newdata, ...)
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
rbc(formula, init, flows, family, data, par, hessian = TRUE)
rbc(formula, init, flows, family, data, par, hessian = TRUE)
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? |
an rbc object
## 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]) )
## 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
## S3 method for class 'RegressionByComposition' residuals(object, ...)
## S3 method for class 'RegressionByComposition' residuals(object, ...)
object |
a RegressionByComposition object; usually the result of a call to rbc() |
... |
ignored |
a vector of probabilities of the same length as the data
Scale flow
Scale
Scale
An object of class Flow
(inherits from R6
) of length 6.
ScaleOdds flow
ScaleOdds
ScaleOdds
An object of class Flow
(inherits from R6
) of length 6.
ScaleRisk0 flow
ScaleRisk0
ScaleRisk0
An object of class Flow
(inherits from R6
) of length 6.
ScaleRisk1 flow
ScaleRisk1
ScaleRisk1
An object of class Flow
(inherits from R6
) of length 6.
Growth from birth to 3 years in healthy babies in the US
starr
starr
starr
A data frame with 104,798 rows and 5 columns:
Anonymized identifier
Sex of baby
Age of baby, in days
Jittered height of baby, in cm
Jittered weight of baby, in kg
...
doi:10.1186/s12874-024-02145-1
Summary of a regression by composition
## S3 method for class 'RegressionByComposition' summary(object, compact = FALSE, ...)
## S3 method for class 'RegressionByComposition' summary(object, compact = FALSE, ...)
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
Translate
Translate
An object of class Flow
(inherits from R6
) of length 6.
TranslateRisk1 flow
TranslateRisk1
TranslateRisk1
An object of class Flow
(inherits from R6
) of length 6.
Extract variance-covariance matrix from a regression by composition
## S3 method for class 'RegressionByComposition' vcov(object, ...)
## S3 method for class 'RegressionByComposition' vcov(object, ...)
object |
a RegressionByComposition object; usually the result of a call to rbc() |
... |
ignored |