简单的坐标系为了解释方差分解——如何创建下面的图形?

简单的坐标系为了解释方差分解——如何创建下面的图形?

基于我低水平的初学者乳胶技能,在这种情况下我完全不知所措。我不知道如何创建代码以获得如下所示的所需输出,我想我已经开始错了。

我迄今为止的代码:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    axis lines=middle,
    axis line style={very thick},
    xmin=0,xmax=10,ymin=0,ymax=5,
    xtick distance=1,
    ytick distance=1,
    xlabel=$x$,
    ylabel=$y$,
    title={Varianzzerlegung im linearen Regressionsmodell},
    grid=major,
    grid style={thin,densely dotted,black!20}]
    \addplot [domain=0:10,samples=2] {x*0+2} node[right]{$a$};

    \addplot [domain=0:10,samples=2] {x*1/8+1.5};

    \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述1

答案1

这是一个提议。

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{arrows.meta,decorations.pathmorphing}
\begin{document}
    \begin{tikzpicture}[bullet/.style={circle,fill,inner sep=1pt}]
    \begin{axis}[
    axis lines=middle,
    axis line style={very thick},
    xmin=0,xmax=10,ymin=0,ymax=5,
    xtick distance=1,
    ytick distance=1,
    xlabel=$x$,
    ylabel=$y$,
    title={Varianzzerlegung im linearen Regressionsmodell},
    grid=major,
    grid style={thin,densely dotted,black!20}]
    \addplot [domain=0:10,samples=2] {x*0+2} node[right]{$a$};

    \addplot [domain=0:10,samples=2] {x*1/8+1.5};
    \path  (8,2) node[bullet,label=below:$\bar y$]  (ybari){}
    (8,2.5) node[bullet,label=above:$\widehat{y}_i$] (yhati){} 
    (8,3) node[bullet,label=above:$y_i$] (yi){};
    \draw [thick,decoration={brace}, decorate] ([xshift=-2mm]ybari.west) --
    ([xshift=-2mm]yi.west) node [pos=0.5, left] 
    {$y_i-\bar y$};
    \draw [thick,decoration={brace}, decorate] ([xshift=2mm]yi.east) -- 
    ([xshift=2mm]yhati.east) 
    node [pos=0.5, right] {$y_i-\widehat{y}_i$};
    \draw [thick,decoration={brace}, decorate] ([xshift=2mm]yhati.east) -- 
    ([xshift=2mm]ybari.east) 
    node [pos=0.5, right] {$\widehat{y}_i-\bar y$};

    \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

请注意,除了这些xshifts,您还可以使用raise(但我发现xshift这里的 s 更直观)。

我个人会放大感兴趣的区域。

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{arrows.meta,decorations.pathmorphing}
\begin{document}
    \begin{tikzpicture}[bullet/.style={circle,fill,inner sep=1pt}]
    \begin{axis}[
    axis lines=middle,
    axis line style={very thick},
    xmin=3,xmax=10,ymin=1.5,ymax=3.5,
    xtick distance=1,
    ytick distance=1,
    xlabel=$x$,
    ylabel=$y$,
    title={Varianzzerlegung im linearen Regressionsmodell},
    grid=major,
    grid style={thin,densely dotted,black!20}]
    \addplot [domain=0:10,samples=2] {x*0+2} node[right]{$a$};

    \addplot [domain=0:10,samples=2] {x*1/8+1.5};
    \path  (8,2) node[bullet,label=below:$\bar y$]  (ybari){}
    (8,2.5) node[bullet,label=above:$\widehat{y}_i$] (yhati){} 
    (8,3) node[bullet,label=above:$y_i$] (yi){};
    \draw [thick,decoration={brace}, decorate] ([xshift=-2mm]ybari.west) --
    ([xshift=-2mm]yi.west) node [pos=0.5, left] 
    {$y_i-\bar y$};
    \draw [thick,decoration={brace}, decorate] ([xshift=2mm]yi.east) -- 
    ([xshift=2mm]yhati.east) 
    node [pos=0.5, right] {$y_i-\widehat{y}_i$};
    \draw [thick,decoration={brace}, decorate] ([xshift=2mm]yhati.east) -- 
    ([xshift=2mm]ybari.east) 
    node [pos=0.5, right] {$\widehat{y}_i-\bar y$};

    \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容