deaseasonalize temperature data using means
3 views (last 30 days)
Show older comments
I have a set of data that includes dates (years from 1995-2018 and months (1-12), where dv(:,1)=year and dv(:,2)=month. It also includes temperature (temp). The dataset has 350,000 data points. I would like to find the monthly mean for each year (e.g., Jan 1995, Jan 1996...Jan 2018) and the mean for each year (e.g., 1995, 1996...2018). To deaseasonalize the data, I need to adjust each monthly mean based on the mean for that year. If the yearly mean is greater than the monthly mean then yrmean-mmean. If the monthly mean is greater than the yearly mean, then mmean-yrmean. This should give me a new 128x1 of deasonalized data. This is where I get stuck. Any help is appreciated! Here's what I have so far:
%find yearly mean
G=findgroups(dv(:,1));
meanyr_temp=splitapply(@mean,temp,G); %yearly mean is 17x1 double, note not all years have data
%find monthly mean for each year
H=findgroups(dv(:,1),dv(:,2));
meanmyr_temp=splitapply(@mean,temp,H); %month/year mean is 128x1 double
0 Comments
Answers (1)
Star Strider
on 18 Dec 2018
Without your data, it is difficult to write specific code.
From your description, this may work:
Yrv = [ones(12,1)*2017; ones(12,1)*2018]; % Create Data
Mov = repmat((1:12)', 2,1); % Create Data
Tv = 10 + 0.1*(1:24)' + sin((1:24)'*pi/6)*15; % Create Data
Data = [Yrv Mov Tv]; % Matrix Of Years, Months, Temperatures
Times = datetime(Data(:,1), Data(:,2), ones(size(Data,1),1)); % Create ‘datetime’ Array
TData = timetable(Times, Data(:,3)); % Convert To ‘timetable’
YrMean = retime(TData, 'yearly', 'mean') % Yearly Mean
MoMean = retime(TData, 'monthly', 'mean') % Monthly Mean
DYrMean = timetable2table(YrMean); % Convert To ‘table’
DMoMean = timetable2table(MoMean); % Convert To ‘table’
Deseasonalize = abs(bsxfun(@minus, DMoMean.Var1, DYrMean.Var1')); % Absolute Value Of The Difference
The ‘Deseasonalize’ assignment takes the absolute value of the difference between the monthly and yearly means for each year. I am not exactly certain what you mean by ‘deseasonalize’, or what you want for ‘deseasonalized’ data, so this is my best guess. It should get you started.
0 Comments
See Also
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!