{VERSION 3 0 "IBM INTEL NT" "3.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {EXCHG {PARA 0 "" 0 "" {TEXT -1 30 "First we input some librar ies:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "with(stats): readli b(randomize):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 104 "We can reset th e random number seed with the function \"randomize.\" This can be don e at any point below." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "ra ndomize(12345); # this sets the seed to 12345" }{TEXT -1 0 "" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 95 "Now we give a function to make a c ertain number of plots of an AR(1) with Gaussian white noise:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 63 "ar1_gaussian := proc(num_plo ts, time_ser_length, c, phi, sigma)" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 16 " local i,t,k,y;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 33 " y := arra y(0..time_ser_length);" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 12 " y[0] := 0;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 30 " for i from 1 to num_plots \+ do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 38 " for t from 1 to time_ser_ length do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 62 " y[t] := c + phi* y[t-1] + sigma*stats[random, normald](1)" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 7 " od;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 89 " prin t(plot(y[k],k=0..time_ser_length,numpoints=10*time_ser_length+1,adapti ve=false));" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 5 " od;" }}{PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 4 "end:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 181 "S o to get 2 plots of a time series of length 500 based on the AR(1) pro cess Y_t = c + phi * Y_\{t-1\} + eps_t with eps_t a Gaussian white noi se, with c=0, phi=1, and sigma=1, we type:" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 26 "ar1_gaussian(2,500,0,1,1);" }{TEXT -1 0 "" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 100 "Now we give a similar program, ex cept that it uses noise that is +1 or -1 each with probability 1/2." } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 67 "ar1_disc_uniform := proc(n um_plots, time_ser_length, c, phi, sigma)" }{TEXT -1 0 "" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 16 " local i,t,k,y;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 33 " y := array(0..time_ser_length);" }}{PARA 0 "> " 0 " " {MPLTEXT 1 0 12 " y[0] := 0;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 30 " for i from 1 to num_plots do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 38 " \+ for t from 1 to time_ser_length do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 81 " y[t] := c + phi*y[t-1] + sigma*(2*stats[random, discreteun iform[0,1]](1)-1)" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 7 " od;" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 89 " print(plot(y[k],k=0..time_ser_l ength,numpoints=10*time_ser_length+1,adaptive=false));" }}{PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 5 " od;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "end: " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 20 "Now for a few tests:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "randomize(123);" }{TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "ar1_disc_uniform(1,6 0,0,1,1);" }{TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "ar1_disc_uniform(1,600,0,1,1);" }{TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 80 "Now we use a Cauchy distribution as our noise. This should look very different:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "ar1_cauchy := proc(num_plots, time_ser_length, c, phi, sigma)" } }{PARA 0 "> " 0 "" {MPLTEXT 1 0 16 " local i,t,k,y;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 33 " y := array(0..time_ser_length);" }}{PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 12 " y[0] := 0;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 30 " for i from 1 to num_plots do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 38 " for t from 1 to time_ser_length do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 65 " y[t] := c + phi*y[t-1] + sigma*stats[random,cau chy[0,1]](1)" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 7 " od;" }}{PARA 0 " > " 0 "" {MPLTEXT 1 0 89 " print(plot(y[k],k=0..time_ser_length,num points=10*time_ser_length+1,adaptive=false));" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 5 " od;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "end:" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 19 "Now for a test run:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "ar1_cauchy(2,500,0,1,1);" }{TEXT -1 0 "" }}}}{MARK "3 0 1" 0 }{VIEWOPTS 1 1 0 1 1 1803 }