Group-specific predictors in nlmefit
84 ビュー (過去 30 日間)
古いコメントを表示
Does anyone have a simple example of estimating group-specific predictors (non-empty VFUN model parameter) for the nlmefit function?
0 件のコメント
採用された回答
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
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?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Nonlinear Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!