Learn R Programming

expectreg (version 0.53)

rb: Creates base for a regression based on covariates

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

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)

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.

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.

Author

Fabian Otto- Sobotka
Carl von Ossietzky University Oldenburg
https://uol.de

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

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

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

Warning

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

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.

%\item{radial}{2-dimensional base, knots are subset of observations, % base is calculated as r^2*log(r) with r equalling % the euclidean distance between the current observation % and the knots. The base has size 50 if possible.}

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

References

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

See Also

quant.bundle, expectreg.ls

Examples

Run this code
x <- rnorm(100)

bx <- rb(x,"pspline")

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

by <- rb(y,"random")

Run the code above in your browser using DataLab