17
MATH420 Section 0101 1 Project 1 Sean Pannella, Lauren Fox [email protected], [email protected] 1 Abstract In the project, we modelled the aids epidemic and analyzed the sensitivity of our model. The goals of this project are to develop and test methods for fitting parameters of the modified SIR model we developed to the data, and to determine how the parameters that best fit the data depend on the data itself; in particular, we want to quantify what the uncertainty in the parameters is for a given amount of uncertainty in the data. We used data from all of US, Baltimore, Boston, Chicago, Detroit, Los Angeles, Miami, New York, San Francisco, and Washington D.C. We found that α closely followed by λ were the most sensitive parameters. We also found that different locations had different parameters change to the same noise. 2 Introduction In this project our goal is to model the aids epidemic. Modeling epidemics is important for science and public policy. It can be helpful for prevention of the disease or for controlling the spread of the disease. An epidemic is defined as a widespread occurrence of an infectious disease in a community at a particular time. In the US, the Aids epidemic started around 1982 and is still taking place today. Aids is considered an infectious disease, this means that it can be transferred to others by various means. Unfortunately, people do not recover from aids, once they get the disease, it stays with them until death. To sum it up, AIDS started with no one being infected, then was transferred by those infected to those in our population that have not been infected, and then some people who are infected die. In our project we used the SIg (susceptible, infected, and growth rate) model to model this epidemic. There are a few assumptions that we make in this model. First we assume that there is a sub-population that is susceptible to Aids and this population may grow over time. This means they are not born with aids, however they all have the chance to get it. The next assumption is that infected individuals spread the disease to the susceptible individuals, who then stay infected indefinitely. Lastly, we assume a closed population where people can only be classified in one category of susceptible or infected. Therefore S+I=N current where S is the number of susceptible, I is the total number of infected and N current is the total number of people currently in the system. This number changes based on the growth rate g. 3 Model 3.1 Model Definition dS dt = λ(μ × N - S×I N ) dI dt = λ( S×I N - v × I ) dR dt = λ × v × I where: λ = p × N,μ = q (λ×N) and v = r λ Initial conditions: S(0), I (0) 0, 3.2 Parameters N controls the size of the outbreak λ controls the rate of outbreak, μ and v are rates of the renewal (new susceptible) and recovery/removal processes relative to the infection process.

Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox [email protected], [email protected] 1 Abstract In the project, we modelled

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

MATH420 Section 0101 1

Project 1

Sean Pannella, Lauren Fox

[email protected], [email protected]

1 Abstract

In the project, we modelled the aids epidemic and analyzed the sensitivity of our model. The goals of this project are todevelop and test methods for fitting parameters of the modified SIR model we developed to the data, and to determine howthe parameters that best fit the data depend on the data itself; in particular, we want to quantify what the uncertainty in theparameters is for a given amount of uncertainty in the data. We used data from all of US, Baltimore, Boston, Chicago, Detroit,Los Angeles, Miami, New York, San Francisco, and Washington D.C. We found that α closely followed by λ were the mostsensitive parameters. We also found that different locations had different parameters change to the same noise.

2 Introduction

In this project our goal is to model the aids epidemic. Modeling epidemics is important for science and public policy. It canbe helpful for prevention of the disease or for controlling the spread of the disease. An epidemic is defined as a widespreadoccurrence of an infectious disease in a community at a particular time. In the US, the Aids epidemic started around 1982 andis still taking place today. Aids is considered an infectious disease, this means that it can be transferred to others by variousmeans. Unfortunately, people do not recover from aids, once they get the disease, it stays with them until death. To sum it up,AIDS started with no one being infected, then was transferred by those infected to those in our population that have not beeninfected, and then some people who are infected die. In our project we used the SIg (susceptible, infected, and growth rate)model to model this epidemic.

There are a few assumptions that we make in this model. First we assume that there is a sub-population that is susceptibleto Aids and this population may grow over time. This means they are not born with aids, however they all have the chanceto get it. The next assumption is that infected individuals spread the disease to the susceptible individuals, who then stayinfected indefinitely. Lastly, we assume a closed population where people can only be classified in one category of susceptibleor infected. Therefore S+I=Ncurrent where S is the number of susceptible, I is the total number of infected and Ncurrent isthe total number of people currently in the system. This number changes based on the growth rate g.

3 Model

3.1 Model DefinitiondSdt = λ(µ×N − S×I

N )

dIdt = λ(S×IN − v × I)

dRdt = λ× v × I

where: λ = p×N,µ = q(λ×N) and v = r

λ Initial conditions: S(0), I(0) ≥ 0,

3.2 Parameters

N controls the size of the outbreak

λ controls the rate of outbreak, µ and v are rates of the renewal (new susceptible) and recovery/removal processes relative tothe infection process.

Page 2: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

2 4 SENSITIVITY

There are two more parameters that determine the relative sizes of S(0), I(0), and R(0), whose sum we have called N . Forexample, we could use dimensionless parameters.

α = I(0)/N

β = R(0)/N.

3.3 Units

If time 0 is early in the outbreak, it maybe reasonable to assume that β is essentially 0. Modified the SIR model so nowwe are using the SIg model (r = 0 but q 0) which means we aren’t modelling the removal process relative to the infectiousprocess. The variables S, I and R have units of “population”. A unit of population could be one person, but sometimes otherunits are used; e.g., census data is often tabulated in units of thousands of people. The derivatives dS

dt , dIdt , dRdt have units ofpopulation/time. Therefore:

p has units of 1/(population · time).

q has units of population/time.

r has units of 1/time.

4 Sensitivity

4.1 Dataset

Data from the following locations were used. The data came from AIDS Public Use (Vintage 2002) set from CDC Wonder.And the years 1982 to 2001 were used.

Name of Location Number Marker

US 1Baltimore 2Boston 3Chicago 4Detroit 5Los Angeles 6Miami 7New York 8San Francisco 9Washington D.C. 10

4.2 How Noise was Applied

4.2.1 Types of NoiseAll the noises applied to the data were multiplicative Gaussian noise with the following distributions.

Page 3: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

3

Noise Label µ σ2

Noise 1 -2 18

Noise 2 -2 12

Noise 3 -2 1Noise 4 -1 1

8Noise 5 -1 1

2Noise 6 -1 1Noise 7 0 1

8Noise 8 0 1

2Noise 9 0 1

4.2.2 Application of the NoiseLet A = original data sample and let X NormalDistribution[µ,σ2] then A′ = A× Exp(X + 1)

4.2.3 Use of the NoiseOne the data was perturbed it was then fit again with 400 max function calls while using MATLAB’s fminsearch. The initialposition for each search for each location was the optimal parameter values for that location before the data was perturbed.In most cases the search converged before the max function calls were reached. The optimal parameters, Ey and RMS werekept for each fit. There were 3 fit trials for each noise distribution then the results of those three fit trials were averaged togive the result for that fit. There were 10 locations and 9 different noise distributions totaling 270 trials and at max 108000function evaluations.

5 Results

5.1 Overview

5.1.1 Comparison of Variable Sensitivity

Figure 1: Variable 1 is N , variable 2 is α, variable 3 is λ, variable 4 is µ. It can be seen that α has the most relative change ofall of the variables.

Page 4: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

4 5 RESULTS

5.1.2 Comparison of Output Sensitivity

Figure 2: Variable 1 is N , variable 2 is α, variable 3 is λ, variable 4 is µ, variable 5 is Ey , variable 6 is RMS. It can be seenthat Ey has the most relative change of all of the variables.

5.1.3 ExplanationIn our analysis we found that parameter α was the most sensitive parameter to noise and bias in the data when averaging overseveral different locations and running a few (3) trials of random number over each noise type location pair. The entire resultsdataset can be accessed on request.

5.2 Location Comparison

The multiplicative Gaussian noise will be be referred to by the following:

Noise Label µ σ2

Noise 1 -2 18

Noise 2 -2 12

Noise 3 -2 1Noise 4 -1 1

8Noise 5 -1 1

2Noise 6 -1 1Noise 7 0 1

8Noise 8 0 1

2Noise 9 0 1

Page 5: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

5.2 Location Comparison 5

5.2.1 US under 9 types of Noise

Figure 3: The top left graph is RMS, the top middle graph is Ey , the top right graph is µ, the bottom left graph is λ, thebottom middle graph is α, the bottom right graph is N . The first three types of noise are multiplicative Gaussian centered at-2 with σ = 1

8 ,12 , and1. Then the other 2 types of noise are also Gaussian with the same variances centered at -1 then 0.

5.2.2 Baltimore Maryland under 9 types of Noise

Figure 4: The top left graph is RMS, the top middle graph is Ey , the top right graph is µ, the bottom left graph is λ, thebottom middle graph is α, the bottom right graph is N . The first three types of noise are multiplicative Gaussian centered at-2 with σ = 1

8 ,12 , and1. Then the other 2 types of noise are also Gaussian with the same variances centered at -1 then 0.

Page 6: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

6 5 RESULTS

5.2.3 Looks at San Francisco under 9 types of Noise

Figure 5: The top left graph is RMS, the top middle graph is Ey , the top right graph is µ, the bottom left graph is λ, thebottom middle graph is α, the bottom right graph is N . The first three types of noise are multiplicative Gaussian centered at-2 with σ = 1

8 ,12 , and1. Then the other 2 types of noise are also Gaussian with the same variances centered at -1 then 0.

5.2.4 ExplanationIt can be seen that different locations were impacted by the noise in different ways for instance for US the addition of noise 1spiked the change in α and λ. While for Baltimore both α and λ change the same for all of the different noises.

5.3 Noise Type Comparison

Name of Location Number Marker

US 1Baltimore 2Boston 3Chicago 4Detroit 5Los Angeles 6Miami 7New York 8San Francisco 9Washington D.C. 10

Page 7: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

5.3 Noise Type Comparison 7

5.3.1 Looks at Noise Type 1 for each Location

Figure 6: The top left graph is RMS, the top middle graph is Ey , the top right graph is µ, the bottom left graph is λ, thebottom middle graph is α, the bottom right graph is N .

5.3.2 Looks at Noise Type 3 for each Location

Figure 7: The top left graph is RMS, the top middle graph is Ey , the top right graph is µ, the bottom left graph is λ, thebottom middle graph is α, the bottom right graph is N .

Page 8: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

8 7 CODE APPENDIX

5.3.3 Looks at Noise Type 7 for each Location

Figure 8: The top left graph is RMS, the top middle graph is Ey , the top right graph is µ, the bottom left graph is λ, thebottom middle graph is α, the bottom right graph is N .

5.3.4 ExplanationThese graphs show the same data as the graphs broken up by noise but this time broken up by location to focus on howdifferent locations were impacted by different noises. US overall is affected the most and this is likely due to fact that it ismultiplicative noise so with US having more cases the noise is also amplified.

6 Conclusion

This paper not only shows that α can be be quite sensitive to data but also that the shape of your data before perturbingit also has a major factor into how much a parameter will be impacted. It would have been interesting to have exploredVariance-based methods for sensitivity analysis but it did not fit so well with how the problem was posed.

7 Code Appendix

7.1 main.m

c l o s e a l l ;c l c ;c l e a r a l l ;filename = 'C:\M3C\math420\Group1\ t r u n k\ u s a i d s . t x t ' ;delimiter = ' ' ;formatSpec = '%f %[ˆ\n\ r ] ' ;fileID = fopen (filename , ' r ' ) ;dataArray = textscan (fileID , formatSpec , ' D e l i m i t e r ' , delimiter , ' Re tu rnOnEr ro r ' , false ) ;f c l o s e (fileID ) ;A = dataArray{ : , 1} ;clearvars filename delimiter formatSpec fileID dataArray ans ;tspan= 1 : 2 4 1 ;A=A ( 1 : 2 4 0 ) ;%N=p ( 1 ) ;%a l p h a =p ( 2 ) ;%lambda=p ( 3 ) ;%mu=p ( 4 ) ;B= z e r o s ( s i z e (A , 1 ) , 1 ) ;f o r i=1: s i z e (A , 1 )

B (i , 1 ) =sum (A ( 1 :i ) ) ;end

Page 9: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

7.1 main.m 9

p0=[899999 .123285547 ; 0 .031709355644176 ; 0 .0233917326804032 ; 0 . 0 2 5 3 4 8 2 2 5 9 6 6 2 8 3 ] ;p0_SI=[900000 ; 0 .0220970869120796 ; 0 . 02 4 51 8 25 3 0 59 2 73 5 ] ;lb = [ 8 5 8 5 5 2 ; 0 . 0 0 0 0 0 1 ; 0 . 0 0 0 0 0 1 ; 0 . 0 0 0 0 0 1 ] ;ub = [1000*1000*1000 ; 1 ; 1 ; 1 ] ;lb_SI = [ 8 5 8 5 5 1 ; 0 . 0 0 0 0 0 1 ; 0 . 0 0 0 0 0 1 ] ;ub_SI = [1000*1000*1000 ; 1 ; 1 ] ;[y_opt ,fval ] = sir_optimize_1 (p0 , A , tspan ) ;[y_opt_SI ,fval_SI ] = sir_optimize_1_SI (p0_SI , A , tspan ) ;y_optfvals q r t (fval / 2 4 0 )y_opt_SIfval_SIs q r t (fval_SI / 2 4 0 )[t ,y ]=sir_solve_p ( tspan , y_opt ) ;c l o s e a l l ;f i g u r e ( 1 ) , c l f ;ho ld on ;y l a b e l ({ ' Number o f Peo p l e I n f e c t e d ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' F i t t e d SIg Model ' }) ;p l o t (t , y , ' l i n e w i d t h ' , 2 ) ;p l o t (tspan ( 1 : ( s i z e (B , 1 ) ) ) , B , ' k* ' , ' m a r k e r s i z e ' , 10) ;l e g e n d ( ' s u s c e p t i b l e ' , ' i n f e c t e d ' , ' r e c o v e r e d ' , ' d a t a ' )s e t ( gca , ' F o n t S i z e ' , 15 )ho ld off ;dI = d i f f (y ( : , 2 ) ) ;f i g u r e ( 2 ) ;ho ld on ;y l a b e l ({ ' Number o f Peo p l e Newly I n f e c t e d ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' F i t t e d SIg Model ' }) ;p l o t (tspan ( 1 : ( s i z e (dI , 1 ) ) ) , dI , ' l i n e w i d t h ' , 2 ) ;p l o t (tspan ( 1 : ( s i z e (A , 1 ) ) ) , A , ' k* ' , ' m a r k e r s i z e ' , 10) ;l e g e n d ( ' i n f e c t e d ' , ' d a t a ' )s e t ( gca , ' F o n t S i z e ' , 15 )ho ld off ;r = (dI−A ) . ˆ 2 ;f i g u r e ( 3 ) ;ho ld on ;y l a b e l ({ ' Squared D i f f e r e n c e i n Number o f I n f e c t e d Pe op l e ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' R e s i d u a l s f o r SIg ' }) ;scatter (tspan ( 1 : ( s i z e (r , 1 ) ) ) ,r ) ;ho ld off ;[t ,y ]=SI ( tspan , y_opt_SI ) ;f i g u r e ( 4 ) ;ho ld on ;y l a b e l ({ ' Number o f Peo p l e I n f e c t e d ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' F i t t e d SI Model ' }) ;p l o t (t , y , ' l i n e w i d t h ' , 2 ) ;p l o t (tspan ( 1 : ( s i z e (B , 1 ) ) ) , B , ' k* ' , ' m a r k e r s i z e ' , 10) ;l e g e n d ( ' s u s c e p t i b l e ' , ' i n f e c t e d ' , ' r e c o v e r e d ' , ' d a t a ' )s e t ( gca , ' F o n t S i z e ' , 15 )ho ld off ;dI_SI = d i f f (y ( : , 2 ) ) ;f i g u r e ( 5 ) ;ho ld on ;y l a b e l ({ ' Number o f Peo p l e Newly I n f e c t e d ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' F i t t e d SI Model ' }) ;p l o t (tspan ( 1 : ( s i z e (dI_SI , 1 ) ) ) , dI_SI , ' l i n e w i d t h ' , 2 ) ;p l o t (tspan ( 1 : ( s i z e (A , 1 ) ) ) , A , ' k* ' , ' m a r k e r s i z e ' , 10) ;l e g e n d ( ' i n f e c t e d ' , ' d a t a ' )s e t ( gca , ' F o n t S i z e ' , 15 )ho ld off ;r = (dI_SI−A ) . ˆ 2 ;f i g u r e ( 6 ) ;ho ld on ;y l a b e l ({ ' Squared D i f f e r e n c e i n Number o f I n f e c t e d Pe op l e ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' R e s i d u a l s f o r SI ' }) ;scatter (tspan ( 1 : ( s i z e (r , 1 ) ) ) ,r ) ;ho ld off ;f i g u r e ( 7 ) ;ho ld on ;y l a b e l ({ ' Number o f Peo p l e Newly I n f e c t e d ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' SIg vs SI Model ' }) ;p l o t (tspan ( 1 : ( s i z e (dI_SI , 1 ) ) ) , dI_SI , ' l i n e w i d t h ' , 1 ) ;p l o t (tspan ( 1 : ( s i z e (dI , 1 ) ) ) , dI , ' l i n e w i d t h ' , 3 ) ;

Page 10: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

10 7 CODE APPENDIX

p l o t (tspan ( 1 : ( s i z e (A , 1 ) ) ) , A , ' k* ' , ' m a r k e r s i z e ' , 10) ;l e g e n d ( ' SI ' , ' SIg ' )s e t ( gca , ' F o n t S i z e ' , 15 )ho ld off ;

7.2 main2.m

c l o s e a l l ;c l c ;c l e a r a l l ;filename = 'C:\M3C\math420\Group1\ t r u n k\ u s a i d s . t x t ' ;delimiter = ' ' ;formatSpec = '%f %[ˆ\n\ r ] ' ;fileID = fopen (filename , ' r ' ) ;dataArray = textscan (fileID , formatSpec , ' D e l i m i t e r ' , delimiter , ' Re tu rnOnEr ro r ' , false ) ;f c l o s e (fileID ) ;A = dataArray{ : , 1} ;clearvars filename delimiter formatSpec fileID dataArray ans ;tspan= 1 : 2 4 1 ;tspan1= 1 : 1 8 1 ;A1=A ( 1 : 2 4 0 ) ;%N=p ( 1 ) ;%a l p h a =p ( 2 ) ;%lambda=p ( 3 ) ;%mu=p ( 4 ) ;B= z e r o s ( s i z e (A1 , 1 ) , 1 ) ;f o r i=1: s i z e (A1 , 1 )

B (i , 1 ) =sum (A1 ( 1 :i ) ) ;endp0=[899987 .991967296 ; 0 .0146514273653253 ; 0 .0289579082266554 ; 1e−06];p0_SI=[900000 .019854036 ; 0 .0142396016092235 ; 0 . 02 8 95 7 73 7 15 9 51 9 1 ] ;lb = [ 8 5 8 5 5 2 ; 0 . 0 0 0 0 0 1 ; 0 . 0 0 0 0 0 1 ; 0 . 0 0 0 0 0 1 ] ;ub = [1000*1000*1000 ; 1 ; 1 ; 1 ] ;lb_SI = [ 8 5 8 5 5 1 ; 0 . 0 0 0 0 0 1 ; 0 . 0 0 0 0 0 1 ] ;ub_SI = [1000*1000*1000 ; 1 ; 1 ] ;D=A1 ( 1 8 1 : 2 4 0 ) ;A=A1 ( 1 : 1 8 0 ) ;[y_opt ,fval ] = sir_optimize_1 (p0 , A , tspan1 ) ;

%[ y op t , f v a l , e x i t f l a g , o u t p u t ] = s i r o p t i m i z e 1 s a ( p0 , A, t span1 , lb , ub ) ;r = EYError2 ( 1 8 1 : 2 4 1 , y_opt , D ) ;[y_opt_SI ,fval_SI ] = sir_optimize_1_SI (p0_SI , A , tspan1 ) ;

%[ y o p t S I , f v a l S I , e x i t f l a g , o u t p u t ] = s i r o p t i m i z e 1 S I s a ( p0 SI , A, t span1 , l b S I , ub SI ) ;r_SI = EYError2SI ( 1 8 1 : 2 4 1 , y_opt_SI , D ) ;d i s p ( ' SIg ' )d i s p ( ' ================================ ' )y_optfvals q r t (fval / 1 8 1 )rs q r t (r / 6 0 )d i s p ( ' ================================ ' )d i s p ( ' SI ' )d i s p ( ' ================================ ' )y_opt_SIfval_SIs q r t (fval_SI / 1 8 1 )r_SIs q r t (r_SI / 6 0 )d i s p ( ' ================================ ' )[t ,y ]=sir_solve_p ( tspan , y_opt ) ;c l o s e a l l ;f i g u r e ( 1 ) , c l f ;ho ld on ;y l a b e l ({ ' Number o f Peo p l e I n f e c t e d ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' F i t t e d SIg Model ' }) ;p l o t (t , y , ' l i n e w i d t h ' , 2 ) ;p l o t (tspan ( 1 : ( s i z e (B , 1 ) ) ) , B , ' k* ' , ' m a r k e r s i z e ' , 10) ;l e g e n d ( ' s u s c e p t i b l e ' , ' i n f e c t e d ' , ' r e c o v e r e d ' , ' d a t a ' )s e t ( gca , ' F o n t S i z e ' , 15 )ho ld off ;dI = d i f f (y ( : , 2 ) ) ;f i g u r e ( 2 ) ;ho ld on ;y l a b e l ({ ' Number o f Peo p l e Newly I n f e c t e d ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;

Page 11: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

7.3 EYError2.m 11

t i t l e ({ ' F i t t e d SIg Model ' }) ;p l o t (tspan ( 1 : ( s i z e (dI , 1 ) ) ) , dI , ' l i n e w i d t h ' , 2 ) ;p l o t (tspan ( 1 : ( s i z e (A1 , 1 ) ) ) , A1 , ' k* ' , ' m a r k e r s i z e ' , 10) ;l e g e n d ( ' i n f e c t e d ' , ' d a t a ' )s e t ( gca , ' F o n t S i z e ' , 15 )ho ld off ;r = (dI−A1 ) . ˆ 2 ;f i g u r e ( 3 ) ;ho ld on ;y l a b e l ({ ' Squared D i f f e r e n c e i n Number o f I n f e c t e d Pe op l e ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' R e s i d u a l s f o r SIg ' }) ;scatter (tspan ( 1 : ( s i z e (r , 1 ) ) ) ,r ) ;ho ld off ;[t ,y ]=SI ( tspan , y_opt_SI ) ;f i g u r e ( 4 ) ;ho ld on ;y l a b e l ({ ' Number o f Peo p l e I n f e c t e d ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' F i t t e d SI Model ' }) ;p l o t (t , y , ' l i n e w i d t h ' , 2 ) ;p l o t (tspan ( 1 : ( s i z e (B , 1 ) ) ) , B , ' k* ' , ' m a r k e r s i z e ' , 10) ;l e g e n d ( ' s u s c e p t i b l e ' , ' i n f e c t e d ' , ' r e c o v e r e d ' , ' d a t a ' )s e t ( gca , ' F o n t S i z e ' , 15 )ho ld off ;dI_SI = d i f f (y ( : , 2 ) ) ;f i g u r e ( 5 ) ;ho ld on ;y l a b e l ({ ' Number o f Peo p l e Newly I n f e c t e d ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' F i t t e d SI Model ' }) ;p l o t (tspan ( 1 : ( s i z e (dI_SI , 1 ) ) ) , dI_SI , ' l i n e w i d t h ' , 2 ) ;p l o t (tspan ( 1 : ( s i z e (A1 , 1 ) ) ) , A1 , ' k* ' , ' m a r k e r s i z e ' , 10) ;l e g e n d ( ' i n f e c t e d ' , ' d a t a ' )s e t ( gca , ' F o n t S i z e ' , 15 )ho ld off ;r = (dI_SI−A1 ) . ˆ 2 ;f i g u r e ( 6 ) ;ho ld on ;y l a b e l ({ ' Squared D i f f e r e n c e i n Number o f I n f e c t e d Pe op l e ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' R e s i d u a l s f o r SI ' }) ;scatter (tspan ( 1 : ( s i z e (r , 1 ) ) ) ,r ) ;ho ld off ;f i g u r e ( 7 ) ;ho ld on ;y l a b e l ({ ' Number o f Peo p l e Newly I n f e c t e d ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' SIg vs SI Model ' }) ;p l o t (tspan ( 1 : ( s i z e (dI_SI , 1 ) ) ) , dI_SI , ' l i n e w i d t h ' , 1 ) ;p l o t (tspan ( 1 : ( s i z e (dI , 1 ) ) ) , dI , ' l i n e w i d t h ' , 3 ) ;p l o t (tspan ( 1 : ( s i z e (A1 , 1 ) ) ) , A1 , ' k* ' , ' m a r k e r s i z e ' , 10) ;l e g e n d ( ' SI ' , ' SIg ' )s e t ( gca , ' F o n t S i z e ' , 15 )ho ld off ;

7.3 EYError2.m

f u n c t i o n [ r ] = EYError2 ( tspan , params , data )[ t ,y ] = sir_solve_p ( tspan , params ) ;yp= d i f f (y ( : , 2 ) ) ;r = sum ( (yp−data ) . ˆ 2 ) ;

end

7.4 EYError2SI.m

f u n c t i o n [ r ] = EYError2SI ( tspan , params , data )[ t ,y ] = SI ( tspan , params ) ;yp= d i f f (y ( : , 2 ) ) ;r = sum ( (yp−data ) . ˆ 2 ) ;

end

Page 12: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

12 7 CODE APPENDIX

7.5 SI.m

f u n c t i o n [ tspan ,y ] = SI ( tspan , params )N=params ( 1 ) ;alpha=params ( 2 ) ;lambda=params ( 3 ) ;delta = l o g ( ( 1 / alpha )−1) /lambda ;g = @ (x ) 1 . / ( 1 + exp(−x ) ) ;IEqn = @ (t ) N . *g (lambda . * (t−delta ) ) ;DEqn = @ (t ) [N−IEqn (t ) ; IEqn (t ) ; z e r o s ( 1 , l e n g t h (t ) ) ] ;y = DEqn (tspan ) ;y=y ' ;

end

7.6 sir solve.m

f u n c t i o n [ t ,x ] = sir_solve ( tspan , y0 , p )% y0 = [N a l p h a ] ;% p0 = [ lambda mu ] ;N = y0 ( 1 ) ;alpha=y0 ( 2 ) ;I0=alpha*N ;S0=N−I0 ;R0=0;u0=[S0 I0 R0 ] ;options = odeset ( ' Re lTo l ' , 1e−4, ' NonNegat ive ' , [ 1 2 3 ] ) ;[t ,x ] = ode45 (@sir , tspan , u0 , options ) ;f u n c t i o n [ dx ] = sir ( t , x )

dx = [ 0 ; 0 ; 0 ] ;lambda = p ( 1 ) ;mu = p ( 2 ) ;dx ( 1 ) = lambda*(mu*N−(1/N ) * x ( 1 ) * x ( 2 ) ) ;dx ( 2 ) = lambda * ( ( 1 /N ) * x ( 1 ) * x ( 2 ) ) ;dx ( 3 ) = 0 ;

endend

7.7 sir solve p.m

f u n c t i o n [ t ,x ] = sir_solve_p ( tspan , params )N=params ( 1 ) ;alpha=params ( 2 ) ;lambda=params ( 3 ) ;mu=params ( 4 ) ;y0=[N alpha ] ;p0=[lambda mu ] ;[ t ,x ] = sir_solve ( tspan , y0 , p0 ) ;

end

7.8 sir optimize 1.m

f u n c t i o n [p_opt ,fval ] = sir_optimize_1 (params , data , tspan )[p_opt ,fval ] = fminsearch (@sir_disc_nested , params ) ;

f u n c t i o n disc = sir_disc_nested (p )%N=p ( 1 ) ;%a l p h a =p ( 2 ) ;%lambda=p ( 3 ) ;%mu=p ( 4 ) ;disc = EYError2 ( tspan , p , data ) ;

endend

Page 13: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

7.9 sir optimize 1 SI.m 13

7.9 sir optimize 1 SI.m

f u n c t i o n [p_opt ,fval ] = sir_optimize_1_SI (params , data , tspan )[p_opt ,fval ] = fminsearch (@sir_disc_nested , params ) ;f u n c t i o n disc = sir_disc_nested (p )

%N=p ( 1 ) ;%a l p h a =p ( 2 ) ;%lambda=p ( 3 ) ;disc = EYError2SI ( tspan , p , data ) ;

endend

7.10 gaussnoiser.m

f u n c t i o n [ output ] = gaussnoiser ( A , mean , s t d )noise = exp ( s t d . * randn ( s i z e (A , 1 ) , s i z e (A , 2 ) ) +mean ) +1;output = A . *noise ;

end

7.11 tester.m

f u n c t i o n [ y_opt ,fval ,rms ] = tester ( A ,city ,number ,p0 )postfix = strcat ( ' ' ,city , ' ' , num2s t r (number ) , ' . png ' ) ;tspan= 1 : 2 4 1 ;A=A ( 1 : 2 4 0 ) ;B= z e r o s ( s i z e (A , 1 ) , 1 ) ;f o r i=1: s i z e (A , 1 )

B (i , 1 ) =sum (A ( 1 :i ) ) ;end%p0 ( 1 ) =B( s i z e (A, 1 ) ) * 2 ;[y_opt ,fval ] = sir_optimize_1 (p0 , A , tspan ) ;rms = s q r t (fval / 2 4 0 ) ;[t ,y ]=sir_solve_p ( tspan , y_opt ) ;c l o s e a l l ;f i g u r e ( ' V i s i b l e ' , ' o f f ' ) , c l f ;ho ld on ;y l a b e l ({ ' Number o f Peo p l e I n f e c t e d ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' F i t t e d SIg Model ' }) ;p l o t (t , y , ' l i n e w i d t h ' , 2 ) ;p l o t (tspan ( 1 : ( s i z e (B , 1 ) ) ) , B , ' k* ' , ' m a r k e r s i z e ' , 10) ;l e g e n d ( ' s u s c e p t i b l e ' , ' i n f e c t e d ' , ' r e c o v e r e d ' , ' d a t a ' )s e t ( gca , ' F o n t S i z e ' , 15 )ho ld off ;saveas ( gcf ,strcat ( ' t o t a l ' ,postfix ) , ' png ' ) ;dI = d i f f (y ( : , 2 ) ) ;f i g u r e ( ' V i s i b l e ' , ' o f f ' ) , c l f ;ho ld on ;y l a b e l ({ ' Number o f Peo p l e Newly I n f e c t e d ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' F i t t e d SIg Model ' }) ;p l o t (tspan ( 1 : ( s i z e (dI , 1 ) ) ) , dI , ' l i n e w i d t h ' , 2 ) ;p l o t (tspan ( 1 : ( s i z e (A , 1 ) ) ) , A , ' k* ' , ' m a r k e r s i z e ' , 10) ;l e g e n d ( ' i n f e c t e d ' , ' d a t a ' )s e t ( gca , ' F o n t S i z e ' , 15 )ho ld off ;saveas ( gcf ,strcat ( ' new ' ,postfix ) , ' png ' ) ;r = (dI−A ) . ˆ 2 ;f i g u r e ( ' V i s i b l e ' , ' o f f ' ) , c l f ;ho ld on ;y l a b e l ({ ' Squared D i f f e r e n c e i n Number o f I n f e c t e d Pe op l e ' }) ;x l a b e l ({ ' Number o f Months s i n c e Dec 31 1981 ' }) ;t i t l e ({ ' R e s i d u a l s f o r SIg ' }) ;scatter (tspan ( 1 : ( s i z e (r , 1 ) ) ) ,r ) ;ho ld off ;saveas ( gcf ,strcat ( ' r e s i d u a l s ' ,postfix ) , ' png ' ) ;end

Page 14: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

14 7 CODE APPENDIX

7.12 newmain.m

filename = 'C:\M3C\math420\ v e c t o r i z e d D a t a . t x t ' ;delimiter = '\ t ' ;formatSpec = '%f%f%f%f%f%f%f%f%f %[ˆ\n\ r ] ' ;fileID = fopen (filename , ' r ' ) ;dataArray = textscan (fileID , formatSpec , ' D e l i m i t e r ' , delimiter , ' Re tu rnOnEr ro r ' , false ) ;f c l o s e (fileID ) ;citydata = [dataArray{1: end−1}];clearvars filename delimiter formatSpec fileID dataArray ans ;labels = { ' B a l t i m o r e ' , ' Bos ton ' , ' Chicago ' , ' D e t r o i t ' , ' LosAngeles ' , ' Miami ' , ' NewYork ' , ' S a n F r a n c i s c o ' , ' Washington ' } ;noiseParams = [−2 ( 1 / 8 ) 8 −8;−2 ( 1 / 2 ) 8 −2;−2 1 8 1;−1 ( 1 / 8 ) 2 −8;−1 ( 1 / 2 ) 2 −2;−1 1 2 1 ; 0 ( 1 / 8 ) 1 −8;0 ( 1 / 2 ) 1 −2;0←↩

1 1 1 ; 0 1 ( 1 / 2 ) (−1/2) ] ;p0s = [1214 .85633400658 0.000224214452024301 0.109018888419189 −0.00178929553206651; ←↩

2337.61094240219 0.000875114493189291 0.0946396907608108 −0.00154335637249116; ←↩1058850.03940973 6.7225871926053e−07 0.16330664627642 −0.0600379330595209; ←↩113059.541701017 9.5328904166831e−08 0.220496186597724 −0.0437760421498296; ←↩311820018.503851 5.6128005706708e−08 0.119815413311129 −0.0812363807722872; ←↩2972.61888981265 0.001736550380109 0.0870704458467836 −0.00119787082878746; 94887972.4645 ←↩

1.21043899813842e−06 0.103060239254847 −0.0954674059472589; 291799645.459626 ←↩1.55262823088294e−07 0.0980966646822119 −0.0987281340260494; 3547.45272298287 0.00323292939995256 ←↩0.081407318392085 −0.00229157187247312; ] ;

BigSet= z e r o s ( 9 , 1 0 , 3 0 , 2 , 6 ) ;%N=p ( 1 ) ;%a l p h a =p ( 2 ) ;%lambda=p ( 3 ) ;%mu=p ( 4 ) ;p0 = [10000 0 . 0 2 0 . 0 2 0 . 0 0 1 ] ;skip = 5 8 ;w = 0 ;f o r c=1:9

j=0;f o r i=1:10

rng ( 0 , ' t w i s t e r ' ) ;f o r k=1:3

i f w>skipmean=noiseParams (i , 1 ) ;s t d =noiseParams (i , 2 ) ;lb=noiseParams (i , 3 ) ;ub=noiseParams (i , 4 ) ;A=citydata ( : , c ) ;p0=p0s (c , : ) ;D=gaussnoiser ( A , mean , s t d ) ;[ y_opt ,fval ,rms ] = tester ( D ,labels{c} ,j ,p0 ) ;BigSet (c ,i ,k , 1 , 1 ) =y_opt ( 1 ) ;BigSet (c ,i ,k , 1 , 2 ) =y_opt ( 2 ) ;BigSet (c ,i ,k , 1 , 3 ) =y_opt ( 3 ) ;BigSet (c ,i ,k , 1 , 4 ) =y_opt ( 4 ) ;BigSet (c ,i ,k , 1 , 5 ) =fval ;BigSet (c ,i ,k , 1 , 6 ) =rms ;endj = j + 1 ;w = w +1;w

endend

end

7.13 US.m

filename = 'C:\M3C\math420\Group1\ t r u n k\ u s a i d s . t x t ' ;delimiter = ' ' ;formatSpec = '%f %[ˆ\n\ r ] ' ;fileID = fopen (filename , ' r ' ) ;dataArray = textscan (fileID , formatSpec , ' D e l i m i t e r ' , delimiter , ' Re tu rnOnEr ro r ' , false ) ;f c l o s e (fileID ) ;A = dataArray{ : , 1} ;clearvars filename delimiter formatSpec fileID dataArray ans ;noiseParams = [−2 ( 1 / 8 ) 8 −8;−2 ( 1 / 2 ) 8 −2;−2 1 8 1;−1 ( 1 / 8 ) 2 −8;−1 ( 1 / 2 ) 2 −2;−1 1 2 1 ; 0 ( 1 / 8 ) 1 −8;0 ( 1 / 2 ) 1 −2;0←↩

1 1 1 ; 0 1 ( 1 / 2 ) (−1/2) ] ;w=0;US= z e r o s ( 1 0 , 3 , 6 ) ;skip =0;j=0;

Page 15: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

7.13 US.m 15

f o r i=1:10rng ( 0 , ' t w i s t e r ' ) ;f o r k=1:3

i f w>skipmean=noiseParams (i , 1 ) ;s t d =noiseParams (i , 2 ) ;p0=[308181 .257970646 ; 0 .0543547540092025 ; 0 .0198857489288853 ; 0 . 4 0 4 1 0 9 5 6 9 6 3 1 4 2 5 ] ;D=gaussnoiser ( A , mean , s t d ) ;[ y_opt ,fval ,rms ] = tester ( D , 'US ' ,j ,p0 ) ;US (i ,k , 1 ) =y_opt ( 1 ) ;US (i ,k , 2 ) =y_opt ( 2 ) ;US (i ,k , 3 ) =y_opt ( 3 ) ;US (i ,k , 4 ) =y_opt ( 4 ) ;US (i ,k , 5 ) =fval ;US (i ,k , 6 ) =rms ;endj = j + 1 ;w = w +1;w

endend

US_summary= z e r o s ( 1 0 , 6 , 2 ) ;BigSet_summary= z e r o s ( 9 , 1 0 , 6 , 2 ) ;f o r i=1:10

f o r k=1:6US_summary (i ,k , 1 ) = mean (US (i , : , k ) ) ;US_summary (i ,k , 2 ) = var (US (i , : , k ) ) ;

endendf o r c=1:9f o r i=1:10

f o r k=1:6BigSet_summary (c ,i ,k , 1 ) = mean (BigSet (c ,i , : , 1 , k ) ) ;BigSet_summary (c ,i ,k , 2 ) = var (BigSet (c ,i , : , 1 , k ) ) ;

endendendtotal_summary= z e r o s ( 1 0 , 1 0 , 6 , 2 ) ;f o r c=1:10

i f c==1f o r i=1:10

f o r k=1:6total_summary (c ,i ,k , 1 ) = US_summary (i ,k , 1 ) ;total_summary (c ,i ,k , 2 ) = US_summary (i ,k , 2 ) ;

endende l s ef o r i=1:10

f o r k=1:6total_summary (c ,i ,k , 1 ) = BigSet_summary (c−1,i ,k , 1 ) ;total_summary (c ,i ,k , 2 ) = BigSet_summary (c−1,i ,k , 2 ) ;

endendend

endtotal_difference = z e r o s ( 1 0 , 1 0 , 6 , 1 ) ;f o r c=1:10

i f c==1D = A ;p0=p0s (c , : ) ;[ y_opt ,fval ,rms ] = tester (D , ' t e s t e r ' , 0 ,p0 ) ;

e l s eD = citydata ( : , c−1) ;p0=p0s (c , : ) ;[ y_opt ,fval ,rms ] = tester (D , ' t e s t e r ' , 0 ,p0 ) ;

endf o r i=1:10

total_difference (c ,i , 1 ) = p0 ( 1 )−total_summary (c ,i , 1 , 1 ) ;total_difference (c ,i , 2 ) = p0 ( 2 )−total_summary (c ,i , 2 , 1 ) ;total_difference (c ,i , 3 ) = p0 ( 3 )−total_summary (c ,i , 3 , 1 ) ;total_difference (c ,i , 4 ) = p0 ( 4 )−total_summary (c ,i , 4 , 1 ) ;total_difference (c ,i , 5 ) = fval − total_summary (c ,i , 5 , 1 ) ;total_difference (c ,i , 6 ) = rms − total_summary (c ,i , 6 , 1 ) ;

endendtotal_difference = total_difference ( : , 1 : 9 , : ) ;%N=p ( 1 ) ;%a l p h a =p ( 2 ) ;%lambda=p ( 3 ) ;%mu=p ( 4 ) ;f o r i=1:9

f o r k=1:6

Page 16: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

16 7 CODE APPENDIX

t = [1 2 3 4 5 6 7 8 9 1 0 ] ;f i g u r e ( ' V i s i b l e ' , ' o f f ' ) , c l f ;ho ld on ;y l a b e l ({ ' A b s o l u t e R e s i d u a l s ' }) ;x l a b e l ({ ' L o c a t i o n ' }) ;i f k==1

t i t l e ({strcat ( ' A b s o l u t e R e s i d u a l s f o r ' , 'N ' ) }) ;e l s e i f k==2

t i t l e ({strcat ( ' A b s o l u t e R e s i d u a l s f o r ' , ' a l p h a ' ) }) ;e l s e i f k==3

t i t l e ({strcat ( ' A b s o l u t e R e s i d u a l s f o r ' , ' lambda ' ) }) ;e l s e i f k==4

t i t l e ({strcat ( ' A b s o l u t e R e s i d u a l s f o r ' , 'mu ' ) }) ;e l s e i f k==5

t i t l e ({strcat ( ' A b s o l u t e R e s i d u a l s f o r ' , ' E r r o r ' ) }) ;e l s e

t i t l e ({strcat ( ' A b s o l u t e R e s i d u a l s f o r ' , 'RMS ' ) }) ;endscatter (t ,total_difference ( : , i ,k ) ) ;ho ld off ;saveas ( gcf ,strcat ( ' s c a t t e r ' , num2s t r (i ) , ' ' , num2s t r (k ) , ' . png ' ) , ' png ' ) ;

endend

f o r k=1:6t = [1 2 3 4 5 6 ] ;f i g u r e ( ' V i s i b l e ' , ' o f f ' ) , c l f ;ho ld on ;y l a b e l ({ ' A b s o l u t e R e s i d u a l s ' }) ;x l a b e l ({ ' L o c a t i o n ' }) ;i f k==1

t i t l e ({strcat ( ' Mean A b s o l u t e R e s i d u a l s f o r ' , 'N ' ) }) ;e l s e i f k==2

t i t l e ({strcat ( ' Mean A b s o l u t e R e s i d u a l s f o r ' , ' a l p h a ' ) }) ;e l s e i f k==3

t i t l e ({strcat ( ' Mean A b s o l u t e R e s i d u a l s f o r ' , ' lambda ' ) }) ;e l s e i f k==4

t i t l e ({strcat ( ' Mean A b s o l u t e R e s i d u a l s f o r ' , 'mu ' ) }) ;e l s e i f k==5

t i t l e ({strcat ( ' Mean A b s o l u t e R e s i d u a l s f o r ' , ' E r r o r ' ) }) ;e l s e

t i t l e ({strcat ( ' Mean A b s o l u t e R e s i d u a l s f o r ' , 'RMS ' ) }) ;endb a r ( mean ( mean (total_difference ( : , : , : ) ) ) ) ;ho ld off ;saveas ( gcf ,strcat ( ' m e a n s c a t t e r ' , num2s t r (i ) , ' ' , num2s t r (k ) , ' . png ' ) , ' png ' ) ;

endrel_difference = z e r o s ( 1 0 , 1 0 , 6 , 1 ) ;f o r c=1:10

i f c==1D = A ;p0=p0s (c , : ) ;[ y_opt ,fval ,rms ] = tester (D , ' t e s t e r ' , 0 ,p0 ) ;

e l s eD = citydata ( : , c−1) ;p0=p0s (c , : ) ;[ y_opt ,fval ,rms ] = tester (D , ' t e s t e r ' , 0 ,p0 ) ;

endf o r i=1:10

rel_difference (c ,i , 1 ) = (p0 ( 1 )−total_summary (c ,i , 1 , 1 ) ) / ( p0 ( 1 ) ) ;rel_difference (c ,i , 2 ) = (p0 ( 2 )−total_summary (c ,i , 2 , 1 ) ) / ( p0 ( 2 ) ) ;rel_difference (c ,i , 3 ) = (p0 ( 3 )−total_summary (c ,i , 3 , 1 ) ) / ( p0 ( 3 ) ) ;rel_difference (c ,i , 4 ) = (p0 ( 4 )−total_summary (c ,i , 4 , 1 ) ) / ( p0 ( 4 ) ) ;rel_difference (c ,i , 5 ) = (fval − total_summary (c ,i , 5 , 1 ) ) /fval ;rel_difference (c ,i , 6 ) = (rms − total_summary (c ,i , 6 , 1 ) ) /rms ;

endendrel_difference = rel_difference ( : , 1 : 9 , : ) ;f o r i=1:9

f o r k=1:6t = [1 2 3 4 5 6 7 8 9 1 0 ] ;f i g u r e ( ' V i s i b l e ' , ' o f f ' ) , c l f ;ho ld on ;y l a b e l ({ ' R e l a t i v e Change ' }) ;x l a b e l ({ ' L o c a t i o n ' }) ;i f k==1

t i t l e ({strcat ( ' R e l a t i v e R e s i d u a l s f o r ' , 'N f o r n o i s e ' , num2s t r (i ) ) }) ;e l s e i f k==2

t i t l e ({strcat ( ' R e l a t i v e R e s i d u a l s f o r ' , ' a l p h a f o r n o i s e ' , num2s t r (i ) ) }) ;e l s e i f k==3

t i t l e ({strcat ( ' R e l a t i v e R e s i d u a l s f o r ' , ' lambda f o r n o i s e ' , num2s t r (i ) ) }) ;e l s e i f k==4

t i t l e ({strcat ( ' R e l a t i v e R e s i d u a l s f o r ' , 'mu f o r n o i s e ' , num2s t r (i ) ) }) ;

Page 17: Project 1 - Weeblylaurenfoxstat.weebly.com/.../math420_project_1.pdf · Project 1 Sean Pannella, Lauren Fox spannella@gmail.com, lfaf373@gmail.com 1 Abstract In the project, we modelled

7.13 US.m 17

e l s e i f k==5t i t l e ({strcat ( ' R e l a t i v e R e s i d u a l s f o r ' , ' E r r o r f o r n o i s e ' , num2s t r (i ) ) }) ;

e l s et i t l e ({strcat ( ' R e l a t i v e R e s i d u a l s f o r ' , 'RMS f o r n o i s e ' , num2s t r (i ) ) }) ;

endb a r (total_difference ( : , i ,k ) ) ;ho ld off ;saveas ( gcf ,strcat ( ' b a r ' , num2s t r (i ) , ' ' , num2s t r (k ) , ' . png ' ) , ' png ' ) ;

endendf o r i=1:10

f o r k=1:6t = [1 2 3 4 5 6 7 8 9 ] ;f i g u r e ( ' V i s i b l e ' , ' o f f ' ) , c l f ;ho ld on ;y l a b e l ({ ' R e l a t i v e Change ' }) ;x l a b e l ({ ' Noise Type ' }) ;i f k==1

t i t l e ({strcat ( ' R e l a t i v e R e s i d u a l s f o r ' , 'N f o r l o c a t i o n ' , num2s t r (i ) ) }) ;e l s e i f k==2

t i t l e ({strcat ( ' R e l a t i v e R e s i d u a l s f o r ' , ' a l p h a f o r l o c a t i o n ' , num2s t r (i ) ) }) ;e l s e i f k==3

t i t l e ({strcat ( ' R e l a t i v e R e s i d u a l s f o r ' , ' lambda f o r l o c a t i o n ' , num2s t r (i ) ) }) ;e l s e i f k==4

t i t l e ({strcat ( ' R e l a t i v e R e s i d u a l s f o r ' , 'mu f o r l o c a t i o n ' , num2s t r (i ) ) }) ;e l s e i f k==5

t i t l e ({strcat ( ' R e l a t i v e R e s i d u a l s f o r ' , ' E r r o r f o r l o c a t i o n ' , num2s t r (i ) ) }) ;e l s e

t i t l e ({strcat ( ' R e l a t i v e R e s i d u a l s f o r ' , 'RMS f o r l o c a t i o n ' , num2s t r (i ) ) }) ;endb a r (total_difference (i , : , k ) ) ;ho ld off ;saveas ( gcf ,strcat ( ' b a r N o i s e ' , num2s t r (i ) , ' ' , num2s t r (k ) , ' . png ' ) , ' png ' ) ;

endend