Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #####################
- # BIO360 Lab 3 Code #
- #####################
- # Required R packages
- #####################
- library(Rcmdr)
- library(PASWR)
- # Import data
- #############
- # Import dataset:
- # ---------------
- SelfEfficacy <-
- read.table("/Users/riya/OneDrive - University of Toronto/BIO360 Labs/BIO360-Lab3/SelfEfficacy.txt",
- header=TRUE, sep="\t", na.strings="NA", dec=".", strip.white=TRUE)
- #Reorder groups:
- # --------------
- SelfEfficacy$Group <- with(SelfEfficacy, factor(Group, levels=c('Intervention','Control')))
- ##########################
- # Q1. Short Term Effects #
- ##########################
- # The goal of this section is to test whether patients who receive a tailored information package have higher initial self-efficacy than patients who don't receive hte package, indicate the short-term effect of informatino packages at increasing self-efficacy in stroke patients.
- # For each type of group (Intervention, Control), a one-sided Wilcoxon rank sum test is performed to test whether the median of outcome score is significantly higher than 0.
- # Calculate summary statistics for hypothesis 1:
- # ----------------------------------------------
- numSummary(SelfEfficacy[,c("Initial.SE1", "Initial.SE2", "Initial.SE3",
- "Initial.SE4", "Initial.SE5", "Initial.SE6", "Initial.SE7", "Initial.SE8",
- "Initial.SE9"), drop=FALSE], groups=SelfEfficacy$Group, statistics=c("mean",
- "sd", "IQR", "quantiles"), quantiles=c(0.5))
- # Two-sample t-tests (don't interpret)
- # ------------------------------------
- t.test(Initial.SE1~Group, alternative='greater', conf.level=.95, var.equal=FALSE, data=SelfEfficacy)
- t.test(Initial.SE2~Group, alternative='greater', conf.level=.95, var.equal=FALSE, data=SelfEfficacy)
- t.test(Initial.SE3~Group, alternative='greater', conf.level=.95, var.equal=FALSE, data=SelfEfficacy)
- t.test(Initial.SE4~Group, alternative='greater', conf.level=.95, var.equal=FALSE, data=SelfEfficacy)
- t.test(Initial.SE5~Group, alternative='greater', conf.level=.95, var.equal=FALSE, data=SelfEfficacy)
- t.test(Initial.SE6~Group, alternative='greater', conf.level=.95, var.equal=FALSE, data=SelfEfficacy)
- t.test(Initial.SE7~Group, alternative='greater', conf.level=.95, var.equal=FALSE, data=SelfEfficacy)
- t.test(Initial.SE8~Group, alternative='greater', conf.level=.95, var.equal=FALSE, data=SelfEfficacy)
- t.test(Initial.SE9~Group, alternative='greater', conf.level=.95, var.equal=FALSE, data=SelfEfficacy)
- # Wilcoxon rank sum tests (use this)
- # ----------------------------------
- with(SelfEfficacy, tapply(Initial.SE1, Group, median, na.rm=TRUE))
- wilcox.test(Initial.SE1 ~ Group, alternative="greater", data=SelfEfficacy)
- with(SelfEfficacy, tapply(Initial.SE2, Group, median, na.rm=TRUE))
- wilcox.test(Initial.SE2 ~ Group, alternative="greater", data=SelfEfficacy)
- with(SelfEfficacy, tapply(Initial.SE3, Group, median, na.rm=TRUE))
- wilcox.test(Initial.SE3 ~ Group, alternative="greater", data=SelfEfficacy)
- with(SelfEfficacy, tapply(Initial.SE4, Group, median, na.rm=TRUE))
- wilcox.test(Initial.SE4 ~ Group, alternative="greater", data=SelfEfficacy)
- with(SelfEfficacy, tapply(Initial.SE5, Group, median, na.rm=TRUE))
- wilcox.test(Initial.SE5 ~ Group, alternative="greater", data=SelfEfficacy)
- with(SelfEfficacy, tapply(Initial.SE6, Group, median, na.rm=TRUE))
- wilcox.test(Initial.SE6 ~ Group, alternative="greater", data=SelfEfficacy)
- with(SelfEfficacy, tapply(Initial.SE7, Group, median, na.rm=TRUE))
- wilcox.test(Initial.SE7 ~ Group, alternative="greater", data=SelfEfficacy)
- with(SelfEfficacy, tapply(Initial.SE8, Group, median, na.rm=TRUE))
- wilcox.test(Initial.SE8 ~ Group, alternative="greater", data=SelfEfficacy)
- with(SelfEfficacy, tapply(Initial.SE9, Group, median, na.rm=TRUE))
- wilcox.test(Initial.SE9 ~ Group, alternative="greater", data=SelfEfficacy)
- #########################
- # Q2. Long Term Effects #
- #########################
- # The goal of this section is to see if self-efficacy of patients who receive a tailored information package increases over time.
- # For the Intervention group, a sign test is performed to test whether the median of outcome score is significantly higher than 0.
- # Subset data:
- # ------------
- InterventionGroup <- subset(SelfEfficacy, subset=Group == "Intervention", select=c(Follow.up.SE1,Follow.up.SE2,Follow.up.SE3,
- Follow.up.SE4,Follow.up.SE5,Follow.up.SE6,Follow.up.SE7,Follow.up.SE8,Follow.up.SE9,Group,Initial.SE1,Initial.SE2,Initial.SE3,
- Initial.SE4,Initial.SE5,Initial.SE6,Initial.SE7,Initial.SE8,Initial.SE9))
- # Create 'differences' variables:
- # -------------------------------
- InterventionGroup$Difference.SE1 <- with(InterventionGroup, Follow.up.SE1- Initial.SE1)
- InterventionGroup$Difference.SE2 <- with(InterventionGroup, Follow.up.SE2- Initial.SE2)
- InterventionGroup$Difference.SE3 <- with(InterventionGroup, Follow.up.SE3- Initial.SE3)
- InterventionGroup$Difference.SE4 <- with(InterventionGroup, Follow.up.SE4- Initial.SE4)
- InterventionGroup$Difference.SE5 <- with(InterventionGroup, Follow.up.SE5- Initial.SE5)
- InterventionGroup$Difference.SE6 <- with(InterventionGroup, Follow.up.SE6- Initial.SE6)
- InterventionGroup$Difference.SE7 <- with(InterventionGroup, Follow.up.SE7- Initial.SE7)
- InterventionGroup$Difference.SE8 <- with(InterventionGroup, Follow.up.SE8- Initial.SE8)
- InterventionGroup$Difference.SE9 <- with(InterventionGroup, Follow.up.SE9- Initial.SE9)
- # Calculate summary statistics for hypothesis 2:
- # ----------------------------------------------
- numSummary(InterventionGroup[,c("Difference.SE1", "Difference.SE2", "Difference.SE3",
- "Difference.SE4", "Difference.SE5", "Difference.SE6", "Difference.SE7", "Difference.SE8",
- "Difference.SE9"), drop=FALSE], groups=InterventionGroup$Group, statistics=c("mean",
- "sd", "IQR", "quantiles"), quantiles=c(0.5))
- # Paired t-tests (one-sample t-test on differences)
- # -------------------------------------------------
- with(InterventionGroup, (t.test(Difference.SE1, alternative='greater', mu=0.0, conf.level=.95)))
- with(InterventionGroup, (t.test(Difference.SE2, alternative='greater', mu=0.0, conf.level=.95)))
- with(InterventionGroup, (t.test(Difference.SE3, alternative='greater', mu=0.0, conf.level=.95)))
- with(InterventionGroup, (t.test(Difference.SE4, alternative='greater', mu=0.0, conf.level=.95)))
- with(InterventionGroup, (t.test(Difference.SE5, alternative='greater', mu=0.0, conf.level=.95)))
- with(InterventionGroup, (t.test(Difference.SE6, alternative='greater', mu=0.0, conf.level=.95)))
- with(InterventionGroup, (t.test(Difference.SE7, alternative='greater', mu=0.0, conf.level=.95)))
- with(InterventionGroup, (t.test(Difference.SE8, alternative='greater', mu=0.0, conf.level=.95)))
- with(InterventionGroup, (t.test(Difference.SE9, alternative='greater', mu=0.0, conf.level=.95)))
- # Sign tests (interpret this)
- # ---------------------------
- with(InterventionGroup, (SIGN.test(Follow.up.SE1, Initial.SE1, alternative = "greater")))
- with(InterventionGroup, (SIGN.test(Follow.up.SE2, Initial.SE2, alternative = "greater")))
- with(InterventionGroup, (SIGN.test(Follow.up.SE3, Initial.SE3, alternative = "greater")))
- with(InterventionGroup, (SIGN.test(Follow.up.SE4, Initial.SE4, alternative = "greater")))
- with(InterventionGroup, (SIGN.test(Follow.up.SE5, Initial.SE5, alternative = "greater")))
- with(InterventionGroup, (SIGN.test(Follow.up.SE6, Initial.SE6, alternative = "greater")))
- with(InterventionGroup, (SIGN.test(Follow.up.SE7, Initial.SE7, alternative = "greater")))
- with(InterventionGroup, (SIGN.test(Follow.up.SE8, Initial.SE8, alternative = "greater")))
- with(InterventionGroup, (SIGN.test(Follow.up.SE9, Initial.SE9, alternative = "greater")))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement