Skip to content

Instantly share code, notes, and snippets.

@stockedge
Last active February 6, 2016 15:54
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 stockedge/6f9ca2934a426186e6e3 to your computer and use it in GitHub Desktop.
Save stockedge/6f9ca2934a426186e6e3 to your computer and use it in GitHub Desktop.
支持率と勝率の関係性を調べる
#参考
#http://www.amstat.org/chapters/boston/nessis07/presentation_material/Victor_Lo.pdf
#http://hub.hku.hk/bitstream/10722/60987/4/Content_11.pdf?accept=1
ws <- read.csv("winper_and_support.csv", header=F)
ws <- ws[which(ws$V1 != 0),]
ws <- ws[which(ws$V3 > 100),]
x <- matrix(0, ncol=2, nrow=nrow(ws)*(nrow(ws)-1))
k <- 1
for (i in 1:nrow(ws)) {
for (j in 1:nrow(ws)) {
if (i != j) {
print(k)
x[k,1] <-
log(ws[i,]$V1/ws[j,]$V1)
x[k,2] <-
log(ws[i,]$V2/ws[j,]$V2)
k <- k + 1
}
}
}
x <- as.data.frame(x)
names(x) <- c("V1", "V2")
model.lm <- lm(V1 ~ V2 - 1, x)
summary(model.lm)
#
#Call:
#lm(formula = V1 ~ V2 - 1, data = x)
#
#Residuals:
# Min 1Q Median 3Q Max
#-3.0004 -0.3485 0.0000 0.3485 3.0004
#
#Coefficients:
# Estimate Std. Error t value Pr(>|t|)
#V2 0.9538157 0.0005819 1639 <2e-16 ***
#---
#Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
#Residual standard error: 0.5816 on 636005 degrees of freedom
#Multiple R-squared: 0.8086, Adjusted R-squared: 0.8086
#F-statistic: 2.687e+06 on 1 and 636005 DF, p-value: < 2.2e-16
#βが1を下回るから何か根本的に勘違いしているかも…?
.separator ,
.output winper_and_support.csv
select
avg(order_of_finish = 1),
0.788 / (odds - 0.1),
count(*)
from
(select cast(order_of_finish as int) order_of_finish, odds from race_result)
where
order_of_finish <> 0
group by
odds;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment