## gamma-3.R
## PJ Feb 14, 2002 / 2014-08-07
## This is a template showing how to explore the impact
## of changes in the gamma parameters, scale and shape
## Run this a few times, changing the value of sc at
## the top
sc <- 1
sampleSize <- 500
op <- par(no.readonly = TRUE)
SAVEME <- FALSE
if (SAVEME) pdf(file = "distributions-gamma-03-1.pdf", width = 8.5,
height = 10, onefile = FALSE, family = "Times", paper = "special")
par(mfrow = c(5,2))
createDist <-function(i){
sh <- 0.5 + 0.5*(i-1)
z <- rgamma(sampleSize,shape=sh,scale=sc)
title <- paste("Histogram gamma shape=",sh," scale=",sc)
hist(z,breaks=10,main=title)
}
lapply(1:10,createDist)
## [[1]]
## $breaks
## [1] 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
##
## $counts
## [1] 348 71 37 17 10 10 5 1 0 1
##
## $density
## [1] 1.392 0.284 0.148 0.068 0.040 0.040 0.020 0.004 0.000 0.004
##
## $mids
## [1] 0.25 0.75 1.25 1.75 2.25 2.75 3.25 3.75 4.25 4.75
##
## $xname
## [1] "z"
##
## $equidist
## [1] TRUE
##
## attr(,"class")
## [1] "histogram"
##
## [[2]]
## $breaks
## [1] 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0
##
## $counts
## [1] 203 123 58 42 34 18 7 9 1 1 2 1 0 1
##
## $density
## [1] 0.812 0.492 0.232 0.168 0.136 0.072 0.028 0.036 0.004 0.004 0.008
## [12] 0.004 0.000 0.004
##
## $mids
## [1] 0.25 0.75 1.25 1.75 2.25 2.75 3.25 3.75 4.25 4.75 5.25 5.75 6.25 6.75
##
## $xname
## [1] "z"
##
## $equidist
## [1] TRUE
##
## attr(,"class")
## [1] "histogram"
##
## [[3]]
## $breaks
## [1] 0 1 2 3 4 5 6 7 8 9 10
##
## $counts
## [1] 203 153 88 38 8 3 3 2 1 1
##
## $density
## [1] 0.406 0.306 0.176 0.076 0.016 0.006 0.006 0.004 0.002 0.002
##
## $mids
## [1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5
##
## $xname
## [1] "z"
##
## $equidist
## [1] TRUE
##
## attr(,"class")
## [1] "histogram"
##
## [[4]]
## $breaks
## [1] 0 1 2 3 4 5 6 7 8 9 10 11
##
## $counts
## [1] 137 150 98 56 34 12 8 3 0 1 1
##
## $density
## [1] 0.274 0.300 0.196 0.112 0.068 0.024 0.016 0.006 0.000 0.002 0.002
##
## $mids
## [1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5
##
## $xname
## [1] "z"
##
## $equidist
## [1] TRUE
##
## attr(,"class")
## [1] "histogram"
##
## [[5]]
## $breaks
## [1] 0 1 2 3 4 5 6 7 8 9 10 11
##
## $counts
## [1] 69 146 126 79 43 17 12 5 2 0 1
##
## $density
## [1] 0.138 0.292 0.252 0.158 0.086 0.034 0.024 0.010 0.004 0.000 0.002
##
## $mids
## [1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5
##
## $xname
## [1] "z"
##
## $equidist
## [1] TRUE
##
## attr(,"class")
## [1] "histogram"
##
## [[6]]
## $breaks
## [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13
##
## $counts
## [1] 35 129 136 89 43 39 13 8 5 2 0 0 1
##
## $density
## [1] 0.070 0.258 0.272 0.178 0.086 0.078 0.026 0.016 0.010 0.004 0.000
## [12] 0.000 0.002
##
## $mids
## [1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5
##
## $xname
## [1] "z"
##
## $equidist
## [1] TRUE
##
## attr(,"class")
## [1] "histogram"
##
## [[7]]
## $breaks
## [1] 0 1 2 3 4 5 6 7 8 9 10 11 12
##
## $counts
## [1] 22 94 107 94 79 55 31 8 3 4 1 2
##
## $density
## [1] 0.044 0.188 0.214 0.188 0.158 0.110 0.062 0.016 0.006 0.008 0.002
## [12] 0.004
##
## $mids
## [1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5
##
## $xname
## [1] "z"
##
## $equidist
## [1] TRUE
##
## attr(,"class")
## [1] "histogram"
##
## [[8]]
## $breaks
## [1] 0 1 2 3 4 5 6 7 8 9 10 11
##
## $counts
## [1] 10 62 105 119 81 46 35 20 10 7 5
##
## $density
## [1] 0.020 0.124 0.210 0.238 0.162 0.092 0.070 0.040 0.020 0.014 0.010
##
## $mids
## [1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5
##
## $xname
## [1] "z"
##
## $equidist
## [1] TRUE
##
## attr(,"class")
## [1] "histogram"
##
## [[9]]
## $breaks
## [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
##
## $counts
## [1] 4 42 103 109 87 63 27 29 16 9 5 5 0 0 1
##
## $density
## [1] 0.008 0.084 0.206 0.218 0.174 0.126 0.054 0.058 0.032 0.018 0.010
## [12] 0.010 0.000 0.000 0.002
##
## $mids
## [1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 13.5
## [15] 14.5
##
## $xname
## [1] "z"
##
## $equidist
## [1] TRUE
##
## attr(,"class")
## [1] "histogram"
##
## [[10]]
## $breaks
## [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
##
## $counts
## [1] 3 26 68 97 85 76 52 45 20 14 5 5 2 2
##
## $density
## [1] 0.006 0.052 0.136 0.194 0.170 0.152 0.104 0.090 0.040 0.028 0.010
## [12] 0.010 0.004 0.004
##
## $mids
## [1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 13.5
##
## $xname
## [1] "z"
##
## $equidist
## [1] TRUE
##
## attr(,"class")
## [1] "histogram"
if (SAVEME) dev.off()
par(op) ## resets par