Load

library(data.table)
## Warning: package 'data.table' was built under R version 4.0.5
library(lme4)
## Loading required package: Matrix
matches <- read.csv("matches.csv", header=TRUE, sep=";")
matches$match <- as.factor(matches$match)
matches$trait <- as.factor(matches$trait)
matches <- read.csv("matches-wide.csv", header=TRUE, sep=";")
#matches$targets <- as.factor(rowSums(matches[,2:length(matches[1,])]))
matches
traits <- read.csv("traits.csv", header=TRUE, sep=";", stringsAsFactors = TRUE, row.names = 1)
traits
#model <- lmer(place ~ trait + (1|match), data = matches)
#model <- lmer(place ~ . + (1|mmr), data = matches)
model <- lm(place ~ ., data = matches)
summary(model)
## 
## Call:
## lm(formula = place ~ ., data = matches)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.7039 -1.1507  0.0254  0.8307  3.7876 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)  
## (Intercept)      -16.437127   7.972378  -2.062   0.0480 *
## trial             -0.128378   0.077346  -1.660   0.1074  
## mmr                0.012147   0.004497   2.701   0.0113 *
## RedeemedTRUE      -1.544013   1.593393  -0.969   0.3403  
## KnightTRUE         0.286399   1.256866   0.228   0.8213  
## RangerTRUE        -0.168155   1.567184  -0.107   0.9153  
## LegionnaireTRUE    2.797498   2.498208   1.120   0.2717  
## NightbringerTRUE   0.588121   1.407230   0.418   0.6790  
## DawnbringerTRUE   -2.268282   1.521664  -1.491   0.1465  
## HellionTRUE       -1.539688   1.652844  -0.932   0.3590  
## AbominationTRUE    2.068029   2.092613   0.988   0.3309  
## AssassinTRUE      -1.477459   1.281985  -1.152   0.2582  
## BrawlerTRUE        2.726417   1.586297   1.719   0.0960 .
## DraconicTRUE       3.988797   1.974482   2.020   0.0524 .
## DragonslayerTRUE  -0.540631   1.642410  -0.329   0.7443  
## ForgottenTRUE     -1.108075   1.896094  -0.584   0.5633  
## SpellweaverTRUE    2.943684   1.635624   1.800   0.0820 .
## SkirmisherTRUE    -1.785398   1.404833  -1.271   0.2135  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.979 on 30 degrees of freedom
## Multiple R-squared:  0.5751, Adjusted R-squared:  0.3343 
## F-statistic: 2.388 on 17 and 30 DF,  p-value: 0.01802
coefs <- coef(summary(model))
rownames(coefs) <- gsub("TRUE$", "", rownames(coefs))
coefs[order(coefs[,1]),]
##                  Estimate  Std. Error    t value   Pr(>|t|)
## (Intercept)  -16.43712695 7.972377980 -2.0617596 0.04798653
## Dawnbringer   -2.26828225 1.521663832 -1.4906592 0.14649140
## Skirmisher    -1.78539820 1.404833091 -1.2708970 0.21353211
## Redeemed      -1.54401287 1.593392538 -0.9690097 0.34028826
## Hellion       -1.53968848 1.652844432 -0.9315387 0.35901153
## Assassin      -1.47745948 1.281984652 -1.1524783 0.25822563
## Forgotten     -1.10807502 1.896093752 -0.5843989 0.56332131
## Dragonslayer  -0.54063117 1.642409546 -0.3291695 0.74431466
## Ranger        -0.16815477 1.567183879 -0.1072974 0.91526740
## trial         -0.12837785 0.077346035 -1.6597858 0.10737674
## mmr            0.01214713 0.004496823  2.7012688 0.01125005
## Knight         0.28639911 1.256865524  0.2278677 0.82129501
## Nightbringer   0.58812131 1.407229876  0.4179284 0.67897584
## Abomination    2.06802877 2.092612610  0.9882521 0.33093332
## Brawler        2.72641663 1.586296942  1.7187303 0.09596845
## Legionnaire    2.79749791 2.498208052  1.1198018 0.27168367
## Spellweaver    2.94368383 1.635623868  1.7997315 0.08196842
## Draconic       3.98879657 1.974481752  2.0201739 0.05237296
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.0.4
predictionBase <- data.frame(head(matches, n=0))
predictionBase[,'name'] <- factor(levels=rownames(traits))
for (trait in rownames(traits)) {
  predictionBase[trait,'trial'] <- nrow(matches)
  predictionBase[trait,'mmr'] <- matches$mmr[nrow(matches)]
  predictionBase[trait,'type'] <- traits[trait,'type']
  predictionBase[trait,'name'] <- factor(trait)
  for (t in rownames(traits)) {
    predictionBase[trait,t] <- t == trait
  }
}

predictionBase$place <- predict(model, predictionBase)

predictionBase$name <- ordered(
  predictionBase$name,
  levels=predictionBase$name[order(predictionBase$place)]
)

ggplot(predictionBase,
       aes(x=name, y=place, fill=type)
      ) +
  geom_bar(stat="identity") +
  coord_flip()

modelData <- data.frame(coef(model))
colnames(modelData)[1] <- 'est'
modelData$name <- rownames(modelData)
modelData['trial', 'minv'] <- min(matches$trial)
modelData['trial', 'maxv'] <- max(matches$trial)
modelData['mmr', 'minv'] <- min(matches$mmr)
modelData['mmr', 'maxv'] <- max(matches$mmr)
modelData['(Intercept)', 'minv'] <- 1
modelData['(Intercept)', 'maxv'] <- 1

ggplot(modelData[c('trial', 'mmr', '(Intercept)'),],
       aes(x=name, y=est)
      ) +
  geom_pointrange(aes(ymin=minv * est, ymax=maxv * est)) +
  coord_flip()

ggplot(matches, aes(x=mmr, y=place)) + geom_point()