Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. n1=25
  2. set.seed(4455)
  3. E<-rnorm(n1,mean=0,sd=0.1)
  4. X<-runif(n1, min = 0, max = 1)
  5. mx=1-X+exp(-200*(X-0.5)^2)
  6. Y <- mx+E
  7. nrep <- 1000
  8.  
  9. #----------------------------------------Fixed NW
  10. mse_rep1<- rmse_rep1<- mae_rep1<- mape_rep1<-c()
  11. for(i in 1:1500){
  12. set.seed(i+236)
  13. E<-rnorm(n1,mean=0,sd=0.1)
  14. X<-runif(n1, min = 0, max = 1)
  15. mx=1-X+exp(-200*(X-0.5)^2)
  16. Y <- mx+E
  17. hmax <- 2 * sqrt(var(X)) * n1^(-1/5)
  18. lower = 0.01 * hmax
  19. h<- bw.ucv(X,nb = 1000, lower=lower, upper=hmax, tol=0.1*lower)
  20. est1 <- ksmooth(X, Y, kernel = "normal", bandwidth = h)$y
  21. mse1<-(n1^-1)*sum((Y - est1)^2)
  22.  
  23. mse_rep1 <- cbind(mse_rep1,mse1)
  24.  
  25. dimnames(mse_rep1)<-list(c("MSE1"),paste("rep",1:i))
  26.  
  27. }
  28. library(functional)
  29. MSE_rep1<-mse_rep1[,apply(mse_rep1, 2, Compose(is.finite, any))]
  30.  
  31. MSE_fixedNW<- apply(MSE_rep1[1:1000], 1, mean) #calculate the average of the 1000 MSE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement