Hi varin, How about this: Mbv<-data.frame(MSE=rep(NA,1000), biais=rep(NA,1000),variance=rep(NA,1000)) for(i in 1 :1000) { n<-dim(Dataset)[1] p<-0.667 sam<-sample(1 :n,floor(p*n),replace=FALSE) Training <-Dataset [sam,] Testing <- Dataset [-sam,] fit2<-lm(PIB.hab~ISQ.2018) ypred<-predict(fit2,newdata=Testing) y<-Dataset[-sam,]$PIB.hab Mbv$MSE[i] <- mean((y-ypred)^2) Mbv$biais[i] <- mean(ypred-y) Mbv$variance[i] <-mean((ypred- mean(ypred))^2) }
You can then do what you wish to the data frame Mbv. Jim On Thu, Jan 28, 2021 at 7:37 AM varin sacha via R-help <r-help@r-project.org> wrote: > > Dear R-experts, > > Here below my R code working but I would like to get 3 values not only 1. The > value I get is, according to my R code, the variance value. My goal is to get > 3 values : the bias value, the variance value and the MSE value. How to solve > my problem ? > > Many thanks. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.