%% Estimate asymptotic confidence intervals for a nonlinear regression
%% fit using nlparci (Statistics toolbox)

%% Fit simulated dose-response data to a Hill function, given by 
%% y(x) = ymax/(1 + (EC50/dose)^n)

%% Load data
DoseResponse = load('DoseResponseData.dat', '-ascii');
dose = DoseResponse(:,1);
yExpt = DoseResponse(:,2);

%% Call nlinfit to perform nonlinear regression.
betaGuess = [1, 1, 1]; % Initial guess for parameter values
[betaHat, res, Jac, Cov, mse] = nlinfit(dose, yExpt, @Hill, betaGuess);

%% Supply output to nlparci to estimate asymptotic 95% CIs. 
asympCI = nlparci(betaHat, res, 'covar', Cov);

%% Print parameter estimates and asymptotic CIs
[betaHat' asympCI]
