0

I want to obtain a multivariate spline basis using R. I do not know how to do it properly or the best approach for this. According to my limited research on the Internet, I think that the package that can help me is mgcv and the functions ti and smooth.construct.tensor.smooth.spec but I am not sure.

The structure of my data is simple. I have two vectors xdata and alphadata generated as

n = 200 
T = 2 


xdata = as.matrix(rnorm(T*n),T*n,1)
tau = seq(-2,2,by=0.1)
tau = as.matrix(tau,length(tau),1)

So basically I have two vectors xdata and alphadata of dimension n*T and 41, respectively. My goal is then obtain a spline basis (for example a cubic spline) which should be a function of both b(alphadata,xdata).

What I have tried so far is something like this

xdata_data <- data.frame("xdata" = xdata[,1])
tau_data <- data.frame("tau" = tau[,1])

basisobj1 <- ti(tau_data, xdata_data,  bs = 'cr', k = c(6, 6), fx = TRUE) #cr:cubic regression splines

xdata_data <- data.frame("xdata_data" = xdata[,1])
tau_data <- data.frame("tau_data" = tau[,1])

basisobj2 <- smooth.construct.tensor.smooth.spec(basisobj1, data = c(tau_data,xdata_data), knots = NULL)

basis <- basisobj2[["X"]]

Note that I manipulated my data, otherwise I get some errors with smooth.construct.tensor.smooth.spec.

My questions are:

(1) With the previous approach I am doing what I want? (2) Is this a smart approach to do what I want? (3) When I do the above, the number of rows of basis is 41 but shouldn't the number of rows of basis be equal to the product of dimensions of xdata and alphadata as the basis is a function of two vectors?

TUC1685
  • 1
  • 1

0 Answers0