Suppose I want to generate independent data $(y_{i},x_{i})$ such that the conditional mean of $y_{i}$ given $x_{i}$ is a quadratic function in $x_{i}$ and the $.25$ conditional quantile of $y_{i}$ given $x_{i}$ is a function different than the conditional mean function.

I can generate such data with the given conditional mean using R. But how to make the $.25$ conditional quantile function different than the regression function?

  • $\begingroup$ I might be missing the point, but wouldn't $y_i =x_i^2 +\epsilon_i$ where $\epsilon_i$ is normal with mean 0, do the job? $\endgroup$ – Cettt Mar 16 '18 at 6:46
  • $\begingroup$ I am a bit unclear what exactly you require of the quantile. You could follow the advice of @Cettt and draw the noise terms from a normal distribution with a variance that depends on $x_i$, e.g., $\epsilon_i\sim N(0,x_i^2)$, then the quantiles will depend on $x_i$ not only through the mean. $\endgroup$ – Stephan Kolassa Mar 16 '18 at 7:42
  • $\begingroup$ Hi. Thank you all for the useful info. That gave me something to begin with. Thanks. I guess I worked out what I want. Thanks. @StephanKolassa,@Cettt $\endgroup$ – Megadeth Mar 16 '18 at 14:20

A simple approach would be to draw $X\sim U[0,1]$ and $Y\sim N(x^2,x)$, i.e., the variance of $Y$ is $x$. Then the $0.25$ quantile of $Y$ would be $z_{0.25}\sqrt{x}$. Here are simulated data, with the expectation as a black and the quantile as a red line:


R code:

xx <- runif(1e3)
yy <- rnorm(length(xx),xx^2,sqrt(xx))

xx_pred <- seq(.01,.99,by=.01)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.