B must have same rows of A
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi guys,
I constantly receive these errors:
Error using lscov (line 105)
B must have the same number of rows as A.
Error in bisquare (line 10)
beta(:,1)=lscov(X,y);
Error in Portfolioweights_it_bs (line 13)
abeta = bisquare(X, r(:,t+1),k);
Anyone a clue how to resolve?
Thanks!
This is the code for the bisquare estimator:
function BS = bisquare(X, y, k)
%X is regression matrix
%y are values of dependent variables
N_max = 20;
% maximum number of iterations for biqsquare optimization
[M,N]=size(X);
beta = zeros(N,N_max);
beta(:,1)=lscov(X,y);
e = y-X*beta(:,1);
sigmahat = mad(e)/0.6745;
k=sigmahat*4.685;
The code I use to generate the data (partly) before that is this one:
function Weights = Portfolioweights_it_bs(r, z, gamma, r_f, constr_ON, it_ON)
N_max = 10;
k = 1;
[M,T] = size(r);
x = zeros(M,T-1);
t=T-1;
X = [ones(M,1);z(t,1) ;z(t,1).^2];
abeta = bisquare(X, r(:,t+1),k);
ahat = X*abeta;
bbeta = bisquare(X, r(:,t+1).^2,k);
bhat = X*bbeta;
x(:,t) = r_f/gamma * ahat./bhat;
if it_ON==1
disp('4th order Taylor iteration used')
x_it = zeros(M,N_max);
i=1;
x_it(:,1) = x(:,t);
cbeta = bisquare(X, (x_it(:,i).*r(:,t+1)).^2*r(:,t+1),k);
chat = X*cbeta;
dbeta = bisquare(X, (x_it(:,i).*r(:,t+1)).^3*r(:,t+1),k);
dhat = X*dbeta;
x_it(:,i+1) = x(:,t)- b(hat).^(-1).*(0.5*(-gamma-1)/r_f*chat+1/6*(-gamma-1)/r_f^2*(-gamma-2)*dhat);
while ( max(abs(x_it(:,i+1)-x_it(:,i)))>0.01 && i<N_max)
i=i+1
cbeta = bisquare(X, (x_it(:,i).r(:,t+1)).^2.*r(:,t+1),k);
chat = X*cbeta;
dbeta = bisquare(X, (x_it(:,i).r(:,t+1)).^3.*r(:,t+1),k);
dhat = X*dbeta;
x_it(:,i+1) = x(:,t)- b(hat).^(-1).*(0.5*(-gamma-1)/r_f*chat+1/6*(-gamma-1)/r_f^2*(-gamma-2)*dhat);
end
if i==N_max
disp('Maximum number of iteration steps used')
end
x(:,t)=x_it(:,i+1);
else
disp('2nd order Taylor iteration used')
end
if constr_ON==1
x(:,t)=max(0,min(x(:,t),1));
disp('Constraints on x')
end
j=1;
beta(:,j+1)= inv(X'*spdiags(W_BS(e,k),0,M,M)*X)*X'*spdiags(W_BS(e,k),0,M,M)*y;
while (max(abs(beta(:,j+1)-beta(:,j)))>0.001 && j<N_max)
e = y-X*beta(:,j+1);
sigmahat = mad(e)/0.6745;
k=sigmahat*4.685;
j=j+1;
beta(:,j+1)= inv(X'*spdiags(W_BS(e,k),0,M,M)*X)*X'*spdiags(W_BS(e,k),0,M,M)*y;
end
if j==N_max
disp('Bisquare uses maximal number of iterations')
end
BS = beta(:,j+1);
So I am clearly missing something but can't figure out what...
1 comentario
the cyclist
el 2 de Jun. de 2013
Kevin, I moved your code up from an "answer" into your question where it is better placed.
Respuestas (4)
the cyclist
el 2 de Jun. de 2013
Editada: the cyclist
el 2 de Jun. de 2013
It would be helpful if you showed us some of your actual code. However, it looks like you call the function lscov in line 10 of your function bisquare, and when you do that, the variable X has a different number of rows than your variable y. You might want to take a look at the documentation for lscov:
doc lscov
Added after code was included:
Is it possible for you to edit your code so that it is a completely self-contained example that can be executed and show the error?
Have you tried using debugging mode to breakpoint into the code and look at the sizes of the inputs to lscov?
0 comentarios
Ver también
Categorías
Más información sobre Wireless Communications en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!