Stephen Politzer-Ahles
2013-Feb-13 16:55 UTC
[R] e1071::skewness and psych::skew return NaN
Hello everyone, Does anyone know what would cause the skewness() function (from e1071), as well as skew() from psych, to return a value of NaN? I have a vector of positively-skewed data (https://docs.google.com/file/d/0B6-m45Jvl3ZmYzlHRVRHRURzbVk/edit?usp=sharing) which these functions return a value for like normal:> skewness( data ) # returns 1.400405but when I instead give those functions the log-transformed data they return NaN> skewness( log( data ) ) #returns NaNThe same occurs when I feed the function data transformed by reflected reciprocal> skewness( max(data) - 1/data ) ) #returns NaNThe vector has no missing values (and if it did, I would get NA rather than NaN, and the function wouldn't return a number when I give it the raw data). Best, Steve -- Stephen Politzer-Ahles University of Kansas Linguistics Department http://people.ku.edu/~sjpa/
Stephen Politzer-Ahles
2013-Feb-13 17:15 UTC
[R] e1071::skewness and psych::skew return NaN
Hi everyone, Please disregard my last message, I found a 0 in the vector, which is what was causing problems with the log and reciprocal data. Best, Steve On Wed, Feb 13, 2013 at 10:55 AM, Stephen Politzer-Ahles <politzerahless at gmail.com> wrote:> Hello everyone, > > Does anyone know what would cause the skewness() function (from > e1071), as well as skew() from psych, to return a value of NaN? > > I have a vector of positively-skewed data > (https://docs.google.com/file/d/0B6-m45Jvl3ZmYzlHRVRHRURzbVk/edit?usp=sharing) > which these functions return a value for like normal: > >> skewness( data ) # returns 1.400405 > > but when I instead give those functions the log-transformed data they return NaN > >> skewness( log( data ) ) #returns NaN > > The same occurs when I feed the function data transformed by reflected > reciprocal > >> skewness( max(data) - 1/data ) ) #returns NaN > > The vector has no missing values (and if it did, I would get NA rather > than NaN, and the function wouldn't return a number when I give it the > raw data). > > Best, > Steve > > -- > Stephen Politzer-Ahles > University of Kansas > Linguistics Department > http://people.ku.edu/~sjpa/-- Stephen Politzer-Ahles University of Kansas Linguistics Department http://people.ku.edu/~sjpa/
Hello, That value means that some values of your data are negative or zero. A simple inspection shows that any(dat < 0) # FALSE any(dat == 0) # TRUE Solution: don't log your data Hope this helps, Rui Barradas Em 13-02-2013 16:55, Stephen Politzer-Ahles escreveu:> Hello everyone, > > Does anyone know what would cause the skewness() function (from > e1071), as well as skew() from psych, to return a value of NaN? > > I have a vector of positively-skewed data > (https://docs.google.com/file/d/0B6-m45Jvl3ZmYzlHRVRHRURzbVk/edit?usp=sharing) > which these functions return a value for like normal: > >> skewness( data ) # returns 1.400405 > > but when I instead give those functions the log-transformed data they return NaN > >> skewness( log( data ) ) #returns NaN > > The same occurs when I feed the function data transformed by reflected > reciprocal > >> skewness( max(data) - 1/data ) ) #returns NaN > > The vector has no missing values (and if it did, I would get NA rather > than NaN, and the function wouldn't return a number when I give it the > raw data). > > Best, > Steve > > -- > Stephen Politzer-Ahles > University of Kansas > Linguistics Department > http://people.ku.edu/~sjpa/ > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >