Filter löschen
Filter löschen

Error in nlmefit function vectorizeSinglePhiGroupX

5 Ansichten (letzte 30 Tage)
Erin MacMillan
Erin MacMillan am 5 Jul. 2013
Hi, I am trying to use nlmefit to do a linear random effects model of some data using the following command:
beta = nlmefit(a,b,grp,[],@(PHI,X)(X*PHI),[1 0]);
where
a=[0 1 2 0 1 2 0 1 0 1]'; b=[6.4512 5.9866 4.8052 7.0858 6.2563 5.5702 7.0976 7.7617 5.8512 7.1175]'; grp=['ABC' 'ABC' 'ABC' 'ADW' 'ADW' 'ADW' 'AEC' 'AEC' 'AEL' 'AEL'];
a,b, and grp have been shortened for brevity, they are actually 118x1 vectors.
I get the following error that I do not understand:
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in nlmefit>getFcns/vectorizeSinglePhiGroupX (line 1367)
fval(k) = model(phi(i,:),X(k,:),V(i,:));
Error in nlmefit>getFcns/computeFAllAndCount (line 1450)
f = modelVectorizedAllGroups(phi, X, VVectorized);
Error in nlmefit>@(Beta,b)computeFAllAndCount(phiAllGroupsFcn(Beta,b)) (line 1459)
computeFAllGroupsFcn = @(Beta,b) computeFAllAndCount(phiAllGroupsFcn(Beta,b));
Error in nlmefit>@(Beta)computeFAllGroupsFcn(Beta,bDummy) (line 478)
model = @(Beta) computeFAllGroupsFcn(Beta, bDummy);
Error in nlmefit>LMfit (line 1752)
yfit = model(beta);
Error in nlmefit (line 481)
Beta_hat = LMfit(Y,Beta_hat,LMfitOptions,model,jacobian);
Thanks in advance for any clues!
Erin

Akzeptierte Antwort

the cyclist
the cyclist am 6 Jul. 2013
The proximate cause of your error is that your function specification
@(PHI,X)(X*PHI)
has only one parameter, PHI, but you have specified a vector with two initial values, [1 0].
The following syntax will execute
beta = nlmefit(a,b,grp,[],@(PHI,X)(X*PHI),[1]);
although I don't know if that is really the function you are trying to solve.
  1 Kommentar
Erin MacMillan
Erin MacMillan am 8 Jul. 2013
Thank you so much! You are right that the syntax fixed the error but was not actually the function I was trying to solve. If I want my model to be b = Xa + c, where c is some constant, then should the function be
@(PHI,X)(X*PHI(:,1)+PHI(:,2)
The nlmefit function executed without error with this model but I'm not totally sure that this is the correct model. Thanks for your help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by