forked from MichaelBrannick/Meta-analysis-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_correlation_sampler.R
More file actions
37 lines (30 loc) · 935 Bytes
/
2_correlation_sampler.R
File metadata and controls
37 lines (30 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# If not installed, install the package e1071
# Select a CRAN Mirror when a dialog box opens
#install.packages('e1071')
# Run this line just one in an R session
#library(e1071)
# sampling distribution of r, the correlation coefficient
samplesize <- 120
#this is the sample size for each correlation
size.r <- .5
#this is the parameter, rho
numbersamples <- 10000
# this is the number of samples in the empirical sampling distribution
# lines above are setup to run the simulation
out1 <- 1:numbersamples
for (i in 1:numbersamples){
theta <- rnorm(samplesize,0,1)
e1 <- rnorm(samplesize,0,1)
e2 <- rnorm(samplesize,0,1)
weight <- sqrt(size.r)
x <- weight*theta+e1*sqrt(1-size.r)
y <- weight*theta+e2*sqrt(1-size.r)
out1[i] <- cor(x,y)
}
# out1 has the sampled correlatins
summary(out1)
sd(out1)
hist(out1)
skewness(out1)
# You can also screen skewness with a boxplot() function.
#boxplot(out1)