rb: Creates base for a regression based on covariates

Description Usage Arguments Details Value Warning Author(s) References See Also Examples

View source: R/rb.R

Description

Based on given observations a matrix is created that creates a basis e.g. of splines or a markov random field that is evaluated for each observation. Additionally a penalty matrix is generated. Shape constraint p-spline bases can also be specified.

Usage

1
2
3
4
5
6
rb(x, type = c("pspline", "2dspline", "markov", "krig", "random", 
"ridge", "special", "parametric", "penalizedpart_pspline"), B_size = 20, 
B = NA, P = NA, bnd = NA, center = TRUE, by = NA, ...)

mono(x, constraint = c("increase", "decrease", "convex", "concave", "flatend"), 
by = NA)

Arguments

x

Data vector, matrix or data frame. In case of '2dspline', or 'krig' type number of variables of x has to be 2. More dimensions are allowed in 'ridge' and 'special' type. 'markov' and 'random' type require a vector of a factor.

type

Character string defining the type of base that is generated for the given variable(s) x. Further description of the possible options is given below in details.

B_size

Number of basis functions of psplines. Default is 20.

B

For the 'special' type the base B and penalization matrix P are entered manually. The data frame or matrix needs as many rows as observations in x and as many columns as P.

P

Square matrix that has to be provided in 'special' case and with 'markov' type if no bnd is given.

bnd

Object of class bnd, required with 'markov' type if P is not given. See read.bnd.

center

Logical to state whether the basis shall be centered in order to fit additive models with one central intercept.

by

An optional variable defining varying coefficients, either a factor or numeric variable. Per default treatment coding is used. Note that the main effect needs to be specified in a separate basis.

constraint

Character string defining the type of shape constraint that is imposed on the spline curve. The last option 'flatend' results in constant functions at the covariate edges.

...

Currently not used.

Details

Possible types of bases:

pspline

Penalized splines made upon B_size equidistant knots with degree 3. The penalization matrix consists of differences of the second order, see diff.

2dspline

Tensor product of 2 p-spline bases with the same properties as above.

markov

Gaussian markov random field with a neighbourhood structure given by P or bnd.

krig

'kriging' produces a 2-dimensional base, which is calculated as exp(-r/phi)*(1+r/phi) where phi is the maximum euclidean distance between two knots divided by a constant.

random

A 'random' effect is like the 'markov' random field based on a categorial variable, and since there is no neighbourhood structure, P = I.

ridge

In a 'ridge' regression, the base is made from the independent variables while the goal is to determine significant variables from the coefficients. Therefore no penalization is used (P = I).

special

In the 'special' case, B and P are user defined.

parametric

A parametric effect.

penalizedpart_pspline

Penalized splines made upon B_size equidistant knots with degree 3. The penalization matrix consists of differences of the second order, see diff. Generally a P-spline of degree 3 with 2 order penalty can be splited in a linear trend and the deviation of the linear trend. Here only the wiggly deviation of the linear trend is kept. It is possible to combine it with the same covariate of type parametric

Value

List consisting of:

B

Matrix of the evaluated base, one row for each observation, one column for each base element.

P

Penalty square matrix, needed for the smoothing in the regression.

x

The observations x given to the function.

type

The type as given to the function.

bnd

The bnd as given to the function, only needed with 'markov' type.

Zspathelp

Matrix that is also only needed with 'markov' type for calculation of the fitted values.

phi

Constant only needed with 'kriging' type, otherwise 'NA'.

center

The boolean value of the argument center.

by

The variable included in the by argument if available.

xname

Name of the variable x given to the function. Modified by its type.

constraint

Part of the penalty matrix.

B_size

Same as input

P_orig

Original penalty P before restructuring. Used for model selection.

B_mean

Original mean of design matrix B before centering.

param_center

Parameters of centering the covariate.

nbp

Number of penalized parameters in this covariate.

nbunp

Number of unpenalized parameters in this covariate.

Warning

The pspline is now centered around its mean. Thus different results compared to old versions of expectreg occure.

Author(s)

Fabian Otto- Sobotka
Carl von Ossietzky University Oldenburg
http://www.uni-Oldenburg.de

Thomas Kneib, Elmar Spiegel
Georg August University Goettingen
http://www.uni-goettingen.de

Sabine Schnabel
Wageningen University and Research Centre
http://www.wur.nl

Paul Eilers
Erasmus Medical Center Rotterdam
http://www.erasmusmc.nl

References

Fahrmeir L and Kneib T and Lang S (2009) Regression Springer, New York

See Also

quant.bundle, expectreg.ls

Examples

1
2
3
4
5
6
7
x <- rnorm(100)

bx <- rb(x,"pspline")

y <- sample(10,100,replace=TRUE)

by <- rb(y,"random")

expectreg documentation built on Aug. 24, 2019, 1:05 a.m.