Skip to content

Instantly share code, notes, and snippets.

View matthewwolak's full-sized avatar

Matthew matthewwolak

View GitHub Profile
@matthewwolak
matthewwolak / ICCnegativeVariance.Rmd
Created July 6, 2016 21:55
How can a ratio of variances (e.g., repeatability or heritability) be zero when variances cannot be negative?
Although maybe troubling at first, negative repeatability (ICC) estimates may be "okay" in the sense that nothing is wrong with the model - it is just the model accurately reflecting different levels of variation in the data. Suppose a dataset contains repeated measures from several different groups (substitute 'individual' for 'group' here and below if you are more comfortable thinking about measures conducted repeatedly on individuals). A negative ICC is due to a negative estimate of the among group variance. Negative variances are possible to calculate when you use an ANOVA to obtain the variance components.
## ANOVA can give negative variance component estimates
The functions in the R package `ICC` estimate variance components using least squares (really just a one-way ANOVA). In a balanced design, the variance between groups is calculated within `ICC` as:
```
(mean squares among groups - mean squares within groups) / sample size per group
```
@matthewwolak
matthewwolak / ICCbareSpeed_noProfiles.md
Last active August 29, 2015 14:24
ICCbare benchmarks: v2.2.1 versus 2.3.0

ICCbare Speed Benchmarks

Introduction

Below compares the performance of the R function ICC::ICCbare between the current and the previous package versions. The main change between v2.2.1 and 2.3.0 was to greatly improve the non-standard evaluation of all functions in the ICC package. I try and get at how this might affect the time it takes to run ICC::ICCbare in the code below. First, I load the two versions of the function (cut and pasted from the package tarballs) as well as the two versions of ICC::ICCest (which is the main ICC calculation function) for comparison. Then I use the R package microbenchmark to time the various functions. I then strip the ICCbare functions down to what was changed between versions (the interpretation of the function arguments and set up) to hone in on any changes to the speed that may have arisen from the changes.

Create functions

First, create a function to make a data.frame with variables and data

@matthewwolak
matthewwolak / ICCnonStandEval.md
Last active August 29, 2015 14:23
ICC non-standard evaluation

ICC non-standard evaluation examples

The ICC package for R calculates the intraclass correlation coefficient (ICC) from a one-way analysis of variance. Recently, the package was updated to better execute R's non-standard evaluation within each function (version 2.3.0 and higher). The package functions should now be able to handle a range of possible scenarios for calling the functions in, what I hope, is a less grotesque and more standard way of writing R functions. To demonstrate, below are some of those scenarios. Note, the examples use the ICCbare function, but the way in which the function arguments are supplied will apply to all of the functions in ICC.

First, load the package (and make sure the version is >2.3.0)

library(ICC)
packageVersion("ICC")