[R] Optim function with meta parameters

albechan alberto.casetta at satt.biz
Thu Dec 16 21:59:59 CET 2010


Hi guys.
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.

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

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

sa0910<-read.csv("c:/csv/sa0910.csv",header=T,sep=",")
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!
-- 
View this message in context: http://r.789695.n4.nabble.com/Optim-function-with-meta-parameters-tp3091633p3091633.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list