# A PGFplots linear regression problem

I'm having problems with the linear regression function in PGFplots. The eq given by the package has the signs changed.

\documentclass[12pt,letterpaper]{article}
\usepackage[letterpaper, margin = 1 in]{geometry}
\usepackage[spanish, es-tabla]{babel}
\usepackage[utf8]{inputenc}
\usepackage{float}

\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{figure}[H]
\centering
\begin{tikzpicture}
\pgfplotsset{width=10cm,
compat=1.3,
legend style={font=\footnotesize}}
\begin{axis}[
xlabel={$\dfrac{T_{e}-T_{a}}{I_{T}}$ [\si{\kelvin \metre\squared\per\watt}]},
ylabel={Eficiencia instantánea $[-]$},
legend cell align=left,
legend pos=north east]
X Y\\
0.0125613   0.7422\\
0.0128012   0.7384\\
0.0130288   0.7217\\
0.0132965   0.6981\\
0.0135467   0.6715\\
};
y={create col/linear regression={y=Y}}]
{
X Y\\
0.0125613   0.7422\\
0.0128012   0.7384\\
0.0130288   0.7217\\
0.0132965   0.6981\\
0.0135467   0.6715\\
};
\end{axis}

\end{tikzpicture}
\end{figure}

$$\hat{\eta_{i}}=\pgfmathprintnumber{\pgfplotstableregressiona} \pgfmathprintnumber[print sign]{\pgfplotstableregressionb}\frac{\Delta T}{I_{T}}$$


Apart from the fact that your document did not compile, you confused the slope with the offset. \pgfplotstableregressiona is the slope and \pgfplotstableregressionb is the offset. If you correct that, you get

\documentclass[12pt,letterpaper]{article}
\usepackage[letterpaper, margin = 1 in]{geometry}
\usepackage[spanish, es-tabla]{babel}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{siunitx}
\usepackage{mathtools}
\usepackage[dvipsnames,table,longtable,x11names]{xcolor}

\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\pgfplotsset{width=10cm,
compat=1.16,
legend style={font=\footnotesize}}
\begin{axis}[
xlabel={$\dfrac{T_{e}-T_{a}}{I_{T}}$ [\si{\kelvin \metre\squared\per\watt}]},
ylabel={Eficiencia instant\'anea $[-]$},
legend cell align=left,
legend pos=north east]
X Y\\
0.0125613   0.7422\\
0.0128012   0.7384\\
0.0130288   0.7217\\
0.0132965   0.6981\\
0.0135467   0.6715\\
};
y={create col/linear regression={y=Y}}]
{
X Y\\
0.0125613   0.7422\\
0.0128012   0.7384\\
0.0130288   0.7217\\
0.0132965   0.6981\\
0.0135467   0.6715\\
};

\end{axis}

\end{tikzpicture}
\end{figure}

$$\hat{\eta_{i}}=\pgfmathprintnumber{\pgfplotstableregressionb} \pgfmathprintnumber[print sign]{\pgfplotstableregressiona}\frac{\Delta T}{I_{T}}$$
\end{document}


• Sorry, I didn't add \begin{document} and \end{document}. On the other hand, if you say that the x = 0, so the y must be approximately 0.74 and not 1.68 Aug 17 '19 at 0:16
• @MijailLittin You forgot also several packages. And no, it should be ~0.74 for x=1.26*10^{-2}.
– user194703
Aug 17 '19 at 0:19