Difference between revisions of "Beta distributions"
m (→Symmetry of α Β) |
m |
||
(24 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | + | For details on the beta distribution see [[WikiPedia:Beta distribution]]. The parameters p, and q | |
− | For details on the beta distribution see [[WikiPedia:Beta distribution]]. | + | are α & β in the Wikipedia article formula. The x axis range is from 0 to 1, the range for probabilities |
− | |||
Beta distributions have many [http://en.wikipedia.org/wiki/Beta_distribution#Shapes shapes] depending on the parameters. Their flexibility makes them useful for modelling | Beta distributions have many [http://en.wikipedia.org/wiki/Beta_distribution#Shapes shapes] depending on the parameters. Their flexibility makes them useful for modelling | ||
− | uniform distributions & | + | uniform distributions β(1,1) right through to symmetric or skewed distributions, or even U shaped distributions. |
− | ==R programming language== | + | == R programming language == |
For help on functions which create/manipulate beta distributions see; | For help on functions which create/manipulate beta distributions see; | ||
− | < | + | <R> |
− | ?beta # or help(beta) | + | ?beta # or help(beta) |
− | ?rbeta # or help(rbeta) | + | ?rbeta # or help(rbeta) |
− | </ | + | </R> |
Usage examples are provided at; | Usage examples are provided at; | ||
− | < | + | <R> |
example(beta) | example(beta) | ||
example(rbeta) | example(rbeta) | ||
Line 19: | Line 18: | ||
example(pbeta) | example(pbeta) | ||
example(qbeta) | example(qbeta) | ||
− | </ | + | </R> |
− | + | == R code example 1 == | |
− | < | + | |
+ | Let's generate a beta distribution using the ''rbeta'' built in R function. | ||
+ | <R> | ||
quartz() | quartz() | ||
# Alter the parameters | # Alter the parameters | ||
Line 31: | Line 32: | ||
x <- rbeta(n, shape1= p, shape2=q) | x <- rbeta(n, shape1= p, shape2=q) | ||
breaks <- seq(0,1, length=21) | breaks <- seq(0,1, length=21) | ||
− | hist(x, breaks=breaks, freq=FALSE) | + | hist(x, breaks=breaks, freq=FALSE, main=paste("p=",p, ", q=", q, sep="")) lines(density(x, adjust=0.4), col="red") |
− | + | </R> | |
− | </ | + | Notice α and β are less than one, so the plot is U shaped, as described in [[Wikipedia:Beta distribution#Shapes|Wikipedia:Beta distribution#Shapes]]. |
− | ==Symmetry of α Β== | + | == Symmetry of α Β == |
+ | ==R code example 2== | ||
+ | <R> | ||
quartz() | quartz() | ||
# Alter the parameters | # Alter the parameters | ||
− | n <- | + | n <- 10000 # Number of observations |
for(i in 1:50) { | for(i in 1:50) { | ||
p <- q <- i | p <- q <- i | ||
Line 45: | Line 48: | ||
hist(x, breaks=breaks, freq=FALSE, main=paste("p=",p, ", q=", q, sep="")) | hist(x, breaks=breaks, freq=FALSE, main=paste("p=",p, ", q=", q, sep="")) | ||
lines(density(x, adjust=0.4), col="red") | lines(density(x, adjust=0.4), col="red") | ||
+ | Sys.sleep(1) | ||
} | } | ||
+ | </R>> | ||
− | ==See also== | + | == See also == |
[[BetaDistributions.R]] | [[BetaDistributions.R]] | ||
− | |||
[[Category:R]] | [[Category:R]] |
Latest revision as of 20:04, 11 December 2010
For details on the beta distribution see WikiPedia:Beta distribution. The parameters p, and q are α & β in the Wikipedia article formula. The x axis range is from 0 to 1, the range for probabilities
Beta distributions have many shapes depending on the parameters. Their flexibility makes them useful for modelling uniform distributions β(1,1) right through to symmetric or skewed distributions, or even U shaped distributions.
Contents
R programming language
For help on functions which create/manipulate beta distributions see; <R>
?beta # or help(beta) ?rbeta # or help(rbeta)
</R> Usage examples are provided at; <R>
example(beta) example(rbeta) example(dbeta) example(pbeta) example(qbeta)
</R>
R code example 1
Let's generate a beta distribution using the rbeta built in R function. <R>
quartz() # Alter the parameters n <- 1000 # Number of observations p <- 0.1 q <- 0.1
x <- rbeta(n, shape1= p, shape2=q) breaks <- seq(0,1, length=21) hist(x, breaks=breaks, freq=FALSE, main=paste("p=",p, ", q=", q, sep="")) lines(density(x, adjust=0.4), col="red")
</R> Notice α and β are less than one, so the plot is U shaped, as described in Wikipedia:Beta distribution#Shapes.
Symmetry of α Β
R code example 2
<R>
quartz() # Alter the parameters n <- 10000 # Number of observations for(i in 1:50) { p <- q <- i x <- rbeta(n, shape1= p, shape2=q) breaks <- seq(0,1, length=21) hist(x, breaks=breaks, freq=FALSE, main=paste("p=",p, ", q=", q, sep="")) lines(density(x, adjust=0.4), col="red") Sys.sleep(1) }
</R>>