Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bland Altman Plot and initial report #42

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions exercise1.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
library(ggplot2)

ba = read.table("https://raw.githubusercontent.com/OxfordIHTM/teaching_datasets/main/ba.dat",header=TRUE)

average = rowMeans(ba)
ba$average = average
#Mean differences
difference <- ba$Wright - ba$Mini
ba$difference = difference
mean_difference = mean(difference)

#Confidence interval
lower <- mean_difference - 1.96*sd(ba$difference)
upper <- mean_difference + 1.96*sd(ba$difference)
Comment on lines +5 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job here! Well done! This si a good example of a scripts-based approach to calculating all the elements that you need for creating a Bland and Altman plot.

I will add it here as a solution but this doesn't fully answer my task/issue because I was asking for a function. And the examples from Mariano and Clifford below is what I was really looking for.


#Create Bland Altman Plot
ggplot(ba, aes(x = average, y = difference)) +
geom_point() +
geom_hline(yintercept = mean_difference) +
geom_hline(yintercept = lower, color = "red", linetype="dashed") +
geom_hline(yintercept = upper, color = "red", linetype="dashed") +
ylab("PEFR (l/min) Mini Wright meter - Wright meter ") +
xlab("PEFR (l/min) Mini Wright meter + Wright meter / 2")
Comment on lines +17 to +23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Amazing! Good work with the plot using ggplot. Well done!

Again, if I were to be strict with this task, my specific requirement was to create a function. Your script here is a good example of how to script the creation of a ggplot. I was wondering if you would like a challenge in converting this to a function?


BandA =function(W,M){
meanD=mean(abs(W-M))
SDD=sd(abs(W-M))
Expand Down
37 changes: 37 additions & 0 deletions exercise1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,41 @@ knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)

library(ggplot2)
ba = read.table("https://raw.githubusercontent.com/OxfordIHTM/teaching_datasets/main/ba.dat",header=TRUE)

average = rowMeans(ba)
ba$average = average

#Mean differences
difference <- ba$Wright - ba$Mini
ba$difference = difference
mean_difference = mean(difference)

#Confidence interval
lower <- mean_difference - 1.96*sd(ba$difference)
upper <- mean_difference + 1.96*sd(ba$difference)
Comment on lines +17 to +30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good approach here for copying your script form the R file to this part of the RMarkdown. Well done!

```

# Task 4: Report

## 1. Table of the mean and difference of per subject measurements made by the Wright and the Mini-Wright



## 2. Bland and Altman plot
```{r plot}
plot = ggplot(ba, aes(x = average, y = difference)) +
geom_point() +
geom_hline(yintercept = mean_difference) +
geom_hline(yintercept = lower, color = "red", linetype="dashed") +
geom_hline(yintercept = upper, color = "red", linetype="dashed") +
ylab("PEFR (l/min) Mini Wright meter - Wright meter ") +
xlab("PEFR (l/min) Mini Wright meter + Wright meter / 2")

plot
Comment on lines +40 to +49
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff! Good use of the code chunk and placement of plotting code inside.

My only main feedback and this is rather important so I will have to ask you to edit this before I approve it.

Here, you assigned the output of your ggplot script into an object called plot. The word plot is also the name of a function in R called plot. So, whilst the code will not cause an error, any code after you run these lines that needs/uses the plot function will not work properly anymore because within your code, the environment has changed and that plot is not a function anymore but an plotting object.

Generally, we try to avoid using a name of an existing function as an object name to store outputs. So I would suggest renaming this to maybe ba_plot instead.

Does this make sense?

```

## 3. Discussion of the findings with regard to the agreement between the Wright and Mini-Wright tools.

22 changes: 22 additions & 0 deletions exercise1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# Task 4: Report

## 1. Table of the mean and difference of per subject measurements made by the Wright and the Mini-Wright

## 2. Bland and Altman plot

``` r
plot = ggplot(ba, aes(x = average, y = difference)) +
geom_point() +
geom_hline(yintercept = mean_difference) +
geom_hline(yintercept = lower, color = "red", linetype="dashed") +
geom_hline(yintercept = upper, color = "red", linetype="dashed") +
ylab("PEFR (l/min) Mini Wright meter - Wright meter ") +
xlab("PEFR (l/min) Mini Wright meter + Wright meter / 2")

plot
```

![](exercise1_files/figure-gfm/plot-1.png)<!-- -->

## 3. Discussion of the findings with regard to the agreement between the Wright and Mini-Wright tools.
Binary file added exercise1_files/figure-gfm/plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.