fit.BPST: Model Fitting using Bivariate Penalized Spline over...

View source: R/fit.BPST.old.R View source: R/fit.BPST.R

fit.BPSTR Documentation

Model Fitting using Bivariate Penalized Spline over Triangulation

Description

This function conducts the model fitting via bivariate penlized spline over triangulation.

This function conducts the model fitting via bivariate penlized spline over triangulation.

Usage

fit.BPST(
  Y,
  Z,
  V,
  Tr,
  d = 5,
  r = 1,
  lambda = 10^seq(-6, 6, by = 0.5),
  Hmtx = TRUE,
  Kmtx = TRUE,
  QR = TRUE,
  TA = TRUE
)

fit.BPST(
  Y,
  Z,
  V,
  Tr,
  d = 5,
  r = 1,
  lambda = 10^seq(-6, 6, by = 0.5),
  Hmtx = TRUE,
  Kmtx = TRUE,
  QR = TRUE,
  TA = TRUE
)

Arguments

Y

The response variable observed over the domain.

Z

The cooridinates of dimension n by two. Each row is the coordinates of a point.

V

The N by two matrix of vertices of a triangulation, where N is the number of vertices. Each row is the coordinates for a vertex.

Tr

The triangulation matrix of dimention nT by three, where nT is the number of triangles in the triangulation. Each row is the indices of vertices in V.

d

The degree of piecewise polynomials – default is 5, and usually d is greater than one. -1 represents piecewise constant.

r

The smoothness parameter – default is 1, and 0 \le r < d.

lambda

The tuning parameter – default is 10^(-6,-5.5,-5,\ldots,5,5.5,6).

Hmtx

The indicator of whether the smoothness matrix H need to be generated – default is TRUE.

Kmtx

The indicator of whether the energy matrix K need to be generated – default is TRUE.

QR

The indicator of whether a QR decomposition need to be performed on the smoothness matrix – default is TRUE.

TA

The indicator of whether the area of the triangles need to be calculated – default is TRUE.

Details

This R program is modified based on the Matlab program written by Ming-Jun Lai from the University of Georgia and Li Wang from the Iowa State University.

This R program is modified based on the Matlab program written by Ming-Jun Lai from the University of Georgia and Li Wang from the Iowa State University.

Value

A list of vectors and matrice, including:

gamma_hat

The estimated spline coefficients.

lamc

The tuning parameter selected by Generalized Cross Validation (GCV).

B

The spline basis function of dimension n by nT*{(d+1)(d+2)/2}, where n is the number of observationed points, nT is the number of triangles in the given triangulation, and d is the degree of the spline. The length of points means the length of ordering indices of observation points. If some points do not fall in the triangulation, the generation of the spline basis will not take those points into consideration.

Ind.inside

A vector contains the indexes of all the points which are inside the triangulation.

H

The smoothness matrix.

Q2

The Q2 matrix after QR decomposition of the smoothness matrix H.

K

The thin-plate energy function.

tria.all

The area of each triangle within the given triangulation.

A list of vectors and matrice, including:

gamma_hat

The estimated spline coefficients.

lamc

The tuning parameter selected by Generalized Cross Validation (GCV).

B

The spline basis function of dimension n by nT*{(d+1)(d+2)/2}, where n is the number of observationed points, nT is the number of triangles in the given triangulation, and d is the degree of the spline. The length of points means the length of ordering indices of observation points. If some points do not fall in the triangulation, the generation of the spline basis will not take those points into consideration.

Ind.inside

A vector contains the indexes of all the points which are inside the triangulation.

H

The smoothness matrix.

Q2

The Q2 matrix after QR decomposition of the smoothness matrix H.

K

The thin-plate energy function.

tria.all

The area of each triangle within the given triangulation.

Examples

# Triangulation
# Option 1;
# data(V1); data(Tr1); d=5; r=1; V=V1; Tr=Tr1;
# Option 2
data(V2); data(Tr2); d=5; r=1; V=V2; Tr=Tr2;
d=5; r=1;
# Grid Points
n1.grid=101; n2.grid=101; n.grid=n1.grid*n2.grid;
u.grid=seq(0,1,length.out=n1.grid)
v.grid=seq(0,1,length.out=n2.grid)
uu.grid=rep(u.grid,each=n2.grid)
vv.grid=rep(v.grid,times=n1.grid)
Z.grid=as.matrix(cbind(uu.grid,vv.grid))
func=1; sigma=0.1;
gridpoints=data.BPST(Z.grid,V,Tr,func,sigma,2019)
Y.grid=gridpoints$Y; mu.grid=gridpoints$mu;
ind=gridpoints$ind; ind.grid=(1:n.grid)[ind==1];
# Simulation parameters
n=2000;
ind.sam=sort(sample(ind.grid,n))
Y=as.matrix(gridpoints$Y[ind.sam]); Z=as.matrix(gridpoints$Z[ind.sam,]);
mfit=fit.BPST(Y,Z,V,Tr,d,r,lambda=10^seq(-6,6,by=0.5))
rmse=sqrt(mean((Y-mfit$Yhat)^2,na.rm=TRUE))
mpred=predict(mfit,Z.grid)
rmspe=sqrt(mean((Y.grid-mpred$Ypred)^2,na.rm=TRUE))
cat("rmse =",rmse,"and rmspe =",rmspe,"\n")
plot(mfit,Z.grid)
# Triangulation
# Option 1;
# data(V1); data(Tr1); d=5; r=1; V=V1; Tr=Tr1;
# Option 2
data(V2); data(Tr2); d=5; r=1; V=V2; Tr=Tr2;
d=5; r=1;
# Grid Points
n1.grid=101; n2.grid=101; n.grid=n1.grid*n2.grid;
u.grid=seq(0,1,length.out=n1.grid)
v.grid=seq(0,1,length.out=n2.grid)
uu.grid=rep(u.grid,each=n2.grid)
vv.grid=rep(v.grid,times=n1.grid)
Z.grid=as.matrix(cbind(uu.grid,vv.grid))
func=1; sigma=0.1;
gridpoints=data.BPST(Z.grid,V,Tr,func,sigma,2019)
Y.grid=gridpoints$Y; mu.grid=gridpoints$mu;
ind=gridpoints$ind; ind.grid=(1:n.grid)[ind==1];
# Simulation parameters
n=2000;
ind.sam=sort(sample(ind.grid,n))
Y=as.matrix(gridpoints$Y[ind.sam]); Z=as.matrix(gridpoints$Z[ind.sam,]);
mfit=fit.BPST(Y,Z,V,Tr,d,r,lambda=10^seq(-6,6,by=0.5))
rmse=sqrt(mean((Y-mfit$Yhat)^2,na.rm=TRUE))
mpred=predict(mfit,Z.grid)
rmspe=sqrt(mean((Y.grid-mpred$Ypred)^2,na.rm=TRUE))
cat("rmse =",rmse,"and rmspe =",rmspe,"\n")
plot(mfit,Z.grid)

FIRST-Data-Lab/BPST documentation built on Sept. 18, 2023, 7:31 a.m.