I am trying to minimise a likelihood function and estimate the parameter value of $\lambda$ by fitting to the following data. $t$ is the time and $N(t)$ si the population measured at those specific time points $t=[0;1;2;3;4;5;6];$
$N(t)=[350000,210000,80000,20000,100,100,100]; $
The probability density function is $f_N(N(t);\lambda t)=\lambda t e^{-\lambda t N(t)}$.
The Cumulative distribution function is $1-e^{-\lambda tN(t)}$
This is the Matlab code I wrote:
N=[350000,200000,80000,20000,100,100,100];
t=[0 1 2 3 4 5 6];
cutOff=100;
c=(N<=cutOff);%censored data
start=1/mean(N);
pdf_lambda=@(N,lambda)lambda.*t.*exp(-lambda.*t.*N);
cdf_lambda=@(N,lambda)1-exp(-lambda.*t.*N);
[paramEsts,paramCIs] = mle(N, 'censoring',c,'pdf',pdf_lambda, 'cdf',cdf_lambda, ...
'start',start, 'lower',0);
I get an error as Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is
1-by-7.
This is the first time I am using MLE to fit for data and estimate a parameter. So I don't quite understand what I ma dong wrong here. Can someone please let me know how to fix this issue.
I think your problem is due to the definition of the PDF you care about. Just basically check your function handle "pdf_lambda", one could find that the value of this function is actually a vector. However, for a PDF (or CDF) function used in "mle" must be a scalar value function.
This is interesting because the PDF function at different time $t$ is actually different and depends on the parameter $t$. Nevertheless, the PDF function that we estimate the parameter for should be the same in MLE scheme. It may suggest that it is not appropriate to use the data N to estimate.
My suggestion is to multiply the PDF function at different time $t$ together so that the PDF function can be treated as the scalar function of $\lambda$.
I haven't make it work through MATLAB yet, because the data you provide. Since $t=0$, the corresponding PDF function is $f_N(N(1);0)=0$, and the first entry of N should be considered if it is appropriate.
I here suppose that the first entry of $t$ and $N$ are not taken into consideration. The MATLAB code is as follow:
Note: Please do not use $t$ and $N$ in the function handle, because these parameters will not be transferred into the function "mle".