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

Bland Altman Plot and initial report #42

wants to merge 2 commits into from

Conversation

claudiavidalc
Copy link

No description provided.

Copy link
Member

@ernestguevarra ernestguevarra left a comment

Choose a reason for hiding this comment

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

@claudiavidalc good work on this! Well done!

I have one major comment below regarding the name you used for the plot output. Please take that comment into mind as it is important as you grow in your R journey.

Can I ask you to edit that and then push again into this pull request with the change and then I will approve?

Comment on lines +5 to +14
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)
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.

Comment on lines +17 to +23
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")
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?

Comment on lines +17 to +30
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)
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!

Comment on lines +40 to +49
```{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
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants