File: ss.R

package info (click to toggle)
r-cran-blockmodeling 1.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 912 kB
  • sloc: ansic: 2,024; f90: 952; sh: 13; makefile: 5
file content (30 lines) | stat: -rw-r--r-- 806 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#' @encoding UTF-8
#' @title Sum of Squared deviations from the mean and sum of Absolute Deviations from the median
#' 
#' @description
#' Functions to compute Sum of Squared deviations from the mean and sum of Absolute Deviations from the median. \code{ssNa} removes missing values (\code{NA}s) before calling the \code{ss} function.
#'
#' @param x A numeric vector.
#'
#' @return Sum of Squared deviations from the mean or sum of Absolute Deviations from the median.
#'
#' @author \enc{Aleš Žiberna}{Ales Ziberna}
#' @keywords univar
#' @importFrom stats median
#' 
#' @export

"ss" <-
function(x){sum(x^2)-sum(x)^2/length(x)}

#' @rdname ss
#' 
#' @export
ssNa<-function(x)ss(na.omit(as.vector(x)))

#' @rdname ss
#' 
#' @export
"ad" <-
function(x)sum(abs(x-median(x)))