Skip to content

Instantly share code, notes, and snippets.

@nashutoing
Created March 31, 2019 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nashutoing/621db870d3f03978f72554a1cd739c42 to your computer and use it in GitHub Desktop.
Save nashutoing/621db870d3f03978f72554a1cd739c42 to your computer and use it in GitHub Desktop.
Principal Component Analysis for MLB2018 batter
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