This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(123) | |
x<- runif(100) | |
y<- 2*x + rnorm(100,0,0.1) | |
plot(x,y) | |
plot(y~x) | |
summary(lm(y~x)) | |
anova(lm(y~x)) | |
abline(lm(y~x)) | |
lm.devo<- lm(y~x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NPB18cebaZ<- scale(NPB18ceba[4:25]) #standardization | |
distZ<- data.frame(NPB18cebaZ) #? | |
distZ<- dist(NPB18cebaZ) #dcalculate distance,default method =euclidean | |
hclust(distZ) #clustering | |
summary(hclust(distZ)) | |
plot(hclust(distZ)) #dendrogram | |
a<- hclust(distZ,method = "average") | |
hclust(distZ)$merge | |
par(mfrow=c(1,2)) #to compare | |
plot(hclust(distZ),main = "default complete:最遠隣法") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) # to use select | |
MB<- select(MB18lim,G:SO) #select the columns(G~SO) | |
MB18limZ<- scale(MB) #standardization | |
prr<- prcomp(MB18limZ) # to use Principal component Analysis | |
prr | |
summary(prr) | |
biplot(prr) | |
prr$rotation #固有ベクトル・ | |
fcl<- sweep(prr$rotation,MARGIN =2, prr$sdev, FUN="*" ) | |
x<- c("G","PA","AB","R","H","X2B","X3B","HR","RBI","SB","CS","BB","SO") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plot(MB18lim$H,MB18lim$AB) | |
mean(MB18lim$H) | |
abline(v=mean(MB18lim$H)) | |
mean(MB18lim$AB) | |
abline(h=mean(MB18lim$AB)) | |
mtext("平均",side=1,line=1,at=84) | |
mtext("平均",side=2,line=2,at=333) | |
text("+",x=130,y=550,cex=5) | |
text("⁻",x=130,y=180,cex=8) | |
text("⁻",x=50,y=550,cex=8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MB18<- read.csv("2018MLB_batter.csv") | |
MB18$H | |
hist(MB18$H) #distorted, not simillar with normal distribution | |
MB18lim<- MB18[MB18$H>20,] #linit the player: under 20Hits are deleted | |
hist(MB18lim$H) | |
MB18O<- MB18[order(MB18$H),] # aort by ascending order as hit number | |
MMM<- MB18lim[order(MB18lim$H),] #〃 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rn<- rnorm(100) #make 100 random numbers followed by N(0,1) | |
rns<- sort(rn) #sort or order by ascending order(essential?) | |
plot(rns) #No useful(x-axis is represented as index) | |
rnss<- ecdf(rns) #ready for making cumlative function | |
par(mfrow=c(1,3)) #divide to set 3 graphs | |
plot(rnss) #cumlative function for rnorm(100) | |
abline(h=0.4) #draw horizon=0.4 line | |
curve(pnorm(x,0,1),xlim=c(-3,3)) | |
abline(h=0.4) #pnorm=cumlative function for normal distribution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rn<- rnorm(100) #make 100 random numbers followed by N(0,1) | |
rns<- sort(rn) #sort or order by ascending order(essential?) | |
plot(rns) #No useful(x-axis and y-axis is opposite) | |
rnss<- ecdf(rns) #ready for making cumlative function | |
par(mfrow=c(1,3)) #divide to set 3 graphs | |
plot(rnss) #cumlative function for rnorm(100) | |
curve(pnorm(x,0,1),xlim=c(-3,3)) #pnorm=cumlative function for normal distribution | |
qqnorm(rn) #make qqplot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aa<- rbinom(1000,500,0.285) | |
bb<- aa/500 | |
hist(bb,freq=TRUE,breaks = seq(0.22,0.35,0.001),xlab = "打率",ylab = "シーズン数", | |
main="500打席に立った青木選手の1000シーズン分の打率分布") | |
pp<- table(bb) | |
qq<- t(pp) | |
print(xtable(qq),type="html") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a<- rbinom(1000,100,0.3) | |
b<- a/100 | |
hist(b,freq=TRUE,breaks=seq(0.1,0.5,0.005),xlab = "打率",ylab = "シーズン数", | |
main="100打席に立った青木選手の1000シーズン分の打率分布") | |
print(xtable(table(b)),type="html") #didn't use (too long) | |
p<- table(b) | |
p | |
q<- t(p) #change rows and columns | |
q | |
print(xtable(q),type="html") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a<- rbinom(1000,10,0.285) | |
打率<- a/10 | |
hist(打率,freq=TRUE,breaks=seq(0,1,0.05),xlab = "打率", ylab = "シーズン数", | |
main = "10打席に立った青木選手の1000シーズン分の打率分布") | |
table(打率) | |
print(xtable(table(打率)),type = "html") #make table(打率) written by html style | |
write.csv(table(b),"aoki10bat.csv",quote = FALSE, sep=",") #make new table(b).csv file |
NewerOlder