Running 'bym.R' [173s]
  Running 'cancerRates.R' [6s]
  Running 'getRates.R' [5s]
  Running 'getSMR.R' [165s]
Running the tests in 'tests/bym.R' failed.
Complete output:
  > havePackages = c(
  +   'INLA' = requireNamespace('INLA', quietly=TRUE)
  + )
  > 
  > print(havePackages)
   INLA 
  FALSE 
  > 
  > if(havePackages) {
  + 	INLA::inla.setOption(num.threads=2)
  + 	# not all versions of INLA support blas.num.threads
  + 	try(INLA::inla.setOption(blas.num.threads=2), silent=TRUE)
  + 	print(INLA::inla.getOption('num.threads'))
  + }
  > 
  > 
  > library('diseasemapping')
  > data('kentucky')
  > kentucky = terra::unwrap(kentucky)
  > 
  > 
  > 
  > 
  > 
  > kentucky = getSMR(kentucky, larynxRates, larynx,
  + 		regionCode="County")
  > 
  > kentuckyAdjMat = terra::adjacent(kentucky, type='intersects')
  > attributes(kentuckyAdjMat)$region.id = kentucky$County
  > 
  > if(all(havePackages)){
  + 
  +   kBYM = bym(
  + 			formula = observed ~ offset(logExpected) + poverty,
  +       data=terra::values(kentucky),
  + 			adjMat = kentuckyAdjMat,
  +       prior = list(sd=c(0.1, 0.5), propSpatial=c(0.5, 0.5)),
  + 			region.id='County',
  + 			control.predictor=list(compute=TRUE)
  +   )
  + 	kBYM$parameters$summary
  + 
  + 	if(!interactive()) pdf("priorPostKentucky.pdf")
  + 	plot(kBYM$parameters$sd$posterior, type='l', xlim = c(0, 1), lwd=2)
  + 	lines(kBYM$parameters$sd$prior, col='blue')
  + 	legend('topright', lty=1, col=c('black','blue'), legend=c('posterior','prior'))
  + 	if(!interactive()) dev.off()
  + 
  + 	
  + 	
  + 
  + 
  + # also try no covariate or adj mat
  + 
  + kBYM = bym(
  + 		formula = observed ~ offset(logExpected),
  + 		prior = list(sd = 0.5, propSpatial = 0.5),
  + 		data=kentucky)
  + 
  + 
  + 
  +  	kBYM$data$exc1 =  unlist(lapply(kBYM$inla$marginals.fitted.bym, INLA::inla.pmarginal, q=log(1.2)))
  + 
  + kBYM$par$summary
  + 
  + if(require('mapmisc', quietly=TRUE)) {
  + 
  + colFit = colourScale(kBYM$data$fitted.exp,
  + 		breaks=6, dec=3)
  + 	
  + plot(kBYM$data, col=colFit$plot)
  + legendBreaks('topleft', colFit)
  + 
  + colExc = colourScale(kBYM$data$exc1 ,
  + 		style='fixed',
  + 		breaks=c(0, 0.2, 0.8,0.9, 1), 
  + 		col=rainbow, rev=TRUE
  + 	)
  + 
  + 	plot(kBYM$data, col=colExc$plot)
  + 	legendBreaks('topleft', colExc)
  +  		
  + }
  + 
  + 	
  + # subtract a few regions
  + 
  + kBYM = bym(
  +     formula=observed ~ offset(logExpected) + poverty,
  +     data=terra::values(kentucky)[-(1:4),],  
  +  	  adjMat = kentuckyAdjMat, region.id="County",
  + 		prior = list(sd=0.1, propSpatial = 0.1))
  +  
  + 
  + kBYM$par$summary
  + 
  + # intercept only, no offset
  + 
  + 
  + kBYM = bym(data=kentucky,  formula=observed ~ 1,
  + 		prior = list(sd=1, propSpatial=0.9))
  + 
  + kBYM$par$summary
  + 
  + 
  + if(require('mapmisc', quietly=TRUE)) {
  + 	
  + 	colFit = colourScale(kBYM$data$fitted.exp,
  + 			breaks=6, dec=1)
  + 	
  + 	plot(kBYM$data, col=colFit$plot)
  + 	legendBreaks('topleft', colFit)
  + 	
  + }
  + 
  +  
  + 
  + # give spdf but some regions have no data
  + # but keep the 'county' column as is
  + kentucky[1:2,-grep("County", names(kentucky))] = NA 
  + 
  + kBYM = bym(observed ~ offset(logExpected) + poverty,
  + 		kentucky, 
  + 		region.id="County",
  + 		prior = list(sd=0.1, propSpatial = 0.5))
  + 
  +  
  + kBYM$par$summary
  + 
  + 
  + # missing value in a categorical variable
  + 
  + pCuts = quantile(kentucky$poverty, na.rm=TRUE)
  + kentucky$povertyFac = cut(kentucky$poverty, 
  + 		breaks = pCuts,
  + 		labels = letters[seq(1,length(pCuts)-1)])
  + kentucky$povertyFac[c(2,34,100)] = NA
  + 
  + kBYM = bym(
  + 		formula = observed ~ offset(logExpected) + povertyFac,
  + 		data = kentucky, 
  + 		region.id="County",
  + 		prior = list(sd=c(0.1, 0.5), propSpatial=c(0.1, 0.5))
  + )
  + 
  + 
  + kBYM$par$summary
  + }
  > 
  > 
  > 
  > proc.time()
     user  system elapsed 
     5.20    0.14    5.32 
Running the tests in 'tests/getSMR.R' failed.
Complete output:
  > library('diseasemapping')
  > data('kentucky')
  > kentucky = terra::unwrap(kentucky)
  > 
  > head(larynx)
      County Cases sex age
  1  Hickman     2   M  NA
  2 Caldwell     3   M  NA
  3 Anderson     3   M  NA
  4   Marion     3   M  NA
  5    Wayne     4   M  NA
  6  Lincoln     3   M  NA
  > 10^5*larynxRates[paste(c("M","F"), 50, sep="_")]
  M_50 F_50 
   9.9  2.3 
  > 
  > kentucky1 = getSMR(terra::values(kentucky), larynxRates)
  > kentucky1[1:4,c(1,2,grep("expected", names(kentucky1),ignore.case=TRUE))]
      County M.0 expected logExpected
  1    Adair 594 0.916000 -0.08773891
  2    Allen 667 0.973271 -0.02709272
  3 Anderson 747 0.924600 -0.07839407
  4  Ballard 237 0.448540 -0.80175742
  > 
  > kentucky1 = getSMR(kentucky, larynxRates)
  > kentucky1[1:4,c(1,2,grep("expected", names(kentucky1),ignore.case=TRUE))]
   class       : SpatVector 
   geometry    : polygons 
   dimensions  : 4, 6  (geometries, attributes)
   extent      : -89.18153, -84.79649, 36.62915, 38.1288  (xmin, xmax, ymin, ymax)
   coord. ref. : +proj=longlat +datum=WGS84 +no_defs 
   names       :   County   M.0 expected expected_surfaceArea
   type        :    <chr> <int>    <num>                <num>
   values      :    Adair   594    0.916            8.573e-10
                    Allen   667   0.9733            1.073e-09
                 Anderson   747   0.9246            1.743e-09
   logExpected_surfaceArea logExpected
                     <num>       <num>
                    -20.88    -0.08774
                    -20.65    -0.02709
                    -20.17    -0.07839
  > 
  > if(require('mapmisc', quietly=TRUE)) {
  + #  kmap = openmap(kentucky)
  +   col = colourScale(
  +       kentucky1$expected,
  +       style='fixed',  
  +       breaks=c(0:5,max(kentucky1$expected)), 
  +     dec=0,opacity=c(0.6,1)
  +   )
  + 
  +   plot(kentucky1, col=col$plot)
  +   legendBreaks('topleft', col)
  + }
  > 
  > junk = getSMR(kentucky, larynxRates, regionCode='junk')
  > 
  > 
  > kentucky2 = getSMR(terra::values(kentucky), larynxRates, 
  +     larynx, 
  +     regionCode="County")
  > kentucky2[1:4,c(1,2,grep("expected|observed", names(kentucky2),ignore.case=TRUE))]
      County M.0 expected logExpected observed
  1    Adair 594 0.916000 -0.08773891        4
  2    Allen 667 0.973271 -0.02709272        0
  3 Anderson 747 0.924600 -0.07839407        3
  4  Ballard 237 0.448540 -0.80175742        0
  > 
  > 
  > kentucky2 = getSMR(kentucky, 
  +     larynxRates, 
  +     casedata=larynx, 
  +     regionCode="County")
  > terra::values(kentucky2)[1:4,c(1,2,grep("expected|observed", names(kentucky2),ignore.case=TRUE))]
      County M.0 expected expected_surfaceArea logExpected_surfaceArea
  1    Adair 594 0.916000         8.572729e-10               -20.87726
  2    Allen 667 0.973271         1.072726e-09               -20.65306
  3 Anderson 747 0.924600         1.743098e-09               -20.16760
  4  Ballard 237 0.448540         6.327389e-10               -21.18096
    logExpected observed
  1 -0.08773891        4
  2 -0.02709272        0
  3 -0.07839407        3
  4 -0.80175742        0
  > 
  > if(require('mapmisc', quietly=TRUE)) {
  + 
  + 
  +   col = colourScale(
  +         kentucky2$observed,
  +         col='RdYlBu',
  +         style='quantile', 
  +         breaks=12, dec=0,opacity=c(0.6,1),
  +         rev=TRUE
  +     )
  +     
  +     plot(kentucky1, col=col$plot)
  +     legendBreaks('topleft', col)
  + 
  +     
  +   col = colourScale(
  +       kentucky2$expected,
  +   style='fixed', 
  +   col=col$col,
  +   breaks=col$breaks,opacity=c(0.6,1)
  +   )
  +   
  +   plot(kentucky2, col=col$plot)
  +   legendBreaks('topleft', col)
  +   
  + }
  > 
  > 
  > kentucky3 = getSMR(terra::values(kentucky), 
  +     model=list(larynxRates, larynxRates*2)
  + )
  > kentucky3[1:4,c(1,2,grep("expected|observed", names(kentucky3),ignore.case=TRUE))]
      County M.0 expected_1 logExpected_1 expected_2 logExpected_2
  1    Adair 594   0.916000   -0.08773891   1.832000     0.6054083
  2    Allen 667   0.973271   -0.02709272   1.946542     0.6660545
  3 Anderson 747   0.924600   -0.07839407   1.849200     0.6147531
  4  Ballard 237   0.448540   -0.80175742   0.897080    -0.1086102
  > 
  > kentucky3 = getSMR(kentucky, 
  +     model=list('1990'=larynxRates, '1991'=larynxRates*2)
  + )
  > terra::values(kentucky3)[1:4,c(1,2,grep("expected|observed", names(kentucky3),ignore.case=TRUE))]
      County M.0 expected_1990 expected_surfaceArea_1990
  1    Adair 594      0.916000              8.572729e-10
  2    Allen 667      0.973271              1.072726e-09
  3 Anderson 747      0.924600              1.743098e-09
  4  Ballard 237      0.448540              6.327389e-10
    logExpected_surfaceArea_1990 logExpected_1990 expected_1991
  1                    -20.87726      -0.08773891      1.832000
  2                    -20.65306      -0.02709272      1.946542
  3                    -20.16760      -0.07839407      1.849200
  4                    -21.18096      -0.80175742      0.897080
    expected_surfaceArea_1991 logExpected_surfaceArea_1991 logExpected_1991
  1              1.714546e-09                    -20.18412        0.6054083
  2              2.145451e-09                    -19.95992        0.6660545
  3              3.486196e-09                    -19.47445        0.6147531
  4              1.265478e-09                    -20.48782       -0.1086102
  > 
  > modelList = list()
  > for (D in 3:12) {
  +   modelList[[
  +       as.character(D)
  +       ]] = larynxRates*D/5
  + }
  > 
  > 
  > kentucky4 = getSMR(
  + 		popdata=list(
  +         '5'=kentucky, '10'=kentucky
  +     ),
  +     model=modelList
  + )
  > terra::values(kentucky4[[1]])[1:4,c(1,2,grep("expected|observed", 
  +             names(kentucky4[[1]]),ignore.case=TRUE))
  + ]
      County M.0 expected_3 expected_surfaceArea_3 logExpected_surfaceArea_3
  1    Adair 594  0.5496000           5.143638e-10                 -21.38809
  2    Allen 667  0.5839626           6.436354e-10                 -21.16389
  3 Anderson 747  0.5547600           1.045859e-09                 -20.67843
  4  Ballard 237  0.2691240           3.796434e-10                 -21.69179
    logExpected_3 expected_4 expected_surfaceArea_4 logExpected_surfaceArea_4
  1    -0.5985645  0.7328000           6.858184e-10                 -21.10041
  2    -0.5379183  0.7786168           8.581805e-10                 -20.87621
  3    -0.5892197  0.7396800           1.394478e-09                 -20.39075
  4    -1.3125830  0.3588320           5.061912e-10                 -21.40411
    logExpected_4 expected_5 expected_surfaceArea_5 logExpected_surfaceArea_5
  1    -0.3108825   0.916000           8.572729e-10                 -20.87726
  2    -0.2502363   0.973271           1.072726e-09                 -20.65306
  3    -0.3015376   0.924600           1.743098e-09                 -20.16760
  4    -1.0249010   0.448540           6.327389e-10                 -21.18096
    logExpected_5 expected_6 expected_surfaceArea_6 logExpected_surfaceArea_6
  1   -0.08773891   1.099200           1.028728e-09                 -20.69494
  2   -0.02709272   1.167925           1.287271e-09                 -20.47074
  3   -0.07839407   1.109520           2.091718e-09                 -19.98528
  4   -0.80175742   0.538248           7.592867e-10                 -20.99864
    logExpected_6 expected_7 expected_surfaceArea_7 logExpected_surfaceArea_7
  1    0.09458264   1.282400           1.200182e-09                 -20.54079
  2    0.15522884   1.362579           1.501816e-09                 -20.31659
  3    0.10392749   1.294440           2.440337e-09                 -19.83113
  4   -0.61943586   0.627956           8.858345e-10                 -20.84449
    logExpected_7 expected_8 expected_surfaceArea_8 logExpected_surfaceArea_8
  1     0.2487333   1.465600           1.371637e-09                 -20.40726
  2     0.3093795   1.557234           1.716361e-09                 -20.18306
  3     0.2580782   1.479360           2.788957e-09                 -19.69760
  4    -0.4652852   0.717664           1.012382e-09                 -20.71096
    logExpected_8 expected_9 expected_surfaceArea_9 logExpected_surfaceArea_9
  1     0.3822647   1.648800           1.543091e-09                 -20.28948
  2     0.4429109   1.751888           1.930906e-09                 -20.06528
  3     0.3916096   1.664280           3.137576e-09                 -19.57982
  4    -0.3317538   0.807372           1.138930e-09                 -20.59318
    logExpected_9 expected_10 expected_surfaceArea_10 logExpected_surfaceArea_10
  1     0.5000478    1.832000            1.714546e-09                  -20.18412
  2     0.5606939    1.946542            2.145451e-09                  -19.95992
  3     0.5093926    1.849200            3.486196e-09                  -19.47445
  4    -0.2139708    0.897080            1.265478e-09                  -20.48782
    logExpected_10 expected_11 expected_surfaceArea_11 logExpected_surfaceArea_11
  1      0.6054083    2.015200            1.886000e-09                  -20.08881
  2      0.6660545    2.141196            2.359996e-09                  -19.86461
  3      0.6147531    2.034120            3.834816e-09                  -19.37914
  4     -0.1086102    0.986788            1.392026e-09                  -20.39251
    logExpected_11 expected_12 expected_surfaceArea_12 logExpected_surfaceArea_12
  1     0.70071845    2.198400            2.057455e-09                  -20.00180
  2     0.76136464    2.335850            2.574542e-09                  -19.77759
  3     0.71006329    2.219040            4.183435e-09                  -19.29213
  4    -0.01330005    1.076496            1.518573e-09                  -20.30549
    logExpected_12
  1     0.78772982
  2     0.84837602
  3     0.79707467
  4     0.07371132
  > terra::values(kentucky4[[2]])[1:4,c(1,2,grep("expected|observed", 
  +             names(kentucky4[[2]]),ignore.case=TRUE))
  + ]
      County M.0 expected_3 expected_surfaceArea_3 logExpected_surfaceArea_3
  1    Adair 594  0.5496000           5.143638e-10                 -21.38809
  2    Allen 667  0.5839626           6.436354e-10                 -21.16389
  3 Anderson 747  0.5547600           1.045859e-09                 -20.67843
  4  Ballard 237  0.2691240           3.796434e-10                 -21.69179
    logExpected_3 expected_4 expected_surfaceArea_4 logExpected_surfaceArea_4
  1    -0.5985645  0.7328000           6.858184e-10                 -21.10041
  2    -0.5379183  0.7786168           8.581805e-10                 -20.87621
  3    -0.5892197  0.7396800           1.394478e-09                 -20.39075
  4    -1.3125830  0.3588320           5.061912e-10                 -21.40411
    logExpected_4 expected_5 expected_surfaceArea_5 logExpected_surfaceArea_5
  1    -0.3108825   0.916000           8.572729e-10                 -20.87726
  2    -0.2502363   0.973271           1.072726e-09                 -20.65306
  3    -0.3015376   0.924600           1.743098e-09                 -20.16760
  4    -1.0249010   0.448540           6.327389e-10                 -21.18096
    logExpected_5 expected_6 expected_surfaceArea_6 logExpected_surfaceArea_6
  1   -0.08773891   1.099200           1.028728e-09                 -20.69494
  2   -0.02709272   1.167925           1.287271e-09                 -20.47074
  3   -0.07839407   1.109520           2.091718e-09                 -19.98528
  4   -0.80175742   0.538248           7.592867e-10                 -20.99864
    logExpected_6 expected_7 expected_surfaceArea_7 logExpected_surfaceArea_7
  1    0.09458264   1.282400           1.200182e-09                 -20.54079
  2    0.15522884   1.362579           1.501816e-09                 -20.31659
  3    0.10392749   1.294440           2.440337e-09                 -19.83113
  4   -0.61943586   0.627956           8.858345e-10                 -20.84449
    logExpected_7 expected_8 expected_surfaceArea_8 logExpected_surfaceArea_8
  1     0.2487333   1.465600           1.371637e-09                 -20.40726
  2     0.3093795   1.557234           1.716361e-09                 -20.18306
  3     0.2580782   1.479360           2.788957e-09                 -19.69760
  4    -0.4652852   0.717664           1.012382e-09                 -20.71096
    logExpected_8 expected_9 expected_surfaceArea_9 logExpected_surfaceArea_9
  1     0.3822647   1.648800           1.543091e-09                 -20.28948
  2     0.4429109   1.751888           1.930906e-09                 -20.06528
  3     0.3916096   1.664280           3.137576e-09                 -19.57982
  4    -0.3317538   0.807372           1.138930e-09                 -20.59318
    logExpected_9 expected_10 expected_surfaceArea_10 logExpected_surfaceArea_10
  1     0.5000478    1.832000            1.714546e-09                  -20.18412
  2     0.5606939    1.946542            2.145451e-09                  -19.95992
  3     0.5093926    1.849200            3.486196e-09                  -19.47445
  4    -0.2139708    0.897080            1.265478e-09                  -20.48782
    logExpected_10 expected_11 expected_surfaceArea_11 logExpected_surfaceArea_11
  1      0.6054083    2.015200            1.886000e-09                  -20.08881
  2      0.6660545    2.141196            2.359996e-09                  -19.86461
  3      0.6147531    2.034120            3.834816e-09                  -19.37914
  4     -0.1086102    0.986788            1.392026e-09                  -20.39251
    logExpected_11 expected_12 expected_surfaceArea_12 logExpected_surfaceArea_12
  1     0.70071845    2.198400            2.057455e-09                  -20.00180
  2     0.76136464    2.335850            2.574542e-09                  -19.77759
  3     0.71006329    2.219040            4.183435e-09                  -19.29213
  4    -0.01330005    1.076496            1.518573e-09                  -20.30549
    logExpected_12
  1     0.78772982
  2     0.84837602
  3     0.79707467
  4     0.07371132
  >  
  > if(require('mapmisc', quietly=TRUE)) {
  +   
  +   
  +   col = colourScale(
  +       kentucky4[[1]]$expected_6,
  +       col='RdYlBu',
  +       style='quantile', 
  +       breaks=15, dec=0,opacity=c(0.6,1),
  +       rev=TRUE
  +   )
  +   
  +   plot(kentucky4[[1]], col=col$plot)
  +   legendBreaks('topleft', col)
  +   
  +   
  +   col = colourScale(
  +       kentucky4[[2]]$expected_11,
  +       col='RdYlBu',
  +       style='quantile', 
  +       breaks=15, dec=0,opacity=c(0.6,1),
  +       rev=TRUE
  +   )
  +   
  +   plot(kentucky4[[2]], col=col$plot)
  +   legendBreaks('topleft', col)
  +   
  + }
  > 
  > proc.time()
     user  system elapsed 
     4.87    0.18    5.04