이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Plot Cook’s distance for mixed effects model
조회 수: 2 (최근 30일)
이전 댓글 표시
Adam Fitchett
2019년 7월 26일
Hello, I have a mixed effects regression model ‘lme’ and I want to plot the Cook’s distance. Apparently the code for this is ‘plotDiagnostics(lme, ‘cookd’)’ but when I enter that I get the error ‘Undefined function ‘plotDiagnostics’. Does anyone know what I am doing wrong here?
댓글 수: 23
Adam Danz
2019년 7월 26일
편집: Adam Danz
2019년 7월 26일
That command goes all the way back to r2012a and requires the Statistics and Machine Learning toolbox.
To confirm that you do not have the function/method,
which plotDiagnostics -all
It looks like you do have the toolbox since you seemed to have generated the model (lme).
Adam Fitchett
2019년 7월 26일
Thank you Adam
I thought I did have the toolbox installed, but when I entered ‘which plotDiagnostics -all’ it said it wasn’t found
Adam Fitchett
2019년 7월 26일
편집: Adam Fitchett
2019년 7월 26일
Indeed, I do have the toolbox as it is listed when I enter “ver” But plotDiagnostics is still not found And I have version 2019a, so should be there
Adam Danz
2019년 7월 26일
편집: Adam Danz
2019년 7월 26일
Physically check that you have the file that contains this method. plotDiagnostics is a function stored in the classdef LinearModel.m.
In windows, on my system, that file can be found in
'C:\Program Files\MATLAB\R2019a\toolbox\stats\classreg\@LinearModel\LinearModel.m'
Do you have that file? If you open the file, can you find the plotDiagnostics function?
Adam Fitchett
2019년 7월 26일
My version is 2019a. I have tried closing and reopening MATLAB, but that didn’t fix it. I tried restoredefaultpath, but that didn’t fix it. I don’t think anything has been deleted or renamed in the toolbox, but maybe it has happened somehow without my knowledge
Adam Fitchett
2019년 7월 26일
Yes, I have the LinearModel.m file and when I search through it plotDiagnostics does seem to be there
Adam Fitchett
2019년 7월 26일
편집: Adam Fitchett
2019년 7월 26일
Yes it’s in that exact directory. I followed through the directory you described in order to find it, and it was precisely there
Adam Danz
2019년 7월 26일
Copy the directory that stores LinearModel.m and add that path using addpath('...'). Then run the which plotDiagnostics -all again.
If that fixes it, then somehow the matlab path got messed up.
Adam Fitchett
2019년 7월 26일
Well that’s curious. I did what you said above, and MATLAB returns “Warning: Name is nonexistent or not a directory”. But I definitely entered the directory of the file.
Xuelong Fan
2021년 3월 2일
Hi!
I have the same problem. And I tried addpath ... but it still says 'plotDiagnostics' not found.
I installed both 2019b and 2020b. But that shouldn't be a problem, should it?
I wonder if anyone has the same problem.
Adam Danz
2021년 3월 2일
편집: Adam Danz
2021년 3월 2일
@Xuelong Fan what is returned by the following commands?
license('test','Statistics_toolbox')
which LinearModel
Katharina
2021년 3월 2일
I do have the same problem and would be grateful for help!
>> license('test','Statistics_toolbox')
ans =
1
>> which LinearModel
/Applications/MATLAB_R2020b.app/toolbox/stats/classreg/@LinearModel/LinearModel.m % LinearModel constructor
>>
Adam Danz
2021년 3월 2일
Please share
- the line of code you're using when calling plotDiagnostics.
- the full error message you receive after calling the function.
Xuelong Fan
2021년 3월 3일
0.
I got something similar after running the codes:
ans =
1
C:\Program Files\MATLAB\R2020b\toolbox\stats\classreg\@LinearModel\LinearModel.m % LinearModel constructor
1&2.
And the full error message is:
lme is a linear mixed-effect model.
3.
After running addpath ...,
I got a warning like this:
maybe relevant?
Adam Danz
2021년 3월 3일
Could you share the line of code you used that led to this error? Ideally, you should share the code and the inputs so we can reproduce the error or trace the stack on our end.
Katharina
2021년 3월 3일
for same lme, I got this error this time:
Undefined function 'plotDiagnostics' for input arguments of type 'LinearMixedModel'.
Xuelong Fan
2021년 3월 4일
Similar to Katharina.
It does not work on any lme.
What could be interesting to you is that:
1) when you type in the command line till the point "plotDiagnostics(", the hint of how to use this function can pop up.
But when you run it, it cannot be found:
>> Unrecognized function or variable 'plotDiagnostics'.
2) when you run addpath ... as you mentioned before, other functions such as plotResidual cannot be found neither (it can before).
I think it might have to do with conflict of function names??
Adam Danz
2021년 3월 5일
This thread keeps getting attention now and then. I wonder where users get the idea that they can use plotDiagnostics with non-LinearModel objects. If there is a demo or some other souce that is leading people to this problem, please let us know here in the comments section.
답변 (1개)
Adam Danz
2021년 3월 4일
편집: Adam Danz
2021년 3월 5일
plotDiagnostics is a public method of the LinearModel class. The function is defined in LinearModel.m and recieves a LinearModel object as input.
plotDiagnostics is not defined in other model classes such as LinearMixedModel objects. Determine the class of your model using class(mdl) to confirm if it's a LinearModel object. If not, you cannot use plotDiagnostics with the model.
If the LinearModel class has not been constructed, help('plotDiagnostics') will not find the function unless you specify the class name,
clear all
help plotDiagnostics % r2020b
plotDiagnostics not found.
Use the Help browser search field to search the documentation, or
type "help help" for help command options, such as help for methods.
help LinearModel.plotDiagnostics
plotDiagnostics Plot diagnostics of fitted model
plotDiagnostics(LM,PLOTTYPE) plots diagnostics from LinearModel LM in
a plot of type PLOTTYPE. The default value of PLOTTYPE is 'leverage'.
Valid values for PLOTTYPE are:
'contour' residual vs. leverage with overlayed Cook's contours
'cookd' Cook's distance
'covratio' delete-1 ratio of determinant of covariance
'dfbetas' scaled delete-1 coefficient estimates
'dffits' scaled delete-1 fitted values
'leverage' leverage (diagonal of Hat matrix)
's2_i' delete-1 variance estimate
H = plotDiagnostics(...) returns handles to the lines in the plot.
The PLOTTYPE argument can be followed by parameter/value pairs to
specify additional properties of the primary line in the plot. For
example, plotDiagnostics(LM,'cookd','Marker','s') uses a square
marker.
The data cursor tool in the figure window will display the X and Y
values for any data point, along with the observation name or number.
It also displays the coefficient name for 'dfbetas'.
Example:
% Plot the leverage in a fitted regression model
load carsmall
d = dataset(MPG,Weight);
d.Year = ordinal(Model_Year);
lm = fitlm(d,'MPG ~ Year + Weight + Weight^2')
plotDiagnostics(lm,'leverage')
% Look at the data for the high-leverage points, and note that
% their Weight values are near the extremes
high = find(lm.Diagnostics.Leverage>0.11)
d(high,:)
See also LinearModel, plotResiduals.
Documentation for LinearModel/plotDiagnostics
doc LinearModel.plotDiagnostics
The which function only works when the LinearModel class is constructed.
clear all
which plotDiagnostics
'plotDiagnostics' not found.
fitlm(1:5,1:5);
which plotDiagnostics
/MATLAB/toolbox/stats/classreg/@LinearModel/LinearModel.m % LinearModel method
댓글 수: 4
Adam Danz
2021년 3월 4일
You'll have to compute it directly. There may be functions on the file exchange that could help out. Matlab's documentation shows how it's computed.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)