I am using the "mi" package for imputation of missing values. I have run the following code:
'mi' package code
library(mi)
imp_rd<-mi(rd1) ## rd1 is my data file containing 7 variables.
summary(imp_rd)
hist(imp_rd)
Now, I want to save the output of
"imp_rd" (which is my imputed data file) as .csv file. Any one who will help me regarding this problem.
if you want to export imputed data-sets generated by the model that mi estimated, a good way to do it is by using the mi2stata command, which allows you to export to either a .dta or a .csv format.
But remember not to think about exporting "one" imputed data set. The whole point of multiple imputation is that you can get a bunch of different imputed data sets that will allow you to account for the uncertainty induced by the missing data that you originally had.
So be sure to specify how many imputed data sets you want to export and the path where you want to save the imputed data. In the following example I chose to generate 10 imputed data sets.
library(mi)
imp_rd<-mi(rd1)
mi2stata(imp_rd, m=10, "pathtofile/imp_rd.csv")
Hope you find this useful.
if your output file is a dataframe you can use:
write.csv(imp_rd, file = "imp_rd.csv", sep = ",")
this should save file in csv in your working directory
thanks
Related
Is there a way to only use data from one CSV file that is not the same as this other CSV file? I recently split some data to conduct EFA and CFA analysis. I need to not use the information that will use to conduct the EFA analysis because then it serves no point to randomly split the data.
So how do I only use the data that I did not use in the CFA? If anyone can help please, it would be much appreciated.
Edit:
what I did was the following
Usage <-anti_join(file one, file two, by ='the column in which I could separate by')
then I just exported the file into a CSV, thank you all!
Example output of tab_model
I have created a table from tab_model that includes multiple models and wish to extract all 'p-values' and 'Estimates/Odds Ratio' to create a data frame that includes these. Output of tab_model is an html file. I am unable to find a function to pull this info in accordance, any ideas on how I could do this?
For example, I want to retrieve all p-values and Estimates for variable 'age' in all of my models...Only 3 in example image but I have hundreds
You should get these values from the regression models themselves, instead of outputting them to a HTML-table, and then extract them.
Without further knowledge of your process and data it is difficult to provide a more concrete answer.
I conduct a large number of regression analyses using ols and cph (different models, sensitivity analyses etc) which takes on my computer around two hours. Therefore, I would like to save these models so that I don't have to re-run the same analyses every time I want to work with them. The models all have very structured names, so I can create a list of names as follows:
model.names <- list()[grep("^im", ls())
But how can I use this to save those models? Could they be placed into a data frame?
I think you are looking for save()
save writes an external representation of R objects to the specified file. The objects can be read back from the file at a later date by using the function load or attach (or data in some cases).
This kind of question is already on Stackoverflow but it did not seem to solve my 'specific' problem.
I am imputing missing values into a dataset with the imputation package missForest. The output is a list with two elements and one of them is ximp which stores the imputed dataset. This dataset I want to save as a .Rdata file. However, R keeps giving me an error that it cannot find ximp. My code is as follows:
save(random_forest2.1$ximp, file = "random_forest21.Rdata")
The random_forest2.1 (Large missForest(2 elements, 8.7 mb)) is the object that stores and processes the imputation model.
How do I alter the save() function, so one element from that object can be saved?
I am working with multivariate longitudinal data, and was hoping to use the 'longitudinal' package to look at dynamical correlation between variables. I have been able to run the code fine until the end:
[example using stored data from the package]:
library("longitudinal")
data(tcell)
dynpc <- dyn.pcor(tcell.34, lambda=0)
class(dynpc)
(object is of class"shrinkage")
So here is my problem: how do I export this data to a .txt or .csv file? The function gives me a matrix of correlations, along with other information.