plot.sop | R Documentation |
Takes a fitted sop
object produced by sop()
and plots the component smooth functions that make it up, on the scale of the linear predictor.
## S3 method for class 'sop'
plot(x, rug = TRUE, pages = 0, select = NULL, grid, ...)
x |
a fitted |
rug |
when TRUE (default) then the covariate to which the plot applies is displayed as a rug plot at the foot of each plot of a 1-d smooth. Setting to |
pages |
(default 0) the number of pages over which to spread the output. For example, if |
select |
Allows the plot for a single model smooth term to be selected for printing. e.g. if you just want the plot for the second smooth term set |
grid |
number of covariate values 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. Default value 100. |
... |
other graphics parameters to pass on to plotting commands. See details for smooth plot specific options. |
Produces default plot showing the smooth and random components of a fitted SOP.
For smooth terms plot.sop
actually calls plot method functions depending on the dimension of the smooth function.
For plots of smooths in one dimension, the x axis of each plot is labelled with the covariate name, while the y axis is labelled 'f(cov),edf
' where cov
is the covariate name, and edf
the estimated degrees of freedom of the smooth.
Several smooth plots methods using image
will accept a colors
argument, which can be anything documented in topo.colors
(in which case something like colors=rainbow(50)
is appropriate), or the grey
function (in which case something like colors=grey(0:50/50)
is needed).
The function main purpose is to generate plots. It also (silently) returns a list of the data used to produce the plots for the smooth terms. This function is inspired by the plot.gam function of the same name described in mgcv package (but is not a clone).
sop
, predict.sop
library(SOP)
## Simulate the data
set.seed(123)
n <- 1000
sigma <- 0.5
x <- runif(n)
f0 <- function(x) 2*sin(pi*x)
f <- f0(x)
y <- f + rnorm(n, 0, sigma)
dat <- data.frame(x = x, y = y)
# Fit the model
m0 <- sop(formula = y ~ f(x, nseg = 10), data = dat)
summary(m0)
# Plot results
plot(m0)
## An example of use of SOP package with tensor product B-splines in 2D
# Simulate the data
set.seed(123)
n <- 1000
sigma <- 0.1
x1 <- runif(n, -1, 1)
x2 <- runif(n, -1, 1)
f0 <- function(x1, x2) cos(2*pi*sqrt((x1 - 0.5)^2 + (x2 - 0.5)^2))
f <- f0(x1, x2)
y <- f + rnorm(n, 0, sigma)
dat <- data.frame(x1 = x1, x2 = x2, y = y)
m0 <- sop(formula = y ~ f(x1, x2, nseg = 10), data = dat,
control = list(trace = FALSE))
summary(m0)
plot(m0, col = topo.colors(100))
plot(m0, col = grey(0:100/100))
aux <- plot(m0)
names(aux)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.