Calibration plot error - Non-Numeric argument to binary operator - r

I am unable to produce a calibration plot for my logistic classification model, and I am unsure of why I am getting this error / how to fix it.
For the purposes of reproducibility, here is a made up example:
library(tidyverse)
library(classifierplots)
test.df <- as_tibble(data_frame(y = factor(c(0,0,0,0,1,1,0,1,0,1)),pred = c(0.1,0.15,0.2,0.05,0.6,0.7,0.2,0.85,0.1,0.75)))
calibration_plot(test.y = test.df$y,pred.prob = test.df$pred)
When I run this, I get the following error:
Error in alpha * 255 : non-numeric argument to binary operator
Similarly, when I run the code with my actual model, I receive the same error. Any ideas?

Related

Error message when using psych::ICC: argument is of length zero

I would like to compute the ICC for a regression model (done using lmer function), but I always get this error message:
Error in if (n.obs < n.obs.original) message("Warning, missing data were found for ", :
argument is of length zero
Here is the function I used:
ICC(model1, missing = TRUE, alpha = .05,lmer = TRUE,check.keys = FALSE)
What I don't understand is that the ICC function should be able to handle missing values. This is why I have used the package "psych and not the package irr`...
Thank you very much for your help :)

How do I solve an error in x : non-conformable arguments (R)?

I am trying to implement ordinal logistic regression on my dataset in r. I use the function 'polr' for this, but cannot seem to find a lot of information regarding its implementation.
The following errors are the ones I'm stuck on:
> dat.polr <- polr(as.factor(relevance)~allterms+idf.title, data=dat.one)
Warning message:
In polr(as.factor(relevance) ~ allterms + idf.title + idf.desc + :
design appears to be rank-deficient, so dropping some coefs
> dat.pred <- predict(dat.polr,dat.test,type="class")
Error in X %*% object$coefficients : non-conformable arguments
I want to train my model to guess the relevance of a new dataset. dat.one is the dataset I'm using to train the data, dat.test is the dataset I'm using to test the data. I believe that the predict variable's error is caused by the warning in polr. However, I have no clue how to resolve this. Any help would be appreciated :)

Error for predict() with lmer

I'm using a leave-one-out method to evaluate how well a model with one datapoint excluded predicts that datapoint (rotating through all datapoints). The code below has successfully run on essentially the same data with a slightly different DV, so I'm stumped as to why I'm getting the error that I'm getting. Here's the relevant chunk of code:
dataPennTrim.lmer <- lmer(logDur.PENN~cNewNounDen*ContextCode+
Vowel.Contrasts+BlockCode+
(1|subject)+(0+ cNewNounDen +ContextCode|subject)+
(1|word)+(0+ContextCode|word),
data=pennTrim,
control = lmerControl(optimizer = "bobyqa"),REML=FALSE)
pennPred <- predict(dataPennTrim.lmer, newdata = dataFull2)
dataFull2 has the same columns as pennTrim, it just has more rows. Pretty standard use of the predict() function. I get this error:
Error in t(.Call(Csparse_dense_crossprod, y, x)) :
error in evaluating the argument 'x' in selecting a
method for function 't': Error: Cholmod error 'X and/or Y
have wrong dimensions' at file ../MatrixOps/cholmod_sdmult.c, line 90
Any thoughts about what might be causing this error? I can use essentially the same code with the same dataframes swapping out logDur.PENN for logDur.Manual (measurements from a different source) and the code gives no errors.

R segmented regression predict gives error: "subscript out of bounds"

I'm building a segmented regression model using R's Segmented package.
I was able to create the model but have trouble using the predict.segmented function. It always throws an error saying "subscript out of bounds"
This is the exact error message:
Error in newdata[[nameZ[i]]] : subscript out of bounds
Traceback just gives this:
1: predict.segmented(seg_model, xtest)
I created a simple case that gives the same error:
require(segmented)
x = c(1:90, 991:1000)
y = c((x[1:10]/2), (x[11:100]*2))
lm_model = lm(y~x)
seg_model = segmented(lm_model, seg.Z=~x, psi=list(x=NA),
control=seg.control(display=FALSE, K=1, random=TRUE))
xtest = c(1:1000)
predict.segmented(seg_model, xtest)
I am starting to think this could be a bug. I'm new to R and not sure how to debug this either. Any help is appreciated!
You are using predict.segemented incorrectly. Like nearly all the predict() functions, your newdata parameter should be a data.frame, not a vector. Also, it needs to have names that match the variables used in your regression. Try
predict.segmented(seg_model, data.frame(x=xtest))
instead. When using a function for the first time, be sure the read the help page (?predict.segmented) to know what the function expects for each of the parameters.

Why is this error message coming up?

When I run a regression on a data set:
ord_reg<- clm(as.factor(Resp)~log10(Dose), data=dataframe, link="probit")
I get the following error message:
Error in qr.default(X, tol = tol, LAPACK = FALSE) :
NA/NaN/Inf in foreign function call (arg 1)
What is the reason for this? Note that the titles of the data set being called in the regression are the same as that of the data set (i.e. "Dose" and "Resp").
Look at summary(dataframe), as well as summary(log10(dataframe$Dose)).
You may see some NA/NaN reported, possibly because of negative values being given to log10().

Resources