From: francogrex <francogrex_at_mail.com>

Date: Tue, 26 Jun 2007 02:23:10 -0700 (PDT)

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.

etc until 250 rows (or sometimes more)?

where 0 indicates absence and 1 indicates presence/success

Date: Tue, 26 Jun 2007 02:23:10 -0700 (PDT)

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. ______________________________________________ R-help_at_stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.Received on Tue 26 Jun 2007 - 09:28:54 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Tue 26 Jun 2007 - 09:32:18 GMT.