Advertisement
karstenw

Pnw example

Jul 10th, 2011
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. % Simpson's paradox
  2. % Your name
  3. % 2011-07-11
  4.  
  5. # Overview
  6.  
  7. In probability and statistics, Simpson's paradox (or the Yule-Simpson effect) is a paradox
  8. in which a correlation present in different groups is reversed when the groups are
  9. combined. This result is often encountered in social-science and medical-science statistics,
  10. and it occurs when frequency data are hastily given causal interpretations.
  11. Simpson's Paradox disappears when causal relations are brought into consideration
  12. (see Implications to decision making).
  13.  
  14. # Example
  15.  
  16. Simpson's paradox for continuous data: a positive trend appears for two
  17. separate groups (blue and red), a negative trend (black, dashed) appears when the data are combined.
  18.  
  19. <<plot, fig=TRUE>>=
  20. x1 <- c(1,2,3,4)
  21. y1 <- x1 + 5
  22.  
  23. x2 <- x1 + 7
  24. y2 <- x2 - 7
  25.  
  26. x <- c(x1,x2)
  27. y <- c(y1,y2)
  28.  
  29. par(las=1)
  30. par(mar=c(3,3,0.5,0.5))
  31. par(mgp=c(2,1,0))
  32.  
  33. plot(x,y, cex=2, pch=21,
  34. col=rep(c("blue", "red"), each=4), bg=rep(c("lightblue", "pink"), each=4),
  35. xlim=range(x)+c(-2,2), ylim=range(y)+c(-2,2))
  36. abline(lm(y1 ~ x1), col="blue", lwd=2)
  37. abline(lm(y2 ~ x2), col="red", lwd=2)
  38. abline(lm(y ~ x), lwd=2, lty=2)
  39. @
  40.  
  41. # References
  42.  
  43. The text is composed from parts of [Wikipedia](http://en.wikipedia.org/wiki/Simpson's_paradox).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement