[R] Replication : How to get only 1 value
varin sacha
v@r|n@@ch@ @end|ng |rom y@hoo@|r
Thu May 7 22:17:15 CEST 2020
Dear R-experts,
My goal is to get only 1 value : the average/ the mean of the 100 MSE values. How can I finish my R code ?
###################################################################
my.experiment <- function() {
n<-500
x<-runif(n, 0, 5)
z <- rnorm(n, 2, 3)
a <- runif(n, 0, 5)
y_model<- 0.1*x^3 - 0.5 * z^2 - a + 10
y_obs <- y_model +c( rnorm(n*0.97, 0, 0.1), rnorm(n*0.03, 0, 0.5) )
fit1<- lm(y_obs~x^3+z^2+a)
MSE<-mean((fit1$fitted.values - y_model)^2)
return( c(MSE) )
}
my.data = t(replicate( 100, my.experiment() ))
summary(my.data)
################################################################
More information about the R-help
mailing list