# BloodPressure Example # R script for Lab 1 problems. # Prob1 # Create bp1 and bp2 data frames. bp1 = read.table("c:/datasets/blood-pressure1.txt", header=TRUE) bp2 = read.table("c:/datasets/blood-pressure2.txt", header=TRUE) # Prob2 # Print bp1 and bp2 data frames. cat("bp1 dataframe:\n") print(bp1) cat("bp2 dataframe:\n") print(bp2) # Prob3 # Compute univariate statistics from # standing and supine columns in bp1. cat("Sample mean for Standing in bp1:\n") mean(bp1$Standing) cat("\nSample SD for Standing in bp1:\n") sd(bp1$Standing) cat("\nSample quantiles for Standing in bp1:\n") quantile(bp1$Standing, c(0.01, 0.05, 0.25, 0.50, 0.75, 0.95, 0.99)) cat("\nInterquartile range for Standing in bp1:\n") IQR(bp1$Standing) cat("Sample mean for Supine in bp1:\n") mean(bp1$Supine) cat("\nSample SD for Supine in bp1:\n") sd(bp1$Supine) cat("\nSample quantiles for Supine in bp1:\n") quantile(bp1$Supine, c(0.01, 0.05, 0.25, 0.50, 0.75, 0.95, 0.99)) cat("\nInterquartile range for Supine in bp1:\n") IQR(bp1$Supine) # Prob 4 # Skip this problem if using R. pdf = pdf("c:/datasets/bp.pdf") # Prob 5 # Create histograms for Standing and Supine hist(bp1$Standing, xlab="Blood Pressure in Standing Position") hist(bp1$Standing, breaks=seq(100, 700, 200), xlab="Blood Pressure in Standing Position") hist(bp1$Standing, breaks=seq(100, 600, 50), xlab="Blood Pressure in Standing Position") hist(bp1$Supine, xlab="Blood Pressure in Supine Position") hist(bp1$Supine, breaks=seq(0, 200, 100), xlab="Blood Pressure in Supine Position") hist(bp1$Supine, breaks=seq(0, 200, 25), xlab="Blood Pressure in Supine Position") # Prob 6 # Create normal plots for Standing and Supine qqnorm(bp1$Standing, xlab="Blood Pressure in Standing Position") qqnorm(bp1$Supine, xlab="Blood Pressure in Supine Position") # Prob 7 # Create side-by-side boxplots for Press # using Pos as the independent variable. boxplot(bp2$Press ~ bp2$Pos, xlab="Position in which Blood Pressure is Measured", ylab="Blood Pressure") dev.off( ) # Prob 8 # Obtain confidence intervals from one-sample t-test # output. We are not actually performing a t-test, # just obtaining the confidence interval from the output. cat("\nOne-sample t-test output:\n") t.test(bp1$Standing, y=NULL, alternative="two.sided", paired=FALSE, conf.level=0.95) t.test(bp1$Supine, y=NULL, alternative="two.sided", paired=FALSE, conf.level=0.95) # Prob 9 # Paired-sample t-test cat("\nPaired-sample t-test output:") t.test(bp1$Standing, bp1$Supine, alternative="two.sided", paired=TRUE, conf.level=0.95) # Prob 10 # Independent 2-sample t-test cat("\nIndependent 2-sample t-test output:\n") t.test(bp1$Standing, bp1$Supine, alternative="two.sided", paired=FALSE, conf.level=0.95)