
 clc;clear;close all

% ------------------------------------------
% average condition: Mean, Median and Mode

data      = readtable('weather_data.xlsx');
sort_data = sortrows(data);  % sorted data by ascending order

mean_temp  = mean(sort_data.Temperature(:,1));
mean_temp_ = nanmean(sort_data.Temperature(:,1)); % nanmean = if you have missing values

median_temp = median(sort_data.Temperature(:,1));
mode_temp   = mode(sort_data.Temperature(:,1));


% -----------------------------------------------------------------------------------------------
% variation analysis: Departure or anomaly, Variance, standard deviation, Minimum, Maximum, Range

departure    = sort_data.Temperature(:,1) - mean(sort_data.Temperature(:,1));
variance     = var(sort_data.Temperature(:,1));
standard_dev = std(sort_data.Temperature(:,1));
minimum      = min(sort_data.Temperature(:,1));
maximum      = max(sort_data.Temperature(:,1));
Range        = range(sort_data.Temperature(:,1));


% -------------------------------------------------
% r = corelation coefficient
% p = statistical significance

temp = data.Temperature;
rain = data.Rainfall;

[r,p] = corrcoef(temp,rain);    % r = 0.71 and p = 0.0019

% comment: there is a significant positive correlation (r = 0.71, p <0.05
% and 0.01) between temperature and rainfall



% ---------------------------------------------------
% regression analyis
% m = slope
% R = corelation coefficient

[R,m,b] = regression(temp,rain,'one');


% ----------------------------------------------------------------
% R-squared (coefficient of determination) and adjusted R-squared

% step 1: fit a linear regression model

mdl = fitlm(temp,rain)

mdl.Rsquared.Ordinary
mdl.Rsquared.Adjusted
