# I think standard deviation of y is related to size of x. How do I create a model for this / test this?

I have a sample of data $$(x_i, y_i)$$. I hypothesize that $$y_i$$ is not dependent on $$x_i$$, but the standard deviation of $$y_i$$ depends on $$x_i$$

More concretely, say I assume $$\textrm{Var}(y_i | x_i) = f(x_i)$$. This could be say $$cx_i^2$$ for some value of $$c$$. The question is that how do I visualize this and how do I model this? Right now because I do not have multiple value of $$y_i$$ for same value of $$x_i$$, it is not possible to compute the standard standard deviation.

One way to model this type of relationship is by using generalized least squares (GLS).

GLS allows you to specify variables which have a relationship not just with the mean of the response, but also the variance.

Here is how you can do that in R:

GLS <- gls(y ~ x, weights = varPower(form = ~ x), data = data)

• I'm not familiar with gls syntax; is varPower() here saying that the variance of y is a function of the mean of x and not its variance (as the question asks for)? If so, can it be changed to accommodate that?
– mkt
Commented Jul 17 at 21:00
• This is a pretty good starting place. Thanks a lot. Does varPower(form=~x) mean the variance is linear or x? Commented Jul 18 at 8:58
• @Lost1 varPower estimates a power-relationship between $x$ and the variance of $y$. There are multiple alternatives described in the help page for varClasses Commented Jul 18 at 9:23

You are asking models of the variance function, or something in the same vein.

There has to be some sort of smoothing in the variance model, because we don't expect anything useful can be done if each $$Var(y_i\mid x_i)$$ has a completely different parameter. The $$c$$ in your example has done that smoothing. If the # of parameters is low compared to sample size, usual estimation techniques (e.g., mle) should work well. Visualization following estimation is then straightforward, e.g., a curve from your estimated variance function overlapped with squared residuals vs $$x$$.

However, another quick nonparametric check is to group $$x_i$$ into bins so that you have multiple $$Y$$ for each bin of $$X$$.

PS: Better to have a good model on $$E(Y_i\mid X_i)$$ first, before spending too much effort in the variance model.

• PS: Be sure to have a good model on $E(Y_i\mid X_i)$ first, before spending too much effort in the variance model. Commented Jul 17 at 16:09
• You can edit your post and add the postscript. Welcome to CV! Commented Jul 17 at 17:41