Dear R-experts, Here below my R code. The warning message is not a problem to me but there is an error message more problematic. I understand the error message but I don't know if it is possible to correct the error and if yes, how to correct it. Many thanks. n <- 60 b <- runif(n, 0, 5) a <- runif(n, 0, 5) z <- rnorm(n*0.95,2,3) + rnorm(n*0.05,2,9) y_model <- 0.1 * b - 0.5 * z - a + 10 y_obs <- y_model +c( rnorm(n*0.95, 0, 0.1), rnorm(n*0.05, 0, 0.5) ) df<-data.frame(b,a,z,y_obs)
Hi, a is of length 60. b is of length 60. z is of length 57. What do you expect to have happen when you create y_model ? What happens to those other 3 observations? Sarah On Tue, Oct 27, 2020 at 3:07 PM varin sacha via R-help <r-help at r-project.org> wrote:> > Dear R-experts, > > Here below my R code. The warning message is not a problem to me but there is an error message more problematic. I understand the error message but I don't know if it is possible to correct the error and if yes, how to correct it. > > Many thanks. > > > n <- 60 > b <- runif(n, 0, 5) > a <- runif(n, 0, 5) > z <- rnorm(n*0.95,2,3) + rnorm(n*0.05,2,9) > y_model <- 0.1 * b - 0.5 * z - a + 10 > y_obs <- y_model +c( rnorm(n*0.95, 0, 0.1), rnorm(n*0.05, 0, 0.5) ) > df<-data.frame(b,a,z,y_obs) > > ______________________________________________ > 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.-- Sarah Goslee (she/her) http://www.numberwright.com
On 27/10/2020 3:06 p.m., varin sacha via R-help wrote:> Dear R-experts, > > Here below my R code. The warning message is not a problem to me but there is an error message more problematic. I understand the error message but I don't know if it is possible to correct the error and if yes, how to correct it. > > Many thanks. > > > n <- 60 > b <- runif(n, 0, 5) > a <- runif(n, 0, 5) > z <- rnorm(n*0.95,2,3) + rnorm(n*0.05,2,9) > y_model <- 0.1 * b - 0.5 * z - a + 10 > y_obs <- y_model +c( rnorm(n*0.95, 0, 0.1), rnorm(n*0.05, 0, 0.5) ) > df<-data.frame(b,a,z,y_obs) >I suspect you intended to concatenate the two parts of z, i.e. z <- c(rnorm(n*0.95,2,3), rnorm(n*0.05,2,9)) You shouldn't ignore the warning. By the way, it's not true for every n that my expression for z will always give something of length n. It would be safer to do the calculation as m <- round(n*0.95) z <- c(rnorm(m,2,3), rnorm(n-m,2,9) Duncan Murdoch
Dear Varin, I think the following code will solve your problem. n <- 60 b <- runif(n, 0, 5) a <- runif(n, 0, 5) z1 <- data.frame(x0=1:57, x1=rnorm(n*0.95,2,3)) z2 <- data.frame(x0=58:60, x1=rnorm(n*0.05,2,9)) combined=rbind(z1,z2) z=combined[,2] y_model <- 0.1 * b - 0.5 * z - a + 10 y_obs <- y_model +c( rnorm(n*0.95, 0, 0.1), rnorm(n*0.05, 0, 0.5) ) df<-data.frame(b,a,z,y_obs) Thanks. Md On Tue, Oct 27, 2020 at 7:21 PM Sarah Goslee <sarah.goslee at gmail.com> wrote:> Hi, > > a is of length 60. > b is of length 60. > z is of length 57. > > What do you expect to have happen when you create y_model ? What > happens to those other 3 observations? > > Sarah > > On Tue, Oct 27, 2020 at 3:07 PM varin sacha via R-help > <r-help at r-project.org> wrote: > > > > Dear R-experts, > > > > Here below my R code. The warning message is not a problem to me but > there is an error message more problematic. I understand the error message > but I don't know if it is possible to correct the error and if yes, how to > correct it. > > > > Many thanks. > > > > > > n <- 60 > > b <- runif(n, 0, 5) > > a <- runif(n, 0, 5) > > z <- rnorm(n*0.95,2,3) + rnorm(n*0.05,2,9) > > y_model <- 0.1 * b - 0.5 * z - a + 10 > > y_obs <- y_model +c( rnorm(n*0.95, 0, 0.1), rnorm(n*0.05, 0, 0.5) ) > > df<-data.frame(b,a,z,y_obs) > > > > ______________________________________________ > > 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. > > > > -- > Sarah Goslee (she/her) > http://www.numberwright.com > > ______________________________________________ > 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. >-- Best Regards, Md. Moyazzem Hossain Associate Professor Department of Statistics Jahangirnagar University Savar, Dhaka-1342 Bangladesh Website: http://www.juniv.edu/teachers/hossainmm Research: *Google Scholar <https://scholar.google.com/citations?user=-U03XCgAAAAJ&hl=en&oi=ao>*; *ResearchGate <https://www.researchgate.net/profile/Md_Hossain107>*; *ORCID iD <https://orcid.org/0000-0003-3593-6936>* [[alternative HTML version deleted]]
Many thanks Duncan, It works ! Best. Le mardi 27 octobre 2020 ? 20:49:25 UTC+1, Duncan Murdoch <murdoch.duncan at gmail.com> a ?crit : On 27/10/2020 3:06 p.m., varin sacha via R-help wrote:> Dear R-experts, > > Here below my R code. The warning message is not a problem to me but there is an error message more problematic. I understand the error message but I don't know if it is possible to correct the error and if yes, how to correct it. > > Many thanks. > > > n <- 60 > b <- runif(n, 0, 5) > a <- runif(n, 0, 5) > z <- rnorm(n*0.95,2,3) + rnorm(n*0.05,2,9) > y_model <- 0.1 * b - 0.5 * z - a + 10 > y_obs <- y_model +c( rnorm(n*0.95, 0, 0.1), rnorm(n*0.05, 0, 0.5) ) > df<-data.frame(b,a,z,y_obs)>I suspect you intended to concatenate the two parts of z, i.e. ? z <- c(rnorm(n*0.95,2,3), rnorm(n*0.05,2,9)) You shouldn't ignore the warning. By the way, it's not true for every n that my expression for z will always give something of length n.? It would be safer to do the calculation as ? m <- round(n*0.95) ? z <- c(rnorm(m,2,3), rnorm(n-m,2,9) Duncan Murdoch