Working Problem Set R Must Make Function Take Three Arguments Print Sum Squared Errors Tex Q43881646
I am working on a problem set in R, where I must make a functionthat 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 ofx’s, and (3) a vector of y’s. Thefunction should use the guess for the intercept to calculate theslope that passes through the point (mean(x),mean(y)). Remember that you given two points can calculatethe slope as (Y2-Y1) / (X2-X1). Using the linedefined by the intercept passed to the function and the calculatedslope as your prediction rule, calculate the sum of squarederrors for the data given by x andy.
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 helpme make a function that can calculate it correct!
}
Expert Answer
Answer to 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 sq…
OR