How to fit multiple distributions of the same type to the sample data based on grouping variables? Brief the steps

9 visualizaciones (últimos 30 días)
How to fit multiple distributions of the same type to the sample data based on grouping variables? Brief the steps
  1 comentario
dpb
dpb el 16 de Ag. de 2023
  1. <Start here...>
  2. Figure out how to do what you want with all the data without grouping
  3. Build either an m-file or if simple enough an anonymous function to do (2)
  4. Use varfun or findgroups and splitapply with (3)
  5. Admire handiwork...

Iniciar sesión para comentar.

Respuestas (1)

Shivansh
Shivansh el 5 de En. de 2024
Hi Payel!
I understand that you are trying to fit multiple distributions of the same type to the sample data based on the grouping variables. I am assuming that the data is in a “table” format that separates the sample data from the grouping variables.
You can follow the below steps:
  1. Use the “findgroups” function to create a vector of group indices from the grouping variable.
  2. Create a function that takes a subset of the sample data and fits the desired distribution to it. The function should return the parameters or the distribution object.
  3. Apply the function to each subset of the data corresponding to each group using “splitapply”.
  4. Save the fitted parameters for and use functions like “plot” for analysis.
You can refer to the example code below to get a better idea of the above approach:
% Assuming 'dataTable' is a table with 'Samples' and 'Group' columns
groups = findgroups(dataTable.Group);
% Define a function or use an existing function that fits a distribution to the data
fitDistFunc = @(data) fitdist(data, 'Normal');
% Use splitapply to fit the distribution to each subset of data
fittedDistributions = splitapply(fitDistFunc, dataTable.Samples, groups);
In this code, store the data in the “dataTable” variable. Thesplitapply” automatically splits the “Samples” column of “dataTable” into subsets based on the unique values in groups created by “findgroups”. The function “fitDistFunc” is then applied to each subset, and the results are aggregated into the “fittedDistributions” cell array.
You can refer to the below links for more information:
  1. findgroups: https://in.mathworks.com/help/matlab/ref/findgroups.html.
  2. splitapply: https://in.mathworks.com/help/matlab/ref/splitapply.html.
Hope it helps!

Productos


Versión

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by