function alpha_value_calculations_082316 %Type in your file name, including the extension input_file = 'example_areas_and_alpha_values.xlsx'; %input data file name, don't forget the .xls extension input_sheet = 'sheet1'; %excel sheet name [input_data] = xlsread(input_file,input_sheet) %input_data takes in excel data X=input_data(:,1:12); %Forms a matrx of the area data u23expt=input_data(:,13); %Array of mu23/RT values u23err=input_data(:,14); %Array of mu23/RT errors format shortG %Adjusts the length of the float variables Tdt=transpose(X); %Transposes areas matrix for calculating alpha values %This array creates the atom type names for printing a table of the alpha %values from the fits AtomType={'Aliphatic C'; 'Hydroxyl O'; 'Amide O'; 'Amide N'; 'Carboxylate O'; 'Cationic N'; 'Aromatic C'; 'Phosph O'; 'K+'; 'Cl-';'Amine N off aromatic ring'; 'Aromatic N'}; mone=(Tdt*X)^-1; %Creating variable used in fitting and error calculation Alpha_Values = 10000*mone*Tdt*u23expt; %Linear regression producing alpha values %Creates an array of the error squared uer=zeros(length(u23err),1); %Zero array for faster calculation of errors for i=1:length(u23err) uer(i) = u23err(i)^2; end Ohm = diag(u23err.^2); %Finding the diagonal of the error squared matrix aei = mone*Tdt*Ohm*X*mone; %Calculating the error in the alpha values ae=sqrt(aei); %Forming an array of the square root, the diagonal gives the errors %for loop gets the errors from the 'ae' matrix for j=1:length(ae) Alpha_Error(j,1) = 10000*ae(j,j); %Values are multiplied by 10000 to move the decimal to the ones position for the ease of the user end %Print out table of atom types and their alpha values with their errors tbl=table(AtomType, Alpha_Values, Alpha_Error) %This calculates the residuals so that R-square can be calculated %Calculating predicted mu23/RT values tpred=X*Alpha_Values/10000; tperr=X*(Alpha_Values+Alpha_Error)/10000-tpred; %Determines the residuals res=tpred-u23expt; %Calculation of R-square Rsquare=1-sum(res.^2)/sum((u23expt-mean(u23expt)).^2) %Predicted u23/RT values predval = X*Alpha_Values/10000; %Covariance matrix is used to calculate the residuals of the fits cov=mean(res.^2)*mone; fit_a=Alpha_Values/10000; %To adjust the alpha values to their actual value from the prettied calculated values ci=nlparci(fit_a,res,'covar',cov); %Calculates the confidence intervals for each predicted mu23/RT value u23_RTerror = fit_a(1,:) - ci(:,2); %Gets the errors of each predicted mu12/RT from the confidence interval %Prints out the predicted mu23/RT values for each compound plus the %residual errors for each compound. Predicted_vals = [predval, res] %The is to set up the confidence intervals on the plot of mu23/RT versus %compound number. ucld=X*ci(:,1); lcld=X*ci(:,2); %Gives the predicted u23/RT for Records compounds only. Recordu23=u23expt(1:27); Recordpu23=predval(1:27); %Creates a cutoff line for your data versus Redord's data. rec_cutoff = [27.5, 27.5]; recx_co = [-1, 2]; gul = [1:length(u23expt)]; %Zero line setup Zlx = [0, length(u23expt)]; Zly = [0,0]; %Sets up x-values for the lowest and highest experimental mu23/RT values Zl2=[min(u23expt)-.1,max(u23expt)+.1]; %This gets the linear fit and confidence interval of the predicted versus %experimental data fitdata=fit(u23expt,predval,'poly1'); p11=predint(fitdata,u23expt,0.95,'observation','off') %Plots the data for each compounds and shows confidence intervals of %predicted data figure errorbar(u23expt,u23err, 'bo'); hold on; errorbar(predval,tperr,'rs'); hold on; plot(Zlx, Zly, 'm--'); hold on; plot(gul, ucld, 'b--', gul, lcld, 'b--'); hold on; plot(rec_cutoff, recx_co, 'k--'); ylabel('u23/RT'); xlabel('Compound Number'); title('Predicted u23/RT values for each compound'); legend('Experimental u23/RT', 'Predicted u23/RT', 'Zero','Upper Confidence Interval', 'Lower Confidence Interval', 'Cutoff between Records and our compounds'); %Plots the predicted vs the experimental data, plus the confidence interval %of the fit. Two predicted values show up in the second plot so that error %bars can be added to the predicted values. The first green squares are %for the error bars. The second gree squares are from the confidence %interval plot. figure plot(Zl2,Zl2,'m--') hold on errorbar(u23expt,predval,res,'gs'); %Plots the error bars of the predict values hold on; plot(fitdata,u23expt,predval,'gs'); %Plots the confidence intervals for the predicted values hold on; plot(u23expt,p11); hold on; plot(Recordu23,Recordpu23,'rs'); title('Predicted vs Actual u23/RT values'); legend('Line with slope of 1', 'Predicted data', 'Predicted data', 'Linear fit of plot', 'Lower confidence interval', 'Upper confidence interval', 'Records Compouds'); ylabel('Predicted u23/RT'); xlabel('Experimental u23/RT');