Skip to content

Instantly share code, notes, and snippets.

@mcdlee
Created November 27, 2013 08:47
Show Gist options
  • Save mcdlee/7672622 to your computer and use it in GitHub Desktop.
Save mcdlee/7672622 to your computer and use it in GitHub Desktop.
Persantin and side effect
========================================================
author: mcdlee
date: 2013-12
Background of patients
========================================================
```{r echo=FALSE}
library(ggplot2)
library(knitr)
library(plyr)
library(reshape2)
persantin <- read.csv("~/Dropbox/tmp/R/Persantine side effect.csv")
attach(persantin)
summary(Gender)
summary(Age)
summary(Group)
```
Overview -1
========================================================
```{r echo=FALSE}
prop.table(table(Group, S3),1)
prop.table(table(Group, S10),1)
prop.table(table(Group, S20),1)
```
Overview -2
========================================================
```{r echo=FALSE}
chisq.test(Group, S3)
chisq.test(Group, S10)
chisq.test(Group, S20)
```
Overview- figure
========================================================
```{r echo=FALSE, fig.width=12, fig.height=8}
overall_wide <- ddply(persantin, .(Group), summarise,
"3 min" = length(S3[S3=="positive"])/ length(S3),
"10 min" = length(S10[S10=="positive"])/ length(S10),
"20 min" = length(S20[S20=="positive"])/ length(S20),
"Aminophylline" = length(Aminophylline[Aminophylline=="Yes"])/ length(Aminophylline)
)
overall_long <- melt(overall_wide, id.vars="Group", variable.name="Positive", value.name="Ratio")
ggplot(overall_long, aes(x=Positive, y=Ratio, fill=Group)) +
geom_bar(position="dodge") +
geom_text(aes(label=round(Ratio * 100, 2)), vjust=-0.8, color="black", position=position_dodge(0.9), size=3)
```
Transform
========================================================
```{r echo=TRUE}
list <- c(11:43)
FUN <- function(x) {
A <- ifelse(persantin[[x]]==0, "negative", "positive")
A <- as.factor(A)
return(A)
}
for(x in list){
persantin[x] <- FUN(x)
}
attach(persantin)
```
3rd minute
========================================================
```{r echo=FALSE, fig.width=12, fig.height=8}
first_wide <- ddply(persantin, .(Group), summarise,
"Chest pain / tightness" = length(S3.1[S3.1=="positive"])/length(S3.1),
"Palpitation" = length(S3.2[S3.2=="positive"])/length(S3.2),
"Abdominal pain" = length(S3.3[S3.3=="positive"])/length(S3.3),
"Dyspnea" = length(S3.4[S3.4=="positive"])/length(S3.4),
"Diarrhea" = length(S3.5[S3.5=="positive"])/length(S3.5),
"Nausea/vomiting" = length(S3.6[S3.6=="positive"])/length(S3.6),
"Headache" = length(S3.7[S3.7=="positive"])/length(S3.7),
"Dizziness" = length(S3.8[S3.8=="positive"])/length(S3.8),
"Neck soreness" = length(S3.9[S3.9=="positive"])/length(S3.9),
"Weakness" = length(S3.10[S3.10=="positive"])/length(S3.10),
"Flush" = length(S3.11[S3.11=="positive"])/length(S3.11)
)
first_long <- melt(first_wide, id.vars="Group", variable.name="Symptoms", value.name="Ratio")
ggplot(first_long, aes(x=reorder(Symptoms, -Ratio), fill=Group, y=Ratio)) +
geom_bar(position="dodge") +
geom_text(aes(label=round(Ratio *100, 2)), vjust=-0.8, color="black", position=position_dodge(0.9), size=3) +
xlab("Symptoms") +
theme(axis.text.x = element_text(angle=30, hjust=1, vjust=1))
```
10th minute
========================================================
```{r echo=FALSE, fig.width=12, fig.height=8}
second_wide <- ddply(persantin, .(Group), summarise,
"Chest pain / tightness" = length(S10.1[S10.1=="positive"])/length(S10.1),
"Palpitation" = length(S10.2[S10.2=="positive"])/length(S10.2),
"Abdominal pain" = length(S10.3[S10.3=="positive"])/length(S10.3),
"Dyspnea" = length(S10.4[S10.4=="positive"])/length(S10.4),
"Diarrhea" = length(S10.5[S10.5=="positive"])/length(S10.5),
"Nausea/vomiting" = length(S10.6[S10.6=="positive"])/length(S10.6),
"Headache" = length(S10.7[S10.7=="positive"])/length(S10.7),
"Dizziness" = length(S10.8[S10.8=="positive"])/length(S10.8),
"Neck soreness" = length(S10.9[S10.9=="positive"])/length(S10.9),
"Weakness" = length(S10.10[S10.10=="positive"])/length(S10.10),
"Flush" = length(S10.11[S10.11=="positive"])/length(S10.11)
)
second_long <- melt(second_wide, id.vars="Group", variable.name="Symptoms", value.name="Ratio")
ggplot(second_long, aes(x=reorder(Symptoms, -Ratio), fill=Group, y=Ratio)) +
geom_bar(position="dodge") +
geom_text(aes(label=round(Ratio *100, 2)), vjust=-0.8, color="black", position=position_dodge(0.9), size=3) +
xlab("Symptoms") +
theme(axis.text.x = element_text(angle=30, hjust=1, vjust=1))
```
20th minute
========================================================
```{r echo=FALSE, fig.width=12, fig.height=8}
third_wide <- ddply(persantin, .(Group), summarise,
"Chest pain / tightness" = length(S20.1[S20.1=="positive"])/length(S20.1),
"Palpitation" = length(S20.2[S20.2=="positive"])/length(S20.2),
"Abdominal pain" = length(S20.3[S20.3=="positive"])/length(S20.3),
"Dyspnea" = length(S20.4[S20.4=="positive"])/length(S20.4),
"Diarrhea" = length(S20.5[S20.5=="positive"])/length(S20.5),
"Nausea/vomiting" = length(S20.6[S20.6=="positive"])/length(S20.6),
"Headache" = length(S20.7[S20.7=="positive"])/length(S20.7),
"Dizziness" = length(S20.8[S20.8=="positive"])/length(S20.8),
"Neck soreness" = length(S20.9[S20.9=="positive"])/length(S20.9),
"Weakness" = length(S20.10[S20.10=="positive"])/length(S20.10),
"Flush" = length(S20.11[S20.11=="positive"])/length(S20.11)
)
third_long <- melt(third_wide, id.vars="Group", variable.name="Symptoms", value.name="Ratio")
ggplot(third_long, aes(x=reorder(Symptoms, -Ratio), fill=Group, y=Ratio)) +
geom_bar(position="dodge") +
geom_text(aes(label=round(Ratio *100, 2)), vjust=-0.8, color="black", position=position_dodge(0.9), size=3) +
xlab("Symptoms") +
theme(axis.text.x = element_text(angle=30, hjust=1, vjust=1))
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment