R: Formulae for BAMLSS

bamlss.formula {bamlss} | R Documentation

## Formulae for BAMLSS

### Description

This function creates an extended BAMLSS `formula`. In combination with a `bamlss.family` object, each parameter of the response distribution is linked to a single formula. If no formula is supplied for a parameter, a simple intercept only model is created. Moreover, the function identifies hierarchical structures, see the examples. This function is useful for creating complex `model.frame`s for (hierarchical) multi-parameter models and is used by function `bamlss.frame`.

### Usage

    bamlss.formula(formula, family = NULL, specials = NULL, env = NULL, ...)

### Arguments

`formula` | A simple `formula`, or a `list` of simple formulae, or an extended `Formula`. For formula lists or extended `Formula`e, each single formula represents one model for the respective parameter as specified in the `family` object.
`family` | A `bamlss.family` object.
`specials` | A character vector specifying special functions to be used within formulae, see `terms.object`.
`env` | The environment that should be assigned to the formula.
`...` | Arguments passed to the `family`.

### Value

A named list of class `"bamlss.formula"`. Each list entry specifies a model, e.g., for one parameter of a provided `bamlss.family` object. Each entry (parameter model) then holds:

`formula` | A simple `formula`.
`fake.formula` | A formula with all function calls being dropped, e.g., the formula `y ~ s(x1) + s(x2)` is represented in the `fake.formula` entry as `y ~ x1 + x2`. The `fake.formula` is useful for creating model frames.

### See Also

`bamlss`, `bamlss.frame`, `bamlss.family`

### Examples

    ## Simple formula without family object.
    f <- bamlss.formula(y ~ x1 + s(x2))
    print(f)
    print(str(f))

    ## Complex formula with list of formulae.
    f <- list(
      y1 ~ x1 + s(x2),
      y2 ~ x3 + te(lon, lat),
      u ~ x4 + x1
    )

    f <- bamlss.formula(f)
    print(f)
    print(names(f))

    ## Same formula but using extended formulae
    ## of package Formula.
    f <- y1|y2|u ~ x1 + s(x2)|x3 + te(lon,lat)|x4 + x1
    f <- bamlss.formula(f)
    print(f)
    print(names(f))

    ## Using a bamlss family object, e.g., gaussian_bamlss().
    ## The family has two parameters, mu and sigma, for
    ## each parameter one formula is returned. If no
    ## formula is specified an intercept only model is
    ## generated for the respective parameter.
    f <- bamlss.formula(y ~ x1 + s(x2), family = gaussian_bamlss)

    ## Note, same as:
    f <- bamlss.formula(y ~ x1 + s(x2), family = "gaussian")
    print(f)

    ## Specify model for parameter sigma, too
    f <- list(
      y ~ x1 + s(x2),
      sigma ~ x2 + te(lon, lat)
    )
    f <- bamlss.formula(f, family = "gaussian")
    print(f)

    ## With complex hierarchical structures,
    ## each parameter is another list of formulae,
    ## indicated by the h1,...,hk, names.
    f <- list(
      y ~ x1 + s(x2) + id1,
      sigma ~ x2 + te(lon, lat) + id2,
      id1 ~ s(x3) + x4 + s(id3),
      id3 ~ x5 + s(x5, x6),
      id2 ~ x7
    )
    f <- bamlss.formula(f, family = "gaussian")
    print(f)

[Package bamlss version 1.1-7 Index]