# Random data
set.seed(0)
X1<-runif(50)
s1 <- function(x) exp(2 * x)
e <- rnorm(50)
Y <- s1(X1) + e
### gtPS
res<-gtPS(Y~X1)
res@result
sterms(res)
# model input
rdata<-data.frame(Y,X1)
nullmodel<-lm(Y~X1,data=rdata)
gtPS(nullmodel)
# formula input and termlabels
gtPS(Y~exp(2*X1),data=rdata)
gtPS(Y~exp(2*X1),covs="exp(2 * X1)",data=rdata)
sterms(gtPS(Y~exp(2*X1),data=rdata,termlabels=TRUE))
# P-splines arguments
gtPS(Y~X1, bdeg=3, nint=list(a=10, b=30), pord=0)
gtPS(Y~X1, bdeg=3, nint=list(a=10, b=30), pord=0, robust=TRUE)
# Random data: additive model
X2<-runif(50)
s2 <- function(x) 0.2 * x^11 * (10 * (1 - x))^6 + 10 * (10 * x)^3 * (1 - x)^10
Y <- s1(X1) + s2(X2) + e
gtPS(Y~X1+X2)
gtPS(Y~X1+X2, covs="X2")
sterms(gtPS(Y~X1+X2, nint=list(a=c(10,30), b=20)))
# Random data: smooth surface
s12 <- function(a, b, sa = 1, sb = 1) {
(pi^sa * sb) * (1.2 * exp(-(a - 0.2)^2/sa^2 - (b - 0.3)^2/sb^2) +
0.8 * exp(-(a - 0.7)^2/sa^2 - (b - 0.8)^2/sb^2))
}
Y <- s12(X1,X2) + e
# Tensor product of P-splines
res<-gtPS(Y~X1*X2, interact=TRUE)
res@result
sterms(res)
### gtKS
res<-gtKS(Y~X1*X2)
res@result
sterms(res)
gtKS(Y~X1*X2, quant=seq(.05,.95,.05), robust=TRUE)
### gtLI
library(MASS)
data(Boston)
gtLI(medv~., data=Boston, standardize=TRUE)
Run the code above in your browser using DataLab