# efg, Stowers Institute for Medical Research # July 2004. Updated 8 Aug 2005. #source("LombScargle.R") source("http://research.stowers-institute.org/efg/2005/LombScargle/R/LombScargle.R") unit <<- "hour" # Assume calling program sets mfrow=c(2,2),if desired. DemoLombScargleCosine <- function(period=48, N=48, Amplitude=1.0, LowFreq, HighFreq, MFactor=4, EvenSpacing=TRUE, FigureLabels="", Title="Cosine Curve (N=48)") { if (EvenSpacing) { t <- 0:(N-1) # hours } else { t <- sort( runif(N, 0, N) ) } frequency <- 1/period ExpressionProfile <- Amplitude * cos(2*pi*frequency*t) M <- MFactor * N # could be some other multiple of N TestFrequencies <- LowFreq + (HighFreq - LowFreq) * (1:M / M) Nindependent <- NHorneBaliunas(N) LS <- ComputeAndPlotLombScargle(t, ExpressionProfile, TestFrequencies, Nindependent, Title, FigureLabels, GridOption=FALSE, IntervalHistogramOption=FALSE) return(LS) } DemoLombScargleCosineN <- function(period = 48, N=48, Amplitude=1.0, LowFreq=0.0, HighFreq=0.20, MFactor=4, FigureLabels="", Title="") { # Compute Lomb-Scargle Periodogram if (Title == "") { Title <- paste("Cosine Curve (N=", N, ")", sep="") } t <- period * (1:N / N) # hours frequency <- 1/period ExpressionProfile <- Amplitude * cos(2*pi*frequency*t) M <- MFactor * N TestFrequencies <- LowFreq + (HighFreq - LowFreq) * (1:M / M) Nindependent <- NHorneBaliunas(N) LS <- ComputeAndPlotLombScargle(t, ExpressionProfile, TestFrequencies, Nindependent, Title, FigureLabels, GridOption=FALSE, IntervalHistogramOption=FALSE) return(LS) } DemoLombScargleCosineRandomN <- function(period = 48, N=48, Amplitude=1.0, LowFreq=0.0, HighFreq=0.20, MFactor=4, FigureLabels="") { # Compute Lomb-Scargle Periodogram t <- period * (1:N / N) # hours t <- sort( runif(N, 0, period) ) frequency <- 1/period ExpressionProfile <- Amplitude * cos(2*pi*frequency*t) M <- MFactor * N TestFrequencies <- LowFreq + (HighFreq - LowFreq) * (1:M / M) Nindependent <- NHorneBaliunas(N) LS <- ComputeAndPlotLombScargle(t, ExpressionProfile, TestFrequencies, Nindependent, paste("Cosine Curve (N=", N, ")", sep=""), FigureLabels) return(LS) } DemoLombScargleCosineRandomNoise <- function(period = 48, N=48, Amplitude=1.0, LowFreq=0.0, HighFreq=0.20, MFactor=4, EvenSpacing=TRUE, Noise=1.0, FigureLabels="", Title="") { if (Title == "") { Title <- paste("Cosine Curve + Noise (N=", N, ")", sep="") } if (EvenSpacing) { t <- 0:(N-1) } else { t <- sort( runif(N, 0, N) ) } frequency <- 1/period ExpressionProfile <- Amplitude * cos(2*pi*frequency*t) + rnorm(N, mean=0, sd=Noise) M <- MFactor * N TestFrequencies <- LowFreq + (HighFreq - LowFreq) * (1:M / M) Nindependent <- NHorneBaliunas(N) LS <- ComputeAndPlotLombScargle(t, ExpressionProfile, TestFrequencies, Nindependent, Title, FigureLabels, GridOption=FALSE, IntervalHistogramOption=FALSE) return(LS) } ########################################################################## DemoLombScargleNoise <- function(period=48, N=48, LowFreq=0.0, HighFreq=0.20, MFactor=4, Noise=1.0, EvenSpacing=FALSE, FigureLabels="", Title="") { if (Title == "") { Title <- paste("Noise", sep="") } if (EvenSpacing) { t <- 0:(N-1) } else { t <- sort( runif(N, 0, N) ) } frequency <- 1/period ExpressionProfile <- rnorm(N, mean=0, sd=Noise) M <- MFactor * N TestFrequencies <- LowFreq + (HighFreq - LowFreq) * (1:M / M) Nindependent <- NHorneBaliunas(N) LS <- ComputeAndPlotLombScargle(t, ExpressionProfile, TestFrequencies, Nindependent, Title, FigureLabels, GridOption=FALSE, IntervalHistogramOption=FALSE) return(LS) } ########################################################################## DemoLombScargleCosine2 <- function(period1 = 24, period2 = 48, A1=1.0, A2=1.0, LowFreq, HighFreq, MFactor=4, EvenSpacing=TRUE, FigureLabels="", Noise=0.0, Title="") { # Compute Lomb-Scargle Periodogram N <- 48 if (Title == "") { Title <- "Sum of 2 Cosines (N=48)" } if (EvenSpacing) { t <- 0:(N-1) # hardwire over 48 hours for now } else { t <- sort( runif(N, 0, 48) ) # hardwire over 48 hours for now } frequency1 <- 1/period1 frequency2 <- 1/period2 ExpressionProfile <- A1*cos(2*pi*frequency1*t) + A2*cos(2*pi*frequency2*t) + rnorm(N, mean=0, sd=Noise) M <- MFactor * N # could be some other multiple of N TestFrequencies <- LowFreq + (HighFreq - LowFreq) * (1:M / M) Nindependent <- NHorneBaliunas(N) LS <- ComputeAndPlotLombScargle(t, ExpressionProfile, TestFrequencies, Nindependent, Title, FigureLabels="", GridOption=FALSE, IntervalHistogramOption=FALSE) return(LS) } DemoLombScargleCosine3 <- function(period1=24, period2=48, period3=60, A1=1.0, A2=1.0, A3=1.0, LowFreq, HighFreq, MFactor=4, EvenSpacing=TRUE, FigureLabels="", Noise=0.0, Title="") { N <- 48 # assume 48 hours if (Title == "") { Title <- "Sum of 3 Cosines (N=48)" } if (EvenSpacing) { t <- 0:(N-1) # hardwire over 48 hours for now } else { t <- sort( runif(N, 0, 48) ) # hardwire over 48 hours for now } frequency1 <- 1/period1 frequency2 <- 1/period2 frequency3 <- 1/period3 ExpressionProfile <- A1*cos(2*pi*frequency1*t) + A2*cos(2*pi*frequency2*t) + A3*cos(2*pi*frequency3*t) + rnorm(N, mean=0, sd=Noise) M <- MFactor * N # could be some other multiple of N TestFrequencies <- LowFreq + (HighFreq - LowFreq) * (1:M / M) Nindependent <- NHorneBaliunas(N) LS <- ComputeAndPlotLombScargle(t, ExpressionProfile, TestFrequencies, Nindependent, Title, FigureLabels, GridOption=FALSE, IntervalHistogramOption=FALSE) return(LS) }