Dear R-help users, I have a question concerning re-writing a function in R:
Suppose I have the data, y is number of successes and N is total number of
trials and x is the variable
(example:)
x y N
1 10 150
0 1 100
I want to estimate the risk ratio by determining the coefficients of a
log-binomial regression so I use:
> glm(cbind(y, N - y) ~ x, family = binomial(link = "log"))
Coefficients:
(Intercept) x
-4.605 1.897
Using family=binomial(link="log") instead of
family="binomial" to specify
the log instead of the logit link function, so that the coefficient is the
log of the risk ratio.
I know that the equivalent negative log-likelihood
function is:
logregfun = function(a, b) {
p.pred = exp(a + b * x)
-sum(dbinom(y, size = N, prob = p.pred, log = TRUE))
}
But I am interesting in doing the calculation not using the glm function but
by optimizing the log-likelihood myself (so that I can play around with it
later, add priors etc...): using the above negative-log likelihood and optim
I can calculate the coefficients.
But how can I re-write the log-likelihood function if my data are in a list
(and not provided as number of successes and total number of trials): such
as
x y
0 0
0 1
1 1
0 1
... ...
etc until 250 rows (or sometimes more)?
where 0 indicates absence and 1 indicates presence/success
Thanks
--
View this message in context:
http://www.nabble.com/GLM%2C-log-binomial-likelihood-tf3981349.html#a11302456
Sent from the R help mailing list archive at Nabble.com.