Title: | Functions and Datasets for "Bayesian Methods: A Social and Behavioral Sciences Approach" |
---|---|
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>. |
Authors: | Jonathan Homola, Danielle Korman, Jacob Metz, Miguel Pereira, Mauricio Vela, and Jeff Gill <[email protected]> |
Maintainer: | Jeff Gill <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.3 |
Built: | 2025-02-24 03:47:49 UTC |
Source: | https://github.com/cran/BaM |
actuarial claims data for three groups of insurance policyholders p. 449
data(actuarial)
data(actuarial)
dataset with 5 observations of 7 variables
The variables included in the dataset are:
year
payroll
for groups 1, 2, and 3
claims
for groups 1, 2, and 3
Scollnik, D. P. M. (2001). Actuarial Modeling with MCMC and BUGS. North American Actuarial Journal 5, 95-124.
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 over
CASES
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 marijuan
OFFENSE
RACE
1 for 1,554 black cases, 2 for 1,411 white cases
SEX
1 for 2,213 male cases, 2 for 752 female cases
SITE
coded according to: Indianapolis = 1 (759 cases), Ft. Lauderdale = 2 (974 cases),Phoenix = 3 (646 cases), and Dallas = 4 (586 cases)
data(adam.jags)
data(adam.jags)
NATO Fatalities in Afghanistan, 10/01 to 1/07. see page 350
data(afghan.deaths)
data(afghan.deaths)
52 monthly periods, listed by rows
African Coups Data, pp.562-564
data(africa)
data(africa)
data frame with 33 observations of different African countries' military coups with 7 explanatory variables
The variables included in the dataset are:
MILTCOUP
Military Coups
MILITARY
Military Oligarchy
POLLIB
Political Liberalization: 0 for no observable civil rights for political expression, 1 for limited, and 2 for extensive
PARTY93
number of legally registered political parties
PCTVOTE
Percent Legislative Voting
PCTTURN
Percent registered voting
SIZE
in one thousand square kilometer units
POP
Population in millions
NUMREGIM
Regime
NUMELEC
Election
Bratton, M. and Van De Walle, N. (1994). Neopatrimonial Regimes and Political Transitions in Africa. World Politics 46, 453-489.
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.
data(asap.data.list)
data(asap.data.list)
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.
data(baldus)
data(baldus)
The variables included in the dataset are:
race
Defendant's race (1 = Black)
educatn
Educational level
employm
Employment status (1 = Employed)
SES
Socioeconomic status (1 = Low Wage)
married
Marital status (1 = Married)
num.chld
Number of children
military
Military experience (1 = Serving, 0 = No military service, -1 = Dishonorable Discharge)
pr.arrst
plea
Plea to Murder Indictment
sentence
Sentenced
defense
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 appeal
vict.sex
Victim sex
pr.incrc
vict.age
Victim's age
vict.rel
Relation of victim with defendant
vict.st1
Victim status (0 = Non-police+judicial, 1 = Police+judicial)
vict.st2
specialA
Special Circumstances ()
methodA
Method of killing
num.kill
Number of persons killed by defendant
num.prps
Number of persons killed by coperpetrator
def.age
Defendant's age
aggrevat
Aggravating circumstances
bloody
Bloody crime
fam.lov
insane
Defendant invoked insanity defense
mitcir
num.depr
rape
Rape involved
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.
baldus.jags baldus.winbugs
Implementation of bcp function, see pages 362-363 (2nd Edition).
bcp(theta.matrix, y, a, b, g, d)
bcp(theta.matrix, y, a, b, g, d)
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 |
Jeff Gill
## Not run: bcp(theta.matrix,y,a,b,g,d) ## End(Not run)
## Not run: bcp(theta.matrix,y,a,b,g,d) ## End(Not run)
A function to calculate posterior quantities of the bivariate normal. See page 94.
biv.norm.post(data.mat,alpha,beta,m,n0=5)
biv.norm.post(data.mat,alpha,beta,m,n0=5)
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 |
Returns
mu2 |
posterior mean, dimension 1 |
sig1 |
posterior mean, dimension 2 |
sig2 |
posterior variance, dimension 1 |
rho |
posterior variance, dimension 2 |
Jeff Gill
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)
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 (constitutional inter-election period) for eleven Western European countries from 1945 to 1980, page 65
cabinet.duration
cabinet.duration
cabinet duration of 11 countries
The variables included in the dataset are:
N
number of cabinets
dur
average length of duration
Row names indicate country.
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 Support Collection Policies from 50 states from 1982-1991. See page 166
child
child
observations of 8 variables for 50 states
The variables included in the dataset are:
SCCOLL
Change in Child Support collections
ACES
Chapters per Population
INSTABIL
Policy Instability
AAMBIG
Policy Ambiguity
CSTAFF
Change in Agency Staffing
ARD
State Divorce Rate
ASLACK
Organizational Slack
AEXPEND
State Level Expenditures
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.
Modeling code for the example of ancient Chinese wars. See page 163-165
china.wars()
china.wars()
Jeff Gill
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
A vector of British Coal Mining Disasters, see page 549-550
coal.mining.disasters
coal.mining.disasters
vector of length 111
Lynn, R. and Vanhanen, T. (2001). National IQ and Economic Development. Mankind Quarterly LXI, 415-437.
Contraception Data by country. See page 446
data(contracep)
data(contracep)
4 variables for 15 countries
The variables included in the dataset are:
Country
Developing countries by size
URC
Rural Childhood
WED
Years of Education for the Woman
FPE
Exposure to Family Planning Efforts
WED.FPE
Interaction term specified by Wong and Mason
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.
Data on ancient Chinese wars
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
dmultinorm function, see page 376.
dmultinorm(xval,yval,mu.vector,sigma.matrix)
dmultinorm(xval,yval,mu.vector,sigma.matrix)
xval |
Vector of X Random Variables |
yval |
Vector of Y Random Variables |
mu.vector |
Mean Vector |
sigma.matrix |
Matrix of Standard Deviations |
Jeff Gill
Death Penalty Data, See Page 142.
data(dp)
data(dp)
7 variables for 17 states
The variables included in the dataset are:
X
State
EXECUTIONS
Number of capital punishments at state level in 1997
INCOME
Median per capita income in dollars
PERPOVERTY
Percent classified as living in poverty
PERBLACK
Percent of black citizens in population
VC100k96
Rate of violent crime per 100,000 residents for 1996
SOUTH
Is the state in the South?
PROPDEGREE
Proportion of population with college degree
Norrander, B. (2000). The Multi-Layered Impact of Public Opinion on Capital Punishment Implementation in the American States. Political Research Quarterly 53, 771-793.
Simple HPD calculator from Chapter 2 (page 51, 2nd Edition).
durations.hpd(support,fn.eval,start,stop,target=0.90,tol=0.01)
durations.hpd(support,fn.eval,start,stop,target=0.90,tol=0.01)
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 |
Jeff Gill
## 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)
## 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)
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
data(elicspend)
data(elicspend)
1990-1993 W.Europe Ethnic/Minority Populations. see page 280.
data(ethnic.immigration)
data(ethnic.immigration)
total number of ethnic immigrants living in Western Europe from 22 countries
The variables included in the dataset are:
Country.of.Origin
Country of origin of immigrants
Estimated.Total.K.
Estimated total ethnic minority population in Western European Countries
Percent.of.Total
Percent of Total
Peach, C. (1997). Postwar Migration to Europe: Reflux, Influx, Refuge. Social Science Quarterly 78, 269-283.
Execution data.
The variables included in the dataset are:
State
State
EXECUTIONS
Number of capital punishments at state level in 1997
Median.Income
Median per capita income in dollars
Percent.Poverty
Percent classified as living in poverty
Percent.Black
Percent of black citizens in population
Violent.Crime
Rate of violent crime per 100,000 residents for 1996
data(executions)
data(executions)
explanatory variables for 17 states
Fabricated data on campaign fundraising elicitations. See page 120
experts(q1,q2,q3)
experts(q1,q2,q3)
q1 |
the 0.1 quantile |
q2 |
the 0.5 quantile |
q3 |
the 0.9 quantile |
Simple Gibbs sampler demonstration on conditional exponentials from Chapter 1 (pages 25-27).
expo.gibbs(B,k,m)
expo.gibbs(B,k,m)
B |
an upper bound |
k |
length of the subchains |
m |
number of iterations |
Jeff Gill
Simple Metropolis algorithm demonstration using a bivariate exponential target from Chapter 1 (pages 27-30).
expo.metrop(m,x,y,L1,L2,L,B)
expo.metrop(m,x,y,L1,L2,L,B)
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 |
Jeff Gill
expo.metrop(m=5000, x=0.5, y=0.5, L1=0.5, L2=0.1, L=0.01, B=8)
expo.metrop(m=5000, x=0.5, y=0.5, L1=0.5, L2=0.1, L=0.01, B=8)
FDR election data. See page 576
The variables included in the dataset are:
State
State name
FDR
Whether or not FDR won the state in 1932 election, 1 = won, 0 = lost
PRE.DEP
Mean income per state before the Great Depression (1929), in dollars
POST.DEP
Mean income per state after the Great Depression (1932), in dollars
FARM
Total farm wage and salary disbursements in thousands of dollars per state in 1932
data(fdr)
data(fdr)
1964 presidential election data. See page 221
hanjack(N,F,L,W,K,IND,DEM,WR,WD,SD)
hanjack(N,F,L,W,K,IND,DEM,WR,WD,SD)
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 |
Hanushek, E. A. and Jackson, J. E. (1977). Statistical Methods for Social Scientists San Diego, Academic Press
Implementation of hit.run algorithm, p. 361.
hit.run(theta.mat,reps,I.mat)
hit.run(theta.mat,reps,I.mat)
theta.mat |
theta.mat |
reps |
reps |
I.mat |
I.mat |
Jeff Gill
## 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=".")
## 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 for 80 countries. See pages 85-87
data(iq)
data(iq)
Lynn, R. and Vanhanen, T. (2001). National IQ and Economic Development. Mankind Quarterly LXI, 415-437.
## 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)
## 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)
Italian Parties Data. Vote share of Italian parties from 1948-1983. See page 370-371.
data(italy.parties)
data(italy.parties)
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 center
POP
population in the county by thousands
PDEN
population per square county mile
PHOME
the percent of "lunatics" cared for in the home
data(lunatics)
data(lunatics)
Italian Marriage Rates. See page 430
data(marriage.rates)
data(marriage.rates)
a vector containing 16 numbers
Columbo, B. (1952). Preliminary Analysis of Recent Demographic Trends in Italy. Population Index 18, 265-279.
Implementation of metropolis function, p. 359.
metropolis(theta.matrix,reps,I.mat)
metropolis(theta.matrix,reps,I.mat)
theta.matrix |
theta.matrix |
reps |
reps |
I.mat |
I.mat |
Jeff Gill
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 evaluate
Yugoslavia
The proportion change in the size of Yugoslavia's military
Albania
The proportion change in the size of Albania's military
Bulgaria
The proportion change in the size of Bulgaria's military
Czechoslovakia
The proportion change in the size of Czechoslovakia's military
German.Dem.Republic
The proportion change in the size of the German Democratic Republic's military
Hungary
The proportion change in the size of Hungary's military
Poland
The proportion change in the size of Poland's military
Rumania
The proportion change in the size of Romania's military
USSR
The proportion change in the size of the Soviet Union's military
data(militarydf)
data(militarydf)
a data frame with 35 observations of years from 1949 to 1983 with 10 explanatory variables
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.
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 county
Percent.Poverty
percent within the county living in poverty, U.S. definition
Total.Population
county population/1000
nc.sub.dat
nc.sub.dat
data frame with 100 observations of different counties in North Carolina with 3 explanatory variables
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
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.
norm.known.var(data.vec,pop.var,prior.mean,prior.var)
norm.known.var(data.vec,pop.var,prior.mean,prior.var)
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 |
Jeff Gill
A function to calculate posterior quantities of bivariate normals. See pages 74-80.
normal.posterior.summary(reps)
normal.posterior.summary(reps)
reps |
a matrix where the columns are defined as in the output of biv.norm.post: |
Jeff Gill
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 policy
Past.execution.rate
Past execution rate
Politicla.Culture
Political culture
Current.opinion
Current opinion
Citizen.ideology
Citizen ideology
Murder.Rate
Murder rate
Catholic
Catholic
Black
Black
Urban
Urban
Past.laws
Past laws
Past.opinion
Past opinion
data(norr)
data(norr)
private capital investment data. See Page 390.
The variables included in the dataset are:
Fund
Name of the private company
Age
Years the company has been in existence
Status
Whether the company is investing or divesting
Size
Maximum fund size in millions
data(opic)
data(opic)
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 ballots
technology
Voting Technology used, 0 for a datapunch machine or a butterfly ballot, 1 for votomatic
new
Number of "new" voters, as in those who have not voted in the precinct for previous 6 years
size
Total number of precinct voters
Republican
The number of voters registered as Republican
white
The number of white nonminority voters in a given precinct
data(pbc.vote)
data(pbc.vote)
data frame with 516 observations of each precinct in Palm Beach County with 11 explanatory variables
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 code used to produce figure 10.2
plot_walk_G(walk.mat,sim.rm,X=1,Y=2)
plot_walk_G(walk.mat,sim.rm,X=1,Y=2)
walk.mat |
walk.mat |
sim.rm |
sim.rm |
X |
X |
Y |
Y |
Jeff Gill
plot_walk_MH code used to produce figure 10.4
plot_walk_MH(walk.mat)
plot_walk_MH(walk.mat)
walk.mat |
walk.mat |
Jeff Gill
Recidivism Rates. See page 188
The variables included in the dataset are:
Crime.Type
The type of crime committed
Released
The number of individuals released from a facility
Returned
The number of individuals returned to a facility
Percentage
(The number of individuals returned to a facility)/(The number of individuals released from a facility)
data(recidivism)
data(recidivism)
data frame with 27 observations of different crime types with 5 explanatory variables
state-level recidivism data as collected by the Oklahoma Department of Corrections from January 1, 1985 to June 30, 1999
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=44
DSB
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)
data(retail.sales)
data(retail.sales)
data frame with 44 observations of statistics for different economic quarters with 7 explanatory variables
U.S. Department of Commerce data from first quarter of 1979 to fourth quarter of 1989
a function to generate random multivariate Gaussians.
rmultinorm(n, mu, vmat, tol = 1e-07)
rmultinorm(n, mu, vmat, tol = 1e-07)
n |
nu |
mu |
vector of mean |
vmat |
variance-covariance matriz |
tol |
tolerance |
Jeff Gill
Analysis of cultural consensus data using binomial likelihood and beta prior.
romney()
romney()
See for yourself. Modify as desired.
Jeff Gill
Romney, A. K. (1999). Culture Consensus as a Statistical Model.
Current Anthropology 40 (Supplement), S103-S115.
Implementation of Rubin's SIR, see pages 338-341 (2nd Edition)
sir(data.mat,theta.vector,theta.mat,M,m,tol=1e-06,ll.func,df=0)
sir(data.mat,theta.vector,theta.mat,M,m,tol=1e-06,ll.func,df=0)
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 |
Jeff Gill
## 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)
## 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)
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 identifier
Year.Code
1 = 1983, 2 = 1984, 3 = 1985, 4 = 1986
Num.Answers
number of positive answers to seven questions
Party
1 = Conservative, 2 = Labour, 3 = Lib/SDP/Alliance, 4 = others
Social.Class
1 = middle, 2 = upper working, 3 = lower working
Gender
1 = male, 2 = female.
Age
age in years 18-80
Religion
1 = Roman Catholic, 2 = Protestant/Church of England, 3 = others, 4 = none.
data(socatt)
data(socatt)
French Coal Strikes, see page 212 and 213
The variables included in the dataset are:
Year
The year the labor strikes in France occurred
Counts
The number of labor strikes that occurred in France per year
data(strikes)
data(strikes)
data frame with 11 observations of strikes that occurred in different years with 1 explanatory variable
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.
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")
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")
A function to calculate credible intervals and make a table. See page 169.
t_ci_table(coefs,cov.mat,level=0.95,degrees=Inf,quantiles=c(0.025,0.500,0.975))
t_ci_table(coefs,cov.mat,level=0.95,degrees=Inf,quantiles=c(0.025,0.500,0.975))
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 |
quantile.mat matrix of quantiles
Jeff Gill
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 occurred
X.Terrorism
The number of terrorist attacks that would occur per 100000 in the given year
X.Car.Accidents
The number of car accidents that would occur per 100000 in the given year
X.Suicide
The number of suicide that would occur per 100000 in the given year
data(terrorism)
data(terrorism)
data frame with 14 observations of death rates for different years with 5 explanatory variables
Falkenrath, R. (2001). Analytical Models and Policy Prescription: Understanding Recent Innovation in U.S. Counterterrorism. Studies in Conflict and Terrorism 24, 159-181.
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 poverty
BLK
the proportion of Black residents in the county
LAT
the proportion of Latino residents in the county
GVT
a dichotomous variable indicating whether government activities contributed a weighted annual average of 25
SVC
a dichotomous variable indicating whether service activities contributed a weighted annual average of 50
FED
a dichotomous variable indicating whether federally owned lands make up 30
XFR
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 years
POP
the log of the county population total for 1989
data(texas)
data(texas)
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 year
TERM
ratio-level variable measuring the epochal (historical) time of event conclusion, measured in calendar year
EXTENT
number of belligerents involved on all sides of the war
ETHNIC
intra-group or inter-group conflict
DIVERSE
number of ethnic groups participating as belligerents
ALLIANCE
total number of alliances among belligerents
DYADS
number of alliance pairs
POL.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 war
COMPLEX
governmental level of the warring parties, where the first variable is multiplied by ten for scale purposes
POLAR
number of relatively major or great powers at the time of onset
BALANCE
the difference in military capabilities: minor-minor, minor-major, major-major
TEMPOR
type of war: protracted rivalry, integrative conquest, disintegrative/fracturing conflict, sporadic event
SCOPE
political scope of conflicts in terms of governmental units affected
DURATION
duration of conflict, measured in years
data(wars)
data(wars)
a data frame of 104 observations of different China wars with 15 explanatory variables
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.