Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please answer a) and b) in R programming! Reference: (a) Create a function PredictNearestNeighborsParzen1D = function(yval, xval, xpred, WindowSize) that takes as inputs yval: dependent
Please answer a) and b) in R programming!
Reference:
(a) Create a function PredictNearestNeighborsParzen1D = function(yval, xval, xpred, WindowSize) that takes as inputs yval: dependent variable for each data point xval: independent variable for each data point xpred: vector of independent variable values at which the forecast is made WindowSize: Parzen window's size and returns as output NNpreds: vector of predictions for each entry of the vector xpred (b) Consider in-sample and out-of-sample simulated observations as in the code used to generate the experiments of the Slide Set 2 (available on Moodle) with 200 in-sample and 200 out-of-sample observations (instead of 60 in sample and 60 out of sample). Moreover, consider a model of the form Y=0.05X53X2+. Set the random seed equal to 2022. All the other parameters should be defined as in the code of Slide Set 2. \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#GENERATE IN-SAMPLE AND OUT-OF-SAMPLE DATASETS\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# set.seed(1986) \#Set the random seed (ensures results are reproducible) nIN=60 \# number of observations insample nOOS =60 \# number of observations out-of-sample x_min =2# min x value xmax=2#maxx value xvalIS =(xmax-x_min ) runif ( nIN )+xmin xvaloOS =(xmax-x_min )runif( nOOS )+xmin fIS = xvalIS^3 \#true pattern for insample observations foos = xvaloos^3 \#true pattern for out-of-sample observations yobsIS = fIS + rnorm(nIN) \# noisy in sample observations yobsoOs = foOs + rnorm(nOOS) \# noisy out-of-sample observations plot(xvalIS,yobsIS, main='In-sample observations', xlab= 'Predictor x ', ylab= 'Response y ') plot (xvaloos, yobsoos, main='Out-of-sample observations', xlab= Predictor x ', y lab = 'Response y ')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started