线性回归的问题

线性回归的问题

我在使用 PGFplots 中的线性回归函数时遇到了问题。我使用此图得到的结果太陡峭了。表格位于外部文件中,我将其放在第一个图中,这样您就可以看到我的数据。

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[babel,german=guillemets]{csquotes}
\usepackage[backend=biber]{biblatex}
\usepackage{pgfplots,tikz}
\pgfplotsset{compat=1.12}
\usepackage{pgfplotstable}
\begin{document}
\begin{figure}[htbp]
    \label{pic:cmn25}
    \begin{center}
    \begin{tikzpicture}
    \begin{axis}
    [
        width=14cm,
        xlabel={$c_A^2 [-]$},
        ylabel={$c_W [-]$},
        ymin=0.1, ymax=0.25,
        xmin=-0.1, xmax=1.3,
        legend pos=north west,
        legend entries={mit HLW,
                        ohne HLW,
                        lin. mit HLW,
                        lin. ohne HLW},
    ]
    \addplot table[x={cA2_mit},y={cW_mit}]
    {
    cW_mit  cA2_mit cW_ohne cA2_ohne
0.119   0.008   0.113   0.000
0.116   0.042   0.111   0.031
0.117   0.162   0.111   0.111
0.123   0.346   0.117   0.240
0.137   0.570   0.125   0.394
0.155   0.796   0.140   0.555
0.177   1.001   0.157   0.679
0.201   1.185   0.178   0.796
    };
    \addplot table[x={cA2_ohne},y={cW_ohne}]
    {
    cW_mit  cA2_mit cW_ohne cA2_ohne
0.119   0.008   0.113   0.000
0.116   0.042   0.111   0.031
0.117   0.162   0.111   0.111
0.123   0.346   0.117   0.240
0.137   0.570   0.125   0.394
0.155   0.796   0.140   0.555
0.177   1.001   0.157   0.679
0.201   1.185   0.178   0.796
    };
    \addplot [thick, blue] table[y={create col/linear regression={y=cW_mit}}]
    {
    cW_mit  cA2_mit cW_ohne cA2_ohne
0.119   0.008   0.113   0.000
0.116   0.042   0.111   0.031
0.117   0.162   0.111   0.111
0.123   0.346   0.117   0.240
0.137   0.570   0.125   0.394
0.155   0.796   0.140   0.555
0.177   1.001   0.157   0.679
0.201   1.185   0.178   0.796
    };
    \addplot [thick, red] table[y={create col/linear regression={y=cW_ohne}}]
    {
    cW_mit  cA2_mit cW_ohne cA2_ohne
0.119   0.008   0.113   0.000
0.116   0.042   0.111   0.031
0.117   0.162   0.111   0.111
0.123   0.346   0.117   0.240
0.137   0.570   0.125   0.394
0.155   0.796   0.140   0.555
0.177   1.001   0.157   0.679
0.201   1.185   0.178   0.796
    };
    \end{axis}
    \end{tikzpicture}
    \caption{$c_{mN25}$ über $\alpha$}
    \end{center}
\end{figure}
\end{document}

我的结果如下:

结果

它们看起来应该像这样(使用 excel 完成)

在此处输入图片描述

答案1

找到解决方案。在以下行中:

\addplot [thick, red] table[y={create col/linear regression={y=cW_ohne}}]

我必须为 x 值添加一列:

\addplot [thick, red] table[**x={cA2_ohne}**,y={create col/linear regression={y=cW_ohne}}]

我不知道为什么我不必在另一个图表中这样做。哦,好吧,我希望这对某些人有帮助。

相关内容