irr: Krippendorf's Alpha with non-numeric classifications (Warning Message) - r

I am trying to calculate Krippendorf's Alpha using the irr::kripp.alpha function.
My input data consists of non-numeric classifications (e.g., "1.a", "1.b" etc.). When using kripp.alpha() I get the following warning message
Warning message:
In kripp.alpha(as.matrix(p8)) : NAs introduced by coercion
It seems that the function -- nevertheless -- works fine.
Anyhow, I tried to get rid of the warning message by using the following procedure:
input <- data.frame(coder1=c("3.a","3.a","3.b.ii","3.b.ii","3.a","3.a","4.d","4.d"),
coder2=c("3.b","3.a","3.b.i","3.b.ii","3.a","3.a","4.d","4.d"))
# Gives the Warning Message
kripp.alpha(as.matrix(t(input)))
input <- unlist(input)
#Replace levels (strings) with unique numeric values
levels(input) <- 1:length(levels(input))
#Transform back into matrix format that kripp.alpha uses
input <- matrix(input, nrow=2)
kripp.alpha(input)
This works fine. However, it is quite cumbersome for such an easy task. Is there a simpler method? Can somebody explain why the function gives the warning message when using non-numeric classification values?

I just had contact with the package maintainer. The kripp.alpha() function expects numeric classifications as input. They may fix it in one of the next package updates.
So either you live with that warning message or you use the solution posted above.

Related

SuperLearner Error in R - Object 'All' not found

I am trying to fit a model with the SuperLearner package. However, I can't even get past the stage of playing with the package to get comfortable with it....
I use the following code:
superlearner<-SuperLearner::SuperLearner(Y=y, X=as.data.frame(data_train[1:30]), family =binomial(), SL.library = list("SL.glmnet"), obsWeights = weights)
y is a numeric vector of the same length as my dataframe "data_train", containing the correct labels with 9 different classes. The dataframe "data_train" contains 30 columns with numeric data.
When i run this, i get the Error:
Error in get(library$screenAlgorithm[s], envir = env) :
Objekt 'All' not found
I don't really know what the problem could be and i can't really wrap my head around the source code. Please note that the variable obsWeights in the function contains a numeric vector of the same length as my data with weights i calculated for the model. This shouldn't be the problem, as it doesn't work either way.
Unfortunately i can't really share my data on here, but maybe someone had this error before...
Thanks!
this seems to happen if you do not attach SuperLearner, you can fix via library(SuperLearner)

Issue with LCMM Plot Code (invalid subscript type 'list')

I'm attempting to follow a tutorial (link here: https://www.r-bloggers.com/latent-class-mixed-models-with-graphics/) for running a latent class mixture model. My model has run properly, but i'm having an issue plotting the latent classes.
Con2 < lcmm(ConT~AdminCount,random=~AdminCount,subject='PID',mixture=~AdminCount,ng=3,idiag=TRUE,data=datal,link="linear")
summary(Con2)
datal$CONid <- as.character(datal$PID)
people3 <- as.data.frame(Con2$pprob[1:2])
datal$CONgroup <- character(people3$class[sapply(datal$CONid, function(x) which(people3$CONid==x))])
When I try to run the last line of code, I get this error:
Error in people3$class[sapply(datal$CONid, function(x)
which(people3$CONid == : invalid subscript type 'list'
Any ideas what this error means/how I can address it?
Pictures here of all my code and output:
info about variables being used in model
Probability values from model
Model Summary
Graph Code and Error
We still can't recreate your error; I did find the original tutorial posting though as well as the full R code and the data.
So I need to guess your error. Note that the error statement is that the "subscript is a list". The subscript is the function call sapply(datal$CONid, function(x) which(people3$CONid==x). In the default setting, the sapply-function will return a list, if the return values of the function are of irregular length (otherwise a vector or a matrix). That is, the elements of datal$CONid occur with irregular frequency among the entries of people3$CONid.
Hope you can work from here on.

how to use scale and dist with a dataset with column name

Trying to scale a dataset with 9 variables to be prepared for clustering. My data has headers (column names). It keeps giving me this response.
I have already excluded the rownames in the dataset
Warning message:
In dist(DF, method = "euclidean") : NAs introduced by coercion
View(DF)
Error in View : cannot coerce class ""dist"" to a data.frame
First of a comment to your question-style: add a snippet of data and take more time explaining the problem, and what you have tried already!
The error NAs introduced by coercion normally occurs, when conversion between datatypes failed (as the name suggests). Check your column for non-numeric elements (are letters included somewhere? Wrong Decimals?).
This great blog explains nicely where and why the problems occur and how to fix it! http://r-bio.github.io/02-data-frames/.

ImpulseDE2, matrix counts contains non-integer elements

Possibly it's a stupid question (but be patient, I'm a beginner in R's word)... I'm working with ImpulseDE2, a package designed to RNAseq data analysis along different times (see article for more information).
The running function (runImpulseDE2) requires a matrix counts and a annotation data frame. I've created both but it appears this error message:
Error in checkCounts(matCountData, "matCountData"): ERROR: matCountData contains non-integer elements. Requires count data.
I have tried some solutions and nothing seems to work (and I've not found any solution in the Internet)...
as.matrix(data)
(data + 1) > and there isn't NAs nor zero values that originate this error ($ which(is.na(data)) and $ which(data < 1), but both results are integer(0))
as.numeric(data) > and appears another error: ERROR: [Rownames of matCountData] was not given as input.
I think that's something I'm not realizing, but I'm totally locked. Every tip will be welcome!
And here is the (silly) solution! This function seems not to accept float numbers... so applying a simple round is enough to solve this error.
Thanks for your help!

How to use as.numeric(levels(f)[f])

I was attempting an assignment and hit a problem with the dataset. As per the questions, we have to take the Duration, Amount, and Installment columns for analysis. I tried to normalize the data for these columns using scale() command, taking them into a seperate data frame. But, I get an error saying:
Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric
I explored further to find that the dataset may not be purely numeric, although at the sight of it, it seems that all three columns are numeric. I used the is.numeric() command and got the result:
is.numeric(new_dataset)
[1] FALSE
Having gone this far, now I am stuck at how to convert the non-numeric data into numeric type, without having to replace all the values manually. I found some stuff on "as.numeric(levels(f)[f])", but wasn't able to understand how to apply it. I am getting error:
new_dataset_num<-as.numeric(levels(new_dataset[,1:3]))[new_dataset[,1:3]]
Error in as.numeric(levels(new_dataset[, 1:3]))[new_dataset[, 1:3]] :
invalid subscript type 'list'
Can you please help out with this?

Resources