function logLike=mcmcLikelihood(modelOut,data,valid)
  
  [row,col]=size(data);
  nValidTotal=zeros(row,1);
  logLike=0;		
  
  for i=1:row		%%% Loop through the rows
  
  	index=find(valid(i,:)==1);
  	nValid=length(index);
  	nValidTotal(i)=nValid;  
  	if nValid>1 
    	sq = sum( (modelOut(i,index) - data(i,index)).^2 );
    	sigma = sqrt(sq/nValid);
    
    	logLike= logLike+sq/(2*sigma^2);
    	logLike= logLike+nValid*log(sigma);
    	logLike= logLike+nValid*sqrt(2*pi);
  	end  %%% nValid >1
  	
  end
  	
  	if cumsum(nValidTotal)==0
  		logLike=1e31;		%%% Set this to a really large number if we don't have any data to calculated the likelihood
  	end
    
    
%;The true log likelihood function (constants removed):
%;  loglike = (nvalid*alog(sigma))  +  (sq/(2*(sigma^2))) 
%;If you do that math and propagate the constants in, you get 
   

%;comparison is as follows
%;sq= sum ((model-data)^2) 
%;n = nvalid

%;sigma = sqrt(sumsq/n)
%;loglike += n * alog(sigma)
%;loglike += sq / (2 * sigma^2)


%%% Need a function handle to a model


%%%%%%%%%%%%%%