Hello everybody,
i have values for Sodium, creatinine and many more variables for patients. I need to calculate mean median values of them. Should i use everytime mean(ds.Sodium) or is there a easier way to do that ? i ve been trying to use grpstats function i couldnt make it work. if someone would explain me i would be very happy. thank you

댓글 수: 2

Adam Danz
Adam Danz 2019년 9월 8일
What problems are you having? There are lots of examples in documentation which is the first place to go for help.
Adam Danz
Adam Danz 2019년 9월 9일
Ongun Palaoglu's answer moved here as a comment.
True,
DSSTATS = grpstats(DS,GROUPVARS,WHICHSTATS) .
stat1 = grpstats(ds, {'Sodyum' , 'AST'} , {'mean' , 'median'}) i did this, for my dataset ds, {variables} , {what i want to calculate'means'}

댓글을 달려면 로그인하십시오.

 채택된 답변

Adam Danz
Adam Danz 2019년 9월 9일
편집: Adam Danz 2019년 9월 9일

1 개 추천

Have a look at the list of statistics that are accepted as character vectors. Note that 'median' is not one of the options.
Instead, you'll need to use a function handle to list 'median' as a stat.
stat1 = grpstats(ds, {'Sodyum', 'AST'} , {'mean', @median});
That fixes any syntax issues. If problesm persist, please describe the problem in detail and share the result of the following line (assuming ds is a table which appears to be the case).
head(ds) % if ds is a table

댓글 수: 6

Adam Danz
Adam Danz 2019년 9월 9일
편집: Adam Danz 2019년 9월 9일
@ Ongun Palaoglu , please use comment sections to continue discussion unless you're posting an answer. It makes it much easier to follow the threads.
Ongun Palaoglu's answer moved here as a comment, below
ds is dataset
Error using dsgrpstats (line 262)
Data variables must be numeric or logical.
Error in grpstats (line 136)
[varargout{1:nargout}] = dsgrpstats(x,group,whichstats,varargin{:});
these are the errors i have.
Adam Danz
Adam Danz 2019년 9월 9일
편집: Adam Danz 2019년 9월 9일
Datasets might be removed in future releases according to the documentation.
You may want to re-write your code so that your data are stored in tables instead of datasets. You could also convert your dataset to a table using dataset2table().
Conserning this error, "Data variables must be numeric or logical.", I'd like to see what you've got stored in your dataset. This line below will show the first 5 lines (you could add more if needed), assuming your dataset is named "ds". Could you show us this sample?
ds(1:5,:)
Or, better yet, convert your dataset to a table and show us,
head(dsTable)
Adam Danz
Adam Danz 2019년 9월 9일
편집: Adam Danz 2019년 9월 11일
@ Ongun Palaoglu, please use the comments section for discussion rather than posting comments as answer.
I looked at your data and it will be very easy to follow the advice I provided above.
Frist convert your dataset to a table.
T = dataset2table(ds1);
Because your table contains columns that are non-numeric, you need to specify which columns should be used for the statistics. To do that, use the DataVars property in grpstats(). I listed "AST" and "ALT" but you can replace that with whatever numeric columns you'd like to use for the statistics.
stat1 = grpstats(t, {'Sodyum', 'AST'} , {'mean', @median},'DataVars',{'AST','ALT'})
% --> here ^^^^^^^^^^^^^^^^^^^^^^
About recommending a book, I actually don't recommend a book. Whenever you use a new function, look up that function in the documentation and read about it's inputs, outputs, and what the function does. Also look at it's optional parameters. This is the best way to learn how to use functions.
Ongun Palaoglu
Ongun Palaoglu 2019년 9월 11일
편집: Ongun Palaoglu 2019년 9월 11일
I have one more question. When I say 'mean' there should be one value and also for 'median', but there are a lot of values in here. Why is that.
Thank you very much for your time and help. I really appreciate.
Ongun, please spend some time reading through the documentation. I provided a link to the grpstats() function. Often times it help looking at the examples too. Look for an example in the grpstats page that matches your inputs.
In this line
stat1 = grpstats(T, {'Sodyum', 'AST'} , {'mean', @median},'DataVars',{'ALT'})
you are computing the mean and median ALT for each "Sodym" and "AST" group -combination. Those group combinations are the row names in the table output.
Ongun Palaoglu
Ongun Palaoglu 2019년 9월 12일
okay thank you=)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Repeated Measures and MANOVA에 대해 자세히 알아보기

질문:

2019년 9월 8일

댓글:

2019년 9월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by