Question: Using R: The logistic regression model from Question 3 can be extended to more variables, by defining the probability p ( x ) = 1

Using R: The logistic regression model from Question 3 can be extended to more variables, by defining
the probability
p(x)=11+e-(0+1x1+2x2).
(a) Write a function moment_distance(fi) that receives the name of an aftershock file,
and returns a dataframe with three columns: the mainshock seismic log-moment (log
of moment in all_events.csv), the distance between the mainshock and the possible
aftershock location computed (assume that the mainshock is at the centre of the grid of
points in the aftershock file), and column with the presence/abscence of an aftershock.
Use the column names moment, distance, aftershock, and note that the moment is the
same for all the rows, since we are looking only at one mainshock event. Display the first
few rows of the dataframe obtained by applying this function to 2001BHUJIN01YAGI.
(b) Implement a function fit2(X1, X2, Y) that minimises the negative log-likelihood
function f in Question 3 and returns the values of 0,1,2. Use optim (in R) or
scipy .optimize.minimize in Python, and do not use the derivative of f. Obtain the
values of 0,1,2 for 2001BHUJIN01YAGI using moment for x1, distance for x2 and
aftershock for y.
(c) Implement a function fit2_file(fi) that returns the values of 0,1,2 for the af-
tershock file fi using moment for x1, distance for x2 and aftershock for y. Plot
the values of 1 vs 0 and 2 vs 0 in two separate plots, one point for each event in
selectedEvents.csv.
Using R: The logistic regression model from

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!