#####################
# Simulation example
#####################
library(mvnfast)
library(mgcv)
############################################################################
# H0: Covariate X1 does not contribute to interaction effects in the
# prediction model.
# Train data
# Simulate covariates from multivariate standard normal distribution
set.seed(-72498)
nSize <- 100
X <- mvnfast::rmvn(n=nSize, mu=rep(0, 2), sigma=diag(2))
# Response generation
y <- X[, 1]^2 + rnorm(n=nSize, mean=0, sd=0.25)
# Complete data frame
trainDat <- data.frame(X, y=y)
# Test data
# Simulate covariates from multivariate standard normal distribution
testX <- mvnfast::rmvn(n=nSize, mu=rep(0, 2), sigma=diag(2))
# Response generation
testY <- testX[, 1]^2 + rnorm(n=nSize, mean=0, sd=0.25)
testDat <- data.frame(testX, y=testY)
# Estimate generalized additive model with training data
library(mgcv)
gamFit <- gam(formula=y~s(X1)+s(X2), data=trainDat,
family=gaussian())
# Test interaction
testIAD_mpfr1 <- testIAD_mpfr(colInd=1, object=gamFit,
predictfun=function(object, X){
predict(object=object, newdata=X, type="response")
}, X=testDat)
testIAD_mpfr1$pValue
# -> H0 is not rejected with alpha=0.05
###############################################################
# H1: X1 does contribute to at least one interaction effect
# in the prediction model.
# Train data
# Simulate covariates from multivariate standard normal distribution
set.seed(-72498)
nSize <- 150
X <- mvnfast::rmvn(n=nSize, mu=rep(0, 2), sigma=diag(2))
# Response generation
y <- X[, 1]^2 * X[, 2] + rnorm(n=nSize, mean=0, sd=0.25)
# Complete data frame
trainDat <- data.frame(X, y=y)
# Test data
# Simulate covariates from multivariate standard normal distribution
testX <- mvnfast::rmvn(n=nSize, mu=rep(0, 2), sigma=diag(2))
# Response generation
testY <- testX[, 1]^2 * testX[, 2] + rnorm(n=nSize, mean=0, sd=0.25)
testDat <- data.frame(testX, y=testY)
# Estimate generalized additive model with training data
library(mgcv)
gamFit <- gam(formula=y~s(X1, X2, k=25), data=trainDat,
family=gaussian())
# Test interaction
testIAD_mpfr1 <- testIAD_mpfr(colInd=1, object=gamFit,
predictfun=function(object, X){
predict(object=object, newdata=X, type="response")
}, X=testDat)
testIAD_mpfr1$pValue
# -> H0 is rejected with alpha=0.05
Run the code above in your browser using DataLab