简体   繁体   English

R中的gam函数错误

[英]Error in gam function in R

I have a problem with my R code about a multiple linear regression.我的 R 代码有关于多元线性回归的问题。 First, I try to use the gam function but this gives me an error.首先,我尝试使用 gam 功能,但这给了我一个错误。 Here is the code:这是代码:

install.packages("nlme")
library("mgcv")
library("ggplot2")
#Import dataset
setwd("/Users/Sarah/Documents/Master T&O/Master 1/Statistics IV/Assignment 2 ")
weight_data = read.csv("WeightLossGroup190.csv", sep = "", dec = ".", header = TRUE)

#Name of used data
weight <- weight_data$weight  
date <- weight_data$date 
dayNr <- weight_data$dayNumber 
time <- weight_data$time 
#Check linearity 
gam1 <- gam(as.numeric(weight_data$weight) ~ s(as.numeric(weight_data$dayNumber)) + s(as.numeric(weight_data$time)))
summary(gam1)
plot.gam(gam1, se = FALSE, rug = TRUE, all.terms = TRUE)

This gives me the following error:这给了我以下错误:

Error in smooth.construct.tp.smooth.spec(object, dk$data, dk$knots) : 
  A term has fewer unique covariate combinations than specified maximum degrees of freedom

Does anyone have an idea of what I'm doing wrong?有谁知道我做错了什么?

您可能想尝试在 gam 中使用“k =”控制节数。

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

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