The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon...

112
The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author Arne Henningsen <[email protected]>, Ott Toomet <[email protected]> Maintainer Arne Henningsen <[email protected]> Depends R (>= 2.4.0), systemfit Suggests MASS, VGAM, mvtnorm Description Tools for microeconomic analysis and microeconomic modelling License GPL version 2 or newer URL http://www.r-project.org, http://www.micEcon.org R topics documented: Blanciforti86 ........................................ 3 Bleymueller79E25.1 .................................... 4 Coelli ............................................ 5 Missong03E7.7 ....................................... 6 Mroz87 ........................................... 6 RandHIE .......................................... 8 activePar ........................................... 10 aidsBestA0 ......................................... 11 aidsCalc ........................................... 13 aidsElas ........................................... 14 aidsEst ............................................ 17 aidsPx ............................................ 20 aidsTestConsist ....................................... 22 coef.selection ........................................ 24 coefTable .......................................... 25 compareDerivatives ..................................... 26 1

Transcript of The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon...

Page 1: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

The micEcon PackageSeptember 11, 2007

Version 0.3-8

Date 2007/09/11

Title Microeconomics

Author Arne Henningsen <[email protected]>, Ott Toomet <[email protected]>

Maintainer Arne Henningsen <[email protected]>

Depends R (>= 2.4.0), systemfit

Suggests MASS, VGAM, mvtnorm

Description Tools for microeconomic analysis and microeconomic modelling

License GPL version 2 or newer

URL http://www.r-project.org, http://www.micEcon.org

R topics documented:Blanciforti86 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Bleymueller79E25.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Coelli . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Missong03E7.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Mroz87 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6RandHIE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8activePar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10aidsBestA0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11aidsCalc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13aidsElas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14aidsEst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17aidsPx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20aidsTestConsist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22coef.selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24coefTable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25compareDerivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

1

Page 2: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

2 R topics documented:

elas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27germanFarms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28heckit2fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28heckitVcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30hessian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31insertCol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32insertRow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33invMillsRatio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33linearPredictors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37loglikValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38maxBFGS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39maxBHHH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41maxLik . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42maxNR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43maximisationType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46micEcon-deprecated . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47micEcon-internal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48nObs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48nParam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49numericGradient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50predict.snqProfitEst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52priceIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53print.snqProfitEst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55probit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56quadFuncCalc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57quadFuncDeriv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58quadFuncEst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60quantityIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61quasiconcavity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62rSquared . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63readFront41out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64residuals.snqProfitEst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65returnCode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67returnMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69semidefiniteness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73snqProfitCalc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74snqProfitEla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76snqProfitEst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77snqProfitFixEla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81snqProfitHessian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82snqProfitHessianDeriv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83snqProfitImposeConvexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84snqProfitShadowPrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86snqProfitWeights . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87summary.aidsElas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88summary.aidsEst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89summary.maxLik . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

Page 3: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

Blanciforti86 3

summary.maximisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91summary.selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93symMatrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94testConsist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95tobit2fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96translogCalc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97translogDeriv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98translogEst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99translogHessian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100triang . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102vcov-methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103vcov.selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103vecli . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104vecli2m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105veclipos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106writeFront41in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

Index 109

Blanciforti86 U.S. consumption data

Description

The Blanciforti86 data frame contains annual U.S. consumption data from 1947 to 1978 or1981. These data include eleven aggregate commodity groups: (1) food, (2) alcohol plus tobacco,(3) clothing, (4) housing, (5) utilities, (6) transportation, (7) medical care, (8) durable goods, (9)other nondurable goods, (10) other services, and (11) other miscellaneous goods; four food groups:(1) meats, (2) fruits and vegetables, (3) cereal and bakery products, and (4) miscellaneous foods;and four meat groups: (1) beef and veal, (2) pork, (3) fish, and (4) poultry. For each of these groupsthe consumption expenditures, price indices, and expenditure shares are available.

This data frame contains the following variables / columns:

year The year.

xAggX Expenditure on the aggregate commodity group X (in Millions of US-Dollars).

xAgg Total expenditure on all eleven aggregate commodity groups (in Millions of US-Dollars).

xcAggX Deflated expenditure on the aggregate commodity group X (in Million of 1972 US-Dollars).

xcAgg Total deflated expenditure on all eleven aggregate commodity groups (in Million of 1972US-Dollars).

pAggX Price index for the aggregate commodity group X (1972 = 100).

wAggX Expenditure share of the aggregate commodity group X.

xFoodX Per capita expenditure for food group X (in US-Dollars).

xFood Total per capita expenditure for all four food groups (in US-Dollars).

xcFoodX Deflated per capita expenditure for food group X (in 1972 US-Dollars).

xcFood Total deflated per capita expenditure for all four food groups (in 1972 US-Dollars).

Page 4: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

4 Bleymueller79E25.1

pFoodX Price index for food group X (1972 = 100).

wFoodX Expenditure share of food group X.

xFoodUsdoc Expenditure on food published by the US Department of Commerce (USDOC) (inMillions of US-Dollars).

xFoodUsda Expenditure on food published by the US Department of Agriculture (USDA) (in Mil-lions of US-Dollars).

xFoodNew Expenditure on food (new estimates) (in Millions of US-Dollars).

xMeatX Per capita expenditure for meat group X (in US-Dollars).

xMeat Total per capita expenditure for all four meat groups (in US-Dollars).

pMeatX Price index for meat group X (1972 = 100).

cMeatX Per capita consumption of meat group X (in pounds).

pMeat Price index for the meat group (1972 = 100).

pMeatNew Price index for the meat group (new estimate) (1972 = 100).

population3 Population as presented in Table 5.A.3 (in Millions).

population12 Population as presented in Table 5.A.12 (in Millions).

Usage

data(Blanciforti86)

Source

Blanciforti, Laura. A., Richard D. Green and Gordon A. King (1986) U.S. Consumer Behavior Overthe Postwar Period: An Almost Ideal Demand System Analysis. Giannini Foundation MonographNumber 40, August 1986.

Bleymueller79E25.1 Artificial Prices and Quantities

Description

The Bleymueller251 data frame contains prices and quantities of 4 products for the years 1970,1974 and 1978. This data are part of Exercise 25.1 of Bleymueller, Gehler und Guetlicher (1979).

Usage

data(Bleymueller79E25.1)

Page 5: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

Coelli 5

Format

This data frame contains the following columns:

p.A Price of good A.

p.B Price of good B.

p.C Price of good C.

p.D Price of good D.

q.A Quantity of good A.

q.B Quantity of good B.

q.C Quantity of good C.

q.D Quantity of good D.

Source

Bleymueller, J; G. Gehlert and H. Guelicher (1979) Statistik fuer Wirtschaftswissenschaftler. VerlagVahlen, Muenchen.

Coelli Data provided with Coelli’s Frontier 4.1

Description

The Coelli data frame contains cross-sectional data of 60 firms.

Usage

data(Coelli)

Format

This data frame contains the following columns:

firm firm ID.

time time period.

output output.

capital capital.

labour labour.

Source

Coelli, T. (1996) A Guide to FRONTIER Version 4.1: A Computer Program for Stochastic FrontierProduction and Cost Function Estimation, CEPA Working Paper 96/08, http://www.uq.edu.au/economics/cepa/frontier.htm, University of New England.

Page 6: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

6 Mroz87

Missong03E7.7 Meat Prices and Quantities in Germany

Description

The Missong03E7.7 data frame contains meat prices and demanded quantities of a represen-tative (West-)German household for the years 1986 to 1989. This data are part of Exercise 7.7 ofMissong (2003).

Usage

data(Missong03E7.7)

Format

This data frame contains the following columns:

p.beef Average price of beef (DM/kg).

q.beef Demanded Quantity of beef (kg).

p.veal Average price of veal (DM/kg).

q.veal Demanded Quantity of veal (kg).

p.pork Average price of pork (DM/kg).

q.pork Demanded Quantity of pork (kg).

Source

Missong, M. (2003) Aufgabensammlung zur deskriptiven Statistik, Oldenbourg, Muenchen.

Statistisches Bundesamt (1989) Fachserie 15, Reihe 1, p. 76f.

Mroz87 U.S. Women’s Labor Force Participation

Description

The Mroz87 data frame contains data about 753 married women. These data are collected withinthe "Panel Study of Income Dynamics" (PSID). Of the 753 observations, the first 428 are for womenwith positive hours worked in 1975, while the remaining 325 observations are for women whodid not work for pay in 1975. A more complete discussion of the data is found in Mroz (1987),Appendix 1.

Usage

data(Mroz87)

Page 7: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

Mroz87 7

Format

This data frame contains the following columns:

lfp Dummy variable for labor-force participation.

hours Wife’s hours of work in 1975.

kids5 Number of children 5 years old or younger.

kids618 Number of children 6 to 18 years old.

age Wife’s age.

educ Wife’s educational attainment, in years.

wage Wife’s average hourly earnings, in 1975 dollars.

repwage Wife’s wage reported at the time of the 1976 interview.

hushrs Husband’s hours worked in 1975.

husage Husband’s age.

huseduc Husband’s educational attainment, in years.

huswage Husband’s wage, in 1975 dollars.

faminc Family income, in 1975 dollars.

mtr Marginal tax rate facing the wife.

motheduc Wife’s mother’s educational attainment, in years.

fatheduc Wife’s father’s educational attainment, in years.

unem Unemployment rate in county of residence, in percentage points.

city Dummy variable = 1 if live in large city, else 0.

exper Actual years of wife’s previous labor market experience.

nwifeinc Non-wife income.

wifecoll Dummy variable for wife’s college attendance.

huscoll Dummy variable for husband’s college attendance.

Source

Mroz, T. A. (1987) The sensitivity of an empirical model of married women’s hours of work toeconomic and statistical assumptions. Econometrica 55, 765–799.

PSID Staff, The Panel Study of Income Dynamics, Institute for Social ResearchPanel Study ofIncome Dynamics, University of Michigan, http://psidonline.isr.umich.edu.

References

Fox, J. (2004) car: The Companion to Applied Regression Libary - An R and S-PLUS Companionto Applied Regression, http://socserv.mcmaster.ca/jfox/Books/Companion/car.html.

Page 8: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

8 RandHIE

RandHIE RAND Health Insurance Experiment

Description

’The RAND Health Insurance Experiment (RAND HIE) was a comprehensive study of health carecost, utilization and outcome in the United States. It is the only randomized study of health insur-ance, and the only study which can give definitive evidence as to the causal effects of different healthinsurance plans. [...] Although the fieldwork of the study was conducted between 1974 and 1982,the results are still highly relevant, since RAND HIE is the only study which can make causal state-ments.’ (Wikipedia, RAND Health Insurance Experiment, http://en.wikipedia.org/w/index.php?title=RAND_Health_Insurance_Experiment\&oldid=110166949, ac-cessed April 8, 2007).

Usage

data(RandHIE)

Format

This data frame contains the following columns:

plan HIE plan number.

site Participant’s place of residence when the participant was initially enrolled.

coins Coinsurance rate.

tookphys Took baseline physical.

year Study year.

zper Person identifier.

black 1 if race of household head is black.

income Family income.

xage Age in years.

female 1 if person is female.

educdec Education of household head in years.

time Time eligible during the year.

outpdol Outpatient expenses: all covered outpatient medical services excluding dental care, out-patient psychotherapy, outpatient drugs or supplies.

drugdol Drug expenses: all covered outpatient and dental drugs.

suppdol Supply expenses: all covered outpatient supplies including dental.

mentdol Psychotherapy expenses: all covered outpatient psychotherapy services including injec-tions excluding charges for visits in excess of 52 per year, prescription drugs, and inpatientcare.

inpdol Inpatient expenses: all covered inpatient expenses in a hospital, mental hospital, or nursinghome, excluding outpatient care and renal dialysis.

Page 9: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

RandHIE 9

meddol Medical expenses: all covered inpatient and outpatient services, including drugs, supplies,and inpatient costs of newborns excluding dental care and outpatient psychotherapy.

totadm Hospital admissions: annual number of covered hospitalizations.inpmis Incomplete Hospital Records: missing inpatient records.mentvis Psychotherapy visits: indicates the annual number of outpatient visits for psychotherapy.

It includes billed visits only. The limit was 52 covered visits per person per year. The countincludes an initial visit to a psychiatrist or psychologist.

mdvis Face-to-Face visits to physicians: annual covered outpatient visits with physician providers(excludes dental, psychotherapy, and radiology/anesthesiology/pathology-only visits).

notmdvis Face-to-Face visits to nonphysicians: annual covered outpatient visits with nonphysicianproviders such as speech and physical therapists, chiropractors, podiatrists, acupuncturists,Christian Science etc. (excludes dental, healers, psychotherapy, and radiology/anesthesiology/pathology-only visits).

num Family size.mhi Mental health index.disea Number of chronic diseases.physlm Physical limitations.ghindx General health index.mdeoff Maximum expenditure offer.pioff Participation incentive payment.child 1 if age is less than 18 years.fchild female * child.lfam log of num (family size).lpi log of pioff (participation incentive payment).idp 1 if individual deductible plan.logc log(coins+1).fmde 0 if idp=1, ln(max(1,mdeoff/(0.01*coins))) otherwise.hlthg 1 if self-rated health is good – baseline is excellent self-rated health.hlthf 1 if self-rated health is fair – baseline is excellent self-rated health.hlthp 1 if self-rated health is poor – baseline is excellent self-rated health.xghindx ghindx (general healt index) with imputations of missing values.linc log of income (family income).lnum log of num (family size).lnmeddol log of meddol (medical expenses).binexp 1 if meddol > 0.

Source

Data sets of Cameron and Trivedi (2005), http://cameron.econ.ucdavis.edu/mmabook/mmadata.html.

Additional information of variables from Table 20.4 of Cameron and Trivedi (2005) and from New-house (1999).

Page 10: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

10 activePar

References

Cameron, A. C. and Trivedi, P. K. (2005) Microeconometrics: Methods and Applications, Cam-bridge University Press.

Newhouse, J. P. (1999) RAND Health Insurance Experiment [in Metropolitan and Non-MetropolitanAreas of the United States], 1974–1982, ICPSR Inter-university Consortium for Political and SocialResearch, Aggregated Claims Series, Volume 1: Codebook for Fee-for-Service Annual Expendi-tures and Visit Counts, ICPSR 6439.

Wikipedia, RAND Health Insurance Experiment, http://en.wikipedia.org/wiki/RAND_Health_Insurance_Experiment.

activePar free parameters under maximisation

Description

Return a logical vector, indicating which parameters were free under maximisation, as opposed tothe fixed parameters, treated as constants.

Usage

activePar(x, ...)## Default S3 method:activePar(x, ...)

Arguments

x object, created by a maximisation routine, or derived from a maximisation ob-ject. Currently only maxNR and it’s derivations support activePar

... further arguments for methods

Details

Several optimisation routines allow the user to fix some parameter values (or do it automaticallyin some cases). For gradient or Hessian based inference one has to know which parameters carryoptimisation-related information.

Value

A logical vector, indicating whether the parameters were free to change during optimisation algo-rithm.

Author(s)

Ott Toomet, 〈[email protected]

Page 11: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

aidsBestA0 11

See Also

maxNR, nObs

Examples

# a simple two-dimensional exponential hatf <- function(a) exp(-a[1]^2 - a[2]^2)## maximize wrt. both parametersfree <- maxNR(f, start=1:2)summary(free) # results should be close to (0,0)activePar(free)# allow only the second parameter to varycons <- maxNR(f, start=1:2, activePar=c(FALSE,TRUE))summary(cons) # result should be around (1,0)activePar(cons)

aidsBestA0 Find ’best’ Value for alpha 0 in the AIDS

Description

Search for the intercept of the translog price index (α0) that gives the best fit to the Almost IdealDemand System (see Michalek and Keyzer, 1992)

Usage

aidsBestA0( priceNames, shareNames, totExpName,data = NULL, instNames = NULL, shifterNames = NULL, method = "IL:L",a0min = -50, a0max = 50, stoprange = 3, stopiter = 10,verbose = FALSE, ... )

Arguments

priceNames a vector of strings containing the names of the prices.

shareNames a vector of strings containing the names of the expenditure shares.

totExpName a string containing the variable name of total expenditure.

data a data frame containing the data.

instNames an optional vector of strings containing the names of the instrumental variables.

shifterNames an optional vector of strings containing the names of the demand shifters.

method the method to estimate the aids (see aidsEst).

a0min lower limit of the range for searching for α0.

a0max upper limit of the range for searching for α0.

stoprange stop searching when the search interval is smaller than or equal to stoprange.

stopiter maximal number of iterations.

Page 12: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

12 aidsBestA0

verbose print each determinant of the residual covariance matrix immediately after itscalculation.

... arguments passed to aidsEst.

Details

The demand system is estimated using the Iterative Linear Least Squares Estimator (ILLE) sug-gested by Blundell and Robin (1999). This iterative procedure is equivalent to the method proposedby Michalek and Keyzer (1992). However, the latter do not correct the coefficient covariance ma-trix.

The fit of the model is measured in terms of the likelihood value. Since the determinant of theresidual covariance matrix is monotonically decreasing with the likelihood value, we search for thesmallest determinant of the residual covariance matrix.

Since each call of aidsEst generally takes a long time, the search algorithm is constructed tominimize the calls of the function aidsEst.

Value

a list containing following objects:

alpha0 α0 that gives the best fit.

allValues all α0 values that have been tested and the determinants of the correspondingresidual covariance matrices.

iter number of iterations.

Author(s)

Arne Henningsen 〈[email protected]

References

Blundell, R. and J.M. Robin (1999) Estimationin Large and Disaggregated Demand Systems: AnEstimator for Conditionally Linear Systems. Journal of Applied Econometrics, 14, p. 209-232.

Deaton, A.S. and J. Muellbauer (1980) An Almost Ideal Demand System. American EconomicReview, 70, p. 312-326.

Michalek, J. and M. A. Keyzer (1992) Estimation of a two-stage LES-AIDS consumer demandsystem for eight EC countries. European Review of Agricultural Economics, 19 (2), p. 137-163.

See Also

aidsEst

Examples

data( Blanciforti86 )# Data on food consumption are available only for the first 32 yearsBlanciforti86 <- Blanciforti86[ 1:32, ]

Page 13: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

aidsCalc 13

bestA0 <- aidsBestA0( c( "pFood1", "pFood2", "pFood3", "pFood4" ),c( "wFood1", "wFood2", "wFood3", "wFood4" ), "xFood",data = Blanciforti86, method = "IL:L" ) # may take some time

print( bestA0$alpha0 )plot( bestA0$allValues ) # this should be convex

aidsCalc Shares and Quantities of the Almost Ideal Demand System

Description

Given prices, total expenditure and coefficients this function calculates the demanded quantities andexpenditure shares based on the Almost Ideal Demand System.

Usage

aidsCalc( priceNames, totExpName, data = NULL, px = "TL", lnp = NULL,coef = NULL, alpha0 = ifelse( is.null( coef$alpha0 ), 0,coef$alpha0 ) )

Arguments

priceNames a vector of strings containing the names of the prices.

totExpName a string containing the variable name of total expenditure.

data a data frame containing the data.

px prices index (see aidsPx).

lnp log of the price index (only required if ’px’ is not ’TL’).

coef a list containing the coefficients alpha, beta and gamma.

alpha0 coefficient α0 of the translog price index.

Value

aidsCalc returns a list with following elements:

shares a data frame containing the calculated expenditure shares.

quantities a data frame containing the calculated quantites.

Author(s)

Arne Henningsen 〈[email protected]

References

Deaton, A.S. and J. Muellbauer (1980) An Almost Ideal Demand System. American EconomicReview, 70, p. 312-326.

Page 14: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

14 aidsElas

See Also

aidsEst, aidsPx

Examples

data( Blanciforti86 )# Data on food consumption are available only for the first 32 yearsBlanciforti86 <- Blanciforti86[ 1:32, ]

priceNames <- c( "pFood1", "pFood2", "pFood3", "pFood4" )shareNames <- c( "wFood1", "wFood2", "wFood3", "wFood4" )

## LA-AIDSestResult <- aidsEst( priceNames, shareNames, "xFood",

data = Blanciforti86, method = "LA:L" )

lnp <- aidsPx( "L", priceNames, shareNames, Blanciforti86 )

fitted <- aidsCalc( priceNames, "xFood", Blanciforti86,coef = estResult$coef, lnp = lnp )

fitted$shares # equal to estResult$wFittedfitted$quant # equal to estResult$qFitted

## AIDSestResult <- aidsEst( priceNames, shareNames, "xFood",

data = Blanciforti86, method = "IL:L" )

fitted <- aidsCalc( priceNames, "xFood", Blanciforti86,coef = estResult$coef )

fitted$shares # equal to estResult$wFittedfitted$quant # equal to estResult$qFitted

aidsElas Elasticities of the AIDS model

Description

These functions calculate and print the demand elasticities of an AIDS model.

Usage

aidsElas( coef, shares, prices = NULL, method = "AIDS",quantNames = NULL, priceNames = NULL, coefVcov = NULL, df = NULL )

## S3 method for class 'aidsEst':elas( object, method = NULL, ... )

Page 15: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

aidsElas 15

## S3 method for class 'aidsElas':print( x, ... )

Arguments

coef a list containing the coefficients alpha, beta and gamma.

shares a vector of the shares at which the elasticities should be calculated.

prices a vector of the prices at which the elasticities should be calculated (only neededif method ’AIDS’ is used).

method the elasticity formula to be used (see details).

quantNames an optional vector of strings containing the names of the quantities to label elas-ticities.

priceNames an optional vector of strings containing the names of the prices to label elastici-ties.

coefVcov variance covariance matrix of the coefficients (optional).

df degrees of freedom to calculate P-values of the elasticities (optional).

object an object of class aidsEst.

x an object of class aidsElas.

... additional arguments of elas.aidsEst are passed to aidsEla; additionalarguments of print.aidsElas are currently ignored.

Details

elas.aidsEst is a wrapper function to aidsElas that extracts the estimated coefficients(coef), mean expenditure shares (wMeans), mean prices (pMeans), names of the prices (priceNames),estimated coefficient variance covariance matrix (coef$allcov), and degrees of freedom (est$df)from the object of class aidsEst and passes them to aidsElas. If argument method inelas.aidsEst is not specified, the default value depends on the estimation method. If thedemand system was estimated by the linear approximation (LA), the default method is ’Ch’. Ifthe demand system was estimated by the iterative linear least squares estimator (ILLE), the defaultmethod is ’AIDS’.

At the moment the elasticity formulas of the orginal AIDS (AIDS), the formula of Goddard (1983)or Chalfant (1987) (Go or Ch), the formula of Eales and Unnevehr (1988) (EU), the formula ofGreen and Alston (1990) or the first of Buse (1994) (GA or B1) and the second formula of Buse(1994) (B2) are implemented.

The variance covariance matrices of the elasticities are calculated using the formula of Klein (1953,p. 258) (also known as the delta method). At the moment this is implemented only for the elasticityformulas of the orginal AIDS.

Value

a list of class aidsElas containing following elements:

method the elasticity formula used to calculate these elasticities.

Page 16: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

16 aidsElas

df degrees of freedom to calculate P-values of the elasticities (only if argument dfis provided).

exp vector of expenditure elasticities.

hicks matrix of Hicksian (compensated) price elasticities.

marshall matrix of Marshallian (uncompensated) price elasticities.

allVcov variance covariance matrix of all elasticities.

expVcov variance covariance matrix of the expenditure elasticities.

hicksVcov variance covariance matrix of the Hicksian (compensated) price elasticities.

marshallVcov variance covariance matrix of the Marshallian (uncompensated) price elastici-ties.

expStEr standard errors of the expenditure elasticities.

hicksStEr standard errors of the Hicksian (compensated) price elasticities.

marshallStEr standard errors of the Marshallian (uncompensated) price elasticities.

expTval t-values of the expenditure elasticities.

hicksTval t-values of the Hicksian (compensated) price elasticities.

marshallTval t-values of the Marshallian (uncompensated) price elasticities.

expPval P-values of the expenditure elasticities.

hicksPval P-values of the Hicksian (compensated) price elasticities.

marshallPval P-values of the Marshallian (uncompensated) price elasticities.

Author(s)

Arne Henningsen 〈[email protected]

References

Chalfant, J.A. (1987) A Globally Flexible, Almost Ideal Demand System. Journal of Business andEconomic Statistics, 5, p. 233-242.

Deaton, A.S. and J. Muellbauer (1980) An Almost Ideal Demand System. American EconomicReview, 70, p. 312-326.

Eales J.S. and L.J. Unnevehr (1988) Demand for beef and chicken products: separability and struc-tural change. American Journal of Agricultural Economics, 70, p. 521-532.

Klein L.R. (1953) A Textbook of Econometrics. Row, Petersen and Co., New York.

See Also

aidsEst

Page 17: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

aidsEst 17

Examples

data( Blanciforti86 )# Data on food consumption are available only for the first 32 yearsBlanciforti86 <- Blanciforti86[ 1:32, ]

estResult <- aidsEst( c( "pFood1", "pFood2", "pFood3", "pFood4" ),c( "wFood1", "wFood2", "wFood3", "wFood4" ), "xFood",data = Blanciforti86, method = "LA:L" )

wMeans <- colMeans( Blanciforti86[ , c( "wFood1", "wFood2","wFood3", "wFood4" ) ] )

aidsElas( estResult$coef, wMeans, method = "Ch" )

## Repeating the evaluation of different elasticity formulas of## Green & Alston (1990)priceNames <- c( "pFood1", "pFood2", "pFood3", "pFood4" )shareNames <- c( "wFood1", "wFood2", "wFood3", "wFood4" )

# AIDS estimation and elasticitiesestResultA <- aidsEst( priceNames, shareNames, "xFood",

data = Blanciforti86[ -1, ],method = "IL:L", maxiter = 100 )

diag( elas( estResultA, method = "AIDS" )$marshall )

# LA-AIDS estimationestResultLA <- aidsEst( priceNames, shareNames, "xFood",

data = Blanciforti86, method = "LA:SL", maxiter = 100 )

# LA-AIDS + formula of AIDSdiag( elas( estResultLA, method = "AIDS" )$marshall )

# LA-AIDS + formula of Eales + Unnevehrdiag( elas( estResultLA, method = "EU" )$marshall )

# LA-AIDS + formula of Goddard or Chalfant:diag( elas( estResultLA, method = "Go" )$marshall )diag( elas( estResultLA, method = "Ch" )$marshall )

# LA-AIDS + formula of Green + Alston (= 1st of Buse):diag( elas( estResultLA, method = "GA" )$marshall )

aidsEst Estimating the Almost Ideal Demand System (AIDS)

Description

aidsEst does an econometric estimation of the Almost Ideal Demand System (AIDS)

Page 18: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

18 aidsEst

Usage

aidsEst( priceNames, shareNames, totExpName, data = NULL,instNames = NULL, shifterNames = NULL,method = "LA:L", hom = TRUE, sym = TRUE, pxBase,estMethod = ifelse( is.null( instNames ), "SUR", "3SLS" ),ILmaxiter = 50, ILtol = 1e-5, alpha0 = 0, TX = FALSE, ... )

## S3 method for class 'aidsEst':print( x, ... )

Arguments

priceNames a vector of strings containing the names of the prices.

shareNames a vector of strings containing the names of the expenditure shares.

totExpName a string containing the variable name of total expenditure.

data a data frame containing the data.

instNames a vector of strings containing the names of instrumental variables.

shifterNames an optional vector of strings containing the names of the demand shifters.

method the method to estimate the AIDS (see details).

hom logical. Should the homogeneity condition be imposed?

sym logical. Should the symmetry condition be imposed?

pxBase The base to calculate the LA-AIDS price indices (see aidsPx).

estMethod estimation method (e.g. ’SUR’ or ’3SLS’, see systemfit).

ILmaxiter maximum number of iterations of the ’Iterated Linear Least Squares Estima-tion’.

ILtol tolerance level of the ’Iterated Linear Least Squares Estimation’.

alpha0 the intercept of the translog price index (α0).

TX logical. Method to impose homogeneity and symmetry restrictions: either viaR.restr (default) or via TX (see systemfit).

x An object of class aidsEst.

... additional arguments of aidsEst are passed to systemfit; additional argu-ments of print.aidsEst are currently ignored.

Details

At the moment two basic estimation methods are available: The ’Linear Approximate AIDS’ (LA)and the ’Iterative Linear Least Squares Estimator’ (IL) proposed by Blundell and Robin (1999).The LA-AIDS can be estimated with

• Stone price index (’LA:S’),

• Stone price index with lagged shares (’LA:SL’),

• loglinear analogue to the Paasche price index (’LA:P’),

• loglinear analogue of the Laspeyres price index (’LA:L’), and

Page 19: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

aidsEst 19

• Tornqvist price index (’LA:T’).

The ’Iterative Linear Least Squares Estimator’ (IL) needs starting values for the (translog) priceindex. The price index used to calculate the initial price index can be specified in the same way asfor the LA-AIDS (e.g. ’IL:L’)

Value

a list of class aidsEst containing following objects:

coef a list containing the vectors/matrix of the estimated coefficients (alpha, beta, andgamma).

r2 R2-values of all share equations.

r2q R2-values of the estimated quantities.

wFitted fitted expenditure shares.

wResid residuals of the expenditure shares.

qObs observed quantities / quantitiy indices.

qFitted fitted quantities / quantitiy indices.

qResid residuals of the estimated quantities.

iter iterations of SUR/3SLS estimation(s). If the AIDS is estimated by the ’IteratedLinear Least Squares Estimator’ (ILLE): a vector containing the SUR/3SLS it-erations at each iteration.

ILiter number of iterations of the ’Iterated Linear Least Squares Estimation’.

method the method used to estimate the aids (see details).

lnp log of the price index used for estimation.

hom logical. Was the homogeneity condition imposed?

sym logical. Was the symmetry condition imposed?

estMethod estimation method (see systemfit).

rcovformula formula used to calculate the estimated residual covariance matrix (see systemfit).

pMeans means of the prices.

wMeans means of the expenditure shares.

call the call of aidsEst.

priceNames names of the prices.

shareNames names of the expenditure shares.

totExpName name of the variable for total expenditure.

Author(s)

Arne Henningsen 〈[email protected]

Page 20: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

20 aidsPx

References

Deaton, A.S. and J. Muellbauer (1980) An Almost Ideal Demand System. American EconomicReview, 70, p. 312-326.

Blundell, R. and J.M. Robin (1999) Estimationin Large and Disaggregated Demand Systems: AnEstimator for Conditionally Linear Systems. Journal of Applied Econometrics, 14, p. 209-232.

See Also

summary.aidsEst, aidsElas, aidsCalc.

Examples

# Using data published in Blanciforti, Green & King (1986)data( Blanciforti86 )# Data on food consumption are available only for the first 32 yearsBlanciforti86 <- Blanciforti86[ 1:32, ]

## Repeating the demand analysis of Blanciforti, Green & King (1986)## Note: Blanciforti, Green & King (1986) use scaled data,## which leads to slightly different resultsestResult <- aidsEst( c( "pFood1", "pFood2", "pFood3", "pFood4" ),

c( "wFood1", "wFood2", "wFood3", "wFood4" ), "xFood",data = Blanciforti86, method = "LA:SL", maxiter = 100 )

print( estResult )elas( estResult )

## Estimations with a demand shifter: linear trendpriceNames <- c( "pFood1", "pFood2", "pFood3", "pFood4" )shareNames <- c( "wFood1", "wFood2", "wFood3", "wFood4" )Blanciforti86$trend <- c( 0:( nrow( Blanciforti86 ) - 1 ) )estResult <- aidsEst( priceNames, shareNames, "xFood",

data = Blanciforti86, shifterNames = "trend" )print( estResult )

# Estimations with two demand shifters: linear + quadratic trendBlanciforti86$trend2 <- c( 0:( nrow( Blanciforti86 ) - 1 ) )^2estResult <- aidsEst( priceNames, shareNames, "xFood",

data = Blanciforti86, shifterNames = c( "trend", "trend2" ) )print( estResult )

aidsPx Price Index for the AIDS

Description

Calculate log price indices for the AIDS and LA-AIDS.

Page 21: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

aidsPx 21

Usage

aidsPx( px, priceNames, shareNames = NULL, data = NULL, base = 1, coef = NULL,alpha0 = ifelse( is.null( coef$alpha0 ), 0, coef$alpha0 ) )

Arguments

px the price index to be used (see details).priceNames a vector of strings containing the names of the prices.shareNames a vector of strings containing the names of the expenditure shares.data a data frame containing the data.base the base to calculate the indices (see details).coef a list containing the coefficients alpha, beta and gamma (only needed for the

translog price index).alpha0 coefficient α0 of the translog price index.

Details

Currently 6 different price indices are implemented:

• translog price index (’TL’),• Stone price index (’S’),• Stone price index with lagged shares (’SL’),• loglinear analogue to the Paasche price index (’P’),• loglinear analogue of the Laspeyres price index (’L’), and• Tornqvist price index (’T’).

The argument base can be either

• a single number: the row number of the base prices and quantities,• a vector indicating several observations: The means of these observations are used as base

prices and quantities, or• a logical vector with the same length as the data: The means of the observations indicated

as ’TRUE’ are used as base prices and quantities.

Value

a vector containing the log price index.

Author(s)

Arne Henningsen 〈[email protected]

References

Deaton, A.S. and J. Muellbauer (1980) An Almost Ideal Demand System. American EconomicReview, 70, p. 312-326.

Moschini, G. (1995) Units of Measurement and the Stone Index in Demand System Estimation.American Journal of Agricultural Economics, 77, p. 63-68.

Page 22: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

22 aidsTestConsist

See Also

aidsEst

Examples

data( Blanciforti86 )aidsPx( "S", c( "pFood1", "pFood2", "pFood3", "pFood4" ),

c( "wFood1", "wFood2", "wFood3", "wFood4" ), Blanciforti86 )

aidsTestConsist Consistency Test of the AIDS

Description

Test whether the specification of the AIDS is consistent with microeconomic demand theory (i.e.utility maximisation).

Usage

aidsTestConsist( priceNames, shareNames, totExpName, data, coef = NULL,alpha0 = ifelse( is.null( coef$alpha0 ), 0, coef$alpha0 ) )

## S3 method for class 'aidsEst':testConsist( object, ... )

Arguments

priceNames a vector of strings containing the names of the prices.

shareNames a vector of strings containing the names of the expenditure shares.

totExpName a string containing the variable name of total expenditure.

data a data frame containing the data.

coef a list containing the coefficients alpha, beta and gamma.

alpha0 coefficient α0 of the translog price index.

object an object of class aidsEst.

... currently not used.

Details

testConsist.aidsEst is a wrapper function to aidsTestConsist that extracts all rele-vant arguments for aidsTestConsist from object.

Page 23: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

aidsTestConsist 23

Value

a list containing following elements:

monotony a logical vector indicating whether the monotony condition is fulfilled at eachobservation.

mPercent percent of observations where the monotony condition is fulfilled.

concavity a logical vector indicating whether the concavity condition is fulfilled at eachobservation.

cPercent percent of observations where the concavity condition is fulfilled.

cMatrices a list of the ’C’ matrices for each observation to check for concavity (see Deatonand Muellbauer, 1980b, p.76 ).

Author(s)

Arne Henningsen 〈[email protected]

References

Deaton, A.S. and J. Muellbauer (1980a) An Almost Ideal Demand System. American EconomicReview, 70, p. 312-326.

Deaton, A.S. and J. Muellbauer (1980b) Economics and Consumer Behavior, Cambridge UniversityPress, Cambridge.

See Also

aidsEst, aidsElas

Examples

data( Blanciforti86 )# Data on food consumption are available only for the first 32 yearsBlanciforti86 <- Blanciforti86[ 1:32, ]

priceNames <- c( "pFood1", "pFood2", "pFood3", "pFood4" )shareNames <- c( "wFood1", "wFood2", "wFood3", "wFood4" )

estResult <- aidsEst( priceNames, shareNames, "xFood",data = Blanciforti86, method = "IL:L" )

tc <- aidsTestConsist( priceNames, shareNames, "xFood", Blanciforti86,coef = estResult$coef )

tc$mPercent # great!tc$cPercent # Oh, that is bad!

# the same can be obtained in an easier waytestConsist.aidsEst( estResult )

Page 24: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

24 coef.selection

coef.selection Extract Coefficients from Selection Models

Description

This function extracts coefficients from sample selection models

Usage

## S3 method for class 'selection':coef(object, part = "full", ...)## S3 method for class 'summary.selection':coef(object, part = "full", ...)

Arguments

object object of class selection or summary.selection.

part character string indication which parts to extract: "full" for all estimated param-eters (selection estimates, outcome estimates, error variance and correlation) or"outcome" for the outcome estimates only (including the coefficient of the in-verse Mill’s ratio in case of a two-step estimation).

... currently not used.

Value

coef.selection returns a vector of the estimated coefficients.

coef.summary.selection returns a matrix of the estimated coefficients, their standard errors,t-values, and p-values.

Author(s)

Arne Henningsen 〈[email protected]〉, Ott Toomet (〈[email protected]〉)

See Also

coefficients, selection, summary.selection, and vcov.selection

Examples

## Estimate a simple female wage model taking into account the labour## force participation

data(Mroz87)a <- heckit(lfp ~ huswage + kids5 + mtr + fatheduc + educ + city,

log(wage) ~ educ + city, data=Mroz87)## extract all coefficients of the model:coef( a )

## now extract the coefficients of the outcome model only:

Page 25: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

coefTable 25

coef( a, part="outcome")

## extract all coefficients, standard errors, t-values## and p-values of the model:coef( summary( a ) )

## now extract the coefficients, standard errors, t-values## and p-values of the outcome model only:coef( summary( a ), part="outcome")

coefTable Coefficient Table

Description

Generate Table for Coefficients, Std. Errors, t-values and P-values.

Usage

coefTable( coef, stdErr, df = NULL )

Arguments

coef vector that contains the coefficients.

stdErr vector that contains the standard errors of the coefficients.

df degrees of freedom of the t-test used to calculate P-values.

Value

a matrix with 4 columns: coefficients, standard errors, t-values and P-values. If argument df is notprovided, the last column (P-values) is filled with NAs.

Author(s)

Arne Henningsen 〈[email protected]

Examples

coefTable( rnorm( 10 ), 0.5 * abs( rnorm( 10 ) ), 20 )

Page 26: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

26 compareDerivatives

compareDerivatives function to compare analytic and numeric derivatives

Description

This function compares analytic and numerical derivative and prints a few diagnostics. It is intendedfor testing pre-programmed derivative routines for maximisation algorithms.

Usage

compareDerivatives(f, grad, hess=NULL, t0, eps=1e-6, ...)

Arguments

f function to be differentiated. The parameter (vector) of interest must be the firstargument. The function may return a vector.

grad function returning the analytic gradient. Must use the same set of parameters asf. If f is a vector-valued function, grad must return a matrix where the numberof rows equals the number of components of f, and the number of columns mustequal to the number of components in t0.

hess function returning the analytic hessian. If present, hessian matrices are com-pared too. Only appropriate for scalar-valued functions.

t0 parameter vector indicating the point at which the derivatives are compared. Thederivative is taken with respect to this vector.

eps numeric. Step size for numeric differentiation. Central derivative is used.

... further arguments to f, grad and hess.

Details

For every component of f, the parameter value, analytic and numeric derivative and their rela-tive difference (analytic - numeric)/analytic are printed. If analytic derivatives are correct and thefunction is sufficiently smooth, expect the relative differences to be less than 1e-7.

Author(s)

Ott Toomet 〈[email protected]

See Also

numericGradient

Page 27: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

elas 27

Examples

## A simple example with sin(x)' = cos(x)f <- sincompareDerivatives(f, cos, t0=1)#### Example of log-likelihood of normal density. Two-parameter## function.x <- rnorm(100, 1, 2) # generate rnorm xl <- function(b) sum(log(dnorm((x-b[1])/b[2])/b[2]))

# b[1] - mu, b[2] - sigmagradl <- function(b) {c(sum(x - b[1])/b[2]^2,sum((x - b[1])^2/b[2]^3 - 1/b[2]))}compareDerivatives(l, gradl, t0=c(1,2))

elas Calculating and returning elasticities

Description

These functions calculate and return elasticities of microeconomic models. elasticities is analias for elas.

Usage

elas( object, ... )elasticities( object, ... )## Default S3 method:elas( object, ... )

Arguments

object a microeconomic model

... further arguments for methods

Details

This is a generic function. The default method just returns the element elas from object.

Author(s)

Arne Henningsen, 〈[email protected]

See Also

elas.aidsEst

Page 28: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

28 heckit2fit

germanFarms Output and Inputs of Farms in West-Germany

Description

The germanFarms data frame contains annual data of an average full-time farm in West-Germany.Additionally, the price indices for agricultural output and agricultural variable input are included.20 book-keeping years are included - starting in 1975/76 and ending in 1994/95.

Usage

data(germanFarms)

Format

This data frame contains the following columns:

year the book-keeping year.

vOutput the value of Outputs (in current Deutschmark).

pOutput price index of agricultural outputs (1980/81 = 100).

vVarInput the value of variable inputs (in current Deutschmark).

pVarInput price index of variable agricultural inputs (1980/81 = 100).

qLabor the number of full-time worker equivalents.

pLabor costs of an agricultural worker (Deutschmarks per year).

land land used for agricultural production (in ha).

Source

Bundesministerium für Ernährung, Landwirtschaft und Forsten (Federal Department for Food, Agri-culture and Forests), Agrarbericht der Bundesregierung (Agricultural Report of the Federal Gov-ernment), Jahrgänge 1977-1996 (years 1977-1996).

heckit2fit 2-step Heckman (heckit) estimation

Description

These functions do the actual fitting of tobit-2 (sample selection) and tobit-5 (switching regression)models by the 2-step Heckman (heckit) estimation. They are called by selection or heckitand they are intended for micEcon internal use.

Page 29: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

heckit2fit 29

Usage

heckit2fit( selection, outcome, data, inst = NULL, print.level = 0, ... )

heckit5fit( selection, outcome1, outcome2, data = sys.frame(sys.parent()),ys = FALSE, yo = FALSE, xs = FALSE, xo = FALSE, mfs = FALSE,mfo = FALSE, print.level = 0, ... )

Arguments

selection formula for the probit estimation (1st step) (see details).

outcome formula to be estimated (2nd step).

outcome1 formula, the first outcome equation.

outcome2 formula, the second outcome equation.

data a data frame containing the data.

inst an optional one-sided formula specifying instrumental variables for a 2SLS/IVestimation on the 2nd step.

ys, yo, xs, xo, mfs, mfologicals. If true, the response (y), model matrix (x) or the model frame (mf) ofthe selection (s) or outcome (o) equation(s) are returned.

print.level numeric, values greater than 0 will produce increasingly more debugging infor-mation.

... currently not used.

Value

see selection.

Author(s)

Arne Henningsen 〈[email protected]〉, Ott Toomet 〈[email protected]

References

see selection.

See Also

selection, heckit

Page 30: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

30 heckitVcov

heckitVcov Heckit Variance Covariance Matrix

Description

Calculate Variance Covariance Matrix for Heckit Estimations.

Usage

heckitVcov( xMat, wMat, vcovProbit, rho, delta, sigma,saveMemory = TRUE )

Arguments

xMat model matrix of the 2nd step estimation.

wMat model matrix of the 1st step probit estimation.

vcovProbit variance covariance matrix of the 1st step probit estimation.

rho the estimated ρ, see Greene (2003, p. 784).

delta the estimated δs, see Greene (2003, p. 784).

sigma the estimated σ, see Greene (2003, p. 784).

saveMemory logical. Save memory by using a different implementation of the formula? (thisshould not influence the results).

Value

the variance covariance matrix of the coefficients.

Author(s)

Arne Henningsen 〈[email protected]

References

Greene, W. H. (2003) Econometric Analysis, Fifth Edition, Prentice Hall.

Lee, L., G. Maddala and R. Trost (1980) Asymetric covariance matrices of two-stage probit andtwo-stage tobit methods for simultaneous equations models with selectivity. Econometrica, 48, p.491-503.

See Also

heckit.

Page 31: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

hessian 31

hessian Hessian matrix

Description

This function extracts the Hessian of the M-estimator of statistical model. It should be supplied bythe underlying optimisation algorithm, possibly using approximations.

Usage

hessian(x, ...)## Default S3 method:hessian(x, ...)

Arguments

x a M-estimator based statistical model

... other arguments for methods

Value

A numeric matrix, the Hessian of the model at the estimated parameter values. If the maximum isflat, the Hessian is singular. In that case you may want to invert only the non-singular part of thematrix. You may also want to fix certain parameters (see activePar).

Author(s)

Ott Toomet, 〈[email protected]

See Also

maxLik, activePar

Examples

# log-likelihood for normal density# a[1] - mean# a[2] - standard deviationll <- function(a) sum(-log(a[2]) - (x - a[1])^2/(2*a[2]^2))x <- rnorm(1000) # sample from standard normalml <- maxLik(ll, start=c(1,1))# ignore eventual warnings "NaNs produced in: log(x)"summary(ml) # result should be close to c(0,1)hessian(ml) # How the Hessian looks likesqrt(-solve(hessian(ml))) # Note: standard deviations are on the diagonal## Now run the same example while fixing a[2] = 1mlf <- maxLik(ll, start=c(1,1), activePar=c(TRUE, FALSE))summary(mlf) # first parameter close to 0, the second exactly 1.0

Page 32: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

32 insertCol

hessian(mlf)# Now look at the Hessian. Note that the second component has is not# related to the curvature of the object function:sqrt(-solve(hessian(mlf))) # works in current case, although you may get

# warnings.# now invert only the free parameter part of the Hessiansqrt(-solve(hessian(mlf)[activePar(mlf), activePar(mlf)]))# gives the standard deviation for the mean

insertCol Insert Column into a Matrix

Description

Insert a new column into a matrix.

Usage

insertCol( m, c, v = NA )

Arguments

m matrix.

c column number where the new column should be inserted.

v optional values of the new column.

Value

a matrix with one more column than the provided matrix m.

Author(s)

Arne Henningsen 〈[email protected]

See Also

insertRow.

Examples

m <- matrix( 1:4, 2 )insertCol( m, 2, 5:6 )

Page 33: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

insertRow 33

insertRow Insert Row into a Matrix

Description

Insert a new row into a matrix.

Usage

insertRow( m, r, v = NA )

Arguments

m matrix.

r row number where the new row should be inserted.

v optional values for the new row.

Value

a matrix with one more row than the provided matrix m.

Author(s)

Arne Henningsen 〈[email protected]

See Also

insertCol.

Examples

m <- matrix( 1:4, 2 )insertRow( m, 2, 5:6 )

invMillsRatio Inverse Mill’s Ratio of probit models

Description

Calculates the ’Inverse Mill’s Ratios’ of univariate and bivariate probit models.

Usage

invMillsRatio( x, all = FALSE )

Page 34: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

34 invMillsRatio

Arguments

x probit model estimated by probit, glm or vglm.

all a logical value indicating whether the inverse Mill’s Ratios should be calculatedfor all observations.

Details

The formula to calculate the inverse Mill’s ratios for univariate probit models is taken from Greene(2003, p. 785), whereas the formulas for bivariate probit models are derived in Henning and Hen-ningsen (2005).

Value

A data frame that contains the Inverse Mill’s Ratios (IMR) and the delta values (see Greene, 2003,p. 784).

If a univariate probit estimation is provided, the variables IMR1 and IMR0 are the Inverse Mill’sRatios to correct for a sample selection bias of y = 1 and y = 0, respectively. Accordingly, ’delta1’and ’delta0’ are the corresponding delta values.

If a bivariate probit estimation is provided, the variables IMRa1, IMRa0, IMRb1, and IMRb0 arethe Inverse Mills Ratios to correct for a sample selection bias of y = 1 and y = 0 in equations ’a’ and’b’, respectively. Accordingly, ’deltaa1’, ’deltaa0’, ’deltab1’ and ’deltab0’ are the correspondingdelta values.

Author(s)

Arne Henningsen 〈[email protected]

References

Greene, W. H. (2003) Econometric Analysis, Fifth Edition, Prentice Hall.

Henning, C.H.C.A and A. Henningsen (2005) Modeling Price Response of Farm Households inImperfect Labor Markets in Poland: Incorporating Transaction Costs and Heterogeneity into a FarmHousehold Approach. Unpublished, University of Kiel, Germany.

Examples

## Wooldridge( 2003 ): example 17.5, page 590data(Mroz87)myProbit <- glm( lfp ~ nwifeinc + educ + exper + I( exper^2 ) + age +

kids5 + kids618, family = binomial( link = "probit" ), data=Mroz87 )Mroz87$IMR <- invMillsRatio( myProbit )$IMR1myHeckit <- lm( log( wage ) ~ educ + exper + I( exper^2 ) + IMR,

data = Mroz87[ Mroz87$lfp == 1, ] )

# using NO labor force participation as endogenous variableMroz87$nolfp <- 1 - Mroz87$lfpmyProbit2 <- glm( nolfp ~ nwifeinc + educ + exper + I( exper^2 ) + age +

kids5 + kids618, family = binomial( link = "probit" ), data=Mroz87 )all.equal( invMillsRatio( myProbit )$IMR1, invMillsRatio( myProbit2 )$IMR0 )

Page 35: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

invMillsRatio 35

# should be true

# example for bivariate probit## Not run:library( MASS )library( VGAM, pos = 1e7, warn.conflicts = FALSE )

nObs <- 10000

# error terms (trivariate normal)sigma <- symMatrix( c( 2, 0.7, 1.2, 1, 0.5, 1 ) )myData <- as.data.frame( mvrnorm( nObs, c( 0, 0, 0 ), sigma ) )names( myData ) <- c( "e0", "e1", "e2" )

# exogenous variables (indepently normal)myData$x0 <- rnorm( nObs )myData$x1 <- rnorm( nObs )myData$x2 <- rnorm( nObs )

# endogenous variablesmyData$y0 <- -1.5 + 0.8 * myData$x1 + myData$e0myData$y1 <- ( 0.3 + 0.4 * myData$x1 + 0.3 * myData$x2 + myData$e1 ) > 0myData$y2 <- ( -0.1 + 0.6 * myData$x1 + 0.7 * myData$x2 + myData$e2 ) > 0

# bivariate probit (using rhobit transformation)bProbit <- vglm( cbind( y1, y2 ) ~ x1 + x2, family = binom2.rho,

data = myData )summary( bProbit )

# bivariate probit (NOT using rhobit transformation)bProbit2 <- vglm( cbind( y1, y2 ) ~ x1 + x2, family = binom2.rho(

lrho = "identity" ), data = myData )summary( bProbit2 )

# inverse Mills Ratiosimr <- invMillsRatio( bProbit )imr2 <- invMillsRatio( bProbit2 )all.equal( imr, imr2, tolerance = .Machine$double.eps ^ 0.25)

# tests# E[ e0 | y1* > 0 & y2* > 0 ]mean( myData$e0[ myData$y1 & myData$y2 ] )mean( sigma[1,2] * imr$IMR11a + sigma[1,3] * imr$IMR11b, na.rm = TRUE )# E[ e0 | y1* > 0 & y2* <= 0 ]mean( myData$e0[ myData$y1 & !myData$y2 ] )mean( sigma[1,2] * imr$IMR10a + sigma[1,3] * imr$IMR10b, na.rm = TRUE )# E[ e0 | y1* <= 0 & y2* > 0 ]mean( myData$e0[ !myData$y1 & myData$y2 ] )mean( sigma[1,2] * imr$IMR01a + sigma[1,3] * imr$IMR01b, na.rm = TRUE )# E[ e0 | y1* <= 0 & y2* <= 0 ]mean( myData$e0[ !myData$y1 & !myData$y2 ] )mean( sigma[1,2] * imr$IMR00a + sigma[1,3] * imr$IMR00b, na.rm = TRUE )# E[ e0 | y1* > 0 ]

Page 36: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

36 invMillsRatio

mean( myData$e0[ myData$y1 ] )mean( sigma[1,2] * imr$IMR1X, na.rm = TRUE )# E[ e0 | y1* <= 0 ]mean( myData$e0[ !myData$y1 ] )mean( sigma[1,2] * imr$IMR0X, na.rm = TRUE )# E[ e0 | y2* > 0 ]mean( myData$e0[ myData$y2 ] )mean( sigma[1,3] * imr$IMRX1, na.rm = TRUE )# E[ e0 | y2* <= 0 ]mean( myData$e0[ !myData$y2 ] )mean( sigma[1,3] * imr$IMRX0, na.rm = TRUE )

# estimation for y1* > 0 and y2* > 0selection <- myData$y1 & myData$y2# OLS estimationols11 <- lm( y0 ~ x1, data = myData, subset = selection )summary( ols11 )# heckman type estimationheckit11 <- lm( y0 ~ x1 + IMR11a + IMR11b, data = cbind( myData, imr ),

subset = selection )summary( heckit11 )

# estimation for y1* > 0 and y2* <= 0selection <- myData$y1 & !myData$y2# OLS estimationols10 <- lm( y0 ~ x1, data = myData, subset = selection )summary( ols10 )# heckman type estimationheckit10 <- lm( y0 ~ x1 + IMR10a + IMR10b, data = cbind( myData, imr ),

subset = selection )summary( heckit10 )

# estimation for y1* <= 0 and y2* > 0selection <- !myData$y1 & myData$y2# OLS estimationols01 <- lm( y0 ~ x1, data = myData, subset = selection )summary( ols01 )# heckman type estimationheckit01 <- lm( y0 ~ x1 + IMR01a + IMR01b, data = cbind( myData, imr ),

subset = selection )summary( heckit01 )

# estimation for y1* <= 0 and y2* <= 0selection <- !myData$y1 & !myData$y2# OLS estimationols00 <- lm( y0 ~ x1, data = myData, subset = selection )summary( ols00 )# heckman type estimationheckit00 <- lm( y0 ~ x1 + IMR00a + IMR00b, data = cbind( myData, imr ),

subset = selection )summary( heckit00 )

# estimation for y1* > 0

Page 37: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

linearPredictors 37

selection <- myData$y1# OLS estimationols1X <- lm( y0 ~ x1, data = myData, subset = selection )summary( ols1X )# heckman type estimationheckit1X <- lm( y0 ~ x1 + IMR1X, data = cbind( myData, imr ),

subset = selection )summary( heckit1X )

# estimation for y1* <= 0selection <- !myData$y1# OLS estimationols0X <- lm( y0 ~ x1, data = myData, subset = selection )summary( ols0X )# heckman type estimationheckit0X <- lm( y0 ~ x1 + IMR0X, data = cbind( myData, imr ),

subset = selection )summary( heckit0X )

# estimation for y2* > 0selection <- myData$y2# OLS estimationolsX1 <- lm( y0 ~ x1, data = myData, subset = selection )summary( olsX1 )# heckman type estimationheckitX1 <- lm( y0 ~ x1 + IMRX1, data = cbind( myData, imr ),

subset = selection )summary( heckitX1 )

# estimation for y2* <= 0selection <- !myData$y2# OLS estimationolsX0 <- lm( y0 ~ x1, data = myData, subset = selection )summary( olsX0 )# heckman type estimationheckitX0 <- lm( y0 ~ x1 + IMRX0, data = cbind( myData, imr ),

subset = selection )summary( heckitX0 )## End(Not run)

linearPredictors Calculates linear predictors for different models

Description

Calculates the (unobservable) linear predictors for probability models.

Usage

linearPredictors(x, ...)

Page 38: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

38 loglikValue

Arguments

x model of an appropriate class

... other arguments depending on the method

Details

It is a generic function with a method for ’probit’.

Value

A matrix with nrow equal to the number of observations and one column: the linear predictors forobservations

Author(s)

Ott Toomet 〈[email protected]

Examples

data(Mroz87)Mroz87$kids <- ( Mroz87$kids5 + Mroz87$kids618 > 0 )a <- probit(lfp ~ kids + educ + hushrs + huseduc + huswage + mtr +motheduc, data=Mroz87)b <- linearPredictors(a)cor(Mroz87$lfp, b) # should be positive and highly significant

loglikValue Return the log likelihood value

Description

Return the log likelihood value. Objects should be models, estimated by Maksimum Likelihood, orother statistical models where the likelihood makes sense.

Usage

loglikValue(x, ...)

Arguments

x object, usually a model estimated with Maximum Likelihood

... additional arguments to methods

Details

The default method returns the component loglik

Page 39: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

maxBFGS 39

Value

A single numeric, log likelihood of the estimated model

Author(s)

Ott Toomet 〈[email protected]

See Also

maxLik

Examples

## We estimate a tobit-2 model and print the loglik valuelibrary(mvtnorm)N <- 500

vc <- diag(2)vc[2,1] <- vc[1,2] <- -0.7eps <- rmvnorm(N, rep(0, 2), vc)xs <- runif(N)ys <- xs + eps[,1] > 0xo <- runif(N)yo <- (xo + eps[,2])*(ys > 0)a <- selection(ys~xs, yo ~xo)

loglikValue(a) # this values is also printed by 'summary'

maxBFGS BFGS maximisation

Description

This function is a wrapper for optim where the arguments are compatible with maxNR

Usage

maxBFGS(fn, grad = NULL, hess=NULL, start, print.level = 0, iterlim = 200,tol = 1e-06, ... )

Arguments

fn function to be maximised. Must have the parameter vector as the first argument.In order to use numeric gradient and BHHH method, fn must return vector ofobservation-specific likelihood values. Those are summed by maxNR if neces-sary. If the parameters are out of range, fn should return NA. See details forconstant parameters.

Page 40: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

40 maxBFGS

grad gradient of the function. Must have the parameter vector as the first argument.If NULL, numeric gradient is used. For BHHH method it must return a matrix,where rows corresponds to the gradients of the observations. Note that this cor-responds to t(numericGradient(fn)), not numericGradient(fn).It is summed over observations in order to get a single gradient vector.

hess Hessian of the function. Not used by maxBFGS, for compatibility with maxNR.

start initial values for the parameters.

print.level a larger number prints more working information.

iterlim maximum number of iterations.

tol the absolute convergence tolerance (see optim).

... further arguments for fn and grad.

Value

Object of class "maximisation":

maximum value of fn at maximum.

estimate best set of parameters found.

gradient gradient at parameter value estimate.

hessian value of Hessian at optimum.

code integer. Success code, 0 is success (see optim).

message character string giving any additional information returned by the optimizer, orNULL.

iterations two-element integer vector giving the number of calls to fn and gr, respec-tively. This excludes those calls needed to compute the Hessian, if requested,and any calls to fn to compute a finite-difference approximation to the gradient.

type character string "BFGS maximisation".

Author(s)

Ott Toomet 〈[email protected]

See Also

optim, nlm, maxNR, maxBHHH.

Examples

# Maximum Likelihood estimation of the parameter of Poissonian distributionn <- rpois(100, 3)loglik <- function(l) n*log(l) - l - lfactorial(n)# we use numeric gradientsummary(maxBFGS(loglik, start=1))# you would probably prefer mean(n) instead of that ;-)# Note also that maxLik is better suited for Maximum Likelihood

Page 41: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

maxBHHH 41

maxBHHH BHHH maximisation

Description

This function is essentially maxNR where the hessian is approximated by the outer product of thegradient vectro. Only suitable for likelihood maximisation.

Usage

maxBHHH(fn, grad = NULL, hess=NULL, start, print.level = 0, iterlim = 100,...)

Arguments

fn log-likelihood function to be maximised, must have the parameter vector as thefirst argument and must return vector of observation-specific likelihood values.Those are summed for a single likelihood value. If the parameters are out ofrange, fn should return NA.

grad gradient of the log-likelihood function. Must have the parameter vector as thefirst argument. If NULL, numeric gradient is used. It must return a matrix, whererows corresponds to the gradient vectors of individual observations. This matrixis summed over observations in order to get a single gradient vector. It’s matrixproduct is used for approximation of the Hessian.

hess Hessian of the function. Not used by maxBHHH, for compatibility with maxNR.

start initial values for the parameters to be optimized over.

print.level a larger number prints more working information.

iterlim maximum number of iterations.

... further arguments for maxNR, fn and grad.

Details

maxBHHH uses information equality in order to approximate the Hessian of the log-likelihood func-tion. Hence we have to calculate log-likelihood and gradient by individual observations. Hessian isapproximated as sum of outer products of the gradients of individual observations, or, in the matrixform, -t(gradient) %*% gradient.

Value

Object of class "maximisation":

type Character string: "BHHH maximisation"

Plus the other components inherited from maxNR.

Page 42: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

42 maxLik

Warning

As maxBHHH uses likelihood-specific information equation, it is only suitable for maximising log-likelihood!

Author(s)

Ott Toomet 〈[email protected]

See Also

maxNR, maxBFGS, optim, nlm.

Examples

## ML estimation of exponential duration model:t <- rexp(100, 2)loglik <- function(theta) log(theta) - theta*tgradlik <- function(theta) 1/theta - t## Estimate with numeric gradient and hessiana <- maxBHHH(loglik, start=1, print.level=2)summary(a)## Estimate with analytic gradienta <- maxBHHH(loglik, gradlik, start=1)summary(a)

maxLik Maximum likelihood estimation

Description

This is just a wrapper for maximisation routines which return object of class "maxLik". Corre-sponding methods can correctly handle the likelihood-specific properties of the estimate includingthe fact that inverse of negative hessian is the variance-covariance matrix.

Usage

maxLik(logLik, grad = NULL, hess = NULL, start, method = "Newton-Raphson", ...)

Arguments

logLik log-likelihood function. Must have the parameter vector as the first argument.Must return either a single log-likelihood value or a numeric vector where eachcomponent is log-likelihood corresponding to individual observations.

grad gradient of log-likelihood. Must have the parameter vector as the first argu-ment. Must return either single gradient vector with length equal to the numberof parameters, or a matrix where each row corresponds to gradient vector ofindividual observations. If NULL, numeric gradient will be used.

Page 43: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

maxNR 43

hess hessian of log-likelihood. Must have the parameter vector as the first argument.Must return a square matrix. If NULL, numeric gradient will be used.

start numeric vector, initial value of parameters.

method maximisation method, currently either "Newton-Rapshon", "BFGS", or "BHHH".

... further arguments for the maximisation routine.

Value

object of class ’maxLik’ which inherits from class ’maximisation’. Components are identical tothose of class ’maximisation’, see maxNR.

Author(s)

Ott Toomet 〈[email protected]

See Also

maxNR, nlm and optim for different non-linear optimisation routines.

Examples

## ML estimation of exponential duration model:t <- rexp(100, 2)loglik <- function(theta) log(theta) - theta*tgradlik <- function(theta) 1/theta - thesslik <- function(theta) -100/theta^2## Estimate with numeric gradient and hessiana <- maxLik(loglik, start=1, print.level=2)summary(a)## Estimate with analytic gradient and hessiana <- maxLik(loglik, gradlik, hesslik, start=1)summary(a)

maxNR Newton-Raphson maximisation

Description

Unconstrained maximisation based on Newton-Raphson method.

Usage

maxNR(fn, grad = NULL, hess = NULL, start, print.level = 0,tol = 1e-06, gradtol = 1e-06, steptol = 1e-10, lambdatol = 1e-06,qrtol = 1e-10,iterlim = 15,constPar = NULL, activePar=rep(TRUE, nParam), ...)

Page 44: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

44 maxNR

Arguments

fn function to be maximised. It must return either a single number or a numericvector, which is summed (this is useful for BHHH method). If the parametersare out of range, fn should return NA. See details for constant parameters.

grad gradient of the function. If NULL, numeric gradient is used. It must return agradient vector, or matrix where columns correspond to individual parameters.The column sums are treated as gradient components (this is useful for BHHHmethod).

hess Hessian matrix of the function. If missing, numeric Hessian, based on gradient,is used.

start initial value for the parameter vector

print.level this argument determines the level of printing which is done during the mini-mization process. The default value of 0 means that no printing occurs, a valueof 1 means that initial and final details are printed and a value of 2 means thatfull tracing information for every iteration is printed. Higher values will resultin even more details.

tol stopping condition. Stop if the absolute difference between successive iterationsless than tol, return code=2.

gradtol stopping condition. Stop if the norm of the gradient less than gradtol, returncode=1.

steptol stopping/error condition. If the quadratic approximation leads to lower functionvalue instead of higher, or NA, the step length is halved and a new attempt ismade. This procedure is repeated until step < steptol, thereafter code=3 isreturned.

lambdatol control whether the Hessian is treated as negative definite. If the largest of theeigenvalues of the Hessian is larger than -lambdatol, a suitable diagonal ma-trix is subtracted from the Hessian (quadratic hill-climbing) in order to enforcenagetive definiteness.

qrtol QR-decomposition tolerance

iterlim stopping condition. Stop if more than iterlim iterations, return code=4.

constPar index vector. Which of the parameters must be treated as constants.

activePar logical vector, which parameters are treated as free (resp constant)

... further arguments to fn, grad and hess.

Details

The algorithm can work with constant parameters and related changes of parameter values. Constantparameters are useful if a parameter value is converging toward the boundary of support, or fortesting.

One way is to put constPar to non-NULL. Second possibility is to signal by fnwhich parametersare constant and change the values of the parameter vector. The value of fn may have followingattributes:

constPar index vector. Which parameters are redefined to constant

Page 45: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

maxNR 45

constVal numeric vector. Values for the constant parameters.

newVal a list with following components:

index which parameters will have a new value

val the new value of parameters

The difference between constVal and newVal is that the latter parameters are not set to con-stants. If the attribute newVal is present, the new function value is allowed to be below the previousone.

Value

list of class "maximisation" with following components:

maximum fn value at maximum (the last calculated value if not converged).

estimate estimated parameter value.

gradient last gradient value which was calculated. Should be close to 0 if normal conver-gence.

hessian Hessian at the maximum (the last calculated value if not converged).

code return code:

1 gradient close to zero (normal convergence).

2 successive function values within tolerance limit (normal convergence).

3 last step could not find higher value (probably not converged).

4 iteration limit exceeded.

100 Initial value out of range.

message a short message, describing code.

last.step list describing the last unsuccessful step if code=3with following components:

theta0 previous parameter value

f0 fn value at theta0

theta1 new parameter value. In most cases close to theta0.

activePar logical vector, which parameters are not constants.

iterations number of iterations.

type character string, type of maximisation.

Author(s)

Ott Toomet 〈[email protected]

References

W. Greene: "Advanced Econometrics"; S.M. Goldfeld, R.E. Quandt: "Nonlinear Methods in Econo-metrics". Amsterdam, North-Holland 1972.

Page 46: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

46 maximisationType

See Also

nlm for Newton-Raphson optimisation, optim for different gradient-based optimisation methods.

Examples

## ML estimation of exponential duration model:t <- rexp(100, 2)loglik <- function(theta) sum(log(theta) - theta*t)## Note the log-likelihood and gradient are summed over observationsgradlik <- function(theta) sum(1/theta - t)hesslik <- function(theta) -100/theta^2## Estimate with numeric gradient and Hessiana <- maxNR(loglik, start=1, print.level=2)summary(a)## You would probably prefer 1/mean(t) instead ;-)## Estimate with analytic gradient and Hessiana <- maxNR(loglik, gradlik, hesslik, start=1)summary(a)

maximisationType Type of minimisation/maximisation

Description

Returns the type of optimisation. It should be returned by the optimisation routine.

Usage

maximisationType(x)

Arguments

x object of class ’maximisation’ or another object which involves numerical opti-misation.

Value

A text message, describing the involved optimisation algorithm

Author(s)

Ott Toomet, 〈[email protected]

See Also

maxNR

Page 47: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

micEcon-deprecated 47

Examples

## maximise two-dimensional exponential hat. Maximum is at c(2,1):f <- function(a) exp(-(a[1] - 2)^2 - (a[2] - 1)^2)m <- maxNR(f, start=c(0,0))summary(m)maximisationType(m)## Now try BHHH maximisation. It shouldn't work but does.m <- maxBHHH(f, start=c(0,0))summary(m)maximisationType(m)

micEcon-deprecated Deprecated Functions in micEcon package

Description

These functions are provided for compatibility with older versions of micEcon only, and may bedefunct as soon as the next release.

Usage

tobit2(selection, formula, data = sys.frame(sys.parent()),method="ml",

start=NULL, print.level=0,y1=FALSE, z=FALSE, y2=FALSE, x=FALSE, model=FALSE,...)

Arguments

selection a symbolic formula for the selection equation. The response must be binaryvariable where 0 corresponds to invisibility of the outcome and 1 to visibility.

formula a symbolic formula for the equation of interest.data an optional data frame containing the variables in the model. By default the

variables are taken from environment(formula), typically the environment fromwhich the function is called

method the method of calculation: Maximum Likelihood ("ml") or Heckman 2-step("2step")

start numeric, initial values of the parameters. The order is as follows: gamma (se-lection equation), beta (the equation of interest), sigma, rho (distribution of theerror terms) for tobit2;

print.level information about calculations. 0 – nothing is printed, bigger numbers give moreinformation. print.level is sent further to the maximisation algorithm, seemaxNR.

y1, z, y2, x, modellogicals. If TRUE the corresponding components of the fit (the selection re-sponse, the selection model matrix, the equation response, the equation modelmatrix and both model frames) are returned.

... further arguments to the maximisation algorithm, see maxNR.

Page 48: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

48 nObs

Details

The original help page for these functions is often available at help("oldName-deprecated")(note the quotes).

Function tobit2 are for historical compatibility with old versions of micEcon. Use selectioninstead.

See Also

Deprecated, selection

micEcon-internal Internal micEcon Functions

Description

Internal micEcon Functions

Details

These are either various methods, or functions, not to be called directly by the user (or in somecases are just waiting for proper documentation to be written :).

nObs Return number of observations for statistical models

Description

Returns number of observations for statistical models. The default method assumes presence of acomponent $param$nObs in x.

Usage

nObs(x, ...)## Default S3 method:nObs(x, ...)## S3 method for class 'lm':nObs(x, ...)

Arguments

x a statistical model, such as created by lm

... further arguments for methods

Page 49: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

nParam 49

Details

This is a generic function. The default method returns the component x$param$nObs. The lm-method is based on qr-decomposition, in the same way as the does summary.lm.

Value

numeric, number of observations

Author(s)

Ott Toomet, 〈[email protected]

See Also

nParam

Examples

## Do a trivial probit example and find number of observationsx <- runif(100)y <- x + rnorm(100) > 0p <- probit(y ~ x)nObs(p)

nParam Number of model parameters

Description

This function returns the number of model parameters. The default method returns the componentx$param$nParam.

Usage

nParam(x, ...)## Default S3 method:nParam(x, ...)## S3 method for class 'lm':nParam(x, ...)

Arguments

x a statistical model

... other arguments for methods

Details

Not all parameters need to be free nor independent. The number may depend on the normalisation.

Page 50: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

50 numericGradient

Value

Number of parameters in the model

Author(s)

Ott Toomet, 〈[email protected]

See Also

nObs for number of observations

Examples

# Construct a simple OLS regression:x1 <- runif(100)x2 <- runif(100)y <- 3 + 4*x1 + 5*x2 + rnorm(100)m <- lm(y~x1+x2) # estimate itsummary(m)nParam(m) # you get 3

numericGradient Functions to Calculate Numeric Derivatives

Description

Calculate (central) numeric gradient and Hessian. numericGradient accepts vector-valuedfunctions.

Usage

numericGradient(f, t0, eps=1e-06, ...)numericHessian(f, grad=NULL, t0, eps=1e-06, ...)numericNHessian(f, t0, eps=1e-6, ...)

Arguments

f function to be differentiated. The first argument must be the parameter vectorwith respect to which it is differentiated.

grad function, gradient of f

t0 vector, the value of parameters

eps numeric, the step for numeric differentiation

... furter arguments for f

Page 51: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

numericGradient 51

Details

numericGradient numerically differentiates a (vector valued) function with respect to it’s (vec-tor valued) argument. If the functions value is a NVal * 1 vector and the argument is Npar *1 vector, the resulting gradient is a NVal * NPar matrix.

numericHessian checks whether a gradient function is present and calculates a gradient of thegradient (if present), or full numeric Hessian (numericNHessian) if not present.

Value

Matrix. For numericGradient, the number of rows is equal to the length of the function valuevector, and the number of columns is equal to the length of the parameter vector.

For the numericHessian, both numer of rows and columns is equal to the length of the param-eter vector.

Warning

Be careful when using numerical differentiation in optimisation routines. Although quite precise insimple cases, they may work very poorly in more complicated cases.

Author(s)

Ott Toomet 〈[email protected]

See Also

compareDerivatives, deriv

Examples

# A simple example with Gaussian bellf0 <- function(t0) exp(-t0[1]^2 - t0[2]^2)numericGradient(f0, c(1,2))numericHessian(f0, t0=c(1,2))

# An example with the analytic gradientgradf0 <- function(t0) -2*t0*f0(t0)numericHessian(f0, gradf0, t0=c(1,2))# The results should be similar as in the previous case

# The central numeric derivatives have usually quite a high precisioncompareDerivatives(f0, gradf0, t0=1:2)# The differenc is around 1e-10

Page 52: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

52 predict.snqProfitEst

predict.snqProfitEstPredictions from an SNQ profit function

Description

Returns the predicted values, their standard errors and the confidence limits of prediction for anSymmetric Normalized Quadratic (SNQ) profit function.

Usage

## S3 method for class 'snqProfitEst':predict( object, newdata = object$data,

se.fit = FALSE, se.pred = FALSE, interval = "none", level = 0.95, ... )

## S3 method for class 'snqProfitImposeConvexity':predict( object, newdata = object$data,

se.fit = FALSE, se.pred = FALSE, interval = "none", level = 0.95, ... )

Arguments

object an object of type snqProfitEst or snqProfitImposeConvexity.

newdata data frame in which to predict.

se.fit logical. Return the standard error of the fitted values?

se.pred logical. Return the standard error of prediction?

interval Type of interval calculation ("none", "confidence" or "prediction").

level confidence level.

... currently not used.

Details

The variance of the fitted values (used to calculate the standard errors of the fitted values and the"confidence interval") is calculated by V ar[E[y0] − y0] = x0 V ar[b] x0′

The variances of the predicted values (used to calculate the standard errors of the predicted valuesand the "prediction intervals") is calculated by V ar[y0 − y0] = σ2 + x0 V ar[b] x0′

Value

predict.snqProfitEst and predict.snqProfitImposeConvexity return a dataframethat contains the predicted profit and for each netput the predicted quantities (e.g. "quant1" ) andif requested the standard errors of the fitted values (e.g. "quant1.se.fit"), the standard errors of theprediction (e.g. "quant1.se.pred"), and the lower (e.g. "quant1.lwr") and upper (e.g. "quant1.upr")limits of the confidence or prediction interval(s).

Page 53: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

priceIndex 53

Author(s)

Arne Henningsen 〈[email protected]

References

Diewert, W.E. and T.J. Wales (1987) Flexible functional forms and global curvature conditions.Econometrica, 55, p. 43-68.

Diewert, W.E. and T.J. Wales (1992) Quadratic Spline Models for Producer’s Supply and DemandFunctions. International Economic Review, 33, p. 705-722.

Greene, W. H. (2003) Econometric Analysis, Fifth Edition, Macmillan.

Gujarati, D. N. (1995) Basic Econometrics, Third Edition, McGraw-Hill.

Kmenta, J. (1997) Elements of Econometrics, Second Edition, University of Michigan Publishing.

Kohli, U.R. (1993) A symmetric normalized quadratic GNP function and the US demand for im-ports and supply of exports. International Economic Review, 34, p. 243-255.

See Also

snqProfitEst, snqProfitCalc and predict

Examples

data( germanFarms )germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutputgermanFarms$qVarInput <- -germanFarms$vVarInput / germanFarms$pVarInputgermanFarms$qLabor <- -germanFarms$qLaborgermanFarms$time <- c( 0:19 )priceNames <- c( "pOutput", "pVarInput", "pLabor" )quantNames <- c( "qOutput", "qVarInput", "qLabor" )estResult <- snqProfitEst( priceNames, quantNames, c("land","time"), data=germanFarms )predict( estResult )predict( estResult, se.fit = TRUE, se.pred = TRUE, interval = "confidence" )

priceIndex Calculate Price Indices

Description

Calculates a Laspeyres, Paasche or Fisher price index.

Usage

priceIndex( prices, quantities, base, data, method = "Laspeyres",na.rm = FALSE, na.0 = FALSE, weights = FALSE )

Page 54: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

54 priceIndex

Arguments

prices Vector that contains the names of the prices.quantities Vector that contains the names of the quantities that belong to the prices.base The base period(s) to calculate the indices (see details).data Dataframe that contains the prices and quantities.method Which price index: "Laspeyres", "Paasche" or "Fisher".na.rm a logical value passed to ’mean()’ when calculating the base.na.0 logical. Setting all NA values to 0 (after calculating the base)?weights logical. Should an attribute ’weights’ that contains the relatives weights of each

quantity be added?

Details

The argument base can be either(a) a single number: the row number of the base prices and quantities,(b) a vector indicating several observations: The means of these observations are used as base pricesand quantities, or(c) a logical vector with the same length as the data: The means of the observations indicated as’TRUE’ are used as base prices and quantities.

Value

a vector containing the price indices.

Author(s)

Arne Henningsen 〈[email protected]

See Also

quantityIndex.

Examples

data( Missong03E7.7 )# Laspeyres Price IndicespriceIndex( c( "p.beef", "p.veal", "p.pork" ),

c( "q.beef", "q.veal", "q.pork" ), 1, Missong03E7.7 )# Paasche Price IndicespriceIndex( c( "p.beef", "p.veal", "p.pork" ),

c( "q.beef", "q.veal", "q.pork" ), 1, Missong03E7.7, "Paasche" )

data( Bleymueller79E25.1 )# Laspeyres Price IndicespriceIndex( c( "p.A", "p.B", "p.C", "p.D" ), c("q.A", "q.B", "q.C", "q.D" ),

1, Bleymueller79E25.1 )# Paasche Price IndicespriceIndex( c( "p.A", "p.B", "p.C", "p.D" ), c("q.A", "q.B", "q.C", "q.D" ),

1, Bleymueller79E25.1, "Paasche" )

Page 55: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

print.snqProfitEst 55

print.snqProfitEst Print output of estimated SNQ profit function

Description

This function prints a summary estimation results of a symmetric normalized quadraric (SNQ) profitfunction.

Usage

## S3 method for class 'snqProfitEst':print( x, ... )

Arguments

x an object of class snqProfitEst.

... arguments passed to print.

Author(s)

Arne Henningsen 〈[email protected]

See Also

snqProfitEst

Examples

## Not run: library( systemfit )data( germanFarms )germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutputgermanFarms$qVarInput <- -germanFarms$vVarInput / germanFarms$pVarInputgermanFarms$qLabor <- -germanFarms$qLaborpriceNames <- c( "pOutput", "pVarInput", "pLabor" )quantNames <- c( "qOutput", "qVarInput", "qLabor" )

estResult <- snqProfitEst( priceNames, quantNames, "land", data = germanFarms )print( estResult )

Page 56: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

56 probit

probit Probit binary choice model

Description

The functions calculates probit binary choice model

Usage

probit(formula, subset, start = NULL, data = sys.frame(sys.parent()),x=FALSE, y = FALSE, model = FALSE, method="ML", ... )

Arguments

formula a symbolic description of the model to be fit, in the form response ~ explanatoryvariables. The response variable should be either logical or numeric withvalues only 0-1 or a factor with two levels.

subset an optional vector specifying a subset of observations to be used in the fittingprocess.

start inital value of parameters.

data an optional data frame containing the variables in the model. If not found in data,the variables are taken from environment(formula), typically the environmentfrom which probit is called.

x, y, model logicals. If TRUE the corresponding components of the fit (the model matrix,the response, the model frame) are returned.

method the method to be used; for fitting, currently only method = "ML" (MaximumLikelihood) is supported; method = "model.frame" returns the model frame (thesame as with model = TRUE, see below).

... further arguments for maxLik.

Details

The model is estimated using Maximum Likelihood method.

Value

An object of class "probit". It is a list with following components:

LRT Likelihood ration test. The full model is tested against H0: the parameters haveno effect on the result. This is a list with components

LRT The LRT value

df Degrees of freedom for LRT (= df of the model - 1) LRT is distributed bychi2(df) under H0.

nParam Number of parameters of the model including constant

nObs Number of the observations

Page 57: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

quadFuncCalc 57

N1 Number of observations with non-zero (true) response

N0 Number of observations with zero (false) response

df Number of free parameters

x if requested, the model matrix used.

y if requested, the response used.

model the model frame, only if model = TRUE or method = "model.frame".

Other components are inherited from maxLik.

Author(s)

Ott Toomet 〈[email protected]

See Also

maxLik for ready-packaged likelihood maximisation routines and methods, glm for generalisedlinear models, including probit, binomial.

Examples

## A simple MC trial: note probit assumes normal errorsx <- runif(100)e <- 0.5*rnorm(100)y <- x + esummary(probit((y > 0) ~ x))## female labour force participation probabilitydata(Mroz87)Mroz87$kids <- Mroz87$kids5 > 0 | Mroz87$kids618 > 0Mroz87$age30.39 <- Mroz87$age < 40Mroz87$age50.60 <- Mroz87$age >= 50summary(probit(lfp ~ kids + age30.39 + age50.60 + educ + hushrs +

huseduc + huswage + mtr + motheduc, data=Mroz87))

quadFuncCalc Calculate dependent variable of a quadratic function

Description

Calculate the dependent variable of a quadratic function.

Usage

quadFuncCalc( xNames, data, allCoef, quadHalf = TRUE )

Page 58: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

58 quadFuncDeriv

Arguments

xNames a vector of strings containing the names of the independent variables.

data dataframe containing the data.

allCoef vector containing all coefficients.

quadHalf logical. Multiply the quadratic terms by one half?

Value

a vector containing the endogenous variable.

Author(s)

Arne Henningsen 〈[email protected]

See Also

quadFuncEst and quadFuncDeriv.

Examples

data( germanFarms )# output quantity:germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutput# quantity of variable inputsgermanFarms$qVarInput <- germanFarms$vVarInput / germanFarms$pVarInput# a time trend to account for technical progress:germanFarms$time <- c(1:20)

# estimate a quadratic production functionestResult <- quadFuncEst( "qOutput", c( "qLabor", "land", "qVarInput", "time" ),

germanFarms )

quadFuncCalc( c( "qLabor", "land", "qVarInput", "time" ), germanFarms,estResult$allCoef )

#equal to estResult$fitted

quadFuncDeriv Derivatives of a quadratic function

Description

Calculate the derivatives of a quadratic function.

Usage

quadFuncDeriv( xNames, data, allCoef, allCoefCov = NULL, quadHalf = TRUE )

Page 59: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

quadFuncDeriv 59

Arguments

xNames a vector of strings containing the names of the independent variables.

data dataframe containing the data.

allCoef vector containing all coefficients.

allCoefCov optional covariance matrix of the coefficients.

quadHalf logical. Multiply the quadratic terms by one half?

Value

a list of class quadFuncDeriv containing following objects:

deriv data frame containing the derivatives.

variance data frame containing the variances of the derivatives (only if argument allCoefCovis provided).

stdDev data frame containing the standard deviations of the derivatives (only if argu-ment allCoefCov is provided).

Author(s)

Arne Henningsen 〈[email protected]

See Also

quadFuncEst and quadFuncCalc

Examples

data( germanFarms )# output quantity:germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutput# quantity of variable inputsgermanFarms$qVarInput <- germanFarms$vVarInput / germanFarms$pVarInput# a time trend to account for technical progress:germanFarms$time <- c(1:20)

# estimate a quadratic production functionestResult <- quadFuncEst( "qOutput", c( "qLabor", "land", "qVarInput", "time" ),

germanFarms )

# compute the marginal products of the inputsmargProducts <- quadFuncDeriv( c( "qLabor", "land", "qVarInput", "time" ),

germanFarms, estResult$allCoef, estResult$allCoefCov )margProducts$deriv

Page 60: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

60 quadFuncEst

quadFuncEst Estimate a quadratic function

Description

Estimate a quadratic function.

Usage

quadFuncEst( yName, xNames, data, quadHalf = TRUE, exVarScale = 1 )

Arguments

yName a vector of strings containing the name of the dependent variable.

xNames a vector of strings containing the names of the independent variables.

data dataframe containing the data.

quadHalf logical. Multiply the quadratic terms by one half?

exVarScale a scalar or vector with length equal to nrow( data ). All exogenous variables(including the quadratic terms) are divided by this value/these values.

Value

a list of class quadFuncEst containing following objects:

lm a list returned by lm.

residuals residuals.

fitted fitted values.

coef a list containing the the estimated coefficients: alpha0 = α0 (scalar), alpha = αi

(vector), beta = βij (matrix).

allCoef vector of all coefficients.

allCoefCov Covariance matrix of all coefficients.

r2 R2 value.

r2bar adjusted R2 value.

nObs number of observations.

model.matrix the model matrix.

Author(s)

Arne Henningsen 〈[email protected]

See Also

quadFuncCalc, quadFuncDeriv, translogEst and snqProfitEst.

Page 61: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

quantityIndex 61

Examples

data( germanFarms )# output quantity:germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutput# quantity of variable inputsgermanFarms$qVarInput <- germanFarms$vVarInput / germanFarms$pVarInput# a time trend to account for technical progress:germanFarms$time <- c(1:20)

# estimate a quadratic production functionestResult <- quadFuncEst( "qOutput", c( "qLabor", "land", "qVarInput", "time" ),

germanFarms )

estResult$coefestResult$r2

quantityIndex Calculate Quantity Indices

Description

Calculates a Laspeyres, Paasche or Fisher Quantity index.

Usage

quantityIndex( prices, quantities, base, data, method = "Laspeyres",na.rm = FALSE, na.0 = FALSE, weights = FALSE )

Arguments

prices Vector that contains the names of the prices.quantities Vector that contains the names of the quantities that belong to the prices.base The base period(s) to calculate the indices (see details).data Dataframe that contains the prices and quantities.method Which quantity index: "Laspeyres", "Paasche" or "Fisher".na.rm a logical value passed to ’mean()’ when calculating the base.na.0 logical. Setting all NA values to 0 (after calculating the base)?weights logical. Should an attribute ’weights’ that contains the relatives weights of each

quantity be added?

Details

The argument base can be either(a) a single number: the row number of the base prices and quantities,(b) a vector indicating several observations: The means of these observations are used as base pricesand quantities, or(c) a logical vector with the same length as the data: The means of the observations indicated as’TRUE’ are used as base prices and quantities.

Page 62: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

62 quasiconcavity

Value

a vector containing the quantity indices.

Author(s)

Arne Henningsen 〈[email protected]

See Also

quantityIndex.

Examples

data( Missong03E7.7 )# Laspeyres Quantity IndicesquantityIndex( c( "p.beef", "p.veal", "p.pork" ),

c( "q.beef", "q.veal", "q.pork" ), 1, Missong03E7.7 )# Paasche Quantity IndicesquantityIndex( c( "p.beef", "p.veal", "p.pork" ),

c( "q.beef", "q.veal", "q.pork" ), 1, Missong03E7.7, "Paasche" )

data( Bleymueller79E25.1 )# Laspeyres Quantity IndicesquantityIndex( c( "p.A", "p.B", "p.C", "p.D" ), c("q.A", "q.B", "q.C", "q.D" ),

1, Bleymueller79E25.1 )# Paasche Quantity IndicesquantityIndex( c( "p.A", "p.B", "p.C", "p.D" ), c("q.A", "q.B", "q.C", "q.D" ),

1, Bleymueller79E25.1, "Paasche" )

quasiconcavity Test for quasiconcavity / quasiconvexity

Description

Test wether a function is quasiconcave or quasiconvex. The bordered Hessian of this function ischecked by quasiconcavity() or quasiconvexity().

Usage

quasiconcavity( m, tol = .Machine$double.eps )quasiconvexity( m, tol = .Machine$double.eps )

Arguments

m a bordered Hessian matrix or a list containing bordered Hessian matrices

tol tolerance level (values between -tol and tol are considered to be zero).

Page 63: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

rSquared 63

Value

locigal or a logical vector (if m is a list).

Author(s)

Arne Henningsen 〈[email protected]

References

Chiang, A.C. (1984) Fundamental Methods of Mathematical Economics, 3rd ed., McGraw-Hill.

Examples

quasiconcavity( matrix( 0, 3, 3 ) )

quasiconvexity( matrix( 0, 3, 3 ) )

m <- list()m[[1]] <- matrix( c( 0,-1,-1, -1,-2,3, -1,3,5 ), 3, 3 )m[[2]] <- matrix( c( 0,1,-1, 1,-2,3, -1,3,5 ), 3, 3 )

quasiconcavity( m )

quasiconvexity( m )

rSquared Calculate R squared value

Description

Calculate R squared value.

Usage

rSquared( y, resid )

Arguments

y vector of endogenous variables

resid vector of residuals

Author(s)

Arne Henningsen 〈[email protected]

Page 64: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

64 readFront41out

Examples

data( Blanciforti86 )reg <- lm( wFood1 ~ pFood1 + xFood, Blanciforti86 )rSquared( Blanciforti86$wFood1, reg$residuals )summary( reg )$r.squared # returns the same value

readFront41out Read output of Frontier 4.1

Description

Read the output file of Coelli’s program Frontier 4.1 that performs stochastic frontier analysis.

Usage

readFront41out( file = "front41.out", translog = FALSE )

Arguments

file character variable with the name of the file to read.translog logical. Is the estimated function a translog function? (not implemented yet).

Value

a list of class front41out containing following objects:

version the version of Frontier 4.1 that produced the output.insFile name of the instruction file used by Frontier 4.1.dtaFile name of the data file used by Frontier 4.1.modelType model type: either 1 for ’Error Components Frontier’ or 2 for ’Tech. Eff. Effects

Frontier’.modelTypeName

model type: ’Error Components Frontier’ or ’Tech. Eff. Effects Frontier’.functionType function type: either 1 for ’production function’ or 2 for ’cost function’.functionTypeName

function type: ’production function’ or ’cost function’.logDepVar logical. Is the dependent variable logged.olsResults results of the OLS estimation.nXvars number X variables (exogenous variables of the production or cost function.olsLogl log likelihood value of the OLS estimation.gridResults results of the grid search.mleResults results of the maximum likelihood estimation.mleLogl log likelihood value of the maximum likelihood estimation.mleCov coefficient covariance matrix of the maximum likelihood estimation.efficiency technical efficiency estimates.

Page 65: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

residuals.snqProfitEst 65

Author(s)

Arne Henningsen 〈[email protected]

References

Battese, G.E. and T. Coelli (1992), Frontier production functions, technical efficiency and paneldata: with application to paddy farmers in India. Journal of Productivity Analysis, 3, 153-169.

Battese, G.E. and T. Coelli (1995), A model for technical inefficiency effects in a stochastic frontierproduction function for panel data. Empirical Economics, 20, 325-332.

Coelli, T. (1996) A Guide to FRONTIER Version 4.1: A Computer Program for Stochastic FrontierProduction and Cost Function Estimation, CEPA Working Paper 96/08, http://www.uq.edu.au/economics/cepa/frontier.htm, University of New England.

See Also

writeFront41in

Examples

# read the output file that is provided with Frontier 4.1outFile <- system.file( "front41/EG1.OUT", package = "micEcon" )sfa <- readFront41out( outFile )sfa$mleResultssfa$efficiency

# perform an SFA and read the outputdata( Coelli )Coelli$logOutput <- log( Coelli$output )Coelli$logCapital <- log( Coelli$capital )Coelli$logLabour <- log( Coelli$labour )

writeFront41in( Coelli, "firm", "time", "logOutput",c( "logCapital", "logLabour" ) )

## Not run:system( "wine front41.exe" )sfa <- readFront41out()sfa$mleResultssfa$efficiency

## End(Not run)

residuals.snqProfitEstResiduals of an SNQ profit function

Page 66: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

66 residuals.snqProfitEst

Description

Extract the residuals from the estimation of a Symmetric Normalized Quadratic (SNQ) profit func-tion.

Usage

## S3 method for class 'snqProfitEst':residuals( object, scaled = TRUE, ... )

## S3 method for class 'snqProfitImposeConvexity':residuals( object, scaled = TRUE, ... )

Arguments

object an object of type snqProfitEst or snqProfitImposeconvexity.

scaled logical. Return scaled quantities?

... currently not used.

Value

residuals.snqProfitEst and residuals.snqProfitEst return a dataframe that con-tains the residuals for each netput and the profit.

Author(s)

Arne Henningsen 〈[email protected]

See Also

snqProfitEst, snqProfitImposeConvexity and residuals

Examples

data( germanFarms )germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutputgermanFarms$qVarInput <- -germanFarms$vVarInput / germanFarms$pVarInputgermanFarms$qLabor <- -germanFarms$qLaborgermanFarms$time <- c( 0:19 )priceNames <- c( "pOutput", "pVarInput", "pLabor" )quantNames <- c( "qOutput", "qVarInput", "qLabor" )estResult <- snqProfitEst( priceNames, quantNames, c("land","time"), data=germanFarms )residuals( estResult )residuals( estResult, scaled = FALSE )

Page 67: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

returnCode 67

returnCode Return code for optimisation and other objects

Description

This function gives the return code of various optimisation objects. The return code gives a briefinformation about the success or problems, occured during the optimisation (see documentation forthe corresponding function).

Usage

returnCode(x, ...)## Default S3 method:returnCode(x, ...)

Arguments

x object, usually an estimator, achieved by optimisation

... further arguments for other methods

Details

The default methods returns component returnCode.

Value

Integer, the success code of optimisation procedure. However, different optimisation routines maydefine it in a different way.

Author(s)

Ott Toomet, 〈[email protected]

See Also

returnMessage, maxNR

Examples

## maximise the exponential bellf1 <- function(x) exp(-x^2)a <- maxNR(f1, start=2)returnCode(a) # should be success (1 or 2)## Now try to maximise log() functionf2 <- function(x) log(x)a <- maxNR(f2, start=2)returnCode(a) # should give a failure (4)

Page 68: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

68 returnMessage

returnMessage Information about the optimisation process

Description

This function returns a short message, summarising the outcome of the statistical process, typicallyoptimisation. The message should describe either the type of the convergence, or the problem.returnMessage is a generic function, with methods for various optimisation algorithms.

Usage

returnMessage(x, ...)## S3 method for class 'maximisation':returnMessage(x, ...)## S3 method for class 'maxLik':returnMessage(x, ...)

Arguments

x object, should orginate from an optimisation problem... further arguments to other methods

.

Details

The default methods returns component returnMessage.

Value

Character string, the message describing the success or failure of the statistical procedure.

Author(s)

Ott Toomet, 〈[email protected]

See Also

returnCode, maxNR

Examples

## maximise the exponential bellf1 <- function(x) exp(-x^2)a <- maxNR(f1, start=2)returnCode(a) # should be success (1 or 2)## Now try to maximise log() functionf2 <- function(x) log(x)a <- maxNR(f2, start=2)returnCode(a) # should give a failure (4)

Page 69: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

selection 69

selection Heckman-style selection models

Description

This is the frontend for estimating Heckman-style selection models either with one or two outcomes(also known as generalized tobit models).

Usage

selection(selection, outcome, data = sys.frame(sys.parent()),method = "ml", start = NULL,ys = FALSE, xs = FALSE, yo = FALSE, xo = FALSE,mfs = FALSE, mfo = FALSE, print.level = 0, ...)

heckit( selection, outcome, data = sys.frame(sys.parent()),method = "2step", ... )

Arguments

selection formula, the selection equation.

outcome the outcome equation(s). Either a single equation (for tobit 2 models), or a listof two equations (tobit 5 models).

data an optional data frame, list or environment (or object coercible by as.data.frameto a data frame) containing the variables in the model. If not found in data,the variables are taken from environment(formula), typically the envi-ronment from which selection is called.

method how to estimate the model. Either "ml" for Maximum Likelihood, or "2step" for2-step estimation.

start initial values for the ML estimation. Should have names.ys, yo, xs, xo, mfs, mfo

logicals. If true, the response (y), model matrix (x) or the model frame (mf) ofthe selection (s) or outcome (o) equation(s) are returned.

print.level integer. Various debugging information, higher value gives more information.

... additional parameters for the corresponding fitting functions tobit2fit, tobit5fit,heckit2fit, and heckit5fit.

Details

The endogenous variable of the argument ’selection’ must have exactly two levels (e.g. ’FALSE’and ’TRUE’, or ’0’ and ’1’). By default the levels are sorted in increasing order (’FALSE’ is before’TRUE’, and ’0’ is before ’1’).

For tobit-2 (sample selection) models, only those observations are included in the second step es-timation (argument ’outcome’), where this variable equals the second element of its levels (e.g.’TRUE’ or ’1’).

Page 70: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

70 selection

For tobit-5 (switching regression) models, in the second step the first outcome equation (first el-ement of argument ’outcome’) is estimated only for those observations, where this endogenousvariable of the selections equation equals the first element of its levels (e.g. ’FALSE’ or ’0’). Thesecond outcome equation is estimated only for those observations, where this variable equals thesecond element of its levels (e.g. ’TRUE’ or ’1’).

NA-s are allowed in the data. These are ignored if the corresponding outcome is unobserved, other-wise observations which contain NA (either in selection or outcome) are removed.

These selection models assume a known (multivariate normal) distribution of error terms. Becauseof this, the instruments (exclusion restrictions) are not necessary. However, if no instruments aresupplied, the results are based solely on the assumption on multivariate normality. This may or maynot be an appropriate assumption for a particular problem.

The (generic) function ’coef’ (’coef.selection’) can be used to extract the estimated coeffi-cients. The (generic) function ’vcov’ (’vcov.selection’) can be used to extract the estimatedvariance covariance matrix of the coefficients. The (generic) function ’print’ (’print.selection’)can be used to print a few results. The (generic) function ’summary’ (’summary.selection’)can be used to obtain and print detailed results.

Value

’selection’ returns an object of class "selection". If the model estimated by Maximum Likelihood(argument method = "ml"), this object is a list, which has all the components of ’maxLik’, and inaddition the elements ’twoStep’, ’init’, ’param’, termS, termO, and if requested ’ys’, ’xs’, ’yo’,’xo’, ’mfs’, and ’mfo’. If a tobit-2 (sample selection) model is estimated by the two-step method(argument method = "2step"), the returned object is list with components ’probit’, ’coefficients’,’param’, ’vcov’, ’lm’, ’sigma’, ’rho’, ’invMillsRatio’, and ’imrDelta’. If a tobit-2 (sample selection)model is estimated by the two-step method (argument method = "2step"), the returned object is listwith components ’coefficients’, ’vcov’, ’probit’, ’lm1’, ’lm2’, ’rho1’, ’rho2’, ’sigma1’, ’sigma2’,’termsS’, ’termsO’, ’param’, and if requested ’ys’, ’xs’, ’yo’, ’xo’, ’mfs’, and ’mfo’.

probit object of class ’probit’ that contains the results of the 1st step (probit estimation)(only for two-step estimations).

twoStep (only if initial values not given) results of the 2-step estimation, used for initialvalues

init initial values for ML estimationtermsS, termsO

terms for the selection and outcome equationys, xs, yo, xo, mfs, mfo

response, matrix and frame of the selection- and outcome equations (as a list oftwo for the latter). NULL, if not requested.

coefficients estimated coefficients, the complete model. coefficient for the Inverse Mills ratiois treated as a parameter (= %σ).

vcov variance covariance matrix of the estimated coefficients.

param a list with following components: index, a list of numeric vectors: where inthe coef the component are located; oIntercept, a logical: whether theoutcome equation includes intercept; N0, N1, integer, number of observationswith unobserved and observed outcomes; nObs, integer, number of valid obser-vations; nParam, integer, number of the parameters in the model (not all are

Page 71: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

selection 71

independent); df, integer, degrees of freedom. Note this is not equal to nObs- nParam because of the parameters are not independent in all the cases.

lm, lm1, lm2 objects of class ’lm’ that contain the results of the 2nd step estimation(s) of theoutcome equation(s). Note: the standard errors of this estimation are biased,because they do not account for the estimation of γ in the 1st step estimation(the correct standard errors are returned by summary and they are contained invcov component).

sigma, sigma1, sigma2the standard error(s) of the error terms of the outcome equation(s).

rho, rho1, rho2the estimated correlation coefficient(s) between the error term of the selectionequation and the outcome equation(s).

invMillsRatiothe inverse Mills Ratios calculated from the results of the 1st step probit estima-tion.

imrDelta the δs calculated from the inverse Mills Ratios and the results of the 1st stepprobit estimation.

Note

The 2-step estimate of ’rho’ may be outside of the [−1, 1] interval. In that case the standard errorsof invMillsRatio may be meaningless.

Author(s)

Arne Henningsen 〈[email protected]〉, Ott Toomet 〈[email protected]

References

Cameron, A. C. and Trivedi, P. K. (2005) Microeconometrics: Methods and Applications, Cam-bridge University Press.

Greene, W. H. (2003) Econometric Analysis, Fifth Edition, Prentice Hall.

Heckman, J. (1976) The common structure of statistical models of truncation, sample selection andlimited dependent variables and a simple estimator for such models, Annals of Economic and SocialMeasurement, 5(4), p. 475-492.

Johnston, J. and J. DiNardo (1997) Econometric Methods, Fourth Edition, McGraw-Hill.

Lee, L., G. Maddala and R. Trost (1980) Asymetric covariance matrices of two-stage probit andtwo-stage tobit methods for simultaneous equations models with selectivity. Econometrica, 48, p.491-503.

Wooldridge, J. M. (2003) Introductory Econometrics: A Modern Approach, 2e, Thomson South-Western.

See Also

lm, glm, binomial

Page 72: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

72 selection

Examples

## Greene( 2003 ): example 22.8, page 786data( Mroz87 )Mroz87$kids <- ( Mroz87$kids5 + Mroz87$kids618 > 0 )# Two-step estimationsummary( heckit( lfp ~ age + I( age^2 ) + faminc + kids + educ,

wage ~ exper + I( exper^2 ) + educ + city, Mroz87 ) )# ML estimationsummary( selection( lfp ~ age + I( age^2 ) + faminc + kids + educ,

wage ~ exper + I( exper^2 ) + educ + city, Mroz87 ) )

## Wooldridge( 2003 ): example 17.5, page 590data( Mroz87 )# Two-step estimationsummary( heckit( lfp ~ nwifeinc + educ + exper + I( exper^2 ) + age +

kids5 + kids618, log( wage ) ~ educ + exper + I( exper^2 ), Mroz87,method = "2step" ) )

## Cameron and Trivedi (2005): Section 16.6, page 553ffdata( RandHIE )subsample <- RandHIE$year == 2 & !is.na( RandHIE$educdec )selectEq <- binexp ~ logc + idp + lpi + fmde + physlm + disea +

hlthg + hlthf + hlthp + linc + lfam + educdec + xage + female +child + fchild + black

outcomeEq <- lnmeddol ~ logc + idp + lpi + fmde + physlm + disea +hlthg + hlthf + hlthp + linc + lfam + educdec + xage + female +child + fchild + black

# ML estimationcameron <- selection( selectEq, outcomeEq, data = RandHIE[ subsample, ] )summary( cameron )

## example using random numberslibrary( MASS )nObs <- 1000sigma <- matrix( c( 1, -0.7, -0.7, 1 ), ncol = 2 )errorTerms <- mvrnorm( nObs, c( 0, 0 ), sigma )myData <- data.frame( no = c( 1:nObs ), x1 = rnorm( nObs ), x2 = rnorm( nObs ),

u1 = errorTerms[ , 1 ], u2 = errorTerms[ , 2 ] )myData$y <- 2 + myData$x1 + myData$u1myData$s <- ( 2 * myData$x1 + myData$x2 + myData$u2 - 0.2 ) > 0myData$y[ !myData$s ] <- NAmyOls <- lm( y ~ x1, data = myData)summary( myOls )myHeckit <- heckit( s ~ x1 + x2, y ~ x1, myData, print.level = 1 )summary( myHeckit )

## example using random numbers with IV/2SLS estimationlibrary( MASS )nObs <- 1000sigma <- matrix( c( 1, 0.5, 0.1, 0.5, 1, -0.3, 0.1, -0.3, 1 ), ncol = 3 )errorTerms <- mvrnorm( nObs, c( 0, 0, 0 ), sigma )myData <- data.frame( no = c( 1:nObs ), x1 = rnorm( nObs ), x2 = rnorm( nObs ),

Page 73: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

semidefiniteness 73

u1 = errorTerms[ , 1 ], u2 = errorTerms[ , 2 ], u3 = errorTerms[ , 3 ] )myData$w <- 1 + myData$x1 + myData$u1myData$y <- 2 + myData$w + myData$u2myData$s <- ( 2 * myData$x1 + myData$x2 + myData$u3 - 0.2 ) > 0myData$y[ !myData$s ] <- NAmyHeckit <- heckit( s ~ x1 + x2, y ~ w, data = myData )summary( myHeckit ) # biased!myHeckitIv <- heckit( s ~ x1 + x2, y ~ w, data = myData, inst = ~ x1 )summary( myHeckitIv ) # unbiased

## tobit-5 exampleN <- 500

library(mvtnorm)vc <- diag(3)vc[lower.tri(vc)] <- c(0.9, 0.5, 0.6)vc[upper.tri(vc)] <- vc[lower.tri(vc)]eps <- rmvnorm(N, rep(0, 3), vc)xs <- runif(N)ys <- xs + eps[,1] > 0xo1 <- runif(N)yo1 <- xo1 + eps[,2]xo2 <- runif(N)yo2 <- xo2 + eps[,3]a <- selection(ys~xs, list(yo1 ~ xo1, yo2 ~ xo2))summary(a)

## tobit2 examplevc <- diag(2)vc[2,1] <- vc[1,2] <- -0.7eps <- rmvnorm(N, rep(0, 2), vc)xs <- runif(N)ys <- xs + eps[,1] > 0xo <- runif(N)yo <- (xo + eps[,2])*(ys > 0)a <- selection(ys~xs, yo ~xo)summary(a)

semidefiniteness Test for negative and positive semidefiniteness

Description

Test wether a symmetric matrix is negative semidefinite, positive semidefinite, both of them or noneof them.

Usage

semidefiniteness( m, tol = .Machine$double.eps, method = "det" )

Page 74: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

74 snqProfitCalc

Arguments

m a quadratic matrix

tol tolerance level (values between -tol and tol are considered to be zero).

method method to test for semidefiniteness, either "det" (the textbook method: checkingfor the signs of the determinants of sub-matrices) or "eigen" (checking for thesigns of the eigen values).

Author(s)

Arne Henningsen 〈[email protected]

References

Chiang, A.C. (1984) Fundamental Methods of Mathematical Economics, 3rd ed., McGraw-Hill.

Examples

# a positive semidefinite matrixsemidefiniteness( matrix( 1, 3, 3 ))

# a negative semidefinite matrixsemidefiniteness( matrix(-1, 3, 3 ))

# a matrix that is positive and negative semidefinitesemidefiniteness( matrix( 0, 3, 3 ))

# a matrix that is neither positive nor negative semidefinitesemidefiniteness( matrix( 1:9, 3, 3 ))

snqProfitCalc Calculations with the SNQ Profit function

Description

Calculation of netput quantities and profit with the Symmetric Normalized Quadratic (SNQ) Profitfunction.

Usage

snqProfitCalc( priceNames, fixNames, data, weights,scalingFactors = rep( 1, length( weights ) ), coef,quantNames = NULL, form = 0 )

Page 75: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

snqProfitCalc 75

Arguments

priceNames a vector of strings containing the names of netput prices.

fixNames an optional vector of strings containing the names of the quantities of (quasi-)fixinputs.

data a data frame containing the data.

weights vector of weights of the prices for normalization.

quantNames optional vector of strings containing the names of netput quantities.scalingFactors

factors to scale prices (and quantities).

coef a list containing the coefficients alpha, beta, delta and gamma.

form the functional form to be estimated (see snqProfitEst).

Value

a data frame: the first n columns are the netput quantities, the last column is the profit.

Author(s)

Arne Henningsen 〈[email protected]

References

Diewert, W.E. and T.J. Wales (1987) Flexible functional forms and global curvature conditions.Econometrica, 55, p. 43-68.

Diewert, W.E. and T.J. Wales (1992) Quadratic Spline Models for Producer’s Supply and DemandFunctions. International Economic Review, 33, p. 705-722.

Kohli, U.R. (1993) A symmetric normalized quadratic GNP function and the US demand for im-ports and supply of exports. International Economic Review, 34, p. 243-255.

See Also

snqProfitEst and snqProfitWeights.

Examples

data( germanFarms )germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutputgermanFarms$qVarInput <- -germanFarms$vVarInput / germanFarms$pVarInputgermanFarms$qLabor <- -germanFarms$qLaborgermanFarms$time <- c( 0:19 )priceNames <- c( "pOutput", "pVarInput", "pLabor" )quantNames <- c( "qOutput", "qVarInput", "qLabor" )fixNames <- c( "land", "time" )

estResult <- snqProfitEst( priceNames, quantNames, fixNames, data = germanFarms )snqProfitCalc( priceNames, fixNames, estResult$data, estResult$weights,

estResult$scalingFactors, estResult$coef )

Page 76: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

76 snqProfitEla

snqProfitEla Price Elasticities of SNQ Profit function

Description

Calculates the Price Elasticities of a Symmetric Normalized Quadratic (SNQ) profit function.

Usage

snqProfitEla( beta, prices, quant, weights,scalingFactors = rep( 1, length( weights ) ),coefVcov = NULL, df = NULL )

Arguments

beta matrix of estimated β coefficients.

prices vector of netput prices at which the elasticities should be calculated.

quant vector of netput quantities at which the elasticities should be calculated.

weights vector of weights of prices used for normalization.scalingFactors

factors to scale prices (and quantities).

coefVcov variance covariance matrix of the coefficients (optional).

df degrees of freedom to calculate P-values of the elasticities (optional).

Value

a list of class snqProfitEla containing following elements:

ela matrix of the price elasticities.

vcov variance covariance matrix of the price elasticities.

stEr standard errors of the price elasticities.

tval t-values of the price elasticities.

pval P-values of the price elasticities.

Note

A price elasticity is defined as

Eij =

∂qi

qi

∂pj

pj

=∂qi

∂pj· pj

qi

Thus, e.g. Eij = 0.5 means that if the price of netput j (pj) increases by 1%, the quantity of netputi (qi) will increase by 0.5%.

Page 77: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

snqProfitEst 77

Author(s)

Arne Henningsen 〈[email protected]

See Also

snqProfitEst.

Examples

# just a stupid simple examplesnqProfitEla( matrix(101:109,3,3), c(1,1,1), c(1,-1,-1), c(0.4,0.3,0.3) )

# now with real datadata( germanFarms )germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutputgermanFarms$qVarInput <- -germanFarms$vVarInput / germanFarms$pVarInputgermanFarms$qLabor <- -germanFarms$qLaborgermanFarms$time <- c( 0:19 )priceNames <- c( "pOutput", "pVarInput", "pLabor" )quantNames <- c( "qOutput", "qVarInput", "qLabor" )

estResult <- snqProfitEst( priceNames, quantNames, c("land","time"), data=germanFarms )

estResult$ela # price elasticities at mean prices and mean quantities

# price elasticities at the last observation (1994/95)snqProfitEla( estResult$coef$beta, estResult$data[ 20, priceNames ],

estResult$data[ 20, quantNames ], estResult$weights,estResult$scalingFactors )

snqProfitEst Estimation of a SNQ Profit function

Description

Estimation of a Symmetric Normalized Quadratic (SNQ) Profit function.

Usage

snqProfitEst( priceNames, quantNames, fixNames = NULL, instNames = NULL,data, form = 0, base = 1, scalingFactors = NULL,weights = snqProfitWeights( priceNames, quantNames, data, "DW92", base = base ),method = ifelse( is.null( instNames ), "SUR", "3SLS" ), ... )

Page 78: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

78 snqProfitEst

Arguments

priceNames a vector of strings containing the names of netput prices.

quantNames a vector of strings containing the names of netput quantities (inputs must benegative).

fixNames an optional vector of strings containing the names of the quantities of (quasi-)fixed inputs.

instNames an optional vector of strings containing the names of instrumental variables (for3SLS estimation).

data a data frame containing the data.

form the functional form to be estimated (see details).

base the base period(s) for scaling prices (see details).scalingFactors

factors to scale prices (see details).

weights vector of weights of the prices for normalization.

method the estimation method (passed to systemfit).

... arguments passed to systemfit

Details

The Symmetric Normalized Quadratic (SNQ) profit function is defined as follows (this functionalform is used if argument form equals 0):

π (p, z) =n∑

i=1

αipi +12w−1

n∑i=1

n∑j=1

βijpipj +n∑

i=1

m∑j=1

δijpizj +12w

m∑i=1

m∑j=1

γijzizj

with π = profit, pi = netput prices, zi = quantities of fixed inputs, w =∑n

i=1 θipi = price index fornormalization, θi = weights of prices for normalization, and αi, βij , δij and γij = coefficients to beestimated.The netput equations (output supply in input demand) can be obtained by Hotelling’s Lemma (qi =∂π/ ∂pi):

xi = αi + w−1n∑

j=1

βijpj −12θiw

−2n∑

j=1

n∑k=1

βjkpjpk +m∑

j=1

δijzj +12θi

m∑j=1

m∑k=1

γjkzjzk

In my experience the fit of the model is sometimes not very good, because the effect of the fixedinputs is forced to be proportional to the weights for price normalization θi. In this cases I usefollowing extended SNQ profit function (this functional form is used if argument form equals 1):

π (p, z) =n∑

i=1

αipi +12w−1

n∑i=1

n∑j=1

βijpipj +n∑

i=1

m∑j=1

δijpizj +12

n∑i=1

m∑j=1

m∑k=1

γijkpizjzk

The netput equations are now:

xi = αi + w−1n∑

j=1

βijpj −12θiw

−2n∑

j=1

n∑k=1

βjkpjpk +m∑

j=1

δijzj +12

m∑j=1

m∑k=1

γijkzjzk

Page 79: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

snqProfitEst 79

The prices are scaled that they are unity in the base period or - if there is more than one base period- that the means of the prices over the base periods are unity. The argument base can be either(a) a single number: the row number of the base prices,(b) a vector indicating several observations: The means of these observations are used as baseprices,(c) a logical vector with the same length as the data: The means of the observations indicated as’TRUE’ are used as base prices, or(d) NULL: prices are not scaled.If the scaling factors are explicitly specified (argument ’scalingFactors’), the argument ’base’ isignored.

Value

a list of class snqProfitEst containing following objects:

coef a list containing the vectors/matrix of the estimated coefficients:alpha = αi.beta = βij .delta = δij (only if quasi-fix inputs are present).gamma = γij (only if quasi-fix inputs are present).allCoef = vector of all coefficients.allCoefCov = covariance matrix of all coefficients.stats = all coefficients with standard errors, t-values and p-values.liCoef = vector of linear independent coefficients.liCoefCov = covariance matrix of linear independent coefficients.

ela a list of class snqProfitEla that contains (amongst others) the price elastic-ities at mean prices and mean quantities (see snqProfitEla).

fixEla matrix of the fixed factor elasticities at mean prices and mean quantities.

hessian hessian matrix of the profit function with respect to prices evaluated at meanprices.

convexity logical. Convexity of the profit function.

r2 R2-values of all netput equations.

est estimation results returned by systemfit.

weights the weights of prices used for normalization.

normPrice vector used for normalization of prices.

data data frame of originally supplied data.

fitted data frame that contains the fitted netput quantities and the fitted profit.

pMeans means of the scaled netput prices.

qMeans means of the scaled netput quantities.

fMeans means of the (quasi-)fixed input quantities.

priceNames a vector of strings containing the names of netput prices.

quantNames a vector of strings containing the names of netput quantities (inputs must benegative).

fixNames an optional vector of strings containing the names of the quantities of (quasi-)fixed inputs.

Page 80: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

80 snqProfitEst

instNames an optional vector of strings containing the names of instrumental variables (for3SLS estimation).

form the functional form (see details).

base the base period(s) for scaling prices (see details).

weights vector of weights of the prices for normalization.

scalingFactorsfactors to scale prices (and quantities).

method the estimation method.

Author(s)

Arne Henningsen 〈[email protected]

References

Diewert, W.E. and T.J. Wales (1987) Flexible functional forms and global curvature conditions.Econometrica, 55, p. 43-68.

Diewert, W.E. and T.J. Wales (1992) Quadratic Spline Models for Producer’s Supply and DemandFunctions. International Economic Review, 33, p. 705-722.

Kohli, U.R. (1993) A symmetric normalized quadratic GNP function and the US demand for im-ports and supply of exports. International Economic Review, 34, p. 243-255.

See Also

snqProfitEla and snqProfitWeights.

Examples

data( germanFarms )germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutputgermanFarms$qVarInput <- -germanFarms$vVarInput / germanFarms$pVarInputgermanFarms$qLabor <- -germanFarms$qLaborpriceNames <- c( "pOutput", "pVarInput", "pLabor" )quantNames <- c( "qOutput", "qVarInput", "qLabor" )

estResult <- snqProfitEst( priceNames, quantNames, "land", data = germanFarms )estResult$ela # Oh, that looks bad!

# it it reasonable to account for technological progressgermanFarms$time <- c( 0:19 )estResult2 <- snqProfitEst( priceNames, quantNames, c("land","time"), data=germanFarms )estResult2$ela # Ah, that looks good!

Page 81: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

snqProfitFixEla 81

snqProfitFixEla Fixed Factor Elasticities of SNQ Profit function

Description

Calculates the Fixed Factor Elasticities of a Symmetric Normalized Quadratic (SNQ) profit func-tion.

Usage

snqProfitFixEla( delta, gamma, quant, fix, weights,scalingFactors = rep( 1, length( weights ) ) )

Arguments

delta matrix of estimated δ coefficients.

gamma matrix of estimated γ coefficients.

quant vector of netput quantities at which the elasticities should be calculated.

fix vector of quantities of fixed factors at which the elasticities should be calculated.

weights vector of weights of prices used for normalization.

scalingFactorsfactors to scale prices (and quantities).

Note

A fixed factor elasticity is defined as

Eij =

∂qi

qi

∂zj

zj

=∂qi

∂zj· zj

qi

Thus, e.g. Eij = 0.5 means that if the quantity of fixed factor j (zj) increases by 1%, the quantityof netput i (qi) will increase by 0.5%.

Author(s)

Arne Henningsen 〈[email protected]

See Also

snqProfitEst and snqProfitEla.

Page 82: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

82 snqProfitHessian

Examples

# just a stupid simple examplesnqProfitFixEla( matrix(1:6/6,3,2 ), matrix(4:1/4,2 ), c(1,1,1), c(1,1),

c(0.4,0.3,0.3) )

# now with real datadata( germanFarms )germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutputgermanFarms$qVarInput <- -germanFarms$vVarInput / germanFarms$pVarInputgermanFarms$qLabor <- -germanFarms$qLaborgermanFarms$time <- c( 0:19 )priceNames <- c( "pOutput", "pVarInput", "pLabor" )quantNames <- c( "qOutput", "qVarInput", "qLabor" )fixNames <- c( "land", "time" )

estResult <- snqProfitEst( priceNames, quantNames, fixNames, data=germanFarms )

estResult$fixEla # price elasticities at mean quantities of netputs# and fixed factors

# fixed factor elasticities at the last observation (1994/95)snqProfitFixEla( estResult$coef$delta, estResult$coef$gamma,

estResult$data[ 20, quantNames ], estResult$data[ 20, fixNames ],estResult$weights, estResult$scalingFactors )

snqProfitHessian SNQ Profit function: Hessian matrix

Description

Returns the Hessian (substitution) matrix of a Symmetric Normalized Quadratic (SNQ) Profit Func-tion.

Usage

snqProfitHessian( beta, prices, weights,scalingFactors = rep( 1, length( weights ) ) )

Arguments

beta matrix of the beta coefficients.prices vector of netput prices at which the Hessian should be calculated.weights vector of weights of prices for normalization.scalingFactors

factors to scale prices (and quantities).

Author(s)

Arne Henningsen 〈[email protected]

Page 83: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

snqProfitHessianDeriv 83

See Also

snqProfitEst, snqProfitEla and snqProfitHessianDeriv.

Examples

# just a stupid simple examplesnqProfitHessian( matrix(101:109,3,3), c(1,1,1), c(0.4,0.3,0.3) )

# now with real datadata( germanFarms )germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutputgermanFarms$qVarInput <- -germanFarms$vVarInput / germanFarms$pVarInputgermanFarms$qLabor <- -germanFarms$qLaborgermanFarms$time <- c( 0:19 )priceNames <- c( "pOutput", "pVarInput", "pLabor" )quantNames <- c( "qOutput", "qVarInput", "qLabor" )

estResult <- snqProfitEst( priceNames, quantNames, c("land","time"), data=germanFarms )

estResult$hessian # the Hessian at mean prices and mean quantities

# Hessian at the last observation (1994/95)snqProfitHessian( estResult$coef$beta, estResult$data[ 20, priceNames ],

estResult$weights, estResult$scalingFactors )

snqProfitHessianDerivSNQ Profit function: Derivatives of the Hessian

Description

Returns the matrix of derivatives of the vector of linear independent values of the Hessian withrespect to the vector of the linear independent coefficients.

Usage

snqProfitHessianDeriv( prices, weights, nFix = 0, form = 0 )

Arguments

prices vector of netput prices at which the derivatives should be calculated.

weights vector of weights for normalizing prices.

nFix number of (quasi-)fix inputs.

form the functional form to be estimated (see snqProfitEst).

Author(s)

Arne Henningsen 〈[email protected]

Page 84: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

84 snqProfitImposeConvexity

See Also

snqProfitHessian.

Examples

# just a stupid simple examplesnqProfitHessianDeriv( c(1,2,3),c(0.4,0.3,0.3) )

# now with real datadata( germanFarms )germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutputgermanFarms$qVarInput <- -germanFarms$vVarInput / germanFarms$pVarInputgermanFarms$qLabor <- -germanFarms$qLaborgermanFarms$time <- c( 0:19 )priceNames <- c( "pOutput", "pVarInput", "pLabor" )quantNames <- c( "qOutput", "qVarInput", "qLabor" )

estResult <- snqProfitEst( priceNames, quantNames, c("land","time"), data=germanFarms )

snqProfitHessianDeriv( estResult$pMean, estResult$weights, 2 )

snqProfitImposeConvexityImposing Convexity on a SNQ Profit function

Description

Imposing Convexity on a Symmetric Normalized Quadratic (SNQ) Profit function.

Usage

snqProfitImposeConvexity( estResult, rankReduction = 0,start = 10, optimMethod = "BFGS", control = list( maxit=5000 ),stErMethod = "none", nRep = 1000, verbose = 0 )

Arguments

estResult object returned by snqProfitEst.rankReduction

an integer specifying the reduction of the rank of the β matrix.start starting values of the triangular Cholesky matrix.optimMethod method to be used by optim.control list of control parameters passed to optim.stErMethod method to compute standard errors, either ’none’, ’resample’, ’jackknife’ or ’co-

efSim’ (see details).nRep number of replications to compute the standard errors if stErMethod is either

’resample’ or ’coefSim’.verbose an integer idicating the verbose level.

Page 85: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

snqProfitImposeConvexity 85

Details

The procedure proposed by Koebel, Falk and Laisney (2000, 2003) is applied to impose convexityin prices on an estimated symmetric normalized quadratic (SNQ) profit function.The standard errors of the restricted coefficients can be either calculated by bootstrap resampling(’resampling’), jackknife (’jacknife’) or by simulating the distribution of the unrestricted coeffi-cients using its variance covariance matrix (’coefSim’).

Value

a list of class snqProfitImposeConvexity containing the same objects as an object of classsnqProfitEst and additionally the objects:

mindist object returned byoptim.

sim results of the simulation to obtain the standard errors of the estimated coeffi-cients.

Author(s)

Arne Henningsen 〈[email protected]

References

Koebel, B., M. Falk and F. Laisney (2000), Imposing and Testing Curvature Conditions on a Box-Cox Cost Function. Discussion Paper No. 00-70, ZEW, Mannheim, ftp://ftp.zew.de/pub/zew-docs/dp/dp0070.pdf.

Koebel, B., M. Falk and F. Laisney (2003), Imposing and Testing Curvature Conditions on a Box-Cox Cost Function. Journal of Business and Economic Statistics, 21, p. 319-335.

See Also

snqProfitEst.

Examples

data( germanFarms )germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutputgermanFarms$qVarInput <- -germanFarms$vVarInput / germanFarms$pVarInputgermanFarms$qLabor <- -germanFarms$qLaborpriceNames <- c( "pOutput", "pVarInput", "pLabor" )quantNames <- c( "qOutput", "qVarInput", "qLabor" )estResult <- snqProfitEst( priceNames, quantNames, "land", data = germanFarms )estResult # Note: it is NOT convex in netput pricesestResultConvex <- snqProfitImposeConvexity( estResult )estResultConvex # now it is convex

Page 86: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

86 snqProfitShadowPrices

snqProfitShadowPricesShadow Prices of a SNQ Profit function

Description

Calculates the shadow prices of a Symmetric Normalized Quadratic (SNQ) profit function.

Usage

snqProfitShadowPrices( priceNames, fixNames, estResult = NULL,data = estResult$data, weights = estResult$weights,scalingFactors = estResult$scalingFactors,coef = estResult$coef, form = estResult$form )

Arguments

priceNames a vector of strings containing the names of netput prices.

fixNames an optional vector of strings containing the names of the quantities of (quasi-)fixinputs.

estResult object returned by snqProfitEst.

data a data frame containing the data.

weights vector of weights of prices used for normalization.scalingFactors

factors to scale prices (see details).

coef a list containing the coefficients (at least delta and gamma).

form the functional form to be estimated (see details).

Author(s)

Arne Henningsen 〈[email protected]

See Also

snqProfitEst, snqProfitCalc and snqProfitEla.

Examples

data( germanFarms )germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutputgermanFarms$qVarInput <- -germanFarms$vVarInput / germanFarms$pVarInputgermanFarms$qLabor <- -germanFarms$qLaborgermanFarms$time <- c( 0:19 )priceNames <- c( "pOutput", "pVarInput", "pLabor" )quantNames <- c( "qOutput", "qVarInput", "qLabor" )fixNames <- c( "land", "time" )

Page 87: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

snqProfitWeights 87

estResult <- snqProfitEst( priceNames, quantNames, fixNames, data = germanFarms )

snqProfitShadowPrices( priceNames, fixNames, estResult )

snqProfitWeights SNQ Profit function: Weights of prices for normalization

Description

Returns a vector of weights to normalize prices on a Symmetric Normalized Quadratic (SNQ) Profitfunction.

Usage

snqProfitWeights( priceNames, quantNames, data, method = "DW92", base = 1 )

Arguments

priceNames a vector of strings containing the names of netput prices.

quantNames a vector of strings containing the names of netput quantities.

data a data frame containing the data.

method the method to determine the weights (see details).

base the base period(s) for scaling prices (see details).

Details

If argument method is ’DW92’ the method of Diewert and Wales (1992) is applied. They prede-termine the weights by

θi =|xi| p0

in∑

i=1

|xi| p0i

Defining the scaled netput quantities as xti& = &xt

i · p0i we get following formula:

θi =

∣∣∣xi

∣∣∣n∑

i=1

∣∣∣xi

∣∣∣The prices are scaled that they are unity in the base period or - if there is more than one base period- that the means of the prices over the base periods are unity. The argument base can be either(a) a single number: the row number of the base prices,(b) a vector indicating several observations: The means of these observations are used as baseprices,(c) a logical vector with the same length as the data: The means of the observations indicated as’TRUE’ are used as base prices, or (d) NULL: prices are not scaled.

Page 88: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

88 summary.aidsElas

Author(s)

Arne Henningsen 〈[email protected]

See Also

snqProfitEst.

Examples

data( germanFarms )germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutputgermanFarms$qVarInput <- -germanFarms$vVarInput / germanFarms$pVarInputgermanFarms$qLabor <- -germanFarms$qLaborpriceNames <- c( "pOutput", "pVarInput", "pLabor" )quantNames <- c( "qOutput", "qVarInput", "qLabor" )snqProfitWeights( priceNames, quantNames, germanFarms )

summary.aidsElas Summarizing the Elasticities of an Almost Ideal Demand System

Description

These functions summarize and print the estimated elasticities of an Almost Ideal Demand System(AIDS).

Usage

## S3 method for class 'aidsElas':summary( object, ... )

## S3 method for class 'summary.aidsElas':print( x, ... )

Arguments

object an object of class aidsElas.

x an object of class summary.aidsElas.

... currently ignored.

Value

summary.aidsEst returns a list of class summary.aidsElas. It is identical to the providedobject (except for its class), but it contains following additional element:

table a matrix with 4 columns: all elasticities, their standard errors (if available), theirt-values (if available), and their P-values (if available).

Page 89: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

summary.aidsEst 89

Author(s)

Arne Henningsen 〈[email protected]

See Also

aidsElas, aidsEst.

Examples

# Using data published in Blanciforti, Green & King (1986)data( Blanciforti86 )# Data on food consumption are available only for the first 32 yearsBlanciforti86 <- Blanciforti86[ 1:32, ]

## Repeating the demand analysis of Blanciforti, Green & King (1986)estResult <- aidsEst( c( "pFood1", "pFood2", "pFood3", "pFood4" ),

c( "wFood1", "wFood2", "wFood3", "wFood4" ), "xFood",data = Blanciforti86, method = "IL:L" )

summary( elas( estResult ) )

summary.aidsEst Summarizing the Estimation of an Almost Ideal Demand System

Description

summary.aidsEst summarizes the estimation results of an Almost Ideal Demand System (AIDS).

Usage

## S3 method for class 'aidsEst':summary( object, ... )

## S3 method for class 'summary.aidsEst':print( x, ... )

Arguments

object an object of class aidsEst.

x an object of class summary.aidsEst.

... currently ignored.

Value

summary.aidsEst returns a list of class summary.aidsEst that is currently identical to theprovided object (except for its class).

Page 90: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

90 summary.maxLik

Author(s)

Arne Henningsen 〈[email protected]

See Also

aidsEst, aidsElas.

Examples

# Using data published in Blanciforti, Green & King (1986)data( Blanciforti86 )# Data on food consumption are available only for the first 32 yearsBlanciforti86 <- Blanciforti86[ 1:32, ]

## Repeating the demand analysis of Blanciforti, Green & King (1986)estResult <- aidsEst( c( "pFood1", "pFood2", "pFood3", "pFood4" ),

c( "wFood1", "wFood2", "wFood3", "wFood4" ), "xFood",data = Blanciforti86, method = "LA:SL" )

print( summary( estResult ) )

summary.maxLik summary the Maximum-Likelihood estimation

Description

Summary the Maximum-Likelihood estimation including standard errors and t-values.

Usage

## S3 method for class 'maxLik':summary(object, ... )

Arguments

object object of class ’maxLik’, most probably a result from Maximum-Likelihoodestimation.

... currently not used.

Value

object of class ’summary.maxLik’ with following components:

type type of maximisation.

iterations number of iterations.

code code of success.

message a short message describing the code.

loglik the loglik value in the maximum.

Page 91: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

summary.maximisation 91

estimate numeric matrix, the first column contains the parameter estimates, the secondthe standard errors, third t-values and fourth corresponding probabilities.

activePar logical vector, which parameters are treated as free.

NActivePar number of free parameters.

Author(s)

Ott Toomet 〈[email protected]

See Also

maxLik

Examples

## ML estimation of exponential duration model:t <- rexp(100, 2)loglik <- function(theta) log(theta) - theta*tgradlik <- function(theta) 1/theta - thesslik <- function(theta) -100/theta^2## Estimate with numeric gradient and hessiana <- maxLik(loglik, start=1, print.level=2)summary(a)## Estimate with analytic gradient and hessiana <- maxLik(loglik, gradlik, hesslik, start=1)summary(a)

summary.maximisationSummary method for maximisation/minimisation

Description

Summarises the maximisation results

Usage

## S3 method for class 'maximisation':summary( object, hessian=FALSE, unsucc.step=FALSE, ... )

Arguments

object optimisation result, object of class maximisation. See maxNR.

hessian logical, whether to display Hessian matrix.

unsucc.step logical, whether to describe last unsuccesful step if code == 3

... currently not used.

Page 92: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

92 summary.maximisation

Value

Object of class summary.maximisation, intended to print with corresponding print method.There are following components:

type type of maximisation.

iterations number of iterations.

code exit code (see maxNR.)

message a brief message, explaining code.

unsucc.step description of last unsuccessful step, only if requested and code == 3

maximum function value at maximum

estimate matrix with following columns:

results: coefficient estimates at maximum

gradient: estimated gradient at maximum

hessian estimated hessian at maximum, only if requested

Author(s)

Ott Toomet 〈[email protected]

See Also

maxNR

Examples

## minimize a 2D quadratic function:f <- function(b) {x <- b[1]; y <- b[2];val <- (x - 2)^2 + (y - 3)^2attr(val, "gradient") <- c(2*x - 4, 2*y - 6)attr(val, "hessian") <- matrix(c(2, 0, 0, 2), 2, 2)val

}## Note that NR finds the minimum of a quadratic function with a single## iteration. Use c(0,0) as initial value.result1 <- maxNR( f, start = c(0,0) )summary( result1 )## Now use c(1000000, -777777) as initial value and ask for hessianresult2 <- maxNR( f, start = c( 1000000, -777777))summary( result2 )

Page 93: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

summary.selection 93

summary.selection Summarizing Selection Estimations

Description

Print or return a summary of a selection estimation.

Usage

## S3 method for class 'selection':summary(object, ...)## S3 method for class 'summary.selection':print(x,

digits = max(3, getOption("digits") - 3),part = "full", ...)

Arguments

object an object of class ’selection’.

x an object of class ’summary.selection’.

part character string: which parts of the summary to print: "full" for all the esti-mated parameters (probit selection, outcome estimates, correlation and residualvariance), or "outcome" for the outcome results only.

digits numeric, (suggested) number of significant digits.

... currently not used.

Details

The variance-covariance matrix of the two-step estimator is currently implemented only for tobit-2(sample selection) models, but not for the tobit-5 (switching regression) model.

Value

Summary methods return an object of class summary.selection. Print methods return theargument invisibly.

Author(s)

Arne Henningsen 〈[email protected]〉, Ott Toomet 〈[email protected]

See Also

selection

Page 94: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

94 symMatrix

Examples

## Wooldridge( 2003 ): example 17.5, page 590data( Mroz87 )wooldridge <- selection( lfp ~ nwifeinc + educ + exper + I( exper^2 ) +

age + kids5 + kids618, log( wage ) ~ educ + exper + I( exper^2 ),data = Mroz87, method = "2step" )

# summary of the 1st step probit estimation (Example 17.1, p. 562f)# and the 2nd step OLS regression (example 17.5, page 590)summary( wooldridge )

# summary of the outcome equation onlyprint(summary(wooldridge), part="outcome")

symMatrix Symmetric Matrix

Description

Create a Symmetric Matrix.

Usage

symMatrix( data = NA, nrow = NULL, byrow = FALSE,upper = FALSE )

Arguments

data an optional data vector.

nrow the desired number of rows and columns.

byrow logical. If ’FALSE’ (the default) the matrix is filled by columns, otherwise thematrix is filled by rows.

upper logical. If ’FALSE’ (the default) the lower triangular part of the matrix (includ-ing the diagonal) is filled, otherwise the upper triangular part of the matrix isfilled.

Value

a symmetric matrix.

Author(s)

Arne Henningsen 〈[email protected]

See Also

matrix, lower.tri.

Page 95: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

testConsist 95

Examples

# fill the lower triangular part by columnssymMatrix( 1:10, 4 )# fill the upper triangular part by columnssymMatrix( 1:10, 4, upper = TRUE )# fill the lower triangular part by rowssymMatrix( 1:10, 4, byrow = FALSE )

testConsist Testing Theoretical Consistency

Description

Test theoretical consistency of microeconomic models.

Usage

testConsist( object, ... )

Arguments

object a microeconomic model

... further arguments for methods

Details

This is a generic function.

Author(s)

Arne Henningsen 〈[email protected]

See Also

testConsist.aidsEst

Page 96: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

96 tobit2fit

tobit2fit Fitting parametric sample selection models

Description

These functions do the actual fitting of tobit-2 (sample selection) and tobit-5 (switching regres-sion) models by Maximum Likelihood (ML) estimation. The arguments must be given as nu-meric vectors/matrices, initial value of parameters must be specified. These functions are calledby selection and are intended for micEcon internal use.

Usage

tobit2fit(YS, XS, YO, XO, start, print.level = 0,maxMethod="Newton-Raphson", ...)tobit5fit(YS, XS, YO1, XO1, YO2, XO2, start, print.level=0, maxMethod="Newton-Raphson", ...)

Arguments

YS numeric 0/1 vector, where 0 denotes unobserved outcome (tobit 2) or outcome1 observed (tobit 5).

XS, XO, XO1, XO2numeric matrix, model matrix for selection and outcome equations.

YO numeric vector, observed outcomes. Values for unobserved outcomes are ig-nored (they may or may not be NA).

start numeric vector of initial values. The order is: betaS, betaO(1), sigma(1), rho(1),betaO2, sigma2, rho2.

print.level numeric, values greater than 0 will produce increasingly more debugging infor-mation.

maxMethod character, a maximisation method supported by maxLik

... Additional parameters to maxLik.

Value

The returned object is identical to maxLik returned object.

Author(s)

Ott Toomet 〈[email protected]

See Also

selection, maxLik

Page 97: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

translogCalc 97

translogCalc Calculate dependent variable of a translog function

Description

Calculate the dependent variable of a translog function.

Usage

translogCalc( xNames, data, allCoef, quadHalf = TRUE, logValues = FALSE )

Arguments

xNames a vector of strings containing the names of the independent variables.

data dataframe containing the data.

allCoef vector containing all coefficients.

quadHalf logical. Multiply the quadratic terms by one half?

logValues logical. Are the values in data already logged?

Value

a vector containing the endogenous variable.

Author(s)

Arne Henningsen 〈[email protected]

See Also

translogEst and translogDeriv.

Examples

data( germanFarms )# output quantity:germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutput# quantity of variable inputsgermanFarms$qVarInput <- germanFarms$vVarInput / germanFarms$pVarInput# a time trend to account for technical progress:germanFarms$time <- c(1:20)

# estimate a quadratic production functionestResult <- translogEst( "qOutput", c( "qLabor", "land", "qVarInput", "time" ),

germanFarms )

translogCalc( c( "qLabor", "land", "qVarInput", "time" ), germanFarms,estResult$allCoef )

#equal to estResult$fitted

Page 98: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

98 translogDeriv

translogDeriv Derivatives of a translog function

Description

Calculate the derivatives of a translog function.

Usage

translogDeriv( xNames, data, allCoef, allCoefCov = NULL,yName = NULL, quadHalf = TRUE, logValues = FALSE )

Arguments

xNames a vector of strings containing the names of the independent variables.

data dataframe containing the data.

allCoef vector containing all coefficients.

allCoefCov optional covariance matrix of the coefficients.

yName an optional string containing the name of the dependent variable. If it is NULL,the dependent variable is calculated from the independent variables and the co-efficients.

quadHalf logical. Multiply the quadratic terms by one half?

logValues logical. Are the values in data already logged?

Value

a list of class translogDeriv containing following objects:

deriv data frame containing the derivatives.

variance data frame containing the variances of the derivatives (not implemented yet).

stdDev data frame containing the standard deviations of the derivatives (not imple-mented yet).

Author(s)

Arne Henningsen 〈[email protected]

See Also

translogEst, translogCalc nad translogHessian

Page 99: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

translogEst 99

Examples

data( germanFarms )# output quantity:germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutput# quantity of variable inputsgermanFarms$qVarInput <- germanFarms$vVarInput / germanFarms$pVarInput# a time trend to account for technical progress:germanFarms$time <- c(1:20)

# estimate a translog production functionestResult <- translogEst( "qOutput", c( "qLabor", "land", "qVarInput", "time" ),

germanFarms )

# compute the marginal products of the inputs (with "fitted" Output)margProducts <- translogDeriv( c( "qLabor", "land", "qVarInput", "time" ),

germanFarms, estResult$allCoef, estResult$allCoefCov )margProducts$deriv

# compute the marginal products of the inputs (with observed Output)margProductsObs <- translogDeriv( c( "qLabor", "land", "qVarInput", "time" ),

germanFarms, estResult$allCoef, estResult$allCoefCov, "qOutput" )margProductsObs$deriv

translogEst Estimate a translog function

Description

Estimate a translog function.

Usage

translogEst( yName, xNames, data, quadHalf = TRUE, logValues = FALSE )

Arguments

yName a string containing the name of the dependent variable.

xNames a vector of strings containing the names of the independent variables.

data dataframe containing the data.

quadHalf logical. Multiply the quadratic terms by one half?

logValues logical. Are the values in data already logged?

Value

a list of class translogEst containing following objects:

lm a list returned by lm.

Page 100: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

100 translogHessian

residuals residuals.

fitted fitted values.

coef a list containing the the estimated coefficients: alpha0 = α0 (scalar), alpha = αi

(vector), beta = βij (matrix).

allCoef vector of all coefficients.

allCoefCov Covariance matrix of all coefficients.

r2 R2 value.

r2bar adjusted R2 value.

nObs number of observations.

model.matrix the model matrix.

Author(s)

Arne Henningsen 〈[email protected]

See Also

translogCalc, translogDeriv and quadFuncEst.

Examples

data( germanFarms )# output quantity:germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutput# quantity of variable inputsgermanFarms$qVarInput <- germanFarms$vVarInput / germanFarms$pVarInput# a time trend to account for technical progress:germanFarms$time <- c(1:20)

# estimate a quadratic production functionestResult <- translogEst( "qOutput", c( "qLabor", "land", "qVarInput", "time" ),

germanFarms )

estResult$coefestResult$r2

translogHessian Hessian matrix of a translog function

Description

Calculate the Hessian matrices of a translog function.

Usage

translogHessian( xNames, data, allCoef, yName = NULL,quadHalf = TRUE, logValues = FALSE, bordered = FALSE )

Page 101: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

translogHessian 101

Arguments

xNames a vector of strings containing the names of the independent variables.

data dataframe containing the data.

allCoef vector containing all coefficients.

yName an optional string containing the name of the dependent variable. If it is NULL,the dependent variable is calculated from the independent variables and the co-efficients.

quadHalf logical. Multiply the quadratic terms by one half?

logValues logical. Are the values in data already logged?

bordered logical. Should the bordered Hessians be returned?

Value

a list containing following the (bordered) Hessian matrices at each data point.

Author(s)

Arne Henningsen 〈[email protected]

See Also

translogEst, translogDeriv and translogCalc

Examples

data( germanFarms )# output quantity:germanFarms$qOutput <- germanFarms$vOutput / germanFarms$pOutput# quantity of variable inputsgermanFarms$qVarInput <- germanFarms$vVarInput / germanFarms$pVarInput# a time trend to account for technical progress:germanFarms$time <- c(1:20)

# estimate a quadratic production functionestResult <- translogEst( "qOutput", c( "qLabor", "land", "qVarInput", "time" ),

germanFarms )

# compute the Hessian matrices (with "fitted" output)hessians <- translogHessian( c( "qLabor", "land", "qVarInput", "time" ),

germanFarms, estResult$allCoef )hessians[[ 1 ]]

# compute the Hessian matrices (with observed output)hessiansObs <- translogHessian( c( "qLabor", "land", "qVarInput", "time" ),

germanFarms, estResult$allCoef, "qOutput" )hessiansObs[[ 1 ]]

# compute the bordered Hessian matricesborderedHessians <- translogHessian( c( "qLabor", "land", "qVarInput", "time" ),

Page 102: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

102 triang

germanFarms, estResult$allCoef, bordered = TRUE )borderedHessians[[ 1 ]]

triang Upper triangular matrix from a vector

Description

Creates an upper triangular square matrix from a vector.

Usage

triang( v, n )

Arguments

v vector

n desired dimension of the returned square matrix

Note

If the vector has less elements than the upper triangular matrix, the last elements are set to zero.

Author(s)

Arne Henningsen 〈[email protected]

See Also

veclipos.

Examples

v <- c( 1:5 )triang( v, 3 )

Page 103: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

vcov-methods 103

vcov-methods ’vcov’ methods in Package ’micEcon’

Description

Extract variance-covariance matrices.

Usage

## S3 method for class 'probit':vcov( object, ... )## S3 method for class 'maxLik':vcov( object, ... )

Arguments

object an object of class probit or maxLik.

... further arguments (currently ignored).

Value

the estimated variance covariance matrix of the coefficients.

Author(s)

Arne Henningsen 〈[email protected]〉, Ott Toomet 〈[email protected]

See Also

vcov, maxLik.

vcov.selection Extract Variance Covariance Matrix

Description

This function extracts the coefficient variance-covariance matrix from sample selection models.

Usage

## S3 method for class 'selection':vcov(object, part = "full", ...)

Page 104: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

104 vecli

Arguments

object object of class "selection".

part character string indication which parts of the variance-covariance matrix to ex-tract: "full" for all estimated parameters (selection estimates, outcome estimates,error variance and correlation) or "outcome" for the outcome estimates only (in-cluding the coefficient of the inverse Mill’s ratio in case of a two-step estima-tion).

... currently not used.

Details

The variance-covariance matrix of a two-step estimate is currently only partly implemented. Theunimplemented part of the matrix is filled with NAs.

Value

the estimated variance covariance matrix of the coefficients.

Author(s)

Arne Henningsen 〈[email protected]〉, Ott Toomet 〈[email protected]

See Also

vcov, selection, coef.selection.

Examples

## Estimate a simple female wage model taking into account the labour## force participation

data(Mroz87)a <- heckit(lfp ~ huswage + kids5 + mtr + fatheduc + educ + city,

log(wage) ~ educ + city, data=Mroz87)## extract the full variance-covariance matrix:vcov( a )## now extract the variance-covariance matrix of the outcome model only:vcov( a, part = "outcome" )

vecli Vector of linear independent values

Description

Returns a vector containing the linear independent elements of a symmetric matrix (of full rank).

Usage

vecli( m )

Page 105: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

vecli2m 105

Arguments

m symmetric matrix

Author(s)

Arne Henningsen 〈[email protected]

See Also

veclipos.

Examples

# a symmetric n x n matrixm <- cbind(c(11,12,13),c(12,22,23),c(13,23,33))vecli(m) # returns: 11 12 13 22 23 33

vecli2m Convert vector of linear independent values into a Matrix

Description

Converts a vector into a symmetric matrix that the original vector contains the linear independentvalues of the returned symmetric matrix.

Usage

vecli2m( v )

Arguments

v a vector.

Author(s)

Arne Henningsen 〈[email protected]

See Also

vecli, veclipos.

Examples

v <- c( 11, 12, 13, 22, 23, 33 )vecli2m( v )

Page 106: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

106 writeFront41in

veclipos Position in a vector of linear independent values

Description

Returns the position of the [i,j]th element of a symmetric n × n matrix that this element has in avector of the linear independent values of the matrix.

Usage

veclipos( i, j, n )

Arguments

i row of the element in the matrix.

j column of the element in the matrix.

n dimension of the matrix.

Note

A symmetric n × n matrix has n*(n+1)/2 independent values.The function is: n*(n-1)/2-((n-min(i,j))*(n-min(i,j)+1)/2)+max(i,j)

Author(s)

Arne Henningsen 〈[email protected]

See Also

vecli, vecli2m.

Examples

veclipos( 1, 2, 3 ) # returns: 2

writeFront41in Write instruction file for Frontier 4.1

Description

Write an instruction file and a data file for Coelli’s program Frontier 4.1 that performs stochasticfrontier analysis.

Page 107: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

writeFront41in 107

Usage

writeFront41in( data, crossSectionName, timePeriodName,yName, xNames = NULL, zNames = NULL,translog = FALSE, quadHalf = TRUE,functionType = 1, modelType = 1, logDepVar = TRUE, mu = FALSE, eta = FALSE,insFile = "front41.ins", dtaFile = sub( "\\.ins$", ".dta", insFile ),outFile = sub( "\\.ins$", ".out", insFile ) )

Arguments

data data frame that contains the data.crossSectionName

string: name of the cross section identifier.

timePeriodNamestring: name of the time period identifier.

yName string: name of the endogenous variable.

xNames a vector of strings containing the names of the X variables (exogenous variablesof the production or cost function).

zNames a vector of strings containing the names of the Z variables (variables explainingthe efficiency level).

translog logical. Should a translog function be estimated?

quadHalf logical. Multiply the quadratic terms of the translog function by one half?

functionType function type: either 1 for ’production function’ or 2 for ’cost function’.

modelType model type: either 1 for ’Error Components Frontier’ or 2 for ’Tech. Eff. EffectsFrontier’.

logDepVar logical. Is the dependent variable logged.

mu logical. Should a ’mu’ (if modelType = 1) or a delta0 (if modelType = 2) beincluded in the estimation.

eta logical. Should an ’eta’ be included in the estimation (only if modelType = 1).

insFile name of the instruction file.

dtaFile name of the data file.

outFile name of the output file.

Value

writeFront41in writes an instruction file and an data file to disk.

Author(s)

Arne Henningsen 〈[email protected]

Page 108: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

108 writeFront41in

References

Battese, G.E. and T. Coelli (1992), Frontier production functions, technical efficiency and paneldata: with application to paddy farmers in India. Journal of Productivity Analysis, 3, 153-169.

Battese, G.E. and T. Coelli (1995), A model for technical inefficiency effects in a stochastic frontierproduction function for panel data. Empirical Economics, 20, 325-332.

Coelli, T. (1996) A Guide to FRONTIER Version 4.1: A Computer Program for Stochastic FrontierProduction and Cost Function Estimation, CEPA Working Paper 96/08, http://www.uq.edu.au/economics/cepa/frontier.htm, University of New England.

See Also

readFront41out

Examples

data( Coelli )Coelli$logOutput <- log( Coelli$output )Coelli$logCapital <- log( Coelli$capital )Coelli$logLabour <- log( Coelli$labour )

writeFront41in( Coelli, "firm", "time", "logOutput",c( "logCapital", "logLabour" ) )

## Not run:system( "wine front41.exe" )

## End(Not run)

Page 109: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

Index

∗Topic arrayinsertCol, 30insertRow, 31quasiconcavity, 60rSquared, 61semidefiniteness, 71symMatrix, 92triang, 100vecli, 102vecli2m, 103veclipos, 104

∗Topic datasetsBlanciforti86, 1Bleymueller79E25.1, 3Coelli, 3germanFarms, 26Missong03E7.7, 4Mroz87, 5RandHIE, 6

∗Topic internalheckit2fit, 26micEcon-internal, 46tobit2fit, 94

∗Topic mathcompareDerivatives, 24numericGradient, 48

∗Topic methodsactivePar, 8coef.selection, 22elas, 25hessian, 29linearPredictors, 35loglikValue, 36maximisationType, 44nObs, 46nParam, 47returnCode, 65returnMessage, 66summary.maximisation, 89

testConsist, 93vcov-methods, 101vcov.selection, 101

∗Topic miscmicEcon-deprecated, 45

∗Topic modelsaidsBestA0, 9aidsCalc, 11aidsElas, 13aidsEst, 16aidsPx, 18aidsTestConsist, 20coefTable, 23heckit2fit, 26heckitVcov, 28invMillsRatio, 31linearPredictors, 35predict.snqProfitEst, 50priceIndex, 51print.snqProfitEst, 53probit, 54quadFuncCalc, 55quadFuncDeriv, 56quadFuncEst, 58quantityIndex, 59readFront41out, 62residuals.snqProfitEst, 63selection, 67snqProfitCalc, 72snqProfitEla, 74snqProfitEst, 75snqProfitFixEla, 79snqProfitHessian, 80snqProfitHessianDeriv, 81snqProfitImposeConvexity, 82snqProfitShadowPrices, 84snqProfitWeights, 85summary.aidsElas, 86summary.aidsEst, 87

109

Page 110: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

110 INDEX

summary.maxLik, 88summary.selection, 91tobit2fit, 94translogCalc, 95translogDeriv, 96translogEst, 97translogHessian, 98writeFront41in, 104

∗Topic multivariaterSquared, 61

∗Topic nonlinearprobit, 54

∗Topic optimizeactivePar, 8hessian, 29maxBFGS, 37maxBHHH, 39maximisationType, 44maxLik, 40maxNR, 41

∗Topic printsummary.maximisation, 89

∗Topic regressionheckit2fit, 26probit, 54selection, 67tobit2fit, 94

∗Topic univarrSquared, 61

∗Topic utilitiescompareDerivatives, 24numericGradient, 48returnCode, 65returnMessage, 66

activePar, 8, 29aidsBestA0, 9aidsCalc, 11, 18aidsCoef (micEcon-internal), 46aidsElas, 13, 18, 21, 87, 88aidsElasJacobian

(micEcon-internal), 46aidsEst, 10–12, 15, 16, 20, 21, 87, 88aidsJacobian (micEcon-internal),

46aidsPx, 11, 12, 16, 18aidsRestr (micEcon-internal), 46aidsSystem (micEcon-internal), 46aidsTestConsist, 20

binomial, 55, 69Blanciforti86, 1Bleymueller79E25.1, 3

checkNames (micEcon-internal), 46coef.maxLik (maxLik), 40coef.selection, 22, 68, 102coef.summary.probit

(micEcon-internal), 46coef.summary.selection

(coef.selection), 22coefficients, 22coefTable, 23Coelli, 3compareDerivatives, 24, 49

Deprecated, 46deriv, 49

elas, 25elas.aidsEst, 25elas.aidsEst (aidsElas), 13elasticities (elas), 25

germanFarms, 26glm, 32, 55, 69

heckit, 26–28heckit (selection), 67heckit2fit, 26, 67heckit5fit, 67heckit5fit (heckit2fit), 26heckitVcov, 28hessian, 29

insertCol, 30, 31insertRow, 30, 31invMillsRatio, 31

linearPredictors, 35lm, 46, 69loglikValue, 36lower.tri, 92

matrix, 92maxBFGS, 37, 40maxBHHH, 38, 39maximisationType, 44maxLik, 29, 37, 40, 55, 89, 94, 101

Page 111: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

INDEX 111

maxNR, 8, 9, 37–40, 41, 41, 44, 45, 65, 66, 89,90

micEcon-deprecated, 45micEcon-internal, 46micEconIndex (micEcon-internal),

46Missong03E7.7, 4model.frame.probit

(micEcon-internal), 46model.matrix.probit

(micEcon-internal), 46Mroz87, 5

nlm, 38, 40, 41, 44nObs, 9, 46, 48nParam, 47, 47numericGradient, 24, 48numericHessian (numericGradient),

48numericNHessian

(numericGradient), 48

optim, 37, 38, 40, 41, 44, 82

predict, 51predict.snqProfitEst, 50predict.snqProfitImposeConvexity

(predict.snqProfitEst), 50priceIndex, 51print, 53print.aidsElas (aidsElas), 13print.aidsEst (aidsEst), 16print.aidsTestConsist

(micEcon-internal), 46print.selection (selection), 67print.snqProfitEst, 53print.snqProfitImposeConvexity

(micEcon-internal), 46print.summary.aidsElas

(summary.aidsElas), 86print.summary.aidsEst

(summary.aidsEst), 87print.summary.maximisation

(micEcon-internal), 46print.summary.maxLik

(micEcon-internal), 46print.summary.probit

(micEcon-internal), 46

print.summary.selection(summary.selection), 91

probit, 32, 54

quadFuncCalc, 55, 57, 58quadFuncDeriv, 56, 56, 58quadFuncEst, 56, 57, 58, 98quantityIndex, 52, 59, 60quasiconcavity, 60quasiconvexity (quasiconcavity),

60

RandHIE, 6readFront41out, 62, 106residuals, 64residuals.snqProfitEst, 63residuals.snqProfitImposeConvexity

(residuals.snqProfitEst),63

returnCode, 65, 66returnCode.maximisation

(micEcon-internal), 46returnCode.maxLik

(micEcon-internal), 46returnMessage, 65, 66rSquared, 61

selection, 22, 26, 27, 46, 67, 91, 94, 102semidefiniteness, 71snqProfitCalc, 51, 72, 84snqProfitCoef (micEcon-internal),

46snqProfitCoefNames

(micEcon-internal), 46snqProfitEla, 74, 77–79, 81, 84snqProfitElaJacobian

(micEcon-internal), 46snqProfitEst, 51, 53, 58, 64, 73, 75, 75,

79, 81–84, 86snqProfitFixEla, 79snqProfitHessian, 80, 82snqProfitHessianDeriv, 81, 81snqProfitImposeConvexity, 64, 82snqProfitRestrict

(micEcon-internal), 46snqProfitShadowPrices, 84snqProfitSystem

(micEcon-internal), 46

Page 112: The micEcon Packageftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/micEcon.pdf · The micEcon Package September 11, 2007 Version 0.3-8 Date 2007/09/11 Title Microeconomics Author

112 INDEX

snqProfitTestCoef(micEcon-internal), 46

snqProfitWeights, 73, 78, 85summary.aidsElas, 86summary.aidsEst, 18, 87summary.lm, 47summary.maximisation, 89summary.maxLik, 88summary.probit

(micEcon-internal), 46summary.selection, 22, 68, 91symMatrix, 92systemfit, 16, 17, 76, 77

testConsist, 93testConsist.aidsEst, 93testConsist.aidsEst

(aidsTestConsist), 20tobit2 (micEcon-deprecated), 45tobit2fit, 67, 94tobit5fit, 67tobit5fit (tobit2fit), 94translogCalc, 95, 96, 98, 99translogDeriv, 95, 96, 98, 99translogEst, 58, 95, 96, 97, 99translogHessian, 96, 98translogMonoRestr

(micEcon-internal), 46triang, 100

vcov, 101, 102vcov-methods, 101vcov.maxLik (vcov-methods), 101vcov.probit (vcov-methods), 101vcov.selection, 22, 68, 101vecli, 102, 103, 104vecli2m, 103, 104veclipos, 100, 103, 104vglm, 32

writeFront41in, 63, 104