I want to plot a regression line with (a = 0 and b = 1) and add the individual point deviations from this along with identifying the data point with name.
set.seed(123)
namelab <- paste ("ET", 1:10, sep = "")
xvar <- 1:10
yvar <- rnorm(10, 5, 5)
myd <- data.frame(namelab, xvar, yvar)
plot(xvar, yvar)
abline (a= 0, b = 1, col = "red", lty = 2)
Just manual sketch of my intention, I just labelled a single point just for example. The line drawn need a slim.
S(errors) = (SQRT(1 minus R-squared)) x STDEV. So, if you know the standard deviation of Y, and you know the correlation between Y and X, you can figure out what the standard deviation of the errors would be be if you regressed Y on X.
The standard deviation of the residuals calculates how much the data points spread around the regression line. The result is used to measure the error of the regression line's predictability.
dev.new(width=4, height=4)
plot(xvar, yvar, asp=1)
a = 0
b = 1
abline (a, b, col = "red", lty = 2)
myd$xint = with(myd, (b*yvar + xvar - b*a) / (b^2 + 1))
myd$yint = with(myd, (b*yvar + b*xvar + a) / (b^2 + 1))
with(myd, segments(xvar, yvar, xint, yint))
with(myd, text(xvar, yvar, labels=namelab, pos=3, cex=0.5))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With