Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have tried without success to plot the curve of the chi-squared distribution. Is there a generous soul who can come to my rescue.

share|improve this question
13  
Show what you've tried so far in form of a minimal example and add this to your question. –  Thorsten Donig Jan 12 '12 at 20:33
4  
Why haven't you accepted an answer? –  Magpie Jan 22 '13 at 19:11
add comment

2 Answers

If you can access gnuplot, you can try this. This is an adapted version of a gnuplot demo file.

enter image description here

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[%
    xlabel = $x$,
    ylabel = {Probability density},
    samples = 200,
    restrict y to domain = 0:0.5,
    domain = 0.01:15]
    \foreach \k in {0,...,8} {%
      \addplot+[mark={}] gnuplot[raw gnuplot] {%
        isint(x) = (int(x)==x);
        log2 = 0.693147180559945;
        chisq(x,k)=k<=0||!isint(k)?1/0:x<=0?0.0:exp((0.5*k-1.0)*log(x)-0.5*x-lgamma(0.5*k)-k*0.5*log2);
        set xrange [1.00000e-10:15.0000];
        set yrange [0.00000:0.500000];
        samples=200;
        plot chisq(x,\k)};
    \addlegendentryexpanded{$k = \k$}}
  \end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
To see a solution with LuaLaTeX, see here. –  Azoun Jan 15 '12 at 1:07
add comment

if you can use PSTricks, then it is easy. Run the example with xelatex

\documentclass{article} 
\usepackage{pst-plot,pst-func}    
\begin{document}

\psset{xunit=1.2cm,yunit=10cm,plotpoints=200}
\begin{pspicture*}(-0.75,-0.05)(9.5,.65)
\multido{\rnue=0.5+0.5,\iblue=0+10}{10}{%
  \psChiIIDist[linewidth=1pt,linecolor=blue!\iblue,nue=\rnue]{0.01}{9}}
\psaxes[Dy=0.1,ticksize=0 3pt]{->}(0,0)(9.5,.6)
\end{pspicture*}

\end{document}

enter image description here

share|improve this answer
    
Thanks for taking the time to answer my request but when I run the code I have this message of error: ! Package xkeyval Error: plotpoints' undefined in families ,pstricks,pst-grad ,pst-slpe,pst-node,pst-fun'. See the xkeyval package documentation for explanation. Type H <return> for immediate help. ... l.5 \psset{xunit=1.2cm,yunit=10cm,plotpoints=200} ? x Any help would be appreciated. Sincerly. –  Zbigniew Jan 18 '12 at 20:10
    
best result with texlive Unlike MiKTteX. Thank you to everyone. –  Zbigniew Jan 18 '12 at 20:21
    
You may have an outdated version of pstricks. Since you're using TeX Live, call tlmgr update --self --all from your terminal (command prompt). –  Werner Jan 18 '12 at 20:46
    
add \usepackage{pst-plot} to the preamble –  Herbert Jan 18 '12 at 20:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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