population variance (Equivalent of var.p command in excel in Matlab)
7 ビュー (過去 30 日間)
古いコメントを表示
I have a time series data of 5 variables ( data is attached) and I grouped them based on month and year and take variance of each month by following code:
% reading daily data
data1=csvread('ffm.csv',1,0);
% extracting data into a MATLAB Table variable
T=table();
T.year=floor(data1(:,1)/10000);
T.mm=floor((data1(:,1)-T.year*10000)/100);
T.dd=data1(:,1)-T.year*10000-T.mm*100;
T.value=data1(:,2:6);
% compute monthly variance from daily data
v=[];
v=grpstats(T,{'year','mm'},'var');
However, this code by simply 'var' command in the last line of the code, gives the sample variance, but I need to obtain the population variance . The difference between population and sample variance is explained in the below link:
https://www.automateexcel.com/stats/var-p-vs-var-s/#:~:text=The%20VAR.,a%20sample%20of%20a%20populate.
0 件のコメント
採用された回答
Star Strider
2022 年 10 月 22 日
編集済み: Star Strider
2022 年 10 月 22 日
Try something like this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1165263/ffm.csv', 'VariableNamingRule','preserve')
T1.Var1 = datetime(string(T1.Var1), 'InputFormat',"yyyyMMdd"); % Create 'daterime' Array
TT1 = table2timetable(T1); % Convert To 'timetable'
popvar = @(x) sum((x - mean(x)).^2)/numel(x); % Population Variance
TT1 = retime(TT1, 'monthly', @(x)popvar(x)) % Monthly Variances For Each VAriable
NOTE — MATLAB calculates the ‘sample variance’ referred to in that link by default, as noted in the var documentation section on More About. So, this (using ‘popvar’) will produce the correct result.
.
2 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!