Cannot read a bestglm object after writing it with dput - r

I am trying to use bestglm on a logistic regression model fitting a smaller sample of my data (100x25) matrix (originaly 250kx40).
I run it in BATCH mode. and I wish to write the bestglm models to a file.
dput(test2,file="test2.txt",control=c("keepNA","keepInteger","showAttributes"))
t2<-dget(file="test2.txt")
Error in UseMethod("family") :
no applicable method for 'family' applied to an object of class "NULL"
Any ideas as to how to solve this problem?

There is something in the dput'ing of the bestglm that isn't right. If you simply dput to the console, copy+paste it back in to a new object, it will fail with the same error.
It may be a bug and you may want to reach out to the package maintainer(s).
In the meantime, try using saveRDS and readRDS:
saveRDS(test2, file="test2.rds")
t2 <- readRDS("test2.rds")

Related

How to recognize a column in R

I have merged two data sets (data1.csv and data2.csv) and created a data file to run the analyses on. But, when I do the analysis, R cannot recognize some of my columns (variables). My analysis is a multinational logit one.
The code for analysis is:
library(nnet)
mlogit<- multinom(groupadmit~mid_pop, tot_male10, tot_female10, male16,
tot_female16, agemean10, agemean16, IMD_score, IMD_score2, data =
admitqof10_16)
and the error is:
Error in model.frame.default(formula = groupadmit ~ mid_pop, data =
admitqof10_16, :
object 'male16' not found
I tried a couple of ways to solve the problem. For example, I use ls() to see whether the created data.table is in the R or not and it was there. I changed the name of the variable, but again it does not work. I exported the created data and imported it again. But, I have failed.
May someone please help me know why this problem happens and what I can do to resolve it?
Thanks in advance

fpgrowth error in R

I am trying to fit a fpgrowth model on a in-built data set called Adult. While fitting a model, I was getting an error as shown below.
Error in .jcall(jPruning, "[[Ljava/lang/String;", "fpgrowth", support, :
method fpgrowth with signature (DDI)[[Ljava/lang/String; not found
I used the below R code to fit fpgrowth model.
library(rCBA)
data("Adult")
Adult<-as(Adult,"transactions")
rules = rCBA::fpgrowth(Adult, support=0.001, confidence=0.5, maxLength=2)
What's wrong with the above code?
Thanks in advance.
you must specify your "class" or consequent
rules = rCBA::fpgrowth(Adult, support=0.001, confidence=0.5, maxLength=2, consequent="Species")
Try with This:
https://rdrr.io/cran/rCBA/src/R/fpgrowth.R

Where did the forecast.Holtwinters go in R 3.4.3?

I'm using R Studio based on R 3.4.3. However, when I tried to call the forecast.HoltWinters function, R told me that "could not find function "forecast.HoltWinters"". Inspect the installed package (v8.2) told me that it's true, there is no forecast.HoltWinters. But the manual in https://cran.r-project.org/web/packages/forecast/ clearly stated that forecast.HoltWinters is still available.
I have also tried stats::HoldWinters, but it's working wrong. The code run fine on another computer, but it couldn't run at all on mine. Is there any solution?
Here is the code. Book2.csv has enough data to last more than 3 periods.
dltt <- read.csv("book2.csv", header = TRUE)
dltt.ts <- ts(dltt$Total, frequency=12, start=c(2014,4))
dltt.ts.hw <- HoltWinters(dltt.ts)
library(forecast)
dltt.ts.hw.fc <- forecast.HoltWinters(dltt.ts.hw) //Error as soon as I run this line
Fit a HoltWinters model using the HoltWinters function and then use forecast. Its all in the help for HoltWinters and forecast, namely "The function invokes particular _methods_ which depend on the class of the first argument". I'll copy the guts of it here:
m <- HoltWinters(co2)
forecast(m)
Note this will call the non-exported forecast.HoltWinters function, which you should never call directly using triple-colon notation as some may suggest.

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".

problems with multiDiv in paleotree package

I am trying to use the package paleotree to build LTT plots, but I get the following error when I try to input my trees.
a=read.tree(file.choose()) # to choose newick/nexus file
multiDiv(a)
Error in multiDiv(a) : Data of Unknown Type
Does paleotools only take objects of class 'multiphylo' ? I converted the imput tree to class multiphylo, but it still gives the same error. Can anyone suggest how to go about it?
I'm the author of package paleotree. I think what is going on here is that you are passing a single tree to multiDiv, which is setup for analyzing lists of objects, each of which are converted to a diversity curve. You probably want phyloDiv() instead. I can't be certain without know more about your data.

Resources