diff --git a/DESCRIPTION b/DESCRIPTION index f6a14c1..60df6f2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: hdpGLM Title: Hierarchical Dirichlet Process Generalized Linear Models -Version: 1.0.2 +Version: 1.0.3 Authors@R: c(person(given="Diogo", family="Ferrari", email="diogoferrari@gmail.com", role=c("aut", "cre"))) Description: Implementation of MCMC algorithms to estimate the Hierarchical Dirichlet Process Generalized Linear Model (hdpGLM) presented in the paper Ferrari (2020) Modeling Context-Dependent Latent Heterogeneity, Political Analysis and . Depends: R (>= 3.3.3) @@ -35,7 +35,7 @@ Imports: coda, tibble, tidyr, tidyverse -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.3 Suggests: knitr, rmarkdown diff --git a/NEWS.md b/NEWS.md index e2d1fff..4d34dc7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # hdpGLM (development version) +# hdpGLM 1.0.3 + +- This is a minor release with typos corrected and the inclusion of information regarding the publication of the package in the Journal of Statistical Software (10.18637/jss.v107.i10) + # hdpGLM 1.0.2 - The MCMC tunning parameters of the function `hdpGLM()`, namely `epsilon`, `leapFrog`, and `hmc_iter` were removed from that function's signature. Now, when the users want to tune those parameters, they must provide it as part of the named list that is used for the argument `mcmc`. It makes the code and the function signature cleaner. diff --git a/R/src_r_version.R b/R/src_r_version.R index 2b7525e..1698b2b 100644 --- a/R/src_r_version.R +++ b/R/src_r_version.R @@ -1,7 +1,7 @@ ## {{{ print acceptance rate }}} -print.accept.rate <- function(mh.accept.info, accepted, Z, n.display, iter, mcmc, K, Khat, family) +print_accept_rate <- function(mh.accept.info, accepted, Z, n.display, iter, mcmc, K, Khat, family) { ## update acceptance rate mh.accept.info$trial = mh.accept.info$trial + 1 @@ -520,7 +520,7 @@ dpGLM_mcmc_xxr <- function(y, X, weights, K, fix, family, mcmc, epsilon, ## print message with acceptance rate accepted = theta.tmp$accepted Khat = max(Khat,length(table(Z))) - mh.accept.info = print.accept.rate(mh.accept.info, accepted, Z, n.display, iter, mcmc, K, Khat, family) + mh.accept.info = print_accept_rate(mh.accept.info, accepted, Z, n.display, iter, mcmc, K, Khat, family) } diff --git a/README.md b/README.md index 851ef1d..ad8392f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # hdpGLM [![CRAN status](https://www.r-pkg.org/badges/version/hdpGLM?color=green)](https://cran.r-project.org/package=hdpGLM) -[![](https://travis-ci.org/DiogoFerrari/hdpGLM.svg)](https://travis-ci.org/DiogoFerrari/hdpGLM) Overview ======== diff --git a/docs/404.html b/docs/404.html index 6ea17d7..b49b836 100644 --- a/docs/404.html +++ b/docs/404.html @@ -32,7 +32,7 @@ hdpGLM - 1.0.2 + 1.0.3 @@ -103,7 +103,7 @@

Page not found (404)

-

Site built with pkgdown 2.0.3.

+

Site built with pkgdown 2.0.7.

diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 71637e5..bacb727 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -17,7 +17,7 @@ hdpGLM - 1.0.2 + 1.0.3 @@ -78,7 +78,7 @@

License

-

Site built with pkgdown 2.0.3.

+

Site built with pkgdown 2.0.7.

diff --git a/docs/articles/hdpGLM.html b/docs/articles/hdpGLM.html index d7729eb..b24c9fa 100644 --- a/docs/articles/hdpGLM.html +++ b/docs/articles/hdpGLM.html @@ -33,7 +33,7 @@ hdpGLM - 1.0.2 + 1.0.3 @@ -78,7 +78,7 @@ -
+
-## printing the outcome
-summary(mod)
-#>  
-#> -------------------------------- 
-#> dpGLM model object
-#> 
-#> Maximum number of clusters activated during the estimation: 12
-#> Number of MCMC iterations: 500
-#> burn-in: 10
-#> -------------------------------- 
-#> 
-#> Summary statistics of clusters with data points
-#> 
-#> --------------------------------
-#> Coefficients for cluster 1 (cluster label 1)
-#> 
-#>               Post.Mean Post.Median  HPD.lower HPD.upper
-#> 1 (Intercept) -3.823596  -3.8241322 -3.8997256 -3.751683
-#> 2  inequality -1.523853  -1.5249557 -1.5929343 -1.449925
-#> 3      income  3.882122   3.8823532  3.8160525  3.959338
-#> 4    ideology -8.260535  -8.2599947 -8.3367908 -8.189872
-#> 5       sigma  0.972212   0.9733659  0.8506181  1.063681
-#> 
-#> --------------------------------
-#> Coefficients for cluster 2 (cluster label 4)
-#> 
-#>                Post.Mean Post.Median  HPD.lower HPD.upper
-#> 1 (Intercept) -3.8689754   -3.869516 -3.9420464 -3.800124
-#> 2  inequality  2.0005294    1.999374  1.9351815  2.078626
-#> 3      income  3.8528985    3.856421  3.7631929  3.922354
-#> 4    ideology -8.3077366   -8.308183 -8.3751180 -8.230430
-#> 5       sigma  0.9991988    1.000280  0.8882188  1.074176
-#> 
-#> --------------------------------
-

The summary function prints the result in a tidy format. The column k in the summary shows the label of the estimated clusters. The column Mean is the average of the posterior distribution for each linear coefficient in each cluster.

-

The function classify can be used to classify the data points into clusters based on the estimation.

+## printing the outcome +summary(mod) +#> +#> -------------------------------- +#> dpGLM model object +#> +#> Maximum number of clusters activated during the estimation: 14 +#> Number of MCMC iterations: 500 +#> burn-in: 10 +#> -------------------------------- +#> +#> Summary statistics of clusters with data points +#> +#> -------------------------------- +#> Coefficients for cluster 1 (cluster label 1) +#> +#> Post.Mean Post.Median HPD.lower HPD.upper +#> 1 (Intercept) -3.8174826 -3.8168864 -3.8842678 -3.747833 +#> 2 inequality -1.5244855 -1.5217828 -1.6064414 -1.448780 +#> 3 income 3.8816869 3.8822402 3.8172385 3.960788 +#> 4 ideology -8.2579824 -8.2588288 -8.3312731 -8.172078 +#> 5 sigma 0.9710744 0.9725616 0.8584848 1.076870 +#> +#> -------------------------------- +#> Coefficients for cluster 2 (cluster label 3) +#> +#> Post.Mean Post.Median HPD.lower HPD.upper +#> 1 (Intercept) -3.870873 -3.8697608 -3.9448053 -3.805306 +#> 2 inequality 2.004165 2.0050848 1.9321425 2.067918 +#> 3 income 3.849968 3.8508139 3.7775220 3.915007 +#> 4 ideology -8.306840 -8.3071259 -8.3856662 -8.239346 +#> 5 sigma 1.000594 0.9996909 0.9109328 1.085462 +#> +#> --------------------------------
+

The summary function prints the result in a tidy format. The column +k in the summary shows the label of the estimated clusters. +The column Mean is the average of the posterior +distribution for each linear coefficient in each cluster.

+

The function classify can be used to classify the data +points into clusters based on the estimation.

-welfare_clustered = classify(welfare, mod)
-head(welfare_clustered)
-#>   Cluster     support inequality     income   ideology
-#> 1       4 -18.5649610  0.3392724  0.1425111  1.9225985
-#> 2       4  -9.3905812 -0.9906646 -0.5117102  0.2483346
-#> 3       4   0.9276234 -2.2318510 -0.3856288 -1.3619216
-#> 4       4 -12.3594498 -3.0079501 -0.9440585 -0.2088675
-#> 5       1  -2.4834411  0.1000455  0.8322192  0.1321378
-#> 6       4 -11.4187853 -0.9543883 -0.8810503  0.2916444
-tail(welfare_clustered)
-#>      Cluster     support  inequality     income   ideology
-#> 1995       1  -1.5230053 1.055855140 -0.7295937 -0.7067871
-#> 1996       1   0.4814892 0.582588091  2.0051082  0.3090389
-#> 1997       1 -14.1929956 0.391164197 -0.9607449  0.7765482
-#> 1998       1  -8.2396789 0.074437376  1.2020300  1.0874928
-#> 1999       1 -23.1583753 0.434223018 -0.6176438  2.0387294
-#> 2000       1  -7.2075582 0.008355317 -0.4538951  0.2268072
-

There are a series of built-in functions, with various options, to plot the results. In the example below, you see two of those options. The separate parameter plot the posterior samples for each cluster separately, and the option ncols controls how many columns to use for the panels in the figure (to see more, run help(plot.hdpGLM) and help(plot.dpGLM)).

+welfare_clustered = classify(welfare, mod) +head(welfare_clustered) +#> Cluster support inequality income ideology +#> 1 3 -18.5649610 0.3392724 0.1425111 1.9225985 +#> 2 3 -9.3905812 -0.9906646 -0.5117102 0.2483346 +#> 3 3 0.9276234 -2.2318510 -0.3856288 -1.3619216 +#> 4 3 -12.3594498 -3.0079501 -0.9440585 -0.2088675 +#> 5 1 -2.4834411 0.1000455 0.8322192 0.1321378 +#> 6 3 -11.4187853 -0.9543883 -0.8810503 0.2916444 +tail(welfare_clustered) +#> Cluster support inequality income ideology +#> 1995 1 -1.5230053 1.055855140 -0.7295937 -0.7067871 +#> 1996 1 0.4814892 0.582588091 2.0051082 0.3090389 +#> 1997 1 -14.1929956 0.391164197 -0.9607449 0.7765482 +#> 1998 3 -8.2396789 0.074437376 1.2020300 1.0874928 +#> 1999 1 -23.1583753 0.434223018 -0.6176438 2.0387294 +#> 2000 1 -7.2075582 0.008355317 -0.4538951 0.2268072
+

There are a series of built-in functions, with various options, to +plot the results. In the example below, you see two of those options. +The separate parameter plot the posterior samples for each +cluster separately, and the option ncols controls how many +columns to use for the panels in the figure (to see more, run +help(plot.hdpGLM) and help(plot.dpGLM)).

-plot(mod, separate=T, ncols=4)
-#> 
-#> 
-#> Generating plot...
+plot(mod, separate=T, ncols=4) +#> +#> +#> Generating plot...

Estimating Context-dependent Latent Heterogeneity

-

To continue the previous toy example, suppose that we are analyzing data from many countries, and we suspect that the latent heterogeneity is different in each country. The effect of inequality on support for welfare may be gender-specific only in some countries (contexts). Or maybe the way it is gender-specific varies from country to country. Suppose we didn’t have data on gender, but we collect information on countries’ gender gap in welfare provision. Let’s look at this new data set.

+

To continue the previous toy example, suppose that we are analyzing +data from many countries, and we suspect that the latent heterogeneity +is different in each country. The effect of inequality on support for +welfare may be gender-specific only in some countries (contexts). Or +maybe the way it is gender-specific varies from country to country. +Suppose we didn’t have data on gender, but we collect information on +countries’ gender gap in welfare provision. Let’s look at this new data +set.

-## loading and looking at the data
-welfare = read.csv2('welfare2.csv')
-head(welfare)
-#>       support inequality     income   ideology country gap
-#> 1 -18.5649610  0.3392724  0.1425111  1.9225985       0 0.1
-#> 2  -9.3905812 -0.9906646 -0.5117102  0.2483346       0 0.1
-#> 3   0.9276234 -2.2318510 -0.3856288 -1.3619216       0 0.1
-#> 4 -12.3594498 -3.0079501 -0.9440585 -0.2088675       0 0.1
-#> 5  -2.4834411  0.1000455  0.8322192  0.1321378       0 0.1
-#> 6 -11.4187853 -0.9543883 -0.8810503  0.2916444       0 0.1
-tail(welfare)
-#>         support inequality     income    ideology country        gap
-#> 3195  0.3190583 -0.7504798 -0.7839583  0.92300705       4 -0.8280808
-#> 3196 -1.3837239  0.6620435 -1.5566268  0.05634618       4 -0.8280808
-#> 3197 -1.3820016 -0.4298706 -1.0945688  0.71559078       4 -0.8280808
-#> 3198  0.6878775  0.5450604  2.6175887 -1.94844469       4 -0.8280808
-#> 3199 -7.9282930  1.7846004  1.6755823  1.29160208       4 -0.8280808
-#> 3200 -1.7472485  0.5030992 -0.5395479  0.20109879       4 -0.8280808
-

The variable country indicates the country (context) of the observation, and the variable gap the gender gap in welfare provision in the respective country. The estimation is similar to the previous example, but now there is a second formula for the context-level variables. Again, the example below uses few iterations in the MCMC, but in practical applications, one needs to increase that).

+## loading and looking at the data +welfare = read.csv2('welfare2.csv') +head(welfare) +#> support inequality income ideology country gap +#> 1 -18.5649610 0.3392724 0.1425111 1.9225985 0 0.1 +#> 2 -9.3905812 -0.9906646 -0.5117102 0.2483346 0 0.1 +#> 3 0.9276234 -2.2318510 -0.3856288 -1.3619216 0 0.1 +#> 4 -12.3594498 -3.0079501 -0.9440585 -0.2088675 0 0.1 +#> 5 -2.4834411 0.1000455 0.8322192 0.1321378 0 0.1 +#> 6 -11.4187853 -0.9543883 -0.8810503 0.2916444 0 0.1 +tail(welfare) +#> support inequality income ideology country gap +#> 3195 0.3190583 -0.7504798 -0.7839583 0.92300705 4 -0.8280808 +#> 3196 -1.3837239 0.6620435 -1.5566268 0.05634618 4 -0.8280808 +#> 3197 -1.3820016 -0.4298706 -1.0945688 0.71559078 4 -0.8280808 +#> 3198 0.6878775 0.5450604 2.6175887 -1.94844469 4 -0.8280808 +#> 3199 -7.9282930 1.7846004 1.6755823 1.29160208 4 -0.8280808 +#> 3200 -1.7472485 0.5030992 -0.5395479 0.20109879 4 -0.8280808
+

The variable country indicates the country (context) of +the observation, and the variable gap the gender gap in +welfare provision in the respective country. The estimation is similar +to the previous example, but now there is a second formula +for the context-level variables. Again, the example below uses few +iterations in the MCMC, but in practical applications, one needs to +increase that).

-## estimating the model
-mcmc = list(burn.in=1, ## MCMC burn-in period
-            n.iter =50) ## number of MCMC iterations to keep
-mod = hdpGLM(support ~ inequality + income + ideology, 
-             support ~ gap,
-         data=welfare, mcmc=mcmc)
+## estimating the model +mcmc = list(burn.in=1, ## MCMC burn-in period + n.iter =50) ## number of MCMC iterations to keep +mod = hdpGLM(support ~ inequality + income + ideology, + support ~ gap, + data=welfare, mcmc=mcmc)
-summary(mod)
-#>  
-#> -------------------------------- 
-#> hdpGLM Object 
-#> 
-#> Maximum number of clusters activated during the estimation: 1
-#> Number of MCMC iterations: 50
-#> Burn-in: 1
-#> 
-#> Number of contexts : 5
-#> 
-#> Number of clusters (summary across contexts): 
-#> 
-#>   Average Std.Dev Median Min. Max.
-#> 1       5 2.54951      5    1    8
-#> -------------------------------- 
-#> 
-#> 
-#> Summary statistics of clusters with data points in each context
-#> 
-#> --------------------------------
-#> Coefficients and clusters for context 1
-#> 
-#>                 Post.Mean Post.Median  HPD.lower   HPD.upper Cluster
-#> 1  (Intercept) -3.9200103  -3.9086649 -4.0916737 -3.82826390       1
-#> 2   inequality  1.7840391   1.9800815  0.2998919  2.09073735       1
-#> 3       income  3.8695044   3.8633582  3.8097297  3.96215519       1
-#> 4     ideology -8.3401337  -8.3416590 -8.4751317 -8.21856526       1
-#> 5  (Intercept) -2.2387978  -2.3739615 -2.9418510 -1.31788601       3
-#> 6   inequality  0.1876741   0.2056964 -0.1329852  0.59241276       3
-#> 7       income  3.3937737   3.4175683  3.0055069  3.98378178       3
-#> 8     ideology -8.9133117  -8.8768780 -9.5036670 -8.55398762       3
-#> 9  (Intercept) -3.8026545  -3.8645517 -4.1865797 -2.29474105       5
-#> 10  inequality -1.6675150  -1.6128776 -2.7301152 -1.28880865       5
-#> 11      income  3.9841636   3.9104714  3.7369937  5.35167042       5
-#> 12    ideology -8.3075173  -8.3508802 -8.5203981 -7.47045973       5
-#> 13 (Intercept) -3.0352503  -3.1860882 -3.9037019 -1.66774404       6
-#> 14  inequality -0.6841269  -0.3273439 -5.6208047  0.47306063       6
-#> 15      income  2.4741670   2.3702374  1.6612408  3.46469034       6
-#> 16    ideology -6.1972911  -6.7381009 -7.6686466 -0.04033671       6
-#> 17 (Intercept) -3.5119879  -3.7405088 -4.2691582 -1.17936223       7
-#> 18  inequality -1.2734880  -1.5497967 -2.2240719  0.98049926       7
-#> 19      income  2.5102981   3.8556703 -8.1437046  4.13988368       7
-#> 20    ideology -7.5784819  -8.0673148 -8.2630251 -5.31677672       7
-#> 
-#> --------------------------------
-#> Coefficients and clusters for context 2
-#> 
-#>                 Post.Mean Post.Median   HPD.lower   HPD.upper Cluster
-#> 1  (Intercept)  0.2732003  0.24765747  0.08483171  0.59943029       1
-#> 2   inequality -0.2933128 -0.28682990 -0.49909701 -0.08830094       1
-#> 3       income -0.1901150 -0.22034064 -0.50907363  0.03505336       1
-#> 4     ideology -1.8247332 -1.83985305 -1.94757344 -1.48178348       1
-#> 5  (Intercept)  1.5106250  1.44434394  1.14550070  2.57162657       2
-#> 6   inequality  0.7313438  0.84397878  0.24219831  0.97826343       2
-#> 7       income  0.6089516  0.58867164  0.29482767  0.98329998       2
-#> 8     ideology -1.7922469 -1.80373682 -2.13723951 -1.50451308       2
-#> 9  (Intercept) -0.6740773 -0.54561991 -1.18145672 -0.16011462       3
-#> 10  inequality -1.0610592 -1.09467102 -1.42892256 -0.76787129       3
-#> 11      income -0.4313721 -0.51162903 -0.89914787  0.10423671       3
-#> 12    ideology -2.1409275 -2.24963488 -2.59008094 -1.78213644       3
-#> 13 (Intercept)  0.2728293  0.27336499 -0.56435256  1.02437997       4
-#> 14  inequality -0.1939363 -0.21738758 -1.35182344  0.70445477       4
-#> 15      income  1.4764635  1.37804585  0.97006804  2.17856349       4
-#> 16    ideology -0.2310224 -0.31869305 -0.97775407  0.79429604       4
-#> 17 (Intercept)  0.1098856  0.06146258 -0.66553895  0.81635227       6
-#> 18  inequality  1.4695401  1.29127392  0.81911049  3.79368669       6
-#> 19      income  0.7212451  0.96553924 -0.47645000  1.41363031       6
-#> 20    ideology -1.4654754 -1.62243082 -2.30369871  1.46858254       6
-#> 21 (Intercept)  1.6276353  1.48262804  1.30792052  2.24962382       7
-#> 22  inequality  0.7113141  0.82903058 -0.46386869  1.13218786       7
-#> 23      income  1.1361645  1.06517728  0.46247915  1.58836776       7
-#> 24    ideology -1.6624824 -1.75954854 -2.04260080 -0.79330943       7
-#> 25 (Intercept)  0.4072432  0.41621185 -3.78887031  1.10572603       8
-#> 26  inequality -0.9054925 -1.18160709 -2.40898157  2.33015019       8
-#> 27      income -0.3256753 -0.35885498 -1.55389285  2.19606671       8
-#> 28    ideology -2.7148582 -2.88020386 -5.44320220 -0.70872687       8
-#> 29 (Intercept)  1.3103977  1.88449134 -2.80534329  3.14981324       9
-#> 30  inequality -0.1009143  0.24892829 -5.17799840  1.29803660       9
-#> 31      income  0.6023806  0.53718538 -2.71595475  4.42419630       9
-#> 32    ideology -2.5691415 -2.15059230 -6.67724704  0.93035046       9
-#> 
-#> --------------------------------
-#> Coefficients and clusters for context 3
-#> 
-#>                  Post.Mean Post.Median   HPD.lower  HPD.upper Cluster
-#> 1  (Intercept)  0.35564122  0.39771868 -0.17949410  0.5296717       1
-#> 2   inequality -0.37263183 -0.36376692 -0.50666603 -0.2421574       1
-#> 3       income -3.44765040 -3.44133972 -3.60867765 -3.3205957       1
-#> 4     ideology  1.41949114  1.45721960  1.09362917  1.5854301       1
-#> 5  (Intercept) -0.88841237 -0.86594794 -1.40016293 -0.5328050       2
-#> 6   inequality  1.24217561  1.26110918  0.79075018  1.4786188       2
-#> 7       income -3.92865325 -3.90266303 -4.23430391 -3.7145404       2
-#> 8     ideology  0.63933943  0.67598628  0.23099717  1.0321393       2
-#> 9  (Intercept) -0.17036962 -0.18754729 -0.46262535  0.2246101       4
-#> 10  inequality -0.52397781 -0.58681966 -0.74741275  0.3269360       4
-#> 11      income -4.18745525 -4.12836207 -4.93258347 -3.7495211       4
-#> 12    ideology  0.66941139  0.65308917  0.48711278  0.9969330       4
-#> 13 (Intercept) -1.44900977 -1.42130603 -1.69258514 -1.0527716       5
-#> 14  inequality -0.42356130 -0.49683295 -1.02769761  0.1707266       5
-#> 15      income -3.56803773 -3.56385970 -3.98559706 -3.1916302       5
-#> 16    ideology  0.60509219  0.64472298  0.08901490  1.0027910       5
-#> 17 (Intercept) -0.06901937 -0.08288345 -0.67176193  0.3194388      11
-#> 18  inequality  0.43071532  0.46410603 -0.03632484  0.9808859      11
-#> 19      income -2.74875138 -2.92085366 -3.35719143 -2.3897252      11
-#> 20    ideology  2.26478128  2.29540423  1.97541757  2.7870863      11
-#> 
-#> --------------------------------
-#> Coefficients and clusters for context 4
-#> 
-#>                Post.Mean Post.Median   HPD.lower  HPD.upper Cluster
-#> 1 (Intercept)  0.1720970  0.15850410  0.01012377  0.2955098       2
-#> 2  inequality -1.0048874 -1.08837894 -1.18515241 -0.9012064       2
-#> 3      income -2.5814141 -2.57422572 -2.72440873 -2.4240009       2
-#> 4    ideology -0.0672998 -0.05576457 -0.44418144  0.1126058       2
-#> 
-#> --------------------------------
-#> Coefficients and clusters for context 5
-#> 
-#>                  Post.Mean Post.Median  HPD.lower   HPD.upper Cluster
-#> 1  (Intercept)  0.35112841  0.52737155 -0.4656270  0.68626911       2
-#> 2   inequality  1.51297868  1.54842357  1.1726519  1.78528643       2
-#> 3       income -0.05284474 -0.12501810 -0.5087275  0.62043658       2
-#> 4     ideology -1.08106484 -1.07876439 -1.4498601 -0.73146120       2
-#> 5  (Intercept)  0.90999078  0.79466967  0.4362762  2.59032047       3
-#> 6   inequality  0.09580272  0.18286358 -0.6554419  0.46875591       3
-#> 7       income -0.69039572 -0.73321986 -1.6724944  0.05068042       3
-#> 8     ideology -2.27320553 -2.33519249 -2.6504735 -1.54872959       3
-#> 9  (Intercept) -0.97141646 -0.96488526 -2.4458632  2.25946736       5
-#> 10  inequality  0.02880251  0.03212130 -1.3522789  0.42435690       5
-#> 11      income -0.48491948 -0.71713818 -4.4210062  1.82024856       5
-#> 12    ideology -1.81957932 -2.09477993 -2.4766507  7.12661004       5
-#> 13 (Intercept) -0.26533672 -0.31394080 -0.6089792  0.44469833       6
-#> 14  inequality  0.29013509  0.77884268 -1.9584716  1.16701494       6
-#> 15      income -0.23019916 -0.17114408 -1.3522853  0.30178040       6
-#> 16    ideology -1.45117753 -1.95030096 -2.3895288  0.66372491       6
-#> 17 (Intercept)  0.16204728 -0.05510382 -0.9644732  2.87125145       9
-#> 18  inequality -2.80212196 -2.65528984 -4.6829714 -1.78957332       9
-#> 19      income -0.28010501 -0.28778440 -1.3533426  0.70671335       9
-#> 20    ideology -2.20416470 -2.16349929 -4.1285586 -1.30543912       9
-#> 21 (Intercept)  0.18447917  0.23793022 -1.1654610  0.83515362      10
-#> 22  inequality -2.88017535 -2.95639761 -3.3342745 -1.90349010      10
-#> 23      income -0.24403149 -0.28208104 -1.9570586  0.41382556      10
-#> 24    ideology -2.40547313 -2.40413095 -3.3615311 -2.09991780      10
-#> 
-#> --------------------------------
-#> Context-level coefficients:
-#>                Description   Post.Mean HPD.lower HPD.upper
-#> 1     Intercept of beta[0] -0.75338580 -3.378839  1.314950
-#> 2     Intercept of beta[1] -0.08219604 -3.115248  2.339131
-#> 3     Intercept of beta[2] -0.06027461 -2.180591  1.772515
-#> 4     Intercept of beta[3] -1.35226270 -3.861279  1.192784
-#> 5 Effect of gap on beta[0]  0.04922494 -2.298760  2.202872
-#> 6 Effect of gap on beta[1]  0.37408227 -1.416155  1.865252
-#> 7 Effect of gap on beta[2] -0.80822913 -2.559590  1.233182
-#> 8 Effect of gap on beta[3]  0.23634060 -1.731484  2.418950
-#> 
-#> --------------------------------
-

The summary contains more information now. As before, the column k indicates the estimated clusters. The column j indicates the country (context) of the estimated value for the respective cluster’s coefficient. The second summary ($tau) shows the marginal effect of the context-level feature (gap). Details of the interpretation can be found in Ferrari (2020).

-

There are a series of built-in functions to visualize the output. The function plot_tau() displays the estimation of the effect of the context-level variables.

+summary(mod) +#> +#> -------------------------------- +#> hdpGLM Object +#> +#> Maximum number of clusters activated during the estimation: 1 +#> Number of MCMC iterations: 50 +#> Burn-in: 1 +#> +#> Number of contexts : 5 +#> +#> Number of clusters (summary across contexts): +#> +#> Average Std.Dev Median Min. Max. +#> 1 3.8 1.30384 4 2 5 +#> -------------------------------- +#> +#> +#> Summary statistics of clusters with data points in each context +#> +#> -------------------------------- +#> Coefficients and clusters for context 1 +#> +#> Post.Mean Post.Median HPD.lower HPD.upper Cluster +#> 1 (Intercept) -3.850018 -3.831053 -4.0229723 -3.7761732 1 +#> 2 inequality -1.266301 -1.516352 -1.6044299 0.1208613 1 +#> 3 income 3.888059 3.888325 3.8193618 3.9482793 1 +#> 4 ideology -8.274958 -8.265861 -8.3941242 -8.2029475 1 +#> 5 (Intercept) -3.830148 -3.930795 -5.4704281 -1.7055653 3 +#> 6 inequality 2.698005 2.476961 2.0890243 4.7523562 3 +#> 7 income 2.894359 3.087680 0.5420687 3.7025250 3 +#> 8 ideology -6.326634 -6.573921 -7.1981261 -3.0954741 3 +#> 9 (Intercept) -3.683952 -3.799872 -3.9527464 -2.2439587 8 +#> 10 inequality 2.141463 2.032401 1.9139868 3.1865272 8 +#> 11 income 3.839811 3.874678 3.4707271 4.1176459 8 +#> 12 ideology -7.969450 -8.313740 -8.4020125 -1.7240427 8 +#> 13 (Intercept) -4.497681 -4.651865 -5.4672935 -2.8655485 11 +#> 14 inequality 1.680044 1.697127 1.0126947 2.1632947 11 +#> 15 income 3.177055 3.479234 0.9383592 4.4565578 11 +#> 16 ideology -8.136503 -8.326492 -9.1340563 -6.7406244 11 +#> +#> -------------------------------- +#> Coefficients and clusters for context 2 +#> +#> Post.Mean Post.Median HPD.lower HPD.upper Cluster +#> 1 (Intercept) 0.26820457 0.2158852 -0.6387111 3.16198684 1 +#> 2 inequality -0.32966802 -0.2581746 -2.8469563 0.16958412 1 +#> 3 income -0.00474453 -0.1930250 -0.9128338 2.40068345 1 +#> 4 ideology -2.33154026 -1.8418190 -6.6065095 -1.40993445 1 +#> 5 (Intercept) -0.34614107 -0.3312663 -0.6013942 0.08909974 4 +#> 6 inequality -1.13625815 -1.1731203 -1.4213765 -0.64566896 4 +#> 7 income -0.71030796 -0.5511284 -3.1148561 -0.34972378 4 +#> 8 ideology -2.21820821 -2.2268997 -2.4605034 -1.95506546 4 +#> 9 (Intercept) 0.93766701 0.8816030 -0.2345261 3.16835754 5 +#> 10 inequality -1.08511843 -1.0759441 -2.8524324 0.66261946 5 +#> 11 income -0.37491463 -0.1981289 -4.7820876 1.64841044 5 +#> 12 ideology -1.23932565 -1.1166439 -5.8248620 0.56954897 5 +#> 13 (Intercept) 1.40590664 1.2517123 0.8869990 3.35336823 6 +#> 14 inequality 0.67213706 0.8224769 -0.6216086 1.03727770 6 +#> 15 income 0.73993881 0.9611547 0.5139214 1.74369429 6 +#> 16 ideology -1.61525012 -1.6437936 -2.2960005 -1.20174431 6 +#> 17 (Intercept) 0.72691049 0.7499653 0.1064514 1.17306937 7 +#> 18 inequality 0.93554460 1.3044385 -0.8372661 2.14568306 7 +#> 19 income 0.25019338 0.6731732 -3.6588106 1.61649759 7 +#> 20 ideology -2.67148869 -2.5133020 -4.9952761 -1.69346827 7 +#> +#> -------------------------------- +#> Coefficients and clusters for context 3 +#> +#> Post.Mean Post.Median HPD.lower HPD.upper Cluster +#> 1 (Intercept) -0.26958132 -0.27255106 -0.4530445 -0.08352123 2 +#> 2 inequality -0.52824546 -0.52188321 -0.8275946 -0.29652662 2 +#> 3 income -3.94723633 -3.96481908 -4.1931022 -3.54475661 2 +#> 4 ideology 0.70405591 0.68623573 0.4202208 1.13490622 2 +#> 5 (Intercept) 0.06367205 0.07130943 -0.5418888 0.77731603 3 +#> 6 inequality 2.14480673 1.83807021 1.3741663 4.93870581 3 +#> 7 income -3.23920682 -3.40143934 -4.9905422 0.92275018 3 +#> 8 ideology 1.54120367 1.42790533 0.9597712 3.54438599 3 +#> 9 (Intercept) -0.15165257 -0.04072183 -2.6962179 0.44547907 6 +#> 10 inequality 0.36374283 0.39905078 -0.6200306 0.75847969 6 +#> 11 income -2.88937654 -2.86963961 -3.2771568 -2.37248370 6 +#> 12 ideology 2.47914067 2.27484585 1.8904840 6.38954636 6 +#> +#> -------------------------------- +#> Coefficients and clusters for context 4 +#> +#> Post.Mean Post.Median HPD.lower HPD.upper Cluster +#> 1 (Intercept) 0.83021798 0.68878802 -0.03022949 3.140887559 2 +#> 2 inequality -1.58461512 -1.58336282 -2.62800294 -0.016295020 2 +#> 3 income -0.69031623 -0.84359956 -1.96976016 0.325236017 2 +#> 4 ideology 0.25754289 0.20962710 -0.24891019 1.269744923 2 +#> 5 (Intercept) 0.07794797 0.07758135 -0.01556230 0.269848348 3 +#> 6 inequality -1.06651680 -1.05076594 -1.15640203 -0.950865772 3 +#> 7 income -2.64262423 -2.64675437 -2.72896788 -2.478995363 3 +#> 8 ideology -0.11877325 -0.11887087 -0.32833111 0.008842872 3 +#> +#> -------------------------------- +#> Coefficients and clusters for context 5 +#> +#> Post.Mean Post.Median HPD.lower HPD.upper Cluster +#> 1 (Intercept) 1.48417683 1.391018708 0.60851304 2.24602506 2 +#> 2 inequality -2.38014590 -2.630576886 -3.25749998 -1.14669602 2 +#> 3 income -1.00959724 -1.084044609 -1.55632758 -0.03069636 2 +#> 4 ideology -1.78574735 -1.889904364 -2.62883560 -0.90764453 2 +#> 5 (Intercept) -0.52860077 -0.411695995 -2.67741256 2.20494958 3 +#> 6 inequality 1.15931178 1.632231765 -2.65927617 4.49632079 3 +#> 7 income -0.63468894 -0.596065862 -3.69850037 2.80865933 3 +#> 8 ideology -2.47701021 -2.284631615 -5.14091883 -0.37967583 3 +#> 9 (Intercept) -0.04279885 0.097158268 -2.21617514 0.73490354 5 +#> 10 inequality 0.88306251 0.852795748 0.02803985 1.93526238 5 +#> 11 income -0.57270011 -0.265389504 -4.83645159 0.52254922 5 +#> 12 ideology -2.06286047 -2.111867999 -3.42846478 -0.91525928 5 +#> 13 (Intercept) -0.18275686 -0.153757790 -0.91408210 0.39708126 7 +#> 14 inequality 0.49015382 0.748620635 -0.81026353 1.12416091 7 +#> 15 income -0.41788024 -0.250106798 -2.16417778 0.11770630 7 +#> 16 ideology -2.14437779 -2.090991691 -3.01021834 -1.59087165 7 +#> 17 (Intercept) 0.23454252 -0.006609914 -0.31626061 2.31278243 9 +#> 18 inequality -2.80125890 -2.758064654 -3.23831491 -2.40184198 9 +#> 19 income -0.24273827 -0.135219596 -0.51665601 0.38628583 9 +#> 20 ideology -2.20108192 -2.278504066 -3.58542576 0.11818932 9 +#> +#> -------------------------------- +#> Context-level coefficients: +#> Description Post.Mean HPD.lower HPD.upper +#> 1 Intercept of beta[0] -0.8167835 -3.771344 3.218372 +#> 2 Intercept of beta[1] -0.2772584 -4.453605 2.017705 +#> 3 Intercept of beta[2] -0.3300868 -3.278375 2.520085 +#> 4 Intercept of beta[3] -0.8536481 -3.537610 2.513618 +#> 5 Effect of gap on beta[0] -0.4160391 -2.639034 1.729934 +#> 6 Effect of gap on beta[1] 0.4784796 -2.361204 2.821168 +#> 7 Effect of gap on beta[2] -0.4764465 -2.342310 2.150394 +#> 8 Effect of gap on beta[3] 0.6017164 -2.020003 3.376128 +#> +#> -------------------------------- +

The summary contains more information now. As before, +the column k indicates the estimated clusters. The column +j indicates the country (context) of the estimated value +for the respective cluster’s coefficient. The second summary +($tau) shows the marginal effect of the context-level +feature (gap). Details of the interpretation can be found +in Ferrari (2020).

+

There are a series of built-in functions to visualize the output. The +function plot_tau() displays the estimation of the effect +of the context-level variables.

-plot_tau(mod)
+plot_tau(mod)

-

The function plot_pexp_beta() displays the association between the context-level features and the latent heterogeneity in the effect of the linear coefficients in each context. The paramter ‘smooth.line’ plots a line representing the linear association between the context-level feature (gap) and the posterior averages of the marginal effects in each cluster. The parameter ncol.beta controls the number of columns in the figure for the panels. For more options, see help(plot_pexp_beta)

+

The function plot_pexp_beta() displays the association +between the context-level features and the latent heterogeneity in the +effect of the linear coefficients in each context. The paramter +‘smooth.line’ plots a line representing the linear association between +the context-level feature (gap) and the posterior averages +of the marginal effects in each cluster. The parameter +ncol.beta controls the number of columns in the figure for +the panels. For more options, see help(plot_pexp_beta)

-plot_pexp_beta(mod, smooth.line=TRUE, ncol.beta=2)
-#> 
-#> 
-#> Generating plots ...
-#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
-#> "none")` instead.
-#> `geom_smooth()` using formula 'y ~ x'
-#> `geom_smooth()` using formula 'y ~ x'
+plot_pexp_beta(mod, smooth.line=TRUE, ncol.beta=2) +#> +#> +#> Generating plots ... +#> Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as +#> of ggplot2 3.3.4. +#> The deprecated feature was likely used in the hdpGLM package. +#> Please report the issue at <https://github.com/DiogoFerrari/hdpGLM/issues>. +#> This warning is displayed once every 8 hours. +#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was +#> generated. +#> `geom_smooth()` using formula = 'y ~ x' +#> `geom_smooth()` using formula = 'y ~ x'

Reference

-
-
-

Ferrari, Diogo. 2020. “Modeling Context-Dependent Latent Effect Heterogeneity.” Political Analysis 28 (1): 20–46.

+
+
+Ferrari, Diogo. 2020. “Modeling Context-Dependent Latent Effect +Heterogeneity.” Political Analysis 28 (1): 20–46.
@@ -454,7 +527,7 @@

Reference

-

Site built with pkgdown 2.0.3.

+

Site built with pkgdown 2.0.7.

diff --git a/docs/articles/hdpGLM_files/figure-html/unnamed-chunk-10-1.png b/docs/articles/hdpGLM_files/figure-html/unnamed-chunk-10-1.png index 8919b77..03c8ac4 100644 Binary files a/docs/articles/hdpGLM_files/figure-html/unnamed-chunk-10-1.png and b/docs/articles/hdpGLM_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/docs/articles/hdpGLM_files/figure-html/unnamed-chunk-11-1.png b/docs/articles/hdpGLM_files/figure-html/unnamed-chunk-11-1.png index 1ae24e0..6f3456b 100644 Binary files a/docs/articles/hdpGLM_files/figure-html/unnamed-chunk-11-1.png and b/docs/articles/hdpGLM_files/figure-html/unnamed-chunk-11-1.png differ diff --git a/docs/articles/hdpGLM_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/hdpGLM_files/figure-html/unnamed-chunk-6-1.png index 9c9451f..38261c3 100644 Binary files a/docs/articles/hdpGLM_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/hdpGLM_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index fd40cd9..8affc85 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -17,7 +17,7 @@ hdpGLM - 1.0.2 + 1.0.3
@@ -75,7 +75,7 @@

All vignettes

-

Site built with pkgdown 2.0.3.

+

Site built with pkgdown 2.0.7.

diff --git a/docs/authors.html b/docs/authors.html index 6f3a2d9..0601f9f 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -17,7 +17,7 @@ hdpGLM - 1.0.2 + 1.0.3 @@ -74,16 +74,20 @@

Citation

-

Ferrari, Diogo (2020). Modeling Context-Dependent Latent Heterogeneity Political Analysis, 28(1), 20–46

+

Ferrari D (2023). +“hdpGLM: An R Package to Estimate Heterogeneous Effects in Generalized Linear Models Using Hierarchical Dirichlet Process.” +Journal of Statistical Software, 107(10), 1–37. +doi:10.18637/jss.v107.i10. +

@Article{,
-  title = {Hierarchial Dirichlet Process Generalized Linear Mixed Model (hdpGLM)},
+  title = {{hdpGLM}: An {R} Package to Estimate Heterogeneous Effects in Generalized Linear Models Using Hierarchical {D}irichlet Process},
   author = {Diogo Ferrari},
-  journal = {Political Analysis},
-  year = {2020},
-  volume = {1},
-  number = {28},
-  pages = {20-46},
-  url = {https://doi.org/10.1017/pan.2019.13},
+  journal = {Journal of Statistical Software},
+  year = {2023},
+  volume = {107},
+  number = {10},
+  pages = {1--37},
+  doi = {10.18637/jss.v107.i10},
 }
@@ -97,7 +101,7 @@

Citation

-

Site built with pkgdown 2.0.3.

+

Site built with pkgdown 2.0.7.

diff --git a/docs/index.html b/docs/index.html index d54b087..77f8d5d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -12,7 +12,7 @@ - +