0

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]
\addplot[only marks] table[row sep=\\]{
    X Y\\
    0.0125613   0.7422\\
    0.0128012   0.7384\\
    0.0130288   0.7217\\
    0.0132965   0.6981\\
    0.0135467   0.6715\\
};
\addlegendentry{Mediciones}
\addplot[color=NavyBlue,mark=*] table[row sep=\\,
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\\
};
\addlegendentry{Regresión Lineal}
\end{axis}

\end{tikzpicture}
\end{figure}

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

enter image description here

2

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]
\addplot[only marks] table[row sep=\\]{
    X Y\\
    0.0125613   0.7422\\
    0.0128012   0.7384\\
    0.0130288   0.7217\\
    0.0132965   0.6981\\
    0.0135467   0.6715\\
};
\addlegendentry{Mediciones}
\addplot[color=NavyBlue,mark=*] table[row sep=\\,
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\\
};
\addlegendentry{Regresi\'on Lineal}

\end{axis}

\end{tikzpicture}
\end{figure}

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

enter image description here

|improve this answer|||||
  • 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 – Mijail Littin 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}. – Schrödinger's cat Aug 17 '19 at 0:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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