Problem 1

Parametric tests are usually more powerful than non-parametric tests. But, non-parametric tests have less assumptions and they do not make distributional assumptions about the data. Thus, they can be applied even if parametric conditions of validity are not met. Parametric tests are powerful, but non-parametric tests are robust (valid in a broader range of situations as they have fewer conditions).

Problem 2.

The Pearson correlation measures the linear association between two variable. The Spearman correlation utilizes ranks to calculate the correlation; if the relationship is not linear and is strictly monotonic, we can use the Spearman correlation which measures the strength of the monotonic relationship between two variables. It is not influenced by outliers.

Problem 3

Part A.

The Pearson Coefficient = 0.7748, Kendall’s \(\tau\) = 0.6, and Spearman’s correlation = 0.7

Part B.

I would use Kendall’s Tau to determine the correlation.

With a p-value of 0.233 > \(\alpha\) = 0.05, we fail to reject the null hypothesis, which states that the variables are correlated. Thus, we argue that the variables are not correlated.

The relationship between the two variables seems like a monotonic, but it is not strictly monotonic as it dips at (3,20) so we do not use Pearson’s correlation coefficient. This point could be an outlier because the rest of the curve seems exponential. If there was more data, we might be able to have a better judgement call. Additionally, (5,200) may be an outlier, so the Pearson correlation would not be adequate in this situation.

p3 <- data.frame(x=c(1,2,3,4,5), y=c(0,20,-20,50,200))

cor(p3)
##           x         y
## x 1.0000000 0.7748062
## y 0.7748062 1.0000000
cor.test(p3$x,p3$y,method="kendall")
## 
##  Kendall's rank correlation tau
## 
## data:  p3$x and p3$y
## T = 8, p-value = 0.2333
## alternative hypothesis: true tau is not equal to 0
## sample estimates:
## tau 
## 0.6
cor(p3$x,p3$y, method = "kendall")
## [1] 0.6
cor.test(p3$x,p3$y,method="spearman")
## 
##  Spearman's rank correlation rho
## 
## data:  p3$x and p3$y
## S = 6, p-value = 0.2333
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho 
## 0.7
cor(p3$x,p3$y, method = "spearman")
## [1] 0.7

Problem 4.

Part A.

Hypothesis: \(H_0\) : \(\theta_{before} = \theta_{after}\) \(H_A\): \(\theta_{before} \neq \theta_{after}\)

Assumptions Observations are ā€œexchangeableā€ under the null and the data is paired with \(\alpha\) = 0.05.

I am using this hypothesis assuming the hypotheses would be equivalent for the means and medians based on the class notes as the paired comparison permutation test is for medians but we are asked to test the means.

Decision Rule: If p-value < \(\alpha\), reject the \(H_0\)

Conclusion: With a p-value of 0.25 (for a two sided test) > \(\alpha = 0.05\), we fail to reject the \(H_0\). That is, we cannot conclude the means of the two groups are different.

Under the null hypothesis the the medians of both groups are equal, each observation pair has an equal chance of occurring in either group.

Part B.

In this case, this is an exact p-value as we computed all permutations. If the number of permutations is too large we have to randomly sample permutations and we no longer have an exact p-value.

before<-c(102,86,127,140,80)
after<-c(124,110,123,134,154)

diffs<-before-after
diffs
## [1] -22 -24   4   6 -74
Dobs<-mean(diffs)
Dobs
## [1] -22
signs<-expand.grid(c(-1,1),c(-1,1),c(-1,1),c(-1,1),c(-1,1))

n<-5
#Compute all of the permutation means
perms<-as.matrix(signs)%*%as.matrix(diffs)/n
sort(perms)
##  [1] -26.0 -24.4 -23.6 -22.0 -17.2 -16.4 -15.6 -14.8 -14.8 -14.0 -13.2
## [12] -12.4  -7.6  -6.0  -5.2  -3.6   3.6   5.2   6.0   7.6  12.4  13.2
## [23]  14.0  14.8  14.8  15.6  16.4  17.2  22.0  23.6  24.4  26.0
#one-sided p-value, 4 because there are 4 observations that are smaller than -22 = Dobs
4/(2^5)
## [1] 0.125
#can multiply by 2 here because symmetric and two sided
2*4/(2^5)
## [1] 0.25

Problem 5.

We will perform the 1-sample sign test.

Assumptions: The data are independent and identically distribution (iid) and \(\alpha=0.05\).

Hypothesis: \(H_0\) : \(\theta = 50\) \(H_A\): \(\theta > 50\) Where \(\theta\) is the median

Decision Rule: If p-value < \(\alpha\), reject \(H_0\).

Conclusion: From a p-value of 0.8062 > \(\alpha = 0.05\), we fail to reject the null hypothesis. That is, we cannot conclude the median is greater than 50.

dat <- c(124,-1,-114,142,-77,124,-28,101,-99,18,26, 212)

table(sign(dat-50))
## 
## -1  1 
##  7  5
pbinom(7,12,.5)
## [1] 0.8061523
library(BSDA)
## Loading required package: lattice
## 
## Attaching package: 'BSDA'
## The following object is masked from 'package:datasets':
## 
##     Orange
SIGN.test(dat, md = 50, alternative = "greater")
## 
##  One-sample Sign-Test
## 
## data:  dat
## s = 5, p-value = 0.8062
## alternative hypothesis: true median is greater than 50
## 95 percent confidence interval:
##  -48.98091       Inf
## sample estimates:
## median of x 
##          22 
## 
## Achieved and Interpolated Confidence Intervals: 
## 
##                   Conf.Level   L.E.pt U.E.pt
## Lower Achieved CI     0.9270 -28.0000    Inf
## Interpolated CI       0.9500 -48.9809    Inf
## Upper Achieved CI     0.9807 -77.0000    Inf

Problem 6

Part A.

Hypothesis: \(H_0\) : The samples (groups) are from identical populations.

\(\theta_1 = \theta_2 = \theta_3\)

\(H_A\) : At least one of the samples (groups) comes from a different population than the others.

At least one \(\theta_n\) is different.

Assumptions: \(\alpha=0.05\) and \(\theta\) is the median petal width.

Decision Rule: For a p-value < \(\alpha\) = 0.5, we reject the null hypothesis.

With a p-value of 2.2e-16 < \(\alpha =0.05\), we reject the null hypothesis. That is, at least 1 species is from a different population with different median petal width.

head(iris)
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
## 3          4.7         3.2          1.3         0.2  setosa
## 4          4.6         3.1          1.5         0.2  setosa
## 5          5.0         3.6          1.4         0.2  setosa
## 6          5.4         3.9          1.7         0.4  setosa
plot(iris$Petal.Length, iris$Petal.Width, pch=21, bg=c("red","green3","blue")[unclass(iris$Species)], main="Iris Data")

kruskal.test(Petal.Width~Species, data=iris)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  Petal.Width by Species
## Kruskal-Wallis chi-squared = 131.19, df = 2, p-value < 2.2e-16

Part B.

Bonferroni

From the Bonferroni pairwise difference we see all p-values are below \(\alpha = 0.05\) between the different species. As the plot above hints as does the bonferroni paired comparison test suggest a significant differene between the three groups. As the most conservative of the tests, if this test suggests all three are different, I would bet the other two follow suit.

#Bonferroni
pairwise.wilcox.test(iris$Petal.Width, iris$Species, p.adj="bonf", paired = TRUE)
## 
##  Pairwise comparisons using Wilcoxon signed rank test 
## 
## data:  iris$Petal.Width and iris$Species 
## 
##            setosa  versicolor
## versicolor 2.2e-09 -         
## virginica  2.2e-09 3.3e-09   
## 
## P value adjustment method: bonferroni

Tukey HSD

Both the parametric Anova and nonparametric test suggest the same conclusion as the bonferroni: there is a significant difference between all three groups.

#Tukey HSD
TukeyHSD(aov(Petal.Width ~ Species, iris), conf.level = 0.95) 
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Petal.Width ~ Species, data = iris)
## 
## $Species
##                      diff       lwr       upr p adj
## versicolor-setosa    1.08 0.9830903 1.1769097     0
## virginica-setosa     1.78 1.6830903 1.8769097     0
## virginica-versicolor 0.70 0.6030903 0.7969097     0
library(MultNonParam)
tukey.kruskal.test(iris$Petal.Width, iris$Species)
##  1-2  1-3  2-3 
## TRUE TRUE TRUE

LSD

From the package below, we were able to find the LSD comparison.

The source I found (listed below) explains that means sharing the same letter are not significantly different. Virginica is a, versicolor is b, and setosa is c. From this decision rule, we see that different levels suggest the means are significantly different. This agrees with the results above.

https://rcompanion.org/rcompanion/d_05.html

library(agricolae)
## Warning: package 'agricolae' was built under R version 3.5.2
model<-aov(Petal.Width ~ Species, iris)
df<-df.residual(model)
MSerror<-deviance(model)/df

(LSD.test(model, "Species", df, MSerror))
## $statistics
##      MSerror  Df     Mean       CV  t.value        LSD
##   0.04188163 147 1.199333 17.06365 1.976233 0.08088724
## 
## $parameters
##         test p.ajusted  name.t ntr alpha
##   Fisher-LSD      none Species   3  0.05
## 
## $means
##            Petal.Width       std  r       LCL       UCL Min Max Q25 Q50
## setosa           0.246 0.1053856 50 0.1888041 0.3031959 0.1 0.6 0.2 0.2
## versicolor       1.326 0.1977527 50 1.2688041 1.3831959 1.0 1.8 1.2 1.3
## virginica        2.026 0.2746501 50 1.9688041 2.0831959 1.4 2.5 1.8 2.0
##            Q75
## setosa     0.3
## versicolor 1.5
## virginica  2.3
## 
## $comparison
## NULL
## 
## $groups
##            Petal.Width groups
## virginica        2.026      a
## versicolor       1.326      b
## setosa           0.246      c
## 
## attr(,"class")
## [1] "group"

Thus, all three provide the same conclusion. Also, looking at the plot could have given a similar conclusion.

Problem 7

data_7 <- data.frame(y = c(21.308064,6.800487,2.742283, 34.083525, 29.941135,11.941155,51.397883, 36.453405,20.557651), trt = c(1,2,3,1,2,3,1,2,3), block = c(1,1,1,2,2,2,3,3,3))

Part A.

With a p-value of 0.1479 < \(\alpha = 0.05\), this does not yield a significant result. This test is not appropriate here. I think the variabilitiy could be explained by blocking instead of treatment groups.

kruskal.test(data_7$y~data_7$trt)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  data_7$y by data_7$trt
## Kruskal-Wallis chi-squared = 3.8222, df = 2, p-value = 0.1479

Part B.

With a p-value of 0.04979 < \(\alpha = 0.05\), we (BARELY!) reject the \(H_0\) and consider this test significant. I think the test is appropriate here in terms of assumptions. But, this ā€œ0.05ā€ value is arbitrary in my opinion so I’m not really sure how significant this test is in this situation.

friedman.test(data_7$y, data_7$trt, data_7$block)
## 
##  Friedman rank sum test
## 
## data:  data_7$y, data_7$trt and data_7$block
## Friedman chi-squared = 6, df = 2, p-value = 0.04979

Part C.

If we have blocking of the data, it is theoretically okay to ignore the result if a kruskal-wallis test has a p-value < \(\alpha\) and proves to be significant. Ignoring the blocking would only make the test stronger.