# A Simple Transformation Model

First, install and fire-up R on your computer. Within R, one needs to install the tram package by typing

```
install.packages("tram")
```

and hitting the ENTER key. The tram package implements simple formula-based interfaces to some important transformation models. The models themself are fitted using algorithms implemented in mlt add-on package.

Once the package is installed, you can load it using

```
library("tram")
```

```
## Loading required package: mlt
```

```
## Loading required package: basefun
```

```
## Loading required package: variables
```

```
## Loading required package: mvtnorm
```

Now all tram functions are ready to be used, for example the Colr() function for fitting a series of potentially stratified logistic regression models to a continuous outcome variable (let’s start with median Boston Housing values):

```
data("BostonHousing2", package = "mlbench")
library("survival")
BostonHousing2$y <- with(BostonHousing2, Surv(cmedv, cmedv < 50))
Colr_BH_1 <- Colr(y | 0 + chas ~ crim + zn + indus + nox +
rm + age + dis + rad + tax + ptratio + b + lstat,
data = BostonHousing2, support = c(10, 50))
summary(Colr_BH_1)
```

```
##
## (Stratified) Continuous Outcome Logistic Regression
##
## Call:
## Colr(formula = y | 0 + chas ~ crim + zn + indus + nox + rm +
## age + dis + rad + tax + ptratio + b + lstat, data = BostonHousing2,
## support = c(10, 50))
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## crim 0.082647 0.013712 6.027 1.67e-09 ***
## zn -0.010271 0.004923 -2.086 0.0369 *
## indus -0.025173 0.021448 -1.174 0.2405
## nox 7.073292 1.491804 4.741 2.12e-06 ***
## rm -1.534703 0.218959 -7.009 2.40e-12 ***
## age 0.008426 0.005118 1.646 0.0997 .
## dis 0.496542 0.077790 6.383 1.73e-10 ***
## rad -0.120792 0.024925 -4.846 1.26e-06 ***
## tax 0.006482 0.001334 4.861 1.17e-06 ***
## ptratio 0.395692 0.048313 8.190 2.22e-16 ***
## b -0.006452 0.001112 -5.802 6.54e-09 ***
## lstat 0.281476 0.026504 10.620 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Log-Likelihood:
## -1297.489 (df = 26)
## Likelihood-ratio Test: Chisq = 879.7637 on 12 degrees of freedom; p = < 2.2e-16
```

Two separate transformation function are fitted (for houses near and off Charles river, variable chas). The remaining variables enter a linear predictor those coefficients can be interpreted as log-odds ratios. Note that median housing values larger than 50 are correctly treated as being right-censored in the likelihood-

The model can be used to extract the corresponding conditional distribution functions. Let’s put the first house into two locations, near and off Charles river. Then, we compute the two conditional distribution functions:

```
nd <- BostonHousing2[c(1, 1),]
nd$chas <- sort(unique(BostonHousing2$chas))
library("colorspace")
col <- diverge_hcl(2, h = c(246, 40), c = 96, l = c(65, 90))
plot(as.mlt(Colr_BH_1), newdata = nd, type = "distribution", col = col)
legend("bottomright", legend = c("Off", "Near"), title = "Charles river",
col = col, lty = 1, bty = "n")
```

It appears that houses near the river are more expensive, and the variability is also larger compared to houses far away from the river.

The most important feature in this model is that the shape of these distributions have been estimated from data although the models are fully parametric! An introduction to the underlying technology with many more examples is available from the mlt.docreg package vignette.