# How to find the conditional CDF based on observed data in R [closed]

If we have two samples (generally their distribution is not known),say $$X\sim N(0,1)$$, $$Y|X\sim N(X,X^2/2)$$. Can we recover the conditional CDF of $$Y|X$$ based on the observed samples in R?

n=1000
x=rnorm(n)
y=rnorm(n,x,x^2/2)


## closed as off-topic by Nick Cox, Peter Flom♦Apr 19 at 11:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Nick Cox, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

• conditional PDF and CDF can be estimated nonparametrically. There is supposedly at least one package available for those purposes. – Gary Moore Apr 19 at 5:05
• Thank you for your kind comment! Do you have the reference for the method of nonparametric estimation and the R package? – J.Mike Apr 19 at 5:26

## 2 Answers

You can't determine the CDF from samples, but you can easily get an empirical estimate:

set.seed(1359)
n <- 1000
x <- rnorm(n)
y <- rnorm(n, x, x^2/2)

LM <- lm(y ~ 0 + x) # no intercept because you know this, though usually you won't
coef(LM)


Gives me $$\hat{\beta} = 1.076$$, or $$\hat{y} = 1.076 \cdot x + \epsilon$$ (about $$1\times x$$, as you specified).

Similarly, you can get an empirical estimate of the standard deviation you supplied with sd(resid(LM)).

If you don't know anything about their distributions, you could try a non-parametric approach.

• Thank you for your answer! Do you have the reference for the nonparametric approach? – J.Mike Apr 19 at 5:28

Finding the conditional distribution of a variable $$Y$$ conditional on another observed variable $$X$$ is the entire subject matter of regression analysis (construed in its wide sense to include linear and nonlinear regression models, GLMs, GLMMs, etc.). This is a huge subject and a core part of statistical education. If you would like to learn more about it, I would recommend starting with some material on linear regression analysis, and then building up from there.