function [nb_obs, intercept_t1, intercept_t2, slope_t1, slope_t2, rsq, rms1, bias]= reg_statn(XX, YY, log_base) 

%meas = XX, pred = YY
%log_base = 10, exp(1) or anyother number which means not log based
% Computes the Reduced Major Axis (RMA, type 2) or Least square regression (type 1)
%
% The program returns an array with :
%
%	N : Number of samples
%	Intercept
%	Slope
%	R^2
%	RMS
%	Bias
%
% KEYWORDS :
%	LOG10 is to perform the regression on log-transformed data
%	SHOW_RES prints the results on the monitor
%	TYP1 performs "classic" least square regression
%	MK_PLOT makes a plot of modeled vs observed with 1:1 and regression lines + stats results
%	VERTICAL works with SHOW_RES and displays the results vertically
%	(default is horizontal)


	nb_obs = length(XX);
	if log_base==10 	
        logbase=10
		obs = log10(XX);
		theo = log10(YY);		
    elseif log_base==exp(1)
        logbase=exp(1)
        obs = log(XX);
        theo = log(YY);
    else 	
        obs = XX;
        theo = YY;		
    end
	
	sum_obs = sum(obs);
	sum_theo = sum(theo);	
	sum_sq_obs = sum(obs.^2);
	sum_sq_theo = sum(theo.^2);
	
	buf = theo - obs;	
	sum_diff = sum(buf);
	
	buf = buf.^2;	
	sum_sq_diff = sum(buf);
	
	buf = theo .* obs;
	cov = sum(buf);
		
	rms1 = sqrt(sum_sq_diff/(nb_obs - 2));
					
	bias = sum_diff./nb_obs;

	avg_obs = sum(obs)./nb_obs;
	avg_theo = sum(theo)./nb_obs;
	
	cov = (cov/nb_obs) - (avg_obs * avg_theo);

	stdv_obs = sqrt((sum_sq_obs - (sum_obs^2/nb_obs))/nb_obs);	
	stdv_theo = sqrt((sum_sq_theo - (sum_theo^2/nb_obs))/nb_obs);
	
	slope_t1 = cov/stdv_obs^2;	
	slope_t2 = stdv_theo/stdv_obs;
	
	intercept_t1 = avg_theo - (slope_t1*avg_obs);
	intercept_t2 = avg_theo - (slope_t2*avg_obs);
	
	rsq = (cov/(stdv_obs * stdv_theo))^2;

end

		

