Question: I am working on a problem set in R, where I must make a function that will take three arguments and print the sum of

I am working on a problem set in R, where I must make a function that will take three arguments and print the sum of squared errors. The text-problem is as following:

Write function called `model_score_int`. `model_score_int` should take three arguments: (1) a guess for the intercept, (2) a vector of x's, and (3) a vector of y's. The function should use the guess for the intercept to calculate the slope that passes through the point (mean(x), mean(y)). Remember that you given two points can calculate the slope as (Y2-Y1) / (X2-X1). Using the line defined by the intercept passed to the function and the calculated slope as your prediction rule, calculate the sum of squared errors for the data given by x and y.

My code for the function so far is:

model_score_int <- function(intercept, x, y) { b1 <- ((y[2]-y[1])/(x[2]-x[1])) e <- y - b1 sum(e^2)

But when I run it with values I get 'Inf' as output. Please help me make a function that can calculate it correct! }

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 Databases Questions!