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.

Confidence Interval picture

I've been trying to use the following code to produce it, but have no idea how to shade in the tails I am interested in. By the way, the line pointing the (100-C/2)% can be an arrow, does not have to be squiggly as depicted in the picture.

\begin{tikzpicture}[
every pin edge/.style={<-},
every pin/.style={fill=yellow!50,rectangle,rounded corners=3pt,font=\small}]
\begin{axis}[every axis plot post/.append style={
  mark=none,domain=-3:3,samples=50,smooth},
clip=false,
axis y line=none,
axis x line*=bottom,
ymin=0,
xtick=\empty,
]
\addplot {\gauss{0}{0.5}};
\addplot {\gauss{0}{1}};
\node[pin=70:{$\hat{\theta}_1$}] at (axis cs:0.57,0.5) {};
\node[pin=270:{$E(\hat{\theta} = 0$}] at (axis cs:0,0) {};
\draw[dashed] (axis description cs:0.5,0) -- (axis description cs:0.5,0.92);
\end{axis}
\end{tikzpicture}
share|improve this question
1  
Hi ealfons1, can you please provide a minimal working example (MWE)? The given code does not compile with only a standard document and TikZ as the macro \gauss is undefined. –  Alexander Oct 29 '12 at 16:34
2  
You should refer to related questions (the code sample seems to be based on Gonzalo's answer to tex.stackexchange.com/a/79240/2552). Also, please make sure your examples are not just snippets, but complete minimal documents. And finally, you should be more specific about what you've tried so far and how your question differs from similar ones (why didn't Plotting bell shaped curve in TikZ-PGF, which you've been referred to repeatedly, help you?). –  Jake Oct 29 '12 at 16:48
    
First, I want to say many thanks for helping me out with this one. And next time, I will provide more detail as to what it is I am talking about and what I've tried. The Plotting bell.... question did give me an idea as to how to approach this problem (your answer was my template for trying to work with this), but I couldn't figure out how to add the shaded blue parts at the tail ends of the function. Also, the "thetarzan..." site wasn't helping me figure that out. I also wanted to insert the Zt* labels as well. –  ealfons1 Oct 29 '12 at 17:00
add comment

1 Answer

up vote 13 down vote accepted

Using the code and approach from gauss function Plotting bell shaped curve in TikZ-PGF for plotting the bell curves and shading the areas, you can get the following:

Note that you shouldn't put the domain key into every axis plot post/.style, because then you can't override it locally. Also, smooth doesn't work properly when filling curves, so you should deactivate it and use a higher sample number. For drawing the zero line, I've used an approach from How can I add a zero line to a plot?

\documentclass[11pt]{article}
\usepackage{pgfplots}
\usepackage{siunitx}
\begin{document}
\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{tikzpicture}[
    every pin edge/.style={<-},
    every pin/.style={
        fill=yellow!50,
        rectangle,
        rounded corners=3pt,
        font=\small}
    ]
\begin{axis}[
    every axis plot post/.append style={
        mark=none
    },
    domain=-3:3,
    samples=100,
    clip=false,
    axis y line=none,
    axis x line*=bottom,
    xmin=-3,xmax=3,
    ymin=0,
    xtick=\empty,
]
\addplot [fill=cyan!50, draw=none, domain=-3:-0.8, forget plot] {gauss(0,0.5)} \closedcycle;
\addplot [fill=cyan!50, draw=none, domain=0.8:3, forget plot] {gauss(0,0.5)} \closedcycle;
\addplot {gauss(0,0.5)};
\addplot {gauss(0,1)};
\node[pin=70:{$\hat{\theta}_1$}] at (axis cs:0.57,0.5) {};
\node[pin=270:{$E(\hat{\theta} = 0$}] at (axis cs:0,0) {};
\draw [gray] ({rel axis cs:0,0}-|{axis cs:0,0}) -- ({rel axis cs:0,1}-|{axis cs:0,0});
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
I managed to use this code to produce the picture above perfectly! –  ealfons1 Oct 29 '12 at 17:20
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.