Description Usage Arguments Details Value Author(s) Examples
Given an additive quantile model, fitted using qgam
, cqcheck2DI
provides some interactive
2D plots that allow to check what proportion of responses, y
, falls below the fitted quantile.
This is an interactive version of the cqcheck
function.
1 2 3 4 5 6 7 8 9 |
obj |
the output of a |
v |
if a 1D plot is required, |
X |
a dataframe containing the data used to obtain the conditional quantiles. By default it is NULL, in which
case predictions are made using the model matrix in |
y |
vector of responses. Its i-th entry corresponds to the i-th row of X. By default it is NULL, in which
case it is internally set to |
run |
if TRUE (default) the function produces an interactive plot, otherwise it returns the corresponding shiny app. |
width |
the width of the main plot. Default is "100%". |
height |
width the width of the main plot. Default is "680px". |
This is an interactive version of the cqcheck
, see ?cqcheck
for details. The main interactive
feature is that one can select an area by brushing, and then double-click to zoom in. In the 1D case the vertical
part of the selected area is not use: we zoom only along the x axis. Double-clicking without brushing zooms out.
Simply produces an interactive plot.
Matteo Fasiolo <matteo.fasiolo@gmail.com>.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | ## Not run:
#######
# Example 1: Bivariate additive model y~1+x+x^2+z+x*z/2+e, e~N(0, 1)
#######
library(qgam)
set.seed(15560)
n <- 1000
x <- rnorm(n, 0, 1); z <- rnorm(n)
X <- cbind(1, x, x^2, z, x*z)
beta <- c(0, 1, 1, 1, 0.5)
y <- drop(X %*% beta) + rnorm(n)
dataf <- data.frame(cbind(y, x, z))
names(dataf) <- c("y", "x", "z")
#### Fit a constant model for median
qu <- 0.5
fit <- qgam(y~1, qu = qu, data = dataf)
# Look at what happens along x: clearly there is non linear pattern here
cqcheckI(obj = fit, v = c("x"), X = dataf, y = y)
#### Add a smooth for x
fit <- qgam(y~s(x), qu = qu, data = dataf)
cqcheckI(obj = fit, v = c("x"), X = dataf, y = y) # Better!
# Lets look across across x and z. As we move along z (x2 in the plot)
# the colour changes from green to red
cqcheckI(obj = fit, v = c("x", "z"), X = dataf, y = y)
# The effect look pretty linear
cqcheckI(obj = fit, v = c("z"), X = dataf, y = y)
#### Lets add a linear effect for z
fit <- qgam(y~s(x)+z, qu = qu, data = dataf)
# Looks better!
cqcheckI(obj = fit, v = c("z"))
# Lets look across x and y again: green prevails on the top-left to bottom-right
# diagonal, while the other diagonal is mainly red.
cqcheckI(obj = fit, v = c("x", "z"))
### Maybe adding an interaction would help?
fit <- qgam(y~s(x)+z+I(x*z), qu = qu, data = dataf)
# It does! The real model is: y ~ 1 + x + x^2 + z + x*z/2 + e, e ~ N(0, 1)
cqcheckI(obj = fit, v = c("x", "z"))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.