Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
Created July 18, 2019 13:53
Show Gist options
  • Save explodecomputer/d235511367c752df505f6e8d1a71321d to your computer and use it in GitHub Desktop.
Save explodecomputer/d235511367c752df505f6e8d1a71321d to your computer and use it in GitHub Desktop.
Infant weight and later height
library(ggplot2)
library(tidyr)
library(alspac)
data(current)
vars <- c("cf040", "cf041", "cf042", "cf043", "fh3000")
b <- extractVars(subset(current, name %in% vars))
b1 <- subset(b, select=c("aln", "qlet", vars)) %>% filter(!apply(., 1, function(x) any(is.na(x))))
for(i in vars)
{
b1[[i]][b1[[i]] < 2] <- NA
}
c1 <- gather(b1, "key", "value", cf040, cf041, cf042, cf043, fh3000)
c2 <- group_by(c1, key) %>%
mutate(rank=rank(value))
c2$key2 <- as.numeric(as.factor(c2$key))
ggplot(c2, aes(x=key2, y=rank, group=paste(aln, qlet))) +
geom_point() +
geom_line(alpha=0.2) +
theme_void()
mod <- lm(fh3000 ~ cf040 + cf041+cf042+cf043, b1)
summary(mod)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment