Want to study the regime switching of a time series using MSGARCH package in Rstudio. After specifying the model, tried to fit the model using data of series using FitML function.I have used the following code to fit data.
msgarch_fit=FitML(msgarch_spec,data="log_ret") ## I have found the log return of the series and saved it in the vector named "log_ret".
But the following error is displayed.
"Error in f_check_y(data) : y must be numeric"
Being a beginner I can't understand the meaning of it. It would be of great help if someone can explain.
I tried to execute the code but error was displayed.
I was expecting to get the summary output.
Thank you
Related
I was working on a dataset and performing some k-means clustering. I was using the parameters library and the following commands which ran super smoothly until it just stopped giving me results.
The cluster_analysis() command gives the output but predict() gives only NAs and plot gives the error
"Error in UseMethod("principal_components") : no applicable method for 'principal_components' applied to an object of class "c('double', 'numeric')""
The code is shown below. I have attached the data as well along with the sample plot that i used to get when the code ran without errors.
Can someone please help?
library(parameters)
res_kmeans <- cluster_analysis(PC12,
n = 4,
method = "kmeans")
predict(res_kmeans)
plot(res_kmeans)
The output I used to get when the code ran properly
The Data can be found here
Your PC12 object is a matrix. The manual page of the cluster_analysis() function indicates that it requires a data frame. I downloaded your .csv file and used read.csv() to import it and that produces a data frame so it ran fine for me. The cluster_analysis() function does not produce a warning or error matrix when given a matrix, but it returns NAs for the cluster memberships (attr(res_kmeans, "clusters")). The quick solution is to use
res_kmeans <- cluster_analysis(as.data.frame(PC12), n = 4, method = "kmeans")
in your code. You could also contact the package maintainer (maintainer("parameters") to get the email address). It would be simple to check the first argument and convert it to a data frame.
Problem: I am trying to run a mixed ANOVA in R. When I run the ANOVA, I get an error saying that all of my data values are missing.
This is what the data look like (just the first few rows):
Screenshot of data after running View(SWL_data)
When I try to run the ANOVA, I get an error that all the cases are missing values even though they clearly have values when I look at the data file in View(). ANOVA code and error
I checked each of the object types. R code and output of object types
I am not sure how to share the code so that this problem is reproducible without sharing all of my data. This is my first post so thank you for your patience with me!
Asking for a friendly soul that knows how to fix this error or that understands why this is appearing.
Not exactly sure what happened but this error appears every time I try to do a GAM with random effects (bs="re", with mgcv package). This is strange since appears not only to new models but even to models that previously worked (multiple times).
I made sure the data has no NA's, scientific data, or random formulas. Also, I am not using the date format to avoid errors has previously worked as it is.
I also tried to transform the data into a data frame via as.data.frame(x) but the same error occurred.
I have been playing a bit with the formula and it appears that every time the random effects bs="re" are present, either the 2 of them (Site, State) or only one of them (Site), it is when the error occurs. If I take them completely out of the formula it works perfectly.
I am thinking that could be:
Some incompatibility with another package that I may have installed but tried to solve this with no effect. Removed all the most recently installed packages and the error persisted.
Other could be any update to the mgcv package?
Update: It works in R software just not in R studio.
Does anyone have an idea on how to fix this or why this is appearing
The following model was previously working but not anymore, giving me every single time the mentioned error
gam_2a <- gam(Total_Items ~ s(DayI0, k=14) + s(Site, State, bs="re"), offset(log(EffortDayC)),data = x,family=poisson(link="log"),method = "REML")
Description of the variables:
Total_Items = Number of items of debris found per event;
DayI0 = Number of days since first clean up (numeric);
Site = Site of sampling (Sites are within States);
State = State of sampling;
EffortDayC = Effort(Length of the beach, number of volunteers, duration of sampling)*DayC(interval of sampling);
The str(x) output below:
enter image description here
And the head of the data to understand a bit better:
enter image description here
enter image description here
Sorted! the package agricolae was causing some incompatibility with the mgcv package.
My question is with regards to creating a weighted box plot using ENmisc library. I have a dataframe and I want to plot the boxplot based on two different categories (both type chr).
The error given is ## Error: missing value where TRUE/FALSE needed from the line wtd.boxplot(df2J$mean_P32 ~ df2J$mode_Litho,weights=df2J$length). I've attached a log of the portion of code in question below which shows the values of each data type as well as that there is not any data missing. The last line produces a boxplot similar to the one I would expect from the line above.
Unfortunately I don't know how to recreate this error with a general example so I haven't provided code that can be run.
If anyone could shed some light on this error it would be much appreciated.
Other Info:
The plots work if I use the base package boxplot function.
There are other ways I could create weighted boxplots if needed such as this but I really don't see any reason this shouldn't work.
wtd.boxplot function
ENmisc library
I'm not sure why this doesn't show up in the Knitr ourput but The error that shows up in the R console is Error in if (any(out[nna])) stats[c(1, 5)] <- range(x[!out], na.rm = TRUE) :
missing value where TRUE/FALSE needed
I have the same problem and it happens because (I think) you have only 1 member for one of your groups. Check it.
As title, I have collected data for 1:6 matched case-control study and I am trying to analyze the data using matchTab, but it gives me error "subscript out of bounds", I wonder if anyone here has met anything similar before. What does it mean? Some issue about my dataset? As I have tried the manual, I can get the result using the dataset used in the manual.
Thanks.
That error often arises from matrix subsetting beyond the dimensions of the object. Try this for example:
mat <- matrix(1:9, ncol = 3)
mat[,4]
with the last line yielding
> mat[,4]
Error: subscript out of bounds
This sometimes happens in code because the programmer forgot that [ drops empty dimensions - I've done this myself many times, forgetting the 1 column matrix case! I'm not saying this is the problem here, but is one common cause of it in R code.
As you haven't provided a reproducible example and I am unfamiliar with the package you mention, I can't diagnose the problem further. It could be a bug in their package or a problem with how you have supplied, or understood you needed to supply, data to the function.
First thing I would do is re-read the man page for the function. Confirm you have the arguments supplied correctly. If that doesn't help, rerun to generate the error and then call traceback() to see exactly in what function the error is being raised. To debug further, try
options(error = recover)
then rerun your code. This will drop you into the debugger so you can go into the frame where the error occurred and see what all the objects were like, how they were sized etc. and why the error was being raised.
If you are not up to debugging this yourself, you might need to contact the maintainers, or provide a reproducible example...