Skip to content

Instantly share code, notes, and snippets.

@alexpghayes
Created December 12, 2022 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpghayes/94814816a6d93766b7324829d6a4921d to your computer and use it in GitHub Desktop.
Save alexpghayes/94814816a6d93766b7324829d6a4921d to your computer and use it in GitHub Desktop.
x <- c(
-0.54660789, 2.43686553, 1.24397260, -0.73957557, 2.33131378,
-0.97341652, -0.48911950, 0.35658630, -0.77824579, 1.55796356,
0.10641176, 0.89764371, 0.64903636, 1.89822592, -0.35568742,
1.52124163, 0.01328800, 1.33453143, -1.08829020, 0.83033763,
0.68018922, 1.93419047, 1.14073253, 2.56650893, 1.90859128,
1.39105347, 1.37547130, -0.07223141, 0.43142589, 1.78035482,
1.90837367, 1.84173396, -0.09760825, 1.66610817, 0.03379679,
0.97277154, 0.78599263, 0.75538460, 1.23006396, 0.83001685
)
y <- c(
0.64297443, 2.47047888, 2.20400164, 1.63743023, 2.71562759,
0.89221406, 0.95695500, 1.93372675, -0.78510178, 1.67736371,
0.84847015, 1.54191399, 1.06871388, -0.68989956, -0.08968257,
1.03751238, 0.70287354, 0.18421545, -0.12443295, -1.46861684,
0.48048808, 1.84445844, 0.19248018, 1.03515580, 1.13516935,
1.54098541, 2.24399689, -1.12419549, 0.40755826, 1.03454528,
-0.43858469, 0.82394013, -0.64106964, 0.90682616, 2.14253534,
-0.16303192, 0.01571576, 0.05148464, 0.21077641, 0.54581579
)
# point estimate in 4a
cov(x, y)
NMC <- 1e4
replicates <- rep(NA, NMC)
for (i in 1:NMC) {
fakedata <- sample(y)
replicates[i] <- cov(x, fakedata)
}
# two-sided p-value for 4b
mean(abs(replicates) > abs(cov(x, y)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment