population variance (Equivalent of var.p command in excel in Matlab)
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
neda fathi
il 22 Ott 2022
Commentato: Star Strider
il 22 Ott 2022
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 Commenti
Risposta accettata
Star Strider
il 22 Ott 2022
Modificato: Star Strider
il 22 Ott 2022
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!