varin sacha
2020-Mar-16 21:08 UTC
[R] Code seems OK (no warnings, no error messages) but no results
Good afternoon,
Here below my reproducible R code. I don't get any results. I am looking for
MSE_fastMM value and the bootstrap CIs around MSE_fastMM value. How can I
finish/correct my R code to get the results ?
Many thanks for your help.
####################
install.packages( "robustbase",dependencies=TRUE )
install.packages( "boot",dependencies=TRUE )
library(boot)
library(robustbase)
my.experiment <- function() {{
n<-2000
b<-runif(n, 0, 5)
z <- rnorm(n, 2, 3)
a <- runif(n, 0, 5)
y_model<- 0.1*b - 0.5 * z - a + 10
y_obs <- y_model +c( rnorm(n*0.9, 0, 0.1), rnorm(n*0.1, 0, 0.5) )
fastMM <- lmrob( y_obs ~ b+z+a)
MSE_fastMM<-mean((fastMM$fitted.values - y_model)^2)
return( c(MSE_fastMM) )
}
my.data = t(replicate( 50, my.experiment() ))
colnames(my.data) <- c("MSE_fastMM")
summary(my.data)
data <- data.frame(a, z, b, y_obs)
boot.ci.type <- c("norm","basic", "perc")
MSE_fastMM <- function(data,i) {
? boot.MM <- lmrob(y_obs~b+z+a,data=data[i,])
? mean(boot.MM$residuals^2)
}
bootResults_MM <-boot(data=data, statistic=MSE_fastMM, R=100)
boot.ci(bootResults_MM, type = boot.ci.type)
}
###############################
peter dalgaard
2020-Mar-18 08:44 UTC
[R] Code seems OK (no warnings, no error messages) but no results
The double curlies in> my.experiment <- function() {{look suspicious. -pd> On 16 Mar 2020, at 22:08 , varin sacha via R-help <r-help at r-project.org> wrote: > > Good afternoon, > > Here below my reproducible R code. I don't get any results. I am looking for MSE_fastMM value and the bootstrap CIs around MSE_fastMM value. How can I finish/correct my R code to get the results ? > Many thanks for your help. > > #################### > install.packages( "robustbase",dependencies=TRUE ) > install.packages( "boot",dependencies=TRUE ) > library(boot) > library(robustbase) > > my.experiment <- function() {{ > > n<-2000 > b<-runif(n, 0, 5) > z <- rnorm(n, 2, 3) > a <- runif(n, 0, 5) > > y_model<- 0.1*b - 0.5 * z - a + 10 > y_obs <- y_model +c( rnorm(n*0.9, 0, 0.1), rnorm(n*0.1, 0, 0.5) ) > > fastMM <- lmrob( y_obs ~ b+z+a) > MSE_fastMM<-mean((fastMM$fitted.values - y_model)^2) > > return( c(MSE_fastMM) ) > > } > > my.data = t(replicate( 50, my.experiment() )) > colnames(my.data) <- c("MSE_fastMM") > summary(my.data) > > data <- data.frame(a, z, b, y_obs) > boot.ci.type <- c("norm","basic", "perc") > > MSE_fastMM <- function(data,i) { > boot.MM <- lmrob(y_obs~b+z+a,data=data[i,]) > mean(boot.MM$residuals^2) > } > > bootResults_MM <-boot(data=data, statistic=MSE_fastMM, R=100) > boot.ci(bootResults_MM, type = boot.ci.type) > } > ############################### > > ______________________________________________ > R-help at 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.-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
varin sacha
2020-Mar-18 21:21 UTC
[R] Code seems OK (no warnings, no error messages) but no results
Dear R Experts,
So I managed to get the first part of my R code to work with one error message
but R still gives me the result I am looking for. Now I'm trying to
calculate the bootstrap confidence interval around the "MSE_fastMM"
value.
The end of my code after mean(my.data) does not work (error messages). Any help
for my code to work would be highly appreciated.
####################
install.packages( "robustbase",dependencies=TRUE )
install.packages( "boot",dependencies=TRUE )
library(boot)
library(robustbase)
my.experiment <- function() {
n<-2000
b<-runif(n, 0, 5)
z <- rnorm(n, 2, 3)
a <- runif(n, 0, 5)
y_model<- 0.1*b - 0.5 * z - a + 10
y_obs <- y_model +c( rnorm(n*0.9, 0, 0.1), rnorm(n*0.1, 0, 0.5) )
fastMM <- lmrob( y_obs ~ b+z+a)
MSE_fastMM<-mean((fastMM$fitted.values - y_model)^2)
return( c(MSE_fastMM) )
}
my.data = t(replicate( 50, my.experiment() ))
colnames(my.data) <- c("MSE_fastMM")
mean(my.data)
###BOOTSTRAP CIs###
data <- data.frame(a, z, b, y_obs)
boot.ci.type <- c("norm","basic", "perc")
MSE_fastMM <- function(data,i) {
? boot.MM <- lmrob(y_obs~b+z+a,data=data[i,])
? mean(boot.MM$residuals^2)
}
bootResults_MM <-boot(data=data, statistic=MSE_fastMM, R=100)
boot.ci(bootResults_MM, type = boot.ci.type)
}
####################
Le mercredi 18 mars 2020 ? 09:44:19 UTC+1, peter dalgaard <pdalgd at
gmail.com> a ?crit :
The double curlies in
> my.experiment <- function() {{
look suspicious.
-pd
> On 16 Mar 2020, at 22:08 , varin sacha via R-help <r-help at
r-project.org> wrote:
>
> Good afternoon,
>
> Here below my reproducible R code. I don't get any results. I am
looking for MSE_fastMM value and the bootstrap CIs around MSE_fastMM value. How
can I finish/correct my R code to get the results ?
> Many thanks for your help.
>
> ####################
> install.packages( "robustbase",dependencies=TRUE )
> install.packages( "boot",dependencies=TRUE )
> library(boot)
> library(robustbase)
>
> my.experiment <- function() {{
>
> n<-2000
> b<-runif(n, 0, 5)
> z <- rnorm(n, 2, 3)
> a <- runif(n, 0, 5)
>
> y_model<- 0.1*b - 0.5 * z - a + 10
> y_obs <- y_model +c( rnorm(n*0.9, 0, 0.1), rnorm(n*0.1, 0, 0.5) )
>
> fastMM <- lmrob( y_obs ~ b+z+a)
> MSE_fastMM<-mean((fastMM$fitted.values - y_model)^2)
>
> return( c(MSE_fastMM) )
>
> }
>
> my.data = t(replicate( 50, my.experiment() ))
> colnames(my.data) <- c("MSE_fastMM")
> summary(my.data)
>
> data <- data.frame(a, z, b, y_obs)
> boot.ci.type <- c("norm","basic", "perc")
>
> MSE_fastMM <- function(data,i) {
>? boot.MM <- lmrob(y_obs~b+z+a,data=data[i,])
>? mean(boot.MM$residuals^2)
> }
>
> bootResults_MM <-boot(data=data, statistic=MSE_fastMM, R=100)
> boot.ci(bootResults_MM, type = boot.ci.type)
> }
> ###############################
>
> ______________________________________________
> R-help at 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.
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk? Priv: PDalgd at gmail.com