Code seems OK (no warnings, no error messages) but no results

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Code seems OK (no warnings, no error messages) but no results

R help mailing list-2
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)
}
###############################

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: Code seems OK (no warnings, no error messages) but no results

Peter Dalgaard-2

The double curlies in

> my.experiment <- function() {{

look suspicious.

-pd

> On 16 Mar 2020, at 22:08 , varin sacha via R-help <[hidden email]> 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)
> }
> ###############################
>
> ______________________________________________
> [hidden email] 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: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: Code seems OK (no warnings, no error messages) but no results

R help mailing list-2
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 <[hidden email]> a écrit :






The double curlies in

> my.experiment <- function() {{

look suspicious.

-pd

> On 16 Mar 2020, at 22:08 , varin sacha via R-help <[hidden email]> 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)
> }
> ###############################
>
> ______________________________________________
> [hidden email] 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: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] 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.