[R] [External] Get a result but an error message as well ?

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Tue May 19 22:38:24 CEST 2020


Hi Richard,

Thanks for your response. 
However, how can I correct my R code knowing that I want, as a result, only one value : the mean of the 500 MSE_OLS values ?







Le mardi 19 mai 2020 à 21:59:07 UTC+2, Richard M. Heiberger <rmh using temple.edu> a écrit : 





> dim(my.data)
[1]   1 500

you have a matrix with a single row and 500 columns.
you gave a name to only the first column.

Look at the result of replicate().  it is a vector.  You transposed it into a one-row matrix.

>  tmp <- replicate( 500, my.experiment() )
> dim(tmp)
NULL
> length(tmp)
[1] 500
> dim(t(tmp))
[1]   1 500


On Tue, May 19, 2020 at 3:51 PM varin sacha via R-help <r-help using r-project.org> wrote:
> Dear R-experts,
> 
> Here is my R code, I get a result but I also get an error message so I doubt I can trust the result I get. 
> What is going wrong ? Many thanks.
> 
> ########################################
> a<-c(2,4,3,4,6,5,3,1,2,3,4,3,4,5,65)
> b<-c(23,45,32,12,23,43,56,44,33,11,12,54,23,34,54)
> d<-c(9,4,5,3,2,1,3,4,5,6,4,9,10,11,18)
> 
> my.experiment <- function( ) {
> 
> OLS <- lm( a ~ b+d )
> MSE_OLS<-mean(OLS$residuals^2)
> return( c(MSE_OLS) )
> }
> 
> my.data = t(replicate( 500, my.experiment() ))
> colnames(my.data) <- c("MSE_OLS")
> mean(my.data)
> ########################################
>  
> 
> ______________________________________________
> R-help using 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.
> 



More information about the R-help mailing list