Skip to content
Prev 360191 / 398503 Next

R [coding : do not run for every row ]

You can make this much more readable with apply functions.

result <- apply(
  all_combine1,
  1,
  function(x){
    p.value <- sapply(
      seq_len(nSims),
      function(sim){
        gamma1 <- rgamma(x["m"], x["sp(skewness1.5)"], x["scp1"])
        gamma2 <- rgamma(x["n"], x["scp1"], 1)
        gamma1 <- gamma1 - x["sp(skewness1.5)"] * x["scp1"]
        gamma2 <- gamma2 - x["sp(skewness1.5)"]
        c(
          equal = t.test(gamma1, gamma2, var.equal=TRUE)$p.value,
          unequal = t.test(gamma1,gamma2,var.equal=FALSE)$p.value,
          mann = wilcox.test(gamma1,gamma2)$p.value
        )
      }
    )
    rowMeans(p.value <= alpha)
  }
)
cbind(all_combine1, t(result))
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no
more than asking him to perform a post-mortem examination: he may be
able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data. ~ John Tukey


2016-04-18 9:05 GMT+02:00 tan sj <sj_style_1125 at outlook.com>:
Message-ID: <CAJuCY5zHFeSkBBb4icOJSVKo1-nTauYKJsvXdnk6TD=+RCfSYQ@mail.gmail.com>
In-Reply-To: <KL1PR01MB08877493D844C7BAA6E3E433B56B0@KL1PR01MB0887.apcprd01.prod.exchangelabs.com>