testGAMint | R Documentation |
Simluates the sampling distribution of the F statistic when comparing a linear intreraction model to a generalized additive model with a smooth over the two variables in the interaction.
testGAMint(m1, m2, data, R = 1000, ranCoef = FALSE)
m1 |
An object of class |
m2 |
An object of class |
data |
Data frame used to estimate both models |
R |
Number of simulated F values to create. |
ranCoef |
Logcial indicating whether the coefficients should be treated as fixed or whether they should be drawn from their implied sampling distribution for each iteration of the simulation. |
In simple simulations, an F-test of a linear interaction relative to a smooth interaction with a GAM using a nominal .05 type I error rate, has an actual type I error rate of more than double the nominal rate (this tended to be in the low teens). This function tries to build the F-distribution using simulation. First, it uses the coefficients from the linear interaction model, multiplies them by the coefficients from the linear interaction model and for each iteration of the simulation, it creates the simulated dependent variable by adding a random error to the linear predictor with the same standard deviation as the residual standard deviation from the linear interaction model. All of that is to say that this model has all of the same features as the linear interaction model, except that we are certain that this is the right model. The algorithm then estimates both the linear interaction model and the GAM with a smooth interaction on the original X variables and the new simulated y variable. The F-test is performed and the F-statistic saved for each iteraction. The algorithm then calculates the probability of being to the right of the observed F-statistic in the simulated F-distribution.
obsF |
The observed F-statistic from the test on the original models. |
Fdist |
The |
Dave Armstrong
library(mgcv)
data(InteractionEx)
lmod <- lm(y ~ x1*x2 + z, data=InteractionEx)
gmod <- gam(y ~ te(x1) + te(x2) + ti(x1,x2) + z, data=InteractionEx)
out <- testGAMint(lmod, gmod, data=InteractionEx, R=100)
## calculate p-value
mean(out$Fdist > out$obsF)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.