createSample | R Documentation |
This function creates a sample from a centered distribution based on replicates of mixed data.
createSample(z1, z2)
z1 |
A numeric vector where |
z2 |
A numeric vector of the same length as |
A numeric vector representing a sample from the centered distribution.
# Set seed for reproducibility
set.seed(123)
# Generate random data
x1 <- rnorm(1000)
x2 <- rnorm(1000)
y <- rgamma(1000, 10, 2)
z1 <- x1 + y
z2 <- x2 + y
# Use createSample to generate a sample
x <- createSample(z1, z2)
# Perform density estimation
f.x <- stats::density(x, adjust = 1.5)
x.x <- f.x$x
f <- dnorm(x.x)
# Plot the results
plot(NULL, xlim = range(f.x$x), ylim = c(0, max(f, f.x$y)), xlab = "x", ylab = "Density")
lines(x.x, f, col = "blue", lwd = 2)
lines(f.x, col = "orange", lwd = 2)
legend("topright", legend = c(expression(f), expression(f[x])), col = c("blue", "orange"), lwd = 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.