# NOT RUN {
x <- rgamma(1000,2)
m <- c(mean(x),var(x))
g <- function(x,theta) { # from theoretical properties of gamma distr.
g1 <- theta[1] / theta[2]
g2 <- theta[1] / theta[2]^2
c(g1,g2)
}
# should output about 2 and 1
mm(m,g,x)
# }
# NOT RUN {
library(mfp)
data(bodyfat)
# model as a beta distribution
g <- function(x,theta) {
t1 <- theta[1]
t2 <- theta[2]
t12 <- t1 + t2
meanb <- t1 / t12
m1 <- meanb
m2 <- t1*t2 / (t12^2 * (t12+1))
c(m1,m2)
}
x <- bodyfat$brozek/100
m <- c(mean(x),var(x))
# about 4.65 and 19.89
mm(m,g,x)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab