Description Usage Arguments Details Value References Examples

A proof-of-concept implementation of multivariate conditional transformation models

1 2 |

`...` |
marginal transformation models, one for each response |

`formula` |
a model formula describing a model for the dependency
structure via the lambda parameters. The default is set to |

`data` |
a data.frame |

`theta` |
an optional vector of starting values |

`control.outer` |
a list controlling |

`scale` |
logical; parameters are not scaled prior to optimisation by default |

`dofit` |
logical; parameters are fitted by default, otherwise a list with log-likelihood and score function is returned |

The function implements multivariate conditional transformation models as described by Klein et al (2020). The response is assumed absolutely continuous at the moment, discrete versions will be added later.

Below is a simple example for an unconditional bivariate distribution.
See `demo("undernutrition", package = "tram")`

for a conditional
three-variate example.

An object of class `mmlt`

with `coef`

and `predict`

methods.

Nadja Klein, Torsten Hothorn, Luisa Barbanti, Thomas Kneib (2020),
Multivariate Conditional Transformation Models. *Scandinavian Journal
of Statistics*, doi: 10.1111/sjos.12501.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | ```
data("cars")
### fit unconditional bivariate distribution of speed and distance to stop
## fit unconditional marginal transformation models
m_speed <- BoxCox(speed ~ 1, data = cars, support = ss <- c(4, 25),
add = c(-5, 5))
m_dist <- BoxCox(dist ~ 1, data = cars, support = sd <- c(0, 120),
add = c(-5, 5))
## fit multivariate unconditional transformation model
m_speed_dist <- mmlt(m_speed, m_dist, formula = ~ 1, data = cars)
## lambda defining the Cholesky of the precision matrix,
## with standard error
coef(m_speed_dist, newdata = cars[1,], type = "Lambda")
sqrt(vcov(m_speed_dist)["dist.sped.(Intercept)",
"dist.sped.(Intercept)"])
## linear correlation, ie Pearson correlation of speed and dist after
## transformation to bivariate normality
(r <- coef(m_speed_dist, newdata = cars[1,], type = "Corr"))
## Spearman's rho (rank correlation), can be computed easily
## for Gaussian copula as
(rs <- 6 * asin(r / 2) / pi)
## evaluate joint and marginal densities (needs to be more user-friendly)
nd <- expand.grid(c(nd_s <- mkgrid(m_speed, 100), nd_d <- mkgrid(m_dist, 100)))
nd$hs <- predict(m_speed_dist, newdata = nd, marginal = 1L)
nd$hps <- predict(m_speed_dist, newdata = nd, marginal = 1L,
deriv = c("speed" = 1))
nd$hd <- predict(m_speed_dist, newdata = nd, marginal = 2L)
nd$hpd <- predict(m_speed_dist, newdata = nd, marginal = 2L,
deriv = c("dist" = 1))
## joint density
nd$d <- with(nd,
dnorm(hs) *
dnorm(coef(m_speed_dist)["dist.sped.(Intercept)"] * hs + hd) *
hps * hpd)
## compute marginal densities
nd_s <- as.data.frame(nd_s)
nd_s$d <- predict(m_speed_dist, newdata = nd_s, type = "density")
nd_d <- as.data.frame(nd_d)
nd_d$d <- predict(m_speed_dist, newdata = nd_d, marginal = 2L,
type = "density")
## plot bivariate and marginal distribution
col1 <- rgb(.1, .1, .1, .9)
col2 <- rgb(.1, .1, .1, .5)
w <- c(.8, .2)
layout(matrix(c(2, 1, 4, 3), nrow = 2), width = w, height = rev(w))
par(mai = c(1, 1, 0, 0) * par("mai"))
sp <- unique(nd$speed)
di <- unique(nd$dist)
d <- matrix(nd$d, nrow = length(sp))
contour(sp, di, d, xlab = "Speed (in mph)", ylab = "Distance (in ft)", xlim = ss, ylim = sd,
col = col1)
points(cars$speed, cars$dist, pch = 19, col = col2)
mai <- par("mai")
par(mai = c(0, 1, 0, 1) * mai)
plot(d ~ speed, data = nd_s, xlim = ss, type = "n", axes = FALSE,
xlab = "", ylab = "")
polygon(nd_s$speed, nd_s$d, col = col2, border = FALSE)
par(mai = c(1, 0, 1, 0) * mai)
plot(dist ~ d, data = nd_d, ylim = sd, type = "n", axes = FALSE,
xlab = "", ylab = "")
polygon(nd_d$d, nd_d$dist, col = col2, border = FALSE)
### NOTE: marginal densities are NOT normal, nor is the joint
### distribution. The non-normal shape comes from the data-driven
### transformation of both variables to joint normality in this model.
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.