nlmefit error - What does it mean, and how do I fix it?

2 views (last 30 days)
Trying to get to grips with the use of nlmefit
To do this I have written a script that generates a random dataset to fit a real-world equation perfectly +/- a given percentage to represent natural error. When I run the program I get the following error. Essentially what I'm asking is what does it mean, and how do I fix it? I want to be able to use nlmefit, but I don't really understand what the problem here is beyond the fact that some of the outputs are apparently coming out as Inf/NaN.
Warning: The Jacobian at the solution is ill-conditioned in the
Levenberg-Marquardt algorithm. Some fixed effects parameters
may not be estimated well (they are not identifiable).
> In nlmefit>LMfit at 1767
In nlmefit at 413
In Generate at 104
Warning: Principal matrix logarithm is not defined for A with
nonpositive real eigenvalues. A non-principal matrix
logarithm is returned.
> In funm at 168
In logm at 27
In nlmefit>Delta2theta at 1600
In nlmefit at 446
In Generate at 104
Warning: Matrix is singular, close to singular or badly scaled.
Results may be inaccurate. RCOND = NaN.
> In expm>PadeApproximantOfDegree at 123
In expm at 39
In nlmefit>theta2Delta at 1627
In nlmefit at 463
In Generate at 104
??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
Error in ==> nlmefit>GNfitPNLS at 1172
[Q,R]=qr([Zw(grp==i,:);Delta]);
Error in ==> nlmefit at 551
[BetaNew,bNew,stop] = GNfitPNLS(Delta,Y,Beta,b,PNLSOpt,grp,M,N,r,q);
Error in ==> Generate at 104
[beta1,PSI1,stats1] = nlmefit(X(:),Intensity(:),Group(:),V,Model,Beta0)
%%Clear all and load in Data
C;
hold off
cla
load Raw_Data.mat
Groups = 7; % Max 7 % Use these controls to limit data pool for cell 1 - 7
Cols = 14; % Max 14 % and data cols 1 - 14
Percentage = 10; %Percentage Variation for model testing, 0 = perfect set
%%Create Observation Matrix, Assign to Groups and Prep Y for Responses
X = rot90(Raw_Data.Cell1(1:Cols,1));
X = repmat(X,Groups,1);
V2 = zeros(Groups,X(1,size(X,2)));
%%Load Data into temp matrix Y2 prior to sorting into Y
temp = struct2cell(Raw_Data);
for i = 1:numel(temp)-(numel(temp)-Groups)
V2(i,temp{i,1}(:,1)) = temp{i,1}(:,3);
end
clear i temp Raw_Data
V = zeros(Groups,size(X,2));
for i = 1:size(X,2)
V(:,i) = V2(:,X(1,i));
end
clear i V2
Average = zeros(Groups,1);
for i = 1:Groups
Average(i,1) = mean(V(i,:));
end
V = repmat(Average,1,size(X,2));
clear i Average Cols Groups
%%Define Fixed Effects
Nt=330000; %QD Intensity threshold ie. plateau
sed=0.2931; %Sedimentation rate
scale=1.4e-4; %Scaling parameter
Beta0 = [Nt sed scale];
clear Nt sed scale
%%Generate datapoints with random +/- % variation
Mid = V*Beta0(1,2)*Beta0(1,3);
Intensity = Beta0(1,1)*(1-exp((-Mid).*X));
RandN = rand(size(Intensity))*(Percentage/100);
RandT = rand(size(Intensity));
for i = 1:size(X,1)
for j = 1:size(X,2)
if RandT(i,j) <= 0.5
Intensity(i,j) = Intensity(i,j)-(RandN(i,j)*Intensity(i,j));
else
Intensity(i,j) = Intensity(i,j)+(RandN(i,j)*Intensity(i,j));
end
end
end
clear i j RandN RandT Percentage
%%Create Model Function
Model = @(Beta0,Mid,X) Beta0(1,1)*(1-exp((-Mid).*X(:)));
%%Create Group
Group = repmat([1; 2; 3; 4; 5; 6; 7;],1,size(X,2));
%%Run Mixed Effect Model
[beta1,PSI1,stats1] = nlmefit(X(:),Intensity(:),Group(:),V,Model,Beta0)

Answers (0)

Community Treasure Hunt

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

Start Hunting!