سؤال

I'm doing a basic lm model in R. I'd like to get the maximum and average residual as a percentage of fitted value, but don't know how to go about this.

So for instance, if I have a dataset of 3 points - my predictions: (2, 8, 9) and I'm fitting them against the actual data: (4, 10, 12), then the maximum residual (observed - predicted) in terms of percentage of fitted value is from the first match-up, as it's 100% of the fitted value (the residual, 4-2 = 2, and the fitted value ie. my prediction was 2). The average residual percentage in this case would be (100 + 25 + 33)/3 = 52% (approx).

Is there a function that will produce these results if given the lm model object, or does anyone have any suggestions for how to code for it? I'm quite new in R, and am not sure how to extract the correct data to do so manually.

Thanks a lot to anyone who helps!

هل كانت مفيدة؟

المحلول

Counter = 1

Percentages = numeric()

Fitted = c(2, 8, 9)

Residuals = c(2, 2, 3)

for (element in Fitted) {Current_resid = Residuals[Counter] Current_percent = abs((Current_resid/element)*100) Percentages = c(Percentages, Current_percent) Counter = Counter + 1} Current_resid Counter Percentages sum_Percent = sum(Percentages) Average_Percent = sum_Percent/(counter-1)

Counter = 1

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top