Mathematics

2. write an R function that takes as input binomial responses and covariates and uses
the Newton-Raphson algorithm to compute the coefficients of a binomial GLM. You
could use the ‘Kidney stone surgery” data or any other dataset that includes at least
2 explanatory variables. For the ‘Kidney stone surgery’ data, some of the steps could
(but don’t have to) be done as follows
First enter the data
intercept, small=0, keyhole=p, successes, failures
r1<-C(1,0,0,234,36)
r2<-c(1,0,1,81,6)
r3<-c(1,1,0,55,25)
r4<-c(1,1,1,192,71)

Put all data in a matrix
data<-rbind(r1,r2,r3,r4)
Write the function
bglm<-function(data){
beta<-matrix(c(x,x,x)) # X’s denote the initial values of your choice
Define the likelihood, its first and second derivatives
Newton-Raphson algorithm
Finish by returning the vector of coefficients
return(beta);

Double check your results by comparing them to results from a statistical software.
Note that, more general functions can be written by allowing more inputs, such as
initial values etc. (but this is not necessary for the current exercise).
Example – Kidney stone surgery and stone size
Table 6 is from a study investigating the success probabilities of two surgery types for
the removal of kidney stones.1 Success in surgery was determined by the elimination (or
reduction to less than 2mm diameter) of the stones after three months. A total of 700
operations were classified according to variables Y = surgery outcome (success, failure),
X = surgery type ( keyhole, open), and Z 2 stone size (small, large) which here is the
control variable.
Table 6: Treatment of kidney stones
Stone Surgery Outcome Percent
Size Type Success Failure Success
Small Keyhole 234 36 86.7%
Open 81 6 93.1%
Large Keyhole 55 25 68.8%
Open 192 71 73.0%
Total Keyhole 289 61 82.6%
Open 273 77 78.0%
Table 6 consists of two 2 X 2 tables which are refer to as partial or conditional tables,

READ ALSO :   Novice vs Expert Learners

TAKE ADVANTAGE OF OUR PROMOTIONAL DISCOUNT DISPLAYED ON THE WEBSITE AND GET A DISCOUNT FOR YOUR PAPER NOW!