Uploaded by Sai Isogai

STAT 217 Cheat Sheet

advertisement
One-sample t-test
output1 <- t.test(data,mu=0,alternative="two.sided")
output2 <- t.test(data,mu=0,alternative="greater")
output3 <- t.test(data,mu=0,alternative="less")
ANDERSON-DARLING TEST FOR NORMALITY
ad.test(data/data1/data2)
LEVENE’S TEST FOR EQUAL VARIANCE
data.sort <- stack(data[,-1]) *FULL DATA FILE, not data1 or data2
leveneTest(data.sort$values,data.sort$ind)
boxplot(data1,data2) *equal if p-value>0.05
Binomial test for 1 proportion
binom.test(x,n,p0,alternative="two.sided")
binom.test(x,n,p0,alternative="greater")
binom.test(x,n,p0,alternative="less")
Regression coefficients → summary(model)
Conf. interval →
confint(model, level =0.95) Residual plot → plot(model) Scatter plot → model
<- lm(y~x) → plot(x,y)
Regression line → abline(model)
One-way table data analysis
chisq.test(data,p=prob)
qchisq(1-alpha,n-1)  Critical value
sum(data)*prob  expected value
Two proportions z-test
p1hat <- x1/n1
p2hat <- x2/n2
p.pool <- (x1+x2)/(n1+n2)
z.star <- (p1hat-p2hat)/sqrt(p.pool*(1-p.pool)*(1/n1+1/n2))
pnorm(-abs(z.star)) * 2  Case 1
1 - pnorm(z.star)  Case 2
pnorm(z.star)  Case 3
mar.error <- qnorm(1-alpha/2)* sqrt(p1tilt*(1-p1tilt)/(n1+2) + p2tilt*(1p2tilt)/(n2+2))
stat - mar.error  Lower bound stat + mar.error  Upper bound
Two-sample t-test
# Case 1: mu1 =/ mu2
t.test(data1,data2,alternative="two.sided")
# Case 2: mu1 > mu2
t.test(data1,data2,alternative="greater")
# Case 3: mu1 < mu2
t.test(data1,data2,alternative="less")
Matched-pair T-test*for normality, do DIFF (data1-data2)
t.test(data1,data2,paired=TRUE,alternative="two.sided")
t.test(data1,data2,paired=TRUE,alternative="greater")
t.test(data1,data2,paired=TRUE,alternative="less")
Mann-Whitney Test
wilcox.test(data1,data2,exact=FALSE,alternative="two.sided")
wilcox.test(data1,data2,exact=FALSE,alternative="greater")
wilcox.test(data1,data2,exact=FALSE,alternative="less")
Two-way data table analysis
data.summary <- matrix(c(15,10,7,19,4,19),ncol=2,byrow=TRUE)
rownames(data.summary) <- c("Desipramine","Lithium","Placebo")
colnames(data.summary) <- c("No","Yes") chisq.test(data.summary) add
“$observed” or “$expected” conditional distribution of Y given X →
rowcond <scale(t(data.summary),center=FALSE,colSums(t(data.summary)))
marginal distribution of Y → colSums(data.summary)/sum(data.summary)
*** ADD “barplot” for bar chart
conditional distribution of X →
scale(t(data.summary),center=FALSE,colSums(t(data.summary)))
conditional distribution of Y →
scale(data.summary,center=FALSE,colSums(data.summary))
marginal distribution of X → rowSums(data.summary)/sum(data.summary)
conditional distribution of X given Y → colcond <scale(data.summary,center=FALSE,colSums(data.summary))
CRITICAL VALUE for t-test
# Case 1 -> H0: mu = mu0 and H1: mu =/ mu0 qt(alpha/2, df=n-1) qt(1alpha/2, df=n-1)
# Case 2 -> H0: mu <= mu0 and H1: mu > mu0 qt(1-alpha, df=n-1)
# Case 3 -> H0: mu >= mu0 and H1: mu < mu0
qt(alpha, df=n-1)
Mann-Whitney Test-statistic dataagg <- c(data1,data2)
# Case for n1 > n2 sum(rank(dataagg)[(n1+1):(n1+n2)])
# Case for n1 > n2 sum(rank(dataagg)[(n1+1):(n1+n2)])
# Case for n1 = n2 sum(rank(dataagg)[1:n1])
Large sample z-test for 1 proportion
prop.test(x,n,p=p0,alternative="two.sided",correct=FALSE)
prop.test(x,n,p=p0,alternative="greater",correct=FALSE)
prop.test(x,n,p=p0,alternative="less",correct=FALSE)
Wilcox signed test statistic
# T.plus → wilcox.test(data1,data2,paired=TRUE,exact=FALSE,
alternative="two.sided")$statistic # T.minus → n <- length(abs(diff)[diff!=0])
n*(n+1)/2 - wilcox.test(data1,data2,paired=TRUE,exact=FALSE,
alternative="two.sided")$statistic
NORMALITY CHECK
hist(data), boxplot (data)
qqnorm(data,ylim=c(min(data)-1,max(data)+1))
qqline(data,col="red")
with(ToothGrowth, qqPlot(data, ylim=c(min(data)-1,max(data)+1), envelope
= 0.95))
Wilcox signed test*for normality, do DIFF (data1-data2)
wilcox.test(data1,data2,paired=TRUE,exact=FALSE,alternative="two.sided")
wilcox.test(data1,data2,paired=TRUE,exact=FALSE,alternative="greater")
wilcox.test(data1,data2,paired=TRUE,exact=FALSE,alternative="less")
Download