Group-specific predictors in nlmefit

조회 수: 84 (최근 30일)
the cyclist
the cyclist 2012년 7월 26일
댓글: the cyclist 2024년 4월 8일
Does anyone have a simple example of estimating group-specific predictors (non-empty VFUN model parameter) for the nlmefit function?

채택된 답변

Tom Lane
Tom Lane 2012년 7월 27일
If you are happy with a toy illustration rather than a realistic example, here's one. Set up some fake data following a linear model:
subject = kron((1:6)',ones(4,1)); % 6 subjects measure at 4 times
time = kron(ones(6,1),(1:4)');
weight = [100 150 140 200 190 140]'; % weight of each subject
effect = [1 -1 0 -2 2 0]'; % a "random" effect of each subject
y = 5 + effect(subject) - time + .03*weight(subject) + randn(size(subject));
Fit a linear function of time and weight by including weight in the first input as a column. Since weight is measured only once per subject, we have to expand it to the right length.
model = @(phi,t) phi(1) + phi(2)*t(:,1) + phi(3)*t(:,2);
phi0 = [1 1 1];
[beta,PSI,stats,br] = nlmefit([time weight(subject)],y,subject,[],model,phi0,'reparam',1);
beta
br
Now move weight to the separate V input where it does not have to be expanded to have one value per observation:
model = @(phi,t,v) phi(1) + phi(2)*t + phi(3)*v;
phi0 = [1 1 1];
[beta,PSI,stats,br] = nlmefit(time,y,subject,weight,model,phi0,'reparam',1);
beta
br
  댓글 수: 3
yu zhang
yu zhang 2024년 3월 29일
Thanks. I have one more question. [beta,PSI,stats,br] = nlmefit(time,y,subject,weight,model,phi0,'reparam',1); what does the 'reparam',1 means?
mag if my Group vaules , I define the group-specific predictors group, and VFUN like this.
[group, gN,VFUN] = grp2idx(mag)
model = @(c,R,M)(c(1)+c(2)*(M-6)+c(3)*log(M/6)+(c(4)*M+c(5)).*log(sqrt(R(:,1).^2+c(6)^2))+c(7)*R(:,2));
beta0 = [3.08 6.39 -16 -0.61 1.75 10 -0.012];
[BETA,PSI,STATS,B] = nlmefit([rup,RA],lnarias,Mv,gL,model,beta0);
It runs a long time, and gives the waring information "stop calculation because the maximum number of iterations is reached"
if i use [BETA,PSI,STATS,B] = nlmefit([rup,RA],lnarias,Mv,gL,model,beta0,'reparam',1);
It seems woring well. But I don't konw why?
the cyclist
the cyclist 2024년 4월 8일
'reparam' is short-hand for specifying the name-value pair 'REParamsSelect' (which you can think of as short-hand for "random effects parameter selection"). That input is specifying which of your parameters has a random effect.
By default, all elements PHI vector include a random effect. Using
'reparam',1
specifies that only the first element should include a random effect.
See the documentation for nlmefit, for details.

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

추가 답변 (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