[R] Not the same length

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Tue Sep 17 22:36:31 CEST 2019


Many thanks Ana, it perfectly works.







Le mardi 17 septembre 2019 à 22:12:35 UTC+2, Ana PGG <anacream using gmail.com> 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 <- 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 sacha via R-help
Enviado: martes, 17 de septiembre de 2019 21:49
Para: R-help Mailing List
Asunto: [R] Not the same length
 
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) 
 library(earth) 
 
n<-2000 
x<-runif(n, 0, 5)   
 y_model<- 0.1*x^3 - 0.5 * x^2 - x + 10   
y_obs<-rnorm(n*0.9, y_model, 0.1)+rnorm(n*0.1, y_model, 0.5) 
gam_model<- gam(y_obs~s(x)) 
mars_model<- earth(y_obs~x)   
MSE_GAM<-mean((gam_model$fitted.values - y_model)^2) 
MSE_MARS<-mean((mars_model$fitted.values - y_model)^2)   
MSE_GAM 
MSE_MARS
  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
 
______________________________________________
R-help using 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.
 



More information about the R-help mailing list