Hi all,
While running the anscombe.test in R, I'm getting an error of *Error in if (pval > 1) pval <- 2 - pval : missing value where TRUE/FALSE needed* for a few time series columns whereas for most of the series the function is working fine. I have checked for those specific columns for missing values. However, there is no NA/NAN value in the dataset. I have also run kurtosis for those time series and I can get results. I have noticed the same issue was reported in the following post for python (scipy.stat) and the report mentions that there is a bug in moments package in R. I was wondering whether the issue has been resolved. https://github.com/scipy/scipy/issues/1950 Could anyone please help me with the error? I look forward to hearing from you. Regards, Sania [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see 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. |
moments::anscombe.test(x) does give errors when x has too few values or if
all the values in x are the same > moments::anscombe.test(c(1,2,6)) Error in if (pval > 1) pval <- 2 - pval : missing value where TRUE/FALSE needed > moments::anscombe.test(c(2,2,2,2,2,2,2,2)) Error in if (pval > 1) pval <- 2 - pval : missing value where TRUE/FALSE needed You can use tryCatch() to return some special value where these errors occur. E.g., use tryCatch(anscombe.test(x), error=function(e) list(p.value=NA)) instead of ascombe.test (this assumes you will only look at p.value later - add other entries as needed.). -Bill On Thu, Oct 15, 2020 at 12:09 PM Sania Wadud <[hidden email]> wrote: > Hi all, > > While running the anscombe.test in R, I'm getting an error of *Error in if > (pval > 1) pval <- 2 - pval : missing value where TRUE/FALSE needed* for a > few time series columns whereas for most of the series the function is > working fine. I have checked for those specific columns for missing values. > However, there is no NA/NAN value in the dataset. > > I have also run kurtosis for those time series and I can get results. I > have noticed the same issue was reported in the following post for python > (scipy.stat) and the report mentions that there is a bug in moments package > in R. I was wondering whether the issue has been resolved. > > https://github.com/scipy/scipy/issues/1950 > > Could anyone please help me with the error? > > I look forward to hearing from you. > > Regards, > Sania > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see 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. |
Hi Bill,
Thanks for prompt reply and letting me know a way around it. I have more than 1200 observations and not all the values are the same. However, my data points are quite similar, for example, 0.079275, 0.078867, 0.070716 in millions and etc. I have run the data without converting it to millions and I still get the same error message. As I have kurtosis value, it should be fine for the time being. However, in case if you have any other explanation behind the error, I will highly appreciate it. Best wishes, Sania On Thu, 15 Oct 2020 at 20:43, Bill Dunlap <[hidden email]> wrote: > moments::anscombe.test(x) does give errors when x has too few values or if > all the values in x are the same > > > moments::anscombe.test(c(1,2,6)) > Error in if (pval > 1) pval <- 2 - pval : > missing value where TRUE/FALSE needed > > moments::anscombe.test(c(2,2,2,2,2,2,2,2)) > Error in if (pval > 1) pval <- 2 - pval : > missing value where TRUE/FALSE needed > > You can use tryCatch() to return some special value where these errors > occur. E.g., use > > tryCatch(anscombe.test(x), error=function(e) list(p.value=NA)) > > instead of ascombe.test (this assumes you will only look at p.value later > - add other entries as needed.). > > -Bill > > On Thu, Oct 15, 2020 at 12:09 PM Sania Wadud <[hidden email]> > wrote: > >> Hi all, >> >> While running the anscombe.test in R, I'm getting an error of *Error in if >> (pval > 1) pval <- 2 - pval : missing value where TRUE/FALSE needed* for a >> few time series columns whereas for most of the series the function is >> working fine. I have checked for those specific columns for missing >> values. >> However, there is no NA/NAN value in the dataset. >> >> I have also run kurtosis for those time series and I can get results. I >> have noticed the same issue was reported in the following post for python >> (scipy.stat) and the report mentions that there is a bug in moments >> package >> in R. I was wondering whether the issue has been resolved. >> >> https://github.com/scipy/scipy/issues/1950 >> >> Could anyone please help me with the error? >> >> I look forward to hearing from you. >> >> Regards, >> Sania >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> [hidden email] mailing list -- To UNSUBSCRIBE and more, see >> 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. >> > [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see 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. |
Another bad case is
> moments::anscombe.test(rep(c(1,1.1),length=35)) Error in if (pval > 1) pval <- 2 - pval : missing value where TRUE/FALSE needed I haven't checked the formulas carefully, but I suspect the problem is from taking the cube root of a negative number in z <- (1 - 2/(9 * a) - ((1 - 2/a)/(1 + xx * sqrt(2/(a - 4))))^(1/3))/sqrt(2/(9 * a)) In R, the cube root (or any non-integral power) of a negative real number is NaN and ((1 - 2/a)/(1 + xx * sqrt(2/(a - 4)))) is c. -928 in this example. I think the intent was for the cube root to be a negative real, c. -9.76, in this case. If that is the intent, then a fix is to define a cube_root function for reals cube_root <- function (x) sign(x) * abs(x)^(1/3) and change the z<-... line to use cube_root() instead of ^(1/3). z <- (1 - 2/(9 * a) - cube_root(((1 - 2/a)/(1 + xx * sqrt(2/(a - 4))))))/sqrt(2/(9 * a)) -Bill On Thu, Oct 15, 2020 at 3:15 PM Sania Wadud <[hidden email]> wrote: > Hi Bill, > > Thanks for prompt reply and letting me know a way around it. > > I have more than 1200 observations and not all the values are the same. > However, my data points are quite similar, for example, > 0.079275, 0.078867, 0.070716 in millions and etc. I have run the data > without converting it to millions and I still get the same error > message. As I have kurtosis value, it should be fine for the time being. > However, in case if you have any other explanation behind the > error, I will highly appreciate it. > > Best wishes, > Sania > > On Thu, 15 Oct 2020 at 20:43, Bill Dunlap <[hidden email]> > wrote: > >> moments::anscombe.test(x) does give errors when x has too few values or >> if all the values in x are the same >> >> > moments::anscombe.test(c(1,2,6)) >> Error in if (pval > 1) pval <- 2 - pval : >> missing value where TRUE/FALSE needed >> > moments::anscombe.test(c(2,2,2,2,2,2,2,2)) >> Error in if (pval > 1) pval <- 2 - pval : >> missing value where TRUE/FALSE needed >> >> You can use tryCatch() to return some special value where these errors >> occur. E.g., use >> >> tryCatch(anscombe.test(x), error=function(e) list(p.value=NA)) >> >> instead of ascombe.test (this assumes you will only look at p.value later >> - add other entries as needed.). >> >> -Bill >> >> On Thu, Oct 15, 2020 at 12:09 PM Sania Wadud <[hidden email]> >> wrote: >> >>> Hi all, >>> >>> While running the anscombe.test in R, I'm getting an error of *Error in >>> if >>> (pval > 1) pval <- 2 - pval : missing value where TRUE/FALSE needed* for >>> a >>> few time series columns whereas for most of the series the function is >>> working fine. I have checked for those specific columns for missing >>> values. >>> However, there is no NA/NAN value in the dataset. >>> >>> I have also run kurtosis for those time series and I can get results. I >>> have noticed the same issue was reported in the following post for python >>> (scipy.stat) and the report mentions that there is a bug in moments >>> package >>> in R. I was wondering whether the issue has been resolved. >>> >>> https://github.com/scipy/scipy/issues/1950 >>> >>> Could anyone please help me with the error? >>> >>> I look forward to hearing from you. >>> >>> Regards, >>> Sania >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see >>> 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. >>> >> [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see 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. |
Hi Bill,
Thanks for rectifying the issue. It seems to be a cube root of a negative real issue. After updating the function it's working fine and showing the correct results. I highly appreciate your help. Best wishes, Sania On Fri, 16 Oct 2020 at 00:36, Bill Dunlap <[hidden email]> wrote: > Another bad case is > > moments::anscombe.test(rep(c(1,1.1),length=35)) > Error in if (pval > 1) pval <- 2 - pval : > missing value where TRUE/FALSE needed > > I haven't checked the formulas carefully, but I suspect the problem is > from taking the cube root of a negative number in > z <- (1 - 2/(9 * a) - ((1 - 2/a)/(1 + xx * sqrt(2/(a - > 4))))^(1/3))/sqrt(2/(9 * a)) > In R, the cube root (or any non-integral power) of a negative real number > is NaN and ((1 - 2/a)/(1 + xx * sqrt(2/(a - 4)))) > is c. -928 in this example. I think the intent was for the cube root to > be a negative real, c. -9.76, in this case. > > If that is the intent, then a fix is to define a cube_root function for > reals > cube_root <- function (x) sign(x) * abs(x)^(1/3) > and change the z<-... line to use cube_root() instead of ^(1/3). > z <- (1 - 2/(9 * a) - cube_root(((1 - 2/a)/(1 + xx * sqrt(2/(a - > 4))))))/sqrt(2/(9 * a)) > > -Bill > > On Thu, Oct 15, 2020 at 3:15 PM Sania Wadud <[hidden email]> wrote: > >> Hi Bill, >> >> Thanks for prompt reply and letting me know a way around it. >> >> I have more than 1200 observations and not all the values are the same. >> However, my data points are quite similar, for example, >> 0.079275, 0.078867, 0.070716 in millions and etc. I have run the data >> without converting it to millions and I still get the same error >> message. As I have kurtosis value, it should be fine for the time being. >> However, in case if you have any other explanation behind the >> error, I will highly appreciate it. >> >> Best wishes, >> Sania >> >> On Thu, 15 Oct 2020 at 20:43, Bill Dunlap <[hidden email]> >> wrote: >> >>> moments::anscombe.test(x) does give errors when x has too few values or >>> if all the values in x are the same >>> >>> > moments::anscombe.test(c(1,2,6)) >>> Error in if (pval > 1) pval <- 2 - pval : >>> missing value where TRUE/FALSE needed >>> > moments::anscombe.test(c(2,2,2,2,2,2,2,2)) >>> Error in if (pval > 1) pval <- 2 - pval : >>> missing value where TRUE/FALSE needed >>> >>> You can use tryCatch() to return some special value where these errors >>> occur. E.g., use >>> >>> tryCatch(anscombe.test(x), error=function(e) list(p.value=NA)) >>> >>> instead of ascombe.test (this assumes you will only look at p.value >>> later - add other entries as needed.). >>> >>> -Bill >>> >>> On Thu, Oct 15, 2020 at 12:09 PM Sania Wadud <[hidden email]> >>> wrote: >>> >>>> Hi all, >>>> >>>> While running the anscombe.test in R, I'm getting an error of *Error in >>>> if >>>> (pval > 1) pval <- 2 - pval : missing value where TRUE/FALSE needed* >>>> for a >>>> few time series columns whereas for most of the series the function is >>>> working fine. I have checked for those specific columns for missing >>>> values. >>>> However, there is no NA/NAN value in the dataset. >>>> >>>> I have also run kurtosis for those time series and I can get results. I >>>> have noticed the same issue was reported in the following post for >>>> python >>>> (scipy.stat) and the report mentions that there is a bug in moments >>>> package >>>> in R. I was wondering whether the issue has been resolved. >>>> >>>> https://github.com/scipy/scipy/issues/1950 >>>> >>>> Could anyone please help me with the error? >>>> >>>> I look forward to hearing from you. >>>> >>>> Regards, >>>> Sania >>>> >>>> [[alternative HTML version deleted]] >>>> >>>> ______________________________________________ >>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see >>>> 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. >>>> >>> [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see 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. |
Free forum by Nabble | Edit this page |