R/scorer.R

Defines functions calculateScore

calculateScore <- function(x, y, measurement ){

  betweenLowIndice=0
  betweenHighIndice=0
  result <- vector("numeric", length(measurement))
  for(i in 1:length(measurement)){
    for(j in 1:length(x)){
      if ((measurement[i]>=x[j])&&(measurement[i]<=x[j+1])){
        betweenLowIndice=j
        betweenHighIndice=j+1
        break
      }
    }
    slopeAndIntercept=summary(lm(y[betweenLowIndice:betweenHighIndice]~x[betweenLowIndice:betweenHighIndice]))
    score=coef(slopeAndIntercept)[2]*measurement[i]+coef(slopeAndIntercept)[1]
    result[i] <- score
  }
  return(result)
}
Halophila/scorecards documentation built on May 27, 2019, 3:29 p.m.