When using the function boxCox in R I keep getting this error "Error in as.data.frame.default( - r

I have the correct package alr4 which contains cars so it shouldn't be a problem with the function itself
box <- lm(Distance~Speed, data = stop)
boxCox(box)
This is the error
Error in as.data.frame.default(data, optional = TRUE) : cannot coerce class ‘"function"’ to a data.frame
The lm function runs just fine on its own, and I have used it in other analysis just fine, so it isn't an issue there. I am mostly just confused about the error and how to fix it. If you have suggestions or know why it happens that would be appreciated! Thanks

Related

Warning message within R function seems to make the function not work?

Using the syuzhet package in R, the following works but returns a warning message:
object <- get_text_as_string("path/name.txt")
When I put this in a function, it returns the same warning error but does NOT change the value of object:
gen <- function(file){
object <- get_text_as_string(file)
}
gen("path/name.txt")
This is the warning message, if it matters:
Warning message:
In readLines(path_to_file) :
incomplete final line found on 'path/name.txt'
...but again, I get that from get_text_as_string() when used outside of the function, but it DOES change the value of object.
Anyone have any advice? There must be something I don't understand about functions?
(I've looked for similar questions/answers, if I've missed the right one I'd be happy to just be directed there.)

mtable in R: Error in UseMethod("getSummary") : no applicable method for 'getSummary' applied to an object of class "gmnl"

I ran five models using the "gmnl" package in R. I would like to summarize all the models in one table using "mtable". However, I saw the message error below.
"Error in UseMethod("getSummary") : no applicable method for 'getSummary' applied to an object of class "gmnl""
The code to get the table is:
tablemod1 <- mtable("HCONT"=model.1_hcont, "HCT"=model.1_hct, "HBR"=model.1_hbr, "HCTBR"=model.1_hctbr, "NH"=model.1_nh,
signif.symbols = c("***"=0.01, "**"=0.05, "*"=0.1),
summary.stats = c("N", "Log-likelihood", "AIC", "BIC"))
summary(tablemod1).
I wonder if anyone knows how to fix that issue or recommends other ways to get models
side-by-side in one table.
Thank you,
Arsene

How to fix lmer error: "Error in as(value, fieldClass, strict=FALSE) :"?

I'm getting a strange error when I run an lmer function in r.
I've tried changing the variable types (all of them are numeric or factor) and removing the NA before analysis, but nothing seems to work.
model_1 <- lmer(Q14 ~ gender * time + (1|OMID), data=data)
summary(model_1)
Specifically, my error message reads:
Error in as(value, fieldClass, strict = FALSE) :
internal problem in as(): “labelled” is(object, "numeric") is TRUE, but the metadata asserts that the 'is' relation is FALSE
Not sure why this is happening, but I can't seem to find any answers for it. Any help would be appreciated.
Thanks!
I think lmer has a problem with 'labelled' data. If you un-label the predictors it should work fine.
I had the same error: the code for the lme-formula worked perfectly fine and one day I encountered that error. The solution in my case was simply to restart the R session, reload the data - in my case from SPSS via library("haven")::read.sps and after that load library("lme4") and execute the lme-formula.
So, if the formula worked before without any error, maybe just clean the project environment and re-run the most crucial code without any additional packages loaded. Maybe it's just some "cross-contamination" between packages or an unwanted effect of any package on the dataframe.

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.

SparkR distinct (on databricks)

I am new to SparkR, so please forgive if my question is very basic.
I work on databricks and try to get all unique dates of a column of a SparkDataFrame.
When I run:
uniquedays <- SparkR::distinct(df$datadate)
I get the error message:
unable to find an inherited method for function ‘distinct’ for signature ‘"Column"’
On Stack Overflow, I found out that this usually means
(If I run isS4(df), it returns TRUE):
That is the type of message you will get when attempting to apply an S4 generic function to an object of a class for which no defined S4 method exists
I also tried to run
uniquedays <- SparkR::unique(df$datadate)
where I get the error message:
unique() applies only to vectors
It feels like, I am missing something basic here.
Thank you for your help!
Try this:
library(magrittr)
uniquedays <- SparkR::select(df, df$datadate) %>% SparkR::distinct()

Resources