如何在 R 中自动计算每组 RMSE 以拟合数据?

问题描述 投票:0回答:0

例如,我有如下数据。

genotype=rep(c("A","B","C","D","E"), each=5)
env=rep(c(10,20,30,40,50), time=5)
outcome=c(10,15,17,19,22,12,13,15,18,25,10,11,12,13,18,11,15,20,22,28,10,9,10,12,15)
dataA=data.frame(genotype,env,outcome)

然后,我想在每个基因型的 outcome 和 env 之间进行拟合,并且还想计算 RMSE。所以,我使用了这段代码。

A=anova(lm(outcome~env,data=subset(dataA, genotype=="A")))

##
Response: outcome
          Df Sum Sq Mean Sq F value   Pr(>F)   
env        1   78.4  78.400      84 0.002746 **
Residuals  3    2.8   0.933   
##

A_rmse=sqrt(0.933)
A_rmse= 0.9659193

我需要用同样的方法计算B和until E的基因型,但是在我的实际数据中,基因型有100多个,所以不可能一一计算。所以我想知道如何自动计算每种基因型的 RMSE(=方差分析表中 MSE 的平方根)。

你能告诉我怎么做吗?

总是非常感谢,

r square-root mse
© www.soinside.com 2019 - 2024. All rights reserved.