renewalCount() function in countr package in R - r

I am trying to use renewalCount() function in R to get the fitted model of Weibull Distribution. Here is my piece of code:
wei <- renewalCount(formula = packets ~ 1,
data = dfdata,
dist = "weibull", weiMethod = "series_acc",
computeHessian = FALSE,
control = renewal.control(trace = 0))
I am facing the following exception while running this:
error: Mat::init(): requested size is too large; suggest to enable ARMA_64BIT_WORD
Error in optimx.check(par, optcfg$ufn, optcfg$ugr, optcfg$uhess, lower, :
Cannot evaluate function at initial parameters
I am a newbie in the field of R programming and have tried solutions like importing optimx and RcppArmadillo library but it did not work. Is there a way to enable ARMA_64BIT_WORD in RStudio. Any help would be really appreciated. Thanks in advance!

Related

Unused argument error when building a Confusion Matrix in R

I am currently trying to run Logistic Regression model on my DF.
While I was creating a new modelframe with the actual and predicted values i get get the following error message.
Error
Error in confusionMatrix(as.factor(log_class), lgtest$Satisfaction, positive = "satisfied") :
unused argument (positive = "satisfied")
This is my model:
#### Logistic regression model
log_model = glm(Satisfaction~., data = lgtrain, family = "binomial")
summary(log_model)
log_preds = predict(log_model, lgtest[,1:22], type = "response")
head(log_preds)
log_class = array(c(99))
for (i in 1:length(log_preds)){
if(log_preds[i]>0.5){
log_class[i]="satisfied"}else{log_class[i]="neutral or dissatisfied"}}
### Creating a new modelframe containing the actual and predicted values.
log_result = data.frame(Actual = lgtest$Satisfaction, Prediction = log_class)
lgtest$Satisfaction = factor(lgtest$Satisfaction, c(1,0),labels=c("satisfied","neutral or dissatisfied"))
lgtest
confusionMatrix(log_class, log_preds, threshold = 0.5) ####this works
mr1 = confusionMatrix(as.factor(log_class),lgtest$Satisfaction, positive = "satisfied") ## this is the line that causes the error
I had same problem. I typed "?confusionMatrix" and take this output:
Help on topic 'confusionMatrix' was found in the following packages:
confusionMatrix
(in package InformationValue in library /home/beyza/R/x86_64-pc-linux-gnu-library/3.6)
Create a confusion matrix
(in package caret in library /home/beyza/R/x86_64-pc-linux-gnu-library/3.6)
Confusion Matrix
(in package ModelMetrics in library /home/beyza/R/x86_64-pc-linux-gnu-library/3.6)
As we can understand from here, since it is in more than one package, we need to specify which package we want to use.
So I typed code with "caret::confusionMatrix(...)" and it worked!
This is how we can write the code to get rid of argument error when building a confusion matrix in R
caret::confusionMatrix(
data = new_tree_predict$predicted,
reference = new_tree_predict$actual,
positive = "True"
)

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.

Not finding 'weightedMean' object for numFun using kNN in VIM package for R

I'm getting an error stating that the 'weightedMean' argument is not found for the 'numFun' parameter in the kNN imputation function within the VIM R package. I'm attempting to impute data in a fairly large dataset, and I want to use kNN with 5 neighbors using weighted means.
Here is my code:
df.imputed <- kNN(df, variable = c(...), dist_var = c(...), numFun = weightedMean, k = 5, weightDist = TRUE, trace = TRUE, imp_var = TRUE)
And the exact error is:
Error in args(numFun) : object 'weightedMean' not found
Based on the documentation (https://cran.r-project.org/web/packages/VIM/VIM.pdf page 29) it seems like this should work.
Try put this way numFun = weighted.mean,
at least worked for me

What does this error mean while running the ksvm of kernlab package in R

I am calling the ksvm method of the kernlab package in R using the following syntax
svmFit = ksvm(x=solTrainXtrans, y=solTrainYSVM, kernel="stringdot", kpar="automatic", C=1, epsilon=0.1)
The x parameter is a data.frame with feature values and the y parameter is a list with various values.
I get the following error while run the above line.
Error in do.call(kernel, kpar) : second argument must be a list
What is it trying to tell me here?
Try setting kpar = list(length = 4, lambda = 0.5)
Does it help?

R rms package error when using rcs()

Been looking into Harrell's rms package for R and I am getting an error whenever I try to use the spline function rcs() inside a formula. This happens with all datasets. Is there some R setting I am missing?
library(rms)
df = read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")
m = lrm(admit~ rcs(gre), df)
Error in rcspline.eval(x, nk = nknots, inclx = TRUE, pc = pc, fractied = fractied) :
unused argument (fractied = fractied)
What is "fractied"? I haven't been able to find a clear explanation.
I'm using Windows 7, R version 3.1.0, rms version 4.2.0

Resources