## Simulate some data
n <- 200
x1 <- rnorm(n)
x2 <- rnorm(n)
x3 <- rnorm(n)
x4 <- rnorm(n)
mu <- 4 * exp(8 * x1) / (1 + exp(8 * x1)) + exp(x3)
y <- 5 + mu + rnorm(n)
df1 <- data.frame(y, x1, x2, x3, x4)
## Fit a model
ans <- cgaim(y ~ g(x1, x2, label = "foo") + g(x3, x4, label = "bar"),
data = df1)
## Default plot method
plot(ans)
## Select variable
plot(ans, select = 1)
# Same as
plot(ans, select = "foo")
## Add confidence intervals
ci <- confint(ans)
plot(ans, select = 1, ci = ci)
## Change scale and location
# On the response scale
plot(ans, select = 1, ci = ci, yshift = TRUE, yscale = TRUE)
# Arbitrary scale
plot(ans, select = 1, ci = ci, yshift = 1000)
## Change look
# Main line
plot(ans, select = 1, ci = ci, col = 2, lwd = 3)
# Confidence intervals
plot(ans, select = 1, ci = ci, col = 2, lwd = 3,
ci.args = list(col = adjustcolor(2, .5)))
# Confidence interval type
plot(ans, select = 1, ci = ci, ci.plot = "lines", col = 2, lwd = 3,
ci.args = list(col = 2, lty = 4))
## Put curves on the same plot (need to shift and scale)
plot(ans, select = 1, col = 2, ylim = c(-2, 3))
plot(ans, select = 2, col = 4, add = TRUE)
Run the code above in your browser using DataLab