Lineare regression mit pgfplot

Tabellen und Grafiken erstellen und anordnen


prisma89

Lineare regression mit pgfplot

Beitrag von prisma89 »

Hallo,

ich erstelle meine Diagramme alle mit pgfplot. Funktioniert bisher auch ganz gut. Jetzt benötige ich aber eine regressions Gerade durch meine Datenpunkte an der Stelle komme ich mit dem Manual nicht weiter.
Die Regressionsgerade wird zwar erstellt allerdings liegt sie falsch.

Kann mir jenamd sagen wo mein Fehler ist?

PS: ja die Datentabelle ist viel größer. Ich habe nur alle anderen Datenreihen für das Diagramm raus gelöscht damit es übersichtlicher ist


\begin{filecontents}{datatableU}
a	b	c	d	e	f	g	h	i	j	k	l	m	n	o	p	q	r	s	t	u	v	w	x	y	z	aa	ab	ac	ad	ae	af	ag	ah	ai	aj	ak	
0	5.3493	0	0.00	13.55	0.00	0.00	5.1809	0	0.00	12.83	0.00	0.00	10.2819	0.00	0.00	25.11	0.00	0.00	10.3986	0.00	0.00	25.47	0.00	0.00	20.4651	0.00	0.00	47.57	0.00	0.00	20.4762	0.00	0.00	47.55	0.00	0.00
1	5.3529	3.6	0.07	15.48	1.93	14.25	5.1840	3.1	0.06	14.70	1.87	14.56	10.2861	4.20	0.04	26.93	1.82	7.24	10.4020	3.40	0.03	27.34	1.87	7.34	20.4688	3.75	0.02	48.55	0.98	2.06	20.4799	3.70	0.02	49.44	1.89	3.97
2	5.3544	5.1	0.10	16.13	2.58	19.05	5.1860	5.05	0.10	15.36	2.53	19.71	10.2879	5.95	0.06	27.68	2.56	10.21	10.4046	6.00	0.06	27.98	2.51	9.85	20.4709	5.85	0.03	50.36	2.79	5.87	20.4821	5.95	0.03	50.15	2.60	5.47
3	5.3562	6.85	0.13	16.69	3.15	23.22	5.1881	7.2	0.14	15.91	3.08	23.99	10.2892	7.25	0.07	28.14	3.03	12.06	10.4066	8.00	0.08	28.50	3.03	11.91	20.4725	7.40	0.04	50.83	3.26	6.85	20.4831	6.95	0.03	50.69	3.13	6.59
4	5.3565	7.15	0.13	17.06	3.51	25.92	5.1883	7.4	0.14	16.31	3.48	27.12	10.2903	8.40	0.08	28.59	3.48	13.84	10.4065	7.90	0.08	28.98	3.51	13.77	20.4730	7.95	0.04	51.19	3.63	7.62	20.4843	8.15	0.04	51.11	3.55	7.47
20	5.3728	23.5	0.44	23.40	9.85	72.71	5.2042	23.25	0.45	22.61	9.78	76.20	10.3057	23.80	0.23	34.84	9.72	38.72	10.4224	23.80	0.23	35.30	9.83	38.61	20.4899	24.85	0.12	57.45	9.88	20.77	20.5010	24.80	0.12	57.54	9.99	21.00
24	5.3738	24.5	0.46	24.09	10.54	77.84	5.2055	24.6	0.47	23.31	10.48	81.68	10.3070	25.10	0.24	35.99	10.87	43.30	10.4240	25.45	0.24	35.99	10.52	41.29	20.4916	26.55	0.13	58.18	10.62	22.32	20.5022	26.05	0.13	58.22	10.67	22.43
41	5.3814	32.05	0.60	27.32	13.77	101.67	5.2127	31.75	0.61	26.44	13.61	106.05	10.3153	33.40	0.32	39.17	14.06	55.98	10.4320	33.40	0.32	39.42	13.95	54.76	20.4995	34.45	0.17	61.62	14.06	29.55	20.5109	34.75	0.17	61.81	14.26	29.98
64	5.3907	41.35	0.77	30.38	16.84	124.29	5.2217	40.75	0.79	29.27	16.44	128.12	10.3280	46.10	0.45	43.01	17.90	71.26	10.4430	44.45	0.43	43.46	17.99	70.61	20.5116	46.50	0.23	65.84	18.27	38.41	20.5228	46.65	0.23	65.83	18.28	38.44
88	5.3960	46.65	0.87	32.78	19.23	141.97	5.2269	45.95	0.89	31.46	18.63	145.20	10.3351	53.15	0.52	46.49	21.37	85.11	10.4521	53.50	0.51	46.92	21.45	84.23	20.5208	55.75	0.27	69.60	22.04	46.32	20.5319	55.70	0.27	69.75	22.20	46.68
161	5.4075	58.15	1.09	38.99	25.44	187.81	5.2382	57.25	1.11	37.52	24.69	192.41	10.3588	76.85	0.75	57.16	32.05	127.60	10.4759	77.30	0.74	57.73	32.26	126.66	20.5463	81.25	0.40	79.45	31.88	67.03	20.5578	81.60	0.40	79.71	32.16	67.62
205	5.4101	60.8	1.14	40.07	26.52	195.78	5.2403	59.4	1.15	38.26	25.43	198.22	10.3710	89.10	0.87	61.93	36.81	146.59	10.4877	89.15	0.86	62.50	37.03	145.39	20.5612	96.10	0.47	85.07	37.50	78.84	20.5724	96.25	0.47	85.26	37.71	79.30
248	5.4094	60.05	1.12	40.62	27.08	199.89	5.2396	58.7	1.13	38.82	25.99	202.53	10.3780	96.10	0.93	65.70	40.59	161.62	10.4950	96.40	0.93	66.31	40.84	160.36	20.5731	108.00	0.53	91.22	43.65	91.77	20.5845	108.30	0.53	91.27	43.72	91.93
413	5.4119	62.55	1.17	41.64	28.09	207.40	5.2416	60.7	1.17	39.47	26.64	207.61	10.3973	115.35	1.12	73.28	48.17	191.81	10.5144	115.85	1.11	74.14	48.67	191.07	20.6106	145.55	0.71	107.75	60.18	126.52	20.6223	146.15	0.71	107.82	60.27	126.73
557	5.4098	60.45	1.13	41.63	28.09	207.35	5.2394	58.5	1.13	39.31	26.48	206.39	10.4014	119.45	1.16	75.58	50.47	200.96	10.5187	120.15	1.16	76.49	51.02	200.32	20.6302	165.10	0.81	116.87	69.30	145.68	20.6417	165.55	0.81	116.71	69.15	145.42
866	5.4111	61.8	1.16	41.89	28.34	209.24	5.2408	59.9	1.16	39.83	27.00	210.45	10.4066	124.65	1.21	78.43	53.32	212.31	10.5251	126.50	1.22	79.43	53.95	211.84	20.6651	200.00	0.98	132.85	85.28	179.28	20.6769	200.70	0.98	132.49	84.94	178.62
1250	5.4124	63.1	1.18	42.82	29.27	216.11	5.2430	62.05	1.20	40.64	27.81	216.77	10.4105	128.60	1.25	79.93	54.81	218.27	10.5285	129.90	1.25	81.12	55.65	218.51	20.6887	223.65	1.09	143.95	96.39	202.63	20.7006	224.45	1.10	143.58	96.03	201.93
1922	5.4085	59.15	1.11	42.68	29.13	215.05	5.2387	57.75	1.11	40.58	27.75	216.25	10.4063	124.40	1.21	80.38	55.26	220.06	10.5237	125.10	1.20	81.49	56.02	219.93	20.7013	236.20	1.15	153.69	106.12	223.09	20.7124	236.20	1.15	152.65	105.09	221.00
\end{filecontents}

\documentclass[12pt,a4paper]{scrreprt}
\usepackage[ngerman]{babel}    
\usepackage[T1]{fontenc}  
\usepackage[utf8]{inputenc}

\usepackage[locale=DE]{siunitx}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\pgfplotstableread{Dateien/TXT/AP2_CR39_Korrelation.txt}	
	{\datatableU}	
	
\begin{document}

\begin{tikzpicture}
	

\begin{axis}
		[		
				%Überschrift
				title= {},
				%X-Achse
				xlabel= $\Delta$,
				xmax = 2,
				xmin = 0,
				xticklabel style={/pgf/number format/.cd,fixed,precision=1},
				% Y-Achse
				ylabel= $\Delta$,
				ymax = 120,
				ymin = 0.1,
				yticklabel style={/pgf/number format/precision=0},
				% Gitterlinien
				grid = major,
				width= 13cm,
				height=9cm,			
				% Postition Legende
		]
				{
		
		\addplot table [only marks, x = d,y = f ] from \datatableU;
				\addplot table[y={create col/linear regression={y=f}}] from \datatableU;
		}

		\end{axis}
\end{tikzpicture}
		
\end{document}