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 :)
Related
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?
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"
)
I'm trying to replicate the results from An Introduction to Statistical Learning with Applications in R. Specifically, the Lab in section 6.5.3. I have followed the code in the lab exactly:
library("ISLR")
library("leaps")
set.seed(1)
train = sample(c(TRUE, FALSE), nrow(Hitters), rep = TRUE)
test = (!train)
regfit.best = regsubsets(Salary ~., data = Hitters[train,], nvmax= 19)
test.mat = model.matrix(Salary~., data = Hitters[test,])
val.errors = rep(NA, 19)
for (i in 1:19){
coefi= coef(regfit.best, id = i)
pred=test.mat[,names(coefi)]%*%coefi
val.errors[i]=mean((Hitters$Salary[test]-pred)^2)
}
When I run this I still get the following error:
Warning message:
In Hitters$Salary[test] - pred :
longer object length is not a multiple of shorter object length
Error in mean((Hitters$Salary[test] - pred)^2) :
error in evaluating the argument 'x' in selecting a method for function 'mean': Error: dims [product 121] do not match the length of object [148]
And val.errors is a vector of 19 NAs.
I'm still relatively new to R and to the validation approach, so I'm not sure exactly why the dimensions of these are different.
It was actually an issue with not carrying over steps from the previous subsection, which omitted entries that were incomplete.
You need to remove rows with missing data. Run "Hitters = na.omit(Hitters)" at the beginning.
Reproducable example which will give the mentioned error code every time is:
(Note that even without set.seed, the error comes up every time)
library(MASS)
set.seed(seed = 1)
data<-rnorm(n = 10000,mean = 0.0002,sd = 0.001)
fitdistr(x = data,densfun = "t")
The error message is:
Error in stats::optim(x = c(-0.000426453810742332, 0.000383643324222082, :
non-finite finite-difference value [2]
In addition: Warning message:
In log(s) : NaNs produced
The problem is the "non-finite finite-difference value". Fitdistr does not give me a result.
My knowledge:
I researched and apparently this could mean that a parameter is negative during the iteration. And that the solution could be to provide a better or at least different starting value. But I could not figure out how to do this and I am not sure if this is the issue.
MY QUESTION:
a) Why do I get this error message
and
b)how can I fix it in R, so that I can fit the student-t distribution to my normally distributed data?
I am trying to run a stepwise regression model. I keep receiving this message:
#Error in step(cdc.fit, direction = "backward") :
# number of rows in use has changed: remove missing values?
#In addition: There were 50 or more warnings (use warnings() to see the first 50)
Am I receiving this because of missing values?
Here is my code:
model=glm(health~
ALCDAY5+
AVEDRNK2+
CHILDREN+
CHKHEMO3+
POORHLTH+
BLOODCHOYes+
BPHIGH4No+
CHCOCNCRYes
, data=data, fmaily=binomial)
stepmodel_back <- model(cdc.fit,direction='backward')
summary(stepmodel_back)
Thanks!
I've not used the stepAIC() function in MASS, but it looks like the following line is incorrect:
stepmodel_back <- step(cdc.fit, direction = "backward")
You've assigned your glm model to an object called 'model', but this line doesn't reference this object. Should it be:
stepmodel_back <- step(model, direction = "backward)
?
Hope this helps.