jeudi 29 juin 2017

How to generate random numbers in R given a pointwise estimated conditional density?

Given random variables (X,Y) which are dependent, the fact that I know the distribution of X ~ N(0.05, 0.0057) and the given data from experiments ((x1, y1), ..., (x100,y100) I estimated a bandwidth and the conditional density f(Y|X=x) via kernel regression. I now want to generate samples of X using x_sample = rnorm(n, mean=0.05, sd=0.0057) and calculate the conditional density for that sample (meaning: f(Y|X=x_sample)). I evaluate the kernel regression on my datapoints (y1, ..., y100)to get a pointwise density for that given X=x_sample (via

f_hat = function(u, v){ (sum(K(abs(u-data$x)/H_n) * (K(abs(v-data$y)/h_n)))) / (h_n * sum(K(abs(u-data$x)/H_n))) }

with H_nand h_nbeing the bandwidths, data$x, data$ybeing my data and K(u)being the gaussian kernel).

See: Picture of the pointwise estimated density for a sampled X=x

and: Using npregbw and npreg to estimate the pointwise density into a still not continous nor integrable "density"

My Question now: How can I sample a big amount of y given X=x_sample? I need this data to afterwards estimate the distribution of Y.




Aucun commentaire:

Enregistrer un commentaire