createSample: Create a Sample from a Centered Distribution

View source: R/createSample.R

createSampleR Documentation

Create a Sample from a Centered Distribution

Description

This function creates a sample from a centered distribution based on replicates of mixed data.

Usage

createSample(z1, z2)

Arguments

z1

A numeric vector where z_1 = x_1 + y.

z2

A numeric vector of the same length as z_1 where z_2 = x_2 + y.

Value

A numeric vector representing a sample from the centered distribution.

Examples

# 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)

NPFD documentation built on Nov. 4, 2024, 5:07 p.m.