I am looking to find the slope between two vectors via linear regression in Objective C or C (its for xcode). The equation I am attempting to mirror is implemented in matlab. (Info on it here: http://www.mathworks.com/help/techdoc/data_analysis/f1-5937.html)
In matlab the code looks something like this (from the documentation):
x =
11
7
14
11
43
38
61
75
38
28
12
18
18
17
19
32
42
57
44
114
35
11
13
10
y =
11
13
17
13
51
46
132
135
88
36
12
27
19
15
36
47
65
66
55
145
58
12
9
9
Use polyfit to compute a linear regression that predicts y from x:
p = polyfit(x,y,1)
p =
1.5229 -2.1911
p(1) is the slope and p(2) is the intercept of the linear predictor.
I only need the “p(1)” part from an equation similar to this.
Is there a message/method from a framework somewhere that can compute something similar in a C language?
You can code up both the intercept and gradient from your data directly from the formulas here : they are not difficult at all to implement in C
http://en.wikipedia.org/wiki/Simple_linear_regression#Fitting_the_regression_line