proptree: Proportional Trees.

Description Usage Arguments Details Value Methods (by generic) See Also Examples

View source: R/proptree.R

Description

Fit tree models based on the Dirichlet distribution.

Usage

1
2
3
4
5
6
7
proptree(formula, data, na.action, ...)

## S3 method for class 'proptree'
print(x, title = "Proportion tree", objfun = "negative log-likelihood", ...)

## S3 method for class 'proptree'
plot(x, proportions = TRUE, ...)

Arguments

formula

A symbolic description of the model to be fit. This should either be of type 'y1 + y2 + y3 ~ x1 + x2' with reponse vectors 'y1', 'y2', and 'y3' or 'y ~ x1 + x2' with a matrix response 'y'. 'x1' and 'x2' are used as partitioning variables.

data

A data frame containing the variables in the model.

na.action

A function which indicates what should happen when the data contain missing values 'NA'.

...

arguments passed to [partykit::mob_control()], [partykit::print.modelparty()] and [partykit::plot.modelparty()].

x

An object of class 'proptree'.

title

character, title for print method.

objfun

character, labeling objective function.

proportions

logical, display proportions (default) or log-alphas of Dirichlet distribution.

Details

Fit tree models on proportional or compositional data based on the Dirichlet distribution. This funciton is a high-level interface to 'partykit::mob()' in combination with the fitter 'propfit()'.

Value

An object of class 'proptree' inheriting from 'modelparty'.

Methods (by generic)

See Also

[partykit::mob()], [propfit()]

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
### --- toy data ---
set.seed(111)
n <- 500
x <- sample(c(-1, 1), n, replace = TRUE)
alpha <- cbind(
    rnorm(n, 1.4, sd = .1),
    rnorm(n, 1.4, sd = .1),
    jitter(2 + x)
)
y <- alpha / rowSums(alpha)
d <- as.data.frame(y)
names(d) <- paste0("y", 1:3)
d$x <- jitter(x)
tr <- proptree(y1 + y2 + y3 ~ x, data = d)
plot(tr)

### --- Sediment composition  ---
data("ArcticLake", package = "DirichletReg")
tr <- proptree(sand + silt + clay ~ depth, data = ArcticLake)
plot(tr)

meteosimon/proptree documentation built on Feb. 6, 2020, 4:45 a.m.