plot.mgamViz | R Documentation |
This function is similar to plot.gamViz, but it is used to plot multiple quantile GAM models fitted using mqgamV or mqgam. It allows plotting standards 1D and 2D smooths, and parametric effects, It is basically a wrapper around plotting methods that are specific to individual smooth effect classes (such as plot.multi.mgcv.smooth.1D).
## S3 method for class 'mgamViz'
plot(x, n = 100, n2 = 40, select = NULL, allTerms = FALSE, ...)
x |
an object of class |
n |
number of points used for each 1-d plot. For a nice smooth plot this needs to be several times the estimated degrees of freedom for the smooth. |
n2 |
square root of number of grid points used for plotting 2D functions effects using contours or heatmaps. |
select |
allows plotting a subset of model terms. For instance, if you just want the plot
for the second smooth term, set |
allTerms |
if |
... |
other parameters, such as |
An object of class c("plotGam", "gg")
.
library(mgcViz)
set.seed(2) ## simulate some data...
dat <- gamSim(1,n=500,dist="normal",scale=2)
dat$logi <- as.logical( sample(c(TRUE, FALSE), nrow(dat), replace = TRUE) )
dat$fac <- as.factor( sample(c("A1", "A2", "A3"), nrow(dat), replace = TRUE) )
# Fit GAM and get gamViz object
fit <- mqgamV(y ~ fac + s(x0) + s(x1, x2) + x3 + logi, data = dat,
qu = c(0.2, 0.4, 0.6, 0.8))
print(plot(fit, select = 1:4, allTerms = T), pages = 1)
## Not run:
# Example where we are fitting the same model to different datasets, but
# plotting the estimate effects together
dat <- list()
for(ii in 1:4){
# Simulate 4 datasets, we are adding 2 factor variables "fac" and "ref" just
# for illustrating the plotting method (the two factors have no effect on y)
n <- 1000
dat[[ii]] <- gamSim(1,n=n,dist="normal",scale=2)
dat[[ii]]$fac <- as.factor( sample(c("A1", "A2", "A3"), n, replace = TRUE) )
dat[[ii]]$ref <- as.factor( sample(letters[1:10], n, replace = TRUE) )
}
# Estimating model on each dataset
mods <- list()
for(ii in 1:4){
mods[[ii]] <- gamV(y~s(x0)+s(x1, x2)+x3+fac+s(ref, bs = "re"), data = dat[[ii]])
}
# Names will be used to identify the four models we have fitted
names(mods) <- c("M1", "M2", "M3", "M4")
# Plotting on the same plots
print(plot.mgamViz(mods, allTerms = TRUE), pages = 1)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.