syxi function

Linear and GAM Spline Predictions from a Single x-Variable

Linear and GAM Spline Predictions from a Single x-Variable

Compute and display (x,y) plots with their linear and gam() spline y-predictions.

syxi(form, data, i = 1)

Arguments

  • form: A "simple" regression formula [y~x] suitable for use with lm().
  • data: data.frame containing at least 10 observations on both variables in the formula.
  • i: A single integer "index" within 1:25.

Details

The gam() functon from the mgcv R-package is used to compute and, subsequently, to generate plots that visually compare the "linear" fit from lm(y~x) with a potentially "nonlinear" fit using smoothing parameters. The horizontal axis on type = "sy" plots gives potentially "straightened out" x numerical values.

Returns

An output list object of class syxi: - dfname: Name of the data.frame object specified as the second argument.

  • xname: "xi" as Two or Three Characters.

  • sxname: "si" as Two or Three Characters.

  • dfsxf: A data.frame containing 3 variables: "yvec", "xvec", and "sxfit".

  • yxcor: Pearson correlation between "yvec" and "xvec".

  • yscor: Pearson correlation between "yvec" and "sxfit".

  • xscor: Pearson correlation between "xvec" and "sxfit".

  • lmyxc: lm() Coefficients (intercept and slope) for y ~ x.

  • lmysc: lm() Coefficients (intercept and slope) for y ~ sxfit.

  • adjR2: Adjusted R2 value from gam.sum$r.sq.

References

Obenchain RL. (2022) Efficient Generalized Ridge Regression. Open Statistics

3 : 1-18. tools:::Rd_expr_doi("10.1515/stat-2022-0108")

Obenchain RL. (2023) Nonlinear Generalized Ridge Regression. arXiv preprint

https://arxiv.org/abs/2103.05161

Author(s)

Bob Obenchain wizbob@att.net

Examples

library(mgcv) data(longley2) form = GNP ~ Year GNPpred = syxi(form, data=longley2, i = 1) plot(GNPpred, type="xy") title(main="y = GNP on x1 = Year") plot(GNPpred, type="sy") title(main="y = GNP on Spline for Year")
  • Maintainer: Bob Obenchain
  • License: GPL-2
  • Last published: 2023-08-07