Description Usage Arguments Details Examples
This is a simple wrapper to fit and plot a basic type of generalized additive model. The fitted model is of the form gam(Y ~ s(X, k))
, which can be fitted by a specified grouping variable (using the g
argument). Also supported is an optional random effect, in which case the model fitted is gamm(Y ~ s(X, k=k), random = list(R=~1), data=dfr)
.
1 2 3 4 5 |
x |
Variable for X axis (unquoted) |
y |
Variable for Y axis (unquoted) |
g |
Variable for grouping (unquoted); optional |
data |
Dataframe containing x and y |
fittype |
Either 'gam' (default), or 'lm' in which case a simple linear model is fit - useful for comparison. |
kgam |
the |
R |
An optional random effect (quoted) |
log |
Whether to add log axes for x or y (but no transformations are done). |
axes |
Logical (default TRUE), whether to add axes to the plot. |
fitoneline |
Whether to fit only one curve to the entire dataset, regardless of whether a grouping variable was defined. Default FALSE. |
points.col |
Colours of the points, can be a vector (one value for each group, if present). |
lines.col |
Colours of the lines, can be a vector (one value for each group, if present). |
ci.col |
Colour of the confidence band, if plotted. Defaults to a transparent grey colour. |
xlab |
X-axis label |
ylab |
Y-axis label |
band |
Logical. If true, plots the confidence band (as a transparent polygon). |
plotit |
Logical (default TRUE); if FALSE, suppresses the plot. |
add |
Logical (default FALSE), if TRUE, adds to an existing plot. |
npred |
Number of x values to use for prediction |
lwd |
Line thickness (see |
... |
Further arguments passed to |
In either case, the k
parameter necessary for the GAM fit can be set using the kgam
argument. Seechoose.k
for details on this setting (it is important you don't just use the default value here!).
1 2 3 4 5 6 7 | data(Loblolly)
plot_gam(age, height, data=Loblolly)
plot_gam(age, height, Seed, data=Loblolly, band=FALSE, lines.col="black")
plot_gam(age, height, Seed, data=Loblolly, band=FALSE, lines.col="black", fittype="lm")
data(ChickWeight)
plot_gam(Time, weight, Diet, R="Chick", data=ChickWeight, lines.col=rainbow(4))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.