Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n1=25
- set.seed(4455)
- E<-rnorm(n1,mean=0,sd=0.1)
- X<-runif(n1, min = 0, max = 1)
- mx=1-X+exp(-200*(X-0.5)^2)
- Y <- mx+E
- nrep <- 1000
- #----------------------------------------Fixed NW
- mse_rep1<- rmse_rep1<- mae_rep1<- mape_rep1<-c()
- for(i in 1:1500){
- set.seed(i+236)
- E<-rnorm(n1,mean=0,sd=0.1)
- X<-runif(n1, min = 0, max = 1)
- mx=1-X+exp(-200*(X-0.5)^2)
- Y <- mx+E
- hmax <- 2 * sqrt(var(X)) * n1^(-1/5)
- lower = 0.01 * hmax
- h<- bw.ucv(X,nb = 1000, lower=lower, upper=hmax, tol=0.1*lower)
- est1 <- ksmooth(X, Y, kernel = "normal", bandwidth = h)$y
- mse1<-(n1^-1)*sum((Y - est1)^2)
- mse_rep1 <- cbind(mse_rep1,mse1)
- dimnames(mse_rep1)<-list(c("MSE1"),paste("rep",1:i))
- }
- library(functional)
- MSE_rep1<-mse_rep1[,apply(mse_rep1, 2, Compose(is.finite, any))]
- 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