Effective dose (ED) in the drc package - r

I'm using the drc package in R, and after calculating the model I try to use the function ED to get the effective dose at several levels (IC50, IC75, IC90...), however from time to time I get the following error message and I don't seem to find any information on how to solve it.
Error in EDlist(parmChosen, respLev[j], reference = reference, type = type, :
could not find function "EDhelper"
The package is properly installed and loaded, and after checking the documentation it seems EDhelper is indeed no function but rather something else required by the function which R doesn't seem to find anymore.
Sorry for the trouble but any help would be very much appreaciated!

I am unsure what the issue is, because I can't see your data. It may be that EDhelper has been discontinued. I am also working with Dose-Response curves in DRC, the following works for me:
mod1 <- drm(ratio ~ dose, weights = total, data = data_source1, type ="binomial", fct=LL.2())
ED(mod1, c(10, 20, 50, 90, 99), interval = "delta", reference = "control")
or perhaps
ED(mod1,50,interval="fls")

Related

omega function (Psych package R) not working with plot=TRUE

I have to first say that I am not an R user, but I want to apply a certain function I could only find in R.
My purpose is to get a bifactor factor-analysis model using the omega function from the Psych package. I have a data frame with 33 columns and about 100,000 observations and when I call the function (omega(df))
I get the following error:
Error in nchar(tv[1, 21]) : 'nchar()' requires a character vector
I have no idea what it means. If I follow the example in this doc with their data (named "bifact") it works fine, but the example uses a correlation matrix, while I want to use the entire data to be able to extract the factor scores. When I try to call the function with omega(cor(df))
I still get the same error.
Attached is a randomly generated data set that produces the same error.
Any help would be highly appreciated.
A clue to the solution could be the fact that with set.seed(0) I get a different error than with set.seed(100):
set.seed(100)
s_df = as.data.frame(cbind(matrix(seq_len(10000), ncol=1), matrix(rnorm(n=6*10000, mean = 20, sd = 10), ncol=6)))[2:7]
omega(s_df)
Error in nchar(tv[1, 21]) : 'nchar()' requires a character vector
while:
set.seed(0)
s_df = as.data.frame(cbind(matrix(seq_len(10000), ncol=1), matrix(rnorm(n=6*10000, mean = 20, sd = 10), ncol=6)))[2:7]
omega(s_df)
Error in omega.diagram(omega, main = title, sl = sl, labels = labels, :
object 'd.arrow' not found
EDIT: everything works when I call the function with plot=FALSE.
However, I still would like the plot to work. (plot=TRUE) throughs the unwanted error.
Ok, so it turns out I just didn't have the 'Rgraphviz' package installed.
After installing it everything worked great.

Plotting logistic model with package visreg doesn´t work Data not found

My second question of the day: I want to use the visreg package to plot my logistic regression models. As long as I don't use the attribute "by" it works like a charm, but when I want to use it I get an error. The code I used to create my model is the following:
m3<- glm(alive ~ seatbelt*dvcat + sex + ageOFocc + airbag, family = binomial, data = nassCDS, start=)
summary(m3)
If I then use:
visreg(m3, "seatbelt", scale = "response")
I get the following result
which is just fine. But if I now add the "by" attribute I get an error:
visreg(m3, "seatbelt", by="dvcat", scale ="response")
I googled and as far as I understood it the function can't find the data to plot the model. But where can I supply the data? I already tried the "data=" attribute, but it wasn´t working for me (or I did it wrong). There is no console output that I can provide only the message on the graph itself. Can somebody help me? Kind regards, Jan :)
EDIT: I used the "nassCDS" datasat from vincent arel-bundocks github which you can find here: https://vincentarelbundock.github.io/Rdatasets/datasets.html I just inserted the column alive via the column dead so that i am able to use the logistic regression. Therefore i used the dplyr package with the following code:
nassCDS <- nassCDS %>%
mutate(dead1 = as.integer(dead)) %>%
mutate(alive = sjmisc::rec(dead1, rec = "2=0; 1=1")) %>%
select(seatbelt, dead, alive, dvcat, sex, ageOFocc, everything()) %>%
select(-dead1)
Furthermore i changed the columns airbag and seatbelt to numeric as it was suggested by one other stackoverflow user.

Error in eval(parse()) - r unable to find argument input

I am very new to R, and this is my first time of encountering the eval() function. So I am trying to use the med and boot.med function from the following package: mma. I am using it to conduct mediation analysis. med and boot.med take in models such as linear models, and dataframes that specify mediators and predictors and then estimate the mediation effect of each mediator.
The author of the package gives the flexible option of specifying one's own custom.function. From the source code of med, it can be seen that the custom.function is passed to the eval(). So I tried insert the gbmt function as the custom function. However, R kept giving me error message: Error during wrapup: Number of trees to be used in prediction must be provided. I have been searching online for days and tried many ways of specifying the number of trees parameter n.trees, but nothing works (I believe others have raised similar issues: post 1, post 2).
The following codes are part of the source code of the med function:
cf1 = gsub("responseY", "y[,j]", custom.function[j])
cf1 = gsub("dataset123", "x2", cf1)
cf1 = gsub("weights123", "w", cf1)
full.model[[j]] <- eval(parse(text = cf1))
One custom function example the author gives in the package documentation is as follows:
temp1<-med(data=data.bin,n=2,custom.function = 'glm(responseY~.,data=dataset123,family="quasibinomial",
weights=weights123)')
Here the glm is the custom function. This example code works and you can replicate it easily (if you have mma installed and loaded). However when I am trying to use the gbmt function on a survival object, I got errors and here is what my code looks like:
temp1 <- med(data = data.surv,n=2,type = "link",
custom.function = 'gbmt(responseY ~.,
data = dataset123,
distribution = dist,
train_params = start_stop,
cv_folds=10,
keep_gbm_data = TRUE,
)')
Anyone has any idea how the argument about number of trees n.trees can be added somewhere in the above code?
Many thanks in advance!
Update: in order to replicate the example code, please install mma and try the following:
library("mma")
data("weight_behavior") ##binary x #binary y
x=weight_behavior[,c(2,4:14)]
pred=weight_behavior[,3]
y=weight_behavior[,15]
data.bin<-data.org(x,y,pred=pred,contmed=c(7:9,11:12),binmed=c(6,10), binref=c(1,1),catmed=5,catref=1,predref="M",alpha=0.4,alpha2=0.4)
temp1<-med(data=data.bin,n=2) #or use self-defined final function
temp1<-med(data=data.bin,n=2, custom.function = 'glm(responseY~.,data=dataset123,family="quasibinomial",
weights=weights123)')
I changed the custom.function to gbmt and used a survival object as responseY and the error occurs. When I use the gbmt function on my data outside the med function, there is no error.

Error when creating a biplot of stable isotope data using the package SIAR in R

I want to use the package 'SIAR' to create a biplot of d15N in function of d13C.
My data has the same format as found in the guideline
'http://sethnewsome.org/sethnewsome/EE_files/SIAR%20for%20Ecologists.pdf'.
The model however gives me an error.
Model = siarmcmcdirichletv4(DataSIConsumer, DataSISource, corrections = 0, concdep = 0, iterations = 500000, burnin = 50000)
Error in the sources file - check this is numeric.
Problems with inputs: siar has not been run.
I don't understand how to solve this problem. The first column of the source data is not a character and might thus cause the error, but the guideline describes this format of dataset.
How can I solve this error?

Stargazer error with polr in R

I obtain an error when using stargazer in conjunction with polr from the MASS package in R. Here is an example:
library(MASS)
library(stargazer)
# Fake data
set.seed(1234)
fake_data <- data.frame(y = as.factor(sample.int(4, 20, replace = TRUE)),
x1 = rnorm(20, mean = 1, sd = 1),
x2 = rnorm(20, mean = -1, sd = 1))
# Ordered logistic regression
o_log <- MASS::polr(y ~ x1 + x2,
data = fake_data,
Hess = TRUE, method = "logistic")
summary(o_log)
# Create regression table
stargazer(o_log)
I receive the following error message:
% Error: Unrecognized object type.
Does anyone know how to solve this? Thanks in advance.
P.S.: I'm on OS X 10.13, using R 3.4.3, MASS 7.3.47, and stargazer 5.2.
EDIT: According to stargazer's vignette, objects from polr should be supported.
I don't know the reason but when I change MASS::polr into plor, the error is removed and it works fine. It seems that it is a bug of package stargazer.
I encountered the same problem. For some strange reason, this only happens when you call the function using :: (in your case: MASS::polr). It doesn't happen when you first load the package via library(MASS) and then call the specific function.
See: Why do I get different results when using library(MASS) vs. MASS::?
I guess it was because you didn't load the MASS library and instead called the function using ::. MASS library doing some updates on how summary works for polr, which is being used by stargazer to generate the table. By not loading the library, the update was not happened, hence bringing you some trouble with stargazer.

Resources