1

I am trying to figure out how to calculate the scatter index of a scatter plot in R. While I have the formula, I am still very new to using R and coding and am unsure of how to write it in the programming language. The formula is:

My data is:

structure(list(S = c(0.619, 0.582, 0.653, 0.611, 0.649, 0.558 ), 
               O = c(0.58, 0.55, 0.52, 0.56, 0.49, 0.54)), 
          row.names = c(NA, 6L), class = "data.frame")

Any help would be greatly appreciated.

kath
  • 7,624
  • 17
  • 32
R.Rookie
  • 21
  • 5

1 Answers1

2

Here's a stab at your formula:

ScatterIndex <- function(s, o) sqrt( sum((s-mean(s)) - (o-mean(o)))^2 / sum(o^2) )

The vectors provided must be the same length.


Your data, and the output:

x <- structure(list(S = c(0.619, 0.582, 0.653, 0.611, 0.649, 0.558 ), O = c(0.58, 0.55, 0.52, 0.56, 0.49, 0.54)), row.names = c(NA, 6L), class = "data.frame")
ScatterIndex(x$S, x$O)
# [1] 1.676298e-16
r2evans
  • 141,215
  • 6
  • 77
  • 149