[R] Get 3 values not only 1
Jim Lemon
drj|m|emon @end|ng |rom gm@||@com
Wed Jan 27 21:52:21 CET 2021
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 using 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.
More information about the R-help
mailing list