Title: | Functions and Datasets for "Bayesian Methods: A Social and Behavioral Sciences Approach" |
Version: | 1.0.3 |
Author: | Jonathan Homola, Danielle Korman, Jacob Metz, Miguel Pereira, Mauricio Vela, and Jeff Gill <jgill5402@mac.com> |
Maintainer: | Jeff Gill <jgill5402@mac.com> |
Description: | Functions and datasets for Jeff Gill: "Bayesian Methods: A Social and Behavioral Sciences Approach". First, Second, and Third Edition. Published by Chapman and Hall/CRC (2002, 2007, 2014) <doi:10.1201/b17888>. |
Depends: | R (≥ 3.0.1) |
Imports: | MASS, mice |
Suggests: | coda, nnet |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.1.1 |
Packaged: | 2022-10-14 05:13:08 UTC; selimyaman |
NeedsCompilation: | no |
Repository: | CRAN |
Date/Publication: | 2022-10-14 11:25:17 UTC |
DA_cwp
Description
Data on ancient Chinese wars
Details
The variables included in the dataset are:
X1
CHLEG010
LEGHUANG
X.2697
X.2697.1
X2
X1.1
X1.2
X0
X0.1
X2.1
X3
X2.2
X3.1
X2.3
actuarial
Description
actuarial claims data for three groups of insurance policyholders p. 449
Usage
data(actuarial)
Format
dataset with 5 observations of 7 variables
Details
The variables included in the dataset are:
year
payroll
for groups 1, 2, and 3claims
for groups 1, 2, and 3
Source
Scollnik, D. P. M. (2001). Actuarial Modeling with MCMC and BUGS. North American Actuarial Journal 5, 95-124.
adam.jags
Description
data from Differences in the Validity of Self-Reported Drug Use Across Five Factors in Indianapolis, Fort Lauderdale, Phoenix, and Dallas, 1994 (ICPSR Study Number 2706, Rosay and Herz (2000), from the Arrestee Drug Abuse Monitoring (ADAM) Program/Drug Use Forecasting, ICPSR Study Number 2826. The original purpose of the study was to understand the accuracy of self-reported drug use, which is a difficult problem for obvious reasons.
The variables included in the dataset are:
AGEGRP
1 for 1,700 cases 18 through 30 years old, 2 for 1,265 cases 31 years old or overCASES
CATS
COCSELF
indicating self-reported cocaine usage prior to arrest (0 for 2,220 negative responses, 1 for 745 positive responses)COCTEST
COVARS
GROUP
ID
MJSELF
MJTEST
a dichotomous variable indicating a positive urine test for marijuanOFFENSE
RACE
1 for 1,554 black cases, 2 for 1,411 white casesSEX
1 for 2,213 male cases, 2 for 752 female casesSITE
coded according to: Indianapolis = 1 (759 cases), Ft. Lauderdale = 2 (974 cases),Phoenix = 3 (646 cases), and Dallas = 4 (586 cases)
Usage
data(adam.jags)
afghan.deaths
Description
NATO Fatalities in Afghanistan, 10/01 to 1/07. see page 350
Usage
data(afghan.deaths)
Format
52 monthly periods, listed by rows
africa
Description
African Coups Data, pp.562-564
Usage
data(africa)
Format
data frame with 33 observations of different African countries' military coups with 7 explanatory variables
Details
The variables included in the dataset are:
MILTCOUP
Military CoupsMILITARY
Military OligarchyPOLLIB
Political Liberalization: 0 for no observable civil rights for political expression, 1 for limited, and 2 for extensivePARTY93
number of legally registered political partiesPCTVOTE
Percent Legislative VotingPCTTURN
Percent registered votingSIZE
in one thousand square kilometer unitsPOP
Population in millionsNUMREGIM
RegimeNUMELEC
Election
Source
Bratton, M. and Van De Walle, N. (1994). Neopatrimonial Regimes and Political Transitions in Africa. World Politics 46, 453-489.
asap.data.list
Description
The American State Administrator's Project (ASAP) survey asks administrators about the influence of a variety of external political actors including "clientele groups" in their agencies., see page 395.
The variables included in the dataset are:
contracting
scale from 0 : 6 where higher indicates more private contracting within the respondent's agency.gov.incluence
respondents' assessment of the governor's influence on contracting in their agency.leg.influence
respondents' assessment of the legislatures' influence on contracting in their agency, ranging from 0 : 21.elect.board
dichotomous variable coded 1 if appointed by a board, a commission or elected, and 0 otherwise.years.tenure
number of years that the respondent has worked at their current agency.education
ordinal variable for level of education possessed by the respondent.partisan.ID
a 5-point ordinal variable (1-5) for the respondent's partisanship (strong Democrat to strong Republican).category
categories of agency type.med.time
whether the respondent spent more or less than the sample median with representatives of interest groups.medt.contr
interaction variable between med.time and contracting.gov.ideology
state government ideology from Berry et al. (1998) from 0 to 100.lobbyists
total state lobbying registrants in 2000-01 from Gray and Lowery (1996, 2001).nonprofits
provides the total number of nonprofit groups in the respondents' state in the year 2008, divided by 10,000.
Usage
data(asap.data.list)
Baldus Dataset
Description
Data from Baldus Study on death sentences in Georgia (Exercise 14.2, p. 521).
To use the data in JAGS or WinBugs, see baldus.jags
and balfus.winbugs
, respectively.
Usage
data(baldus)
Details
The variables included in the dataset are:
race
Defendant's race (1 = Black)educatn
Educational levelemploym
Employment status (1 = Employed)SES
Socioeconomic status (1 = Low Wage)married
Marital status (1 = Married)num.chld
Number of childrenmilitary
Military experience (1 = Serving, 0 = No military service, -1 = Dishonorable Discharge)pr.arrst
plea
Plea to Murder Indictmentsentence
Sentenceddefense
Status of Principle Defense Council (1 = Retained, 2 = Appointed)dp.sght
Prosecutor Waive/Fail to Seek DP (1 = Failed/Unknown, 2 = Sought DP)jdge.dec
Judge Took Sentence from Jury?pen.phse
Was there a penalty trial?did.appl
Did defendant appeal cov. or sentence?out.appl
Outcome of appealvict.sex
Victim sexpr.incrc
vict.age
Victim's agevict.rel
Relation of victim with defendantvict.st1
Victim status (0 = Non-police+judicial, 1 = Police+judicial)vict.st2
specialA
Special Circumstances ()methodA
Method of killingnum.kill
Number of persons killed by defendantnum.prps
Number of persons killed by coperpetratordef.age
Defendant's ageaggrevat
Aggravating circumstancesbloody
Bloody crimefam.lov
insane
Defendant invoked insanity defensemitcir
num.depr
rape
Rape involved
Source
Baldus, D. C., Pulaski, C., & Woodworth, G. (1983). Comparative review of death sentences: An empirical study of the Georgia experience. The Journal of Criminal Law and Criminology (1973-), 74(3), 661-753.
See Also
baldus.jags baldus.winbugs
bcp
Description
Implementation of bcp function, see pages 362-363 (2nd Edition).
Usage
bcp(theta.matrix, y, a, b, g, d)
Arguments
theta.matrix |
theta.matrix |
y |
Counts of Coal Mining Disasters |
a |
Alpha Value in the lambda Prior |
b |
Beta Value in the lambda Prior |
g |
Gamma Value in the phi Prior |
d |
Delta Value in the phi Prior |
Author(s)
Jeff Gill
Examples
## Not run:
bcp(theta.matrix,y,a,b,g,d)
## End(Not run)
biv.norm.post
Description
A function to calculate posterior quantities of the bivariate normal. See page 94.
Usage
biv.norm.post(data.mat,alpha,beta,m,n0=5)
Arguments
data.mat |
A matrix with two columns of normally distributed data |
alpha |
Wishart first (scalar) parameter |
beta |
Wishart second (matrix) parameter |
m |
prior mean for mu |
n0 |
prior confidence parameter |
Value
Returns
mu2 |
posterior mean, dimension 1 |
sig1 |
posterior mean, dimension 2 |
sig2 |
posterior variance, dimension 1 |
rho |
posterior variance, dimension 2 |
Author(s)
Jeff Gill
Examples
rwishart <- function(df, p = nrow(SqrtSigma), SqrtSigma = diag(p)) {
if((Ident <- missing(SqrtSigma)) && missing(p)) stop("either p or SqrtSigma must be specified")
Z <- matrix(0, p, p)
diag(Z) <- sqrt(rchisq(p, df:(df-p+1)))
if(p > 1) {
pseq <- 1:(p-1)
Z[rep(p*pseq, pseq) + unlist(lapply(pseq, seq))] <- rnorm(p*(p-1)/2)
}
if(Ident) crossprod(Z)
else crossprod(Z %*% SqrtSigma)
}
data.n10 <- rmultinorm(10, c(1,3), matrix(c(1.0,0.7,0.7,3.0),2,2))
rep.mat <- NULL; reps <- 1000
for (i in 1:reps){
rep.mat <- rbind(rep.mat, biv.norm.post(data.n10,3, matrix(c(10,5,5,10),2,2),c(2,2)))
}
round(normal.posterior.summary(rep.mat),3)
cabinet.duration
Description
Cabinet duration (constitutional inter-election period) for eleven Western European countries from 1945 to 1980, page 65
Usage
cabinet.duration
Format
cabinet duration of 11 countries
Details
The variables included in the dataset are:
N
number of cabinetsdur
average length of duration
Note
Row names indicate country.
References
Browne, E. C., Frendreis, J. P., and Gleiber, D. W. (1986). The Process of Cabinet Dissolution: An Exponential Model of Duration and Stability in Western Democracies. American Journal of Political Science 30, 628-650.
child
Description
Child Support Collection Policies from 50 states from 1982-1991. See page 166
Usage
child
Format
observations of 8 variables for 50 states
Details
The variables included in the dataset are:
SCCOLL
Change in Child Support collectionsACES
Chapters per PopulationINSTABIL
Policy InstabilityAAMBIG
Policy AmbiguityCSTAFF
Change in Agency StaffingARD
State Divorce RateASLACK
Organizational SlackAEXPEND
State Level Expenditures
Source
Meier, K.J. and Keisler, L.R. (1996). Public Administration as a Science of the Artificial: A Method for Prescription, Public Administration Review 56, 459-466.
china.wars
Description
Modeling code for the example of ancient Chinese wars. See page 163-165
Usage
china.wars()
Author(s)
Jeff Gill
Source
Claudio Cioffi-Revilla and David Lai, 2001,
"Chinese Warfare and Politics in the Ancient East Asian International System",
Download from <doi:10.1080/03050620108434971>
Henry A. Murray Research Archive
Center for International Relations, Department of Political Science, University of Colorado, Boulder, USA
coal.mining.disasters
Description
A vector of British Coal Mining Disasters, see page 549-550
Usage
coal.mining.disasters
Format
vector of length 111
Source
Lynn, R. and Vanhanen, T. (2001). National IQ and Economic Development. Mankind Quarterly LXI, 415-437.
contracep
Description
Contraception Data by country. See page 446
Usage
data(contracep)
Format
4 variables for 15 countries
Details
The variables included in the dataset are:
Country
Developing countries by sizeURC
Rural ChildhoodWED
Years of Education for the WomanFPE
Exposure to Family Planning EffortsWED.FPE
Interaction term specified by Wong and Mason
Source
Wong, G. Y. and Mason, W. M. (1985). The Hierarchical Logistic Regression Model for Multilevel Analysis. Journal of the American Statistical Association 80, 513-524.
dmultinorm
Description
dmultinorm function, see page 376.
Usage
dmultinorm(xval,yval,mu.vector,sigma.matrix)
Arguments
xval |
Vector of X Random Variables |
yval |
Vector of Y Random Variables |
mu.vector |
Mean Vector |
sigma.matrix |
Matrix of Standard Deviations |
Author(s)
Jeff Gill
dp
Description
Death Penalty Data, See Page 142.
Usage
data(dp)
Format
7 variables for 17 states
Details
The variables included in the dataset are:
X
StateEXECUTIONS
Number of capital punishments at state level in 1997INCOME
Median per capita income in dollarsPERPOVERTY
Percent classified as living in povertyPERBLACK
Percent of black citizens in populationVC100k96
Rate of violent crime per 100,000 residents for 1996SOUTH
Is the state in the South?PROPDEGREE
Proportion of population with college degree
Source
Norrander, B. (2000). The Multi-Layered Impact of Public Opinion on Capital Punishment Implementation in the American States. Political Research Quarterly 53, 771-793.
durations.hpd
Description
Simple HPD calculator from Chapter 2 (page 51, 2nd Edition).
Usage
durations.hpd(support,fn.eval,start,stop,target=0.90,tol=0.01)
Arguments
support |
x-axis values |
fn.eval |
function values at x-axis points |
start |
starting point in the vectors |
stop |
stoppng point in the vectors |
target |
Desired X Level |
tol |
Tolerance for round-off |
Author(s)
Jeff Gill
Examples
## Not run:
get("cabinet.duration")
ruler <- seq(0.45,0.75,length=10000)
g.vals <- round(dgamma(ruler,shape=sum(cabinet.duration$N),
rate=sum(cabinet.duration$N*cabinet.duration$dur)),2)
start.point <- 1000; stop.point <- length(g.vals)
durations.hpd(ruler,g.vals,start.point,stop.point)
## End(Not run)
elicspend
Description
Eliciting expected campaign spending data. Eight campaign experts are queried for quantiles at levels m = [0.1, 0.5, 0.9], and they provide the following values reflecting the national range of expected total intake by Senate candidates (in thousands). See page 120
Usage
data(elicspend)
ethnic.immigration
Description
1990-1993 W.Europe Ethnic/Minority Populations. see page 280.
Usage
data(ethnic.immigration)
Format
total number of ethnic immigrants living in Western Europe from 22 countries
Details
The variables included in the dataset are:
Country.of.Origin
Country of origin of immigrantsEstimated.Total.K.
Estimated total ethnic minority population in Western European CountriesPercent.of.Total
Percent of Total
Source
Peach, C. (1997). Postwar Migration to Europe: Reflux, Influx, Refuge. Social Science Quarterly 78, 269-283.
executions
Description
Execution data.
The variables included in the dataset are:
State
StateEXECUTIONS
Number of capital punishments at state level in 1997Median.Income
Median per capita income in dollarsPercent.Poverty
Percent classified as living in povertyPercent.Black
Percent of black citizens in populationViolent.Crime
Rate of violent crime per 100,000 residents for 1996
Usage
data(executions)
Format
explanatory variables for 17 states
Campaign fundraisign elicitations
Description
Fabricated data on campaign fundraising elicitations. See page 120
Usage
experts(q1,q2,q3)
Arguments
q1 |
the 0.1 quantile |
q2 |
the 0.5 quantile |
q3 |
the 0.9 quantile |
expo.gibbs
Description
Simple Gibbs sampler demonstration on conditional exponentials from Chapter 1 (pages 25-27).
Usage
expo.gibbs(B,k,m)
Arguments
B |
an upper bound |
k |
length of the subchains |
m |
number of iterations |
Author(s)
Jeff Gill
expo.metrop
Description
Simple Metropolis algorithm demonstration using a bivariate exponential target from Chapter 1 (pages 27-30).
Usage
expo.metrop(m,x,y,L1,L2,L,B)
Arguments
m |
number of iterations |
x |
starting point for the x vector |
y |
starting point for the y vector |
L1 |
event intensity for the x dimension |
L2 |
event intensity for the y dimension |
L |
shared event intensity |
B |
upper bound |
Author(s)
Jeff Gill
Examples
expo.metrop(m=5000, x=0.5, y=0.5, L1=0.5, L2=0.1, L=0.01, B=8)
fdr
Description
FDR election data. See page 576
The variables included in the dataset are:
State
State nameFDR
Whether or not FDR won the state in 1932 election, 1 = won, 0 = lostPRE.DEP
Mean income per state before the Great Depression (1929), in dollarsPOST.DEP
Mean income per state after the Great Depression (1932), in dollarsFARM
Total farm wage and salary disbursements in thousands of dollars per state in 1932
Usage
data(fdr)
hanjack
Description
1964 presidential election data. See page 221
Usage
hanjack(N,F,L,W,K,IND,DEM,WR,WD,SD)
Arguments
N |
number of cases in the group |
F |
Observed cell proportion voting for Johnson |
L |
log-ratio of this proportion, see p. 246 |
W |
collects the inverse of the diagonal of the matrix for the group-weighting from $[N_iP_i(1-P_i)]$ |
K |
constant |
IND |
indifference to the election |
DEM |
stated preference for Democratic party issues |
WR |
Weak Republican |
WD |
Weak Democrat |
SD |
Strong Democrat |
References
Hanushek, E. A. and Jackson, J. E. (1977). Statistical Methods for Social Scientists San Diego, Academic Press
hit.run
Description
Implementation of hit.run algorithm, p. 361.
Usage
hit.run(theta.mat,reps,I.mat)
Arguments
theta.mat |
theta.mat |
reps |
reps |
I.mat |
I.mat |
Author(s)
Jeff Gill
Examples
## Not run:
#code to implement graph on p. 362, see page 376.
num.sims <- 10000
Sig.mat <- matrix(c(1.0,0.95,0.95,1.0),2,2)
walks<-rbind(c(-3,-3),matrix(NA,nrow=(num.sims-1),ncol=2))
walks <- hit.run(walks,num.sims,Sig.mat)
z.grid <- outer(seq(-3,3,length=100),seq(-3,3,length=100),
FUN=dmultinorm,c(0,0),Sig.mat)
contour(seq(-3,3,length=100),seq(-3,3,length=100),z.grid,
levels=c(0.05,0.1,0.2))
points(walks[5001:num.sims,],pch=".")
iq data frame
Description
IQ data for 80 countries. See pages 85-87
Usage
data(iq)
Source
Lynn, R. and Vanhanen, T. (2001). National IQ and Economic Development. Mankind Quarterly LXI, 415-437.
Examples
## Not run:
{
data(iq)
n <- length(iq[1,])
t.iq <- (iq[1,]-mean(as.numeric(iq)))/(sd(iq[1,])/sqrt(n))
r.t <- (rt(100000, n-1)*(sd(iq)/sqrt(n))) + mean(as.numeric(iq))
quantile(r.t,c(0.01,0.10,0.25,0.5,0.75,0.90,0.99))
r.sigma.sq <- 1/rgamma(100000,shape=(n-2)/2, rate=var(as.numeric(iq))*(n-1)/2)
quantile(sqrt(r.sigma.sq), c(0.01,0.10,0.25,0.5,0.75,0.90,0.99))
}
## End(Not run)
italy.parties
Description
Italian Parties Data. Vote share of Italian parties from 1948-1983. See page 370-371.
Usage
data(italy.parties)
lunatics
Description
An 1854 study on mental health in the fourteen counties of Massachusetts yields data on 14 cases. This study was performed by Edward Jarvis (then president of the American Statistical Association)
The variables included in the dataset are:
NBR
the number of "lunatics" per county.DISt
distance to the nearest mental healthcare centerPOP
population in the county by thousandsPDEN
population per square county milePHOME
the percent of "lunatics" cared for in the home
Usage
data(lunatics)
Marriage Rates in Italy
Description
Italian Marriage Rates. See page 430
Usage
data(marriage.rates)
Format
a vector containing 16 numbers
Source
Columbo, B. (1952). Preliminary Analysis of Recent Demographic Trends in Italy. Population Index 18, 265-279.
metropolis
Description
Implementation of metropolis function, p. 359.
Usage
metropolis(theta.matrix,reps,I.mat)
Arguments
theta.matrix |
theta.matrix |
reps |
reps |
I.mat |
I.mat |
Author(s)
Jeff Gill
militarydf
Description
A dataset of two variables. The proportional changes in military personnel for the named countries. See page 483-484
The variables included in the dataset are:
Year
The year selected to evaluateYugoslavia
The proportion change in the size of Yugoslavia's militaryAlbania
The proportion change in the size of Albania's militaryBulgaria
The proportion change in the size of Bulgaria's militaryCzechoslovakia
The proportion change in the size of Czechoslovakia's militaryGerman.Dem.Republic
The proportion change in the size of the German Democratic Republic's militaryHungary
The proportion change in the size of Hungary's militaryPoland
The proportion change in the size of Poland's militaryRumania
The proportion change in the size of Romania's militaryUSSR
The proportion change in the size of the Soviet Union's military
Usage
data(militarydf)
Format
a data frame with 35 observations of years from 1949 to 1983 with 10 explanatory variables
Source
Faber, J. (1989). Annual Data on Nine Economic and Military Characteristics of 78 Nations (SIRE NATDAT), 1948-1983. Ann Arbor: Inter-University Consortium for Political and Social Research and Amsterdam, and Amsterdam, the Netherlands: Europa Institute, Steinmetz Archive.
nc.sub.dat
Description
North Carolina county level health data from the 2000 U.S. census and North Carolina public records, see page 78.
The variables included in the dataset are:
Substantiated.Abuse
within family documented abuse for the countyPercent.Poverty
percent within the county living in poverty, U.S. definitionTotal.Population
county population/1000
Usage
nc.sub.dat
Format
data frame with 100 observations of different counties in North Carolina with 3 explanatory variables
Source
data from 2000 US census and North Carolina Division of Public Health, Women's and Children's Health Section in Conjunction with State Center for Health Statistics
norm.known.var
Description
A function to calculate posterior quanties for a normal-normal model with known variance (pages 70-72). It produces the posterior mean, variance, and 95% credible interval for user-specified prior.
Usage
norm.known.var(data.vec,pop.var,prior.mean,prior.var)
Arguments
data.vec |
a vector of assumed normally distributed data |
pop.var |
known population variance |
prior.mean |
mean of specified prior distribution for mu |
prior.var |
variance of specified prior distribution for mu |
Author(s)
Jeff Gill
normal posterior summary
Description
A function to calculate posterior quantities of bivariate normals. See pages 74-80.
Usage
normal.posterior.summary(reps)
Arguments
reps |
a matrix where the columns are defined as in the output of biv.norm.post: |
Author(s)
Jeff Gill
See Also
norr
Description
An 1854 study on mental health in the fourteen counties of Massachusetts yields data on 14 cases. This study was performed by Edward Jarvis (then president of the American Statistical Association)
The variables included in the dataset are:
Current.policy
Current sentencing policyPast.execution.rate
Past execution ratePoliticla.Culture
Political cultureCurrent.opinion
Current opinionCitizen.ideology
Citizen ideologyMurder.Rate
Murder rateCatholic
CatholicBlack
BlackUrban
UrbanPast.laws
Past lawsPast.opinion
Past opinion
Usage
data(norr)
opic
Description
private capital investment data. See Page 390.
The variables included in the dataset are:
Fund
Name of the private companyAge
Years the company has been in existenceStatus
Whether the company is investing or divestingSize
Maximum fund size in millions
Usage
data(opic)
pbc.vote
Description
Precinct level data for Palm Beach County, Florida from the 2000 U.S. Presidential Election, see page 149
The variables included in the dataset are:
badballots
Total number of spoiled ballotstechnology
Voting Technology used, 0 for a datapunch machine or a butterfly ballot, 1 for votomaticnew
Number of "new" voters, as in those who have not voted in the precinct for previous 6 yearssize
Total number of precinct votersRepublican
The number of voters registered as Republicanwhite
The number of white nonminority voters in a given precinct
Usage
data(pbc.vote)
Format
data frame with 516 observations of each precinct in Palm Beach County with 11 explanatory variables
Source
Palm Beach Post collected data from state and federal sources about precinct level data in Palm Beach County for the 2000 US presidential election
plot_walk_G
Description
plot_walk_G code used to produce figure 10.2
Usage
plot_walk_G(walk.mat,sim.rm,X=1,Y=2)
Arguments
walk.mat |
walk.mat |
sim.rm |
sim.rm |
X |
X |
Y |
Y |
Author(s)
Jeff Gill
plot_walk_MH
Description
plot_walk_MH code used to produce figure 10.4
Usage
plot_walk_MH(walk.mat)
Arguments
walk.mat |
walk.mat |
Author(s)
Jeff Gill
recidivism
Description
Recidivism Rates. See page 188
The variables included in the dataset are:
Crime.Type
The type of crime committedReleased
The number of individuals released from a facilityReturned
The number of individuals returned to a facilityPercentage
(The number of individuals returned to a facility)/(The number of individuals released from a facility)
Usage
data(recidivism)
Format
data frame with 27 observations of different crime types with 5 explanatory variables
Source
state-level recidivism data as collected by the Oklahoma Department of Corrections from January 1, 1985 to June 30, 1999
retail.sales
Description
Retail sales from 1979 through 1989 based on data provided by the U.S. Department of Commerce through the Survey of Current Business, see page 439
The variables included in the dataset are:
TIME
the economic quarter specified, starting from the first quarter of 1979 where j=1 to the fourth quarter of 1989 where j=44DSB
national income wage and salary disbursements (in billions of dollars)EMP
employees on non-agricultural payrolls (in thosuands)BDG
building material dealer sales (in millions of dollars)CAR
retail automotive dealer sales (in millions of dollars)FRN
home furnishings dealer sales (in millions of dollars)GMR
general merchandise dealer sales (in millions of dollars)
Usage
data(retail.sales)
Format
data frame with 44 observations of statistics for different economic quarters with 7 explanatory variables
Source
U.S. Department of Commerce data from first quarter of 1979 to fourth quarter of 1989
rmultinorm
Description
a function to generate random multivariate Gaussians.
Usage
rmultinorm(n, mu, vmat, tol = 1e-07)
Arguments
n |
nu |
mu |
vector of mean |
vmat |
variance-covariance matriz |
tol |
tolerance |
Author(s)
Jeff Gill
See Also
romney
Description
Analysis of cultural consensus data using binomial likelihood and beta prior.
Usage
romney()
Format
See for yourself. Modify as desired.
Author(s)
Jeff Gill
Source
Romney, A. K. (1999). Culture Consensus as a Statistical Model.
Current Anthropology 40 (Supplement), S103-S115.
sir
Description
Implementation of Rubin's SIR, see pages 338-341 (2nd Edition)
Usage
sir(data.mat,theta.vector,theta.mat,M,m,tol=1e-06,ll.func,df=0)
Arguments
data.mat |
A matrix with two columns of normally distributed data |
theta.vector |
The initial coefficient estimates |
theta.mat |
The initial vc matrix |
M |
The number of draws |
m |
The desired number of accepted values |
tol |
The rounding/truncing tolerance |
ll.func |
loglike function for empirical posterior |
df |
The df for using the t distribution as the approx distribution |
Author(s)
Jeff Gill
Examples
## Not run:
sir <- function(data.mat,theta.vector,theta.mat,M,m,tol=1e-06,ll.func,df=0) {
importance.ratio <- rep(NA,M)
rand.draw <- rmultinorm(M,theta.vector,theta.mat,tol = 1e-04)
if (df > 0)
rand.draw <- rand.draw/(sqrt(rchisq(M,df)/df))
empirical.draw.vector <- apply(rand.draw,1,ll.func,data.mat)
if (sum(is.na(empirical.draw.vector)) == 0) {
print("SIR: finished generating from posterior density function")
print(summary(empirical.draw.vector))
}
else {
print(paste("SIR: found",sum(is.na(empirical.draw.vector)),
"NA(s) in generating from posterior density function, quiting"))
return()
}
if (df == 0) {
normal.draw.vector <- apply(rand.draw,1,normal.posterior.ll,data.mat)
}
else {
theta.mat <- ((df-2)/(df))*theta.mat
normal.draw.vector <- apply(rand.draw,1,t.posterior.ll,data.mat,df)
}
if (sum(is.na(normal.draw.vector)) == 0) {
print("SIR: finished generating from approximation distribution")
print(summary(normal.draw.vector))
}
else {
print(paste("SIR: found",sum(is.na(normal.draw.vector)),
"NA(s) in generating from approximation distribution, quiting"))
return()
}
importance.ratio <- exp(empirical.draw.vector - normal.draw.vector)
importance.ratio[is.finite=F] <- 0
importance.ratio <- importance.ratio/max(importance.ratio)
if (sum(is.na(importance.ratio)) == 0) {
print("SIR: finished calculating importance weights")
print(summary(importance.ratio))
}
else {
print(paste("SIR: found",sum(is.na(importance.ratio)),
"NA(s) in calculating importance weights, quiting"))
return()
}
accepted.mat <- rand.draw[1:2,]
while(nrow(accepted.mat) < m+2) {
rand.unif <- runif(length(importance.ratio))
accepted.loc <- seq(along=importance.ratio)[(rand.unif-tol) <= importance.ratio]
rejected.loc <- seq(along=importance.ratio)[(rand.unif-tol) > importance.ratio]
accepted.mat <- rbind(accepted.mat,rand.draw[accepted.loc,])
rand.draw <- rand.draw[rejected.loc,]
importance.ratio <- importance.ratio[rejected.loc]
print(paste("SIR: cycle complete,",(nrow(accepted.mat)-2),"now accepted"))
}
accepted.mat[3:nrow(accepted.mat),]
}
# The following are log likelihood functions that can be plugged into the sir function above.
logit.posterior.ll <- function(theta.vector,X) {
Y <- X[,1]
X[,1] <- rep(1,nrow(X))
sum( -log(1+exp(-X
-log(1+exp(X)))))
}
normal.posterior.ll <- function(coef.vector,X) {
dimnames(coef.vector) <- NULL
Y <- X[,1]
X[,1] <- rep(1,nrow(X))
e <- Y - X
sigma <- var(e)
return(-nrow(X)*(1/2)*log(2*pi)
-nrow(X)*(1/2)*log(sigma)
-(1/(2*sigma))*(t(Y-X)*(Y-X)))
}
t.posterior.ll <- function(coef.vector,X,df) {
Y <- X[,1]
X[,1] <- rep(1,nrow(X))
e <- Y - X
sigma <- var(e)*(df-2)/(df)
d <- length(coef.vector)
return(log(gamma((df+d)/2)) - log(gamma(df/2))
- (d/2)*log(df)
-(d/2)*log(pi) - 0.5*(log(sigma))
-((df+d)/2*sigma)*log(1+(1/df)*
(t(Y-X*(Y-X)))))
}
probit.posterior.ll <- function (theta.vector,X,tol = 1e-05) {
Y <- X[,1]
X[,1] <- rep(1,nrow(X))
Xb <- X
h <- pnorm(Xb)
h[h<tol] <- tol
g <- 1-pnorm(Xb)
g[g<tol] <- tol
sum( log(h)*Y + log(g)*(1-Y) )
}
## End(Not run)
socatt
Description
Data from the British Social Attitudes (BSA) Survey 1983-1986.
The variables included in the dataset are:
District
identifying for geographic district.Respondent.Code
respondent identifierYear.Code
1 = 1983, 2 = 1984, 3 = 1985, 4 = 1986Num.Answers
number of positive answers to seven questionsParty
1 = Conservative, 2 = Labour, 3 = Lib/SDP/Alliance, 4 = othersSocial.Class
1 = middle, 2 = upper working, 3 = lower workingGender
1 = male, 2 = female.Age
age in years 18-80Religion
1 = Roman Catholic, 2 = Protestant/Church of England, 3 = others, 4 = none.
Usage
data(socatt)
strikes
Description
French Coal Strikes, see page 212 and 213
The variables included in the dataset are:
Year
The year the labor strikes in France occurredCounts
The number of labor strikes that occurred in France per year
Usage
data(strikes)
Format
data frame with 11 observations of strikes that occurred in different years with 1 explanatory variable
Source
Conell, C. and Cohn, S. (1995). Learning from Other People's Actions: Environmental Variation and Diffusion in French Coal Mining Strikes, 1890-1935. American Journal of Sociology 101, 366-403.
Examples
n <- length(strikes)
r <- 1
s.y <- sum(strikes)
p.posterior.1000000 <- rbeta(1000000,n*r,s.y+0.5)
length(p.posterior.1000000[p.posterior.1000000<0.05])/1000000
par(mar=c(3,3,3,3))
ruler <- seq(0,1,length=1000)
beta.vals <- dbeta(ruler,n*r,s.y+0.5)
plot(ruler[1:200],beta.vals[1:200],yaxt="n",main="",ylab="",type="l")
mtext(side=2,line=1,"Density")
for (i in 1:length(ruler))
if (ruler[i] < 0.05)
segments(ruler[i],0,ruler[i],beta.vals[i])
segments(0.04,3,0.02,12.2)
text(0.02,12.8,"0.171")
t_ci_table
Description
A function to calculate credible intervals and make a table. See page 169.
Usage
t_ci_table(coefs,cov.mat,level=0.95,degrees=Inf,quantiles=c(0.025,0.500,0.975))
Arguments
coefs |
vector of coefficient estimates, usually posterior means |
cov.mat |
variance-covariance matrix |
level |
desired coverage level |
degrees |
degrees of freedom parameter for students-t distribution assumption |
quantiles |
vector of desired CDF points (quantiles) to return |
Value
quantile.mat matrix of quantiles
Author(s)
Jeff Gill
terrorism
Description
Dataset comparing incidents of terrorism to car accidents, suicide, and murder, see page 140
The variables included in the dataset are:
Year
The given year in which the statistics occurredX.Terrorism
The number of terrorist attacks that would occur per 100000 in the given yearX.Car.Accidents
The number of car accidents that would occur per 100000 in the given yearX.Suicide
The number of suicide that would occur per 100000 in the given year
Usage
data(terrorism)
Format
data frame with 14 observations of death rates for different years with 5 explanatory variables
Source
Falkenrath, R. (2001). Analytical Models and Policy Prescription: Understanding Recent Innovation in U.S. Counterterrorism. Studies in Conflict and Terrorism 24, 159-181.
texas
Description
Poverty in Texas, see page 299
The variables included in the dataset are:
POV
a dichotomous outcome variable indicates whether 20% or more of the county's residents live in povertyBLK
the proportion of Black residents in the countyLAT
the proportion of Latino residents in the countyGVT
a dichotomous variable indicating whether government activities contributed a weighted annual average of 25SVC
a dichotomous variable indicating whether service activities contributed a weighted annual average of 50FED
a dichotomous variable indicating whether federally owned lands make up 30XFR
a dichotomous factor indicating whether income from transfer payments (federal, state, and local) contributed a weighted annual average of 25 percent or more of total personal income over the past three yearsPOP
the log of the county population total for 1989
Usage
data(texas)
wars
Description
Data for Chinese wars example, see page 163
The variables included in the dataset are:
ONSET
ratio-level variable measuring the epochal (whether historical or calendar) time of event occurrence, measured in calendar yearTERM
ratio-level variable measuring the epochal (historical) time of event conclusion, measured in calendar yearEXTENT
number of belligerents involved on all sides of the warETHNIC
intra-group or inter-group conflictDIVERSE
number of ethnic groups participating as belligerentsALLIANCE
total number of alliances among belligerentsDYADS
number of alliance pairsPOL.LEV
nominal-level variable measuring the political level of belligerent involvement regarding domestic and foreign belligerents, with a 1 for internal war, 2 for interstate warCOMPLEX
governmental level of the warring parties, where the first variable is multiplied by ten for scale purposesPOLAR
number of relatively major or great powers at the time of onsetBALANCE
the difference in military capabilities: minor-minor, minor-major, major-majorTEMPOR
type of war: protracted rivalry, integrative conquest, disintegrative/fracturing conflict, sporadic eventSCOPE
political scope of conflicts in terms of governmental units affectedDURATION
duration of conflict, measured in years
Usage
data(wars)
Format
a data frame of 104 observations of different China wars with 15 explanatory variables
Source
Cioffi-Revilla, C. and Lai, D. (1995). War and Politics in Ancient China, 2700 B.C. to 722 B.C.: Measurement and Comparative Analysis. Journal of Conflict Resolution 39, 467-494.