This is not for the real statistic work...
But I need this for simple statistics for students of 15 year of age. To interpretate simple correlation in combination of a scatterplot. (Exam questions). Once I have a basic working example, I can make tons of questions. –
I can draw a scatterplot out of table of data, I can (with the help of others) draw the regression line.But now I want to calculate the correlation with the data of the table.
I already looked atHow to display R^2 value using pgfplots?
But I was not able to adapt it to the solution I want.
So in this example, where XXXXX is printed, I want the correlation (Pearson)
\documentclass[]{article}\usepackage{tikz}\usepackage{pgfplotstable}\begin{document}\begin{center}\pgfplotstableread{ x y 70.6 68 66.2 66.3 73.9 74.1 68.2 71.3 64.2 56.7 69.8 69.6 60.3 62.4 56.8 57.6 55 55.1 67 65.2 57.9 55.7 57.9 59.6 53.1 55.3 61.2 59 66.2 66.6 56.9 52.3 58 57.3 78.5 79.9 63.5 62.5 51 54.1 62.4 67.5 50.5 50.2 61.7 62.4 70.5 73.5}\tableWisFysTrendlijn\begin{tikzpicture}\begin{axis}[title=title, axis lines=center, axis x discontinuity=crunch, axis y discontinuity=crunch, ymin=30, ymax=100, xmin=30, xmax=100, height=10cm, width=\linewidth, ylabel near ticks, xlabel near ticks,xlabel={A},ylabel={B}, scatter/classes={a={mark=*,draw=black}}]\addplot[only marks, mark size = 1pt] table{\tableWisFysTrendlijn};\addplot[no marks,red, thick] table[y={create col/linear regression={y=y}}] {\tableWisFysTrendlijn};\legend{leerling, $y= \pgfmathprintnumber{\pgfplotstableregressiona} \cdot x \pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}\end{axis}\end{tikzpicture}\end{center}The equation is $y= \pgfmathprintnumber{\pgfplotstableregressiona} \cdot x \pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$\\The correlation is: XXXXXXXXXXXX\end{document}