Course - Math 206 - Data Analysis
Author - Brad Hartlaub
Reading in a data set
library(Stat2Data)
data("WeightLossIncentive4")
Looking at the structure of a data set
str(WeightLossIncentive4)
## 'data.frame': 36 obs. of 2 variables:
## $ WeightLoss: num 12.5 12 1 -5 3 -5 7.5 -2.5 20 -1 ...
## $ Group : Factor w/ 2 levels "Control","Incentive": 1 1 1 1 1 1 1 1 1 1 ...
Basic Plots
hist(WeightLossIncentive4$WeightLoss)
boxplot(WeightLoss~Group, data=WeightLossIncentive4)
Basic Descriptive Statistics
summary(WeightLossIncentive4)
## WeightLoss Group
## Min. :-17.000 Control :19
## 1st Qu.: 1.750 Incentive:17
## Median : 7.750
## Mean : 9.472
## 3rd Qu.: 18.625
## Max. : 30.000
Summary Statistics by Group
library(psych)
describe(WeightLossIncentive4$WeightLoss)
## vars n mean sd median trimmed mad min max range skew kurtosis
## X1 1 36 9.47 10.89 7.75 9.52 12.6 -17 30 47 -0.03 -0.66
## se
## X1 1.82
describeBy(WeightLossIncentive4$WeightLoss, WeightLossIncentive4$Group)
## $Control
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 19 3.92 9.11 3 4.21 8.15 -17 20 37 -0.13 -0.37 2.09
##
## $Incentive
## vars n mean sd median trimmed mad min max range skew kurtosis
## X1 1 17 15.68 9.41 18 15.8 11.86 -0.5 30 30.5 -0.12 -1.51
## se
## X1 2.28
##
## attr(,"call")
## by.default(data = x, INDICES = group, FUN = describe, type = type)
Two sample t test
t.test(WeightLoss~Group, data=WeightLossIncentive4)
##
## Welch Two Sample t-test
##
## data: WeightLoss by Group
## t = -3.7982, df = 33.276, p-value = 0.0005889
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -18.05026 -5.46058
## sample estimates:
## mean in group Control mean in group Incentive
## 3.921053 15.676471
t.test(WeightLoss~Group, data=WeightLossIncentive4, var.equal=TRUE)
##
## Two Sample t-test
##
## data: WeightLoss by Group
## t = -3.8054, df = 34, p-value = 0.0005635
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -18.033330 -5.477506
## sample estimates:
## mean in group Control mean in group Incentive
## 3.921053 15.676471
Two Sample t-test
data: WeightLoss by Group
t = -3.8054, df = 34, p-value = 0.0005635
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-18.033330 -5.477506
sample estimates:
mean in group Control mean in group Incentive
3.921053 15.676471