Learn R Programming

psych (version 1.0-23)

kurtosi: Kurtosis of a vector, matrix, or data frame

Description

Find the kurtosis of a vector, matrix, or dataframe.

Usage

kurtosi(x, na.rm = TRUE)

Arguments

x
vector, matrix, or data frame
na.rm
na.rm =TRUE removes missing data from the column

Value

  • kurtosia vector of the kurtosis for each column of the matrix

Details

Kurtosis in the E1071 program finds the kurtosis for a single vector. This does it for matrices and dataframes. Used in the describe function

See Also

skew, describe

Examples

Run this code
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.
 round(kurtosi(attitude),2)

## The function is currently defined as
function (x, na.rm = TRUE) 
{
    if (length(dim(x)) == 0) {
        if (na.rm) {
            x <- x[!is.na(x)]
        			}
       if (is.matrix(x) ) { mx <- colMeans(x,na.rm=na.rm)} else {mx <- mean(x,na.rm=na.rm)}
       
         sdx <- sd(x,na.rm=na.rm)
        kurt <- sum((x - mx)^4)/(length(x) * sd(x)^4)  -3
        } else {
    
    kurt <- rep(NA,dim(x)[2])
  #  mx <- mean(x,na.rm=na.rm)
  if (is.matrix(x) ) { mx <- colMeans(x,na.rm=na.rm)} else {mx <- mean(x,na.rm=na.rm)}
       
    sdx <- sd(x,na.rm=na.rm)
    for (i in 1:dim(x)[2]) {
    kurt[i] <- sum((x[,i] - mx[i])^4,  na.rm = na.rm)/((length(x[,i]) - sum(is.na(x[,i]))) * sdx[i]^4)  -3
            }
    }
    return(kurt)
}

Run the code above in your browser using DataLab