Splitapply array to fit distributions
显示 更早的评论
I have an Mx1 vector and an Mx1 column of categorical variables. Is there a way to splitapply so that I can get a distribution for each data in a column according to their group? I want to do this as compactly as possible because in reality I have an MxN array and I will iterate column-wise such that I get a probability distribution for each cateogries values at each column. Like the code below:
%%Generate some data
X1 = 10 + 5 * randn(200, 1);
X2 = 20 + 8 * randn(250 ,1);
cat1=repmat("a",200,1);
cat2=repmat("b",250,1);
X = [X1; X2];
cats=[cat1:cat2]
%%Fit a distribution using a kernel smoother
myFit1 = fitdist(X1, 'kernel')
myFit2 = fitdist(X2, 'kernel')
I would like to make sure each of the fits are the same as when I do something like:
newfit=splitapply(@fitdist,X,G)
but I get the error that fitdist doesn't have enough input arguments. I'm new to anonymous functions, but I suspect I need to somehow pass 'kernel' to fitdist in splitapply. Can anyone help?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!