The amazing, elegant graph below is from this post. Could someone help me make this same graph, but with homoskedasticity (instead of heteroskedasticity)? Perhaps Jake? Thank you, Jake, for the original.

enter image description here

  • 1
    Welcome. Could you please add a minimal working example? – user156344 Mar 20 at 16:12
  • You want the width of the Gaussians to remain constant? If so, this is a simple change of Jake's great answer. The third argument of his functions is the width, you only need to take it equal. – marmot Mar 20 at 16:24

According to Wikipedia you seem to want Gaussians whose width doesn't change when you are asking about homoskedasticity. And this can be achieved with a minimal surgery of Jake's great answer.


    \fill circle [x radius=0.02, y radius=0.08];


\begin{tikzpicture}[ % Define Normal Probability Function
declare function={
            normal(\x,\m,\s) = 1/(2*\s*sqrt(pi))*exp(-(\x-\m)^2/(2*\s^2));
    declare function={invgauss(\a,\b) = sqrt(-2*ln(\a))*cos(deg(2*pi*\b));}
    %no markers,
    zmin=0, zmax=1,
    xmin=0, xmax=3,
   samples y=0,
    axis lines=middle,
    enlarge y limits=false,
    xticklabels={$x_1$, $x_2$, $x_3$},
    xlabel=$x$, xlabel style={at={(rel axis cs:1,0,0)}, anchor=west},
    ylabel=$y$, ylabel style={at={(rel axis cs:0,1,0)}, anchor=south west},
    zlabel=Probability density, zlabel style={at={(rel axis cs:0,0,0.5)}, rotate=90, anchor=south},
    set layers, mark=cube

\addplot3 [gray!50, only marks, mark=dot, mark layer=like plot, samples=200,
domain=0.1:2.9, on layer=axis background] (x, {1.5*(x-0.5)+3+invgauss(rnd,rnd)}, 0);
\addplot3 [samples=2, samples y=0, domain=0:3] (x, {1.5*(x-0.5)+3}, 0);
\addplot3 [cyan!50!black, thick] (0.5, x, {normal(x, 3, 0.75)});
\addplot3 [cyan!50!black, thick] (1.5, x, {normal(x, 4.5, 0.75)});
\addplot3 [cyan!50!black, thick] (2.5, x, {normal(x, 6, 0.75)});

\begin{pgfonlayer}{axis background}
\draw [gray, on layer=axis background] (0.5, 3, 0) -- (0.5, 3, {normal(0,0,0.75)}) (0.5,0,0) -- (0.5,12,0)
    (1.5, 4.5, 0) -- (1.5, 4.5, {normal(0,0,0.7)}) (1.5,0,0) -- (1.5,12,0)
    (2.5, 6, 0) -- (2.5, 6, {normal(0,0,0.75)}) (2.5,0,0) -- (2.5,12,0);


enter image description here

  • Much appreciated! I knew it would be easy for the right person. – twse Mar 20 at 18:15

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.