function [betafmat,betarmat,Emat,sig2mat,betarimat]...
    =gs_HNRM_nocovs(y,Ximat,yimat,k,kf,kr,n,J,obs,r1,r2,muf0,Vf0,...
    mur0,Vr0,betardraw,phi0,gam0,Edraw,eta0,tau0,sig2draw);

R = r1+r2;
betafmat=zeros(kf,r2); 
betarmat=zeros(kr,r2);
betarimat=zeros(kr*n,1);
Emat=zeros(kr,r2);
sig2mat=zeros(1,r2);


thoucount=1000;
% start main loop
i=1;
for i=1:R
        
   %%%%%%%%%%%%%%%%%%%%%%%%%%%
   % draw fixed coefficients 
   %%%%%%%%%%%%%%%%%%%%%%%%%%%
   int1=zeros(kf,kf);
   int2=zeros(kf,1);
   for j=1:n; 
        yi=yimat{j};
        Xi=Ximat{j};
        Xif=Xi(:,1:kf);
        Xir=Xi(:,kf+1:end);
        Vi=sig2draw*eye(J)+Xir*(Edraw)*Xir';
        int1=int1+(Xif'*inv(Vi)*Xif);
        int2=int2+(Xif'*inv(Vi)*(yi-Xir*betardraw));
   end
    V1=inv(inv(Vf0)+int1);
    mu1=V1*(inv(Vf0)*muf0+int2);
    betafdraw=mvnrnd(mu1,V1)';
   if i>r1
       betafmat(:,i-r1)=betafdraw; 
   end


   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   % draw betar (uncond. on betari); 
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   int1=zeros(kr,kr);
   int2=zeros(kr,1);
   for j=1:n;
        yi=yimat{j};
        Xi=Ximat{j};
        Xif=Xi(:,1:kf);
        Xir=Xi(:,kf+1:end);
        Vi=sig2draw*eye(J)+Xir*(Edraw)*Xir';
        int1=int1+(Xir'*inv(Vi)*Xir);
        int2=int2+(Xir'*inv(Vi)*(yi-Xif*betafdraw));
    end
    V1=inv(inv(Vr0)+int1);
    mu1=V1*(inv(Vr0)*mur0+int2);
    betardraw=mvnrnd(mu1,V1)';
   if i>r1
       betarmat(:,i-r1)=betardraw; 
   end
   
   %%%%%%%%%%%%%%%
   % draw betari's
   %%%%%%%%%%%%%%%
   betaridraw=[];
   for j=1:n;
        yi=yimat{j};
        Xi=Ximat{j};
        Xif=Xi(:,1:kf);
        Xir=Xi(:,kf+1:end);
        V1=inv(inv(Edraw)+(1/sig2draw)*Xir'*Xir);
        mu1=V1*(inv(Edraw)*betardraw+(1/sig2draw)*Xir'*(yi-Xif*betafdraw));
        draw=mvnrnd(mu1,V1)';
        betaridraw=[betaridraw draw];%will be kr by n
        % capture this for draws of sig2 below and Chib method
   end
  if i>r1
       betarimat(:,i-r1)=reshape(betaridraw,kr*n,1);% just needed for Chib routine
  end
      
    %%%%%%%%%%%%%%%%%%
    % draw sig2
    %%%%%%%%%%%%%%%%%%
    int=reshape(betaridraw',n*kr,1)';
    int=repmat(int,J,1);
    int=reshape(int,n*J,kr);
    
    betamat=[repmat(betafdraw',obs,1) int];
    int=sum(cell2mat(Ximat).*betamat,2);% Xf*bf + Xr*bri, stacked for all i
    
    eta1=(obs+2*eta0)/2;
    tau1=(1/2)*((y-int)'*(y-int)+2*tau0);
    sig2draw=1/gamrnd(eta1,1/tau1); 
    
    if i>r1
       sig2mat(:,i-r1)=sig2draw;
    end
    
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % draw E
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

   int=betaridraw'-repmat(betardraw',n,1);%n by kr
   phi1=(n+2*phi0)/2;
   for ii=1:kr
       gam1=(1/2)*(int(:,ii)'*int(:,ii)+2*gam0);
       Edraw(ii,ii)=1/gamrnd(phi1,1/gam1);
   end
   
   if i>r1
       Emat(:,i-r1)= diag(Edraw);
   end

    
    
        
    if i== thoucount
        i
        thoucount=thoucount+1000;
    end
        
    
 end


