Function to calculate R2 (R-squared) in R

前端 未结 6 777
悲&欢浪女
悲&欢浪女 2020-11-27 15:59

I have a dataframe with observed and modelled data, and I would like to calculate the R2 value. I expected there to be a function I could call for this, but can\'t locate o

6条回答
  •  不知归路
    2020-11-27 16:44

    Why not this:

    rsq <- function(x, y) summary(lm(y~x))$r.squared
    rsq(obs, mod)
    #[1] 0.8560185
    

提交回复
热议问题