simResponse: Simulate response data given input lagged env data and an...

Description Usage Arguments Value Examples

View source: R/sim_response.R

Description

Simulate response data given input lagged env data and an expression

Usage

1
simResponse(x, mu, rfunc = stats::rnorm, ...)

Arguments

x

data.frame containing at least 1 matrix column of lagged data

mu

R expression describing how mean response relates to variables in x

rfunc

function generating response from mean and parameters in ...

...

additional arguments to rfunc

Value

data.frame with all the variables in x plus a response variable

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
test <- lagData(env_data, response_data, unit = "month", 6, 24, "envVar")
# generate a response linear in the lag, normal errors sd = 5
test1 <- simResponse(test, 0.05*x1 + rowSums(0.1*lag_6_24*envVar_6_24), sd = 5)
fit1 <- mgcv::gam(response ~ x1 + s(lag_6_24, by = envVar_6_24), data = test1)
summary(fit1)

# poisson response with sine function of lag and an offset
test2 <- simResponse(test, exp(-2 + log(offset) - 0.05*x1 +
rowSums(envVar_6_24*sin(lag_6_24/pi))), rpois)
fit2 <- mgcv::gam(response ~ offset(log(offset))  + x1 + s(lag_6_24, by = envVar_6_24),
data = test2, family = poisson)
summary(fit2)

atyre2/flmtools documentation built on Oct. 21, 2020, 5:26 a.m.