---
title: "R sources for Which Combination of Test Metrics Can Predict Success of a Software Project?"
author: "Marina Filipovic, Fabian Gilson, with support from Elena Moltchanova"
date: "24/8/2023"
output:
  pdf_document: default
  html_document: default
---

Load data and define Fix.next variable for analysis

```{r}
rm(list=ls())

d <- read.csv('Data_stac_higher_prec.csv')

d$Fix.next <- c(d$FE[-1],NA)
d$Fix.next[d$Sprint=='sprint 6'] <- NA

d$Rec.next <- c(d$RSP[-1],NA)
d$Rec.next[d$Sprint=='sprint 6'] <- NA

d$Def.next <- c(d$DSP[-1],NA)
d$Def.next[d$Sprint=='sprint 6'] <- NA


```

Fit all models from paper

```{r}
#library(lme4)
library(lmerTest)

# 4.4.1
m <- lmer(PSP ~ FEUT+BEUT+AAT+MAT+(1|Team), data=d)
summary(m)

m <- lmer(PSP ~ OAT+(1|Team), data=d)
summary(m)

m <- lmer(PSP ~ AVGTC+(1|Team), data=d)
summary(m)

# 4.4.2
m <- lmer(PSP ~ ATE+MTE+FE+IE+(1|Team), data=d)
summary(m)

m <- lmer(PSP ~ TTE+(1|Team), data=d)
summary(m)

# 4.4.3
m <- lmer(DSP ~ FEUT+BEUT+AAT+MAT+(1|Team), data=d)
summary(m)

# not shown
m <- lmer(DSP ~ OAT+(1|Team), data=d)
summary(m)

# not shown
m <- lmer(DSP ~ AVGTC+(1|Team), data=d)
summary(m)

m <- lmer(DSP ~ ATE+MTE+FE+IE+(1|Team), data=d)
summary(m)

# not shown
m <- lmer(DSP ~ TTE+(1|Team), data=d)
summary(m)

# 4.4.4
m <- lmer(Fix.next ~ FEUT+BEUT+AAT+MAT+(1|Team), data=d)
summary(m)

# not shown
m <- lmer(Fix.next ~ OAT+(1|Team), data=d)
summary(m)

# not shown
m <- lmer(Fix.next ~ AVGTC+(1|Team), data=d)
summary(m)

# not shown
m <- lmer(Fix.next ~ ATE+MTE+FE+IE+(1|Team), data=d)
summary(m)

m <- lmer(Fix.next ~ TTE+(1|Team), data=d)
summary(m)

# 4.4.5
m <- lmer(Fix.next ~ PSP+(1|Team), data=d)
summary(m)

# other hypotheses, rejected
m <- lmer(Rec.next ~ FEUT+BEUT+AAT+MAT+(1|Team), data=d)
summary(m)

m <- lmer(Rec.next ~ ATE+MTE+FE+IE+(1|Team), data=d)
summary(m)

m <- lmer(Def.next ~ FEUT+BEUT+AAT+MAT+(1|Team), data=d)
summary(m)

m <- lmer(Def.next ~ ATE+MTE+FE+IE+(1|Team), data=d)
summary(m)


```

Generate graphs

```{r}
library(ggplot2)
library(lmerTest)

# total testing effort on fixing effort in next sprint

m <- lmer(Fix.next ~ TTE*Sprint+(1|Team), data=d)
dft <- expand.grid(TTE = seq(0,.5,length.out=101),Sprint=sort(unique(d$Sprint))[1:4])

dft$y <- predict(m,dft,re.form=~0)

ggplot()+
  geom_point(data=d,aes(x=TTE,y=Fix.next,
                        col=Sprint))+
  geom_line(data=dft,aes(x=TTE,y=y,col=Sprint))
```

```{r}
library(ggplot2)
library(lmerTest)

# Average test coverage on passed stories

m <- lmer(PSP ~ AVGTC+(1|Team), data=d)
dft <- expand.grid(AVGTC = seq(0,1,length.out=101),Team=sort(unique(d$Team))[1:7])

dft$y <- predict(m,dft,re.form=~0)

ggplot()+
  geom_point(data=d,aes(x=AVGTC,y=PSP,
                        col=Team)) +
    geom_line(data=dft,aes(x=AVGTC,y=y,col=Team))

```
