Movatterモバイル変換


[0]ホーム

URL:


Type:Package
Title:Modeling of Revealed Preferences Matchings
Version:0.7-4
Date:2025-10-22
Description:Statistical estimation of revealed preference models from data collected on bipartite matchings. The models are for matchings within a bipartite population where individuals have utility for people based on known and unknown characteristics. People can form a partnership or remain unpartnered. The model represents both the availability of potential partners of different types and preferences of individuals for such people. The software estimates preference parameters based on sample survey data on partnerships and population composition. The simulation of matchings and goodness-of-fit are considered. See Goyal, Handcock, Jackson, Rendall and Yeung (2022) <doi:10.1093/jrsssa/qnad031>.
License:GPL-3 + file LICENSE
License_is_FOSS:yes
License_restricts_use:no
URL:https://github.com/handcock/rpm
BugReports:https://github.com/handcock/rpm/issues
LinkingTo:Rcpp, RcppArmadillo
Depends:R (≥ 4.0.0), abind, future, doRNG, methods
Suggests:testthat
Imports:Rcpp, nloptr, matrixStats, MASS, dplyr, ggplot2, coda,doFuture, foreach
Encoding:UTF-8
RoxygenNote:7.3.3
NeedsCompilation:yes
Packaged:2025-10-23 01:37:48 UTC; handcock
Author:Mark S. HandcockORCID iD [aut, cre], Ryan M. Admiraal [ctb], Fiona C. Yeung [ctb], Heide M. Jackson [ctb], Michael S. Rendall [ctb], Shuchi Goyal [ctb]
Maintainer:Mark S. Handcock <handcock@stat.ucla.edu>
Repository:CRAN
Date/Publication:2025-10-23 10:40:07 UTC

Modeling of Revealed Preferences Matchings

Description

An integrated set of tools to fit a revealed preference modelfor men and women of certaincharacteristics (or shared characteristics) of people of the opposite sex.The model assumes a one-to-one stable matching using an observed set ofmatchings and a set of (possibly dyadic) covariates to estimate the parameters forlinear equations of utilities.It does this using an large-population likelihood based on ideas from Dagsvik (2000), Menzel (2015) and Goyal et al (2023).

Details

For a complete list of the functions, uselibrary(help="rpm") orread the rest of the manual.

When publishing results obtained using this package the original authors areto be cited as:

Mark S. Handcock, Ryan M. Admiraal, Fiona C. Yeung, Heide M. Jackson, Michael S. Rendall and Shuchi Goyal (2022)rpm: Modeling of Revealed Preferences MatchingsR package, Los Angeles, CA. Version 0.70,https://github.com/handcock/rpm.

All programs derived from this package must cite it. For complete citationinformation, use
citation(package="rpm").

For details on how to construct data for input torpm() see the documentation:

help(fauxmatching)

For information on the current terms that can be used in formulas forrpm() see the documentation:

help("rpm-terms")

Value

No return value, called for side effects.

Author(s)

Mark S. Handcock <handcock@stat.ucla.edu>

References

Goyal, Shuchi; Handcock, Mark S.; Jackson, Heide M.; Rendall, Michael S. and Yeung, Fiona C. (2023).A Practical Revealed Preference Model for Separating Preferences and Availability Effects in Marriage Formation,Journal of the Royal Statistical Society, A.doi:10.1093/jrsssa/qnad031

Dagsvik, John K. (2000)Aggregation in Matching Markets,International Economic Review, Vol. 41, 27-57.JSTOR: https://www.jstor.org/stable/2648822,doi:10.1111/1468-2354.00054

Menzel, Konrad (2015).Large Matching Markets as Two-Sided Demand Systems,Econometrica, Vol. 83, No. 3 (May, 2015), 897-941.doi:10.3982/ECTA12299

See Also

Useful links:

Examples

library(rpm)data(fauxmatching)fit <- rpm(~match("edu") + WtoM_diff("edu",3),          Xdata=fauxmatching$Xdata, Zdata=fauxmatching$Zdata,          X_w="X_w", Z_w="Z_w",          pair_w="pair_w", pair_id="pair_id", Xid="pid", Zid="pid",          sampled="sampled",sampling_design="stock-flow")summary(fit)# For details on how to construct data for input:help(fauxmatching)# For information on the current terms that can be used in formulas:help("rpm-terms")

This is the version of Gale-Shapley stable matching algorithm (translated from the Matlab code in Menzel (2015)).

Description

This code allows the self-matched option

Usage

Gale_Shapley(U, V, return.data.frame = FALSE, cpp = TRUE, nmax = 10 * nrow(U))

Arguments

U

The utility matrix for the women's side. Each row is a woman, each column is a man.The matrix entry (i,j) is the utility that womani gains from pairing with manj. In other words, the utility is computed from womani's perspective.

V

The utility matrix for the men's side. Each column is a man, each row is a woman.The matrix entry (i,j) is the utility that manj gains from pairing with womani. In other words, the utility is computed from manj's perspective.

return.data.frame

logical Should adata.frame of the matching be returned instead of theparing matrix mu?

cpp

logical Should theRcpp version of the code be used. This is much faster and uses a lot less memory.

nmax

count The maximum number of iterations of the inner loop within the Gale-Shapley algorithm.This can be reduced to speed up the algorithm at the potential cost of many partnerships being non-equilibruim.

Value

The function return depends on thereturn.data.frame value. If TRUE, it returns

data.frame

a two-columndata.frame with the first column a women's index and the second column the men's index of their partner. It has as many rows as there are partnerships.

If FALSE, it returns the following matrix:

mu

Ifcpp=TRUE, a vector of length the number of women (nrow(U)) with the index of the matching man (i.e., the index is the row inV of the man). If there is nomatching man, the index is 0. This can be used to reconstruct the matching matrix.Ifcpp=FALSE, the matching matrix, where 1 represents a pairing, 0 otherwise. Each row is a woman, each column is a man. The order of the rows is the same as the rows inU. The order of the columns is the same as the columns inV.

References

Goyal, Shuchi; Handcock, Mark S.; Jackson, Heide M.; Rendall, Michael S. and Yeung, Fiona C. (2023).A Practical Revealed Preference Model for Separating Preferences and Availability Effects in Marriage Formation,Journal of the Royal Statistical Society, A.doi:10.1093/jrsssa/qnad031

Dagsvik, John K. (2000)Aggregation in Matching MarketsInternational Economic Review, Vol. 41, 27-57.JSTOR: https://www.jstor.org/stable/2648822,doi:10.1111/1468-2354.00054

Menzel, Konrad (2015).Large Matching Markets as Two-Sided Demand SystemsEconometrica, Vol. 83, No. 3 (May, 2015), 897-941.doi:10.3982/ECTA12299

See Also

rpm


ANOVA for rpm Fits

Description

Compute an analysis of variance table for one or more rpm fits.

Usage

## S3 method for class 'rpm'anova(object, ...)anova_rpmlist(object, ...)

Arguments

object,...

objects of classrpm, usually, a result of acall torpm.

Details

Specifying a single object gives a sequential analysis of variance table forthat fit. That is, the reductions in the residual sum of squares as eachterm of the formula is added in turn are given in the rows of a table, plusthe residual sum of squares.

The table will contain F statistics (and P values) comparing the mean squarefor the row to the residual mean square.

If more than one object is specified, the table has a row for the residualdegrees of freedom and sum of squares for each model. For all but the firstmodel, the change in degrees of freedom and sum of squares is also given.(This only make statistical sense if the models are nested.) It isconventional to list the models from smallest to largest, but this is up tothe user.

Optionally the table can include test statistics. Normally the F statisticis most appropriate, which compares the mean square for a row to theresidual sum of squares for the largest model considered. Ifscaleis specified chi-squared tests can be used. Mallows'C_p statisticis the residual sum of squares plus twice the estimate of\sigma^2 times the residual degrees of freedom.

If any of the objects do not have estimated log-likelihoods, produces anerror, unlesseval.loglik=TRUE.

Value

An object of class"anova" inheriting from class"data.frame".

Warning

The comparison between two or more models will only bevalid if they are fitted to the same dataset. This may be a problem if thereare missing values.

See Also

The model fitting functionrpm,anova,logLik.rpm for adding the log-likelihood to an existingrpm object.

Examples

library(rpm)data(fauxmatching)fit <- rpm(~match("edu") + WtoM_diff("edu",3),          Xdata=fauxmatching$Xdata, Zdata=fauxmatching$Zdata,          X_w="X_w", Z_w="Z_w",          pair_w="pair_w", pair_id="pair_id", Xid="pid", Zid="pid",          sampled="sampled",sampling_design="stock-flow")anova(fit)

Auxiliary for Controlling rpm

Description

Auxiliary function as user interface for fine-tuning RPM model fitting algorithm,which computes the MLPLE of the Revealed Preferences Model via optimization.

Usage

control.rpm(  init_theta = NULL,  algorithm = "NLOPT_LD_SLSQP",  print_level = 0,  xtol_rel = 1e-08,  ftol_rel = 1e-08,  ftol_abs = 1e-06,  lower.bound = -10,  upper.bound = 10,  maxeval = 2000,  bs.maxeval = 2000,  bs.xtol_rel = 1e-08,  bs.save.data = FALSE,  check_derivatives = FALSE,  bootstrap = TRUE,  hessian = FALSE,  seed = NULL,  parallel.type = "PSOCK",  parallel.ncores = 1,  ncores = 1,  constraints = c("none", "M_single"),  logodds_single = FALSE,  save.data = TRUE,  robust.cov = FALSE,  local_opts = list(algorithm = "NLOPT_LD_SLSQP", xtol_rel = 1e-07, maxeval = maxeval),  nbootstrap = 50,  nbootstrap.SD = 20,  large.population.bootstrap = 5000,  alpha = 0.05)

Arguments

init_theta

vector; numeric vector of starting parameter values. This value and other possible starting values are applied to find a good optimizer. This can either have length the number of parameterscorresponding to the terms in the formula or in addition the equilibrium constraints.

algorithm

string; The optimization algorithm to use. Seenloptr::nloptr.print.options()and theNLopt website for a description of the algorithms.

print_level

integer; possible values: 0, 1, 2, or 3.This controls how much output is shown during theoptimization process. Possible values: 0 (default): no output; 1:show iteration number and value of objective function; 2: 1 + showvalue of equalities/constraints; 3: 2 + show value of controls.

xtol_rel

scalar; Stop when an optimization step (or an estimate of the optimum)changes every parameter by less than xtol_rel multiplied by theabsolute value of the parameter. If there is any chance that anoptimal parameter is close to zero, you might want to set an absolutetolerance with xtol_abs as well. Criterion is disabled if xtol_rel isnon-positive. Possible values: xtol_rel > 0. Default value: 1.0e-08.

ftol_rel

scalar; Stop when an optimization step (or an estimate of the optimum)changes the log-likelihood by less than ftol_rel multiplied by theabsolute value of the log-likelihood.

ftol_abs

scalar; Stop when an optimization step (or an estimate of the optimum)changes the log-likelihood by less than ftol_abs.tolerance with xtol_abs as well. Criterion is disabled if ftol_abs isnon-positive. Possible values: ftol_abs > 0. Default value: 1.0e-06.

lower.bound

numeric; lower bounds on the parameter estimates (that is, the beta and gamma parameters in the model). Can be a vector of the same size as the coefficientvector or a single number which is used for all bounds.

upper.bound

numeric; upper bounds on the parameter estimates (that is, the beta and gamma parameters in the model). Can be a vector of the same size as the coefficientvector or a single number which is used for all bounds.

maxeval

integer; Stop when the number of function evaluations exceeds maxeval. This isnot a strict maximum: the number of function evaluations may exceedmaxeval slightly, depending upon the algorithm. Criterion is disabledif maxeval is non-positive. Default value: 1000.

bs.maxeval

integer; Stop the bootstrap optimization when the number of function evaluations exceeds bs.maxeval. This isnot a strict maximum: the number of function evaluations may exceedbs.maxeval slightly, depending upon the algorithm. Criterion is disabledif bs.maxeval is non-positive. Default value:50

bs.xtol_rel

scalar; Stop the bootstrap optimization when an optimization step (or an estimate of the optimum)changes every parameter by less than bs.xtol_rel multiplied by theabsolute value of the parameter. See the parameter xtol_rel for details.

bs.save.data

logical; Should the bootstrapped data be saved in the bootstrap return list (as componentsXdata andZdata).

check_derivatives

logical; Compare the user-supplied analytic gradientswith the finite difference approximations.

bootstrap

logical; If 'TRUE' use a bootstrap to compute the standard errors and associatedcovariance matrices. If 'FALSE' base the standard errors and associatedcovariance matrices on the Hessian of the(constrained) log-likelihood. In all cases the extended covariance matrix is returned inext.covar.hessian.This is the matrix of parameters, log-odds of being single and the Lagrange multipliers.

hessian

logical; Depreciated. The negation of the 'bootstrap' argument.

seed

Seed value (integer) for the random number generator. Seeset.seed

parallel.type

The type of cluster to run. The typical choices are "MPI" and "PSOCK", where youmust have "MPI" installed to use the former. The defaultis "PSOCK".

parallel.ncores

count; Depreciated. The renamed 'ncores' argument.

ncores

Number of processors to use in the bootstrap computations. The defaultis 1, that is no parallel processing.

constraints

string; Additional constraints to force the proportions of singles tomatch the (weighted) population estimates? This should not be required, but does stabilizethe estimates in cases where there is much uncertainty.The possible values are "none" and "M_single" (the numbers of male singles of each type are reproduced). Note that adding constraints leads to over-constrained optimization which may fail.

logodds_single

logical; Should the log-odds ratio of being single relative to a randomly chosen person of the same sex from the the population be returned. If FALSE the log-odds of being single relative is returned. This is a pure preference parameter.

save.data

logical; Should the data be saved in the return list (as componentsXdata andZdata).

robust.cov

logical; Should the covariance matrix of the estimates be computed using arobust method (MASS::cov.mcd)? Only use if the bootstrap is unstable.

local_opts

list; list of options fornloptr sub-algorithm. See thenloptr package, but these are rarely changed.

nbootstrap

integer; Number of bootstrap resamples to take in the estimation of thecovariance matrix of the parameter estimates.

nbootstrap.SD

integer; Number of bootstrap resamples to take in the estimation of thevariances used in the studentized bootstrap. This is run for each nbootstrap sample and so is expensive.

large.population.bootstrap

integer; If the population size exceedslarge.population.bootstrap then the large population approximation is used to simulate the matchings in the bootstrap. Otherwise the small population simulation is used (including the Gale-Shapley algorithm).The small population method is more accurate in smaller populations, with the default cutoff being 5000 people.

alpha

proportion; Type I error rate for the confidence intervals produced by the bootstrap.

Details

This function is only used within a call to therpmfunction.

Some of the arguments are not yet fully implemented.It will evolve slower to incorporate morearguments as the package develops.

Value

A list with arguments as components.

See Also

rpm


Faux Data on Heterosexual Matching

Description

This data set represents a simulation of a bipartite matching.The data set is named fauxmatching.Its primary use is to illustrate the fitting of a Revealed Preference Matchings Model (rpm).The model assumes a one-to-one stable matching using an observed set ofmatchings and a set of (possibly dyadic) covariates to estimate the parameters forlinear equations of utilities. This provides such datafor a matching between men and women of certaincharacteristics (or shared characteristics) of people of the opposite sex.

Usage

data(fauxmatching)

Format

fauxmatching is a list containing a pair ofdata.frame objects:Xdata andZdata.

Xdata is for women. Each row is a woman, each column is a variable on that womenor her partnerships. The women's ID variable s calledpid andthe variable with the ID of the women's partner is calledpair_id. If the women is single the men's ID is NA.Zdata is for men. Each row is a man, each column is a variable on that menThe men's ID variable is calledpid.

pair_id

The ID of the person's partner. This is in bothXdata andZdata.

sampled

The indicator that the person was sampled directly (as distinct from being included as the match of a directly sampledperson. All single people are directly sampled. This is in bothXdata andZdata.

Details

The pairings are determined by thepair_id variable inXdata. If that variable is NA then the women isassumed to be single. If men are listed inZdata and are not partnered then they are assumed single.Weights are specified by three optional variables inXdata.

X_w

The weight variable for women. The sum of the weights of the sampled women is thenumber of women in the population.

Z_w

The weight variable for men. The sum of the weights of the sampled men is thenumber of men in the population.

pair_w

The weight variable for pairs.

Value

No return value, called for side effects.

Source

The data set is simulation based upon an rpm model fit to data fromthe 2008 SIPP.

References

Goyal, Shuchi; Handcock, Mark S.; Jackson, Heide M.; Rendall, Michael S. and Yeung, Fiona C. (2023).A Practical Revealed Preference Model for Separating Preferences and Availability Effects in Marriage Formation,Journal of the Royal Statistical Society, A.doi:10.1093/jrsssa/qnad031

Dagsvik, John K. (2000)Aggregation in Matching MarketsInternational Economic Review, Vol. 41, 27-57.JSTOR: https://www.jstor.org/stable/2648822,doi:10.1111/1468-2354.00054

Menzel, Konrad (2015).Large Matching Markets as Two-Sided Demand SystemsEconometrica, Vol. 83, No. 3 (May, 2015), 897-941.doi:10.3982/ECTA12299

Examples

library(rpm)data(fauxmatching)fit <- rpm(~match("edu") + WtoM_diff("edu",3),          Xdata=fauxmatching$Xdata, Zdata=fauxmatching$Zdata,          X_w="X_w", Z_w="Z_w",          pair_w="pair_w", pair_id="pair_id", Xid="pid", Zid="pid",          sampled="sampled")summary(fit)

Calculate goodness-of-fit statistics for Revealed Preference Matchings Model based on observed data

Description

gof.rpm ...It is typically based on the estimate from arpm() call.

Usage

gof(object, ...)## S3 method for class 'rpm'gof(  object,  ...,  empirical_p = TRUE,  compare_sim = "sim-est",  control = object$control,  reboot = FALSE,  verbose = FALSE)## S3 method for class 'gofrpm'plot(x, ..., cex.axis = 0.7, main = "Goodness-of-fit diagnostics")

Arguments

object

list; an object of classrpm that is typically the result of a call torpm().

...

Additional arguments, to be passed to lower-level functions.

empirical_p

logical; (Optional) If TRUE the function returns the empirical p-value of the samplestatistic based onnsim simulations

compare_sim

string; describes which two objects are compared to compute simulated goodness-of-fitstatistics; valid values are"sim-est": compares the marginal distribution of pairings in asimulated sample to therpm model estimate of the marginal distribution based on that same simulated sample;mod-est: compares the marginal distribution of pairings in asimulated sample to therpm model estimate used to generate the sample

control

A list of control parameters for algorithm tuning. Constructed usingcontrol.rpm, which should be consulted for specifics.

reboot

logical; if this isTRUE, the program will rerun the bootstrap at the coefficient values, rather than expect the object to contain abs.results component with the bootstrap results run at the solution values.The latter is the default forrpm fits.

verbose

logical; if this isTRUE, the program will print outadditional information, including data summary statistics.

x

a list, usually an object of class gofrpm

cex.axis

the magnification of the text used in axis notation;

main

Title for the goodness-of-fit plots.

Details

The functionrpm is used to fit a revealed preference modelfor men and women of certaincharacteristics (or shared characteristics) of people of the opposite sex.The model assumes a one-to-one stable matching using an observed set ofmatchings and a set of (possibly dyadic) covariates to estimate the parameters forlinear equations of utilities.It does this using an large-population likelihood based on ideas from Dagsvik (2000), Menzel (2015) and Goyal et al (2023).

The model represents the dyadic utility functions as deterministic linear utility functions ofdyadic variables. These utility functions are functions of observed characteristics of the womenand men.These functions are entered as terms in the function calltorpm. This function simulates from such a model.

Value

gof.rpm returns a list consisting of the following elements:

observed_pmf

numeric matrix giving observed probability mass distribution over different household types

model_pmf

numeric matrix giving expected probability mass distribution fromrpm model

obs_chi_sq

the count-based observed chi-square statistic comparing marginal distributions of the populationthe data and the model estimate

obs_chi_sq_cell

the contribution to the observed chi-squared statistic by household type

obs_kl

the Kullback-Leibler (KL) divergence computed by comparing the observed marginal distributions to theexpected marginal distribution based on therpm model estimate

obs_kl_cell

the contribution to the observed KL divergence by household type

empirical_p_chi_sq

the proportion of simulated chi-square statistics that are greater thanor equal to the observed chi-square statistic

empirical_p_kl

the proportion of simulated KL divergences that are greater thanor equal to the observed KL divergence

chi_sq_simulated

vector of sizensim storing all simulated chi-square statistics

kl_simulated

vector of sizensim storing all simulated KL divergences

chi_sq_cell_mean

Mean contributions of each household type to the simulated chi_sq statistic

chi_sq_cell_sd

Standard deviation of the contributions of each household type to the simulated chi_sq statistics

chi_sq_cell_median

Median contributions of each household type to the simulated chi_sq statistic

chi_sq_cell_iqr

Interquartile range of the contributions of each household type to the simulated chi_sq statistics

kl_cell_mean

Mean contributions of each household type to the simulated KL divergences

kl_cell_sd

Standard deviation of the contributions of each household type to the simulated KL divergencesc

kl_cell_median

Median contributions of each household type to the simulated KL divergences

kl_cell_iqr

Interquartile range of the contributions of each household type to the simulated KL divergences

Methods (by class)

Functions

References

Goyal, Shuchi; Handcock, Mark S.; Jackson, Heide M.; Rendall, Michael S. and Yeung, Fiona C. (2023).A Practical Revealed Preference Model for Separating Preferences and Availability Effects in Marriage Formation,Journal of the Royal Statistical Society, A.doi:10.1093/jrsssa/qnad031

Dagsvik, John K. (2000)Aggregation in Matching MarketsInternational Economic Review, Vol. 41, 27-57.JSTOR: https://www.jstor.org/stable/2648822,doi:10.1111/1468-2354.00054

Menzel, Konrad (2015).Large Matching Markets as Two-Sided Demand SystemsEconometrica, Vol. 83, No. 3 (May, 2015), 897-941.doi:10.3982/ECTA12299

Examples

library(rpm)data(fauxmatching)fit <- rpm(~match("edu") + WtoM_diff("edu",3),          Xdata=fauxmatching$Xdata, Zdata=fauxmatching$Zdata,          X_w="X_w", Z_w="Z_w",          pair_w="pair_w", pair_id="pair_id", Xid="pid", Zid="pid",          sampled="sampled")a <- gof(fit)

Returns a list containing the terms in a given formula

Description

Returns a list containing the terms in a given formula

Usage

list_rhs.formula(object)

Arguments

object

formula A formula having a right-hand-side that can be interpretated as a rpm specification.returns a list containing terms in a givenformula, handling+ and- operators and parentheses, andkeeping track of whether a term has a plus or a minus sign.

Value

list_rhs.formula returns a list of formula terms, with an additional numerical vector attribute"sign" with of the same length, giving the corresponding term's sign as+1 or-1.


AlogLik method for ['rpm'] fits.

Description

A function to return the log-likelihood associated with anrpm fit

Usage

## S3 method for class 'rpm'logLik(object, ...)

Arguments

object

Anrpm fit, returned byrpm.

...

Other arguments to the likelihood functions.

Value

alogLik object.

See Also

logLik,logLikNull

Examples

library(rpm)data(fauxmatching)fit <- rpm(~match("edu") + WtoM_diff("edu",3),          Xdata=fauxmatching$Xdata, Zdata=fauxmatching$Zdata,          X_w="X_w", Z_w="Z_w",          pair_w="pair_w", pair_id="pair_id", Xid="pid", Zid="pid",          sampled="sampled",sampling_design="stock-flow")logLik(fit)

Calculate the null model likelihood

Description

Calculate the null model likelihood

Usage

logLikNull(object, ...)## S3 method for class 'rpm'logLikNull(object, ...)

Arguments

object

a fitted model.

...

further arguments to lower-level functions.

logLikNull computes, when possible the log-probability ofthe data under the null model (reference distribution).

Value

logLikNull returns an object of typelogLik if it isable to compute the null model probability, andNA otherwise.

Methods (by class)


['print'] objects to the ['message'] output.

Description

A thin wrapper around ['print'] that captures its output and printsit as a ['message'], usually to STDERR.Tis is part of ['statnet.common'].

Usage

message_print(..., messageArgs = NULL)

Arguments

...

arguments to ['print'].

messageArgs

a list of arguments to be passed directly to ['message'].

Value

No return value, called for side effects.

Examples

cat(1:5)print(1:5)message_print(1:5) # Looks the same (though may be in a different color on some frontends).suppressMessages(print(1:5)) # Still printssuppressMessages(message_print(1:5)) # Silenced

Micro simulate a population from a Revealed Preference Matchings Model

Description

microsimulate simulates a population of the pairs and singlesfrom a Revealed Preference Matchings Model. It is typically based on the estimate from arpm() call.

Usage

microsimulate(  object,  nsim = 1,  seed = NULL,  pmfW_N = NULL,  pmfM_N = NULL,  large.population = TRUE,  bootstrap = FALSE,  control = control.rpm(),  counts.only = FALSE,  verbose = FALSE)

Arguments

object

list; an object of classrpm that is typically the result of a call torpm().

nsim

Number of matchings to be randomly drawn from the givenmodel on the set of all matchings / singles.

seed

integer; (Optional) random number seed.

pmfW_N

vector; The population count of the number of women of each type. This should be compatible with the type in the object.

pmfM_N

vector; The population count of the number of men of each type. This should be compatible with the type in the object.

large.population

logical; If TRUE a large population approximation is used to generatethe matchings (rather than the individual level generation of utilities). This is much faster anduses a lot less memory. It is TRUE by default. If used, a sample is drawn rather than thepopulation being returned. The sample size is controlled bypmfW_N andpmfM_N.

bootstrap

logical; If TRUE the original population is sampled from. If FALSE thepopulation underlying the fitted model is sampled from.

control

A list of control parameters for algorithm tuning. Constructed usingcontrol.rpm, which should be consulted for specifics.

counts.only

logical; If TRUE only the matrices of counts and the PMF of the population of households is returned.If FALSE It is FALSE by default.

verbose

logical; Should verbose messages be printed out.

Details

The function requites the numbers of women of each type and the number of men of each type to be specified.

The functionrpm is used to fit a revealed preference modelfor men and women of certaincharacteristics (or shared characteristics) of people of the opposite sex.The model assumes a one-to-one stable matching using an observed set ofmatchings and a set of (possibly dyadic) covariates to estimate the parameters forlinear equations of utilities.It does this using an large-population likelihood based on ideas from Dagsvik (2000), Menzel (2015) and Goyal et al (2023).

The model represents the dyadic utility functions as deterministic linear utility functions ofdyadic variables. These utility functions are functions of observed characteristics of the womenand men.These functions are entered as terms in the function calltorpm. This function simulates a population from such a model.

Value

A list of lists, each a simulation from the population. Each of the simulation lists containscomponentspopulation being a list with componentsXdata andZdata (for use withrpm()).

References

Goyal, Shuchi; Handcock, Mark S.; Jackson, Heide M.; Rendall, Michael S. and Yeung, Fiona C. (2023).A Practical Revealed Preference Model for Separating Preferences and Availability Effects in Marriage Formation,Journal of the Royal Statistical Society, A.doi:10.1093/jrsssa/qnad031

Dagsvik, John K. (2000)Aggregation in Matching MarketsInternational Economic Review, Vol. 41, 27-57.JSTOR: https://www.jstor.org/stable/2648822,doi:10.1111/1468-2354.00054

Menzel, Konrad (2015).Large Matching Markets as Two-Sided Demand SystemsEconometrica, Vol. 83, No. 3 (May, 2015), 897-941.doi:10.3982/ECTA12299

Examples

library(rpm)data(fauxmatching)fit <- rpm(~match("edu") + WtoM_diff("edu",3),          Xdata=fauxmatching$Xdata, Zdata=fauxmatching$Zdata,          X_w="X_w", Z_w="Z_w",          pair_w="pair_w", pair_id="pair_id", Xid="pid", Zid="pid",          sampled="sampled")num_women = fit$N*exp(fit$gw)num_men   = fit$N*exp(fit$gm)pmfW_N <- round(fit$pmfW * num_women)pmfM_N <- round(fit$pmfM * num_men)a <- microsimulate(fit, pmfW_N=pmfW_N, pmfM_N=pmfM_N)

Row-wise argmax (0-based column indices)

Description

Returns the column index of the maximum element in each row of an integer matrix.Uses Armadillo's 'index_max()' to avoid deprecated '.max(uword&)'.

Usage

rowwise_imax_idx(A)

Arguments

A

Integer matrix.

Value

A row vector of 0-based column indices of the maxima.


Row-wise argmax (0-based column indices)

Description

Returns the column index of the maximum element in each row of A.Uses Armadillo's 'index_max()' to avoid deprecated '.max(uword&)'.

Usage

rowwise_max_idx(A)

Arguments

A

Numeric matrix.

Value

A row vector of 0-based column indices of the maxima.


Fit a Revealed Preference Matchings Model

Description

rpm estimates the parameters of a revealed preference modelfor men and women of certaincharacteristics (or shared characteristics) of people of the opposite sex.The model assumes a one-to-one stable matching using an observed set ofmatchings and a set of (possibly dyadic) covariates to estimate the parameters forlinear equations of utilities.It does this using an large-population likelihood based on ideas from Dagsvik (2000), Menzel (2015) and Goyal et al (2023).

Usage

rpm(  formula,  Xdata,  Zdata,  Xid = NULL,  Zid = NULL,  pair_id = NULL,  X_w = NULL,  Z_w = NULL,  pair_w = NULL,  sampled = NULL,  sampling_design = "stock-flow",  fixed.margins = NULL,  control = control.rpm(),  verbose = FALSE)

Arguments

formula

formula; anformula object, of the form~ <model terms>. For the details on the possible<model terms>, seerpm-terms.

Xdata

data.frame for women. Each row is a woman, each column is a variable on that womenor her partnerships. It must contain the women's ID variable (seeXid) anda variable with the ID of the women's partner. If the women is single the men's ID should be NA.

Zdata

data.frame for men. Each row is a man, each column is a variable on that menIt must contain the men's ID variable (seeZid).

Xid

string The name of the variable inXdata containing the IDs of the women.

Zid

string The name of the variable inZdata containing the IDs of the men.

pair_id

string The name of the variable inXdata containing the ID of the men paired with the women inXid. If the women is not paired it must be NA.

X_w

string The name of the variable inXdata containing the individual weight of the women.If this is NULL then it is assumed the sample is unweighted from a population with 2000 women in it.

Z_w

string The name of the variable inZdata containing the individual weight of the manIf this is NULL then it is assumed the sample is unweighted from a population with 2000 men in it.

pair_w

string The name of the variable inXdata containing the pair weight of that women.If the women is not paired it should be NA.If this is NULL then it is computed from the individual weights using thesampling_design.Note that the pair weights currently do not play a role in the estimation. They do in the quasi-likelihood version of the code.If this is NULL then it is assumed the sample is unweighted from a population with 2000 men in it.

sampled

string The name of the logical variable inXdata andZdata containing the indicator that the person was sampled directly (as distinct from being included as the match of a directly sampledperson. All single people are directly sampled.

sampling_design

string; The name of the sampling protocol used to select the survey data. Valid values are"stock-flow" (default) (individuals are sampled, data contains bothsingles and couples);"stock-stock" (households are sampled, each household can be a single or a couple);"census" (the sample is a census of the population of people).

fixed.margins

list If not NULL the numbers of men and women (i.e, inpmfW andpmfM) are assumed determined byoutside information and are hence fixed. In this casefixed.margins should be a list with two elements. The first isa vector of women's margins for each type and the second is the men's margins for each type.The default, NULL, means these are estimated from sample data.

control

A list of control parameters for algorithm tuning. Constructed usingcontrol.rpm, which should be consulted for specifics.

verbose

logical; if this isTRUE, the program will print outadditional information, including data summary statistics.

Details

The pairings are determined by thepair_id variable inXdata. If that variable is NA then the women isassumed to be single. If men are listed inZdata and are not partnered then they are assumed single.Weights are specified by three optional variables inXdata.

X_w

: This is character string of the name of the weight variable for women. The sum of the weights should be thenumber of women in the population.

Z_w

: This is character string of the name of the weight variable for men. The sum of the weights should be thenumber of men in the population.

pair_w

: This is character string of the name of the weight variable for pairs.

Value

rpm returns an object of classrpm.objectthat is a list consisting of the following elements:

coef

The maximum psuedo-likelihood estimate of\theta, the vector ofcoefficients for the model parameters. This includes the model\beta and the model\Gamma.

coefficients

The bias-corrected bootstrap estimate of\theta, the vector ofcoefficients for the model parameters. This includes the model\beta and the model\Gamma.

loglik

The value of the maximized log-likelihood.

exitflag

integer value with the status of the optimization (4 is success asxtol_rel orxtol_abs was reached). Other codes are 1 = generic success; 2 = optimization stopped becauseftol_rel orftol_abs was reached; 3 = optimization stopped becausestopval was reached; 4 = optimization stopped becausextol_rel orxtol_abs was reached; 5 = optimization stopped becausemaxeval was reached; 6 = optimization stopped becausemaxtime was reached.

call

the call that was made tonloptr.

x0

vector with starting values for the optimization.

message

more informative message with the status of the optimization.

iterations

number of iterations that were executed.

objective

value if the objective function in the solution.

solution

optimal value of the controls.

version

version of NLopt that was used.

covar

Approximate covariance matrix of the estimates.

eq

Values from the equality constraints. Larger values indicate non-convergence.

sample

A matrix with the number of rows the MCMC sample size and the number of rows the number of parameters.

References

Goyal, Shuchi; Handcock, Mark S.; Jackson, Heide M.; Rendall, Michael S. and Yeung, Fiona C. (2023).A Practical Revealed Preference Model for Separating Preferences and Availability Effects in Marriage Formation,Journal of the Royal Statistical Society, A.doi:10.1093/jrsssa/qnad031

Dagsvik, John K. (2000)Aggregation in Matching MarketsInternational Economic Review, Vol. 41, 27-57.JSTOR: https://www.jstor.org/stable/2648822,doi:10.1111/1468-2354.00054

Menzel, Konrad (2015).Large Matching Markets as Two-Sided Demand SystemsEconometrica, Vol. 83, No. 3 (May, 2015), 897-941.doi:10.3982/ECTA12299

See Also

control.rpm, summary.rpm, print.rpm

Examples

library(rpm)data(fauxmatching)fit <- rpm(~match("edu") + WtoM_diff("edu",3),          Xdata=fauxmatching$Xdata, Zdata=fauxmatching$Zdata,          X_w="X_w", Z_w="Z_w",          pair_w="pair_w", pair_id="pair_id", Xid="pid", Zid="pid",          sampled="sampled",sampling_design="stock-flow")summary(fit)

Internal rpm Objects

Description

Internalrpm functions.

Details

Most of these are not to be called by the user (or in some cases are justwaiting for proper documentation to be written.

Value

No return value, called for side effects.

See Also

rpm-package


Terms used in a Revealed Preference Matchings Model

Description

The functionrpm is used to fit a revealed preference modelfor men and women of certaincharacteristics (or shared characteristics) of people of the opposite sex.The model assumes a one-to-one stable matching using an observed set ofmatchings and a set of (possibly dyadic) covariates to estimate the parameters forlinear equations of utilities.It does this using an large-population likelihood based on ideas from Dagsvik (2000), Menzel (2015) and Goyal et al (2023).

Details

The model represents the dyadic utility functions as deterministic linear utility functions ofdyadic variables. These utility functions are functions of observed characteristics of the womenand men.These functions are entered as terms in the function calltorpm. This page describes the possible terms (and hencelinear utility functions) included inrpm package.

Value

No return value, called for side effects.

Specifying models

Terms torpm are specified by a formula to represent thepairings and covariates This is done via aformula, that is,an formula object, of the form~ <term 1> + <term 2> ..., where<term 1>,<term 2>, etc, are each terms chosenfrom the list given below.

absdiff(attr) (quantitative attribute),absdiff(attr) (quantitative attribute)

Absolute difference:Theattr argument specifies a quantitative attribute This term adds one statistic to the model equalingabs(attr[i]-attr[j]) for all women-man dyad (i,j).

W_greaterthan(attr)

Women's valuegreater than the men's value Adds one statisticindicating if the women's value exceeds the men's value.

M_greaterthan(attr)

Men's valuegreater than the women's value Adds one statisticindicating if the men's value exceeds the women's value.

W_atleast(attr,threshold=0)

Valuesgreater than or equal to a threshold Adds one statisticindicating if the women's value of the attribute equals or exceedsthreshold.

W_atmost(threshold=0)

Valuesless than or equal to a threshold Adds one statisticindicating if the women's value equals or is exceeded bythreshold.

W_cov(attr) (quantitative attribute),W_cov(attr) (quantitative attribute)

Main effect of a covariate for women:Theattr argument specifies a quantitative attributeThis term adds a single statistic equaling the value ofattr(i) for womeni in the dyad.For categorical attributes,seeW_factor.

diff(attr) (quantitative attribute),diff(attr)(quantitative attribute)

Woman's Gap:Theattr argument specifies a quantitative attributeThis term adds one statistic to the modelbeingattr[i]-attr[j] for womeni and manj.Specifically, it is the excess of the woman's value over the man's value.

WtoM_diff(attr, diff) (ordinal categorical attribute),WtoM_diff(attr)(ordinal categorical discrete attribute)

Woman's Gap:Theattr argument specifies a ordinal categorical attributeThis term adds one statistic to the modelbeing an indicator thatattr[i]=attr[j]+diff for womeni and manj.Specifically, it indicates if the woman's value isdiff higher than the man's value.

MtoW_diff(attr, diff) (ordinal categorical attribute),MtoW_diff(attr)(ordinal categorical discrete attribute)

Man's Gap:Theattr argument specifies a ordinal categorical attributeThis term adds one statistic to the modelbeing an indicator thatattr[j]=attr[i]+diff for womeni and manj.Specifically, it indicates if the man's value isdiff higher than the woman's value.

MtoW_diff(attr) (quantitative attribute),MtoW_diff(attr)(quantitative attribute)

Difference:Theattr argument specifies a quantitative attributeThis term adds one statistic to the modelattr[j]-attr[i] for womeni and manj.

W_factor(attr, base=1, levels=-1) (categorical attribute),W_factor(attr, base=1, levels=-1) (categorical attribute)

Factor attribute effect for women:Theattr argument specifies a categorical attributeThis term addsmultiple statistics to the model, one for each of (a subset of) theunique values of theattr attribute. Each of these statisticsindicates if the women's has that attribute.

homophily(attr)

Uniform homophily effect:Theattr argument specifies a categorical attributeThis term adds one statistic to the modelindicating that the dyad matches on that attribute.

match(attr, diff=FALSE, collapse=NULL)

Attribute-based homophily effect:Theattr argument specifies a categorical attributeThis term adds one statistic to the model for each categorical level,unlessdiff is set toTRUE, in which case the term adds multiple statistics to the model, one for each of (a subset of) the unique values of theattrattribute. Ifdiff is set toTRUE, the optional argumentcollapse control what dyads are collapsed (or pooled).Specifically, it is a list of indices of attribute values which are to be collapsed into asingle term. For example,collapse=list(c(1,4)) will collapse the(1,1) and the(4,4) dyads into a single term (and group). Multiple lists can be included with arbitrary numbers of dyads in a group.

mix(attr, base=NULL, collapse=NULL)

Attribute mixing: Theattr argument specifies a categorical attributesBy default, this term adds one statistic tothe model for each possible pairing of attribute values. Thestatistic indicates if the dyad has that pairing of values.In other words, this term produces one statistic forevery entry in the mixing matrix for the attribute(s). The ordering ofthe attribute values is lexicographic: alphabetical (for nominal categories) ornumerical (for ordered categories).The optional argumentbase control what statistics are included in the model, specifically it lists the index of the omitted terms (in order).For example,base=2 omits the second term. The optional argumentcollapse control what dyads are collapsed (or pooled).Specifically, it is a list of lists. Each element of the list is a list of dyads which are to be collapsed into asingle term. For example,collapse=list(list(c(1,4),c(2,4))) will collapse the(1,4) and the(2,4) dyads into a single term (and group). Multiple lists can be included with arbitrary numbers of dyads in a group.

References

Goyal, Shuchi; Handcock, Mark S.; Jackson, Heide M.; Rendall, Michael S. and Yeung, Fiona C. (2023).A Practical Revealed Preference Model for Separating Preferences and Availability Effects in Marriage Formation,Journal of the Royal Statistical Society, A.doi:10.1093/jrsssa/qnad031

Dagsvik, John K. (2000)Aggregation in Matching MarketsInternational Economic Review, Vol. 41, 27-57.JSTOR: https://www.jstor.org/stable/2648822,doi:10.1111/1468-2354.00054

Menzel, Konrad (2015).Large Matching Markets as Two-Sided Demand SystemsEconometrica, Vol. 83, No. 3 (May, 2015), 897-941.doi:10.3982/ECTA12299

See Also

rpm package,rpm

Examples

library(rpm)data(fauxmatching)fit <- rpm(~match("edu") + WtoM_diff("edu",3),          Xdata=fauxmatching$Xdata, Zdata=fauxmatching$Zdata,          X_w="X_w", Z_w="Z_w",          pair_w="pair_w", pair_id="pair_id", Xid="pid", Zid="pid",          sampled="sampled")summary(fit)

Creates a model function list for the continuous terms in a Revealed Preference Matchings Model

Description

rpm.model.matrix assumes a bipartite network (i.e. two-sided matching market)It creates a model matrix according to the formula passed in.Seerpm-terms for a description of the possible terms.

Usage

rpm.model.functions(model.terms, control)

Arguments

model.terms

For the details on the possible countinuous<model terms>, seerpm-terms. This includes the covariates used to construct the model matrix.They are used in conjunction with the model terms.

control

A list of control parameters for algorithm tuning. Constructed usingcontrol.rpm, which should be consulted for specifics.

Value

A list of model terms as bivariate functions.

References

Goyal, Shuchi; Handcock, Mark S.; Jackson, Heide M.; Rendall, Michael S. and Yeung, Fiona C. (2023).A Practical Revealed Preference Model for Separating Preferences and Availability Effects in Marriage Formation,Journal of the Royal Statistical Society, A.doi:10.1093/jrsssa/qnad031

Dagsvik, John K. (2000)Aggregation in Matching MarketsInternational Economic Review, Vol. 41, 27-57.JSTOR: https://www.jstor.org/stable/2648822,doi:10.1111/1468-2354.00054

Menzel, Konrad (2015).Large Matching Markets as Two-Sided Demand SystemsEconometrica, Vol. 83, No. 3 (May, 2015), 897-941.doi:10.3982/ECTA12299

See Also

rpm

Examples

# nothing yet

Creates a model matrix to estimate the parameters of a Revealed Preference Matchings Model

Description

rpm.model.matrix assumes a bipartite network (i.e. two-sided matching market)It creates a model matrix according to the formula passed in.Seerpm-terms for a description of the possible terms.

Usage

rpm.model.matrix(model.terms, Xall, Zall, intercept = TRUE)

Arguments

model.terms

For the details on the possible<model terms>, seerpm-terms. This includes the covariates used to construct the model matrix.They are used in conjunction with the model terms.

Xall

the unique types of women

Zall

the unique types of men

intercept

logical; If TRUE, the default, an intercept term is prepended.

Value

A list consists of the following elements:

X

the model matrix for women.

Z

the model matrix for men.

Xnames

the names of the covariates for women.

Znames

the names of the covariates for men.

References

Goyal, Shuchi; Handcock, Mark S.; Jackson, Heide M.; Rendall, Michael S. and Yeung, Fiona C. (2023).A Practical Revealed Preference Model for Separating Preferences and Availability Effects in Marriage Formation,Journal of the Royal Statistical Society, A.doi:10.1093/jrsssa/qnad031

Dagsvik, John K. (2000)Aggregation in Matching MarketsInternational Economic Review, Vol. 41, 27-57.JSTOR: https://www.jstor.org/stable/2648822,doi:10.1111/1468-2354.00054

Menzel, Konrad (2015).Large Matching Markets as Two-Sided Demand SystemsEconometrica, Vol. 83, No. 3 (May, 2015), 897-941.doi:10.3982/ECTA12299

See Also

rpm

Examples

# nothing yet

Fit a Revealed Preference Matchings Model

Description

rpm_MLPLE estimates the parameters of a revealed preference modelfor men and women of certaincharacteristics (or shared characteristics) of people of the opposite sex.The model assumes a one-to-one stable matching using an observed set ofmatchings and a set of (possibly dyadic) covariates to estimate the parameters forlinear equations of utilities.It does this using an large-population likelihood based on ideas from Dagsvik (2000), Menzel (2015) and Goyal et al (2023).

Usage

rpm_MLPLE(  formula,  Xdata,  Zdata,  Xid = NULL,  Zid = NULL,  pair_id = NULL,  X_w = NULL,  Z_w = NULL,  pair_w = NULL,  sampled = NULL,  sampling_design = "stock-flow",  fixed.margins = fixed.margins,  control = control.rpm(),  verbose = FALSE)

Arguments

formula

formula; anformula object, of the form~ <model terms>. For the details on the possible<model terms>, seerpm-terms.

Xdata

data.frame for women. Each row is a woman, each column is a variable on that womenor her partnerships. It must contain the women's ID variable (seeXid) anda variable with the ID of the women's partner. If the women is single the men's ID should be NA.

Zdata

data.frame for men. Each row is a man, each column is a variable on that menIt must contain the men's ID variable (seeZid).

Xid

string The name of the variable inXdata containing the IDs of the women.

Zid

string The name of the variable inZdata containing the IDs of the men.

pair_id

string The name of the variable inXdata containing the ID of the men paired with the women inXid. If the women is not paired it must be NA.

X_w

string The name of the variable inXdata containing the individual weight of the women.If this is NULL then it is assumed the sample is unweighted from a population with 2000 women in it.

Z_w

string The name of the variable inZdata containing the individual weight of the manIf this is NULL then it is assumed the sample is unweighted from a population with 2000 men in it.

pair_w

string The name of the variable inXdata containing the pair weight of that women.If the women is not paired it should be NA.If this is NULL then it is computed from the individual weights using thesampling_design.Note that the pair weights currently do not play a role in the estimation. They do in the quasi-likelihood version of the code.If this is NULL then it is assumed the sample is unweighted from a population with 2000 men in it.

sampled

string The name of the logical variable inXdata andZdata containing the indicator that the person was sampled directly (as distinct from being included as the match of a directly sampledperson. All single people are directly sampled.

sampling_design

string; The name of the sampling protocol used to select the survey data. Valid values are"stock-flow" (default) (individuals are sampled, data contains bothsingles and couples);"stock-stock" (households are sampled, each household can be a single or a couple);"census" (the sample is a census of the population of people).

fixed.margins

list If not NULL the numbers of men and women (i.e, inpmfW andpmfM) are assumed determined byoutside information and are hence fixed. In this casefixed.margins should be a list with two elements. The first isa vector of women's margins for each type and the second is the men's margins for each type.The default, NULL, means these are estimated from sample data.

control

A list of control parameters for algorithm tuning. Constructed usingcontrol.rpm, which should be consulted for specifics.

verbose

logical; if this isTRUE, the program will print outadditional information, including data summary statistics.

Details

It is usually called via therpm function.

The pairings are determined by thepair_id variable inXdata. If that variable is NA then the women isassumed to be single. If men are listed inZdata and are not partnered then they are assumed single.Weights are specified by three optional variables inXdata.

X_w

: This is character string of the name of the weight variable for women. The sum of the weights should be thenumber of women in the population.

Z_w

: This is character string of the name of the weight variable for men. The sum of the weights should be thenumber of men in the population.

pair_w

: This is character string of the name of the weight variable for pairs.

Value

rpm returns an object of classrpm.objectthat is a list consisting of the following elements:

coefficients

The bias-corrected bootstrap estimate of\theta, the vector ofcoefficients for the model parameters. This includes the model\beta and the model\Gamma.

loglik

The value of the maximized log-likelihood.

exitflag

integer value with the status of the optimization (4 is success asxtol_rel orxtol_abs was reached). Other codes are 1 = generic success; 2 = optimization stopped becauseftol_rel orftol_abs was reached; 3 = optimization stopped becausestopval was reached; 4 = optimization stopped becausextol_rel orxtol_abs was reached; 5 = optimization stopped becausemaxeval was reached; 6 = optimization stopped becausemaxtime was reached.

call

the call that was made tonloptr.

x0

vector with starting values for the optimization.

message

more informative message with the status of the optimization.

iterations

number of iterations that were executed.

objective

value if the objective function in the solution.

solution

optimal value of the controls.

version

version of NLopt that was used.

covar

Approximate covariance matrix of the estimates.

eq

Values from the equality constraints. Larger values indicate non-convergence.

References

Goyal, Shuchi; Handcock, Mark S.; Jackson, Heide M.; Rendall, Michael S. and Yeung, Fiona C. (2023).A Practical Revealed Preference Model for Separating Preferences and Availability Effects in Marriage Formation,Journal of the Royal Statistical Society, A.doi:10.1093/jrsssa/qnad031

Dagsvik, John K. (2000)Aggregation in Matching MarketsInternational Economic Review, Vol. 41, 27-57.JSTOR: https://www.jstor.org/stable/2648822,doi:10.1111/1468-2354.00054

Menzel, Konrad (2015).Large Matching Markets as Two-Sided Demand SystemsEconometrica, Vol. 83, No. 3 (May, 2015), 897-941.doi:10.3982/ECTA12299

See Also

control.rpm, summary.rpm, print.rpm

Examples

library(rpm)data(fauxmatching)fit <- rpm(~match("edu") + WtoM_diff("edu",3),          Xdata=fauxmatching$Xdata, Zdata=fauxmatching$Zdata,          X_w="X_w", Z_w="Z_w",          pair_w="pair_w", pair_id="pair_id", Xid="pid", Zid="pid",          sampled="sampled",sampling_design="stock-flow")summary(fit)

Compute the population distribution of pairs and singles from a Revealed Preference Matchings Model

Description

rpmpopulationpmf computes the probability mass function for a population of the pairs and singlesfrom a Revealed Preference Matchings Model based on arbitary availability distribution and preferences. It is typically based on the estimate from arpm() call.

Usage

rpmpopulationpmf(  object,  N = 2000,  num_women = NULL,  num_men = NULL,  pmfW = NULL,  pmfM = NULL,  verbose = FALSE)

Arguments

object

list; an object of classrpm that is typically the result of a call torpm().

N

integer; The total population size. This must be set. The number of women and men are derived from the(weighted) data.

num_women

integer; (Optional) The number of women in the population.

num_men

integer; (Optional) The number of men in the population.

pmfW

vector; (Optional) The population proportions of the numbers of women of each type. This should be compatible with the type in the object.

pmfM

vector; (Optional) The population proportions of the numbers of men of each type. This should be compatible with the type in the object.

verbose

logical; Should verbose messages be printed out.

Details

The functionrpm is used to fit a revealed preference modelfor men and women of certaincharacteristics (or shared characteristics) of people of the opposite sex.The model assumes a one-to-one stable matching using an observed set ofmatchings and a set of (possibly dyadic) covariates to estimate the parameters forlinear equations of utilities.It does this using an large-population likelihood based on ideas from Dagsvik (2000), Menzel (2015) and Goyal et al (2023).

The model represents the dyadic utility functions as deterministic linear utility functions ofdyadic variables. These utility functions are functions of observed characteristics of the womenand men.These functions are entered as terms in the function calltorpm. This function simulates from such a model.

Value

A list of data.frame, each a simulation from the population.

References

Goyal, Shuchi; Handcock, Mark S.; Jackson, Heide M.; Rendall, Michael S. and Yeung, Fiona C. (2023).A Practical Revealed Preference Model for Separating Preferences and Availability Effects in Marriage Formation,Journal of the Royal Statistical Society, A.doi:10.1093/jrsssa/qnad031

Dagsvik, John K. (2000)Aggregation in Matching MarketsInternational Economic Review, Vol. 41, 27-57.JSTOR: https://www.jstor.org/stable/2648822,doi:10.1111/1468-2354.00054

Menzel, Konrad (2015).Large Matching Markets as Two-Sided Demand SystemsEconometrica, Vol. 83, No. 3 (May, 2015), 897-941.doi:10.3982/ECTA12299

Examples

library(rpm)data(fauxmatching)fit <- rpm(~match("edu") + WtoM_diff("edu",3),          Xdata=fauxmatching$Xdata, Zdata=fauxmatching$Zdata,          X_w="X_w", Z_w="Z_w",          pair_w="pair_w", pair_id="pair_id", Xid="pid", Zid="pid",          sampled="sampled")a <- rpmpopulationpmf(fit)

Simulate a sample of pairs and singles from a Revealed Preference Matchings Model

Description

simulate.rpm simulates a population of the pairs and singlesfrom a Revealed Preference Matchings Model. It is typically based on the estimate from arpm() call.

Usage

## S3 method for class 'rpm'simulate(  object,  nsim = 1,  seed = NULL,  ...,  N = NULL,  num_women = NULL,  num_men = NULL,  pmfW = NULL,  pmfM = NULL,  large.population = TRUE,  num_sampled = NULL,  bootstrap = FALSE,  sampling_design = NULL,  control = control.rpm(),  verbose = FALSE)

Arguments

object

list; an object of classrpm that is typically the result of a call torpm().

nsim

Number of matchings to be randomly drawn from the givenmodel on the set of all matchings / singles.

seed

integer; (Optional) random number seed.

...

Additional arguments, to be passed to lower-level functions.

N

integer; The total population size. This must be set. The number of women and men are derived from the(weighted) data.

num_women

integer; (Optional) The number of women in the population.

num_men

integer; (Optional) The number of men in the population.

pmfW

vector; (Optional) The population proportions of the numbers of women of each type. This should be compatible with the type in the object.

pmfM

vector; (Optional) The population proportions of the numbers of men of each type. This should be compatible with the type in the object.

large.population

logical; If TRUE a large population approximation is used to generatethe matchings (rather than the individual level generation of utilities). This is much faster anduses a lot less memory. It is TRUE by default. If used, a sample is drawn rather than thepopulation being returned. The sample size is controlled bynum_sampled.

num_sampled

integer; The size of the sample to be drawn. For "stock-stock" sampling this is the number of sampled households. For "stock-flow" it is the number of sampled people.For "census" it is the total population size, N. If NULL the size is the same asthe passed fitted object (that is, the original data), although this is only a guess and it should be explicitly set.

bootstrap

logical; If TRUE the original population is sampled from. If FALSE thepopulation underlying the fitted model is sampled from.

sampling_design

string; The name of the sampling protocol used to select the survey data. Valid values are"stock-flow" (individuals are sampled, data contains bothsingles and couples);"stock-stock" (households are sampled, each household can be a single or a couple);"census" (the sample is a census of the population of people).The final option, the default, is NULL whereby the design is taken from the passed object.

control

A list of control parameters for algorithm tuning. Constructed usingcontrol.rpm, which should be consulted for specifics.

verbose

logical; Should verbose messages be printed out.

Details

The functionrpm is used to fit a revealed preference modelfor men and women of certaincharacteristics (or shared characteristics) of people of the opposite sex.The model assumes a one-to-one stable matching using an observed set ofmatchings and a set of (possibly dyadic) covariates to estimate the parameters forlinear equations of utilities.It does this using an large-population likelihood based on ideas from Dagsvik (2000), Menzel (2015) and Goyal et al (2023).

The model represents the dyadic utility functions as deterministic linear utility functions ofdyadic variables. These utility functions are functions of observed characteristics of the womenand men.These functions are entered as terms in the function calltorpm. This function simulates from such a model.

Value

A list of data.frame, each a simulation from the population.

References

Goyal, Shuchi; Handcock, Mark S.; Jackson, Heide M.; Rendall, Michael S. and Yeung, Fiona C. (2023).A Practical Revealed Preference Model for Separating Preferences and Availability Effects in Marriage Formation,Journal of the Royal Statistical Society, A.doi:10.1093/jrsssa/qnad031

Dagsvik, John K. (2000)Aggregation in Matching MarketsInternational Economic Review, Vol. 41, 27-57.JSTOR: https://www.jstor.org/stable/2648822,doi:10.1111/1468-2354.00054

Menzel, Konrad (2015).Large Matching Markets as Two-Sided Demand SystemsEconometrica, Vol. 83, No. 3 (May, 2015), 897-941.doi:10.3982/ECTA12299

Examples

library(rpm)data(fauxmatching)fit <- rpm(~match("edu") + WtoM_diff("edu",3),          Xdata=fauxmatching$Xdata, Zdata=fauxmatching$Zdata,          X_w="X_w", Z_w="Z_w",          pair_w="pair_w", pair_id="pair_id", Xid="pid", Zid="pid",          sampled="sampled")a <- simulate(fit)

Summarizing rpm Model Fits

Description

[base::summary()] method for [rpm()] fits.

Usage

## S3 method for class 'rpm'summary(  object,  ...,  digits = max(3, getOption("digits") - 3),  correlation = FALSE,  covariance = FALSE,  include.single = TRUE)## S3 method for class 'summary.rpm'print(  x,  digits = max(3, getOption("digits") - 3),  correlation = FALSE,  covariance = FALSE,  signif.stars = getOption("show.signif.stars"),  eps.Pvalue = 1e-04,  print.header = TRUE,  print.formula = FALSE,  print.fitinfo = TRUE,  print.coefmat = TRUE,  print.message = TRUE,  print.deviances = TRUE,  print.drop = TRUE,  ...)

Arguments

object

an object of classrpm, usually, a result of a call to[rpm()].

...

For [summary.rpm()] additional arguments are passed to[logLik.rpm()]. For [print.summary.rpm()], to [stats::printCoefmat()].

digits

significant digits for coefficients. The default is max(3, getOption("digits")-3).

correlation

logical whether the correlation matrix of the estimated parametersshould be printed (T or F); default=FALSE

covariance

logical whether the covariance matrix of the estimated parametersshould be printed (T or F); default=FALSE

include.single

logical; if 'TRUE', include in the summary table the coefficients of the log-odds of being single for each category of women and men.

x

object of class 'summary.rpm' returned by [summary.rpm()].

signif.stars

whether to print dots and stars to signifystatistical significance. See [print.summary.lm()].

eps.Pvalue

p-values below this level will be printedas "<'eps.Pvalue'".

print.formula,print.fitinfo,print.coefmat,print.message,print.deviances,print.drop,print.header

which components of the fit summary to print.

Details

[summary.rpm()] tries to be smart about formatting thecoefficients, standard errors, etc.

The default printout of the summary object contains thecall, number of iterations used, null and residual deviances, andthe values of AIC and BIC.The coefficient table contains the followingcolumns:

- 'Estimate', 'Std. Error' - parameter estimates and their standard errors- 'z value', 'Pr(>|z|)' - z-test and p-values

Value

The function [summary.rpm()] computes and returns a list of summarystatistics of the fitted [rpm()] model given in 'object'. Note that forbackwards compatibility, it returns the coefficient table.

The returned object is a list of class "summary.rpm" with the followingelements:

formula

ERGM model formula

digits

the 'digits' inputted to <summary.rpm> or the default value (despite the fact the digits will be 5)

correlation,covariance

whether to print correlation/covariance matrices of the estimated parameters

iterations

object$iterations

control

the [control.rpm()] object used

samplesize

MCMC sample size

message

optional message on the validity of the standard error estimates

aic.null,bic.null

values of AIC and BIC for the null model

aic,bic

values of AIC and BIC

coefficients

data frames with model parameters and associated statistics

asycov

asymptotic covariance matrix

asyse

asymptotic standard error matrix

offset,drop,estimate,iterations,mle.lik,null.lik

see documentation of the object returned by [rpm()]

See Also

The model fitting function [rpm()], [print.rpm()], and[base::summary()]. Function [stats::coef()] will extract the data frame ofcoefficients with standard errors, t-statistics and p-values.

Examples

library(rpm)data(fauxmatching)fit <- rpm(~match("edu") + WtoM_diff("edu",3),          Xdata=fauxmatching$Xdata, Zdata=fauxmatching$Zdata,          X_w="X_w", Z_w="Z_w",          pair_w="pair_w", pair_id="pair_id", Xid="pid", Zid="pid",          sampled="sampled",sampling_design="stock-flow")summary(fit)

Summarize Revealed Preference Matchings data via a Model Specification

Description

summary_rpm produces tabular summaries of data revealed preference matchingsbased on a formula specifying a revealed preference modelfor men and women of certaincharacteristics (or shared characteristics) of people of the opposite sex.The model assumes a one-to-one stable matching using an observed set ofmatchings and a set of (possibly dyadic) covariates to estimate the parameters forlinear equations of utilities.

Usage

summary_rpm(  formula,  Xdata,  Zdata,  Xid = NULL,  Zid = NULL,  pair_id = NULL,  X_w = NULL,  Z_w = NULL,  pair_w = NULL,  sampled = NULL,  sampling_design = "stock-flow",  control = control.rpm(),  verbose = FALSE)

Arguments

formula

formula; anformula object, of the form~ <model terms>. For the details on the possible<model terms>, seerpm-terms.

Xdata

data.frame for women. Each row is a woman, each column is a variable on that womenor her partnerships. It must contain the women's ID variable (seeXid) anda variable with the ID of the women's partner. If the women is single the men's ID should be NA.

Zdata

data.frame for men. Each row is a man, each column is a variable on that menIt must contain the men's ID variable (seeZid).

Xid

string The name of the variable inXdata containing the IDs of the women.

Zid

string The name of the variable inZdata containing the IDs of the men.

pair_id

string The name of the variable inXdata containing the ID of the men paired with the women inXid. If the women is not paired it must be NA.

X_w

string The name of the variable inXdata containing the individual weight of the women.If this is NULL then it is assumed the sample is unweighted from a population with 2000 women in it.

Z_w

string The name of the variable inZdata containing the individual weight of the manIf this is NULL then it is assumed the sample is unweighted from a population with 2000 men in it.

pair_w

string The name of the variable inXdata containing the pair weight of that women.If the women is not paired it should be NA.If this is NULL then it is computed from the individual weights using thesampling_design.Note that the pair weights currently do not play a role in the estimation. They do in the quasi-likelihood version of the code.If this is NULL then it is assumed the sample is unweighted from a population with 2000 men in it.

sampled

string The name of the logical variable inXdata andZdata containing the indicator that the person was sampled directly (as distinct from being included as the match of a directly sampledperson. All single people are directly sampled.

sampling_design

string; The name of the sampling protocol used to select the survey data. Valid values are"stock-flow" (default) (individuals are sampled, data contains bothsingles and couples);"stock-stock" (households are sampled, each household can be a single or a couple);"census" (the sample is a census of the population of people).

control

A list of control parameters for algorithm tuning. Constructed usingcontrol.rpm, which should be consulted for specifics.

verbose

logical; if this isTRUE, the program will print outadditional information, including data summary statistics.

Details

The pairings are determined by thepair_id variable inXdata. If that variable is NA then the women isassumed to be single. If men are listed inZdata and are not partnered then they are assumed single.Weights are specified by three optional variables inXdata.

X_w

: This is character string of the name of the weight variable for women. The sum of the weights should be thenumber of women in the population.

Z_w

: This is character string of the name of the weight variable for men. The sum of the weights should be thenumber of men in the population.

pair_w

: This is character string of the name of the weight variable for pairs.

Value

summary returns a list with many components, likerpm object without the model estimates. In particular it includesstats andpopstats.stats is the named vector of sample statistics from the model. whilepopstats is the named vector of population statistics from the model. It alos includescounts andpmf. Each of these is a contingency table in arrayrepresentation of S3 classc("xtabs", "table"), with a"call"

References

Goyal, Shuchi; Handcock, Mark S.; Jackson, Heide M.; Rendall, Michael S. and Yeung, Fiona C. (2023).A Practical Revealed Preference Model for Separating Preferences and Availability Effects in Marriage Formation,Journal of the Royal Statistical Society, A.doi:10.1093/jrsssa/qnad031

Dagsvik, John K. (2000)Aggregation in Matching MarketsInternational Economic Review, Vol. 41, 27-57.JSTOR: https://www.jstor.org/stable/2648822,doi:10.1111/1468-2354.00054

Menzel, Konrad (2015).Large Matching Markets as Two-Sided Demand SystemsEconometrica, Vol. 83, No. 3 (May, 2015), 897-941.doi:10.3982/ECTA12299

See Also

control.rpm, summary.rpm, rpm

Examples

library(rpm)data(fauxmatching)summary_rpm(~match("edu") + WtoM_diff("edu",3),        Xdata=fauxmatching$Xdata, Zdata=fauxmatching$Zdata,        X_w="X_w", Z_w="Z_w",        pair_w="pair_w", pair_id="pair_id", Xid="pid", Zid="pid",        sampled="sampled",sampling_design="stock-flow")

Extract or replace the *ult*imate (last) element of a vector or a list, or an element counting from the end.

Description

Extract or replace the *ult*imate (last) element of a vector or a list, or an element counting from the end.

Usage

ult(x, i = 1L) <- valueult(x, i = 1L)

Arguments

x

a vector or a list.

i

index from the end of the list to extract or replace (where 1 is the last element, 2 is the penultimate element, etc.).

value

Replacement value for the 'i'th element from the end.

Value

An element of 'x'.

Note

Due to the way in which assigning to a function isimplemented in R, 'ult(x) <- e' may be less efficient than'x[[length(x)]] <- e'.

Examples

(x <- c(1:5))(ult(x) <- 6)(ult(x, 2) <- 7) # 2nd last.xx <- 1:5(last <- ult(x))(penultimate <- ult(x, 2)) # 2nd last.

[8]ページ先頭

©2009-2025 Movatter.jp