Return something similar to a contrast matrix for a categorical covariate that we wish to be monotonically non-decreasing in a specified order.

1 | ```
contr.isotonic.rev(n, perm, contrasts = TRUE, sparse = FALSE)
``` |

`n` |
a vector of levels for a factor, or the number of levels. |

`perm` |
a permutation of the levels of |

`contrasts` |
a logical indicating whether constrasts should be computed. |

`sparse` |
included for compatibility reasons. Has no effect. |

This function is used in creating the design matrix for categorical covariates with a specified order under a particular parameterisation. This is required if a categorical covariate is defined as monotonic.

In the order specified by `perm`

, the coefficient
associated with each level is the sum of increments between
the following levels. That is, if there are a total of *k*
levels, the first level is defined as *d_2 + d_3 + d_4 + \cdots + d_k*,
the second as *d_3 + d_4 + \cdots + d_k*,
the third as *d_4 + \cdots + d_k*, and so on. In fitting the model,
these increments are constrained to be non-positive.

Note that these are not ‘contrasts’ as defined in the
theory for linear models, rather this is used to define the
`contrasts`

attribute of each variable so that
`model.matrix`

produces the desired design
matrix.

A matrix with `n`

rows and *k* columns, with
*k=n-1* if `contrasts`

is `TRUE`

and
*k=n* if `contrasts`

is `FALSE`

.

Mark W. Donoghoe markdonoghoe@gmail.com

`model.matrix`

, which uses
`contr.isotonic.rev`

to create the design matrix.

`contr.treatment`

, `contrasts`

for
their usual use in regression models.

1 2 3 4 5 6 7 8 | ```
contr.isotonic.rev(4,1:4)
contr.isotonic.rev(4,c(1,3,2,4))
# Show how contr.isotonic.rev applies within model.matrix
x <- factor(round(runif(20,0,2)))
mf <- model.frame(~x)
contrasts(x) <- contr.isotonic.rev(levels(x), levels(x))
model.matrix(mf)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.