Use of sigma in non-linear utility estimation

1 view (last 30 days)
I am estimating a non-linear utility using the following function, adapted from another researchers code:
function f = mufunc(X, sigma)
%This function computes the non-linear part of the utility %This is based on the code written by Aviv Nevo, 1998
global nsm price1
[n, K] = size(X);
inc = lognrnd(1.656, 0.30, 2301,nsm);
v = normrnd(0,1,2301,K*nsm); % multivariate normal draws, one for each characteristic
mu=zeros(n,nsm);
for i = 1:nsm
v_i = v(:,i:nsm:K*nsm);
inc_i = inc(:,i);
mu(:,i) = (-sigma(1).*price1./inc_i+(X.*v_i*(sigma(2:end))'));
end
f = mu;
The vector inc_i = 2301 x 1, the matrix v_i = 2301 x 4, X = 2301 x 4. I keep on getting that the dimensionality of sigma is such that I cannot perform .*, because of dimensionality issues. But I cannot seem to find exactly what sigma(1) does, and what its dimensions ought to be. Can someone perhaps explain to me what exactly it is this sigma(1) does?
The error message displayed is the following:
Error using .* Matrix dimensions must agree.
Error in mufunc (line 14) mu(:,i) = (-Sigma(:,1).*price1./inc_i+(X.*v_i*(Sigma(2:end))'));
  1 Comment
Brendan Hamm
Brendan Hamm on 2 Mar 2015
Edited: Brendan Hamm on 2 Mar 2015
The error you are giving to us has different code than the code you are showing us. Please fix this if you want clarification.
What are the sizes of all of the variables on line 14?
To answer what I can, sigma(1) is giving you the first element of sigma.
About dimension errors: In order to use multiplication A*B the inner dimensions must agree. That is if A is m-by-2, B must be 2-by-n. To use the element-wise multiplication A.*B the matrices must be of the same size. That is if A is m-by-n then B must be m-by-n.
This can be violated if A or B is a 1-by-1 matrix (scalar element) in which case that scalar value is multiplied against each element of the matrix.

Sign in to comment.

Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!