Rotterdam
Rotterdam

Reputation: 23

Duplicated levels in factor

For weeks I have used the same Rcode. This morning I started to get an error: `

Duplicated levels in factor Study_ID: Kumaravel, Gradl, Moroni.

What is the problem with duplicate levels?
Each study has different arms which all have a own row. What can I do about it?

Dataset on my dropbox: https://www.dropbox.com/s/j1urqzr99bt76ip/Basics%20excel%20file%20complication%20and%20reoperation%20rate.xlsx?dl=0

library(meta)
library(stargazer)
library(foreign)

All <-read.spss("C:\\Users\\313635aa.STUDENT\\Desktop\\Meta-Analyse Complications.sav",to.data.frame = T, use.value.labels = T)
All <- na.omit(All)


#outcomes
Complications <- All[which(All[,"Event_Type"] == "Complications"),]
Re_operation <- All[which(All[,"Event_Type"] == "Reoperations"),]

#treatment type
EF <- All[which(All[,"Treatment"] == "EF"),]
IMN <- All[which(All[,"Treatment"] == "IMN"),]
pc <- All[which(All[,"Treatment"] == "PC"),]
KW <- All[which(All[,"Treatment"] == "KW"),]
VPO <- All[which(All[,"Treatment"] == "VPO"),]

#combined ones
EF_C <- EF[which(EF[,"Event_Type"] == "Complications"),]
EF_R <- EF[which(EF[,"Event_Type"] == "Reoperations"),]

IMN_C <- IMN[which(IMN[,"Event_Type"] == "Complications"),]
IMN_R <- IMN[which(IMN[,"Event_Type"] == "Reoperations"),]

pc_C <- pc[which(pc[,"Event_Type"] == "Complications"),]
pc_R <- pc[which(pc[,"Event_Type"] == "Reoperations"),]

KW_C <- KW[which(KW[,"Event_Type"] == "Complications"),]
KW_R <- KW[which(KW[,"Event_Type"] == "Reoperations"),]

VPO_C <- VPO[which(VPO[,"Event_Type"] == "Complications"),]
VPO_R <- VPO[which(VPO[,"Event_Type"] == "Reoperations"),]

#Pooling

Output <- function(x, y, k.min=10){
file <- metaprop(Events_n, N, Study_ID, data = x)

forest.meta(file, studlab = T, pooled.totals = T, bysort = F)

dev.copy2pdf(file=y, width = 11.69, height = 8.27)
print(file)
    }

A part of the dataset:

Study| Event Type| Treatment| Number of Events (n)| N| n/N|
Kumaravel| Complications| EF| 3| 23| 0,1304348|
Franck| Complications| EF| 2| 20| 0,1|
Schonnemann| Complications| EF| 8| 30| 0,2666667|
Aita| Complications| EF| 1| 16| 0,0625|
Hove| Complications| EF| 31| 39| 0,7948718|
Andersen| Complications| EF| 26| 75| 0,3466667|
Krughaug| Complications| EF| 22| 75| 0,2933333|
Moroni| Complications| EF| 0| 20| 0|
Plate| Complications| IMN| 3| 30| 0,1|
Chappuis| Complications| IMN| 4| 16| 0,25|
Gradl| Complications| IMN| 12| 66| 0,1818182|
Schonnemann| Complications| IMN| 6| 31| 0,1935484|
Aita| Complications| IMN| 1| 16| 0,0625|
Dremstrop| Complications| IMN| 17| 44| 0,3863636|
Wong| Complications| PC| 1| 30| 0,0333333|
Kumaravel| Complications| PC| 4| 25| 0,16|

Upvotes: 1

Views: 1144

Answers (1)

Marco Sandri
Marco Sandri

Reputation: 24262

Here is a solution for your problem.
I start loading your Excel dataset and then define the Outcomes dataset:

library(meta)
library(readxl)

All <- read_excel("Basics excel file complication and reoperation rate.xlsx", sheet=1)
names(All) <- c("Study_ID","Event_Type","Treatment","Events_n","N","nN")

# Outcomes
Complications <- subset(All, Event_Type=="Complications")

Then, I modify your Output function as follows:

Output <- function(x, file_name) {
  mtpr <- metaprop(Events_n, N, Study_ID, data = x)
  forest.meta(mtpr, studlab = TRUE, pooled.totals = TRUE, bysort = FALSE)
  dev.copy2pdf(file=file_name, width = 11.69, height = 8.27)
  print(mtpr)
}

and now I use Output with the Complications dataset:

Output(Complications, "Complications.pdf")

The output is:

enter image description here

Upvotes: 1

Related Questions