I am in a student research position and am new to R. I have asked a question similar (posted here:MLE Issues). I have resolved the initial problem but i have encountered more problems with this function.
I am still using this function for trying to estimate theta[i],
where each of the other variables is currently known.
Below is my code:
maxParam < function(theta) {
logl < sum(for (i in 1:length(doses)) {
sum(
for (j in 1:LITTERS.M) {
sum(
for (k in 0:(litterResponses[i,j]1)) {
sum(log10(probabilityResponses[i] + k * theta[i]))
}
+
for (k in 0:(litterSizes[i,j]litterResponses[i,j]1)) {
sum(log10(1  probabilityResponses[i] + k * theta[i]))
}

for (k in 0:(litterSizes[i,j]  1)) {
sum(log10(1 + k * theta[i]))
}
)
}
)
})
return (logl)
}
mle.fit < mle(maxParam, start=list(theta=c(1,1,1,1,1,1)))
print(mle.fit)
Error: argument "theta" is missing, with no default
The function mle
does not accept a vector of initial starting values. Each parameter to be found by optimisation needs to be passed as a scalar. It is sufficient to change the declaration of your function to:
maxParam < function(theta_1 = 1, theta_2 = 1, etc) {
theta < unlist(as.list(environment()))
... # rest of function follows
}
where etc
means replace this with theta_3 = 1
, theta_4 = 1
as necessary. The function mle
can then be called with:
mle.fit < mle(maxParam)