Created
March 31, 2019 13:04
-
-
Save nashutoing/621db870d3f03978f72554a1cd739c42 to your computer and use it in GitHub Desktop.
Principal Component Analysis for MLB2018 batter
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") | |
par(mfrow=c(1,1)) | |
plot(fcl[,1],pch=x,ylim=c(-1,1)) | |
plot(fcl[,2],pch=x,ylim=c(-1,1)) | |
plot(fcl[,1],fcl[,2],pch=x,xlim=c(-1,1),ylim=c(-1,1)) | |
#因子負荷量のプロット(didn't use) | |
library(dplyr) | |
prrr<- select(MB18R,G:SO) | |
MBp<- scale(prrr) | |
MBpp<- prcomp(MBp) | |
MBpp | |
summary(MBpp) | |
biplot(MBpp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment