简体   繁体   English

平滑样条回归的gam函数误差

[英]Error in gam function of smoothing spline regression

I'm trying to run a smoothing spline regression using gam for y as a function of a and b, variables in the dataset. 我正在尝试使用gam for y作为数据集中变量a和b的函数运行平滑样条回归。 But when I run the following code, I get the following error. 但是,当我运行以下代码时,出现以下错误。

> autogam_axb <- gam(data$y~s(data$a,data$b))
Error in eval(expr, envir, enclos) : object 'a' not found

Any idea what I am doing wrong? 知道我在做什么错吗?

You need to separate the model specification from the locations of the data. 您需要将模型规范与数据位置分开。 The former is specified via the formula, whilst the data argument is used to tell gam about the latter: 前者通过公式指定,而data参数用于告知gam后者:

autogam_axb <- gam(y ~ s(a, b), data = data)

This serves two purposes: 这有两个目的:

  1. The specification of the model is clear and not cluttered with data$ , which makes it easier to see what it being fitted, and 该模型的规格清晰明了,并且不会被data$弄乱,这使得查看模型的适应性变得更加容易,并且
  2. You are explicit about where the variables required to fit the model are to be found, but you do this in a single place in the function call. 您明确指出了在哪里可以找到适合模型的变量,但是您可以在函数调用的单个位置中执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM