分散・平均・正規分布の検討

$ R


cilia <- rnorm(50)

range(cilia)
max(cilia)
min(cilia)

meancilia1 <- sum(cilia)/length(cilia)
meancilia2 <- mean(cilia)
median(cilia)




png("110317.figure1.png")
plot(cilia)
lines(c(1,20),c(min(cilia),min(cilia)),lty = 2)
lines(c(1,20),c(max(cilia),max(cilia)),lty = 2)
lines(c(10,10), c(min(cilia),max(cilia)))
text(10,max(cilia)-1,"Range = min(cilia) to max(cilia)")
dev.off()


png("110317.figure2.png")
plot(cilia)
abline(h= mean(cilia))
for(i in 1:length(cilia)){lines(c(i,i),c(mean(cilia),cilia[i]))}
dev.off()


SUM <- sum((cilia-mean(cilia))^2)
LENGTH <- length(cilia)
VALIANCE1 <-  SUM/(LENGTH-1)

VALIANCE2 <- var(cilia)

VALIANCE3 <- (sum(cilia^2)-sum(cilia)^2/length(cilia))/(length(cilia)-1)

VALIANCE1
VALIANCE2
VALIANCE3




png("110317_figure3.png")
par(mfrow = c(1,2))
plot(rnorm(1000),rnorm(1000), ylab = "Label for y axis",xlab = "Label for x axis")
plot(rnorm(1000),rnorm(1000), ylab = "Label for y axis",xlab = "Label for x axis",las = 1 , cex.lab = 1.5, main = "rnorm plot")
dev.off()


x <- seq(-4,4, len =101)
plot(x, sin(x))
plot(x, sin(x), type ="l", xaxt = "n", xlab = expression(pasete("Phase Angle",phi)), ylab = expression("sin"phi))



kansu <- function(x){
maximum <- max(x)
minimum <- min(x)
mean <- mean(x)
median <- median(x)
length <- length(x)
cat("Maximum", maximum, "\n")
cat("Minimum", minimum, "\n")
cat("Mean", mean, "\n")
cat("Median", median, "\n")
cat("Length",length, "\n")
}
x <- rnorm(100)
kansu(x)



plot(c(0,32), c(0,15), type="n", xlab = "Sample size", ylab = "Variance")
for(df in seq(3,31,2)){
for(i in 1:30){
x <- rnorm(df, mean =10, sd =2)
points(df, var(x))
}
}



png("110317_figure4.png")
plot(c(0,32), c(0,15), type="n", xlab = "Sample size", ylab = "Variance")
for(df in seq(3,31,2)){
for(i in 1:300){
x <- rnorm(df, mean =10, sd =2)
points(df, var(x))
}
}
dev.off()



png("110317_figure6.png")
par(mfrow = c(1,5))
for(i in 1:5){
plot(runif(10^i, min = 0, max = 100))
}
dev.off()

png("110317_figure7.png")
means <- numeric(10000)
for (i in 1:10000){
means[i] <- mean(runif(5, min = 0, max = 10))
}
hist(means)
dev.off()


means <- numeric(10000)
for (i in 1:10000){
means[i] <- mean(runif(5, min=0, max=10))
}
hist(means)
yv <- dnorm(seq(0,10,0.1), mean = mean(means), sd = sd(means))*5000
line(seq(0,10,0.1), yv)