1
$\begingroup$

I have a data set that looks at a five-year timespan of peoples' lives and indicates if specific events have occurred (Divorce, Birth of Child, Health Shock, etc.).

# Sample data in R
n <- 100
set.seed(1337)
exampleFrame <- as.data.frame(cbind(1:n,replicate(7, sample(0:1,n, TRUE))))
colnames(exampleFrame) <- c('Person',paste(rep("Event",7),1:7, sep = ''))

First thing I did was simply show a correlation matrix.

cor(exampleFrame)

And it gives an idea of what items follow each other, so next I ran a logistic regression to see how events are likely to improve odds of occurring together.

glm(Event1 ~ . - Person,family = binomial(link = 'logit'), data = exampleFrame)

And this is interesting, but I feel like I'm missing something more compelling. Am I chasing a phantom? Does anyone know a better way to demonstrate which life events occur together in this five-year span?

$\endgroup$
1
$\begingroup$

It's just a simple idea but you could calculate the conditional probabilities of an event given another:

library(plyr)

condProbEvents <- function(d) {
  ldply(colnames(d), function(col1) {
    t(ldply(colnames(d), function(col2) {
      nrow(d[d[,col1] & d[,col2],]) / nrow(d[d[,col2],]) # p(col1|col2)
    }))
  })
}

This gives you values which are easy to interpret, e.g. for p(divorce|marriage): "X% of the people who had a marriage also had a divorce"

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.