Calculation of the standard deviation of the scattering pattern in R

I created a scatter plot of two vectors using R, combined with a line (using abline) that represents the diagonal x = y. I want to calculate the standard deviation of the points from the diagonal and color the area that is between the first and third quantiles.
I have no idea how to do this, and would appreciate any help !!! Thank you in advance. Hajj.

+4
source share
1 answer

Well what do you want to do:

# sample data x <- rnorm(50,0,2) y <- x+rnorm(50,0,2) # construct polygons div <- quantile(yx,c(0.25,0.75)) x1 <- min(c(x,y)) x2 <- max(c(x,y)) plot(x,y,type="n") polygon(x=c(x1,x1,x2,x2),y=c(x1+div,(x2+div)[c(2,1)]),col="grey") abline(0,1) points(x,y) 

What I would do is:

 qplot(x,y,geom="point") + stat_smooth(method="lm") 

The standard deviation you want to calculate is

 sd(yx) 

The correct measure you're probably looking for is:

 sd(residuals(lm(y~x))) 

You must think in terms of a linear model of y by x in order to get any meaningful result if you have no very good reason not to. If the ratio between x and y is not 1 on 1, then on condition that the correct model does not make sense like that. And if the ratio of x to y is not 1 to 1, yx will not be normally distributed and, therefore, sd will be difficult to interpret in a meaningful way.

+3
source

Source: https://habr.com/ru/post/1333247/


All Articles