I would like to compute a weighted linear regression of my data, but my data file lists the standard deviation of each point, not the variance.
Is there a way to have an equation in the variance to square my standard deviation? I will be reading my data in from a file.
I have seen the following in the PGFPlotsTable manual, but can't make it work in my instance. I've altered it to do what I want it to do.
\pgfplotstableset{
create on use/vari/.style={
create col/expr={U^2}}
}
My file:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}
\begin{tikzpicture}[baseline]
\begin{axis}[
xlabel={$x$},
ylabel={$y$},
]
\addplot[
only marks,
error bars/.cd, y dir=both, y explicit,
]
table[
x = X,
y = Y,
y error = U,
]
{
X Y U
1 1 1
20 20 4.472
40 35 5.916
60 71 8.426
80 78 8.832
100 114 10.677
};
\addplot[
red,
]
table[
x = X,
y = {create col/linear regression={y=Y, variance=U}}, %this should be U^2
]
{
X Y U
1 1 1
20 20 4.472
40 35 5.916
60 71 8.426
80 78 8.832
100 114 10.677
};
\end{axis}
\end{tikzpicture}
\end{document}