Re: [R] Not the same length

2019-09-18 Thread varin sacha via R-help
Ar ! What a pity, I have not seen it ! Many thanks ! Le mercredi 18 septembre 2019 à 19:07:42 UTC+2, peter dalgaard a écrit : Redefining n is probably not a good idea... [...snip...] > m <-runif(n, 0, 5) > n <-rnorm(n, 2, 3) Oops! n is now a vector of length 2000. [...snip...]

Re: [R] Not the same length

2019-09-18 Thread Ana PGG
Dear Varin Sacha, My guess to try to help you is the following: I think you may want to change this: y_obs <- rnorm(n*0.9, y_model, 0.1) + rnorm(n*0.1, y_model, 0.5) for: y_obs <- c( rnorm(n*0.9, y_model, 0.1), rnorm(n*0.1, y_model, 0.5) ) then y_obs: > length(y_obs) [1] 2000 De: varin

Re: [R] Not the same length

2019-09-18 Thread peter dalgaard
Redefining n is probably not a good idea... [...snip...] > m <-runif(n, 0, 5) > n <-rnorm(n, 2, 3) Oops! n is now a vector of length 2000. [...snip...] > y_obs <- y_model +c( rnorm(n*0.97, 0, 0.1), rnorm(n*0.03, 0, 0.5) ) now length(n*0.97) == 2000 > 1, so rnorm(n*0.97, ...) gets you a

Re: [R] Not the same length

2019-09-18 Thread varin sacha via R-help
Dear Peter Dalgaard, Really appreciated, but my code does not work. There is still a problem ! Here below the reproducible example with 20 variables library(mgcv) library(earth) n<-2000 x<-runif(n, 0, 5) z <- rnorm(n, 2, 3) a <- runif(n, 0, 5) b <- rnorm(n, 2, 3) c <- runif(n, 0, 5) d

Re: [R] Not the same length

2019-09-18 Thread peter dalgaard
Um, I think not... The mean of the last 200 observation won't line up with the x and z. Possibly, if what you want is the last 200 obs to have a different variance, y_obs <- y_model + c(rnorm(0.9 * n, 0, 0.1), rnorm(0.1 * n, 0, 0.5)) or y_obs <- rnorm(n, y_model, rep(c(0.1, 0.5), c(.9 * n,

Re: [R] Not the same length

2019-09-17 Thread David Winsemius
On 9/17/19 2:08 PM, David Winsemius wrote: On 9/17/19 1:35 PM, varin sacha wrote: Many thanks David, it perfectly works. Now, one last think. If I want my R code here below to run let's say B=500 times and at the end I want to get the average for the MSE_GAM and for the MSE_MARS. How can I

Re: [R] Not the same length

2019-09-17 Thread David Winsemius
On 9/17/19 1:35 PM, varin sacha wrote: Many thanks David, it perfectly works. Now, one last think. If I want my R code here below to run let's say B=500 times and at the end I want to get the average for the MSE_GAM and for the MSE_MARS. How can I do that ? The `replicate` function is

Re: [R] Not the same length

2019-09-17 Thread varin sacha via R-help
Many thanks Ana, it perfectly works. Le mardi 17 septembre 2019 à 22:12:35 UTC+2, Ana PGG a écrit : Dear Varin Sacha,   My guess to try to help you is the following:   I think you may want to change this: y_obs <- rnorm(n*0.9, y_model, 0.1) + rnorm(n*0.1, y_model, 0.5) for: y_obs

Re: [R] Not the same length

2019-09-17 Thread varin sacha via R-help
Many thanks David, it perfectly works. Now, one last think. If I want my R code here below to run let's say B=500 times and at the end I want to get the average for the MSE_GAM and for the MSE_MARS. How can I do that ? library(mgcv) library(earth) n<-2000 x<-runif(n, 0, 5) z <- runif(n, 0,

Re: [R] Not the same length

2019-09-17 Thread peter dalgaard
It depends on what you want to do, which is likely not what you do do You might be looking for y_obs <- ifelse(runif(n) < .9, rnorm(n, y_model, 0.1), rnorm(n, y_model, 0.5)) -pd > On 17 Sep 2019, at 21:48 , varin sacha via R-help > wrote: > > Dear R-helpers, > > Doing dput(x) and

Re: [R] Not the same length

2019-09-17 Thread David Winsemius
On 9/17/19 12:48 PM, varin sacha via R-help wrote: Dear R-helpers, Doing dput(x) and dput(y_obs), the 2 vectors are not the same length (1800 for y_obs and 2000 for x) How can I solve the problem ? Here is the reproducible R code   #  #  #  #  #  #  #  #  #  # library(mgcv)