datagen: Generate data over the range of variables used in smooths

Description Usage Arguments Value Author(s) Examples

Description

For each smooth in a GAM, generate new data over the range of the variables in volved in a smooth.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
datagen(x, ...)

## S3 method for class 'mgcv.smooth'
datagen(x, n = 100, data, ...)

## S3 method for class 'gam'
datagen(x, n = 200, ...)

## S3 method for class 'gamm'
datagen(x, ...)

Arguments

x

an object for which new data is required. Currently objects of classes "gam", and "gamm" are supported, as are smooths from mgcv inheriting from class "mgcv.smooth".

...

arguments passed to methods

n

numeric; the number of data values to generate per term in each smooth.

data

data frame; for "mgcv.smooth" objects, the data used to fit the GAM need to be supplied.

Value

A data frame of new values spread over the range of the observed values.

Author(s)

Gavin L. Simpson

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
library("mgcv")

## 1d example
set.seed(2)
dat <- gamSim(1, n = 400, dist = "normal", scale = 2)
m1 <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, method = "REML")
df <- datagen(m1)
head(df)

## 2d example
dat <- gamSim(2, n = 400, dist = "normal", scale = 2)
m2 <- gam(y ~ s(x, z), data = dat$data, method = "REML")
df <- datagen(m2)
head(df)
## alternative showing using the mgcv.smooth method for a single smooth
df2 <- datagen(m2[["smooth"]][[1L]], data = dat$data)
head(df2)

gavinsimpson/tsgam documentation built on May 16, 2019, 10:11 p.m.