0

I am fairly new to R (honestly, coding in general). I am having trouble figuring out the best way to apply the CCC (Lin's Concordance Correlation Coefficient) function from the DescTools package on my dataframe in Rstudio. I was able to get the global analysis to work, but I really need to be able to apply it to different groups within my dataset. I have 37 subjects that rated 80 leaves for percent disease coverage both with and without a guide. I also have the actual values of percent disease coverage for leaf that were obtained using a computational approach in situ. I need to be able to compare each individual rater (with and without the guide) to the actual values. I also need to compare each rater scores with and without the guide (interrater reliability).

The CCC function in DescTools is a multi-step function, and the results are stored as lists (some lists containing dataframes). The end goal would be to pull a portion of the results (i.e. s.shift, l.shift, C.b) from the lists and feed it into a new dataframe(s) for downstream analysis. Therefore, for each functional iteration over a subject, I will need to rename each result list.

Right now, my data is in wide format. I am not sure if that is the best approach, but it is what I have working for the first rater. PC = actual value, WOSAD.1 = rater 1 without the guide

#Lin's correlation coefficient per rater
WOSAD.1.ccc <- CCC(PC, WOSAD.1, ci = "z-transform", conf.level = 0.95)
WOSAD.1.mean <- mean(WOSAD.1.ccc$blalt$delta)
WOSAD.1.sd <- sqrt(var(WOSAD.1.ccc$blalt$delta))

lab <- paste("CCC: ", round(WOSAD.1.ccc$rho.c[,1], digits = 2), " (95% CI ", 
              round(WOSAD.1.ccc$rho.c[,2], digits = 2), " - ",
              round(WOSAD.1.ccc$rho.c[,3], digits = 2), ")", sep = "")
WOSAD.1.z <- lm(WOSAD.1 ~ PC)

How would I go about renaming each dataset as I move through each rater (i.e. WOSAD.1.ccc for the 1st rater, WOSAD.2.ccc for the 2nd rater, etc.)? I would assume I need to add in a for loop to iterate over each rater, but I am not sure if there is an easier way.

I have tried using lapply and played around with dplyr as a substitute for writing out the for loop. I have switched my data around from long format to wide format, and have only been able to get it to work in wide format where each rater is a separate column as opposed to 37 separate rows.

Phil
  • 7,287
  • 3
  • 36
  • 66

0 Answers0