0
私は多少の誤差があるかもしれませんが、以下のコードは、形状検査のパラメトリックな方法だと思います:ノンパラメトリック形状テストの実行方法は?
# Shape test
glu <- diabetes$Glucose
BPre <- diabetes$BloodPressure
plot(density(glu))
plot(density(BPre))
# To compare the shape, first to standardize them
glu1<- (glu - mean(glu))/sd(glu)
BPre1 <- (BPre - mean(BPre))/sd(BPre)
plot(density(glu1))
lines(density(BPre1), col = "red")
# Compute test statistic
q <- c(0.1, 0.4, 0.6, 0.8, 0.9)
x1 <- quantile(glu1, probs = q)
x2 <- quantile(BPre1, probs = q)
tstat <- sum(abs(x1 - x2))
tstat
s1 <- rnorm(length(glu1))
s2 <- rnorm(length(BPre1))
# Describe the population and generate one synthetic sample
f1 <- function()
{
s1 <- rnorm(length(glu1))
s2 <- rnorm(length(BPre1))
q <- c(0.1, 0.4, 0.6, 0.8, 0.9)
x1 <- quantile(s1, probs = q)
x2 <- quantile(s2, probs = q)
return(sum(abs(x1 - x2)))
}
# Create sampling distribution
sdist <- replicate(10000, f1())
# Plot sampling distribution & create p-value
plot(density(sdist))
abline(v = tstat, col = "dark red")
# Gap
gap <- abs(mean(sdist) - tstat)
abline(v = mean(sdist) + c(-1,1) * gap, col = "dark orange")
s1 <- sdist[sdist <(mean(sdist - gap)) | sdist >(mean(sdist + gap))]
pvalue <- length(s1)/length(sdist)
pvalue
私は、同じデータをノンパラメトリック形状のテストを行うことができます場合、私は思っていました。私の直感は私に言ったことが可能です。 glu1とBPresをノンパラメトリックな方法に変換する方法についてちょっとインスピレーションが必要です。ありがとう!