How to reinterpolate the data to same length by package ‘dtwclust’ - r

I'm trying to do a hierarchical cluster dendrogram of time series in R using the dtwclust package. For my test dataset I have 7 columns with unequal lengths. The dtwclust package offers a way to equalize the lengths using a reinterpolate function. However I get this error when I try to use it with the following code
data <- reinterpolate(my_data, new.length = max(lengths(my_data)))
Error in check_consistency(x, "ts") : There are missing values in the series.
I do not know if this means that the data table is not organized properly. Can anyone suggest how to read in the data (I just imported it using RStudio) or any other way to resolve this issue. I tried the analysis using the data provided in the package and it worked as advertised.

Related

K-Means Clustering using parameters library suddenly not showing results. Cluster_analysis() , predict(), plot()

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.

using the 'ptw' package in R

I am working on applying the ptw package to my GC-MS wine data. So far I have been able to correctly use this package on the apples example data described in the vignette (MTBLS99). Since I am new to R, I am unable to get my .CDF files into the format they used to start the vignette. They started with three data frames (All.pks, All.tics, All.xset). I assume that this was generated using the xcms package. But I cannot recreate the specific steps used for the data to be formatted in this manner. Has anyone successfully applied 'ptw' to their LC/GC-MS data? can someone share the code used for generating the All.pks, All.tics, All.xset data frames?

How do I organize my data for time series cluster analysis using the dtwclust package?

I'm trying to do a hierarchical cluster dendrogram of time series in R using the dtwclust package. For my test dataset I have 4 columns with unequal lengths. the dtwclust package offers a way to equalize the lengths using a reinterpolate function. However I get this error when I try to use it with the following code
data <- reinterpolate(fshdtw, new.length = max(lengths(fshdtw)))
Error in check_consistency(x, "ts") : There are missing values in the series. This makes me think (I could be wrong) that the data table is not organized properly. Can anyone suggest how to 1. read in the data (I just imported it using RStudio) or any other way to resolve this issue. PS: I tried the analysis using the data provided in the package and it worked as advertised. Thanks in advance!
The data file is here https://www.dropbox.com/s/dih39ji0zop9xa0/fshdtw.txt?dl=0

Import Eviews workfile into R

I have problem importing an Eviews workfile into R. I use the hexView package and I can get the time series data into R but I do not get the periods responding to the time series imported. (The periods is not stored as a timeseries object.)
I would not like to create an time series objects for the periods in the workfile to solve the problem.
If there is another way than using the hexView package to import the data and the responding periods it would be great.
Right now I use this simple code to read the data into R
d <- readEViews("testData.wf1", as.data.frame = TRUE)
Any and all help will be greatly appreciated.
This question motivated me to create an R package EviewsR, which is available on CRAN.
Please follow the following steps in R:
install.packages("EviewsR")
library(EviewsR)
import("importedDataframe","testData")
eviews$importedDataframe # to access the imported dataframe in R
The package works with base R, R Markdown and Quarto.
I am currently updating the package to provide new features
I look forward to your feedback.

Using Amelia (multiple imputation) output for analysis using functions other than linear regression

Background Use of the Zelig package on Amelia output for linear regression is well outlined in the Amelia II documentation.
Problem Unfortunately, I am unable to find any documentation of how to use this output for other analysis. The problem seems to lie with how other packages see the Amelia output.
Since the Zelig package seems be able to treat all the imputations as one data set, I'd love to be able to use that single data set for manipulation with other packages (e.g., dplyr), but I'm unable to get a single data.frame out of the package.
I'm not sure if this answers your question, but you can extract the imputed datasets using:
df <- a.out$imputations[[1]]
Which will assign the first imputed dataset to the data.frame df.

Resources