Module # 4 Programming structure in R


The following data was collected by the local hospital. This data set contains 5 variables based on observation of 8 patients. In addition to the measurements of the patients checking in to the hospital that night, this data provides the patients' histories regarding the frequency of their visits to the hospital in the last 12 months.This data displays the measurement of blood pressure, first assessment by general doctor (bad=1, good =0) titled "first," the second assessment by external doctor (called "second"), and the last row provides the head of the emergency unit's decision regarding immediate care for the patient based on the values 0 or 1 (low = 0, high =1).
The names of your variables are as follows: "Freq","bloodp","first”, " second”, ”finaldecision”


> # Create vectors for each variable

> Frequency <- c(0.6, 0.3, 0.4, 0.4, 0.2, 0.6, 0.3, 0.4, 0.9, 0.2)

> BP <- c(103, 87, 32, 42, 59, 109, 78, 205, 135, 176)

> First <- c(1, 1, 1, 1, 0, 0, 0, 0, NA, 1)

> Second <- c(0, 0, 1, 1, 0, 0, 1, 1, 1, 1)

> FinalDecision <- c(0, 1, 0, 1, 0, 1, 0, 1, 1, 1)

> # Combine the data into a data frame

> data <- data.frame(Frequency, BP, First, Second, FinalDecision)

> # Check the updated data

> print(data)

   Frequency  BP First Second FinalDecision

1        0.6 103     1      0             0

2        0.3  87     1      0             1

3        0.4  32     1      1             0

4        0.4  42     1      1             1

5        0.2  59     0      0             0

6        0.6 109     0      0             1

7        0.3  78     0      1             0

8        0.4 205     0      1             1

9        0.9 135    NA      1             1

10       0.2 176     1      1             1

> # Replace NA values in 'First' column with 0

> data$First[is.na(data$First)] <- 0

> # Side-by-side boxplot

> boxplot(BP ~ First, data = data,

+         main = "Blood Pressure vs. MD's Rating (First Assessment)",

+         xlab = "MD's First Assessment",

+         ylab = "Blood Pressure (BP)",

+         col = c("lightblue", "lightgreen"))

> # Histogram for Blood Pressure (BP)

> hist(data$BP,

+      main = "Histogram of Blood Pressure (BP)",

+      xlab = "Blood Pressure (BP)",

+      col = "lightblue",

+      border = "black",

+      breaks = 5)







Looking at the boxplot, I can see the blood pressure (BP) readings are pretty different between the patients who were rated "bad" or "good" by the first doctor. The "bad" group had a wider range of BP values, including a few really high ones. The "good" group’s BP values were more on the lower side, which might suggest that people with lower BP got a better rating.

The histogram shows that most of the BP values fall between low and medium, but there are a few higher outliers. This means that while most people have normal BP, some have really high BP, which could be a sign of more serious health issues.

https://github.com/Ijennin/R-Functions/blob/450d7282798c57b69a5d4d63937be5a22a3e6b59/Module%20%23%204%20Programming%20structure%20in%20R





Comments

Popular posts from this blog

Final project - create your own R Package

Module # 1 assignment(R)