close all;
clear all;
disp(' ')
disp(' John Horel')
disp('atmos 5040 final/6040 midterm')
disp('compare Trax pm2.5 concentrations to other info')

data = csvread('trax_exam.csv',1);
%columns: 1 day; 2 hour; 3 min; 4 distance on red line from hospital (km)
% 5 pm2.5 concentration measured on trax in micrograms per m^3
% 6 pm2.5 concentration measured at mtn met in micrograms per m^3
% 7 pm2.5 concentration measured at hawthorne in micrograms per m^3
% 8 train speed (m/s)
% 9 distance between train and mountain met (km)
% 10 distance between train and hawthorne (km)

%create time vectors
n= length(data(:,1));
t= datenum(2014*ones(n,1),ones(n,1),data(:,1),data(:,2),data(:,3),zeros(n,1));
tv= datevec(t);

%plot trax pm2.5 concentrations
figure(1)
bar(t,data(:,5))
axis('tight')
datetick('x','dd','keepticks','keeplimits')

%Question. Trax 1.
%compute the mean, median, mode, sample standard deviation, 
%skewness, and IQR of the trax pm2.5 concentrations
%for 
%tmean =
%tmedian = 
%tmode = 
%tsd = 
%tskew = 
%tiqr = 

%Question. Trax 2.
%create an empirical cumulative density function of the trax pm2.5 concentrations
%figure(2)



%create vectors for each two miles along red line
%beginning centered at 1 km from the hospital
%a few get into two adjacent bins
%also getting hawthorne data syncd to "downtown" 5km
trax=nan(2000,21);
haw = nan(2000);
for m=1:2:21
    ctr=(m-1)*2+1;
    ind = find(abs(data(:,4)-ctr)<=1.0);
    i=length(ind);
    trax(1:i,m)=data(ind,5);
    if(m==3)
     haw(1:i)=data(ind,7);
    end
end

%Question. Trax 3
%use the info from this boxplot to answer the questions
%remember that col 1 refers to 1 km from the hospital
%and column 21 refers to 41 km from the hospital
%(end of the line is 40.4km)
figure(3)
labels = {'1 km','5 km','9 km','13 km','17 km','21 km',...
    '25 km','29 km','33 km','37 km','41 km'};
boxplot(trax(:,1:2:21),labels,'symbol','o')
xlabel('distance from hospital')
ylabel('PM2.5 Concentration')


%Questions. Trax 4 and 5
%You want to know if the air downtown (5km) is "significantly" dirtier 
%than near the hospital (1km) 
%Using the info on pg 5-1 of the notes, compute the t value for the
%difference between the mean pm2.5 concentration at downtown vs. that
%at the hospital. Use the notation as defined in the problem and 
%you can assume each observation is independent of the others

%don't want to worry about nan's
%so get samples at hospital and 5 km and hawthorne at time when
%downtown oobs available
h_t = trax(~isnan(trax(:,1)),1);
d_t = trax(~isnan(trax(:,3)),3);
hw = haw(~isnan(haw));

%n_h = 
%n_d = 
%mh = 
%md = 
%sh = 
%sd = 
%denom = 
%t = 

%Question 6. We now test whether the t value could have been drawn
%randomly from a Gaussian population with a mean of zero and a weighted population
%standard deviation given by denom. This assumption is ok since
%our sample size is large
%we accept a 1% probability that the t value could have happened by chance
%we use norminv to define the limit above which we can reject the null
%hypothesis. Replace XX and YY with appropriate values
%x_99 = norminv([0,.99],XX,YY);

%Question 7.

%compute the Pearson correlation coefficient between hawthorne and downtown trax
%pm2.5 concentrations

%r=

%get the slope of the linear regression if we were to estimate
% hawthorne from downtown trax
%b = 

% define possible values of downtown from which we will estimate hawthorne 
%(we can choose whatever range of x's we want)
%x = 
%y = 

%define for each value of x, +- 1 standard deviations of hawthorne pm2.5 as ymsd and ypsd
%ypsd = 
%ymsd = 

% plot estimate of y as line and plot original data as points
figure(4)
xlabel('Downtown Trax','FontSize',16)
ylabel('Hawthorne','FontSize',16)
