Learn R Programming

gplsim

Generalized partially linear single-index models (GPLSIM) are important tools in nonparametric regression. They extend popular generalized linear models to allow flexible nonlinear dependence on some predictors while overcoming the “curse of dimensionality”.

In gplsim package, we provides functions that employ penalised spline (P-spline) to estimate generalised partially linear single index models, which extend the generalised linear models to include nonlinear effect for some predictors.

We are trying to post this package to CRAN for more general users.

Or you can install it simply with the following code in R:

devtools::install_github("zzz1990771/gplsim")
library(gplsim)
?gplsim

If you run into any dependency issues, you can install the dependent package manually:

install.packages("mgcv","minpack.lm")

Quick example:

# parameter settings
n=1000
true.theta = c(1, 1, 1)/sqrt(3)
# Generating data (binary case)
# This function generates a sin bump model as in Yu et al. (2007).
# You may use your data instead.
data <- generate_data(n,true.theta=true.theta,family="binomial")
y=data$Y       # binary response
X=data$X       # single index term ;
Z=data$Z       # partially linear term ;

# Fit the generalised partially linear single-index models
result <- gplsim(y,X,Z,family = binomial)

# Estimation of Theta
result$theta

# The coefficients of the fitted model. 
# Parametric coefficients are first, followed by coefficients for each spline term in turn.
result$coefficients

# summary of the fitted model
summary(result)

#plot the estimated single index function curve
plot_si(result)


# Gaussian case
# This function generate a plain sin bump model with gaussian response.
data <- generate_data(n,true.theta=true.theta,family="gaussian")
y=data$Y       # continous response
X=data$X       # single index term ;
Z=data$Z       # partially linear term ;

result <- gplsim(y,X,Z,family = gaussian)
result$theta
result$coefficients
summary(result)


#plot the estimated single index function curve
plot_si(result)
#par(new=T)
#plot_si(result,index=Z,xaxt="n", yaxt="n",col="red")

# A real data example
data(air)
y=air$ozone               # response
X=as.matrix(air[,3:4])    # single index term ;
Z=air[,2]                 # partially linear term ;

result <- gplsim(y,X,Z=Z,family = gaussian,k=10)
result$theta
result$coefficients
summary(result)

# Or you can try different spline basis
result <- gplsim(y,X,Z=Z,family = gaussian,bs="tp",k=10)
result$theta
result$coefficients
summary(result)

Copy Link

Version

Install

install.packages('gplsim')

Monthly Downloads

201

Version

1.0.0

License

GPL-2

Maintainer

Tianhai Zu

Last Published

February 11th, 2023

Functions in gplsim (1.0.0)

generate_data

Data generation function for simulation and demonstration A sine-bump setting has been employed.
add_sim_bound

function dedicated to add simulation standard error bound, in development draw the bound to current plot
print.summary.gplsim

Print Summary function of gplsim object
si

An internal function to optimization and fitting. Don't use it solely.
plot_si

Function that plot fitted curve for the unknown univariate function for single index term
gplsim

Function to fit generalized partially linear single-index models via penalized splines
summary.gplsim

Summary function of gplsim object
Predict.matrix.tr.smooth

prediction method function for the tr smooth class
smooth.construct.tr.smooth.spec

supporting function to make tr smooth
air

dataset from an environmental study.