how to compute a linear mixed effect using nlmefit?
Afficher commentaires plus anciens
Hi,
I'd like to fit a simple linear mixed model Y=XB+Zb+e with X the design matrix of the fixed effect (always the same size but not always the same values) and Z described subjects (which I specify as random)
here is the code I used
% generate data
for subject=1:10
x(:,subject) = [1:10]+randi(30,1);
coef(subject) = (3+rand(1));
y(:,subject) = coef(subject)*x(:,subject)+3*randn(10,1)- 5*mean(x(:,subject));
end
% create X, Y, subject for nlmefit
Y = y(:);
X = [x(:) ones(100,1)];
subject = sum(kron(diag(1:10),ones(10,1)),2);
% fit the data using 'model'
model = @(Betas,X) (X*Betas)
[Betas,PSI,stats] = nlmefit(X,Y,subject,[],model,[1 0])
The error is: Error using * Inner matrix dimensions must agree. Error in @(Betas,X)(X*Betas)
in a fixed effect Betas=pinv(X)Y and the fitted data = X*Betas, and that why i defined model this way, assuming that for each subject, parameters are fitted using 'model' ?? any idea what I am doing wrong ?
Thanks Cyril
2 commentaires
Walter Roberson
le 13 Mar 2013
Do you in fact want algebraic matrix multiplication? Or do you want element-by-element multiplication which is the .* operator ?
Cyril Pernet
le 14 Mar 2013
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Nonlinear Regression dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!