Question: Exercise 2. Describe mathematically what the following code does. Add comments to each line describing what each line accomplishes. Design a scenario where this code

 Exercise 2. Describe mathematically what the following code does. Add comments

Exercise 2. Describe mathematically what the following code does. Add comments to each line describing what each line accomplishes. Design a scenario where this code would be useful and write that scenario in R. (The scenario should not involve more than four lines of R code) OpSp = function(y, x) { n = length (y) s=n - 1 xs = sort (x) ci = rep(0, s) ssri = rep(0, s) for (i in 1:s) { ci [i] = (xs[i] + xs [i+1])/2 y1 = y [xci [i]] - mean( y [x>ci [i]] ) ssri [i] = sum( y1~2 ) + sum( y2-2 ) } return (ci [which . min (ssri) ]) 7

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