Hi! I have a dataset that has a response value for each year for each “id”. I want to detrend the response variable (“response”) using 3 different splines (3yr, 5yr, 10yr). I’d like to end up with one value, per ID, per year, per spline, so that the final data would have the following columns: id, year, response, 3yr spline, 5yr spline, 10yr spline. Any help would be greatly appreciated! Simple example below of my data:
id<-c("A","A","A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","B","B","C","C","C","C","C","C","C","C","C","C")
year<-c("2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010")
response<-c(12,11,10,14,9,8,10,7,4,5,8,4,2,6,9,8,10,7,4,5,15,11,12,14,5,8,3,7,2,5)
df<-data.frame(id,year,response)