summaryrefslogtreecommitdiffstats
path: root/R Scripts
diff options
context:
space:
mode:
authorBen Green <bgreen@g.harvard.edu>2015-09-13 11:11:10 -0400
committerBen Green <bgreen@g.harvard.edu>2015-09-13 11:11:13 -0400
commit754bc37b60d5efbcf0ddad7b991f6effafe2237d (patch)
tree42b90919780df34ab0c5465be3ae67238ad60740 /R Scripts
parent750ce1282d4604df96ab9a3d676dba448d9d838f (diff)
downloadcriminal_cascades-754bc37b60d5efbcf0ddad7b991f6effafe2237d.tar.gz
changed background model from sin^2 to sin
Diffstat (limited to 'R Scripts')
-rw-r--r--R Scripts/fit-background.R8
1 files changed, 4 insertions, 4 deletions
diff --git a/R Scripts/fit-background.R b/R Scripts/fit-background.R
index d1799cd..73ab6b2 100644
--- a/R Scripts/fit-background.R
+++ b/R Scripts/fit-background.R
@@ -17,14 +17,14 @@ counts = as.vector(t)
infs = data.frame(days,counts)
# define background function
-fit = function(x, lambda, A, phi) {lambda + A*(sin((pi/365)*x+phi))^2}
-fit_form = counts ~ lambda + A*(sin((pi/365)*days+phi))^2
+fit = function(x, lambda, A, phi) {lambda + A*(sin((2*pi/365.24)*x+phi))}
+fit_form = counts ~ lambda + A*(sin((2*pi/365.24)*days+phi))
# explore data
plot(days,counts)
-curve(fit(x, lambda=1, A=12, phi=2.8), add=TRUE ,lwd=2, col="steelblue")
+curve(fit(x, lambda=3, A=2, phi=4), add=TRUE ,lwd=4, col="steelblue")
-res = nls(formula=fit_form, data=infs, start=list(lambda=1, A=12, phi=2.8))
+res = nls(formula=fit_form, data=infs, start=list(lambda=3, A=2, phi=4))
co = coef(res); co
plot(t)