function R2_result = R2_linear(x_regr,y_regr,beta_1,beta_2);

% best fit to data linear: y=beta_1*x +beta_2

y_fit = beta_1.*x_regr + beta_2;
y_diff = y_regr - y_fit;

sum_y_reg = sum(y_regr);
n_element = length(y_regr);
sst = sum(y_regr.^2)-(sum_y_reg^2)/n_element;
sse = sum(y_diff.^2);

R2_result = 1 - sse/sst;
