rnorm.noise: General Random Normal Noise About a Vector

View source: R/MI_functions.R

rnorm.noiseR Documentation

General Random Normal Noise About a Vector

Description

rnorm.noise generates n random normal deviates about a mean value with a specified standard deviation.

Usage

rnorm.noise(Data, n, sd)

Arguments

Data

frame with two columns. 1st column identifies the group and the 2nd identifies the mean for that group

n

integer specifying the number of random normal deviates to generate for each value of x.

sd

standard deviation of the random normal deviates to be created.

Value

An object of class 'data frame' that contains two columns, one representing the "group" defined by the x parameter and one representing individual random normal deviates about the given "group".

Examples

# Example
rnorm.noise(Data=c(1, 10), n = 10, sd = 0.5)
# Example 2
# Signal data
x <- seq(0, 4 * pi, length = 241)
y <- scales::rescale(cos(seq(0, 4 * pi, length = 241)), to=c(0.2, 0.8))
plot(y ~ seq(0, 24, 0.1), type = "l", xaxt = "n", xlab="Month")
axis(1, at = seq(0, 24, 1), labels = c (rep(month.abb, 2),"Jan"))
# Noise Data
noise <- apply(data.frame(x=seq(0, 24, 0.1), y = y), 1, rnorm.noise, n = 10,
   sd = 0.1)
noise.df <- Reduce(function(...) merge(..., all = TRUE), noise)
# Plot Noise
plot(noise.df[, 2] ~ noise.df[, 1], pch = 20, ylab = "Proportion",
   xlab = "Month", xaxt="n")
axis(1, at = seq(0, 24, 1), labels = c (rep(month.abb, 2),"Jan"))

ballengerj/FishyR documentation built on June 17, 2022, 10:33 p.m.