3rd lab assignment

docx

School

McMaster University *

*We aren’t endorsed by this school

Course

702

Subject

Statistics

Date

Feb 20, 2024

Type

docx

Pages

4

Uploaded by MajorWallabyPerson207

Report
#Lab assignment 3 Jessel Britanico 7544539 HLSC 2P07 Biostatics February 8,2024 Part 1: Using Hq_lab1.csv dataset (make sure to import csv. file into R and name the imported data as “survey”) 1) Calculate mean and sd for variable “ht.m” by “Sex” (report a) pathway of input data, b) R codes, c) results). Code: install.packages("tidyverse") library(tidyverse) library(readr) hq_lab1 <- read_csv("C:/Users/jesse/OneDrive - Brock University/HLSC 2P07/Dataset/hq_lab1.csv") View(hq_lab1) write.csv(hq_lab1,"hq_lab1.csv") survey<- read.csv("hq_lab1.csv") survey aggregate(survey$ht.m, list (survey$Sex),FUN= mean) aggregate(survey$ht.m, list (survey$Sex),FUN= sd) survey$Happy<-as.factor(survey$Happy) Results: > install.packages("tidyverse") > library(tidyverse) > library(readr) > hq_lab1 <- read_csv("C:/Users/jesse/OneDrive - Brock University/HLSC 2P07/Dataset/hq_lab1.csv") > aggregate(survey$ht.m, list (survey$Sex),FUN= mean) Group.1 x 1 1 1.793438 2 2 1.646326 > aggregate(survey$ht.m, list (survey$Sex),FUN= sd) Group.1 x 1 1 0.07273411 2 2 0.08360326 > survey$Happy<-as.factor(survey$Happy) > ggplot(data=survey,mapping=aes(x=Happy, y=ht.m))+geom_boxplot()
2) Boxplot of “ht.m” by “Happy”, report a) R codes, b) graph (hint: factor “Happy” first), c) number of boxplot Code: ggplot(data=survey,mapping=aes(x=Happy, y=ht.m))+geom_boxplot() Results: Part 2: Create a Table 3.2 in R studio and calculate (keep 4 decimal points for all results) 1) Prevalence of CVD by smoking status Code: smoking_status<-c(rep("current smoker",times =2), rep("nonsmoker",times=2)) cvd<-c("no","yes","no","yes") count<-c(2757,298,663,81) data.3.2<-data.frame(smoking_status,cvd,count) data.3.2 data.3.2 data.3.2[2,3] cvd.s<-data.3.2[2,3]/(data.3.2[2,3]+data.3.2[1,3]) cvd.ns<-data.3.2[4,3]/(data.3.2[4,3]+data.3.2[3,3]) cbind("current smoker cvd",cvd.s,"nonsmoker cvd,cvd",cvd.ns)
cbind("current smoker cvd",round(cvd.s,4),"nonsmoker cvd",round(cvd.ns,4)) a<-298+81 b<-2757+298+663+81 prevalence<-round(a/b,4) prevalence Results: > smoking_status<-c(rep("current smoker",times =2), rep("nonsmoker",times=2)) > cvd<-c("no","yes","no","yes") > count<-c(2757,298,663,81) > data.3.2<-data.frame(smoking_status,cvd,count) > data.3.2 smoking_status cvd count 1 current smoker no 2757 2 current smoker yes 298 3 nonsmoker no 663 4 nonsmoker yes 81 > data.3.2 smoking_status cvd count 1 current smoker no 2757 2 current smoker yes 298 3 nonsmoker no 663 4 nonsmoker yes 81 > data.3.2[2,3] [1] 298 > cvd.s<-data.3.2[2,3]/(data.3.2[2,3]+data.3.2[1,3]) > cvd.ns<-data.3.2[4,3]/(data.3.2[4,3]+data.3.2[3,3]) > cbind("current smoker cvd",cvd.s,"nonsmoker cvd,cvd",cvd.ns) cvd.s [1,] "current smoker cvd" "0.0975450081833061" cvd.ns [1,] "nonsmoker cvd,cvd" "0.108870967741935" > cbind("current smoker cvd",round(cvd.s,4),"nonsmoker cvd",round(cvd.ns,4)) [,1] [,2] [,3] [,4] [1,] "current smoker cvd" "0.0975" "nonsmoker cvd" "0.1089" > a<-298+81 > b<-2757+298+663+81 > prevalence<-round(a/b,4) > prevalence [1] 0.0998 2) Relative ratio of CVD for current smoker compared to nonsmoker Code: rr.m<-round(cvd.s/cvd.ns,4)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
rr.m Results: > rr.m<-round(cvd.s/cvd.ns,4) > rr.m [1] 0.896 3) Risk difference of CVD between smokers and nonsmokers Code: rd<-round(abs(cvd.s-cvd.ns),4) rd Results: > rd<-round(abs(cvd.s-cvd.ns),4) > rd [1] 0.0113