r MANOVA塑料双向与bonferroni

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r MANOVA塑料双向与bonferroni相关的知识,希望对你有一定的参考价值。

####
#### These are data on qualities of extruding plastic. There are two factors, rate of 
#### extrusion and amount of an additive (both with two levels - low and high, so g = b = 
#### 2). Within each of the four factor level combinations, n = 5 plastic samples were 
#### observed, for which p = 3 variables were measured: (1) tear resistance, (2) gloss, 
#### and (3) opacity.
####

##
## Input data.
##

X <- read.delim("T6-4.DAT", header = FALSE, sep = "")
n <- 5
p <- 3
g <- b <- 2
colnames(X) <- c("Factor_1", "Factor_2", "X_1", "X_2", "X_3")
attach(X)

## Summary statistics.
x_bar <- colMeans(X[, 3:5])
x_bar_lk <- rbind(colMeans(X[Factor_1 == 0 & Factor_2 == 0, 3:5]), 
  colMeans(X[Factor_1 == 0 & Factor_2 == 1, 3:5]),
  colMeans(X[Factor_1 == 1 & Factor_2 == 0, 3:5]),
  colMeans(X[Factor_1 == 1 & Factor_2 == 1, 3:5]))
x_bar_l_dot <- rbind(colMeans(X[Factor_1 == 0, 3:5]), colMeans(X[Factor_1 == 1, 3:5]))
x_bar_dot_k <- rbind(colMeans(X[Factor_2 == 0, 3:5]), colMeans(X[Factor_2 == 1, 3:5]))

## Boxplots.
pdf("figures/plastic_boxes.pdf", width = 7, height = 3)
par(mfrow = c(1, 3))
boxplot(X[, 3] ~ Factor_1 * Factor_2, names = c("LL", "HL", "LH", "HH"), 
  main = "Tear Resistance")
boxplot(X[, 4] ~ Factor_1 * Factor_2, names = c("LL", "HL", "LH", "HH"), 
  main = "Gloss")
boxplot(X[, 5] ~ Factor_1 * Factor_2, names = c("LL", "HL", "LH", "HH"), 
  main = "Opacity")
dev.off()

## Components for MANOVA.
SSP_cor <- SSP_fac_1 <- SSP_fac_2 <- SSP_int <- SSP_res <- matrix(0, nrow = p, ncol = p)
for(l in 1:g) {
  SSP_fac_1 <- SSP_fac_1 + b * n * t(x_bar_l_dot[l, , drop = FALSE] - x_bar) %*% 
    (x_bar_l_dot[l, , drop = FALSE] - x_bar)
  SSP_fac_2 <- SSP_fac_2 + g * n * t(x_bar_dot_k[l, , drop = FALSE] - x_bar) %*% 
    (x_bar_dot_k[l, , drop = FALSE] - x_bar)
  for(k in 1:b) {
    SSP_int <- SSP_int + n * t(x_bar_lk[(l - 1) * 2 + k, , drop = FALSE] - 
      x_bar_l_dot[l, , drop = FALSE] - x_bar_dot_k[k, , drop = FALSE] + x_bar) %*% 
      (x_bar_lk[(l - 1) * 2 + k, , drop = FALSE] - x_bar_l_dot[l, , drop = FALSE] - 
      x_bar_dot_k[k, , drop = FALSE] + x_bar)
    for(r in 1:n) {
      SSP_res <- SSP_res + t(as.matrix(X[(l - 1) * 2 * n + (k - 1) * n + r, 3:5]) - 
        x_bar_lk[(l - 1) * 2 + k, , drop = FALSE]) %*% 
        (as.matrix(X[(l - 1) * 2 * n + (k - 1) * n + r, 3:5]) - 
        x_bar_lk[(l - 1) * 2 + k, , drop = FALSE])
      SSP_cor <- SSP_cor + t(as.matrix(X[(l - 1) * 2 * n + (k - 1) * n + r, 3:5]) - 
        x_bar) %*% (as.matrix(X[(l - 1) * 2 * n + (k - 1) * n + r, 3:5]) - x_bar)
    }
  }
}

##
## Inference.
##

## No interaction.
Lambda <- det(SSP_res) / det(SSP_int + SSP_res)
1 - pf((((g * b * (n - 1) - p + 1) / 2) / ((abs((g - 1) * (b - 1) - p) + 1) / 2)) * 
  (1 - Lambda) / Lambda, abs((g - 1) * (b - 1) - p) + 1, g * b * (n - 1) - p + 1)

## There is an effect of rate of extrusion.
Lambda <- det(SSP_res) / det(SSP_fac_1 + SSP_res)
1 - pf((((g * b * (n - 1) - p + 1) / 2) / ((abs((g - 1) - p) + 1) / 2)) * 
  (1 - Lambda) / Lambda, abs((g - 1) - p) + 1, g * b * (n - 1) - p + 1)

## There is an effect of amount of additive.
Lambda <- det(SSP_res) / det(SSP_fac_2 + SSP_res)
1 - pf((((g * b * (n - 1) - p + 1) / 2) / ((abs((b - 1) - p) + 1) / 2)) * 
  (1 - Lambda) / Lambda, abs((b - 1) - p) + 1, g * b * (n - 1) - p + 1)

summary(manova(as.matrix(X[, 3:5]) ~ Factor_1 + Factor_2 + Factor_1 * Factor_2), 
  test = "Wilks")

## Bonferroni 95% confidence intervals for factor 1 main effects.
m <- p * g * (g - 1)
nu <- g * b * (n - 1)
x_bar_l_dot[1, 1] - x_bar_l_dot[2, 1] + c(-1, 1) * qt(1 - 0.05 / m, nu) * 
  sqrt(2 * SSP_res[1, 1] / (nu * b * n))
x_bar_l_dot[1, 2] - x_bar_l_dot[2, 2] + c(-1, 1) * qt(1 - 0.05 / m, nu) * 
  sqrt(2 * SSP_res[2, 2] / (nu * b * n))
x_bar_l_dot[1, 3] - x_bar_l_dot[2, 3] + c(-1, 1) * qt(1 - 0.05 / m, nu) * 
  sqrt(2 * SSP_res[3, 3] / (nu * b * n))

## Bonferroni 95% confidence intervals for factor 2 main effects. Note that all of these 
## contain zero (barely, in the case of tear resistance). This is an example where the 
## strength of evidence of an effect is increased by performing a multivariate analysis. 
m <- p * b * (b - 1)
x_bar_dot_k[1, 1] - x_bar_dot_k[2, 1] + c(-1, 1) * qt(1 - 0.05 / m, nu) * 
  sqrt(2 * SSP_res[1, 1] / (nu * g * n))
x_bar_dot_k[1, 2] - x_bar_dot_k[2, 2] + c(-1, 1) * qt(1 - 0.05 / m, nu) * 
  sqrt(2 * SSP_res[2, 2] / (nu * g * n))
x_bar_dot_k[1, 3] - x_bar_dot_k[2, 3] + c(-1, 1) * qt(1 - 0.05 / m, nu) * 
  sqrt(2 * SSP_res[3, 3] / (nu * g * n))








以上是关于r MANOVA塑料双向与bonferroni的主要内容,如果未能解决你的问题,请参考以下文章

R语言manova函数稳健多元方差分析(Robust one-way MANOVA)rrcov包中的wilks.test函数稳健单向MANOVAvegan包的adonis函数非参数Manova等效

r 置信区间T2 Bonferroni Hotelling Bootstrap

r manova花生两种方式

r manova疗养院一种方式

R语言Bonferroni校正的成对t检验进行事后检验(post hoc)实战:单因素方差分析告诉我们并不是所有的群体手段的效果是均等的,确切地找出哪些组彼此不同使用Bonferroni校正检验

R语言manova函数多元方差分析(MANOVA)单因素多元方差分析的两个假设是多元正态性和方差-协方差矩阵的齐性QQ图评估多元正态性mvoutlier包中的aq.plot函数检验多变量异常值