---
title: "Analyse_annual statements"
author: "Dorothy Bishop"
date: "2025-05-10"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
require(tidyverse)
require(janitor)

```

```{r readdata}
df<-read.csv('AnnRepsCoded.csv')
# see Supp2_data_dictionary_ann_statements.csv for data dictionary

# N publications from Dimensions.ai
#About the data: Analytical views - Research Organization - Exported on Apr 23, 2025. Criteria: Publication Year is 2024; Country/Territory is United Kingdom. 	
# (done for separate years 2023 and 2024 as well as whole set of years from 2020-2024)

#This file manually processed to remove non UK and non Education institutions. 
#NB LSHTM coding was wrong and has been corrected, so it is not in rank order 

#University of London is complicated because it is unclear which bits of it are included in the integrity report. I have written for clarification but not had a response.  The size estimate for this institution is therefore wrong and is omitted.



```

```{r forTable2}

#Get Ns for those with a report in either 2023 or 2024 and for N with usable report
table(df$report2023_4)
table(df$include) #include is 1 for those with a usable statement with numbers

#Rather cumbersome way of getting Ns for Table 2, but this ensures those without a report and insufficient data are excluded, so total should always be 109

df$at_least_one_alleg[df$allegations==0] <- 0
df$at_least_one_alleg[df$allegations>0]<-1
df$at_least_one_alleg[df$include==0]<-NA
df$at_least_one_alleg[df$report2023_4==0]<-NA
t1<-table(df$at_least_one_alleg)
t1
sum(t1)
prop.table(t1)

df$at_least_one_invest[df$investigations==0]<-0
df$at_least_one_invest[df$investigations>0]<-1
df$at_least_one_invest[df$include==0]<-NA
df$at_least_one_invest[df$report2023_4==0]<-NA
t2<-table(df$at_least_one_invest)
t2
sum(t2)
prop.table(t2)



df$at_least_one_partial[df$upheld_in_part==0]<-0
df$at_least_one_partial[df$upheld_in_part>0]<-1
df$at_least_one_partial[df$include==0]<-NA
df$at_least_one_partial[df$report2023_4==0]<-NA
t3<-table(df$at_least_one_partial)
t3
sum(t3)  #total is 108 - one not reported so NA
prop.table(t3)

df$at_least_one_full[df$upheld_in_full==0]<-0
df$at_least_one_full[df$upheld_in_full>0]<-1
df$at_least_one_full[df$include==0]<-NA
df$at_least_one_full[df$report2023_4==0]<-NA
t4<-table(df$at_least_one_full)
t4 
sum(t4)
prop.table(t4)

```

```{r comparegroups}

#Split file into those with and without a report

df0 <- df[df$report2023_4==0,]
df1<- df[df$report2023_4==1,]
quantile(df0$pubs_dimensions_2020_2024,probs=c(0,.25,.50,.75))
quantile(df1$pubs_dimensions_2020_2024,probs=c(0,.25,.50,.75))

quantile(df0$size_wikipedia[df0$size_wikipedia>0],probs=c(0,.25,.50,.75),na.rm=T)
quantile(df1$size_wikipedia[df1$size_wikipedia>0],probs=c(0,.25,.50,.75),na.rm=T)


#check on those with 15K+ publications from 2020-2024
df$bigpubs <- 0
df$bigpubs[df$pubs_dimensions_2020_2024>15000] <- 1
table(df$bigpubs,df$report2023_4) #all produced a statement


df$anyallegations <-as.factor(df$at_least_one_alleg)


quantile(df$pubs_dimensions_2020_2024[df$anyallegations==0],probs=c(0,.25,.50,.75,.99),na.rm=T)
quantile(df$pubs_dimensions_2020_2024[df$anyallegations==1],probs=c(0,.25,.50,.75,.99),na.rm=T)


```

```{r ForTable3}
w<-which(df$include==1)
df2 <- df[w,]  #just the 109 from Table 2

n1 <- sum(df2$allegations,na.rm=T)
n2<- sum(df2$investigations,na.rm=T)
n1
n2
n2/n1

n3<-sum(df2$upheld_p_or_f,na.rm=T)
n3
n3/n2

```

```{r forTable4}
#again use df2 as this excludes those with inadequate reports

tab4<-data.frame(matrix(NA,nrow=5,ncol=3))
names(tab4) <- c("Variable","Total cases","Institutions reporting at least one case")

tab4[1,2] <- sum(df2$allegations,na.rm=T)
tab4[2,2] <- sum(df2$plagiarism,na.rm=T)
tab4[3,2] <- sum(df2$ethicsetc,na.rm=T)
tab4[4,2] <- sum(df2$fals_fab,na.rm=T)
tab4[5,2] <- sum(df2$other,na.rm=T)

tab4[2,3]<- sum(df2$plagiarism>0,na.rm=T)
tab4[3,3]<- sum(df2$ethicsetc>0,na.rm=T)
tab4[4,3]<- sum(df2$fals_fab>0,na.rm=T)
tab4[5,3]<- sum(df2$other>0,na.rm=T)

tab4[,1]<- c('N allegations that could be categorised (totalled across institutions)', 'Plagiarism','Failure to meet legal, ethical and professional obligations', 'Fabrication or falsification','Other (including multiple types)')



```
