How can I troubleshoot for an "Convergence criterion not satisfied (line 490)" warning when using mvregress.
조회 수: 3 (최근 30일)
이전 댓글 표시
I am attempting to analyze the attached data set using Longitudinal data analysis.
The Fields are as follows:
Column 1: Subject ID (16 in Total)
Column 2: Type of Treatment
Column 4: Result 1 of Treatment
Column 5: Result 2 of Treatment
Column 6: Gender of subject (0==Female, 1==Male)
So far I have set it up so that MATLAB creates a line of best fit for the data points associated for each individual. In this case the X value are the different types of treatments and the y value is the multiple of Result 1 and 2. Included is a the plot of all 16 lines of best fit.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/167686/image.jpeg)
I now want to use the mvregress function to generate two lines of regression based on the Individual fitted lines, one regression line will be for females (0 in the sixth column of the data set), and the other regression for males (1 in the sixth column). Here I've pretty much followed the steps outlined in the example I provided, specifically defining Design Matrices and creating a cell array to represent them. However, when I try to implement the mvregress function I get this warning:
"Warning: Maximum iterations completed. Convergence criterion not satisfied. > In mvregress (line 490):"
Additionally the estimated coefficients and standard errors that are produced from implementing this function are clearly wrong (shown below).
ans =
1.0e+03 *
0.0000 0.0000
-0.0000 0.0000
1.0000 0.0000
0.0000 0.0000
0.0000 0.0000
-0.0000 0.0000
Note that I've tried increasing the maximum iterations to 50000 from the base of 10 and it did not help.
Here is my code please let me know where I am going wrong. Thanks in advanced!
if true
%%curvefit.m Curve fitting demonstration code
%%Load univeriable Data Set
mat=xlsread('longitudinal Data set');
%set loop variables
Subjectarray = mat(:,1) % subject array
SubjectList = unique(Subjectarray) % make list of subject
SubjectCount = length(SubjectList) % count subject
Trialarray=mat(:,2)
TrialList = unique(Trialarray) % make list of subject
TrialCount = length(TrialList)
XT = cell(SubjectCount,1);
k = 1;
%set plotting variables
x=(1:3)';
ytotal=x;
%%create loop for each Subject
for j=1:SubjectCount;
XTA = ones(TrialCount,6);
% set subject dependent x and y values
for i=1:length(Subjectarray);
if mat(i,1)== j;
dyp(k)= mat(i,4);
dyd(k)= mat(i,5);
dx(k) = mat(i,2);% x values are diffrent treatments
dy(k) = dyd(k).*dyp(k);% y values are Integral of Relief
k=k+1;
end
end
fitfn = @( x, a, b) a*(x)+ b;
% make the error function (sum-of-squares)
% (see steps1.m for a step-by-step construction of this function)
errfn = @( p ) sum( ( fitfn(dx,p(1),p(2)) - dy ).^2 );
% minimize the error function
phat = fminsearch(errfn,[ 0 0 ]);
% report results of fit
fprintf(1,'fit1: y = (%.2f)x + (%.2f) \n',phat(1),phat(2));
y= phat(1)*x + phat(2);
%store line function of each line of each regression
for i=1:length(Subjectarray);
if mat(i,1)== j;
ytotal(:,j)= [y]
if mat(i,6)==0
XTA(:,2)=0
end
XTA(:,3)=y/1000
XTA(:,4)=(y.^2)/1000
XTA(:,5)= ((XTA(:,2)).*(XTA(:,3)))/1000
XTA(:,6)=((XTA(:,2)).*(XTA(:,4)))/1000
XT(j)={XTA}
end
end
%reset loop variables
k = 1;
dx=0;
dy=0;
dyp=0;
dyd=0;
end
%%Create aveage line of regression
[b,sig,E,V,loglikF] = mvregress(XT,ytotal');
[b sqrt(diag(V))]
end
댓글 수: 0
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!