R placing rugarch output into a dataframe - r

I have updated to the last version of R and updated the rugarch package as well.
Unfortunately some code that worked previously no longer works. I now get an error.
I would be greatful for some help to get the output into a dataframe.
library(rugarch)
data(sp500ret)
spec = ugarchspec( )
fit1 = ugarchfit(spec = spec, data = sp500ret)
df.fit1 <- as.data.frame(fit1,which="VaR")
Error in as.data.frame.default(fit1, which = "VaR"):
cannot coerce class "structure("uGARCHfit", package = "rugarch")" to a
data.frame
attributes(fit1)
shows:$fit$sigma
but when I try:
df1 <- data.frame(fit1$fit$sigma)
I get an error message;
Error in fit1$fit : $ operator not defined for this S4 class

as.data.frame(fit1, which="VaR") NEVER worked with an object of class uGARCHfit (you are confusing this with a uGARCHroll object). If you want the conditional VaR you can NOW (in the new version) use the quantile method e.g. quantile(fit1, c(0.01,0.05)).
If you want the conditional standard deviation then you should use sigma(fit1) which will return an xts matrix, or fit1#fit$sigma (# goes after an object in S4 classes). This and most other questions can be answered by carefully reading the documentation, vignette and the author's website which contains details of the changes.

Related

Create CYT object in CytoTree in R

I want to create a CytoTree CYT object in R to analyse my .FCS files. When I am using the Quick start code in the package description, I will always get an error when running the createCYT() function that says:
Error in createCYT(raw.data = fcs.data, normalization.method = "log") :
2022-09-26 15:46:26 meta.data must be a data.frame
As the function should not rely on any meta data and that object is optional, I do not know how to solve the error.
Here is the description:
https://ytdai.github.io/CytoTree/quick-start.html#quick-start-code
I thank you very much in advance for your help!
BR
I have encountered same problem previously.
In the end it worked only when the data.frame was added (yes, even though it should not depend on it).
Here is how:
meta.data <- data.frame(cell = rownames(fcs.data), stage = gsub(".fcs.+", "", rownames(fcs.data)))
meta.data$stage <- factor(as.character(meta.data$stage))
You may as well have a look at the Cytotree PDF in case of more issues.

Error when using *whatNWISdata* function within *dataRetrieval* package from USGS: All components of query must be named

I am trying to use the whatNWISdata function to retrieve all available data for specific USGS sites.
I get the following error after trying to execute the function:
siteNo <- "09508300"
dailyDataAvailable <- whatNWISdata(siteNo, service = "dv", parameterCd = "00060",
statCd = "00003")
Yields:
Error: All components of query must be named
Although I am using the function as recommended in rdocumentation.org and cran, I get the same error. My rstudio is updated to the latest version and so is my dataRetrieval package that this function is part of.
This error was a question that was brought up in 2016 on github, and they recommended downgrading the httr package, but the httr package has been updated since this question was asked and it seems this issue was resolved in the update.
Thanks!
Thank you so much for your input #Dragonthoughts!
I emailed the author and apparently they had made some slight edits in the format of the input values, and yes you are correct in that the first argument needed a value as in the other inputs for the function.
For anyone else having this problem, it works when you change the input to be like this: dailyDataAvailable <- whatNWISdata(siteNumber = "09508300", service = "dv", parameterCd = "00060", statCd = "00003")

Trouble with pairs() function in nlme

I am having trouble getting the pairs() function to work in nlme. Take this example from Pinhiero and Bates Mixed-Effects Models in S and S-Plus.
The model itself runs just fine
fm1Theo.lis <- nlsList(conc ~ SSfol(Dose, Time, lKe, lKa, lCl), data = Theoph)
But the pairs plot...
pairs(fm1Theo.lis, id = 0.1)
...returns this error
Error in as.data.frame.default(x) :
cannot coerce class "c("nlsList", "lmList")" to a data.frame
I also tried
pairs(fm1Theo.lis, ~ ranef(., level = 2), id = 0.1)
But get the same error. Any ideas?
Here's how one may think in this case. The error
Error in as.data.frame.default(x) :
cannot coerce class ‘c("nlsList", "lmList")’ to a data.frame
says that some object of class c("nlsList", "lmList") is being coerced to a data frame. Now since fm1Theo.lis is the result of using nlsList, it seems that the object in the error is indeed nlsList. That means that pairs does not know what to do with objects of such class. To confirm this, we can run
pairs.default(fm1Theo.lis, id = 0.1)
which is what is going to happen when no specific method for fm1Theo.lis is found. Indeed the error is the same. In one way or another confirming that nlsList and comes from nlme, it becomes clear that the issue is with loading the nlme package. Loading it or restarting the session then is almost surely going to help.

Error when using mice object: No applicable method for 'complete_'

library(mice)
md.pattern(dat1)
temp<-mice(dat1, m = 5, seed = 101)
dat1 <- complete(temp, 2)
Error in UseMethod("complete_") :
no applicable method for 'complete_' applied to an object of class "mids"
Hi, I'm trying to impute missing values using mice package.
But I got the above error message.
The first time I imputed missing data it worked, but when I tried again it didn't. I've tried a lot with different options (changing seed, deleting existing data or "temp" variable)
Sometimes it worked but other times it didn't.
What is the problem and solution?
Thanks in advance.
I think the problem here is that you should rather be using some other libraries in your program which have a function named "complete". Just typing "complete" in help menu gave me 2 other libraries (tidyr,RCurl) which have the function in the same name. As simon suggested, I tried using "mice::complete". It works for me.
Try this:
dat1<-mice::complete(temp,2)
mice 3.7.5 redefines the complete() function as the S3 complete.mids() method for the generic tidyr::complete().
Assuming that mice is attached, you should no longer see no applicable method for 'complete_' applied to an object of class "mids".

packaging issues with a function that uses arules

I'm using R and trying to assemble a bunch of functions into a package. One of the function uses the package arules to mine rules from a dataset, subset them and get other interest measures.
I'm having problem with the line that subsets them.
rules <- apriori(trainingTrans, parameter = list(support = 0.005, confidence = 0.0, maxlen = 6)
rulesCases <- subset(rules, subset = rhs %in% "event")
The functions works outside of the package as long as I've loaded arules, but doesn't work in the package whether I've set arules as a Depends, an Imports, or had the function call it with library(arules). The error displayed is 'match' requires vector arguments. I thought Arules has its own version of match to get around that, I've tried arules::match(rhs,"event"), but I still have the same problem.
The issue is that it does not find the correct version of %in%. Possibly this works:
rulesCases <- subset(rules, subset = arules::"%in%"(rhs, "event"))
This should be not necessary if you import arules, but there seems to be something weird going on. I hope this will be resolved in a future release of arules.
I had the same problem in my package and be able to fix it :
The syntax subset(rules, subset = arules::"%in%"(rhs, "event")) forces to use the correct version of %in% in the package, as Michael Hahsler noticed
But rhs is no more related with rules so it needed to be re-precised using rules#rhs
So the correct syntax should be subset(rules, subset = arules::"%in%"(rules#rhs, "event"))
It do the job for my package, with the DESCRIPTION file containing
LinkingTo: arules
Imports: arules
And no further uses of library(arules).

Resources