I have a dataframe that contains coordinates describing each one gridcell, year indications and several variables which I want to include in my linear regression. I want to perform a simple linear regression for a timeseries of 30 years per gridcell (x,y coordinate pair). So far I grouped the dataset by x and y and nested all other variables so that each row contains one column each with x and y coordinate and one column containing a data rame with the independent and predictor variables and one variable indicating the year
first I load the respective dataframe "df" as rds
then I group the dataset and nest all values per coordinate pair
model<-df %>% mutate_at('year',as.numeric) %>% dplyr::select(-year) %>% group_by(x,y) %>% nest() %>% lm(indep_var~.,data =df) #this is where it does not work.
I also tried
lm(indep_var~.,data =df$data) since the column where all variables are nested in within df is called data but this does not work either. The first option gives the error
Error in model.frame.default(formula = ., data = df, subset = indep_var ~ : invalid type (closure) for the variable 'data' . The second option gives the error
Error in eval(predvars, data, env) : object 'x' not found