Hello,

That's just

mean(my.data)

Note that

summary(t(my.data))

also gives the mean. (You need to transpose because the way you ran replicate outputs a 1x100 matrix.)


Hope this helps,

Rui Barradas


Às 21:17 de 07/05/20, varin sacha via R-help escreveu:
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)
################################################################

______________________________________________
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.


______________________________________________
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.

Reply via email to