psm.cv: Cross validation for Partial Splines Model

Description Usage Arguments Value Examples

View source: R/psm.cv.R

Description

The aim of this function is to find the best combination of parameters 'prop.knots' and 'alpha' for Partial Splines function through a k-fold Cross Validation.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
psm.cv(
  y,
  x,
  tx,
  k.fold = 4,
  alpha.v = c(1e-04, 0.001, 0.01, 0.1),
  knots.v = c(0.1, 0.2, 0.3),
  plot.it = F,
  ...
)

Arguments

y

response variable, must be a vector

x

explanatory variables, must be a dataframe

tx

spline variable, must be a vector

k.fold

number of folds

alpha.v

vector of alpha values to compare

knots.v

vector of prop.knots values to compare

plot.it

if TRUE, it plots a point for each combination of the parameters; the size of the point is related to the MSE on the test-set. The smaller point is circled in red

...

further arguments passed to 'PartialSplines'

Value

returns a list containing the optimal values for alpha and prop.knots and a dataframe with the mse for each combination of the parameters

Examples

1
2
3
4
5
6
7
x <- data.frame(x = rnorm(100))
tx <- rnorm(100)
eps <- rnorm(100)
y <- x[,1] + tx^4 + eps
cv <- psm.cv(y, x, tx)
alpha <- cv$alpha.opt
prop.knots <- cv$knots.opt

reealpeppe/PSM documentation built on Dec. 22, 2021, 2:06 p.m.