Message-ID: <b692e57d-7da6-9676-7ebe-f30a8fe35b13@gmail.com>
Date: 2020-10-27T19:48:22Z
From: Duncan Murdoch
Subject: How to correct my error message
In-Reply-To: <497841733.6368680.1603825619018@mail.yahoo.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