3.1思维导图
3.2代码实现
- 书上都有,关注经典的例子(导图上),体会R的操作;
- 后面有时间再补,感觉技术含量不高;
- 方法的思想更重要;但是实际应用会有更便捷的生成方法;
###ch3
###3.1
?runif()
matrix(runif(3*4),3,4)
sample()
rbinom(10,4,0.4)
pnorm(0.5,0,1)
pnorm(0,0,1)
dnorm(0,0,1)
qnorm
dnorm
##3.2
#逆变换方法(连续+离散
###3.3
###3.4
?qbeta()
?qqplot
n <- 1000
a <- 3
b <- 2
u <- rgamma(n, shape=a, rate=1)
v <- rgamma(n, shape=b, rate=1)
x <- u / (u + v)
q <- qbeta(ppoints(n), a, b)
qqplot(q, x, cex=0.25, xlab="Beta(3, 2)", ylab="Sample")
abline(0, 1)
###3.6
n <- 1000
nu <- 2
X <- matrix(rnorm(n*nu), n, nu)^2 #matrix of sq. normals
#sum the squared normals across each row: method 1
y <- rowSums(X)
#method 2
y <- apply(X, MARGIN=1, FUN=sum) #a vector length n
n <- 5000
k <- sample(1:5, size=n, replace=TRUE, prob=(1:5)/15)
rate <- 1/k
x <- rgamma(n, shape=3, rate=rate)
#plot the density of the mixture
#with the densities of the components
plot(density(x), xlim=c(0,40), ylim=c(0,.3),
lwd=3, xlab="x", main="")
for (i in 1:5)
lines(density(rgamma(n, 3, 1/i)))
3.3 本章的用途
个人能力,还未联想到更加宏观的用途;后面完善;