繁体   English   中英

使用 GAM 分析时空模式

[英]Analysing spatio-temporal patterns using a GAM

我正在尝试使用以下 model 分析疾病的时空风险;

mod2 = gam(TB ~ offset(log(Population)) + 
       s(Indigenous, k = 10, bs = "cr") + 
       s(Urbanisation, k = 10, bs = "cr") +
       s(Density, k = 10, bs = "cr") + Poverty + 
       s(Poor_Sanitation, k = 10, bs = "cr") + 
       Unemployment + Timeliness + Year + 
              Region + s(lon, lat), 
              data = TBdata, 
              family = nb(link = 'log'))

我的问题是我还想分析年(2012-2014)的差异,我不相信我的 model 目前确实如此。 我怎么能做到这一点? 我曾尝试在与“人口”的互动中使用“年”,因为它有某种意义,但未能成功地做到这一点。

数据(如果需要);

TBdata
# A tibble: 1,671 × 14
Indigenous Illiteracy Urbanisation Density Poverty Poor_Sanitation Unemployment Timeliness  Year    TB Population Region   lon    lat
<dbl>      <dbl>        <dbl>   <dbl>   <dbl>           <dbl>        <dbl>      <dbl> <int> <int>      <int>  <int> <dbl>  <dbl>
 1      0.335       6.35         84.1   0.714    31.3            15.3         5.41       59.2  2012   323     559543  11001 -60.7 -12.1 
 2      6.45        8.49         71.4   0.743    48.6            29.4         5.92       58.1  2012    15      73193  11002 -64.0  -9.43

添加信息;

在编辑了我的 model 之后,我现在正在尝试 plot 我的预测。

我使用了产生以下 plot 的当前代码,尽管我认为我可能会错过我的预测,所以我目前正在绘制平滑的 function;

mod2 = gam(TB ~ offset(log(Population)) + s(Indigenous, k = 10, bs = "cr") + s(Urbanisation, k = 10, bs = "cr") +
              s(Density, k = 10, bs = "cr") + Poverty + s(Poor_Sanitation, k = 10, bs = "cr") + Unemployment + Timeliness +
              as.factor(Year) + Region + s(lon, lat), 
              data = TBdata, 
              family = nb(link = 'log'))

model总结

在此处输入图像描述

#plot
plot(mod2, contour.col = 'white', too.far = 0.10, scheme = 2, rug = T)

在此处输入图像描述

虽然我认为这显示了我现在需要的不同年份的空间趋势,所以我认为我想要的是 plot 显示我对每一年(2012、2013 和 2014 年)的预测

当您plot() model 时,您只是在可视化估计的平滑函数。 由于您只有一个空间平滑,因此您得到一个 plot。 factor(Year)s(lon,lat)之间没有相互作用。

帮自己一个忙,或者将Year转换为数据中的一个因子,或者创建一个新变量fYear ,即factor(Year) 我假设你在下面做了前者

如果你想要一个交互,你需要在你的 model 中使用像 this Year + s(lon, lat, by = Year)这样的东西。

然后,当您plot() GAM 时,您将获得nlevels(factor(Year))空间平滑。

但即便如此,这些也不是预测 您会注意到刻度以 0 为中心(在本例中为参考年数据的总平均值)。 要获得预测图,您需要使用predict()并将newdata设置为包含要预测的预测变量的所有组合的数据框,或者使用vis.gam() 对于后者,您需要:

layout(matrix(c(1:3), nrow = 1))
vis.gam(mod2, view = c("lon", "lat"), cond = list(Year = "2012"),
        plot.type = "contour")
vis.gam(mod2, view = c("lon", "lat"), cond = list(Year = "2013"), 
        plot.type = "contour")
vis.gam(mod2, view = c("lon", "lat"), cond = list(Year = "2014"), 
        plot.type = "contour")
layout(1)

您未包含在传递给cond的列表中的任何内容都将使用一个值,该值是最接近每个相应连续协变量的中位数的观察值或因子变量的模态水平。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM