Learn R Programming

MCMCglmm (version 2.36)

spl: Orthogonal Spline Design Matrix

Description

Orthogonal Spline Design Matrix

Usage

spl(x,  k=10, knots=NULL, type="LRTP")

Value

Design matrix post-multiplied by the inverse square root of the penalty matrix

Arguments

x

a numeric covariate

k

integer, defines knot points at the 1:k/(k+1) quantiles of x

knots

vector of knot points

type

type of spline - currently only low-rank thin-plate ("LRTP") are implemented

Author

Jarrod Hadfield j.hadfield@ed.ac.uk

Examples

Run this code
if (FALSE) {
x<-rnorm(100)
y<-x^2+cos(x)-x+0.2*x^3+rnorm(100)
plot(y~x)
lines((x^2+cos(x)-x+0.2*x^3)[order(x)]~sort(x))

dat<-data.frame(y=y, x=x)

m1<-MCMCglmm(y~x, random=~idv(spl(x)), data=dat, pr=TRUE, verbose=FALSE) # penalised smoother
m2<-MCMCglmm(y~x+spl(x),data=dat,  verbose=FALSE)                        # non-penalised

pred1<-(cbind(m1$X,m1$Z)%*%colMeans(m1$Sol))@x
pred2<-(cbind(m2$X)%*%colMeans(m2$Sol))@x

lines(pred1[order(x)]~sort(x), col="red")
lines(pred2[order(x)]~sort(x), col="green")

m1$DIC-mean(m1$Deviance)  # effective number of parameters < 13
m2$DIC-mean(m2$Deviance)  # effective number of parameters ~ 13
}

Run the code above in your browser using DataLab