summary dsm x tw summary dsm xyb tw summary dsm xy tw
play

summary(dsm_x_tw) summary(dsm_xyb_tw) summary(dsm_xy_tw) Overview - PowerPoint PPT Presentation

summary(dsm_x_tw) summary(dsm_xyb_tw) summary(dsm_xy_tw) Overview Estimating smooths How wiggly are things? Measuring wigglyness Splines What about these "s" things? Smoothing Translating maths into R Building a model, from


  1. summary(dsm_x_tw) summary(dsm_xyb_tw) summary(dsm_xy_tw) Overview Estimating smooths How wiggly are things? Measuring wigglyness Splines What about these "s" things? Smoothing Translating maths into R Building a model, from scratch Smooths Negative binomial distribution Tweedie distribution Count distributions Getting more out of GAMs Your οΏ½rst DSM Building a model, from scratch Bivariate terms Comparing bivariate and additive models Plotting Building a model, from scratch Bivariate spatial term Response Plotting Adding a term Plotting plot(dsm_xy_tw, pages=1) library (dsm) dsm_xyb_tw <- dsm(count ~ s(x, y), Assumed an additive structure The count model, from scratch Set basis complexity or "size" We think underlying phenomenon is smooth Visually: Know count in segment Just use + ## ## ## π‘œ π‘˜ π‘œ π‘˜ = = 𝐡 π‘˜ π‘ž Μ‚ 𝐡 π‘˜ π‘ž Μ‚ π‘œ π‘˜ = exp [ exp [ 𝐡 π‘˜ π‘ž Μ‚ 𝛾 0 𝛾 0 exp [ + 𝑑 ( + 𝑑 ( 𝛾 0 y π‘˜ y π‘˜ ) + 𝑑 ( ) + 𝑑 ( + 𝑑 ( y π‘˜ Depth π‘˜ Depth π‘˜ ) ] + πœ— π‘˜ ) ] + ) ] + πœ— π‘˜ πœ— π‘˜ dsm_x_tw <- dsm(count~s(x), ddf.obj=df, ddf.obj=df, π‘œ π‘˜ π‘˜ 𝑙 plot(dsm_xyb_tw, select=1, What about area and detectability? We set: It's a statistical model so: π‘˜ π‘˜ π‘˜ I can't teach you all of Functions made of other, Think = smooth plot(dsm_x_tw) Response is a count ## Family: Tweedie(p=1.306) ## Family: Tweedie(p=1.326) ## Family: Tweedie(p=1.29) Var (count) = 𝜚 𝔽 (count) π‘Ÿ "Abundance is a smooth function of depth" Lots of wiggles not smooth segment.data=segs, segment.data=segs, observation.data=obs, scheme=2, asp=1) Fitted smooths have effective degrees of freedom (EDF) What is a GAM? No interaction ## Link function: log ## Link function: log ## Link function: log Var (count) = 𝑑 Want : GAMs in 1 week simpler functions β‡’ observation.data=obs, family=tw()) "type": bases (made up ## ## ## 𝔽 (count) + πœ† 𝔽 (count) 2 Often, it's mostly zero Want a line that is "close" Poisson is dsm_xy_tw <- dsm(count ~ s(x) + s(y), Dashed lines indicate +/- 2 family=tw()) where where Straight line are some errors, very smooth count distribution ## Formula: ## Formula: ## Formula: of basis functions ) What is smoothing? Set "large enough" 1, 2 or more dimensions We can specify s(x,y) (and s(x,y,z,...) ) ddf.obj=df, π‘Ÿ = 1 to all the data Good intro book Basis functions , standard errors π‘œ π‘˜ π‘œ π‘˜ = 𝐡 π‘˜ π‘ž Μ‚ = 𝐡 π‘˜ π‘ž Μ‚ exp [ exp [ 𝛾 0 𝛾 0 + 𝑑 ( + 𝑑 ( y π‘˜ ) + 𝑑 ( y π‘˜ Estimate ) + 𝑑 ( Depth π‘˜ Depth π‘˜ ) ] + ) ] πœ— π‘˜ πœ— π‘˜ π‘œ π‘˜ ∼ count distribution β‡’ π‘œ π‘˜ ∼ On link scale ## count ~ s(x) + s(y) + offset(off.set) ## count ~ s(x, y) + offset(off.set) ## count ~ s(x) + offset(off.set) π‘˜ π‘˜ segment.data=segs, dsm is based on mgcv by Simon Wood 𝑙 mean variance We estimate and 𝑐 𝑙 estimate πœ† ## ## ## π‘œ π‘˜ = 𝑔 ([environmental covariates ) ] π‘˜ observation.data=obs, "maximum Fitting GAMs using dsm β‰  π‘Ÿ 𝜚 (also a good textbook on Balance between Rug plot inside the link: formula=count ~ s(y) (Poisson: 𝛾 𝑙 ## Parametric coefficients: ## Parametric coefficients: ## Parametric coefficients: scheme=2 makes (Poisson isn't good at family=tw()) wigglyness": basis size Lecture 2 : Generalized Additive Models Lecture 2 : Generalized Additive Models That's a Generalized Additive Model! That's a Generalized Additive Model! Now let's look at each bit... Now let's look at each bit... Fitting GAMs using dsm Fitting GAMs using dsm What is smoothing? What is smoothing? Let's have a go... Let's have a go... ## Estimate Std. Error t value Pr(>|t|) ## Estimate Std. Error t value Pr(>|t|) ## Estimate Std. Error t value Pr(>|t|) interpolation and "fit" GLMs and GLMMs) Additive model of smooths : ) this) heatmap has a distribution (count) area of segment - "offset" βˆ‘ 𝐿 (sometimes: ## (Intercept) -20.0908 0.2381 -84.39 <2e-16 *** ## (Intercept) -19.8115 0.2277 -87.01 <2e-16 *** ## (Intercept) -20.2745 0.2477 -81.85 <2e-16 *** On the link scale response distribution: family=nb() or family=tw() 𝑑 Var (count) = 𝔽 (count) 𝑑 ( 𝑦 ) = 𝑙 =1 𝛾 𝑙 𝑐 𝑙 ( 𝑦 ) π‘œ π‘˜ 𝐡 π‘˜ ## --- ## --- ## --- Quite technical in places dimension/complexity) (set too.far to exclude ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 EDF on axis detectability: ddf.obj=df_hr ## ## ## are residuals (differences between model and probability of detection in segment points far from data) 𝑧 More resources on course π‘œ π‘˜ = exp [ 𝛾 0 + 𝑑 ( y π‘˜ ) + 𝑑 ( Depth π‘˜ ) ] Automatically estimate: ## Approximate significance of smooth terms: ## Approximate significance of smooth terms: ## Approximate significance of smooth terms: π‘ž Μ‚ πœ— π‘˜ π‘˜ observations) website offset, data: segment.data=segs, ## edf Ref.df F p-value ## edf Ref.df F p-value ## edf Ref.df F p-value "how wiggly it needs ## s(x) 4.943 6.057 3.224 0.004239 ** ## s(x) 4.962 6.047 6.403 1.07e-06 *** ## s(x,y) 16.89 21.12 4.333 3.73e-10 *** observation.data=obs model terms ## --- ## s(y) 5.293 6.419 4.034 0.000322 *** ## --- to be": smoothing ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 is the link function (NB there is a point mass at parameter(s) ## ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## exp zero not plotted) ## ## R-sq.(adj) = 0.102 Deviance explained = 34.7% ## R-sq.(adj) = 0.0283 Deviance explained = 17.9% ## -REML = 394.86 Scale est. = 4.8248 n = 949 ## -REML = 409.94 Scale est. = 6.0413 n = 949 ## R-sq.(adj) = 0.0678 Deviance explained = 27.4% ## -REML = 399.84 Scale est. = 5.3157 n = 949 21 / 34 21 / 34 34 / 34 34 / 34 19 / 34 33 / 34 32 / 34 31 / 34 17 / 34 18 / 34 12 / 34 30 / 34 22 / 34 20 / 34 27 / 34 28 / 34 16 / 34 10 / 34 29 / 34 14 / 34 25 / 34 14 / 34 13 / 34 26 / 34 11 / 34 15 / 34 23 / 34 24 / 34 3 / 34 1 / 34 9 / 34 8 / 34 7 / 34 4 / 34 2 / 34 7 / 34 6 / 34 6 / 34 5 / 34 1 / 34

  2. Overview The count model, from scratch What is a GAM? What is smoothing? Fitting GAMs using dsm 2 / 34

  3. Building a model, from scratch Know count in segment π‘œ π‘˜ π‘˜ Want : π‘œ π‘˜ = 𝑔 ([environmental covariates ) ] π‘˜ Additive model of smooths : 𝑑 π‘œ π‘˜ = exp [ 𝛾 0 + 𝑑 ( y π‘˜ ) + 𝑑 ( Depth π‘˜ ) ] model terms is the link function exp 3 / 34

  4. Building a model, from scratch What about area and detectability? π‘œ π‘˜ = 𝐡 π‘˜ π‘ž Μ‚ exp [ 𝛾 0 + 𝑑 ( y π‘˜ ) + 𝑑 ( Depth π‘˜ ) ] π‘˜ area of segment - "offset" 𝐡 π‘˜ probability of detection in segment π‘ž Μ‚ π‘˜ 4 / 34

  5. Building a model, from scratch It's a statistical model so: π‘œ π‘˜ = 𝐡 π‘˜ π‘ž Μ‚ exp [ 𝛾 0 + 𝑑 ( y π‘˜ ) + 𝑑 ( Depth π‘˜ ) ] + πœ— π‘˜ π‘˜ has a distribution (count) π‘œ π‘˜ are residuals (differences between model and πœ— π‘˜ observations) 5 / 34

  6. That's a Generalized Additive Model! That's a Generalized Additive Model! 6 / 34 6 / 34

  7. Now let's look at each bit... Now let's look at each bit... 7 / 34 7 / 34

  8. Response π‘œ π‘˜ = 𝐡 π‘˜ π‘ž Μ‚ exp [ 𝛾 0 + 𝑑 ( y π‘˜ ) + 𝑑 ( Depth π‘˜ ) ] + πœ— π‘˜ π‘˜ where π‘œ π‘˜ ∼ count distribution 8 / 34

  9. Count distributions Response is a count Often, it's mostly zero mean variance β‰  (Poisson isn't good at this) 9 / 34

  10. Tweedie distribution Var (count) = 𝜚 𝔽 (count) π‘Ÿ Poisson is π‘Ÿ = 1 We estimate and π‘Ÿ 𝜚 (NB there is a point mass at zero not plotted) 10 / 34

  11. Negative binomial distribution Var (count) = 𝔽 (count) + πœ† 𝔽 (count) 2 Estimate πœ† (Poisson: ) Var (count) = 𝔽 (count) 11 / 34

  12. Smooths π‘œ π‘˜ = 𝐡 π‘˜ π‘ž Μ‚ exp [ 𝛾 0 + 𝑑 ( y π‘˜ ) + 𝑑 ( Depth π‘˜ ) ] + πœ— π‘˜ π‘˜ 12 / 34

  13. What about these "s" things? Think = smooth 𝑑 Want a line that is "close" to all the data Balance between interpolation and "fit" 13 / 34

  14. What is smoothing? What is smoothing? 14 / 34 14 / 34

  15. Smoothing We think underlying phenomenon is smooth "Abundance is a smooth function of depth" 1, 2 or more dimensions 15 / 34

  16. Estimating smooths We set: "type": bases (made up of basis functions ) "maximum wigglyness": basis size (sometimes: dimension/complexity) Automatically estimate: "how wiggly it needs to be": smoothing parameter(s) 16 / 34

  17. Splines Functions made of other, simpler functions Basis functions , 𝑐 𝑙 estimate 𝛾 𝑙 βˆ‘ 𝐿 𝑑 ( 𝑦 ) = 𝑙 =1 𝛾 𝑙 𝑐 𝑙 ( 𝑦 ) 17 / 34

  18. Measuring wigglyness Visually: Lots of wiggles not smooth β‡’ Straight line very smooth β‡’ 18 / 34

  19. How wiggly are things? Set basis complexity or "size" 𝑙 Fitted smooths have effective degrees of freedom (EDF) Set "large enough" 𝑙 19 / 34

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend