I want to do a linear regression by removing values to evaluate the performance of the regressions in terms of correlation coefficient in comparison to a threshold value
datas <- data.frame(x= c(0,0.45,2,8,10,18,30,45,50,52),y= c(1,3,5,7,9,17,26,44,48,50))
This is my function and i dont know how can remove first or last point and run and compare the result automatically
formula_lm <- as.formula(paste0(py,"~",px))
model <- lm(formula_lm, data = df)
rslt <- df %>%
mutate(a = round(model$coefficients[2],3),
r_carre = round(summary(model)$r.squared,3),
comp_val_critic = ifelse(r_carre <=threeshold, "linearity_down","linearity_high"))
rslt
} ```
Use function
``` lm_f(df = datas,
py = "y",
px = "x")```