Gaussian Probability: 1 to 2 in tikz

  • Context: MHB 
  • Thread starter Thread starter karush
  • Start date Start date
  • Tags Tags
    Gaussian Probability
Click For Summary
SUMMARY

This discussion focuses on using TikZ for visualizing Gaussian probability distributions, specifically calculating the area under the curve between z-scores of 1 and 2. Users shared methods for defining Gaussian functions and approximating cumulative distribution functions (CDF) within TikZ. The conversation highlighted the limitations of TikZ in performing integral calculations compared to Desmos, while also providing a workaround using the declare function feature to approximate the area under the Gaussian graph.

PREREQUISITES
  • Familiarity with TikZ and pgfplots packages in LaTeX
  • Understanding of Gaussian probability distributions and z-scores
  • Basic knowledge of LaTeX syntax for defining functions
  • Experience with cumulative distribution functions (CDF) and integration concepts
NEXT STEPS
  • Explore TikZ documentation for advanced plotting techniques
  • Learn about cumulative distribution functions in statistical analysis
  • Research integration methods in LaTeX for mathematical visualization
  • Investigate the capabilities of Desmos for statistical graphing
USEFUL FOR

Mathematicians, statisticians, educators, and anyone interested in visualizing Gaussian distributions using LaTeX and TikZ.

karush
Gold Member
MHB
Messages
3,240
Reaction score
5
\begin{tikzpicture}[scale=0.6]
%preamble \usepackage{pgfplots}
\newcommand\gauss[2]{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))} % Gauss function, parameters mu and sigma
\begin{axis}[every axis plot post/.append style={
mark=none,samples=50,smooth}, % All plots: 50 samples, smooth, no marks
axis x line*=bottom, % no box around the plot, only x axis
axis y line=none, % the * suppresses the arrow tips
enlargelimits=upper, % extend the axes a bit to the right and top
domain=-4:4, % Default for all plots: from -4:4
xtick={1,2},
xticklabels={$1$,$2$},
width=10cm,
height=4cm]
\addplot [fill=cyan!30, draw=none, domain=1:2] {\gauss{0}{1}} \closedcycle;
\addplot {\gauss{0}{1}};
\end{axis}
\end{tikzpicture}

ok this was for P(1<z<2) scaled the graph to .6
the ultimate answer of course is the area in the domain which I don't know if we can derive from the gauss{}{} function
I tried to put the newcommand quass{}{} in the preamble of Overleaf but it didn't take
also thot since all 12 of homework problem are just graphing P()
be nice just have a newcommand \Pg with arguments but also need code that can be colabortive with Overleaf and MHB

again mega mahalo for all the help
 
Physics news on Phys.org
this is what it looks like in Overleaf...

Screenshot 2021-08-13 11.20.21 AM.png
 
I'm afraid that TikZ is not an advanced calculator.
It does not have a function that calculates the area below the Gaussian graph.
And it cannot calculate the integral of a function either.
 
ok well that seems to an advantage of desmos over tikz except tikz is much more exotic
 
Last edited:
karush said:
ok well that seem to an advantage of desmos over tikz except tikz is much more exotic
It appears I misunderstood your question somehow.
Desmos does not have such ability either.
Can you clarify what you want?
 
well i have graph i wanted
i was just curious about integration function in tikx

but yes desmos has a integration function its under misc in the function menu
i have used it many times
 
Well, with a bit of trickery, we can do:
\begin{tikzpicture}[scale=1,
declare function={
gauss(\x,\mean,\sigma) = 1/(\sigma*sqrt(2*pi))*exp(-(\x-\mean)^2/(2*\sigma^2));
normcdf(\x,\m,\s)=1/(1 + exp(-0.07056*((\x-\m)/\s)^3 - 1.5976*(\x-\m)/\s));
},
]
%preamble \usepackage{pgfplots}
\begin{axis}[every axis plot post/.append style={
mark=none,samples=50,smooth}, % All plots: 50 samples, smooth, no marks
axis x line*=bottom, % no box around the plot, only x axis
axis y line=none, % the * suppresses the arrow tips
enlargelimits=upper, % extend the axes a bit to the right and top
domain=-4:4, % Default for all plots: from -4:4
xtick={1,2},
width=10cm,
height=4cm]
\addplot [fill=cyan!30, draw=none, domain=1:2] {gauss(x,0,1)} \closedcycle;
\addplot {gauss(x,0,1)};
\path foreach \y [evaluate=\y as \yeval using {normcdf(\y,0,1)-normcdf(1,0,1)}] in {2} { node[ left ] at (axis cs:{\y},0.05) {\yeval} };
\end{axis}
\end{tikzpicture}

It uses
Code:
[declare function={
    normcdf(\x,\m,\s)=1/(1 + exp(-0.07056*((\x-\m)/\s)^3 - 1.5976*(\x-\m)/\s));
}]
to approximate the area under the Gaussian graph.

And it uses evaluate=\y as \yeval using syntax to convert the function call into a value before printing it.
 
wow that is pretty cool...
 

Similar threads

Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • Poll Poll
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 0 ·
Replies
0
Views
6K