Created
September 4, 2017 17:32
-
-
Save peterdalle/7bce0bbebc13c36180fbbac1353a5353 to your computer and use it in GitHub Desktop.
Calculate 95 % CI from ICC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code by Ashe: https://stats.stackexchange.com/questions/184767/how-do-i-calculate-the-confidence-interval-of-an-icc | |
#Make some mocked data | |
library(lme4) | |
library(reshape2) | |
set.seed(2024) #For the Bell Riots | |
id <- factor(seq(1, 15)) | |
id.mu <- rnorm(15, 10, 5) | |
mydat <- NULL | |
for (a in 1:length(id)){ | |
score <- rnorm(2, id.mu[a], 3) | |
id.fr <- data.frame(id=id[a], score1=score[1], score2=score[2]) | |
mydat <- rbind(mydat, id.fr) | |
} | |
mydat <- melt(mydat, id.vars='id', value.name='score') | |
#Create function to calculate ICC from fitted model | |
calc.icc <- function(y) { | |
sumy <- summary(y) | |
(sumy$varcor$id[1]) / (sumy$varcor$id[1] + sumy$sigma^2) | |
} | |
#Fit the random effects model and calculate the ICC | |
mymod <- lmer(score ~ 1 + (1|id), data=mydat) | |
summary(mymod) | |
calc.icc(mymod) | |
#Calculate the bootstrap distribution | |
boot.icc <- bootMer(mymod, calc.icc, nsim=1000) | |
#Draw from the bootstrap distribution the usual 95% upper and lower confidence limits | |
quantile(boot.icc$t, c(0.025, 0.975)) |
Hi Liz,
I realize I haven't calculated that thing in seven years and the code above doesn't work anymore. Check out the Stack Overflow link (https://stats.stackexchange.com/questions/184767/how-do-i-calculate-the-confidence-interval-of-an-icc) and try to post the issue there.
All the best,
Peter
No worries, thanks for the reply.
…On Wed, Mar 27, 2024 at 5:58 PM Peter M. Dahlgren ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Hi Liz,
I realize I haven't calculated that thing in seven years and the code
above doesn't work anymore. Check out the Stack Overflow link (
https://stats.stackexchange.com/questions/184767/how-do-i-calculate-the-confidence-interval-of-an-icc)
and try to post the issue there.
All the best,
Peter
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/peterdalle/7bce0bbebc13c36180fbbac1353a5353#gistcomment-5003254>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZ2Q2KULYM7FJDGJ4JGZYFDY2MCDVBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVA3TMNRRG4ZDSM5HORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I found your demo, but I'm having trouble getting it to work (the function, specifically) on my data. I need to calculate the 95%CI for ICC. This is how I'm calculating the ICC.
Empty model
library(lme4)
M0 <- glmer(outcome ~ ( 1 | pracid), data=master, family = "binomial")
summary(M0)
icc <- M0@theta[1]^2/ (M0@theta[1]^2 + (3.14159^2/3))
icc # Intraclass correlation coefficient.
Thanks a ton! It's been a challenge!
Liz