Error analysis lecture 22

Embed Size (px)

Citation preview

  • 7/30/2019 Error analysis lecture 22

    1/28

    Physics 509 1

    Physics 509: Searching for

    Periodic Signals

    Scott OserLecture #22

    December 1, 2008

  • 7/30/2019 Error analysis lecture 22

    2/28

    Physics 509 2

    Do you see any periodicity in this data?

  • 7/30/2019 Error analysis lecture 22

    3/28

    Physics 509 3

    How about this data?

  • 7/30/2019 Error analysis lecture 22

    4/28

    Physics 509 4

    How about now?

  • 7/30/2019 Error analysis lecture 22

    5/28

    Physics 509 5

    Uses and issues with periodicity analyses

    Many obvious applications: astronomy: orbits, pulsars, oscillating objects particle physics: oscillation analyses general experimental physics: seasonal or diurnal effects

    But lots of issues: do you know the period ahead of time? how do you even tell if there is a period and not a coincidence?

    if your data has finite sampling or gaps, how does this limit what youcan learn about the underlying periodicity? how do you handle non-sinusoidal periodic behavior?

    This is an extremely rich area---today we'll just scratch the surface andlearn some basic principles

  • 7/30/2019 Error analysis lecture 22

    6/28

    Physics 509 6

    Fourier decomposition

    The basis for most periodicity analyses is the Fourier decomposition:any smooth function over the interval -T/2 to +T/2 can be written as aseries expansion of sines and cosines:

    y t=n=0

    [an cos n0 tbnsin n0 t]

    with an=2

    TT/2

    T/2

    dt y tcosn0 t bn=2

    TT/2

    T/2

    dt y tsin n0 t

    and o=2

    T

  • 7/30/2019 Error analysis lecture 22

    7/28

    Physics 509 7

    Fourier transform

    In the limit that T , this becomes the Fourier transform:

    An obvious periodicity analysis would be to a Fourier transform of thedata, and then to test whether the amplitude of any frequencycomponent is inconsistent with zero.

    This is the conceptual basis for many different periodicity tests, but isn'texactly how they are implemented.

    y t=

    df Y fe2 i f t

    where Y f=

    dt y te2 i f t

  • 7/30/2019 Error analysis lecture 22

    8/28

    Physics 509 8

    Nyquist theorem

    Usually we have finite sampling of our data. Suppose we sample ourdata at regular time intervals separated by t. In principle we aremissing information, since we don't know what the waveform does inbetween samples.

    But the Nyquist theorem may save us:If the Fourier transform of the true continuous waveform contains nofrequency component higher than f

    c, then samples at t

  • 7/30/2019 Error analysis lecture 22

    9/28

    Physics 509 9

    Aliasing

    Aliasing is the appearance of a periodic signal at the wrong frequencydue to undersampling:

    In this diagram, both sine waves fit the data equally well. The red curve has

    frequency f=0.9. The sampling frequency is fs=1, and the Nyquist frequency isfc=

    fs/2=0.5. Given our sampling frequency, we'd truncate the series at f=0.5

    and conclude that the power was at f=0.1

    Generally, power at a high frequency f can also appear at |f Nfs|, where N isan integer. When f is smaller than f

    cthen the minimum frequency from this

    expression occurs for N=0, and there's no confusion. In the above figure,|0.9-N| has its minimum of 0.1 at N=1, and we conclude there's power at this

    frequency.

  • 7/30/2019 Error analysis lecture 22

    10/28

    Physics 509 10

    The Rayleigh Power test: first seen in Lecture 7

  • 7/30/2019 Error analysis lecture 22

    11/28

    Physics 509 11

    Rayleigh power periodicity test

    Imagine doing a randomwalk in 2D. If all directions(phases) equally likely, nonet displacement. If somephases more likely than

    others, on average you geta net displacement.

    This motivates the

    Rayleigh power statistic:

    S=i=1

    N

    sin ti2

    i=1

    N

    cos ti2

    Really just the length(squared) of thedisplacement vector fromthe origin. For the werewolf

    data, S=8167.

    This is an unbinned test!

  • 7/30/2019 Error analysis lecture 22

    12/28

    Physics 509 12

    Null hypothesis expectation for Rayleigh power

    So S=8167. Is that likely or not? What do we expect to get?

    If no real time variation, all phases are equally likely. It's like arandom walk in 2D. By Central Limit Theorem, total displacementin x or in y should be Gaussian with mean 0 and variance N2:

    2=1

    20

    2

    cos2 d=

    1

    20

    2

    sin2d=

    1

    2

    Since average displacements in x and y are uncorrelated (you cancalculate the covariance to show this), the joint PDF must be

    Px , y=2

    Nexp [ 1N x2y2 ]

    Since average displacements in x and y are uncorrelated (you cancalculate the covariance to show this), the joint PDF must be

    We can do a change of variables to get this as a 1D PDF in s=r2(marginalizing over the angle):

    Ps=1

    Nes/N

  • 7/30/2019 Error analysis lecture 22

    13/28

    Physics 509 13

    So, do werewolves come out with the full moon?

    Data set had S=8167 for N=885. How likely is that?

    Assuming werewolf sightings occur randomly in time, then theprobability of getting s>8167 is:

    Ps=8167

    1885

    es /885=exp [8167/885]=104

    Because this is a very small probability, we conclude thatwerewolves DO come out with the full moon.

    (Actually, we should only conclude that their appearances varywith a period of 28 days---maybe they only come out during thenew moon ...)

    Data was actually drawn from a distribution:

    Pt 0.90.1sin t

  • 7/30/2019 Error analysis lecture 22

    14/28

    Physics 509 14

    What if you don't know the frequency?

    The Rayleigh power is straightforward if you know the frequency youwant to look at. What if you wanted to try other frequencies? You couldcalculate the Rayleigh power at all frequencies, then make a plot:

    It's easy to find the biggest peakover the range you searched. Butyou pay a trials penalty. Theprobability of any one frequencyhaving a Rayleigh power greater

    than S is exp(-S/N). If you testedm independent frequencies, theodds of getting at least one peakthat large is now:

    Prob=11expS/Nm

  • 7/30/2019 Error analysis lecture 22

    15/28

    Physics 509 15

    How many independent frequencies?

    We could get the probability of seeing a peak this large from:

    But how many independentfrequencies

    do we use? In the plot to the left, 1000values of omega are plotted, but mostfrequencies are not independent, asindicated by the width.

    Best solution: use Monte Carlo data setsto estimate the probability that the largestpeak is bigger than S.

    Second-best rule of thumb: Each peakhas a width of d=2/T, where T is thelength of the entire data set. Here T=365days, so d=0.017. We then estimatethat there should be approximately(0.5-0.1)/0.017 = 23 independentfrequencies over this range.

    Prob=11exp S/Nm

    Ad t /Di d t f th R l i h

  • 7/30/2019 Error analysis lecture 22

    16/28

    Physics 509 16

    Advantages/Disadvantages of the RayleighPower Test

    Advantages:

    1) Easy to implement

    2) Analytic solution fordistribution of the Rayleighpower at any one frequency

    3) Great for unbinned data,such as arrival times of events.

    Disadvantages:

    1) Not obviously useful forbinned data

    2) Rayleigh power distribution isdistorted if there are gaps in thedata

    3) If data is periodic on multiplefrequencies (more than onesignificant peak), it's not clearwhat to do about it

  • 7/30/2019 Error analysis lecture 22

    17/28

    Physics 509 17

    Gappy Data

    Consider the case where you onlyobserve data some of the time---forexample, a 2-week observing cycleset by the moon.

    This produces a modulation of thedata that is itself periodic!

    The nominal Rayleighpower is absurd---a hugeperiodicity is seen justfrom the observingroutine.

  • 7/30/2019 Error analysis lecture 22

    18/28

    Physics 509 18

    What to do when you have gappy data

    In any periodicity test you need to be very careful about missing gaps inthe data, since the frequency spectrum of when the detector is on vs. offwill itself introduce frequency components into the analysis. Somepossible solutions:

    1) Use Monte Carlo to calculate the expected distribution of the teststatistic, including the effects of the gaps, and use the results to interprethow likely or unlikely your observed value of the test statistic is.

    2) In some cases, you may be able to calculate the effect of the gaps on

    the distribution of the test statistic analytically (Rayleigh power is such acase).

    3) Construct a test statistic that somehow takes into account the gaps inthe data---we'll see an example of this later.

    BE VERY SKEPTICAL OF CLAIMS FOR PERIODICITIES THATCOINCIDE WITH NATURAL FREQUENCIES OF DETECTORS OROBSERVERS (eg. 1-day, 7-day, 1-year).

  • 7/30/2019 Error analysis lecture 22

    19/28

    Physics 509 19

    Classical Periodogram

    Suppose we have N evenly sampled data points y(ti) with ti=t0+it, andi=1 ... N. The classical periodogram is a discrete Fourier transform ofthe data:

    Just as in the Rayleigh power test you can test on P() to see if anyfrequency has a significant power. But there are problems inherent tothe test---it doesn't deal well with unevenly spaced data, as written it

    doesn't include uncertainties on the measurements, and finally it canhave bad aliasing problems.

    P= 1N [ iy ticos ti

    2

    i y tisin ti 2

    ]The independent frequencies are then n=

    2n

    T

    with n=0,1,..., N/2

  • 7/30/2019 Error analysis lecture 22

    20/28

    Physics 509 20

    Lomb-Scargle Periodogram

    A generalization to deal with unevenly spaced data with equal errors:

    This looks complicated, but it's basically the regular periodogramadapted to handle unevenly spaced data. In the limit of equal spacing,it actually reduces to the classical result.

    P=1

    22 [ y tiy cos ti]

    2

    cos2ti

    [ y tiy sin ti]2

    sin2ti y=

    1

    Ni=1

    N

    y ti2=

    1

    N1i=1

    N

    y ti y 2

    tan 2= sin2 ti cos 2 ti

  • 7/30/2019 Error analysis lecture 22

    21/28

    Physics 509 21

    Properties of the Lomb-Scargle periodogram

    The most important feature of the Lomb-Scargle periodogram is thesignificance of the power at an individual frequency:

    You still have to worry about the number of independent frequenciesyou test to account for trials factors, which can be handled in the sameway as for the Rayleigh power test:

    See ApJ 263:835-753 for details on the Lomb-Scargle periodogram,including generalizations to the case where different data points havedifferent error bars.

    ProbPz=exp z

  • 7/30/2019 Error analysis lecture 22

    22/28

    Physics 509 22

    Maximum Likelihood for periodicity

    An alternative approach is to do maximum likelihood hypothesis testing.Imagine fitting your data in an ML fit to:

    There are three free parameters in the fit. Look at the value of A anddecide if it is consistent with zero. In fact, by the likelihood ratiotheorem the quantity:

    will be distributed as a 2 with 2 degrees of freedom (since therestricted case of A=0 removes two degrees of freedom from theparameter space: A and .) In fact P(>z)=exp(-z).

    You can do this fit over a whole range of frequencies and use as yourtest statistic.

    y t=y0Asin t

    =2 lnL maxA freeln Lmax A0

  • 7/30/2019 Error analysis lecture 22

    23/28

    Physics 509 23

    Why use Maximum Likelihood for periodicity?

    There are a number of advantages of the ML method over the Lomb-Scargle and Rayleigh power approaches.

    1) Very straightforward to include errors

    2) No need to bin data---can even use it with individual events3) Can generalize to other shapes if you like4) Can factor out gaps in data! Suppose that you are looking forperiodicity in the rate of some process, but took data only at certain

    times. Define a windowing function W(t) such that:W(t) = 1 if detector was alive at time t, and W(t)=0 otherwiseNow fit the data to:

    Your likelihood function now knows when the detector was on andwhen it was off, so gaps don't produce any false power in the spectrum!

    y t=Wt[y0

    Asin t]

  • 7/30/2019 Error analysis lecture 22

    24/28

    Physics 509 24

    Bayesian analyses

    Bayesian analyses use a number of different approaches (see forexample Gregory Ch 13 or for details see ApJ 398: 146-168)

    At any given period, parameterize thelight curve by a variable number of bins.

    For m bins, there are the following freeparameters:

    frequency/periodphase

    value in each of the m bins

    Use a Bayesian analysis to comparethe probability of m=1 vs the probabilityof m=2, m=3, m=4, etc. Usually m=12

    bins is an adequate number. Occam'sfactors penalize models with more bins,so the m=1 (no periodicity) model isautomatically preferred unless the datademands it.

    Some epoch-folded lightcurves

    This approach is ideal whenyou have no idea what the

    light curve should look like.

  • 7/30/2019 Error analysis lecture 22

    25/28

    Physics 509 25

    Advantages of non-uniform sampling

    Consider the following Lomb-Scargle periodograms of an f=0.8signal.Top: sampling exactly once perday at noon

    Bottom: sampling once per day ata random time within the 24-hourperiod.

    Regular sampling gives strong

    alias peak at f=0.2: in factNyquist frequency is f

  • 7/30/2019 Error analysis lecture 22

    26/28

    Physics 509 26

    What when you don t know the shape of thesignal (the light curve)?

    A lot of these tests (except the Bayesian) sound a lot like doing aFourier decomposition of the signal and then testing the biggest peak.But that will not be very sensitive to non-sinusoidal signals where thepower is spread out over many different frequency components. What

    are some good general tests?A simple (but not necessarilygood) approach is to bin thedata modulo the period. Theresult is a phase diagram.

    Then test a 2 for flat!

    If you did know the shape ofthe light curve, you shouldinstead fit the light curve to thephase diagram and testwhether the amplitude isconsistent with zero.

    Th H

  • 7/30/2019 Error analysis lecture 22

    27/28

    Physics 509 27

    The H-test

    The H-test is a test for sparse (arrival time) data that is good at testingfor general periodicities. Let t1

    ... tN

    be the set of arrival times of your

    data. Using the assumed period, calculate the phase of each event by

    i=(2/) mod(t

    i,T). Now define:

    Define Zm

    2 as

    Finally, define H as

    k=1

    Ni=1

    N

    cos ki and k=1

    Ni=1

    N

    sin ki

    Zm2=2N

    k=1

    m

    k2 k

    2

    H max1m20

    Zm24m4

    Th H t t

  • 7/30/2019 Error analysis lecture 22

    28/28

    Physics 509 28

    The H-test

    Under the null hypothesis, up to about H of 23, H has the distribution

    The H-test basically considers fitting the phase diagram with varyingnumber of Fourier components, finds a best fit of sorts, and tests onthat. This means it's good for anything between broad pulses and verynarrow ones (up to about 1/20th of the width of the phase peak).

    As with other periodicity statistics, it can be applied in a scan across afrequency range if you account for the trials factor associated withtesting many, not entirely independent, frequencies. Often this is best

    done by Monte Carlo, but for some illuminating discussion, and moredescription of the H-test, see O.C. De Jager, J.W.H. Swanepoel, andB.C. Raubenheimer,Astron. Astrophys. 221, 180-190 (1989)

    ProbHh=exp [0.398h ]