0

I need to run lm on nested data and use map with lm. But I put it in a function to have a different set of independent variables in the model. The code looks like this

predictors1<-c("TWO_YEAR_PRIOR_SCALE_0","PV1.Dim1")

student_progress_model<-function(df, predictors){
  lm(
  as.formula(paste("SCALE_SCORE_0", paste(predictors, collapse="+"), sep="~")),
  data=df, na.action=na.exclude)
}
    
data_nested<-data_nested%>%      
  mutate(
    model=map(data, student_progress_model(df=., predictors=predictors1)),
    stand_resids = map2(data, model, rstandard)
  )

It comes up with the error that object 'SCALE_SCORE_0' not found

How can i specify that my variables are in the data passed to the function? Is it something to do with tidy eval? I tried to put {{}} in my function like

lm(
      as.formula(paste("SCALE_SCORE_0", paste({{predictors}}, collapse="+"), sep="~")),
      data=df, na.action=na.exclude)

But it does not help...

also, will rstandard give me standardised residuals this way?

Thank you

m45ha
  • 399
  • 1
  • 9

0 Answers0