Fatal error when runing es() function in R - r

es function in smooth package has a weird behavior for some short time-series. Here is a case:
require(smooth) # version 2.4.7
#create two time series of length 10
vec1_ts<-ts(c(36,24,51,7,7,77,1,29,19,2),start=c(2016,1),frequency=12)
vec2_ts<-ts(1:10,start=c(2016,1),frequency=12)
#this works:
es(vec1_ts)
#but this doesn't:
es(vec2_ts)
# another non-working example with a shorter length
vec3_ts<-ts(c(23,5,4,12,2,5),start=c(2016,1),frequency = 12)
es(vec3_ts)
I got a "R encountered a fatal error" message, and then forced to terminate the session when running es for the second time-series.

This looks like a bug in the function of that package. Can you, please, submit the bug here: https://github.com/config-i1/smooth/issues
The StackOverflow is not for solving problems of specific packages, it is for the solution of more general problems.

Related

Quantmod/getOptionChain Error in .Date(Exp/86400) : could not find function ".Date"

I'm getting an error when running getOptionChain from quantmod package.
The code should get Option chain data and subset into a new list that contains only the puts.
The error I get is: Error in .Date(Exp/86400) : could not find function ".Date"
Same code, sometimes runs without error. If I shorten the list of Symbols, there's no error, but the error as far as I know is not related to a specific symbol, because I made to run successfully. Seems random but frequent error.
All symbols are weekly expirations and the desired output is the next weekly expiration, so from my understanding, there's no need to specify a exp date.
library(quantmod)
library(xts)
Symbols<-c ("AA","AAL","AAOI","AAPL","ABBV","ABC","ABNB","ABT","ACAD","ACB","ACN","ADBE","ADI","ADM","ADP",
"ADSK","AEO","AFL","AFRM","AG","AGNC","AHT","AIG","AKAM","ALGN","AMAT","AMBA","AMC","AMD","AMGN",
"AMPX","AMRN","AMRS","AMZN","ANET","ANF","ANY","APA","APO","APPH","APPS","APRN","APT","AR","ARVL")
Options.20221118 <- lapply(Symbols, getOptionChain)
names(Options.20221118) <- Symbols
only_puts_list <- lapply(Options.20221118, function(x) x$puts)
After upgrading to R 4.2.2 the issue is fixed.

How to solve the following error running rmcorr in R: Error in isa(Participant, "character") : could not find function "isa"

I have the data in long format, with subject (numbered 1 to 124), Day, measure1, and measure2. There are about 14 repeating measures per subject. I want to run rmcorr to see if there is a correlation between measure1 and measure2 across all subjects. I used the code:
rmcorr(participant, measure1, measure2, data)
I get:
Error in isa(Participant, "character") : could not find function "isa"
I have used the same syntax before without any errors arising!
I've seen this error with older versions of R and strangely with 4.0.4, but only in Linux. I would try updating R. Hopefully that works!
The isa() function is a function in the base library (https://stat.ethz.ch/R-manual/R-devel/library/base/html/class.html), which is not part of all versions of R (use "?class()" to see if your version includes it).
In my case it worked to replace it with the "is()"-function, which does (in most cases, see documentation) pretty much the same. Just do
library(rmcorr)
isa = is
rmcorr(your input)
and you will be fine.
Best regards,
JF

R function seas() not found in v.4.1.0

I have a script that I have used several times over the past year. The last time I used it was 3 months ago. It was all working with no errors.
In the interim, I have upgraded R to v. 4.1.0. This may be a generic problem, but I've covered what I think are the obvious possible explanations (packages not installed, libs not loaded, typos, etc).
Here's the relevant code (all calls are successful up to the seas() call):
library(fpp2)
library(ggplot2)
library(seasonal)
library(seas) # Added recently in attempt to mitigate this issue
hh=6
ff=12
LT <- read.csv("C:\\...\\lt.csv")
LTts <- ts(LT, start=c(2007,1),frequency=12)
#...
LTx11 <- seas(LTts, x11="")
RESULT (Console output):
> LTx11 <- seas(LTts, x11="")
#Error in seas(LTts, x11 = "") : could not find function "seas"
Any tips or suggestions would be greatly appreciated.
After digging around a little more, I found the original text reference where I had learned to use the seas() function in Hyndman's text: https://otexts.com/fpp2/x11.html
In that text, I also found that seas() should be exposed by the seasonal library and verified this in the docs for that library.
After verifying this, added seasonal:: in front of the function and it worked. I wish I knew WHY this happened, but I don't. So here is the workaround.
Workaround:
LTx11 <- seasonal::seas(LTts, x11="")
If anyone can explain why this was necessary in v.4.1.0 and not earlier versions of R, please do!

ggplot2 error: Error in default + theme : non-numeric argument to binary operator

I have been getting the error Error in default + theme : non-numeric argument to binary operator. I have been using R and teaching R for a long time but I can't find this problem. I have included a reproducible example that fails this way below:
library(tibble)
library(ggplot2)
brains <- as_tibble(brains)
brains <- brains[1:10, ]
brains
ggplot(brains, aes(x = BodyWt, y = BrainWt)) +
geom_point()
The error occurs when executing the ggplot() statement.
My hardware is an HP Laptop 15-ef0xxx. I am running Windows 10 Home version 2004. I am running RStudio community edition "Water Lily" and R version R x64** 4.0.2.
I know this is a simple error and it is driving me crazy.
So I finally solved this problem. On the github issue I had opened Hiroaki commented that "One possibility is that you might set a invalid default theme in your .Rprofile, but I'm not sure..." (see link to issue below).
I'm not sure if your R file is part of a project but mine is.
So I went back and deleted the theme_set() line in my R file, went in and double checked all my project options and selected the option "Disable .Rprofile execution on session start/resume" and "Quit child processes on exit". And then I restarted the R session and now everything works. Including on the default R editor console.
I'm not sure if all those steps are necessary but that seemed to do the trick for me! Hope it helps.
I thought this was an RStudio issue but it seems it's possibly a ggplot2 > problem. I have verified using two different datasets that the same >error comes up when I try using ggplot2 in RStudio or using the default R >console. I get the exact same error with code that's been working fine >but now suddenly won't. I have opened an issue on Github (ggplot2) with a >reprex. Might be worth checking there: >https://github.com/tidyverse/ggplot2/issues/4177
I know this is not an answer per se but I don't have enough reputation >points to add a comment to the previous answer but I thought linking to >the issue on Github might help.
I think you have numbers quoted somewhere and you are trying to perform mathematical operation on character values. Consider
x <- c("5","6")
y <- x/1
> y <- x/1
Error in x/1 : non-numeric argument to binary operator
Now try converting x to numeric and perform the same operation.
y <- as.numeric(x)/1
> y
[1] 5 6
So, you need to use as.numeric on your variable.
The following should resove this issue
ggplot(brains, aes(x = as.numeric(BodyWt), y = as.numeric(BrainWt)))

Error in `freeParam` in fitting of normal copula [R]

I am using R version 3.3.2 and the package copula version 0.999-15 to evaluate the fitting of the normal copula to my data. My data and code are:
Data: https://www.dropbox.com/s/tdg8bfzmy4nd1dd/jumps.dat?dl=0
library(copula)
data <- read.csv(file="jumps.dat", head=F, sep="")
cop_model <- ellipCopula("normal", dim = 2)
m <- pobs(as.matrix(data))
fitCopula(cop_model, m, method = 'mpl')
After I run the code I receive the following error:
Error in `freeParam<-`(`*tmp*`, value = estimate) : the length of 'value' is not equal to the number of free parameters
Calls: fitCopula ... fitCopula.ml -> fitCopStart -> fitCopula.icor -> freeParam<-
Execution halted
I have no idea what is happening here. The fitting for Clayton and Gumbel is pretty fine. Searching for similar errors in the web, I have found nothing. Reading the documentation (https://www.rdocumentation.org/packages/copula/versions/0.999-15/topics/fitCopula?) for some specificity for ellipCopula, I have found an specific option for posDef, but it did not returns any solution at all.
Old question, but I found this, so will share my solution.
Try to run the following, this is a minimum working example:
library(copula)
print("-----------")
mycop <- ellipCopula("normal", dim=4)
data <- matrix(runif(400), nrow=4)
fitCopula(mycop, t(data))
print("-----------")
For me, this works fine if I open R and type in the lines one by one, but fails if I run as a script with Rscript. The solution is that you need library(methods) as well.
For some reason this worked with copula v0.999-v14, but was broken by v0.999-v16. Alas.

Resources