# [R] optim function with meta parameters

Alberto Casetta alberto.casetta at satt.biz
Fri Dec 17 16:07:02 CET 2010

```Hi.
I have a dataset with 4 columns. In the first and second column I have
the same qualitative variable referred to different teams of people.
There are 10 teams in total and they compete against each other to
perform a certain task whose result is stored in the third column for
the team recorded in the first column, and in the fourth column for the
team in the second column.
For example, the first row of the dataset is:
team1   team2      2     3
that means that team1 performed the task competing against team 2 and
got 2 points while team 2 got 3 points. Every working team competes
against all other 9. It's exactly like a soccer league.

I have 190 observations in total and I need to estimate through a MLE
the parameters of a poisson distribution that drive the results.

Assuming the independency of the results, I wrote the following code
calculating the log-likelihood of the double poisson derived:

est<-c()
poisson.lik<-function(theta,x){
lambda<-theta[1]
mu<-theta[2]
n<-length(data[,1])
logl<-sum(x[,1])*log(lambda)-n*lambda+sum(x[,2])*log(mu)-n*mu
return(-logl)
}
for(i in 1:10){
data<-data.frame(subset(sa0910\$FTHG,sa0910\$Team1==levels(sa0910\$Team1)[i]),subset(sa0910\$FTAG,sa0910\$Team2==levels(sa0910\$Team2)[i]))

est[i]<-optim(c(1,1),p.lik,x=data,method="BFGS",hessian=T)
}

Now I should be able to do the task defining
lambda=alfa(i)*beta(j)*gamma and mu=alfa(j)*beta(i) where i indicates
team1 and j team2, while gamma is some sort of "home" advantage.
I have troubles to estimate alfa, beta and gamma.
Anyone can help?
Thank you so much!
Cordiali saluti / Best regards
Alberto Casetta

--
SATT S.r.l.