Error in nlmefit function vectorizeSinglePhiGroupX

조회 수: 3 (최근 30일)
Erin MacMillan
Erin MacMillan 2013년 7월 5일
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

채택된 답변

the cyclist
the cyclist 2013년 7월 6일
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
Erin MacMillan
Erin MacMillan 2013년 7월 8일
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!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Nonlinear Regression에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by