I am modelling the average claim amount (claim amount/number of claims), so i used a gamma glm with weights=number of claims, as:
> model<-glm(claimamount/numclaims ~ 1 + veh_age + zone + insured_age, > family=Gamma(link = "log"), weights = numclaims)
After this i want to find the log likelihood at each observation, but glm only return the sum, for instances:
> logLik(model) >'log Lik.' -70665.26
How can i get the loglikelihood for each observation?
I tried to do:
> x<-claimamount/numclaims > m<-model.matrix(model) # covariates > mu<-as.vector(exp(m%*%coef(model))) #mean > delta<-summary(model)$dispersion # dispersion parameter > ll<-log(dgamma(x,1/delta,1/(delta*mu)))
But when i sum all the loglikelihoods(to check if it is ok), i don't get the same value as in
My question is: what am i doing wrong? is it because i used weights in glm and i also have to use the weights in dgamma?