Last updated on 2026-06-08 10:51:59 CEST.
| Flavor | Version | Tinstall | Tcheck | Ttotal | Status | Flags |
|---|---|---|---|---|---|---|
| r-devel-linux-x86_64-debian-clang | 0.1-16 | 2.92 | 97.43 | 100.35 | NOTE | |
| r-devel-linux-x86_64-debian-gcc | 0.1-16 | 1.95 | 40.99 | 42.94 | ERROR | |
| r-devel-linux-x86_64-fedora-clang | 0.1-16 | 155.82 | OK | |||
| r-devel-linux-x86_64-fedora-gcc | 0.1-16 | 5.00 | 176.20 | 181.20 | OK | |
| r-devel-windows-x86_64 | 0.1-16 | 3.00 | 147.00 | 150.00 | OK | |
| r-patched-linux-x86_64 | 0.1-16 | 2.71 | 91.63 | 94.34 | OK | |
| r-release-linux-x86_64 | 0.1-16 | 2.52 | 92.48 | 95.00 | OK | |
| r-release-macos-arm64 | 0.1-16 | 1.00 | 34.00 | 35.00 | OK | |
| r-release-macos-x86_64 | 0.1-16 | 2.00 | 147.00 | 149.00 | OK | |
| r-release-windows-x86_64 | 0.1-16 | 3.00 | 147.00 | 150.00 | OK | |
| r-oldrel-macos-arm64 | 0.1-16 | OK | ||||
| r-oldrel-macos-x86_64 | 0.1-16 | 2.00 | 148.00 | 150.00 | OK | |
| r-oldrel-windows-x86_64 | 0.1-16 | 5.00 | 177.00 | 182.00 | OK |
Version: 0.1-16
Check: CRAN incoming feasibility
Result: NOTE
Maintainer: ‘Arne Henningsen <arne.henningsen@gmail.com>’
Found the following (possibly) invalid file URIs:
URI: geraldine.henningsen@googlemail.com
From: inst/doc/Manuscript.pdf
URI: arne@ifro.ku.dk
From: inst/doc/Manuscript.pdf
Flavors: r-devel-linux-x86_64-debian-clang, r-devel-linux-x86_64-debian-gcc
Version: 0.1-16
Check: tests
Result: NOTE
Running ‘logit.R’ [1s/1s]
Comparing ‘logit.Rout’ to ‘logit.Rout.save’ ...
22,24c22,98
< > proc.time()
< user system elapsed
< 0.762 0.086 0.855
---
> > options( digits = 4 )
> >
> > # load data set
> > data( "Mroz87", package = "sampleSelection" )
> >
> > # create dummy variable for kids
> > Mroz87$kids <- as.numeric( Mroz87$kids5 > 0 | Mroz87$kids618 > 0 )
> >
> > ### linear in age
> > estLogitLin <- glm( lfp ~ kids + age + educ,
> + family = binomial(link = "logit"),
> + data = Mroz87 )
> > summary( estLogitLin )
>
> Call:
> glm(formula = lfp ~ kids + age + educ, family = binomial(link = "logit"),
> data = Mroz87)
>
> Coefficients:
> Estimate Std. Error z value Pr(>|z|)
> (Intercept) -0.1144 0.7346 -0.16 0.8763
> kids -0.5035 0.1993 -2.53 0.0115 *
> age -0.0311 0.0114 -2.73 0.0063 **
> educ 0.1690 0.0351 4.82 1.4e-06 ***
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> (Dispersion parameter for binomial family taken to be 1)
>
> Null deviance: 1029.75 on 752 degrees of freedom
> Residual deviance: 993.53 on 749 degrees of freedom
> AIC: 1002
>
> Number of Fisher Scoring iterations: 4
>
> > # mean values of the explanatory variables
> > xMeanLin <- c( 1, colMeans( Mroz87[ , c( "kids", "age", "educ" ) ] ) )
> > # semi-elasticity of age without standard errors
> > urbinEla( coef( estLogitLin ), xMeanLin, xPos = 3, model = "logit" )
> semEla stdEr
> -0.3237 NA
> > # semi-elasticity of age based on numerical derivation
> > 100 * ( predict( estLogitLin,
> + newdata = as.data.frame( t( xMeanLin * c( 1, 1, 1.005, 1 ) ) ),
> + type = "response" ) -
> + predict( estLogitLin,
> + newdata = as.data.frame( t( xMeanLin * c( 1, 1, 0.995, 1 ) ) ),
> + type = "response" ) )
> 1
> -0.3237
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estLogitLin ), xMeanLin, 3, seSimplify = FALSE,
> + model = "logit" )$derivCoef
> kids age educ
> 0.04658 0.03242 12.39575 0.57236
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estLogitLin ),
> + allXVal = xMeanLin, xPos = 3, model = "logit" ) )
> + }
> (Intercept) kids age educ
> [1,] 0.04658 0.03242 12.4 0.5724
> > # simplified partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estLogitLin ), xMeanLin, 3, model = "logit",
> + seSimplify = TRUE )$derivCoef
> [1] 0.00 0.00 10.41 0.00
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinEla( coef( estLogitLin ), xMeanLin, 3, model = "logit",
> + vcov( estLogitLin ) )
> semEla stdEr
> -0.3237 0.1183
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinEla( coef( estLogitLin ), xMeanLin, 3, model = "logit",
> + sqrt( diag( vcov( estLogitLin ) ) ), seSimplify = FALSE )
> semEla stdEr
> -0.3237 0.1465
26,27c100,667
< In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
< there is no package called 'sampleSelection'
---
> In urbinEla(coef(estLogitLin), xMeanLin, 3, model = "logit", sqrt(diag(vcov(estLogitLin))), :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > # semi-elasticity of age with standard errors (only standard errors, simplified)
> > urbinEla( coef( estLogitLin ), xMeanLin, 3, model = "logit",
> + sqrt( diag( vcov( estLogitLin ) ) ) )
> semEla stdEr
> -0.3237 0.1184
> > # semi-elasticity of age based on partial derivative calculated by the mfx package
> > if( mfxLoaded ) {
> + estLogitLinMfx <- logitmfx( lfp ~ kids + age + educ, data = Mroz87 )
> + print( estLogitLinMfx$mfxest[ "age", 1:2 ] * xMeanLin[ "age" ] )
> + }
> dF/dx Std. Err.
> -0.3237 0.1183
> > if( mfxLoaded ) {
> + print( urbinEla( estLogitLinMfx$mfxest[ "age", 1 ], xMeanLin["age"], 1, iPos = 0,
> + model = "lpm", estLogitLinMfx$mfxest[ "age", 2 ] ) )
> + }
> semEla stdEr
> -0.3237 0.1183
> > if( mfxLoaded ) {
> + print( urbinEla( estLogitLinMfx$mfxest[ , 1 ], xMeanLin[-1], 2, iPos = 0,
> + model = "lpm", estLogitLinMfx$mfxest[ , 2 ] ) )
> + }
> semEla stdEr
> -0.3237 0.1183
> >
> >
> > ### quadratic in age
> > estLogitQuad <- glm( lfp ~ kids + age + I(age^2) + educ,
> + family = binomial(link = "logit"),
> + data = Mroz87 )
> > summary( estLogitQuad )
>
> Call:
> glm(formula = lfp ~ kids + age + I(age^2) + educ, family = binomial(link = "logit"),
> data = Mroz87)
>
> Coefficients:
> Estimate Std. Error z value Pr(>|z|)
> (Intercept) -6.94366 2.27412 -3.05 0.00226 **
> kids -0.70271 0.21334 -3.29 0.00099 ***
> age 0.30802 0.10737 2.87 0.00412 **
> I(age^2) -0.00400 0.00126 -3.17 0.00153 **
> educ 0.17229 0.03545 4.86 1.2e-06 ***
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> (Dispersion parameter for binomial family taken to be 1)
>
> Null deviance: 1029.75 on 752 degrees of freedom
> Residual deviance: 983.26 on 748 degrees of freedom
> AIC: 993.3
>
> Number of Fisher Scoring iterations: 4
>
> > # mean values of the explanatory variables
> > xMeanQuad <- c( xMeanLin[ 1:3 ], xMeanLin[3]^2, xMeanLin[4] )
> > # semi-elasticity of age without standard errors
> > urbinEla( coef( estLogitQuad ), xMeanQuad, c( 3, 4 ), model = "logit" )
> semEla stdEr
> -0.3172 NA
> > # semi-elasticity of age based on numerical derivation
> > 100 * ( predict( estLogitQuad,
> + newdata = as.data.frame( t( xMeanQuad * c( 1, 1, 1.005, 1.005^2, 1 ) ) ),
> + type = "response" ) -
> + predict( estLogitQuad,
> + newdata = as.data.frame( t( xMeanQuad * c( 1, 1, 0.995, 0.995^2, 1 ) ) ),
> + type = "response" ) )
> 1
> -0.3172
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estLogitQuad ), xMeanQuad, c( 3, 4 ), model = "logit",
> + seSimplify = FALSE )$derivCoef
> kids age age educ
> 0.08535 0.05939 13.49480 993.64782 1.04864
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estLogitQuad ),
> + allXVal = xMeanQuad, xPos = c( 3, 4 ), model = "logit" ) )
> + }
> (Intercept) kids age I(age^2) educ
> [1,] 0.08535 0.05939 13.49 993.6 1.049
> > # simplified partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estLogitQuad ), xMeanQuad, c( 3, 4 ), model = "logit",
> + seSimplify = TRUE )$derivCoef
> [1] 0.000 0.000 9.864 839.216 0.000
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinEla( coef( estLogitQuad ), xMeanQuad, c( 3, 4 ), model = "logit",
> + vcov( estLogitQuad ) )
> semEla stdEr
> -0.3172 0.1125
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinEla( coef( estLogitQuad ), xMeanQuad, c( 3, 4 ), model = "logit",
> + sqrt( diag( vcov( estLogitQuad ) ) ), seSimplify = FALSE )
> semEla stdEr
> -0.3172 1.9265
> Warning messages:
> 1: In urbinEla(coef(estLogitQuad), xMeanQuad, c(3, 4), model = "logit", :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> 2: In urbinEla(allCoef = coef(estLogitQuad), allXVal = xMeanQuad, xPos = c(3, 4), model = "logit", allCoefVcov = sqrt(diag(vcov(estLogitQuad))), seSimplify = FALSE) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # semi-elasticity of age with standard errors (only standard errors, simplified)
> > urbinEla( coef( estLogitQuad ), xMeanQuad, c( 3, 4 ), model = "logit",
> + sqrt( diag( vcov( estLogitQuad ) ) ) )
> semEla stdEr
> -0.3172 1.4979
> Warning message:
> In urbinEla(allCoef = coef(estLogitQuad), allXVal = xMeanQuad, xPos = c(3, 4), model = "logit", allCoefVcov = sqrt(diag(vcov(estLogitQuad)))) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # semi-elasticity of age with standard errors (only standard errors, xMeanSd)
> > urbinEla( coef( estLogitQuad ), xMeanQuad, c( 3, 4 ), model = "logit",
> + sqrt( diag( vcov( estLogitQuad ) ) ),
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ),
> + seSimplify = FALSE )
> semEla stdEr
> -0.31715 0.09913
> Warning message:
> In urbinEla(coef(estLogitQuad), xMeanQuad, c(3, 4), model = "logit", :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > # semi-elasticity of age with standard errors (only standard errors, xMeanSd, simplified)
> > urbinEla( coef( estLogitQuad ), xMeanQuad, c( 3, 4 ), model = "logit",
> + sqrt( diag( vcov( estLogitQuad ) ) ),
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> semEla stdEr
> -0.3172 0.1360
> > # semi-elasticity of age based on partial derivatives calculated by the mfx package
> > # (differs from the above, because mean(age)^2 is not the same as mean(age^2))
> > if( mfxLoaded ) {
> + estLogitQuadMfx <- logitmfx( lfp ~ kids + age + I(age^2) + educ, data = Mroz87 )
> + print( estLogitQuadMfx$mfxest[ "age", 1:2 ] * xMeanQuad[ "age" ] +
> + 2 * estLogitQuadMfx$mfxest[ "I(age^2)", 1:2 ] * xMeanQuad[ "age" ]^2 )
> + }
> dF/dx Std. Err.
> -0.3347 2.2359
> > if( mfxLoaded ) {
> + print( urbinEla( estLogitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 1 ],
> + xMeanQuad["age"], 1:2, iPos = 0,
> + model = "lpm", estLogitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 2 ] ) )
> + }
> semEla stdEr
> -0.3347 1.5810
> Warning message:
> In urbinEla(allCoef = estLogitQuadMfx$mfxest[c("age", "I(age^2)"), 1], allXVal = xMeanQuad["age"], xPos = 1:2, model = "lpm", allCoefVcov = estLogitQuadMfx$mfxest[c("age", "I(age^2)"), 2], iPos = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > if( mfxLoaded ) {
> + print( urbinEla( estLogitQuadMfx$mfxest[ , 1 ],
> + xMeanQuad[-1], 2:3, iPos = 0,
> + model = "lpm", estLogitQuadMfx$mfxest[ , 2 ] ) )
> + }
> semEla stdEr
> -0.3347 1.5810
> Warning message:
> In urbinEla(allCoef = estLogitQuadMfx$mfxest[, 1], allXVal = xMeanQuad[-1], xPos = 2:3, model = "lpm", allCoefVcov = estLogitQuadMfx$mfxest[, 2], iPos = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > if( mfxLoaded ) {
> + print( urbinEla( estLogitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 1 ],
> + xMeanQuad["age"], 1:2, iPos = 0,
> + model = "lpm", estLogitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 2 ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) ) )
> + }
> semEla stdEr
> -0.3347 0.1435
> > if( mfxLoaded ) {
> + print( urbinEla( estLogitQuadMfx$mfxest[ , 1 ],
> + xMeanQuad[-1], 2:3, iPos = 0,
> + model = "lpm", estLogitQuadMfx$mfxest[ , 2 ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) ) )
> + }
> semEla stdEr
> -0.3347 0.1435
> >
> >
> > ### age is interval-coded (age is in the range 30-60)
> > # create dummy variables for age intervals
> > Mroz87$age30.37 <- Mroz87$age >= 30 & Mroz87$age <= 37
> > Mroz87$age38.44 <- Mroz87$age >= 38 & Mroz87$age <= 44
> > Mroz87$age45.52 <- Mroz87$age >= 45 & Mroz87$age <= 52
> > Mroz87$age53.60 <- Mroz87$age >= 53 & Mroz87$age <= 60
> > all.equal(
> + Mroz87$age30.37 + Mroz87$age38.44 + Mroz87$age45.52 + Mroz87$age53.60,
> + rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > # estimation
> > estLogitInt <- glm( lfp ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + family = binomial(link = "logit"),
> + data = Mroz87 )
> > summary( estLogitInt )
>
> Call:
> glm(formula = lfp ~ kids + age30.37 + age38.44 + age53.60 + educ,
> family = binomial(link = "logit"), data = Mroz87)
>
> Coefficients:
> Estimate Std. Error z value Pr(>|z|)
> (Intercept) -1.4441 0.4548 -3.18 0.0015 **
> kids -0.6045 0.2080 -2.91 0.0037 **
> age30.37TRUE 0.2208 0.2060 1.07 0.2839
> age38.44TRUE 0.1973 0.2203 0.90 0.3704
> age53.60TRUE -0.8271 0.2653 -3.12 0.0018 **
> educ 0.1743 0.0354 4.93 8.2e-07 ***
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> (Dispersion parameter for binomial family taken to be 1)
>
> Null deviance: 1029.75 on 752 degrees of freedom
> Residual deviance: 987.04 on 747 degrees of freedom
> AIC: 999
>
> Number of Fisher Scoring iterations: 4
>
> > # mean values of the explanatory variables
> > xMeanInt <- c( xMeanLin[1:2], mean( Mroz87$age30.37 ),
> + mean( Mroz87$age38.44 ), mean( Mroz87$age53.60 ), xMeanLin[4] )
> > # semi-elasticity of age without standard errors
> > urbinElaInt( coef( estLogitInt ), xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "logit" )
> semEla stdEr
> -0.3777 NA
> > # semi-elasticities based on numerical derivation
> > Mroz87Lower <- Mroz87
> > Mroz87Lower$age <- Mroz87$age * 0.95
> > Mroz87Lower$age30.37 <- Mroz87Lower$age <= 37.5
> > Mroz87Lower$age38.44 <- Mroz87Lower$age > 37.5 & Mroz87Lower$age <= 44.5
> > Mroz87Lower$age45.52 <- Mroz87Lower$age > 44.5 & Mroz87Lower$age <= 52.5
> > Mroz87Lower$age53.60 <- Mroz87Lower$age > 52.5
> > all.equal(
> + Mroz87Lower$age30.37 + Mroz87Lower$age38.44 + Mroz87Lower$age45.52 +
> + Mroz87Lower$age53.60, rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > Mroz87Upper <- Mroz87
> > Mroz87Upper$age <- Mroz87$age * 1.05
> > Mroz87Upper$age30.37 <- Mroz87Upper$age <= 37.5
> > Mroz87Upper$age38.44 <- Mroz87Upper$age > 37.5 & Mroz87Upper$age <= 44.5
> > Mroz87Upper$age45.52 <- Mroz87Upper$age > 44.5 & Mroz87Upper$age <= 52.5
> > Mroz87Upper$age53.60 <- Mroz87Upper$age > 52.5
> > all.equal(
> + Mroz87Upper$age30.37 + Mroz87Upper$age38.44 + Mroz87Upper$age45.52 +
> + Mroz87Upper$age53.60, rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > 10 * mean( predict( estLogitInt, newdata = Mroz87Upper, type = "response" ) -
> + predict( estLogitInt, newdata = Mroz87Lower, type = "response" ) )
> [1] -0.351
> > Mroz87LowerMean <- Mroz87Lower
> > Mroz87UpperMean <- Mroz87Upper
> > Mroz87LowerMean$kids <- Mroz87UpperMean$kids <- xMeanInt[ "kids" ]
> > Mroz87LowerMean$educ <- Mroz87UpperMean$educ <- xMeanInt[ "educ" ]
> > 10 * mean( predict( estLogitInt, newdata = Mroz87UpperMean, type = "response" ) -
> + predict( estLogitInt, newdata = Mroz87LowerMean, type = "response" ) )
> [1] -0.3688
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinElaInt( coef( estLogitInt ), xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "logit" )$derivCoef
> [1] -0.003229 -0.002247 -0.343126 -0.030585 0.336143 -0.039678
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinElaInt( x, ... )$semEla },
> + t0 = coef( estLogitInt ), allXVal = xMeanInt,
> + xPos = c( 3, 4, 0, 5 ), xBound = c( 30, 37.5, 44.5, 52.5, 60 ),
> + model = "logit" ) )
> + }
> (Intercept) kids age30.37TRUE age38.44TRUE age53.60TRUE educ
> [1,] -0.003229 -0.002247 -0.3431 -0.03058 0.3361 -0.03968
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinElaInt( coef( estLogitInt ), xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "logit",
> + allCoefVcov = vcov( estLogitInt ) )
> semEla stdEr
> -0.3777 0.1017
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinElaInt( coef( estLogitInt ), xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "logit",
> + allCoefVcov = sqrt( diag( vcov( estLogitInt ) ) ) )
> semEla stdEr
> -0.3777 0.1140
> > # semi-elasticity of age based on partial derivatives calculated by the mfx package
> > if( mfxLoaded ) {
> + estLogitIntMfx <- logitmfx( lfp ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + data = Mroz87 )
> + print( urbinElaInt( estLogitIntMfx$mfxest[ 2:4, 1 ], xMeanInt[ 3:5 ],
> + c( 1, 2, 0, 3 ), iPos = 0, c( 30, 37.5, 44.5, 52.5, 60 ), model = "lpm",
> + estLogitIntMfx$mfxest[ 2:4, 2 ] ) )
> + }
> semEla stdEr
> -0.3799 0.1173
> > if( mfxLoaded ) {
> + print( urbinElaInt( estLogitIntMfx$mfxest[ , 1 ], xMeanInt[ -1 ],
> + c( 2, 3, 0, 4 ), iPos = 0, c( 30, 37.5, 44.5, 52.5, 60 ), model = "lpm",
> + estLogitIntMfx$mfxest[ , 2 ] ) )
> + }
> semEla stdEr
> -0.3799 0.1173
> >
> >
> > ### effect of age changing between discrete intervals
> > ### if age is used as linear explanatory variable
> > # mean values of the 'other' explanatory variables
> > xMeanLinInt <- c( xMeanLin[ 1:2 ], NA, xMeanLin[4] )
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # without standard errors
> > urbinEffInt( coef( estLogitLin ), allXVal = xMeanLinInt, xPos = 3,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "logit" )
> effect stdEr
> -0.1525 NA
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # based on predicted values
> > predict( estLogitLin,
> + newdata = as.data.frame( t( replace( xMeanLin, 3, 55 ) ) ),
> + type = "response" ) -
> + predict( estLogitLin,
> + newdata = as.data.frame( t( replace( xMeanLin, 3, 35 ) ) ),
> + type = "response" )
> 1
> -0.1525
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEffInt( coef( estLogitLin ), xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "logit" )$derivCoef
> [1] 0.01582 0.01101 5.54183 0.19437
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estLogitLin ),
> + allXVal = xMeanLinInt, xPos = 3,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "logit" ) )
> + }
> (Intercept) kids age educ
> [1,] 0.01582 0.01101 5.542 0.1944
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (full covariance matrix)
> > urbinEffInt( coef( estLogitLin ), xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "logit", allCoefVcov = vcov( estLogitLin ) )
> effect stdEr
> -0.15247 0.05533
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (only standard errors)
> > urbinEffInt( coef( estLogitLin ), allXVal = xMeanLinInt, xPos = 3,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "logit",
> + allCoefVcov = sqrt( diag( vcov( estLogitLin ) ) ) )
> effect stdEr
> -0.15247 0.06446
> > # semi-elasticity of age based on partial derivative calculated by the mfx package
> > if( mfxLoaded ) {
> + print( urbinEffInt( estLogitLinMfx$mfxest[ "age", 1 ], NULL, 1, iPos = 0,
> + c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estLogitLinMfx$mfxest[ "age", 2 ] ) )
> + }
> effect stdEr
> -0.15219 0.05564
> > if( mfxLoaded ) {
> + print( urbinEffInt( estLogitLinMfx$mfxest[ , 1 ], NULL, 2, iPos = 0,
> + c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estLogitLinMfx$mfxest[ , 2 ] ) )
> + }
> effect stdEr
> -0.15219 0.05564
> >
> >
> > ### effect of age changing between discrete intervals
> > ### if age is used as linear and quadratic explanatory variable
> > # mean values of the 'other' explanatory variables
> > xMeanQuadInt <- c( xMeanLin[ 1:2 ], NA, NA, xMeanLin[4] )
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # without standard errors
> > urbinEffInt( coef( estLogitQuad ), allXVal = xMeanQuadInt,
> + xPos = c( 3, 4 ), refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "logit" )
> effect stdEr
> -0.2535 NA
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # based on predicted values
> > predict( estLogitQuad,
> + newdata = as.data.frame( t( replace( xMeanQuad, 3:4, c( 55, 55^2 ) ) ) ),
> + type = "response" ) -
> + predict( estLogitQuad,
> + newdata = as.data.frame( t( replace( xMeanQuad, 3:4, c( 35, 35^2 ) ) ) ),
> + type = "response" )
> 1
> -0.2534
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffInt( coef( estLogitQuad ), xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "logit" )$derivCoef
> [1] 1.806e-03 1.257e-03 4.760e+00 4.249e+02 2.219e-02
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estLogitQuad ),
> + allXVal = xMeanQuadInt, xPos = c( 3, 4 ),
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "logit" ) )
> + }
> (Intercept) kids age I(age^2) educ
> [1,] 0.001806 0.001257 4.76 424.9 0.02219
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (full covariance matrix)
> > urbinEffInt( coef( estLogitQuad ), xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "logit",
> + allCoefVcov = vcov( estLogitQuad ) )
> effect stdEr
> -0.25354 0.06224
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (only standard errors)
> > urbinEffInt( coef( estLogitQuad ), allXVal = xMeanQuadInt,
> + xPos = c( 3, 4 ), refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "logit", allCoefVcov = sqrt( diag( vcov( estLogitQuad ) ) ) )
> effect stdEr
> -0.2535 0.7408
> Warning message:
> In urbinEffInt(allCoef = coef(estLogitQuad), allXVal = xMeanQuadInt, xPos = c(3, 4), refBound = c(30, 40), intBound = c(50, 60), model = "logit", allCoefVcov = sqrt(diag(vcov(estLogitQuad)))) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (standard errors + mean value and standard deviation of age)
> > urbinEffInt( coef( estLogitQuad ), xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "logit",
> + allCoefVcov = sqrt( diag( vcov( estLogitQuad ) ) ),
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> effect stdEr
> -0.25354 0.07205
> > # semi-elasticity of age based on partial derivative calculated by the mfx package
> > if( mfxLoaded ) {
> + print( urbinEffInt( estLogitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 1 ], NULL, 1:2,
> + iPos = 0, c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estLogitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 2 ] ) )
> + }
> effect stdEr
> -0.2538 0.7652
> Warning message:
> In urbinEffInt(allCoef = estLogitQuadMfx$mfxest[c("age", "I(age^2)"), 1], allXVal = NULL, xPos = 1:2, refBound = c(30, 40), intBound = c(50, 60), model = "lpm", allCoefVcov = estLogitQuadMfx$mfxest[c("age", "I(age^2)"), 2], iPos = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > if( mfxLoaded ) {
> + print( urbinEffInt( estLogitQuadMfx$mfxest[ , 1 ], NULL, 2:3,
> + iPos = 0, c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estLogitQuadMfx$mfxest[ , 2 ] ) )
> + }
> effect stdEr
> -0.2538 0.7652
> Warning message:
> In urbinEffInt(allCoef = estLogitQuadMfx$mfxest[, 1], allXVal = NULL, xPos = 2:3, refBound = c(30, 40), intBound = c(50, 60), model = "lpm", allCoefVcov = estLogitQuadMfx$mfxest[, 2], iPos = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > if( mfxLoaded ) {
> + print( urbinEffInt( estLogitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 1 ], NULL, 1:2,
> + iPos = 0, c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estLogitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 2 ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) ) )
> + }
> effect stdEr
> -0.25377 0.07577
> > if( mfxLoaded ) {
> + print( urbinEffInt( estLogitQuadMfx$mfxest[ , 1 ], NULL, 2:3,
> + iPos = 0, c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estLogitQuadMfx$mfxest[ , 2 ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) ) )
> + }
> effect stdEr
> -0.25377 0.07577
> >
> >
> > ### grouping and re-basing categorical variables
> > ### effects of age changing from the 30-44 category to the 53-60 category
> > # without standard errors
> > urbinEffCat( coef( estLogitInt ), xMeanInt, c( 3:5 ), c( -1, -1, 1, 0 ),
> + model = "logit" )
> effect stdEr
> -0.2538 NA
> > # effects calculated based on predicted values
> > names( xMeanInt ) <- sub( "TRUE", "", names( coef( estLogitInt ) ) )
> > df30.37 <- df38.44 <- df45.52 <- df53.60 <- as.data.frame( t( xMeanInt ) )
> > df30.37[ , 3:5 ] <- c( TRUE, FALSE, FALSE )
> > df38.44[ , 3:5 ] <- c( FALSE, TRUE, FALSE )
> > df45.52[ , 3:5 ] <- c( FALSE, FALSE, FALSE )
> > df53.60[ , 3:5 ] <- c( FALSE, FALSE, TRUE )
> > predict( estLogitInt, newdata = df53.60, type = "response" ) -
> + sum( Mroz87$age30.37 ) / sum( Mroz87$age30.37 + Mroz87$age38.44 ) *
> + predict( estLogitInt, newdata = df30.37, type = "response" ) -
> + sum( Mroz87$age38.44 ) / sum( Mroz87$age30.37 + Mroz87$age38.44 ) *
> + predict( estLogitInt, newdata = df38.44, type = "response" )
> 1
> -0.2538
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffCat( coef( estLogitInt ), xMeanInt, c( 3:5 ),
> + c( -1, -1, 1, 0 ), model = "logit" )$derivCoef
> [1] -0.003642 -0.002534 -0.138529 -0.097136 0.232023 -0.044745
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estLogitInt ),
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ),
> + model = "logit" ) )
> + }
> (Intercept) kids age30.37TRUE age38.44TRUE age53.60TRUE educ
> [1,] -0.003642 -0.002534 -0.1385 -0.09714 0.232 -0.04474
> > # with full covariance matrix
> > urbinEffCat( coef( estLogitInt ), xMeanInt, c( 3:5 ), c( -1, -1, 1, 0 ),
> + allCoefVcov = vcov( estLogitInt ), model = "logit" )
> effect stdEr
> -0.25381 0.06583
> > # with standard errors only
> > urbinEffCat( coef( estLogitInt ), xMeanInt, c( 3:5 ), c( -1, -1, 1, 0 ),
> + allCoefVcov = sqrt( diag( vcov( estLogitInt ) ) ), model = "logit" )
> effect stdEr
> -0.25381 0.07119
> > # semi-elasticity of age based on partial derivative calculated by the mfx package
> > if( mfxLoaded ) {
> + print( urbinEffCat( estLogitIntMfx$mfxest[ 2:4, 1 ], xMeanInt[ 3:5 ], c(1:3),
> + c( -1, -1, 1, 0 ), iPos = 0, model = "lpm", estLogitIntMfx$mfxest[ 2:4, 2 ] ) )
> + }
> effect stdEr
> -0.25514 0.07315
> > if( mfxLoaded ) {
> + print( urbinEffCat( estLogitIntMfx$mfxest[ , 1 ], xMeanInt[ -1 ], c(2:4),
> + c( -1, -1, 1, 0 ), iPos = 0, model = "lpm", estLogitIntMfx$mfxest[ , 2 ] ) )
> + }
> effect stdEr
> -0.25514 0.07315
> >
> >
> > ### effects of age changing from the 53-60 category to the 38-52 category
> > # without standard errors
> > urbinEffCat( coef( estLogitInt ), xMeanInt, c( 3:5 ), c( 0, 1, -1, 1 ),
> + model = "logit" )
> effect stdEr
> 0.2239 NA
> > # effects calculated based on predicted values
> > sum( Mroz87$age38.44 ) / sum( Mroz87$age38.44 + Mroz87$age45.52 ) *
> + predict( estLogitInt, newdata = df38.44, type = "response" ) +
> + sum( Mroz87$age45.52 ) / sum( Mroz87$age38.44 + Mroz87$age45.52 ) *
> + predict( estLogitInt, newdata = df45.52, type = "response" ) -
> + predict( estLogitInt, newdata = df53.60, type = "response" )
> 1
> 0.2236
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffCat( coef( estLogitInt ), xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), model = "logit" )$derivCoef
> [1] 0.009917 0.006901 0.000000 0.105139 -0.232023 0.121846
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estLogitInt ),
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( 0, 1, -1, 1 ),
> + model = "logit" ) )
> + }
> (Intercept) kids age30.37TRUE age38.44TRUE age53.60TRUE educ
> [1,] 0.009917 0.006901 0 0.1051 -0.232 0.1218
> > # with full covariance matrix
> > urbinEffCat( coef( estLogitInt ), xMeanInt, c( 3:5 ), c( 0, 1, -1, 1 ),
> + allCoefVcov = vcov( estLogitInt ), model = "logit" )
> effect stdEr
> 0.22386 0.06109
> > # with standard errors only
> > urbinEffCat( coef( estLogitInt ), xMeanInt, c( 3:5 ), c( 0, 1, -1, 1 ),
> + allCoefVcov = sqrt( diag( vcov( estLogitInt ) ) ), model = "logit" )
> effect stdEr
> 0.22386 0.06609
> > # semi-elasticity of age based on partial derivative calculated by the mfx package
> > if( mfxLoaded ) {
> + print( urbinEffCat( estLogitIntMfx$mfxest[ 2:4, 1 ], xMeanInt[ 3:5 ], c(1:3),
> + c( 0, 1, -1, 1 ), iPos = 0, model = "lpm", estLogitIntMfx$mfxest[ 2:4, 2 ] ) )
> + }
> effect stdEr
> 0.22466 0.06745
> > if( mfxLoaded ) {
> + print( urbinEffCat( estLogitIntMfx$mfxest[ , 1 ], xMeanInt[ -1 ], c(2:4),
> + c( 0, 1, -1, 1 ), iPos = 0, model = "lpm", estLogitIntMfx$mfxest[ , 2 ] ) )
> + }
> effect stdEr
> 0.22466 0.06745
> >
> >
Running ‘logitEffCat.R’ [0s/0s]
Comparing ‘logitEffCat.Rout’ to ‘logitEffCat.Rout.save’ ... OK
Running ‘logitEffInt.R’ [0s/0s]
Comparing ‘logitEffInt.Rout’ to ‘logitEffInt.Rout.save’ ... OK
Running ‘logitEla.R’ [0s/0s]
Comparing ‘logitEla.Rout’ to ‘logitEla.Rout.save’ ... OK
Running ‘logitElaInt.R’ [0s/0s]
Comparing ‘logitElaInt.Rout’ to ‘logitElaInt.Rout.save’ ... OK
Running ‘lpm.R’ [0s/0s]
Comparing ‘lpm.Rout’ to ‘lpm.Rout.save’ ...
14,16c14,179
< > proc.time()
< user system elapsed
< 0.249 0.061 0.303
---
> > options( digits = 4 )
> >
> > # load data set
> > data( "Mroz87", package = "sampleSelection" )
> >
> > # create dummy variable for kids
> > Mroz87$kids <- as.numeric( Mroz87$kids5 > 0 | Mroz87$kids618 > 0 )
> >
> > ### linear in age
> > estLpmLin <- lm( lfp ~ kids + age + educ,
> + data = Mroz87 )
> > summary( estLpmLin )
>
> Call:
> lm(formula = lfp ~ kids + age + educ, data = Mroz87)
>
> Residuals:
> Min 1Q Median 3Q Max
> -0.861 -0.530 0.275 0.431 0.711
>
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) 0.47432 0.17069 2.78 0.0056 **
> kids -0.11481 0.04564 -2.52 0.0121 *
> age -0.00716 0.00262 -2.73 0.0064 **
> educ 0.03893 0.00781 4.98 7.8e-07 ***
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> Residual standard error: 0.485 on 749 degrees of freedom
> Multiple R-squared: 0.0466, Adjusted R-squared: 0.0427
> F-statistic: 12.2 on 3 and 749 DF, p-value: 8.5e-08
>
> > # mean values of the explanatory variables
> > xMeanLin <- c( 1, colMeans( Mroz87[ , c( "kids", "age", "educ" ) ] ) )
> > # semi-elasticity of age without standard errors
> > urbinEla( coef( estLpmLin )[ "age" ], xMeanLin[ "age" ], xPos = 1, iPos = 0,
> + model = "lpm" )
> semEla stdEr
> -0.3044 NA
> > urbinEla( coef( estLpmLin ), xMeanLin, xPos = 3, model = "lpm" )
> semEla stdEr
> -0.3044 NA
> > # semi-elasticity of age based on numerical derivation
> > 100 * ( predict( estLpmLin,
> + newdata = as.data.frame( t( xMeanLin * c( 1, 1, 1.005, 1 ) ) ) ) -
> + predict( estLpmLin,
> + newdata = as.data.frame( t( xMeanLin * c( 1, 1, 0.995, 1 ) ) ) ) )
> 1
> -0.3044
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estLpmLin )["age"], xMeanLin["age"], xPos = 1, iPos = 0,
> + model = "lpm" )$derivCoef
> [1] 42.54
> > urbinEla( coef( estLpmLin ), xMeanLin, xPos = 3, model = "lpm" )$derivCoef
> [1] 0.00 0.00 42.54 0.00
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estLpmLin )["age"],
> + allXVal = xMeanLin["age"], xPos = 1, iPos = 0, model = "lpm" ) )
> + }
> age
> [1,] 42.54
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estLpmLin ),
> + allXVal = xMeanLin, xPos = 3, model = "lpm" ) )
> + }
> (Intercept) kids age educ
> [1,] 0 0 42.54 0
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinEla( coef( estLpmLin ), xMeanLin, xPos = 3, model = "lpm",
> + vcov( estLpmLin ) )
> semEla stdEr
> -0.3044 0.1114
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinEla( coef( estLpmLin )["age"], xMeanLin["age"], xPos = 1, iPos = 0,
> + model = "lpm", sqrt( diag( vcov( estLpmLin ) ) )["age"] )
> semEla stdEr
> -0.3044 0.1114
> > urbinEla( coef( estLpmLin ), xMeanLin, xPos = 3, model = "lpm",
> + sqrt( diag( vcov( estLpmLin ) ) ) )
> semEla stdEr
> -0.3044 0.1114
> >
> > ### quadratic in age
> > estLpmQuad <- lm( lfp ~ kids + age + I(age^2) + educ,
> + data = Mroz87 )
> > summary( estLpmQuad )
>
> Call:
> lm(formula = lfp ~ kids + age + I(age^2) + educ, data = Mroz87)
>
> Residuals:
> Min 1Q Median 3Q Max
> -0.869 -0.531 0.270 0.428 0.742
>
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) -1.095252 0.518174 -2.11 0.03487 *
> kids -0.157282 0.047256 -3.33 0.00092 ***
> age 0.070988 0.024515 2.90 0.00389 **
> I(age^2) -0.000921 0.000287 -3.21 0.00140 **
> educ 0.039008 0.007764 5.02 6.3e-07 ***
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> Residual standard error: 0.482 on 748 degrees of freedom
> Multiple R-squared: 0.0595, Adjusted R-squared: 0.0545
> F-statistic: 11.8 on 4 and 748 DF, p-value: 2.54e-09
>
> > # mean values of the explanatory variables
> > xMeanQuad <- c( xMeanLin[ 1:3 ], xMeanLin[3]^2, xMeanLin[4] )
> > # semi-elasticity of age without standard errors
> > urbinEla( coef( estLpmQuad )[ c( "age", "I(age^2)" ) ], xMeanQuad[ "age" ],
> + xPos = c( 1, 2 ), iPos = 0, model = "lpm" )
> semEla stdEr
> -0.3122 NA
> > urbinEla( coef( estLpmQuad ), xMeanQuad, xPos = c( 3, 4 ), model = "lpm" )
> semEla stdEr
> -0.3122 NA
> > # semi-elasticity of age based on numerical derivation
> > 100 * ( predict( estLpmQuad,
> + newdata = as.data.frame( t( xMeanQuad * c( 1, 1, 1.005, 1.005^2, 1 ) ) ) ) -
> + predict( estLpmQuad,
> + newdata = as.data.frame( t( xMeanQuad * c( 1, 1, 0.995, 0.995^2, 1 ) ) ) ) )
> 1
> -0.3122
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estLpmQuad )[ c( "age", "I(age^2)" ) ], xMeanQuad[ "age" ],
> + xPos = c( 1, 2 ), iPos = 0, model = "lpm" )$derivCoef
> [1] 42.54 3618.94
> > urbinEla( coef( estLpmQuad ), xMeanQuad, xPos = c( 3, 4 ), model = "lpm" )$derivCoef
> [1] 0.00 0.00 42.54 3618.94 0.00
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estLpmQuad )[ c( "age", "I(age^2)" ) ],
> + allXVal = xMeanQuad[ "age" ], xPos = c( 1, 2 ), iPos = 0, model = "lpm" ) )
> + }
> age I(age^2)
> [1,] 42.54 3619
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estLpmQuad ),
> + allXVal = xMeanQuad, xPos = c( 3, 4 ), model = "lpm" ) )
> + }
> (Intercept) kids age I(age^2) educ
> [1,] 0 0 42.54 3619 0
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinEla( coef( estLpmQuad )[ c( "age", "I(age^2)" ) ], xMeanQuad["age"],
> + xPos = c( 1, 2 ), iPos = 0, model = "lpm",
> + vcov( estLpmQuad )[ c( "age", "I(age^2)" ), c( "age", "I(age^2)" ) ] )
> semEla stdEr
> -0.3122 0.1107
> > urbinEla( coef( estLpmQuad ), xMeanQuad, xPos = c( 3, 4 ), model = "lpm",
> + vcov( estLpmQuad ) )
> semEla stdEr
> -0.3122 0.1107
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinEla( coef( estLpmQuad )[ c( "age", "I(age^2)" ) ], xMeanQuad[ "age" ],
> + xPos = c( 1, 2 ), iPos = 0, model = "lpm",
> + sqrt( diag( vcov( estLpmQuad ) ) )[ c( "age", "I(age^2)" ) ] )
> semEla stdEr
> -0.3122 1.4723
18,19c181,613
< In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
< there is no package called 'sampleSelection'
---
> In urbinEla(allCoef = coef(estLpmQuad)[c("age", "I(age^2)")], allXVal = xMeanQuad["age"], xPos = c(1, 2), model = "lpm", allCoefVcov = sqrt(diag(vcov(estLpmQuad)))[c("age", "I(age^2)")], iPos = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEla( coef( estLpmQuad ), xMeanQuad, xPos = c( 3, 4 ), model = "lpm",
> + sqrt( diag( vcov( estLpmQuad ) ) ) )
> semEla stdEr
> -0.3122 1.4723
> Warning message:
> In urbinEla(allCoef = coef(estLpmQuad), allXVal = xMeanQuad, xPos = c(3, 4), model = "lpm", allCoefVcov = sqrt(diag(vcov(estLpmQuad)))) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # semi-elasticity of age with standard errors (only standard errors, xMeanSd)
> > urbinEla( coef( estLpmQuad )[ c( "age", "I(age^2)" ) ], xMeanQuad["age"],
> + xPos = c( 1, 2 ), iPos = 0, model = "lpm",
> + sqrt( diag( vcov( estLpmQuad ) ) )[ c( "age", "I(age^2)" ) ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> semEla stdEr
> -0.3122 0.1337
> > urbinEla( coef( estLpmQuad ), xMeanQuad, xPos = c( 3, 4 ), model = "lpm",
> + sqrt( diag( vcov( estLpmQuad ) ) ),
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> semEla stdEr
> -0.3122 0.1337
> >
> > ### age is interval-coded (age is in the range 30-60)
> > # create dummy variables for age intervals
> > Mroz87$age30.37 <- Mroz87$age >= 30 & Mroz87$age <= 37
> > Mroz87$age38.44 <- Mroz87$age >= 38 & Mroz87$age <= 44
> > Mroz87$age45.52 <- Mroz87$age >= 45 & Mroz87$age <= 52
> > Mroz87$age53.60 <- Mroz87$age >= 53 & Mroz87$age <= 60
> > all.equal(
> + Mroz87$age30.37 + Mroz87$age38.44 + Mroz87$age45.52 + Mroz87$age53.60,
> + rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > # estimation
> > estLpmInt <- lm( lfp ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + data = Mroz87 )
> > summary( estLpmInt )
>
> Call:
> lm(formula = lfp ~ kids + age30.37 + age38.44 + age53.60 + educ,
> data = Mroz87)
>
> Residuals:
> Min 1Q Median 3Q Max
> -0.858 -0.523 0.279 0.437 0.780
>
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) 0.17366 0.10237 1.70 0.0902 .
> kids -0.13594 0.04666 -2.91 0.0037 **
> age30.37TRUE 0.05019 0.04773 1.05 0.2934
> age38.44TRUE 0.04545 0.05130 0.89 0.3759
> age53.60TRUE -0.19102 0.06105 -3.13 0.0018 **
> educ 0.03960 0.00777 5.10 4.4e-07 ***
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> Residual standard error: 0.483 on 747 degrees of freedom
> Multiple R-squared: 0.0547, Adjusted R-squared: 0.0484
> F-statistic: 8.65 on 5 and 747 DF, p-value: 5.54e-08
>
> > # coefficients of the 'intervals'
> > coefLpmInt <- c( coef( estLpmInt )[3:4], 0, coef( estLpmInt )[5] )
> > # mean values of the explanatory variables
> > xMeanInt <- c( xMeanLin[1:2], mean( Mroz87$age30.37 ),
> + mean( Mroz87$age38.44 ), mean( Mroz87$age53.60 ), xMeanLin[4] )
> > # mean shares of the 'intervals'
> > xMeanIntShares <- c( xMeanInt[3:4], 1 - sum( xMeanInt[3:5] ), xMeanInt[5] )
> > # semi-elasticity of age without standard errors
> > urbinElaInt( coef( estLpmInt )[3:5], xMeanInt[3:5],
> + c( 30, 37.5, 44.5, 52.5, 60 ), xPos = c( 1, 2, 0, 3 ), iPos = 0,
> + model = "lpm" )
> semEla stdEr
> -0.3559 NA
> > urbinElaInt( coef( estLpmInt ), xMeanInt,
> + c( 30, 37.5, 44.5, 52.5, 60 ), xPos = c( 3, 4, 0, 5 ), model = "lpm" )
> semEla stdEr
> -0.3559 NA
> > # semi-elasticities based on numerical derivation
> > Mroz87Lower <- Mroz87
> > Mroz87Lower$age <- Mroz87$age * 0.95
> > Mroz87Lower$age30.37 <- Mroz87Lower$age <= 37.5
> > Mroz87Lower$age38.44 <- Mroz87Lower$age > 37.5 & Mroz87Lower$age <= 44.5
> > Mroz87Lower$age45.52 <- Mroz87Lower$age > 44.5 & Mroz87Lower$age <= 52.5
> > Mroz87Lower$age53.60 <- Mroz87Lower$age > 52.5
> > all.equal(
> + Mroz87Lower$age30.37 + Mroz87Lower$age38.44 + Mroz87Lower$age45.52 +
> + Mroz87Lower$age53.60, rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > Mroz87Upper <- Mroz87
> > Mroz87Upper$age <- Mroz87$age * 1.05
> > Mroz87Upper$age30.37 <- Mroz87Upper$age <= 37.5
> > Mroz87Upper$age38.44 <- Mroz87Upper$age > 37.5 & Mroz87Upper$age <= 44.5
> > Mroz87Upper$age45.52 <- Mroz87Upper$age > 44.5 & Mroz87Upper$age <= 52.5
> > Mroz87Upper$age53.60 <- Mroz87Upper$age > 52.5
> > all.equal(
> + Mroz87Upper$age30.37 + Mroz87Upper$age38.44 + Mroz87Upper$age45.52 +
> + Mroz87Upper$age53.60, rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > 10 * mean( predict( estLpmInt, newdata = Mroz87Upper ) -
> + predict( estLpmInt, newdata = Mroz87Lower ) )
> [1] -0.3475
> > Mroz87LowerMean <- Mroz87Lower
> > Mroz87UpperMean <- Mroz87Upper
> > Mroz87LowerMean$kids <- Mroz87UpperMean$kids <- xMeanInt[ "kids" ]
> > Mroz87LowerMean$educ <- Mroz87UpperMean$educ <- xMeanInt[ "educ" ]
> > 10 * mean( predict( estLpmInt, newdata = Mroz87UpperMean ) -
> + predict( estLpmInt, newdata = Mroz87LowerMean ) )
> [1] -0.3475
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinElaInt( coef( estLpmInt )[3:5], xMeanInt[3:5],
> + c( 30, 37.5, 44.5, 52.5, 60 ), xPos = c( 1, 2, 0, 3 ), iPos = 0,
> + model = "lpm" )$derivCoef
> [1] -1.4594 -0.1294 1.4487
> > urbinElaInt( coef( estLpmInt ), xMeanInt,
> + c( 30, 37.5, 44.5, 52.5, 60 ), xPos = c( 3, 4, 0, 5 ), model = "lpm" )$derivCoef
> [1] 0.0000 0.0000 -1.4594 -0.1294 1.4487 0.0000
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinElaInt( x, ... )$semEla },
> + t0 = coef( estLpmInt )[3:5], allXVal = xMeanInt[3:5],
> + xBound = c( 30, 37.5, 44.5, 52.5, 60 ), xPos = c( 1, 2, 0, 3 ), iPos = 0,
> + model = "lpm" ) )
> + }
> age30.37TRUE age38.44TRUE age53.60TRUE
> [1,] -1.459 -0.1294 1.449
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinElaInt( x, ... )$semEla },
> + t0 = coef( estLpmInt ), allXVal = xMeanInt,
> + xBound = c( 30, 37.5, 44.5, 52.5, 60 ), xPos = c( 3, 4, 0, 5 ),
> + model = "lpm" ) )
> + }
> (Intercept) kids age30.37TRUE age38.44TRUE age53.60TRUE educ
> [1,] 0 0 -1.459 -0.1294 1.449 0
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > vcovLpmInt <- vcov( estLpmInt )
> > vcovLpmInt <- rbind( vcovLpmInt[ 3:4, ], 0, vcovLpmInt[ 5, ] )
> > vcovLpmInt <- cbind( vcovLpmInt[ , 3:4 ], 0, vcovLpmInt[ , 5 ] )
> > urbinElaInt( coef( estLpmInt )[3:5], xMeanInt[3:5],
> + c( 30, 37.5, 44.5, 52.5, 60 ), xPos = c( 1, 2, 0, 3 ), iPos = 0,
> + model = "lpm", allCoefVcov = vcov( estLpmInt )[ 3:5, 3:5 ] )
> semEla stdEr
> -0.35586 0.09966
> > urbinElaInt( coef( estLpmInt ), xMeanInt,
> + c( 30, 37.5, 44.5, 52.5, 60 ), xPos = c( 3, 4, 0, 5 ), model = "lpm",
> + allCoefVcov = vcov( estLpmInt ) )
> semEla stdEr
> -0.35586 0.09966
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinElaInt( coef( estLpmInt )[3:5], xMeanInt[3:5],
> + c( 30, 37.5, 44.5, 52.5, 60 ), xPos = c( 1, 2, 0, 3 ), iPos = 0,
> + model = "lpm", allCoefVcov = sqrt( diag( vcov( estLpmInt ) ) )[3:5] )
> semEla stdEr
> -0.3559 0.1128
> > urbinElaInt( coef( estLpmInt ), xMeanInt,
> + c( 30, 37.5, 44.5, 52.5, 60 ), xPos = c( 3, 4, 0, 5 ), model = "lpm",
> + allCoefVcov = sqrt( diag( vcov( estLpmInt ) ) ) )
> semEla stdEr
> -0.3559 0.1128
> >
> >
> > ### effect of age changing between discrete intervals
> > ### if age is used as linear explanatory variable
> > # mean values of the 'other' explanatory variables
> > xMeanLinInt <- c( xMeanLin[ 1:2 ], NA, xMeanLin[4] )
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # without standard errors
> > urbinEffInt( coef( estLpmLin )[3], NULL, c( 30, 40 ), c( 50, 60 ), xPos = 1,
> + iPos = 0, model = "lpm" )
> effect stdEr
> -0.1431 NA
> > urbinEffInt( coef( estLpmLin ), NULL, c( 30, 40 ), c( 50, 60 ), xPos = 3,
> + model = "lpm" )
> effect stdEr
> -0.1431 NA
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # based on predicted values
> > predict( estLpmLin,
> + newdata = as.data.frame( t( replace( xMeanLin, 3, 55 ) ) ) ) -
> + predict( estLpmLin,
> + newdata = as.data.frame( t( replace( xMeanLin, 3, 35 ) ) ) )
> 1
> -0.1431
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEffInt( coef( estLpmLin ), NULL, xPos = 3,
> + c( 30, 40 ), c( 50, 60 ), model = "lpm" )$derivCoef
> [1] 0 0 20 0
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estLpmLin )[3], allXVal = NULL,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + xPos = 1, iPos = 0, model = "lpm" ) )
> + }
> age
> [1,] 20
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estLpmLin ), allXVal = NULL,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), xPos = 3, model = "lpm" ) )
> + }
> (Intercept) kids age educ
> [1,] 0 0 20 0
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (full covariance matrix)
> > urbinEffInt( coef( estLpmLin ), NULL,
> + c( 30, 40 ), c( 50, 60 ), xPos = 3, model = "lpm",
> + allCoefVcov = vcov( estLpmLin ) )
> effect stdEr
> -0.14310 0.05236
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (only standard errors)
> > urbinEffInt( coef( estLpmLin )[3], NULL, c( 30, 40 ), c( 50, 60 ),
> + xPos = 1, iPos = 0, model = "lpm",
> + allCoefVcov = sqrt( diag( vcov( estLpmLin ) ) )[3] )
> effect stdEr
> -0.14310 0.05236
> > urbinEffInt( coef( estLpmLin ), NULL, c( 30, 40 ), c( 50, 60 ), xPos = 3,
> + model = "lpm", allCoefVcov = sqrt( diag( vcov( estLpmLin ) ) ) )
> effect stdEr
> -0.14310 0.05236
> >
> >
> > ### effect of age changing between discrete intervals
> > ### if age is used as linear and quadratic explanatory variable
> > # mean values of the 'other' explanatory variables
> > xMeanQuadInt <- c( xMeanLin[ 1:2 ], NA, NA, xMeanLin[4] )
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # without standard errors
> > urbinEffInt( coef( estLpmQuad )[3:4], NULL,
> + c( 30, 40 ), c( 50, 60 ), xPos = 1:2, iPos = 0, model = "lpm" )
> effect stdEr
> -0.2375 NA
> > urbinEffInt( coef( estLpmQuad ), NULL,
> + c( 30, 40 ), c( 50, 60 ), xPos = 3:4, model = "lpm" )
> effect stdEr
> -0.2375 NA
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # based on predicted values
> > predict( estLpmQuad,
> + newdata = as.data.frame( t( replace( xMeanQuad, 3:4, c( 55, 55^2 ) ) ) ),
> + type = "response" ) -
> + predict( estLpmQuad,
> + newdata = as.data.frame( t( replace( xMeanQuad, 3:4, c( 35, 35^2 ) ) ) ),
> + type = "response" )
> 1
> -0.2375
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffInt( coef( estLpmQuad ), NULL, xPos = c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "lpm" )$derivCoef
> [1] 0 0 20 1800 0
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estLpmQuad )[3:4], allXVal = NULL,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), xPos = 1:2, iPos = 0,
> + model = "lpm" ) )
> + }
> age I(age^2)
> [1,] 20 1800
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estLpmQuad ),
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), xPos = 3:4, model = "lpm" ) )
> + }
> (Intercept) kids age I(age^2) educ
> [1,] 0 0 20 1800 0
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (full covariance matrix)
> > urbinEffInt( coef( estLpmQuad )[3:4], NULL, c( 30, 40 ), c( 50, 60 ),
> + xPos = 1:2, iPos = 0, model = "lpm",
> + allCoefVcov = vcov( estLpmQuad )[3:4,3:4] )
> effect stdEr
> -0.23747 0.05978
> > urbinEffInt( coef( estLpmQuad ), NULL, c( 30, 40 ), c( 50, 60 ),
> + xPos = 3:4, model = "lpm", allCoefVcov = vcov( estLpmQuad ) )
> effect stdEr
> -0.23747 0.05978
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (only standard errors)
> > urbinEffInt( coef( estLpmQuad )[3:4], NULL, c( 30, 40 ), c( 50, 60 ),
> + xPos = 1:2, iPos = 0, model = "lpm",
> + allCoefVcov = sqrt( diag( vcov( estLpmQuad ) ) )[3:4] )
> effect stdEr
> -0.2375 0.7125
> Warning message:
> In urbinEffInt(allCoef = coef(estLpmQuad)[3:4], allXVal = NULL, xPos = 1:2, refBound = c(30, 40), intBound = c(50, 60), model = "lpm", allCoefVcov = sqrt(diag(vcov(estLpmQuad)))[3:4], iPos = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEffInt( coef( estLpmQuad ), NULL, c( 30, 40 ), c( 50, 60 ),
> + xPos = 3:4, model = "lpm",
> + allCoefVcov = sqrt( diag( vcov( estLpmQuad ) ) ) )
> effect stdEr
> -0.2375 0.7125
> Warning message:
> In urbinEffInt(allCoef = coef(estLpmQuad), allXVal = NULL, xPos = 3:4, refBound = c(30, 40), intBound = c(50, 60), model = "lpm", allCoefVcov = sqrt(diag(vcov(estLpmQuad)))) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (standard errors + mean value and standard deviation of age)
> > urbinEffInt( coef( estLpmQuad ), NULL, xPos = c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + allCoefVcov = sqrt( diag( vcov( estLpmQuad ) ) ),
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> effect stdEr
> -0.23747 0.06992
> >
> > ### grouping and re-basing categorical variables
> > ### effects of age changing from the 30-44 category to the 53-60 category
> > # without standard errors
> > urbinEffCat( coef( estLpmInt )[3:5], xMeanInt[3:5], 1:3, iPos = 0,
> + c( -1, -1, 1, 0 ), model = "lpm" )
> effect stdEr
> -0.2393 NA
> > urbinEffCat( coef( estLpmInt ), xMeanInt, 3:5, c( -1, -1, 1, 0 ),
> + model = "lpm" )
> effect stdEr
> -0.2393 NA
> > # effects calculated based on predicted values
> > names( xMeanInt ) <- sub( "TRUE", "", names( coef( estLpmInt ) ) )
> > df30.37 <- df38.44 <- df45.52 <- df53.60 <- as.data.frame( t( xMeanInt ) )
> > df30.37[ , 3:5 ] <- c( TRUE, FALSE, FALSE )
> > df38.44[ , 3:5 ] <- c( FALSE, TRUE, FALSE )
> > df45.52[ , 3:5 ] <- c( FALSE, FALSE, FALSE )
> > df53.60[ , 3:5 ] <- c( FALSE, FALSE, TRUE )
> > predict( estLpmInt, newdata = df53.60 ) -
> + sum( Mroz87$age30.37 ) / sum( Mroz87$age30.37 + Mroz87$age38.44 ) *
> + predict( estLpmInt, newdata = df30.37 ) -
> + sum( Mroz87$age38.44 ) / sum( Mroz87$age30.37 + Mroz87$age38.44 ) *
> + predict( estLpmInt, newdata = df38.44 )
> 1
> -0.2393
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffCat( coef( estLpmInt )[3:5], xMeanInt[3:5], 1:3, iPos = 0,
> + c( -1, -1, 1, 0 ), model = "lpm" )$derivCoef
> [1] -0.5878 -0.4122 1.0000
> > urbinEffCat( coef( estLpmInt ), xMeanInt, 3:5, c( -1, -1, 1, 0 ),
> + model = "lpm" )$derivCoef
> [1] 0.0000 0.0000 -0.5878 -0.4122 1.0000 0.0000
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estLpmInt )[3:5], xPos = 1:3, iPos = 0,
> + allXVal = xMeanInt[3:5], xGroups = c( -1, -1, 1, 0 ), model = "lpm" ) )
> + }
> age30.37TRUE age38.44TRUE age53.60TRUE
> [1,] -0.5878 -0.4122 1
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estLpmInt ), xPos = 3:5,
> + allXVal = xMeanInt, xGroups = c( -1, -1, 1, 0 ), model = "lpm" ) )
> + }
> (Intercept) kids age30.37TRUE age38.44TRUE age53.60TRUE educ
> [1,] 0 0 -0.5878 -0.4122 1 0
> > # with full covariance matrix
> > urbinEffCat( coef( estLpmInt )[3:5], xMeanInt[3:5], 1:3, iPos = 0,
> + c( -1, -1, 1, 0 ), model = "lpm",
> + allCoefVcov = vcov( estLpmInt )[3:5, 3:5] )
> effect stdEr
> -0.23926 0.06451
> > urbinEffCat( coef( estLpmInt ), xMeanInt, 3:5, c( -1, -1, 1, 0 ),
> + model = "lpm", allCoefVcov = vcov( estLpmInt ) )
> effect stdEr
> -0.23926 0.06451
> > # with standard errors only
> > urbinEffCat( coef( estLpmInt )[3:5], xMeanInt[3:5], 1:3, iPos = 0,
> + c( -1, -1, 1, 0 ), model = "lpm",
> + allCoefVcov = sqrt( diag( vcov( estLpmInt ) ) )[3:5] )
> effect stdEr
> -0.23926 0.07044
> > urbinEffCat( coef( estLpmInt ), xMeanInt, 3:5, c( -1, -1, 1, 0 ),
> + model = "lpm", allCoefVcov = sqrt( diag( vcov( estLpmInt ) ) ) )
> effect stdEr
> -0.23926 0.07044
> > ### effects of age changing from the 53-60 category to the 38-52 category
> > # without standard errors
> > urbinEffCat( coef( estLpmInt )[3:5], xMeanInt[3:5], 1:3, iPos = 0,
> + c( 0, 1, -1, 1 ), model = "lpm" )
> effect stdEr
> 0.2108 NA
> > urbinEffCat( coef( estLpmInt ), xMeanInt, 3:5, c( 0, 1, -1, 1 ),
> + model = "lpm" )
> effect stdEr
> 0.2108 NA
> > # effects calculated based on predicted values
> > sum( Mroz87$age38.44 ) / sum( Mroz87$age38.44 + Mroz87$age45.52 ) *
> + predict( estLpmInt, newdata = df38.44 ) +
> + sum( Mroz87$age45.52 ) / sum( Mroz87$age38.44 + Mroz87$age45.52 ) *
> + predict( estLpmInt, newdata = df45.52 ) -
> + predict( estLpmInt, newdata = df53.60 )
> 1
> 0.2108
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffCat( coef( estLpmInt )[3:5], xMeanInt[3:5], 1:3, iPos = 0,
> + c( 0, 1, -1, 1 ), model = "lpm" )$derivCoef
> [1] 0.0000 0.4346 -1.0000
> > urbinEffCat( coef( estLpmInt ), xMeanInt, 3:5, c( 0, 1, -1, 1 ),
> + model = "lpm" )$derivCoef
> [1] 0.0000 0.0000 0.0000 0.4346 -1.0000 0.0000
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estLpmInt )[3:5], xPos = 1:3, iPos = 0,
> + allXVal = xMeanInt[3:5], xGroups = c( 0, 1, -1, 1 ), model = "lpm" ) )
> + }
> age30.37TRUE age38.44TRUE age53.60TRUE
> [1,] 0 0.4346 -1
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estLpmInt ), xPos = 3:5,
> + allXVal = xMeanInt, xGroups = c( 0, 1, -1, 1 ), model = "lpm" ) )
> + }
> (Intercept) kids age30.37TRUE age38.44TRUE age53.60TRUE educ
> [1,] 0 0 0 0.4346 -1 0
> > # with full covariance matrix
> > urbinEffCat( coef( estLpmInt )[3:5], xMeanInt[3:5], 1:3, iPos = 0,
> + c( 0, 1, -1, 1 ), model = "lpm",
> + allCoefVcov = vcov( estLpmInt )[3:5,3:5] )
> effect stdEr
> 0.2108 0.0599
> > urbinEffCat( coef( estLpmInt ), xMeanInt, 3:5, c( 0, 1, -1, 1 ),
> + model = "lpm", allCoefVcov = vcov( estLpmInt ) )
> effect stdEr
> 0.2108 0.0599
> > # with standard errors only
> > urbinEffCat( coef( estLpmInt )[3:5], xMeanInt[3:5], 1:3, iPos = 0,
> + c( 0, 1, -1, 1 ), model = "lpm",
> + allCoefVcov = sqrt( diag( vcov( estLpmInt ) ) )[3:5] )
> effect stdEr
> 0.21077 0.06499
> > urbinEffCat( coef( estLpmInt ), xMeanInt, 3:5, c( 0, 1, -1, 1 ),
> + model = "lpm", allCoefVcov = sqrt( diag( vcov( estLpmInt ) ) ) )
> effect stdEr
> 0.21077 0.06499
> >
> >
Running ‘mlogit.R’ [1s/2s]
Comparing ‘mlogit.Rout’ to ‘mlogit.Rout.save’ ...
17,19c17,239
< > proc.time()
< user system elapsed
< 1.280 0.153 1.471
---
> > options( digits = 4 )
> >
> > # load data set
> > data( "Mroz87", package = "sampleSelection" )
> >
> > # create dummy variable for kids
> > Mroz87$kids <- as.numeric( Mroz87$kids5 > 0 | Mroz87$kids618 > 0 )
> >
> > ### create categorical variable
> > Mroz87$lfp3 <- factor( ifelse( Mroz87$hours == 0, "no",
> + ifelse( Mroz87$hours <= 1300, "part", "full" ) ),
> + levels = c( "no", "part", "full" ) )
> > table( Mroz87$lfp3 )
>
> no part full
> 325 204 224
> > all.equal( Mroz87$lfp3 == "no", Mroz87$lfp == 0 )
> [1] TRUE
> >
> > ### linear in age
> > estMLogitLin <- mlogit( lfp3 ~ 0 | kids + age + educ, data = Mroz87,
> + reflevel = "no", shape = "wide" )
> > # remove non-reproducible results such as the duration of the estimation
> > estMLogitLin$est.stat <- NULL
> > summary( estMLogitLin )
>
> Call:
> mlogit(formula = lfp3 ~ 0 | kids + age + educ, data = Mroz87,
> reflevel = "no", shape = "wide", method = "nr")
>
> Frequencies of alternatives:choice
> no full part
> 0.432 0.297 0.271
>
> NULL
>
> Coefficients :
> Estimate Std. Error z-value Pr(>|z|)
> (Intercept):full -0.0810 0.8579 -0.09 0.92480
> (Intercept):part -1.6356 0.8883 -1.84 0.06559 .
> kids:full -0.7990 0.2296 -3.48 0.00050 ***
> kids:part -0.1529 0.2436 -0.63 0.53014
> age:full -0.0379 0.0133 -2.85 0.00433 **
> age:part -0.0236 0.0136 -1.73 0.08302 .
> educ:full 0.1533 0.0407 3.77 0.00016 ***
> educ:part 0.1862 0.0420 4.43 9.2e-06 ***
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> Log-Likelihood: -789
> McFadden R^2: 0.027
> Likelihood ratio test : chisq = 43.7 (p.value = 8.31e-08)
> > # vector for permuting coefficients so that they are ordered in the same way
> > # as expected by urbinEla()
> > coefPermuteLin <- c( seq( 1, 7, 2 ), seq( 2, 8, 2 ) )
> > # mean values of the explanatory variables
> > xMeanLin <- c( 1, colMeans( Mroz87[ , c( "kids", "age", "educ" ) ] ) )
> > # semi-elasticity of age without standard errors
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, xPos = 3,
> + model = "mlogit", yCat = 0 )
> semEla stdEr
> 0.3243 NA
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, xPos = 3,
> + model = "mlogit", yCat = 1 )
> semEla stdEr
> -0.2562 NA
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, xPos = 3,
> + model = "mlogit", yCat = 2 )
> semEla stdEr
> -0.06813 NA
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, xPos = 3,
> + model = "mlogit", yCat = 0:1 )
> semEla stdEr
> 0.06813 NA
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, xPos = 3,
> + model = "mlogit", yCat = 1:2 )
> semEla stdEr
> -0.3243 NA
> > all.equal( c( 0, NA ), unlist(
> + urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, xPos = 3,
> + model = "mlogit", yCat = 0:2 )[ c( "semEla", "stdEr" ) ] ),
> + check.attributes = FALSE )
> [1] TRUE
> > # semi-elasticity of age based on numerical derivation
> > Mroz87Lower <- as.data.frame( t( xMeanLin * c( 1, 1, 0.995, 1 ) ) )
> > Mroz87Lower$lfp3 <- factor( "no", levels = levels( Mroz87$lfp3 ) )
> > Mroz87mLower <- mlogit.data( Mroz87Lower, shape = "wide",
> + choice = "lfp3" )
> > Mroz87Upper <- as.data.frame( t( xMeanLin * c( 1, 1, 1.005, 1 ) ) )
> > Mroz87Upper$lfp3 <- factor( "no", levels = levels( Mroz87$lfp3 ) )
> > Mroz87mUpper <- mlogit.data( Mroz87Upper, shape = "wide",
> + choice = "lfp3" )
> > 100 * ( predict( estMLogitLin, newdata = Mroz87mUpper, type = "response" ) -
> + predict( estMLogitLin, newdata = Mroz87mLower, type = "response" ) )
> no full part
> 0.32429 -0.25617 -0.06813
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3,
> + seSimplify = FALSE, model = "mlogit", yCat = 0 )$derivCoef
> [1] 0.013569 0.009443 -4.874550 0.166724 -0.058871 -0.040967 -7.479414
> [8] -0.723334
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3,
> + seSimplify = FALSE, model = "mlogit", yCat = 1 )$derivCoef
> [1] -0.10352 -0.07204 4.49431 -1.27193 0.08995 0.06259 0.38024 1.10521
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3,
> + seSimplify = FALSE, model = "mlogit", yCat = 2 )$derivCoef
> [1] 0.08995 0.06259 0.38024 1.10521 -0.03108 -0.02163 7.09918 -0.38187
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3,
> + seSimplify = FALSE, model = "mlogit", yCat = 0:1 )$derivCoef
> [1] -0.08995 -0.06259 -0.38024 -1.10521 0.03108 0.02163 -7.09918 0.38187
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3,
> + seSimplify = FALSE, model = "mlogit", yCat = 1:2 )$derivCoef
> [1] -0.013569 -0.009443 4.874550 -0.166724 0.058871 0.040967 7.479414
> [8] 0.723334
> > all.equal( rep( 0, 8 ),
> + urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3,
> + seSimplify = FALSE, model = "mlogit", yCat = 0:2 )$derivCoef )
> [1] TRUE
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estMLogitLin )[ coefPermuteLin ],
> + allXVal = xMeanLin, xPos = 3, model = "mlogit", yCat = 0 ) )
> + }
> (Intercept):full kids:full age:full educ:full (Intercept):part kids:part
> [1,] 0.01357 0.009443 -4.875 0.1667 -0.05887 -0.04097
> age:part educ:part
> [1,] -7.479 -0.7233
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estMLogitLin )[ coefPermuteLin ],
> + allXVal = xMeanLin, xPos = 3, model = "mlogit", yCat = 1 ) )
> + }
> (Intercept):full kids:full age:full educ:full (Intercept):part kids:part
> [1,] -0.1035 -0.07204 4.494 -1.272 0.08995 0.06259
> age:part educ:part
> [1,] 0.3802 1.105
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estMLogitLin )[ coefPermuteLin ],
> + allXVal = xMeanLin, xPos = 3, model = "mlogit", yCat = 2 ) )
> + }
> (Intercept):full kids:full age:full educ:full (Intercept):part kids:part
> [1,] 0.08995 0.06259 0.3802 1.105 -0.03108 -0.02163
> age:part educ:part
> [1,] 7.099 -0.3819
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estMLogitLin )[ coefPermuteLin ],
> + allXVal = xMeanLin, xPos = 3, model = "mlogit", yCat = 0:1 ) )
> + }
> (Intercept):full kids:full age:full educ:full (Intercept):part kids:part
> [1,] -0.08995 -0.06259 -0.3802 -1.105 0.03108 0.02163
> age:part educ:part
> [1,] -7.099 0.3819
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estMLogitLin )[ coefPermuteLin ],
> + allXVal = xMeanLin, xPos = 3, model = "mlogit", yCat = 1:2 ) )
> + }
> (Intercept):full kids:full age:full educ:full (Intercept):part kids:part
> [1,] -0.01357 -0.009443 4.875 -0.1667 0.05887 0.04097
> age:part educ:part
> [1,] 7.479 0.7233
> > if( maxLikLoaded ) {
> + print( all.equal( rep( 0, 8 ), c(
> + numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estMLogitLin )[ coefPermuteLin ],
> + allXVal = xMeanLin, xPos = 3, model = "mlogit", yCat = 0:2 ) ) ) )
> + }
> [1] TRUE
> > # simplified partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3,
> + model = "mlogit", seSimplify = TRUE, yCat = 0 )$derivCoef
> [1] 0.000 0.000 -5.452 0.000 0.000 0.000 -4.975 0.000
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3,
> + model = "mlogit", seSimplify = TRUE, yCat = 1 )$derivCoef
> [1] 0.000 0.000 8.898 0.000 0.000 0.000 -3.446 0.000
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3,
> + model = "mlogit", seSimplify = TRUE, yCat = 2 )$derivCoef
> [1] 0.000 0.000 -3.446 0.000 0.000 0.000 8.421 0.000
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3,
> + model = "mlogit", seSimplify = TRUE, yCat = 0:1 )$derivCoef
> [1] 0.000 0.000 3.446 0.000 0.000 0.000 -8.421 0.000
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3,
> + model = "mlogit", seSimplify = TRUE, yCat = 1:2 )$derivCoef
> [1] 0.000 0.000 5.452 0.000 0.000 0.000 4.975 0.000
> > all.equal( rep( 0, 8 ),
> + urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3,
> + model = "mlogit", seSimplify = TRUE, yCat = 0:2 )$derivCoef )
> [1] TRUE
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + vcov( estMLogitLin )[ coefPermuteLin, coefPermuteLin ], yCat = 0 )
> semEla stdEr
> 0.3243 0.1186
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + vcov( estMLogitLin )[ coefPermuteLin, coefPermuteLin ], yCat = 1 )
> semEla stdEr
> -0.2562 0.1065
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + vcov( estMLogitLin )[ coefPermuteLin, coefPermuteLin ], yCat = 2 )
> semEla stdEr
> -0.06813 0.10335
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + vcov( estMLogitLin )[ coefPermuteLin, coefPermuteLin ], yCat = 0:1 )
> semEla stdEr
> 0.06813 0.10335
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + vcov( estMLogitLin )[ coefPermuteLin, coefPermuteLin ], yCat = 1:2 )
> semEla stdEr
> -0.3243 0.1186
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + vcov( estMLogitLin )[ coefPermuteLin, coefPermuteLin ], yCat = 0:2 )[
> + c( "semEla", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ], seSimplify = FALSE,
> + yCat = 0 )
> semEla stdEr
> 0.3243 0.1361
21,22c241,1901
< In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
< there is no package called 'sampleSelection'
---
> In urbinEla(coef(estMLogitLin)[coefPermuteLin], xMeanLin, 3, model = "mlogit", :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ], seSimplify = FALSE,
> + yCat = 1 )
> semEla stdEr
> -0.2562 0.1523
> Warning message:
> In urbinEla(coef(estMLogitLin)[coefPermuteLin], xMeanLin, 3, model = "mlogit", :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ], seSimplify = FALSE,
> + yCat = 2 )
> semEla stdEr
> -0.06813 0.13640
> Warning message:
> In urbinEla(coef(estMLogitLin)[coefPermuteLin], xMeanLin, 3, model = "mlogit", :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ], seSimplify = FALSE,
> + yCat = 0:1 )
> semEla stdEr
> 0.06813 0.13640
> Warning message:
> In urbinEla(coef(estMLogitLin)[coefPermuteLin], xMeanLin, 3, model = "mlogit", :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ], seSimplify = FALSE,
> + yCat = 1:2 )
> semEla stdEr
> -0.3243 0.1361
> Warning message:
> In urbinEla(coef(estMLogitLin)[coefPermuteLin], xMeanLin, 3, model = "mlogit", :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ], seSimplify = FALSE,
> + yCat = 0:2 )[ c( "semEla", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> Warning message:
> In urbinEla(coef(estMLogitLin)[coefPermuteLin], xMeanLin, 3, model = "mlogit", :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > # semi-elasticity of age with standard errors (only standard errors, simplified)
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ], yCat = 0 )
> semEla stdEr
> 0.32429 0.09924
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ], yCat = 1 )
> semEla stdEr
> -0.2562 0.1273
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ], yCat = 2 )
> semEla stdEr
> -0.06813 0.12353
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ], yCat = 0:1 )
> semEla stdEr
> 0.06813 0.12353
> > urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ], yCat = 1:2 )
> semEla stdEr
> -0.32429 0.09924
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEla( coef( estMLogitLin )[ coefPermuteLin ], xMeanLin, 3, model = "mlogit",
> + sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ], yCat = 0:2 )[
> + c( "semEla", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> >
> > ### quadratic in age
> > estMLogitQuad <- mlogit( lfp3 ~ 0 | kids + age + I(age^2) + educ,
> + data = Mroz87, reflevel = "no", shape = "wide" )
> > # remove non-reproducible results such as the duration of the estimation
> > estMLogitQuad$est.stat <- NULL
> > summary( estMLogitQuad )
>
> Call:
> mlogit(formula = lfp3 ~ 0 | kids + age + I(age^2) + educ, data = Mroz87,
> reflevel = "no", shape = "wide", method = "nr")
>
> Frequencies of alternatives:choice
> no full part
> 0.432 0.297 0.271
>
> NULL
>
> Coefficients :
> Estimate Std. Error z-value Pr(>|z|)
> (Intercept):full -7.84220 2.70423 -2.90 0.00373 **
> (Intercept):part -7.26604 2.75894 -2.63 0.00845 **
> kids:full -1.00739 0.24177 -4.17 3.1e-05 ***
> kids:part -0.33170 0.25895 -1.28 0.20022
> age:full 0.34631 0.12753 2.72 0.00662 **
> age:part 0.25672 0.13105 1.96 0.05011 .
> I(age^2):full -0.00453 0.00150 -3.02 0.00254 **
> I(age^2):part -0.00330 0.00155 -2.14 0.03256 *
> educ:full 0.15714 0.04111 3.82 0.00013 ***
> educ:part 0.18867 0.04225 4.47 8.0e-06 ***
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> Log-Likelihood: -784
> McFadden R^2: 0.0335
> Likelihood ratio test : chisq = 54.3 (p.value = 5.95e-09)
> > # vector for permuting coefficients so that they are ordered in the same way
> > # as expected by urbinEla()
> > coefPermuteQuad <- c( seq( 1, 9, 2 ), seq( 2, 10, 2 ) )
> > # mean values of the explanatory variables
> > xMeanQuad <- c( xMeanLin[ 1:3 ], xMeanLin[3]^2, xMeanLin[4] )
> > # semi-elasticity of age without standard errors
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", yCat = 0 )
> semEla stdEr
> 0.3191 NA
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", yCat = 1 )
> semEla stdEr
> -0.2692 NA
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", yCat = 2 )
> semEla stdEr
> -0.04998 NA
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", yCat = 0:1 )
> semEla stdEr
> 0.04998 NA
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", yCat = 1:2 )
> semEla stdEr
> -0.3191 NA
> > all.equal( c( 0, NA ), unlist(
> + urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", yCat = 0:2 )[ c( "semEla", "stdEr" ) ] ),
> + check.attributes = FALSE )
> [1] TRUE
> > # semi-elasticity of age based on numerical derivation
> > Mroz87Lower <- as.data.frame(
> + t( xMeanQuad * c( 1, 1, 0.995, 0.995^2, 1 ) ) )
> > Mroz87Lower$lfp3 <- factor( "no", levels = levels( Mroz87$lfp3 ) )
> > Mroz87mLower <- mlogit.data( Mroz87Lower, shape = "wide",
> + choice = "lfp3" )
> > Mroz87Upper <- as.data.frame(
> + t( xMeanQuad * c( 1, 1, 1.005, 1.005^2, 1 ) ) )
> > Mroz87Upper$lfp3 <- factor( "no", levels = levels( Mroz87$lfp3 ) )
> > Mroz87mUpper <- mlogit.data( Mroz87Upper, shape = "wide",
> + choice = "lfp3" )
> > 100 * ( predict( estMLogitQuad, newdata = Mroz87mUpper, type = "response" ) -
> + predict( estMLogitQuad, newdata = Mroz87mLower, type = "response" ) )
> no full part
> 0.3191 -0.2691 -0.0500
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", seSimplify = FALSE, yCat = 0 )$derivCoef
> [1] -1.001e-02 -6.967e-03 -5.778e+00 -4.735e+02 -1.230e-01 -7.418e-02
> [7] -5.162e-02 -7.698e+00 -5.207e+02 -9.114e-01
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", seSimplify = FALSE, yCat = 1 )$derivCoef
> [1] -0.08515 -0.05925 5.94795 660.10343 -1.04623 0.09516
> [7] 0.06622 -0.16997 -186.65319 1.16925
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", seSimplify = FALSE, yCat = 2 )$derivCoef
> [1] 0.09516 0.06622 -0.16997 -186.65319 1.16925 -0.02098
> [7] -0.01460 7.86763 707.31100 -0.25781
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", seSimplify = FALSE, yCat = 0:1 )$derivCoef
> [1] -0.09516 -0.06622 0.16997 186.65319 -1.16925 0.02098
> [7] 0.01460 -7.86763 -707.31100 0.25781
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", seSimplify = FALSE, yCat = 1:2 )$derivCoef
> [1] 1.001e-02 6.967e-03 5.778e+00 4.735e+02 1.230e-01 7.418e-02 5.162e-02
> [8] 7.698e+00 5.207e+02 9.114e-01
> > all.equal( rep( 0, 10 ),
> + urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", seSimplify = FALSE, yCat = 0:2 )$derivCoef )
> [1] TRUE
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estMLogitQuad )[ coefPermuteQuad ],
> + allXVal = xMeanQuad, xPos = c( 3, 4 ), model = "mlogit", yCat = 0 ) )
> + }
> (Intercept):full kids:full age:full I(age^2):full educ:full
> [1,] -0.01001 -0.006967 -5.778 -473.5 -0.123
> (Intercept):part kids:part age:part I(age^2):part educ:part
> [1,] -0.07418 -0.05162 -7.698 -520.7 -0.9114
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estMLogitQuad )[ coefPermuteQuad ],
> + allXVal = xMeanQuad, xPos = c( 3, 4 ), model = "mlogit", yCat = 1 ) )
> + }
> (Intercept):full kids:full age:full I(age^2):full educ:full
> [1,] -0.08515 -0.05925 5.948 660.1 -1.046
> (Intercept):part kids:part age:part I(age^2):part educ:part
> [1,] 0.09516 0.06622 -0.17 -186.7 1.169
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estMLogitQuad )[ coefPermuteQuad ],
> + allXVal = xMeanQuad, xPos = c( 3, 4 ), model = "mlogit", yCat = 2 ) )
> + }
> (Intercept):full kids:full age:full I(age^2):full educ:full
> [1,] 0.09516 0.06622 -0.17 -186.7 1.169
> (Intercept):part kids:part age:part I(age^2):part educ:part
> [1,] -0.02098 -0.0146 7.868 707.3 -0.2578
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estMLogitQuad )[ coefPermuteQuad ],
> + allXVal = xMeanQuad, xPos = c( 3, 4 ), model = "mlogit", yCat = 0:1 ) )
> + }
> (Intercept):full kids:full age:full I(age^2):full educ:full
> [1,] -0.09516 -0.06622 0.17 186.7 -1.169
> (Intercept):part kids:part age:part I(age^2):part educ:part
> [1,] 0.02098 0.0146 -7.868 -707.3 0.2578
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estMLogitQuad )[ coefPermuteQuad ],
> + allXVal = xMeanQuad, xPos = c( 3, 4 ), model = "mlogit", yCat = 1:2 ) )
> + }
> (Intercept):full kids:full age:full I(age^2):full educ:full
> [1,] 0.01001 0.006967 5.778 473.5 0.123
> (Intercept):part kids:part age:part I(age^2):part educ:part
> [1,] 0.07418 0.05162 7.698 520.7 0.9114
> > if( maxLikLoaded ) {
> + print( all.equal( rep( 0, 10 ), c(
> + numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estMLogitQuad )[ coefPermuteQuad ],
> + allXVal = xMeanQuad, xPos = c( 3, 4 ), model = "mlogit", yCat = 0:2 ) ) ) )
> + }
> [1] TRUE
> > # simplified partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", seSimplify = TRUE, yCat = 0 )$derivCoef
> [1] 0.000 0.000 -5.352 -455.334 0.000 0.000 0.000 -4.542
> [9] -386.432 0.000
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", seSimplify = TRUE, yCat = 1 )$derivCoef
> [1] 0.000 0.000 9.570 814.181 0.000 0.000 0.000 -4.218
> [9] -358.846 0.000
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", seSimplify = TRUE, yCat = 2 )$derivCoef
> [1] 0.000 0.000 -4.218 -358.846 0.000 0.000 0.000 8.760
> [9] 745.278 0.000
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", seSimplify = TRUE, yCat = 0:1 )$derivCoef
> [1] 0.000 0.000 4.218 358.846 0.000 0.000 0.000 -8.760
> [9] -745.278 0.000
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", seSimplify = TRUE, yCat = 1:2 )$derivCoef
> [1] 0.000 0.000 5.352 455.334 0.000 0.000 0.000 4.542 386.432
> [10] 0.000
> > all.equal( rep( 0, 10 ),
> + urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", seSimplify = TRUE, yCat = 0:2 )$derivCoef )
> [1] TRUE
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", vcov( estMLogitQuad )[ coefPermuteQuad, coefPermuteQuad ],
> + yCat = 0 )
> semEla stdEr
> 0.3191 0.1130
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", vcov( estMLogitQuad )[ coefPermuteQuad, coefPermuteQuad ],
> + yCat = 1 )
> semEla stdEr
> -0.2692 0.1197
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", vcov( estMLogitQuad )[ coefPermuteQuad, coefPermuteQuad ],
> + yCat = 2 )
> semEla stdEr
> -0.04998 0.11086
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", vcov( estMLogitQuad )[ coefPermuteQuad, coefPermuteQuad ],
> + yCat = 0:1 )
> semEla stdEr
> 0.04998 0.11086
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", vcov( estMLogitQuad )[ coefPermuteQuad, coefPermuteQuad ],
> + yCat = 1:2 )
> semEla stdEr
> -0.3191 0.1130
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", vcov( estMLogitQuad )[ coefPermuteQuad, coefPermuteQuad ],
> + yCat = 0:2 )[ c( "semEla", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + seSimplify = FALSE, yCat = 0 )
> semEla stdEr
> 0.3191 1.6604
> Warning messages:
> 1: In urbinEla(coef(estMLogitQuad)[coefPermuteQuad], xMeanQuad, c(3, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> 2: In urbinEla(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuad, xPos = c(3, 4), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], seSimplify = FALSE, yCat = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + seSimplify = FALSE, yCat = 1 )
> semEla stdEr
> -0.2692 1.3290
> Warning messages:
> 1: In urbinEla(coef(estMLogitQuad)[coefPermuteQuad], xMeanQuad, c(3, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> 2: In urbinEla(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuad, xPos = c(3, 4), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], seSimplify = FALSE, yCat = 1) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + seSimplify = FALSE, yCat = 2 )
> semEla stdEr
> -0.04998 1.55241
> Warning messages:
> 1: In urbinEla(coef(estMLogitQuad)[coefPermuteQuad], xMeanQuad, c(3, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> 2: In urbinEla(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuad, xPos = c(3, 4), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], seSimplify = FALSE, yCat = 2) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + seSimplify = FALSE, yCat = 0:1 )
> semEla stdEr
> 0.04998 1.55241
> Warning messages:
> 1: In urbinEla(coef(estMLogitQuad)[coefPermuteQuad], xMeanQuad, c(3, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> 2: In urbinEla(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuad, xPos = c(3, 4), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], seSimplify = FALSE, yCat = 0:1) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + seSimplify = FALSE, yCat = 1:2 )
> semEla stdEr
> -0.3191 1.6604
> Warning messages:
> 1: In urbinEla(coef(estMLogitQuad)[coefPermuteQuad], xMeanQuad, c(3, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> 2: In urbinEla(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuad, xPos = c(3, 4), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], seSimplify = FALSE, yCat = 1:2) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + seSimplify = FALSE, yCat = 0:2 )[ c( "semEla", "stdEr" ) ] ),
> + check.attributes = FALSE )
> [1] TRUE
> Warning messages:
> 1: In urbinEla(coef(estMLogitQuad)[coefPermuteQuad], xMeanQuad, c(3, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> 2: In urbinEla(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuad, xPos = c(3, 4), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], seSimplify = FALSE, yCat = 0:2) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # semi-elasticity of age with standard errors (only standard errors, simplified)
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + yCat = 0 )
> semEla stdEr
> 0.3191 1.2820
> Warning message:
> In urbinEla(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuad, xPos = c(3, 4), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], yCat = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + yCat = 1 )
> semEla stdEr
> -0.2692 1.8958
> Warning message:
> In urbinEla(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuad, xPos = c(3, 4), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], yCat = 1) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + yCat = 2 )
> semEla stdEr
> -0.04998 1.79571
> Warning message:
> In urbinEla(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuad, xPos = c(3, 4), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], yCat = 2) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + yCat = 0:1 )
> semEla stdEr
> 0.04998 1.79571
> Warning message:
> In urbinEla(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuad, xPos = c(3, 4), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], yCat = 0:1) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + yCat = 1:2 )
> semEla stdEr
> -0.3191 1.2820
> Warning message:
> In urbinEla(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuad, xPos = c(3, 4), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], yCat = 1:2) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + yCat = 0:2 )[ c( "semEla", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> Warning message:
> In urbinEla(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuad, xPos = c(3, 4), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], yCat = 0:2) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # semi-elasticity of age with standard errors (only standard errors, xMeanSd)
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ),
> + seSimplify = FALSE, yCat = 0 )
> semEla stdEr
> 0.31913 0.06911
> Warning message:
> In urbinEla(coef(estMLogitQuad)[coefPermuteQuad], xMeanQuad, c(3, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ),
> + seSimplify = FALSE, yCat = 1 )
> semEla stdEr
> -0.2692 0.1989
> Warning message:
> In urbinEla(coef(estMLogitQuad)[coefPermuteQuad], xMeanQuad, c(3, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ),
> + seSimplify = FALSE, yCat = 2 )
> semEla stdEr
> -0.04998 0.17818
> Warning message:
> In urbinEla(coef(estMLogitQuad)[coefPermuteQuad], xMeanQuad, c(3, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ),
> + seSimplify = FALSE, yCat = 0:1 )
> semEla stdEr
> 0.04998 0.17818
> Warning message:
> In urbinEla(coef(estMLogitQuad)[coefPermuteQuad], xMeanQuad, c(3, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ),
> + seSimplify = FALSE, yCat = 1:2 )
> semEla stdEr
> -0.31913 0.06911
> Warning message:
> In urbinEla(coef(estMLogitQuad)[coefPermuteQuad], xMeanQuad, c(3, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ),
> + seSimplify = FALSE, yCat = 0:2 )[ c( "semEla", "stdEr" ) ] ),
> + check.attributes = FALSE )
> [1] TRUE
> Warning message:
> In urbinEla(coef(estMLogitQuad)[coefPermuteQuad], xMeanQuad, c(3, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > # semi-elasticity of age with standard errors (only standard errors, xMeanSd, simplified)
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ), yCat = 0 )
> semEla stdEr
> 0.3191 0.1164
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ), yCat = 1 )
> semEla stdEr
> -0.2692 0.1721
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ), yCat = 2 )
> semEla stdEr
> -0.04998 0.16307
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ), yCat = 0:1 )
> semEla stdEr
> 0.04998 0.16307
> > urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ), yCat = 1:2 )
> semEla stdEr
> -0.3191 0.1164
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEla( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuad, c( 3, 4 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ), yCat = 0:2 )[
> + c( "semEla", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> > # semi-elasticity of age based on partial derivatives calculated by the mfx package
> > # (differs from the above, because mean(age)^2 is not the same as mean(age^2))
> > # estMLogitQuadMfx <- logitmfx( lfp ~ kids + age + I(age^2) + educ, data = Mroz87 )
> > # estMLogitQuadMfx$mfxest[ "age", 1:2 ] * xMeanQuad[ "age" ] +
> > # 2 * estMLogitQuadMfx$mfxest[ "I(age^2)", 1:2 ] * xMeanQuad[ "age" ]^2
> >
> > ### age is interval-coded (age is in the range 30-60)
> > # create dummy variables for age intervals
> > Mroz87$age30.37 <- Mroz87$age >= 30 & Mroz87$age <= 37
> > Mroz87$age38.44 <- Mroz87$age >= 38 & Mroz87$age <= 44
> > Mroz87$age45.52 <- Mroz87$age >= 45 & Mroz87$age <= 52
> > Mroz87$age53.60 <- Mroz87$age >= 53 & Mroz87$age <= 60
> > all.equal(
> + Mroz87$age30.37 + Mroz87$age38.44 + Mroz87$age45.52 + Mroz87$age53.60,
> + rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > # estimation
> > estMLogitInt <- mlogit( lfp3 ~ 0 | kids + age30.37 + age38.44 + age53.60 + educ,
> + data = Mroz87, reflevel = "no", shape = "wide" )
> > # remove non-reproducible results such as the duration of the estimation
> > estMLogitInt$est.stat <- NULL
> > summary( estMLogitInt )
>
> Call:
> mlogit(formula = lfp3 ~ 0 | kids + age30.37 + age38.44 + age53.60 +
> educ, data = Mroz87, reflevel = "no", shape = "wide", method = "nr")
>
> Frequencies of alternatives:choice
> no full part
> 0.432 0.297 0.271
>
> NULL
>
> Coefficients :
> Estimate Std. Error z-value Pr(>|z|)
> (Intercept):full -1.7786 0.5283 -3.37 0.00076 ***
> (Intercept):part -2.5688 0.5557 -4.62 3.8e-06 ***
> kids:full -0.9126 0.2388 -3.82 0.00013 ***
> kids:part -0.2448 0.2517 -0.97 0.33073
> age30.37TRUE:full 0.3551 0.2459 1.44 0.14872
> age30.37TRUE:part 0.0886 0.2433 0.36 0.71579
> age38.44TRUE:full 0.3409 0.2618 1.30 0.19284
> age38.44TRUE:part 0.0530 0.2625 0.20 0.83994
> age53.60TRUE:full -0.8297 0.3106 -2.67 0.00757 **
> age53.60TRUE:part -0.8108 0.3369 -2.41 0.01609 *
> educ:full 0.1592 0.0410 3.88 0.00010 ***
> educ:part 0.1907 0.0422 4.52 6.3e-06 ***
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> Log-Likelihood: -786
> McFadden R^2: 0.0312
> Likelihood ratio test : chisq = 50.7 (p.value = 1.99e-07)
> > # vector for permuting coefficients so that they are ordered in the same way
> > # as expected by urbinEla()
> > coefPermuteInt <- c( seq( 1, 11, 2 ), seq( 2, 12, 2 ) )
> > # mean values of the explanatory variables
> > xMeanInt <- c( xMeanLin[1:2], mean( Mroz87$age30.37 ),
> + mean( Mroz87$age38.44 ), mean( Mroz87$age53.60 ), xMeanLin[4] )
> > # semi-elasticity of age without standard errors
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 0 )
> semEla stdEr
> 0.3774 NA
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 1 )
> semEla stdEr
> -0.2512 NA
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 2 )
> semEla stdEr
> -0.1262 NA
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 0:1 )
> semEla stdEr
> 0.1262 NA
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 1:2 )
> semEla stdEr
> -0.3774 NA
> > all.equal( c( 0, NA ), unlist(
> + urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 0:2 )[
> + c( "semEla", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> > # semi-elasticities based on numerical derivation
> > Mroz87Lower <- Mroz87
> > Mroz87Lower$age <- Mroz87$age * 0.95
> > Mroz87Lower$age30.37 <- Mroz87Lower$age <= 37.5
> > Mroz87Lower$age38.44 <- Mroz87Lower$age > 37.5 & Mroz87Lower$age <= 44.5
> > Mroz87Lower$age45.52 <- Mroz87Lower$age > 44.5 & Mroz87Lower$age <= 52.5
> > Mroz87Lower$age53.60 <- Mroz87Lower$age > 52.5
> > all.equal(
> + Mroz87Lower$age30.37 + Mroz87Lower$age38.44 + Mroz87Lower$age45.52 +
> + Mroz87Lower$age53.60, rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > Mroz87Lower$lfp3 <- factor( "no", levels = levels( Mroz87$lfp3 ) )
> > Mroz87mLower <- mlogit.data( Mroz87Lower, shape = "wide",
> + choice = "lfp3" )
> > Mroz87Upper <- Mroz87
> > Mroz87Upper$age <- Mroz87$age * 1.05
> > Mroz87Upper$age30.37 <- Mroz87Upper$age <= 37.5
> > Mroz87Upper$age38.44 <- Mroz87Upper$age > 37.5 & Mroz87Upper$age <= 44.5
> > Mroz87Upper$age45.52 <- Mroz87Upper$age > 44.5 & Mroz87Upper$age <= 52.5
> > Mroz87Upper$age53.60 <- Mroz87Upper$age > 52.5
> > all.equal(
> + Mroz87Upper$age30.37 + Mroz87Upper$age38.44 + Mroz87Upper$age45.52 +
> + Mroz87Upper$age53.60, rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > Mroz87Upper$lfp3 <- factor( "no", levels = levels( Mroz87$lfp3 ) )
> > Mroz87mUpper <- mlogit.data( Mroz87Upper, shape = "wide",
> + choice = "lfp3" )
> > 10 * ( colMeans(
> + predict( estMLogitInt, newdata = Mroz87mUpper, type = "response" ) ) -
> + colMeans(
> + predict( estMLogitInt, newdata = Mroz87mLower, type = "response" ) ) )
> no full part
> 0.35009 -0.25792 -0.09217
> > Mroz87mLowerMean <- Mroz87mLower
> > Mroz87mUpperMean <- Mroz87mUpper
> > Mroz87mLowerMean$kids <- Mroz87mUpperMean$kids <- xMeanInt[ "kids" ]
> > Mroz87mLowerMean$educ <- Mroz87mUpperMean$educ <- xMeanInt[ "educ" ]
> > 10 * ( colMeans(
> + predict( estMLogitInt, newdata = Mroz87mUpperMean, type = "response" ) ) -
> + colMeans(
> + predict( estMLogitInt, newdata = Mroz87mLowerMean, type = "response" ) ) )
> no full part
> 0.3688 -0.2512 -0.1176
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 0 )$derivCoef
> [1] 0.02852 0.01985 0.18926 0.01703 -0.16111 0.35041 -0.02456 -0.01709
> [9] 0.15428 0.01359 -0.17470 -0.30177
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 1 )$derivCoef
> [1] -0.12037 -0.08376 -0.32843 -0.02912 0.20931 -1.47891 0.09185 0.06391
> [9] 0.13917 0.01209 -0.04820 1.12850
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 2 )$derivCoef
> [1] 0.09185 0.06391 0.13917 0.01209 -0.04820 1.12850 -0.06729 -0.04682
> [9] -0.29345 -0.02568 0.22290 -0.82673
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 0:1 )$derivCoef
> [1] -0.09185 -0.06391 -0.13917 -0.01209 0.04820 -1.12850 0.06729 0.04682
> [9] 0.29345 0.02568 -0.22290 0.82673
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 1:2 )$derivCoef
> [1] -0.02852 -0.01985 -0.18926 -0.01703 0.16111 -0.35041 0.02456 0.01709
> [9] -0.15428 -0.01359 0.17470 0.30177
> > all.equal( rep( 0, 12 ),
> + urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 0:2 )$derivCoef )
> [1] TRUE
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinElaInt( x, ... )$semEla },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3, 4, 0, 5 ),
> + xBound = c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 0 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] 0.02852 0.01985 0.1893 0.01703
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] -0.1611 0.3504 -0.02456 -0.01709 0.1543
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] 0.01359 -0.1747 -0.3018
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinElaInt( x, ... )$semEla },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3, 4, 0, 5 ),
> + xBound = c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 1 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] -0.1204 -0.08376 -0.3284 -0.02912
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] 0.2093 -1.479 0.09185 0.06391 0.1392
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] 0.01209 -0.0482 1.128
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinElaInt( x, ... )$semEla },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3, 4, 0, 5 ),
> + xBound = c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 2 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] 0.09185 0.06391 0.1392 0.01209
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] -0.0482 1.128 -0.06729 -0.04682 -0.2934
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] -0.02568 0.2229 -0.8267
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinElaInt( x, ... )$semEla },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3, 4, 0, 5 ),
> + xBound = c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 0:1 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] -0.09185 -0.06391 -0.1392 -0.01209
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] 0.0482 -1.128 0.06729 0.04682 0.2934
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] 0.02568 -0.2229 0.8267
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinElaInt( x, ... )$semEla },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3, 4, 0, 5 ),
> + xBound = c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 1:2 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] -0.02852 -0.01985 -0.1893 -0.01703
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] 0.1611 -0.3504 0.02456 0.01709 -0.1543
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] -0.01359 0.1747 0.3018
> > if( maxLikLoaded ) {
> + print( all.equal( rep( 0, 12 ), c(
> + numericGradient( function( x, ... ){ urbinElaInt( x, ... )$semEla },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3, 4, 0, 5 ),
> + xBound = c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit", yCat = 0:2 ) ) ) )
> + }
> [1] TRUE
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + yCat = 0 )
> semEla stdEr
> 0.3774 0.1021
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + yCat = 1 )
> semEla stdEr
> -0.25125 0.08043
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + yCat = 2 )
> semEla stdEr
> -0.12618 0.08437
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + yCat = 0:1 )
> semEla stdEr
> 0.12618 0.08437
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + yCat = 1:2 )
> semEla stdEr
> -0.3774 0.1021
> > all.equal( rep( 0, 2 ), unlist(
> + urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + yCat = 0:2 )[ c( "semEla", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + yCat = 0 )
> semEla stdEr
> 0.3774 0.1020
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + yCat = 1 )
> semEla stdEr
> -0.2512 0.1596
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + yCat = 2 )
> semEla stdEr
> -0.1262 0.1402
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + yCat = 0:1 )
> semEla stdEr
> 0.1262 0.1402
> > urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + yCat = 1:2 )
> semEla stdEr
> -0.3774 0.1020
> > all.equal( rep( 0, 2 ), unlist(
> + urbinElaInt( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + yCat = 0:2 )[ c( "semEla", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> >
> >
> > ### effect of age changing between discrete intervals
> > ### if age is used as linear explanatory variable
> > # mean values of the 'other' explanatory variables
> > xMeanLinInt <- c( xMeanLin[ 1:2 ], NA, xMeanLin[4] )
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # without standard errors
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], allXVal = xMeanLinInt,
> + xPos = 3, refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit",
> + yCat = 0 )
> effect stdEr
> 0.152 NA
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], allXVal = xMeanLinInt,
> + xPos = 3, refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit",
> + yCat = 1 )
> effect stdEr
> -0.1175 NA
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], allXVal = xMeanLinInt,
> + xPos = 3, refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit",
> + yCat = 2 )
> effect stdEr
> -0.03458 NA
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], allXVal = xMeanLinInt,
> + xPos = 3, refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit",
> + yCat = 0:1 )
> effect stdEr
> 0.03458 NA
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], allXVal = xMeanLinInt,
> + xPos = 3, refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit",
> + yCat = 1:2 )
> effect stdEr
> -0.152 NA
> > all.equal( c( 0, NA ), unlist(
> + urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], allXVal = xMeanLinInt,
> + xPos = 3, refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit",
> + yCat = 0:2 )[ c( "effect", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # based on predicted values
> > Mroz87Ref <- as.data.frame( t( replace( xMeanLin, 3, 35 ) ) )
> > Mroz87Ref$lfp3 <- factor( "no", levels = levels( Mroz87$lfp3 ) )
> > Mroz87mRef <- mlogit.data( Mroz87Ref, shape = "wide",
> + choice = "lfp3" )
> > Mroz87Int <- as.data.frame( t( replace( xMeanLin, 3, 55 ) ) )
> > Mroz87Int$lfp3 <- factor( "no", levels = levels( Mroz87$lfp3 ) )
> > Mroz87mInt <- mlogit.data( Mroz87Int, shape = "wide",
> + choice = "lfp3" )
> > predict( estMLogitLin, newdata = Mroz87mInt, type = "response" ) -
> + predict( estMLogitLin, newdata = Mroz87mRef, type = "response" )
> no full part
> 0.15205 -0.11747 -0.03458
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit", yCat = 0 )$derivCoef
> [1] 0.009378 0.006526 -2.056823 0.115227 -0.024719 -0.017202 -3.467033
> [8] -0.303721
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit", yCat = 1 )$derivCoef
> [1] -0.05036 -0.03505 1.74563 -0.61880 0.04098 0.02852 0.31119 0.50357
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit", yCat = 2 )$derivCoef
> [1] 0.04098 0.02852 0.31119 0.50357 -0.01627 -0.01132 3.15584 -0.19985
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit", yCat = 0:1 )$derivCoef
> [1] -0.04098 -0.02852 -0.31119 -0.50357 0.01627 0.01132 -3.15584 0.19985
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit", yCat = 1:2 )$derivCoef
> [1] -0.009378 -0.006526 2.056823 -0.115227 0.024719 0.017202 3.467033
> [8] 0.303721
> > all.equal( rep( 0, 8 ),
> + urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit", yCat = 0:2 )$derivCoef )
> [1] TRUE
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estMLogitLin )[ coefPermuteLin ],
> + allXVal = xMeanLinInt, xPos = 3,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit", yCat = 0 ) )
> + }
> (Intercept):full kids:full age:full educ:full (Intercept):part kids:part
> [1,] 0.009378 0.006526 -2.057 0.1152 -0.02472 -0.0172
> age:part educ:part
> [1,] -3.467 -0.3037
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estMLogitLin )[ coefPermuteLin ],
> + allXVal = xMeanLinInt, xPos = 3,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit", yCat = 1 ) )
> + }
> (Intercept):full kids:full age:full educ:full (Intercept):part kids:part
> [1,] -0.05036 -0.03505 1.746 -0.6188 0.04098 0.02852
> age:part educ:part
> [1,] 0.3112 0.5036
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estMLogitLin )[ coefPermuteLin ],
> + allXVal = xMeanLinInt, xPos = 3,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit", yCat = 2 ) )
> + }
> (Intercept):full kids:full age:full educ:full (Intercept):part kids:part
> [1,] 0.04098 0.02852 0.3112 0.5036 -0.01627 -0.01132
> age:part educ:part
> [1,] 3.156 -0.1998
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estMLogitLin )[ coefPermuteLin ],
> + allXVal = xMeanLinInt, xPos = 3,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit", yCat = 0:1 ) )
> + }
> (Intercept):full kids:full age:full educ:full (Intercept):part kids:part
> [1,] -0.04098 -0.02852 -0.3112 -0.5036 0.01627 0.01132
> age:part educ:part
> [1,] -3.156 0.1998
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estMLogitLin )[ coefPermuteLin ],
> + allXVal = xMeanLinInt, xPos = 3,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit", yCat = 1:2 ) )
> + }
> (Intercept):full kids:full age:full educ:full (Intercept):part kids:part
> [1,] -0.009378 -0.006526 2.057 -0.1152 0.02472 0.0172
> age:part educ:part
> [1,] 3.467 0.3037
> > if( maxLikLoaded ) {
> + print( all.equal( rep( 0, 8 ), c(
> + numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estMLogitLin )[ coefPermuteLin ],
> + allXVal = xMeanLinInt, xPos = 3,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit", yCat = 0:2 ) ) ) )
> + }
> [1] TRUE
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (full covariance matrix)
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitLin )[ coefPermuteLin, coefPermuteLin ],
> + yCat = 0 )
> effect stdEr
> 0.15205 0.05541
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitLin )[ coefPermuteLin, coefPermuteLin ],
> + yCat = 1 )
> effect stdEr
> -0.11747 0.04657
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitLin )[ coefPermuteLin, coefPermuteLin ],
> + yCat = 2 )
> effect stdEr
> -0.03458 0.04733
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitLin )[ coefPermuteLin, coefPermuteLin ],
> + yCat = 0:1 )
> effect stdEr
> 0.03458 0.04733
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitLin )[ coefPermuteLin, coefPermuteLin ],
> + yCat = 1:2 )
> effect stdEr
> -0.15205 0.05541
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitLin )[ coefPermuteLin, coefPermuteLin ],
> + yCat = 0:2 )[ c( "effect", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (only standard errors)
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], allXVal = xMeanLinInt,
> + xPos = 3, refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ],
> + yCat = 0 )
> effect stdEr
> 0.15205 0.06107
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], allXVal = xMeanLinInt,
> + xPos = 3, refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ],
> + yCat = 1 )
> effect stdEr
> -0.1175 0.0703
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], allXVal = xMeanLinInt,
> + xPos = 3, refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ],
> + yCat = 2 )
> effect stdEr
> -0.03458 0.06205
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], allXVal = xMeanLinInt,
> + xPos = 3, refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ],
> + yCat = 0:1 )
> effect stdEr
> 0.03458 0.06205
> > urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], allXVal = xMeanLinInt,
> + xPos = 3, refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ],
> + yCat = 1:2 )
> effect stdEr
> -0.15205 0.06107
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEffInt( coef( estMLogitLin )[ coefPermuteLin ], allXVal = xMeanLinInt,
> + xPos = 3, refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitLin ) ) )[ coefPermuteLin ],
> + yCat = 0:2 )[ c( "effect", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> >
> >
> > ### effect of age changing between discrete intervals
> > ### if age is used as linear and quadratic explanatory variable
> > # mean values of the 'other' explanatory variables
> > xMeanQuadInt <- c( xMeanLin[ 1:2 ], NA, NA, xMeanLin[4] )
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # without standard errors
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], allXVal = xMeanQuadInt,
> + xPos = c( 3, 4 ), refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "mlogit", yCat = 0 )
> effect stdEr
> 0.2491 NA
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], allXVal = xMeanQuadInt,
> + xPos = c( 3, 4 ), refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "mlogit", yCat = 1 )
> effect stdEr
> -0.1753 NA
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], allXVal = xMeanQuadInt,
> + xPos = c( 3, 4 ), refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "mlogit", yCat = 2 )
> effect stdEr
> -0.07382 NA
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], allXVal = xMeanQuadInt,
> + xPos = c( 3, 4 ), refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "mlogit", yCat = 0:1 )
> effect stdEr
> 0.07382 NA
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], allXVal = xMeanQuadInt,
> + xPos = c( 3, 4 ), refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "mlogit", yCat = 1:2 )
> effect stdEr
> -0.2491 NA
> > all.equal( c( 0, NA ), unlist(
> + urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], allXVal = xMeanQuadInt,
> + xPos = c( 3, 4 ), refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "mlogit", yCat = 0:2 )[ c( "effect", "stdEr" ) ] ),
> + check.attributes = FALSE )
> [1] TRUE
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # based on predicted values
> > Mroz87Ref <- as.data.frame( t( replace( xMeanQuad, 3:4, c( 35, 35^2 ) ) ) )
> > Mroz87Ref$lfp3 <- factor( "no", levels = levels( Mroz87$lfp3 ) )
> > Mroz87mRef <- mlogit.data( Mroz87Ref, shape = "wide",
> + choice = "lfp3" )
> > Mroz87Int <- as.data.frame( t( replace( xMeanQuad, 3:4, c( 55, 55^2 ) ) ) )
> > Mroz87Int$lfp3 <- factor( "no", levels = levels( Mroz87$lfp3 ) )
> > Mroz87mInt <- mlogit.data( Mroz87Int, shape = "wide",
> + choice = "lfp3" )
> > predict( estMLogitQuad, newdata = Mroz87mInt, type = "response" ) -
> + predict( estMLogitQuad, newdata = Mroz87mRef, type = "response" )
> no full part
> 0.24919 -0.17672 -0.07247
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt,
> + c( 3, 4 ), c( 30, 40 ), c( 50, 60 ), model = "mlogit", yCat = 0 )$derivCoef
> [1] 0.02298 0.01599 -1.29640 -160.72167 0.28236 -0.02489
> [7] -0.01732 -3.47902 -265.40716 -0.30581
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt,
> + c( 3, 4 ), c( 30, 40 ), c( 50, 60 ), model = "mlogit", yCat = 1 )$derivCoef
> [1] -0.08523 -0.05931 -0.17123 147.93976 -1.04716 0.06225 0.04332
> [8] 1.46763 12.78191 0.76481
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt,
> + c( 3, 4 ), c( 30, 40 ), c( 50, 60 ), model = "mlogit", yCat = 2 )$derivCoef
> [1] 0.06225 0.04332 1.46763 12.78191 0.76481 -0.03736 -0.02600
> [8] 2.01139 252.62525 -0.45899
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt,
> + c( 3, 4 ), c( 30, 40 ), c( 50, 60 ), model = "mlogit", yCat = 0:1 )$derivCoef
> [1] -0.06225 -0.04332 -1.46763 -12.78191 -0.76481 0.03736
> [7] 0.02600 -2.01139 -252.62525 0.45899
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt,
> + c( 3, 4 ), c( 30, 40 ), c( 50, 60 ), model = "mlogit", yCat = 1:2 )$derivCoef
> [1] -0.02298 -0.01599 1.29640 160.72167 -0.28236 0.02489 0.01732
> [8] 3.47902 265.40716 0.30581
> > all.equal( rep( 0, 10 ),
> + urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt,
> + c( 3, 4 ), c( 30, 40 ), c( 50, 60 ), model = "mlogit", yCat = 0:2 )$derivCoef )
> [1] TRUE
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estMLogitQuad )[ coefPermuteQuad ],
> + allXVal = xMeanQuadInt, xPos = c( 3, 4 ),
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit", yCat = 0 ) )
> + }
> (Intercept):full kids:full age:full I(age^2):full educ:full
> [1,] 0.02298 0.01599 -1.296 -160.7 0.2824
> (Intercept):part kids:part age:part I(age^2):part educ:part
> [1,] -0.02489 -0.01732 -3.479 -265.4 -0.3058
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estMLogitQuad )[ coefPermuteQuad ],
> + allXVal = xMeanQuadInt, xPos = c( 3, 4 ),
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit", yCat = 1 ) )
> + }
> (Intercept):full kids:full age:full I(age^2):full educ:full
> [1,] -0.08523 -0.05931 -0.1712 147.9 -1.047
> (Intercept):part kids:part age:part I(age^2):part educ:part
> [1,] 0.06225 0.04332 1.468 12.78 0.7648
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estMLogitQuad )[ coefPermuteQuad ],
> + allXVal = xMeanQuadInt, xPos = c( 3, 4 ),
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit", yCat = 2 ) )
> + }
> (Intercept):full kids:full age:full I(age^2):full educ:full
> [1,] 0.06225 0.04332 1.468 12.78 0.7648
> (Intercept):part kids:part age:part I(age^2):part educ:part
> [1,] -0.03736 -0.026 2.011 252.6 -0.459
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estMLogitQuad )[ coefPermuteQuad ],
> + allXVal = xMeanQuadInt, xPos = c( 3, 4 ),
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit", yCat = 0:1 ) )
> + }
> (Intercept):full kids:full age:full I(age^2):full educ:full
> [1,] -0.06225 -0.04332 -1.468 -12.78 -0.7648
> (Intercept):part kids:part age:part I(age^2):part educ:part
> [1,] 0.03736 0.026 -2.011 -252.6 0.459
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estMLogitQuad )[ coefPermuteQuad ],
> + allXVal = xMeanQuadInt, xPos = c( 3, 4 ),
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit", yCat = 1:2 ) )
> + }
> (Intercept):full kids:full age:full I(age^2):full educ:full
> [1,] -0.02298 -0.01599 1.296 160.7 -0.2824
> (Intercept):part kids:part age:part I(age^2):part educ:part
> [1,] 0.02489 0.01732 3.479 265.4 0.3058
> > if( maxLikLoaded ) {
> + print( all.equal( rep( 0, 10 ), c(
> + numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estMLogitQuad )[ coefPermuteQuad ],
> + allXVal = xMeanQuadInt, xPos = c( 3, 4 ),
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "mlogit", yCat = 0:2 ) ) ) )
> + }
> [1] TRUE
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (full covariance matrix)
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt,
> + c( 3, 4 ), c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitQuad )[ coefPermuteQuad, coefPermuteQuad ],
> + yCat = 0 )
> effect stdEr
> 0.24907 0.06262
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt,
> + c( 3, 4 ), c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitQuad )[ coefPermuteQuad, coefPermuteQuad ],
> + yCat = 1 )
> effect stdEr
> -0.17525 0.04818
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt,
> + c( 3, 4 ), c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitQuad )[ coefPermuteQuad, coefPermuteQuad ],
> + yCat = 2 )
> effect stdEr
> -0.07382 0.05322
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt,
> + c( 3, 4 ), c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitQuad )[ coefPermuteQuad, coefPermuteQuad ],
> + yCat = 0:1 )
> effect stdEr
> 0.07382 0.05322
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt,
> + c( 3, 4 ), c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitQuad )[ coefPermuteQuad, coefPermuteQuad ],
> + yCat = 1:2 )
> effect stdEr
> -0.24907 0.06262
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt,
> + c( 3, 4 ), c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = vcov( estMLogitQuad )[ coefPermuteQuad, coefPermuteQuad ],
> + yCat = 0:2 )[ c( "effect", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (only standard errors)
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], allXVal = xMeanQuadInt,
> + xPos = c( 3, 4 ), refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + yCat = 0 )
> effect stdEr
> 0.2491 0.6860
> Warning message:
> In urbinEffInt(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuadInt, xPos = c(3, 4), refBound = c(30, 40), intBound = c(50, 60), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], yCat = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], allXVal = xMeanQuadInt,
> + xPos = c( 3, 4 ), refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + yCat = 1 )
> effect stdEr
> -0.1753 0.4158
> Warning message:
> In urbinEffInt(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuadInt, xPos = c(3, 4), refBound = c(30, 40), intBound = c(50, 60), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], yCat = 1) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], allXVal = xMeanQuadInt,
> + xPos = c( 3, 4 ), refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + yCat = 2 )
> effect stdEr
> -0.07382 0.54580
> Warning message:
> In urbinEffInt(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuadInt, xPos = c(3, 4), refBound = c(30, 40), intBound = c(50, 60), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], yCat = 2) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], allXVal = xMeanQuadInt,
> + xPos = c( 3, 4 ), refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + yCat = 0:1 )
> effect stdEr
> 0.07382 0.54580
> Warning message:
> In urbinEffInt(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuadInt, xPos = c(3, 4), refBound = c(30, 40), intBound = c(50, 60), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], yCat = 0:1) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], allXVal = xMeanQuadInt,
> + xPos = c( 3, 4 ), refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + yCat = 1:2 )
> effect stdEr
> -0.2491 0.6860
> Warning message:
> In urbinEffInt(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuadInt, xPos = c(3, 4), refBound = c(30, 40), intBound = c(50, 60), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], yCat = 1:2) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], allXVal = xMeanQuadInt,
> + xPos = c( 3, 4 ), refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "mlogit", sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + yCat = 0:2 )[ c( "effect", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> Warning message:
> In urbinEffInt(allCoef = coef(estMLogitQuad)[coefPermuteQuad], allXVal = xMeanQuadInt, xPos = c(3, 4), refBound = c(30, 40), intBound = c(50, 60), model = "mlogit", allCoefVcov = sqrt(diag(vcov(estMLogitQuad)))[coefPermuteQuad], yCat = 0:2) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (standard errors + mean value and standard deviation of age)
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ), yCat = 0 )
> effect stdEr
> 0.2491 0.0566
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ), yCat = 1 )
> effect stdEr
> -0.17525 0.06915
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ), yCat = 2 )
> effect stdEr
> -0.07382 0.07777
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ), yCat = 0:1 )
> effect stdEr
> 0.07382 0.07777
> > urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ), yCat = 1:2 )
> effect stdEr
> -0.2491 0.0566
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEffInt( coef( estMLogitQuad )[ coefPermuteQuad ], xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "mlogit",
> + allCoefVcov = sqrt( diag( vcov( estMLogitQuad ) ) )[ coefPermuteQuad ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ), yCat = 0:2 )[
> + c( "effect", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> >
> >
> > ### grouping and re-basing categorical variables
> > ### effects of age changing from the 30-44 category to the 53-60 category
> > # without standard errors
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ), model = "mlogit", yCat = 0 )
> effect stdEr
> 0.2534 NA
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ), model = "mlogit", yCat = 1 )
> effect stdEr
> -0.1669 NA
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ), model = "mlogit", yCat = 2 )
> effect stdEr
> -0.08649 NA
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ), model = "mlogit", yCat = 0:1 )
> effect stdEr
> 0.08649 NA
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ), model = "mlogit", yCat = 1:2 )
> effect stdEr
> -0.2534 NA
> > all.equal( c( 0, NA ), unlist(
> + urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ), model = "mlogit", yCat = 0:2 )[
> + c( "effect", "stdEr" ) ] ), check.attributes = FALSE )
> [1] TRUE
> > # effects calculated based on predicted values
> > names( xMeanInt )[3:5] <- c( "age30.37", "age38.44", "age53.60" )
> > df30.37 <- df38.44 <- df45.52 <- df53.60 <- as.data.frame( t( xMeanInt ) )
> > df30.37[ , 3:5 ] <- c( TRUE, FALSE, FALSE )
> > df38.44[ , 3:5 ] <- c( FALSE, TRUE, FALSE )
> > df45.52[ , 3:5 ] <- c( FALSE, FALSE, FALSE )
> > df53.60[ , 3:5 ] <- c( FALSE, FALSE, TRUE )
> > df30.37$lfp3 <- df38.44$lfp3 <- df45.52$lfp3 <- df53.60$lfp3 <-
> + factor( "no", levels = levels( Mroz87$lfp3 ) )
> > df30.37m <- mlogit.data( df30.37, shape = "wide", choice = "lfp3" )
> > df38.44m <- mlogit.data( df38.44, shape = "wide", choice = "lfp3" )
> > df45.52m <- mlogit.data( df45.52, shape = "wide", choice = "lfp3" )
> > df53.60m <- mlogit.data( df53.60, shape = "wide", choice = "lfp3" )
> > predict( estMLogitInt, newdata = df53.60m, type = "response" ) -
> + sum( Mroz87$age30.37 ) / sum( Mroz87$age30.37 + Mroz87$age38.44 ) *
> + predict( estMLogitInt, newdata = df30.37m, type = "response" ) -
> + sum( Mroz87$age38.44 ) / sum( Mroz87$age30.37 + Mroz87$age38.44 ) *
> + predict( estMLogitInt, newdata = df38.44m, type = "response" )
> no full part
> 0.2534 -0.1669 -0.0865
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3:5 ), c( -1, -1, 1, 0 ), model = "mlogit", yCat = 0 )$derivCoef
> [1] 0.01930 0.01343 0.07671 0.05379 -0.11121 0.23708 -0.01514 -0.01054
> [9] 0.06198 0.04346 -0.12059 -0.18604
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3:5 ), c( -1, -1, 1, 0 ), model = "mlogit", yCat = 1 )$derivCoef
> [1] -0.08059 -0.05608 -0.13230 -0.09277 0.14448 -0.99024 0.06130 0.04266
> [9] 0.05559 0.03898 -0.03327 0.75316
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3:5 ), c( -1, -1, 1, 0 ), model = "mlogit", yCat = 2 )$derivCoef
> [1] 0.06130 0.04266 0.05559 0.03898 -0.03327 0.75316 -0.04616 -0.03212
> [9] -0.11757 -0.08244 0.15386 -0.56712
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3:5 ), c( -1, -1, 1, 0 ), model = "mlogit", yCat = 0:1 )$derivCoef
> [1] -0.06130 -0.04266 -0.05559 -0.03898 0.03327 -0.75316 0.04616 0.03212
> [9] 0.11757 0.08244 -0.15386 0.56712
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3:5 ), c( -1, -1, 1, 0 ), model = "mlogit", yCat = 1:2 )$derivCoef
> [1] -0.01930 -0.01343 -0.07671 -0.05379 0.11121 -0.23708 0.01514 0.01054
> [9] -0.06198 -0.04346 0.12059 0.18604
> > all.equal( rep( 0, 12 ),
> + urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3:5 ), c( -1, -1, 1, 0 ), model = "mlogit", yCat = 0:2 )$derivCoef )
> [1] TRUE
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ),
> + model = "mlogit", yCat = 0 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] 0.0193 0.01343 0.07671 0.05379
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] -0.1112 0.2371 -0.01514 -0.01054 0.06198
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] 0.04346 -0.1206 -0.186
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ),
> + model = "mlogit", yCat = 1 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] -0.08059 -0.05608 -0.1323 -0.09277
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] 0.1445 -0.9902 0.0613 0.04266 0.05559
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] 0.03898 -0.03327 0.7532
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ),
> + model = "mlogit", yCat = 2 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] 0.0613 0.04266 0.05559 0.03898
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] -0.03327 0.7532 -0.04616 -0.03212 -0.1176
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] -0.08244 0.1539 -0.5671
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ),
> + model = "mlogit", yCat = 0:1 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] -0.0613 -0.04266 -0.05559 -0.03898
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] 0.03327 -0.7532 0.04616 0.03212 0.1176
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] 0.08244 -0.1539 0.5671
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ),
> + model = "mlogit", yCat = 1:2 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] -0.0193 -0.01343 -0.07671 -0.05379
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] 0.1112 -0.2371 0.01514 0.01054 -0.06198
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] -0.04346 0.1206 0.186
> > if( maxLikLoaded ) {
> + print( all.equal( rep( 0, 12 ), c(
> + numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ),
> + model = "mlogit", yCat = 0:2 ) ) ) )
> + }
> [1] TRUE
> > # with full covariance matrix
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( -1, -1, 1, 0 ), vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + model = "mlogit", yCat = 0 )
> effect stdEr
> 0.25344 0.06612
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( -1, -1, 1, 0 ), vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + model = "mlogit", yCat = 1 )
> effect stdEr
> -0.16695 0.05016
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( -1, -1, 1, 0 ), vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + model = "mlogit", yCat = 2 )
> effect stdEr
> -0.08649 0.05409
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( -1, -1, 1, 0 ), vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + model = "mlogit", yCat = 0:1 )
> effect stdEr
> 0.08649 0.05409
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( -1, -1, 1, 0 ), vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + model = "mlogit", yCat = 1:2 )
> effect stdEr
> -0.25344 0.06612
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( -1, -1, 1, 0 ), vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + model = "mlogit", yCat = 0:2 )[ c( "effect", "stdEr" ) ] ),
> + check.attributes = FALSE )
> [1] TRUE
> > # with standard errors only
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( -1, -1, 1, 0 ), sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + model = "mlogit", yCat = 0 )
> effect stdEr
> 0.25344 0.06406
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( -1, -1, 1, 0 ), sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + model = "mlogit", yCat = 1 )
> effect stdEr
> -0.1669 0.1000
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( -1, -1, 1, 0 ), sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + model = "mlogit", yCat = 2 )
> effect stdEr
> -0.08649 0.08816
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( -1, -1, 1, 0 ), sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + model = "mlogit", yCat = 0:1 )
> effect stdEr
> 0.08649 0.08816
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( -1, -1, 1, 0 ), sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + model = "mlogit", yCat = 1:2 )
> effect stdEr
> -0.25344 0.06406
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( -1, -1, 1, 0 ), sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + model = "mlogit", yCat = 0:2 )[ c( "effect", "stdEr" ) ] ),
> + check.attributes = FALSE )
> [1] TRUE
> > ### effects of age changing from the 53-60 category to the 38-52 category
> > # without standard errors
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), model = "mlogit", yCat = 0 )
> effect stdEr
> -0.2221 NA
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), model = "mlogit", yCat = 1 )
> effect stdEr
> 0.1277 NA
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), model = "mlogit", yCat = 2 )
> effect stdEr
> 0.09439 NA
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), model = "mlogit", yCat = 0:1 )
> effect stdEr
> -0.09439 NA
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), model = "mlogit", yCat = 1:2 )
> effect stdEr
> 0.2221 NA
> > all.equal( c( 0, NA ), unlist(
> + urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), model = "mlogit", yCat = 0:2 )[ c( "effect", "stdEr" ) ] ),
> + check.attributes = FALSE )
> [1] TRUE
> > # effects calculated based on predicted values
> > sum( Mroz87$age38.44 ) / sum( Mroz87$age38.44 + Mroz87$age45.52 ) *
> + predict( estMLogitInt, newdata = df38.44m, type = "response" ) +
> + sum( Mroz87$age45.52 ) / sum( Mroz87$age38.44 + Mroz87$age45.52 ) *
> + predict( estMLogitInt, newdata = df45.52m, type = "response" ) -
> + predict( estMLogitInt, newdata = df53.60m, type = "response" )
> no full part
> -0.22245 0.12867 0.09378
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3:5 ), c( 0, 1, -1, 1 ), model = "mlogit", yCat = 0 )$derivCoef
> [1] -0.013811 -0.009611 0.000000 -0.054330 0.111209 -0.169700 0.003202
> [8] 0.002228 0.000000 -0.051013 0.120589 0.039344
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3:5 ), c( 0, 1, -1, 1 ), model = "mlogit", yCat = 1 )$derivCoef
> [1] 0.06664 0.04637 0.00000 0.09174 -0.14448 0.81881 -0.05283 -0.03676
> [9] 0.00000 -0.03741 0.03327 -0.64911
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3:5 ), c( 0, 1, -1, 1 ), model = "mlogit", yCat = 2 )$derivCoef
> [1] -0.05283 -0.03676 0.00000 -0.03741 0.03327 -0.64911 0.04963 0.03453
> [9] 0.00000 0.08843 -0.15386 0.60977
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3:5 ), c( 0, 1, -1, 1 ), model = "mlogit", yCat = 0:1 )$derivCoef
> [1] 0.05283 0.03676 0.00000 0.03741 -0.03327 0.64911 -0.04963 -0.03453
> [9] 0.00000 -0.08843 0.15386 -0.60977
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3:5 ), c( 0, 1, -1, 1 ), model = "mlogit", yCat = 1:2 )$derivCoef
> [1] 0.013811 0.009611 0.000000 0.054330 -0.111209 0.169700 -0.003202
> [8] -0.002228 0.000000 0.051013 -0.120589 -0.039344
> > all.equal( rep( 0, 12 ),
> + urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt,
> + c( 3:5 ), c( 0, 1, -1, 1 ), model = "mlogit", yCat = 0:2 )$derivCoef )
> [1] TRUE
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( 0, 1, -1, 1 ),
> + model = "mlogit", yCat = 0 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] -0.01381 -0.009611 0 -0.05433
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] 0.1112 -0.1697 0.003202 0.002228 0
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] -0.05101 0.1206 0.03934
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( 0, 1, -1, 1 ),
> + model = "mlogit", yCat = 1 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] 0.06664 0.04637 0 0.09174
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] -0.1445 0.8188 -0.05283 -0.03676 0
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] -0.03741 0.03327 -0.6491
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( 0, 1, -1, 1 ),
> + model = "mlogit", yCat = 2 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] -0.05283 -0.03676 0 -0.03741
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] 0.03327 -0.6491 0.04963 0.03453 0
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] 0.08843 -0.1539 0.6098
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( 0, 1, -1, 1 ),
> + model = "mlogit", yCat = 0:1 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] 0.05283 0.03676 0 0.03741
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] -0.03327 0.6491 -0.04963 -0.03453 0
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] -0.08843 0.1539 -0.6098
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( 0, 1, -1, 1 ),
> + model = "mlogit", yCat = 1:2 ) )
> + }
> (Intercept):full kids:full age30.37TRUE:full age38.44TRUE:full
> [1,] 0.01381 0.009611 0 0.05433
> age53.60TRUE:full educ:full (Intercept):part kids:part age30.37TRUE:part
> [1,] -0.1112 0.1697 -0.003202 -0.002228 0
> age38.44TRUE:part age53.60TRUE:part educ:part
> [1,] 0.05101 -0.1206 -0.03934
> > if( maxLikLoaded ) {
> + print( all.equal( rep( 0, 12 ), c(
> + numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estMLogitInt )[ coefPermuteInt ],
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( 0, 1, -1, 1 ),
> + model = "mlogit", yCat = 0:2 ) ) ) )
> + }
> [1] TRUE
> > # with full covariance matrix
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + model = "mlogit", yCat = 0 )
> effect stdEr
> -0.22205 0.06141
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + model = "mlogit", yCat = 1 )
> effect stdEr
> 0.12766 0.04451
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + model = "mlogit", yCat = 2 )
> effect stdEr
> 0.09439 0.05058
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + model = "mlogit", yCat = 0:1 )
> effect stdEr
> -0.09439 0.05058
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + model = "mlogit", yCat = 1:2 )
> effect stdEr
> 0.22205 0.06141
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), vcov( estMLogitInt )[ coefPermuteInt, coefPermuteInt ],
> + model = "mlogit", yCat = 0:2 )[ c( "effect", "stdEr" ) ] ),
> + check.attributes = FALSE )
> [1] TRUE
> > # with standard errors only
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + model = "mlogit", yCat = 0 )
> effect stdEr
> -0.22205 0.05778
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + model = "mlogit", yCat = 1 )
> effect stdEr
> 0.12766 0.08367
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + model = "mlogit", yCat = 2 )
> effect stdEr
> 0.09439 0.08056
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + model = "mlogit", yCat = 0:1 )
> effect stdEr
> -0.09439 0.08056
> > urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + model = "mlogit", yCat = 1:2 )
> effect stdEr
> 0.22205 0.05778
> > all.equal( rep( 0, 2 ), unlist(
> + urbinEffCat( coef( estMLogitInt )[ coefPermuteInt ], xMeanInt, c( 3:5 ),
> + c( 0, 1, -1, 1 ), sqrt( diag( vcov( estMLogitInt ) ) )[ coefPermuteInt ],
> + model = "mlogit", yCat = 0:2 )[ c( "effect", "stdEr" ) ] ),
> + check.attributes = FALSE )
> [1] TRUE
> >
> >
Running ‘mvprobit.R’ [1s/1s]
Comparing ‘mvprobit.Rout’ to ‘mvprobit.Rout.save’ ...
17,19c17,102
< > proc.time()
< user system elapsed
< 0.423 0.071 0.543
---
> > options( digits = 2 )
> >
> > # load data set
> > data( "Mroz87", package = "sampleSelection" )
> >
> > # create dummy variable for husband is moonlightning
> > Mroz87$husMoonlight <- Mroz87$hushrs > 2500
> >
> > # create dummy variable for kids
> > Mroz87$kids <- as.numeric( Mroz87$kids5 > 0 | Mroz87$kids618 > 0 )
> >
> > ### linear in age
> > estMvProbitLin <- mvProbit( cbind( lfp, husMoonlight ) ~ kids + age + educ,
> + data = Mroz87, nGHK = 300, iterlim = 0, oneSidedGrad = TRUE, eps = 1e-4,
> + start = c( -0.07332, -0.31572, -0.01915, 0.10475,
> + -0.70550, 0.09776, -0.00889, 0.03258, -0.10837 ) )
> > summary( estMvProbitLin )
>
> Call:
> mvProbit(formula = cbind(lfp, husMoonlight) ~ kids + age + educ,
> data = Mroz87, start = c(-0.07332, -0.31572, -0.01915, 0.10475,
> -0.7055, 0.09776, -0.00889, 0.03258, -0.10837), nGHK = 300,
> oneSidedGrad = TRUE, eps = 1e-04, iterlim = 0)
>
> Coefficients:
> Estimate Std. error t value Pr(> t)
> b_1_0 -0.073320 0.462114 -0.159 0.87394
> b_1_1 -0.315720 0.127760 -2.471 0.01347 *
> b_1_2 -0.019150 0.007084 -2.703 0.00686 **
> b_1_3 0.104750 0.021673 4.833 1.34e-06 ***
> b_2_0 -0.705500 0.492101 -1.434 0.15167
> b_2_1 0.097760 0.137391 0.712 0.47675
> b_2_2 -0.008890 0.007636 -1.164 0.24434
> b_2_3 0.032580 0.022246 1.465 0.14304
> R_1_2 -0.108370 0.062642 -1.730 0.08363 .
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> BHHH maximisation, 0 iterations
> Return code 4: Iteration limit exceeded (iterlim)
> Log-likelihood: -931 on 9 Df
>
> > # mean values of the explanatory variables
> > xMeanLin <- c( 1, colMeans( Mroz87[ , c( "kids", "age", "educ" ) ] ) )
> > # semi-elasticity of age without standard errors
> > urbinEla( coef( estMvProbitLin )[1:4], xMeanLin, xPos = 3, model = "probit" )
> semEla stdEr
> -0.32 NA
> > # semi-elasticity of age based on numerical derivation
> > Mroz87Lower <- as.data.frame( t( xMeanLin * c( 1, 1, 0.995, 1 ) ) )
> > Mroz87Upper <- as.data.frame( t( xMeanLin * c( 1, 1, 1.005, 1 ) ) )
> > Mroz87Lower$lfp <- Mroz87Upper$lfp <- 1
> > Mroz87Lower$husMoonlight <- Mroz87Upper$husMoonlight <- 1
> > 100 * ( mvProbitExp( cbind( lfp, husMoonlight ) ~ kids + age + educ,
> + coef = coef( estMvProbitLin ), data = Mroz87Upper ) -
> + mvProbitExp( cbind( lfp, husMoonlight ) ~ kids + age + educ,
> + coef = coef( estMvProbitLin ), data = Mroz87Lower ) )
> lfp husMoonlight
> 1 -0.32 -0.12
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estMvProbitLin )[1:4], xMeanLin, 3, model = "probit",
> + seSimplify = FALSE )$derivCoef
> kids age educ
> 0.057 0.040 19.140 0.705
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estMvProbitLin )[1:4],
> + allXVal = xMeanLin, xPos = 3, model = "probit" ) )
> + }
> b_1_0 b_1_1 b_1_2 b_1_3
> [1,] 0.057 0.04 19 0.7
> > # simplified partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estMvProbitLin )[1:4], xMeanLin, 3, model = "probit",
> + seSimplify = TRUE )$derivCoef
> [1] 0 0 17 0
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinEla( coef( estMvProbitLin )[1:4], xMeanLin, 3, model = "probit",
> + vcov( estMvProbitLin )[1:4,1:4] )
> semEla stdEr
> -0.32 0.12
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinEla( coef( estMvProbitLin )[1:4], xMeanLin, 3, model = "probit",
> + sqrt( diag( vcov( estMvProbitLin ) ) )[1:4], seSimplify = FALSE )
> semEla stdEr
> -0.32 0.14
21,22c104,734
< In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
< there is no package called 'sampleSelection'
---
> In urbinEla(coef(estMvProbitLin)[1:4], xMeanLin, 3, model = "probit", :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > # semi-elasticity of age with standard errors (only standard errors, simplified)
> > urbinEla( coef( estMvProbitLin )[1:4], xMeanLin, 3, model = "probit",
> + sqrt( diag( vcov( estMvProbitLin ) ) )[1:4] )
> semEla stdEr
> -0.32 0.12
> > # semi-elasticity of age based on partial derivative calculated by the mfx package
> > estMvProbitLinME <- margEff( estMvProbitLin,
> + data = as.data.frame( t( xMeanLin ) ), calcVCov = TRUE, eps = 1e-4 )
> > estMvProbitLinME[[ "d_y1_d_age" ]] * xMeanLin[ "age" ]
> age
> -0.32
> > estMvProbitLinMEVcov <- attr( estMvProbitLinME, "vcov" )[ 1, , ]
> > urbinEla( estMvProbitLinME[[ "d_y1_d_age" ]], xMeanLin["age"], 1, iPos = 0,
> + model = "lpm", sqrt( estMvProbitLinMEVcov[ "d_y1_d_age", "d_y1_d_age" ] ) )
> semEla stdEr
> -0.32 0.12
> > urbinEla( unlist( estMvProbitLinME[ c( 1, 3, 5 ) ] ), xMeanLin[-1], 2, iPos = 0,
> + model = "lpm", estMvProbitLinMEVcov[ c( 1, 3, 5 ), c( 1, 3, 5 ) ] )
> semEla stdEr
> -0.32 0.12
> >
> >
> > ### quadratic in age
> > estMvProbitQuad <- mvProbit(
> + cbind( lfp, husMoonlight ) ~ kids + age + I(age^2) + educ,
> + data = Mroz87, nGHK = 300, iterlim = 0, oneSidedGrad = TRUE, eps = 1e-4,
> + start = c( -4.336110, -0.438580, 0.192469, -0.002497, 0.107107,
> + 0.547970, 0.134075, -0.071620, 0.000741, 0.032548, -0.103104 ) )
> > summary( estMvProbitQuad )
>
> Call:
> mvProbit(formula = cbind(lfp, husMoonlight) ~ kids + age + I(age^2) +
> educ, data = Mroz87, start = c(-4.33611, -0.43858, 0.192469,
> -0.002497, 0.107107, 0.54797, 0.134075, -0.07162, 0.000741,
> 0.032548, -0.103104), nGHK = 300, oneSidedGrad = TRUE, eps = 1e-04,
> iterlim = 0)
>
> Coefficients:
> Estimate Std. error t value Pr(> t)
> b_1_0 -4.3361100 1.4015824 -3.094 0.00198 **
> b_1_1 -0.4385800 0.1341077 -3.270 0.00107 **
> b_1_2 0.1924690 0.0655681 2.935 0.00333 **
> b_1_3 -0.0024970 0.0007706 -3.240 0.00119 **
> b_1_4 0.1071070 0.0220489 4.858 1.19e-06 ***
> b_2_0 0.5479700 1.4730815 0.372 0.70990
> b_2_1 0.1340750 0.1444198 0.928 0.35322
> b_2_2 -0.0716200 0.0701757 -1.021 0.30745
> b_2_3 0.0007410 0.0008239 0.899 0.36845
> b_2_4 0.0325480 0.0222756 1.461 0.14397
> R_1_2 -0.1031040 0.0629743 -1.637 0.10158
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> BHHH maximisation, 0 iterations
> Return code 4: Iteration limit exceeded (iterlim)
> Log-likelihood: -926 on 11 Df
>
> > # mean values of the explanatory variables
> > xMeanQuad <- c( xMeanLin[ 1:3], xMeanLin[3]^2, xMeanLin[4] )
> > # semi-elasticity of age without standard errors
> > urbinEla( coef( estMvProbitQuad )[1:5], xMeanQuad, c( 3, 4 ), model = "probit" )
> semEla stdEr
> -0.32 NA
> > # semi-elasticity of age based on numerical derivation
> > 100 * ( mvProbitExp( cbind( lfp, husMoonlight ) ~ kids + age + I(age^2) + educ,
> + coef = coef( estMvProbitQuad ), data = Mroz87Upper ) -
> + mvProbitExp( cbind( lfp, husMoonlight ) ~ kids + age + I(age^2) + educ,
> + coef = coef( estMvProbitQuad ), data = Mroz87Lower ) )
> lfp husMoonlight
> 1 -0.32 -0.12
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estMvProbitQuad )[1:5], xMeanQuad, c( 3, 4 ), model = "probit",
> + seSimplify = FALSE )$derivCoef
> kids age age educ
> 1.1e-01 7.6e-02 2.1e+01 1.6e+03 1.3e+00
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estMvProbitQuad )[1:5],
> + allXVal = xMeanQuad, xPos = c( 3, 4 ), model = "probit" ) )
> + }
> b_1_0 b_1_1 b_1_2 b_1_3 b_1_4
> [1,] 0.11 0.076 21 1560 1.3
> > # simplified partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estMvProbitQuad )[1:5], xMeanQuad, c( 3, 4 ), model = "probit",
> + seSimplify = TRUE )$derivCoef
> [1] 0 0 16 1361 0
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinEla( coef( estMvProbitQuad )[1:5], xMeanQuad, c( 3, 4 ), model = "probit",
> + vcov( estMvProbitQuad )[1:5,1:5] )
> semEla stdEr
> -0.32 0.11
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinEla( coef( estMvProbitQuad )[1:5], xMeanQuad, c( 3, 4 ), model = "probit",
> + sqrt( diag( vcov( estMvProbitQuad ) ) )[1:5], seSimplify = FALSE )
> semEla stdEr
> -0.32 1.82
> Warning messages:
> 1: In urbinEla(coef(estMvProbitQuad)[1:5], xMeanQuad, c(3, 4), model = "probit", :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> 2: In urbinEla(allCoef = coef(estMvProbitQuad)[1:5], allXVal = xMeanQuad, xPos = c(3, 4), model = "probit", allCoefVcov = sqrt(diag(vcov(estMvProbitQuad)))[1:5], seSimplify = FALSE) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # semi-elasticity of age with standard errors (only standard errors, simplified)
> > urbinEla( coef( estMvProbitQuad )[1:5], xMeanQuad, c( 3, 4 ), model = "probit",
> + sqrt( diag( vcov( estMvProbitQuad ) ) )[1:5] )
> semEla stdEr
> -0.32 1.48
> Warning message:
> In urbinEla(allCoef = coef(estMvProbitQuad)[1:5], allXVal = xMeanQuad, xPos = c(3, 4), model = "probit", allCoefVcov = sqrt(diag(vcov(estMvProbitQuad)))[1:5]) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # semi-elasticity of age with standard errors (only standard errors, xMeanSd)
> > urbinEla( coef( estMvProbitQuad )[1:5], xMeanQuad, c( 3, 4 ), model = "probit",
> + sqrt( diag( vcov( estMvProbitQuad ) ) )[1:5],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ),
> + seSimplify = FALSE )
> semEla stdEr
> -0.32 0.11
> Warning message:
> In urbinEla(coef(estMvProbitQuad)[1:5], xMeanQuad, c(3, 4), model = "probit", :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > # semi-elasticity of age with standard errors (only standard errors, xMeanSd, simplified)
> > urbinEla( coef( estMvProbitQuad )[1:5], xMeanQuad, c( 3, 4 ), model = "probit",
> + sqrt( diag( vcov( estMvProbitQuad ) ) )[1:5],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> semEla stdEr
> -0.32 0.13
> > # semi-elasticity of age based on partial derivatives calculated by the mfx package
> > estMvProbitQuadME <- margEff( estMvProbitQuad,
> + data = as.data.frame( t( xMeanQuad ) ), calcVCov = TRUE, eps = 1e-4 )
> > estMvProbitQuadME[[ "d_y1_d_age" ]] * xMeanQuad[ "age" ] +
> + 2 * estMvProbitQuadME[[ "d_y1_d_I(age^2)" ]] * xMeanQuad[ "age" ]^2
> age
> -0.32
> > estMvProbitQuadMEVcov <- attr( estMvProbitQuadME, "vcov" )[ 1, , ]
> > urbinEla( unlist( estMvProbitQuadME[ c( "d_y1_d_age", "d_y1_d_I(age^2)" ) ] ),
> + xMeanQuad["age"], 1:2, iPos = 0, model = "lpm",
> + estMvProbitQuadMEVcov[ c( 3, 5 ), c( 3, 5 ) ] )
> semEla stdEr
> -0.32 0.11
> > urbinEla( unlist( estMvProbitQuadME[ c( 1, 3, 5, 7 ) ] ), xMeanQuad[-1],
> + 2:3, iPos = 0, model = "lpm",
> + estMvProbitQuadMEVcov[ c( 1, 3, 5, 7 ), c( 1, 3, 5, 7 ) ] )
> semEla stdEr
> -0.32 0.11
> > urbinEla( unlist( estMvProbitQuadME[ c( "d_y1_d_age", "d_y1_d_I(age^2)" ) ] ),
> + xMeanQuad["age"], 1:2, iPos = 0, model = "lpm",
> + sqrt( diag( estMvProbitQuadMEVcov ) )[ c( 3, 5 ) ] )
> semEla stdEr
> -0.32 1.39
> Warning message:
> In urbinEla(allCoef = unlist(estMvProbitQuadME[c("d_y1_d_age", "d_y1_d_I(age^2)")]), allXVal = xMeanQuad["age"], xPos = 1:2, model = "lpm", allCoefVcov = sqrt(diag(estMvProbitQuadMEVcov))[c(3, 5)], iPos = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEla( unlist( estMvProbitQuadME[ c( 1, 3, 5, 7 ) ] ), xMeanQuad[-1],
> + 2:3, iPos = 0, model = "lpm",
> + sqrt( diag( estMvProbitQuadMEVcov ) )[ c( 1, 3, 5, 7 ) ] )
> semEla stdEr
> -0.32 1.39
> Warning message:
> In urbinEla(allCoef = unlist(estMvProbitQuadME[c(1, 3, 5, 7)]), allXVal = xMeanQuad[-1], xPos = 2:3, model = "lpm", allCoefVcov = sqrt(diag(estMvProbitQuadMEVcov))[c(1, 3, 5, 7)], iPos = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEla( unlist( estMvProbitQuadME[ c( "d_y1_d_age", "d_y1_d_I(age^2)" ) ] ),
> + xMeanQuad["age"], 1:2, iPos = 0, model = "lpm",
> + sqrt( diag( estMvProbitQuadMEVcov ) )[ c( 3, 5 ) ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> semEla stdEr
> -0.32 0.13
> > urbinEla( unlist( estMvProbitQuadME[ c( 1, 3, 5, 7 ) ] ), xMeanQuad[-1],
> + 2:3, iPos = 0, model = "lpm",
> + sqrt( diag( estMvProbitQuadMEVcov ) )[ c( 1, 3, 5, 7 ) ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> semEla stdEr
> -0.32 0.13
> >
> >
> > ### age is interval-coded (age is in the range 30-60)
> > # create dummy variables for age intervals
> > Mroz87$age30.37 <- Mroz87$age >= 30 & Mroz87$age <= 37
> > Mroz87$age38.44 <- Mroz87$age >= 38 & Mroz87$age <= 44
> > Mroz87$age45.52 <- Mroz87$age >= 45 & Mroz87$age <= 52
> > Mroz87$age53.60 <- Mroz87$age >= 53 & Mroz87$age <= 60
> > all.equal(
> + Mroz87$age30.37 + Mroz87$age38.44 + Mroz87$age45.52 + Mroz87$age53.60,
> + rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > # estimation
> > estMvProbitInt <- mvProbit(
> + cbind( lfp, husMoonlight ) ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + data = Mroz87, nGHK = 300, iterlim = 0, oneSidedGrad = TRUE, eps = 1e-4,
> + start = c( -0.8929, -0.3775, 0.1346, 0.1219, -0.5144, 0.1082,
> + -1.3155, 0.0883, 0.3853, 0.2785, 0.2929, 0.0326, -0.1018 ) )
> > summary( estMvProbitInt )
>
> Call:
> mvProbit(formula = cbind(lfp, husMoonlight) ~ kids + age30.37 +
> age38.44 + age53.60 + educ, data = Mroz87, start = c(-0.8929,
> -0.3775, 0.1346, 0.1219, -0.5144, 0.1082, -1.3155, 0.0883,
> 0.3853, 0.2785, 0.2929, 0.0326, -0.1018), nGHK = 300, oneSidedGrad = TRUE,
> eps = 1e-04, iterlim = 0)
>
> Coefficients:
> Estimate Std. error t value Pr(> t)
> b_1_0 -0.89290 0.27543 -3.242 0.00119 **
> b_1_1 -0.37750 0.13060 -2.891 0.00385 **
> b_1_2 0.13460 0.12985 1.037 0.29993
> b_1_3 0.12190 0.13810 0.883 0.37740
> b_1_4 -0.51440 0.16311 -3.154 0.00161 **
> b_1_5 0.10820 0.02186 4.949 7.46e-07 ***
> b_2_0 -1.31550 0.30303 -4.341 1.42e-05 ***
> b_2_1 0.08830 0.13979 0.632 0.52761
> b_2_2 0.38530 0.13876 2.777 0.00549 **
> b_2_3 0.27850 0.14913 1.867 0.06183 .
> b_2_4 0.29290 0.17521 1.672 0.09459 .
> b_2_5 0.03260 0.02271 1.435 0.15122
> R_1_2 -0.10180 0.06302 -1.615 0.10623
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> BHHH maximisation, 0 iterations
> Return code 4: Iteration limit exceeded (iterlim)
> Log-likelihood: -924 on 13 Df
>
> > # mean values of the explanatory variables
> > xMeanInt <- c( xMeanLin[1:2], mean( Mroz87$age30.37 ),
> + mean( Mroz87$age38.44 ), mean( Mroz87$age53.60 ), xMeanLin[4] )
> > # semi-elasticity of age without standard errors
> > urbinElaInt( coef( estMvProbitInt )[1:6], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "probit" )
> semEla stdEr
> -0.38 NA
> > # semi-elasticities based on numerical derivation
> > Mroz87Lower <- Mroz87
> > Mroz87Lower$age <- Mroz87$age * 0.95
> > Mroz87Lower$age30.37 <- Mroz87Lower$age <= 37.5
> > Mroz87Lower$age38.44 <- Mroz87Lower$age > 37.5 & Mroz87Lower$age <= 44.5
> > Mroz87Lower$age45.52 <- Mroz87Lower$age > 44.5 & Mroz87Lower$age <= 52.5
> > Mroz87Lower$age53.60 <- Mroz87Lower$age > 52.5
> > all.equal(
> + Mroz87Lower$age30.37 + Mroz87Lower$age38.44 + Mroz87Lower$age45.52 +
> + Mroz87Lower$age53.60, rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > Mroz87Upper <- Mroz87
> > Mroz87Upper$age <- Mroz87$age * 1.05
> > Mroz87Upper$age30.37 <- Mroz87Upper$age <= 37.5
> > Mroz87Upper$age38.44 <- Mroz87Upper$age > 37.5 & Mroz87Upper$age <= 44.5
> > Mroz87Upper$age45.52 <- Mroz87Upper$age > 44.5 & Mroz87Upper$age <= 52.5
> > Mroz87Upper$age53.60 <- Mroz87Upper$age > 52.5
> > all.equal(
> + Mroz87Upper$age30.37 + Mroz87Upper$age38.44 + Mroz87Upper$age45.52 +
> + Mroz87Upper$age53.60, rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > 10 * colMeans(
> + mvProbitExp(
> + cbind( lfp, husMoonlight ) ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + coef = coef( estMvProbitInt ), data = Mroz87Upper ) -
> + mvProbitExp(
> + cbind( lfp, husMoonlight ) ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + coef = coef( estMvProbitInt ), data = Mroz87Lower ) )
> lfp husMoonlight
> -0.352 -0.081
> > Mroz87LowerMean <- Mroz87Lower
> > Mroz87UpperMean <- Mroz87Upper
> > Mroz87LowerMean$kids <- Mroz87UpperMean$kids <- xMeanInt[ "kids" ]
> > Mroz87LowerMean$educ <- Mroz87UpperMean$educ <- xMeanInt[ "educ" ]
> > 10 * colMeans(
> + mvProbitExp(
> + cbind( lfp, husMoonlight ) ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + coef = coef( estMvProbitInt ), data = Mroz87UpperMean ) -
> + mvProbitExp(
> + cbind( lfp, husMoonlight ) ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + coef = coef( estMvProbitInt ), data = Mroz87LowerMean ) )
> lfp husMoonlight
> -0.366 -0.075
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinElaInt( coef( estMvProbitInt )[1:6], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "probit" )$derivCoef
> [1] -0.0041 -0.0029 -0.5552 -0.0494 0.5454 -0.0509
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinElaInt( x, ... )$semEla },
> + t0 = coef( estMvProbitInt )[1:6], allXVal = xMeanInt,
> + xPos = c( 3, 4, 0, 5 ), xBound = c( 30, 37.5, 44.5, 52.5, 60 ),
> + model = "probit" ) )
> + }
> b_1_0 b_1_1 b_1_2 b_1_3 b_1_4 b_1_5
> [1,] -0.0041 -0.0029 -0.56 -0.049 0.55 -0.051
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinElaInt( coef( estMvProbitInt )[1:6], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ),
> + model = "probit", vcov( estMvProbitInt )[1:6,1:6] )
> semEla stdEr
> -0.38 0.10
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinElaInt( coef( estMvProbitInt )[1:6], xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ),
> + model = "probit", sqrt( diag( vcov( estMvProbitInt ) ) )[1:6] )
> semEla stdEr
> -0.38 0.11
> > # semi-elasticity of age based on partial derivatives calculated by the mfx package
> > names( xMeanInt )[3:5] <- c( "age30.37", "age38.44", "age53.60" )
> > estMvProbitIntME <- margEff( estMvProbitInt,
> + data = as.data.frame( t( xMeanInt ) ), calcVCov = TRUE, eps = 1e-4,
> + dummyVars = names( xMeanInt )[3:5] )
> > estMvProbitIntMEVcov <- attr( estMvProbitIntME, "vcov" )[ 1, , ]
> > urbinElaInt( unlist( estMvProbitIntME[ c( 3, 5, 7 ) ] ), xMeanInt[ 3:5 ],
> + c( 1, 2, 0, 3 ), iPos = 0, c( 30, 37.5, 44.5, 52.5, 60 ), model = "lpm",
> + estMvProbitIntMEVcov[ c( 3, 5, 7 ), c( 3, 5, 7 ) ] )
> semEla stdEr
> -0.38 0.10
> > urbinElaInt( unlist( estMvProbitIntME[ c( 1, 3, 5, 7, 9 ) ] ), xMeanInt[-1],
> + c( 2, 3, 0, 4 ), iPos = 0, c( 30, 37.5, 44.5, 52.5, 60 ), model = "lpm",
> + estMvProbitIntMEVcov[ c( 1, 3, 5, 7, 9 ), c( 1, 3, 5, 7, 9 ) ] )
> semEla stdEr
> -0.38 0.10
> > urbinElaInt( unlist( estMvProbitIntME[ c( 3, 5, 7 ) ] ), xMeanInt[ 3:5 ],
> + c( 1, 2, 0, 3 ), iPos = 0, c( 30, 37.5, 44.5, 52.5, 60 ), model = "lpm",
> + sqrt( diag( estMvProbitIntMEVcov ) )[ c( 3, 5, 7 ) ] )
> semEla stdEr
> -0.38 0.12
> > urbinElaInt( unlist( estMvProbitIntME[ c( 1, 3, 5, 7, 9 ) ] ), xMeanInt[-1],
> + c( 2, 3, 0, 4 ), iPos = 0, c( 30, 37.5, 44.5, 52.5, 60 ), model = "lpm",
> + sqrt( diag( estMvProbitIntMEVcov ) )[ c( 1, 3, 5, 7, 9 ) ] )
> semEla stdEr
> -0.38 0.12
> >
> >
> > ### effect of age changing between discrete intervals
> > ### if age is used as linear explanatory variable
> > # mean values of the 'other' explanatory variables
> > xMeanLinInt <- c( xMeanLin[ 1:2 ], NA, xMeanLin[4] )
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # without standard errors
> > urbinEffInt( coef( estMvProbitLin )[1:4], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "probit" )
> effect stdEr
> -0.15 NA
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # based on predicted values
> > Mroz87Ref <- as.data.frame( t( xMeanLin ) )
> > Mroz87Int <- as.data.frame( t( xMeanLin ) )
> > Mroz87Ref$age <- 35
> > Mroz87Int$age <- 55
> > Mroz87Ref$lfp <- Mroz87Int$lfp <- 1
> > Mroz87Ref$husMoonlight <- Mroz87Int$husMoonlight <- 1
> > mvProbitExp( cbind( lfp, husMoonlight ) ~ kids + age + educ,
> + coef = coef( estMvProbitLin ), data = Mroz87Int ) -
> + mvProbitExp( cbind( lfp, husMoonlight ) ~ kids + age + educ,
> + coef = coef( estMvProbitLin ), data = Mroz87Ref )
> lfp husMoonlight
> 1 -0.15 -0.058
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEffInt( coef( estMvProbitLin )[1:4], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "probit" )$derivCoef
> [1] 0.020 0.014 8.653 0.242
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estMvProbitLin )[1:4],
> + allXVal = xMeanLinInt, xPos = 3,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "probit" ) )
> + }
> b_1_0 b_1_1 b_1_2 b_1_3
> [1,] 0.02 0.014 8.7 0.24
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (full covariance matrix)
> > urbinEffInt( coef( estMvProbitLin )[1:4], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "probit",
> + allCoefVcov = vcov( estMvProbitLin )[1:4,1:4] )
> effect stdEr
> -0.151 0.055
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (only standard errors)
> > urbinEffInt( coef( estMvProbitLin )[1:4], xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "probit",
> + allCoefVcov = sqrt( diag( vcov( estMvProbitLin ) ) )[1:4] )
> effect stdEr
> -0.151 0.062
> > # semi-elasticity of age based on marginal effects
> > urbinEffInt( estMvProbitLinME[ "d_y1_d_age" ], NULL, 1, iPos = 0,
> + c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + sqrt( estMvProbitLinMEVcov[ "d_y1_d_age", "d_y1_d_age" ] ) )
> effect stdEr
> -0.150 0.056
> > urbinEffInt( estMvProbitLinME[ c( 1, 3, 5 ) ], NULL, 2, iPos = 0,
> + c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estMvProbitLinMEVcov[ c( 1, 3, 5 ), c( 1, 3, 5 ) ] )
> effect stdEr
> -0.150 0.056
> > urbinEffInt( estMvProbitLinME[ c( 1, 3, 5 ) ], NULL, 2, iPos = 0,
> + c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + sqrt( diag( estMvProbitLinMEVcov ) )[ c( 1, 3, 5 ) ] )
> effect stdEr
> -0.150 0.056
> >
> >
> > ### effect of age changing between discrete intervals
> > ### if age is used as linear and quadratic explanatory variable
> > # mean values of the 'other' explanatory variables
> > xMeanQuadInt <- c( xMeanLin[ 1:2 ], NA, NA, xMeanLin[4] )
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # without standard errors
> > urbinEffInt( coef( estMvProbitQuad )[1:5], xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "probit" )
> effect stdEr
> -0.25 NA
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # based on predicted values
> > mvProbitExp( cbind( lfp, husMoonlight ) ~ kids + age + I(age^2) + educ,
> + coef = coef( estMvProbitQuad ), data = Mroz87Int ) -
> + mvProbitExp( cbind( lfp, husMoonlight ) ~ kids + age + I(age^2) + educ,
> + coef = coef( estMvProbitQuad ), data = Mroz87Ref )
> lfp husMoonlight
> 1 -0.25 -0.033
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffInt( coef( estMvProbitQuad )[1:5], xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "probit" )$derivCoef
> [1] 2.2e-03 1.5e-03 7.7e+00 6.9e+02 2.7e-02
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estMvProbitQuad )[1:5],
> + allXVal = xMeanQuadInt, xPos = c( 3, 4 ),
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "probit" ) )
> + }
> b_1_0 b_1_1 b_1_2 b_1_3 b_1_4
> [1,] 0.0022 0.0015 7.7 686 0.027
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (full covariance matrix)
> > urbinEffInt( coef( estMvProbitQuad )[1:5], xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "probit",
> + allCoefVcov = vcov( estMvProbitQuad )[1:5,1:5] )
> effect stdEr
> -0.253 0.063
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (only standard errors)
> > urbinEffInt( coef( estMvProbitQuad )[1:5], xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "probit",
> + allCoefVcov = sqrt( diag( vcov( estMvProbitQuad ) ) )[1:5] )
> effect stdEr
> -0.25 0.73
> Warning message:
> In urbinEffInt(allCoef = coef(estMvProbitQuad)[1:5], allXVal = xMeanQuadInt, xPos = c(3, 4), refBound = c(30, 40), intBound = c(50, 60), model = "probit", allCoefVcov = sqrt(diag(vcov(estMvProbitQuad)))[1:5]) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (standard errors + mean value and standard deviation of age)
> > urbinEffInt( coef( estMvProbitQuad )[1:5], xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "probit",
> + allCoefVcov = sqrt( diag( vcov( estMvProbitQuad ) )[1:5] ),
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> effect stdEr
> -0.253 0.071
> > # semi-elasticity of age based on marginal effects
> > urbinEffInt( estMvProbitQuadME[ c( "d_y1_d_age", "d_y1_d_I(age^2)" ) ],
> + NULL, 1:2, iPos = 0, c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estMvProbitQuadMEVcov[ c( "d_y1_d_age", "d_y1_d_I(age^2)" ),
> + c( "d_y1_d_age", "d_y1_d_I(age^2)" ) ] )
> effect stdEr
> -0.243 0.059
> > urbinEffInt( estMvProbitQuadME[ c( 1, 3, 5, 7 ) ], NULL, 2:3, iPos = 0,
> + c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estMvProbitQuadMEVcov[ c( 1, 3, 5, 7 ), c( 1, 3, 5, 7 ) ] )
> effect stdEr
> -0.243 0.059
> > urbinEffInt( estMvProbitQuadME[ c( "d_y1_d_age", "d_y1_d_I(age^2)" ) ],
> + NULL, 1:2, iPos = 0, c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + sqrt( diag( estMvProbitQuadMEVcov ) )[ c( "d_y1_d_age", "d_y1_d_I(age^2)" ) ] )
> effect stdEr
> -0.24 0.67
> Warning message:
> In urbinEffInt(allCoef = estMvProbitQuadME[c("d_y1_d_age", "d_y1_d_I(age^2)")], allXVal = NULL, xPos = 1:2, refBound = c(30, 40), intBound = c(50, 60), model = "lpm", allCoefVcov = sqrt(diag(estMvProbitQuadMEVcov))[c("d_y1_d_age", "d_y1_d_I(age^2)")], iPos = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEffInt( estMvProbitQuadME[ c( 1, 3, 5, 7 ) ], NULL, 2:3, iPos = 0,
> + c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + sqrt( diag( estMvProbitQuadMEVcov ) )[ c( 1, 3, 5, 7 ) ] )
> effect stdEr
> -0.24 0.67
> Warning message:
> In urbinEffInt(allCoef = estMvProbitQuadME[c(1, 3, 5, 7)], allXVal = NULL, xPos = 2:3, refBound = c(30, 40), intBound = c(50, 60), model = "lpm", allCoefVcov = sqrt(diag(estMvProbitQuadMEVcov))[c(1, 3, 5, 7)], iPos = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEffInt( estMvProbitQuadME[ c( "d_y1_d_age", "d_y1_d_I(age^2)" ) ],
> + NULL, 1:2, iPos = 0, c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + sqrt( diag( estMvProbitQuadMEVcov ) )[ c( "d_y1_d_age", "d_y1_d_I(age^2)" ) ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> effect stdEr
> -0.243 0.065
> > urbinEffInt( estMvProbitQuadME[ c( 1, 3, 5, 7 ) ], NULL, 2:3, iPos = 0,
> + c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + sqrt( diag( estMvProbitQuadMEVcov ) )[ c( 1, 3, 5, 7 ) ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> effect stdEr
> -0.243 0.065
> >
> >
> > ### grouping and re-basing categorical variables
> > ### effects of age changing from the 30-44 category to the 53-60 category
> > # without standard errors
> > urbinEffCat( coef( estMvProbitInt )[1:6], xMeanInt, c( 3:5 ), c( -1, -1, 1, 0 ),
> + model = "probit" )
> effect stdEr
> -0.25 NA
> > # effects calculated based on predicted values
> > df30.37 <- df38.44 <- df45.52 <- df53.60 <-
> + as.data.frame( t( c( xMeanInt, lfp = 1, husMoonlight = 1 ) ) )
> > df30.37[ , 3:5 ] <- c( TRUE, FALSE, FALSE )
> > df38.44[ , 3:5 ] <- c( FALSE, TRUE, FALSE )
> > df45.52[ , 3:5 ] <- c( FALSE, FALSE, FALSE )
> > df53.60[ , 3:5 ] <- c( FALSE, FALSE, TRUE )
> > mvProbitExp(
> + cbind( lfp, husMoonlight ) ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + coef = coef( estMvProbitInt ), data = df53.60 ) -
> + sum( Mroz87$age30.37 ) / sum( Mroz87$age30.37 + Mroz87$age38.44 ) *
> + mvProbitExp(
> + cbind( lfp, husMoonlight ) ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + coef = coef( estMvProbitInt ), data = df30.37 ) -
> + sum( Mroz87$age38.44 ) / sum( Mroz87$age30.37 + Mroz87$age38.44 ) *
> + mvProbitExp(
> + cbind( lfp, husMoonlight ) ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + coef = coef( estMvProbitInt ), data = df38.44 )
> lfp husMoonlight
> 1 -0.25 -0.017
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffCat( coef( estMvProbitInt )[1:6], xMeanInt, c( 3:5 ), c( -1, -1, 1, 0 ),
> + model = "probit" )$derivCoef
> [1] -0.0046 -0.0032 -0.2240 -0.1570 0.3765 -0.0559
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estMvProbitInt )[1:6],
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ),
> + model = "probit" ) )
> + }
> b_1_0 b_1_1 b_1_2 b_1_3 b_1_4 b_1_5
> [1,] -0.0046 -0.0032 -0.22 -0.16 0.38 -0.056
> > # with full covariance matrix
> > urbinEffCat( coef( estMvProbitInt )[1:6], xMeanInt, c( 3:5 ), c( -1, -1, 1, 0 ),
> + model = "probit", allCoefVcov = vcov( estMvProbitInt )[1:6,1:6] )
> effect stdEr
> -0.252 0.066
> > # with standard errors only
> > urbinEffCat( coef( estMvProbitInt )[1:6], xMeanInt, c( 3:5 ), c( -1, -1, 1, 0 ),
> + model = "probit", allCoefVcov = sqrt( diag( vcov( estMvProbitInt ) ) )[1:6] )
> effect stdEr
> -0.252 0.071
> > # semi-elasticity of age based on marginal effects
> > urbinEffCat( unlist( estMvProbitIntME[ c( 3, 5, 7 ) ] ),
> + xMeanInt[ 3:5 ], c(1:3), iPos = 0, c( -1, -1, 1, 0 ), model = "lpm",
> + estMvProbitIntMEVcov[ c( 3, 5, 7 ), c( 3, 5, 7 ) ] )
> effect stdEr
> -0.253 0.067
> > urbinEffCat( unlist( estMvProbitIntME[ c( 1, 3, 5, 7, 9 ) ] ),
> + xMeanInt[ -1 ], c(2:4), iPos = 0, c( -1, -1, 1, 0 ), model = "lpm",
> + estMvProbitIntMEVcov[ c( 1, 3, 5, 7, 9 ), c( 1, 3, 5, 7, 9 ) ] )
> effect stdEr
> -0.253 0.067
> > urbinEffCat( unlist( estMvProbitIntME[ c( 3, 5, 7 ) ] ),
> + xMeanInt[ 3:5 ], c(1:3), iPos = 0, c( -1, -1, 1, 0 ), model = "lpm",
> + sqrt( diag( estMvProbitIntMEVcov ) )[ c( 3, 5, 7 ) ] )
> effect stdEr
> -0.253 0.073
> > urbinEffCat( unlist( estMvProbitIntME[ c( 1, 3, 5, 7, 9 ) ] ),
> + xMeanInt[ -1 ], c(2:4), iPos = 0, c( -1, -1, 1, 0 ), model = "lpm",
> + sqrt( diag( estMvProbitIntMEVcov ) )[ c( 1, 3, 5, 7, 9 ) ] )
> effect stdEr
> -0.253 0.073
> >
> > ### effects of age changing from the 53-60 category to the 38-52 category
> > # without standard errors
> > urbinEffCat( coef( estMvProbitInt )[1:6], xMeanInt, c( 3:5 ), c( 0, 1, -1, 1 ),
> + model = "probit" )
> effect stdEr
> 0.22 NA
> > # effects calculated based on predicted values
> > sum( Mroz87$age38.44 ) / sum( Mroz87$age38.44 + Mroz87$age45.52 ) *
> + mvProbitExp(
> + cbind( lfp, husMoonlight ) ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + coef = coef( estMvProbitInt ), data = df38.44 ) +
> + sum( Mroz87$age45.52 ) / sum( Mroz87$age38.44 + Mroz87$age45.52 ) *
> + mvProbitExp(
> + cbind( lfp, husMoonlight ) ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + coef = coef( estMvProbitInt ), data = df45.52 ) -
> + mvProbitExp(
> + cbind( lfp, husMoonlight ) ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + coef = coef( estMvProbitInt ), data = df53.60 )
> lfp husMoonlight
> 1 0.22 -0.053
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffCat( coef( estMvProbitInt )[1:6], xMeanInt, c( 3:5 ), c( 0, 1, -1, 1 ),
> + model = "probit" )$derivCoef
> [1] 0.0123 0.0086 0.0000 0.1690 -0.3765 0.1517
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estMvProbitInt )[1:6],
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( 0, 1, -1, 1 ),
> + model = "probit" ) )
> + }
> b_1_0 b_1_1 b_1_2 b_1_3 b_1_4 b_1_5
> [1,] 0.012 0.0086 0 0.17 -0.38 0.15
> > # with full covariance matrix
> > urbinEffCat( coef( estMvProbitInt )[1:6], xMeanInt, c( 3:5 ), c( 0, 1, -1, 1 ),
> + model = "probit", allCoefVcov = vcov( estMvProbitInt )[1:6,1:6] )
> effect stdEr
> 0.223 0.061
> > # with standard errors only
> > urbinEffCat( coef( estMvProbitInt )[1:6], xMeanInt, c( 3:5 ), c( 0, 1, -1, 1 ),
> + model = "probit", allCoefVcov = sqrt( diag( vcov( estMvProbitInt ) ) )[1:6] )
> effect stdEr
> 0.223 0.066
> > # semi-elasticity of age based on partial derivative calculated by the mfx package
> > urbinEffCat( unlist( estMvProbitIntME[ c( 3, 5, 7 ) ] ),
> + xMeanInt[ 3:5 ], c(1:3), iPos = 0, c( 0, 1, -1, 1 ), model = "lpm",
> + estMvProbitIntMEVcov[ c( 3, 5, 7 ), c( 3, 5, 7 ) ] )
> effect stdEr
> 0.224 0.062
> > urbinEffCat( unlist( estMvProbitIntME[ c( 1, 3, 5, 7, 9 ) ] ),
> + xMeanInt[ -1 ], c(2:4), iPos = 0, c( 0, 1, -1, 1 ), model = "lpm",
> + estMvProbitIntMEVcov[ c( 1, 3, 5, 7, 9 ), c( 1, 3, 5, 7, 9 ) ] )
> effect stdEr
> 0.224 0.062
> > urbinEffCat( unlist( estMvProbitIntME[ c( 3, 5, 7 ) ] ),
> + xMeanInt[ 3:5 ], c(1:3), iPos = 0, c( 0, 1, -1, 1 ), model = "lpm",
> + sqrt( diag( estMvProbitIntMEVcov ) )[ c( 3, 5, 7 ) ] )
> effect stdEr
> 0.224 0.067
> > urbinEffCat( unlist( estMvProbitIntME[ c( 1, 3, 5, 7, 9 ) ] ),
> + xMeanInt[ -1 ], c(2:4), iPos = 0, c( 0, 1, -1, 1 ), model = "lpm",
> + sqrt( diag( estMvProbitIntMEVcov ) )[ c( 1, 3, 5, 7, 9 ) ] )
> effect stdEr
> 0.224 0.067
> >
Running ‘oprobit.R’ [0s/0s]
Comparing ‘oprobit.Rout’ to ‘oprobit.Rout.save’ ...
17,19c17,124
< > proc.time()
< user system elapsed
< 0.277 0.043 0.349
---
> > options( digits = 3 )
> >
> > # load data set
> > data( "Mroz87", package = "sampleSelection" )
> >
> > # create dummy variable for kids
> > Mroz87$kids <- as.numeric( Mroz87$kids5 > 0 | Mroz87$kids618 > 0 )
> >
> > ### create categorical variable
> > Mroz87$lfp3 <- factor( ifelse( Mroz87$hours == 0, "no",
> + ifelse( Mroz87$hours <= 1300, "part", "full" ) ),
> + levels = c( "no", "part", "full" ), ordered = TRUE )
> > table( Mroz87$lfp3 )
>
> no part full
> 325 204 224
> > all.equal( Mroz87$lfp3 == "no", Mroz87$lfp == 0 )
> [1] TRUE
> >
> > ### linear in age
> > estOProbitLin <- polr( lfp3 ~ kids + age + educ, data = Mroz87,
> + method = "probit", Hess = TRUE )
> > summary( estOProbitLin )
> Call:
> polr(formula = lfp3 ~ kids + age + educ, data = Mroz87, Hess = TRUE,
> method = "probit")
>
> Coefficients:
> Value Std. Error t value
> kids -0.3769 0.10947 -3.44
> age -0.0185 0.00627 -2.95
> educ 0.0776 0.01864 4.16
>
> Intercepts:
> Value Std. Error t value
> no|part -0.272 0.405 -0.672
> part|full 0.452 0.405 1.115
>
> Residual Deviance: 1589.68
> AIC: 1599.68
> > # mean values of the explanatory variables and specification of the threshold
> > xMeanLin <- c( colMeans( Mroz87[ , c( "kids", "age", "educ" ) ] ), -1, 0 )
> > # semi-elasticity of age without standard errors
> > urbinEla( coef( summary( estOProbitLin ) )[,1], xMeanLin, xPos = 2,
> + iPos = 4, model = "oprobit" )
> semEla stdEr
> -0.31 NA
> > urbinEla( coef( summary( estOProbitLin ) )[-5,1], xMeanLin[-5], xPos = 2,
> + iPos = 4, model = "oprobit" )
> semEla stdEr
> -0.31 NA
> > # semi-elasticity of age based on numerical derivation
> > Mroz87Lower <- as.data.frame( t( xMeanLin * c( 1, 0.995, 1, 1, 1 ) ) )
> > Mroz87Upper <- as.data.frame( t( xMeanLin * c( 1, 1.005, 1, 1, 1 ) ) )
> > elaLinNum <- 100 * (
> + predict( estOProbitLin, newdata = Mroz87Upper, type = "probs" ) -
> + predict( estOProbitLin, newdata = Mroz87Lower, type = "probs" ) )
> > print( elaLinNum )
> no part full
> 0.3098 -0.0391 -0.2706
> > print( sum( elaLinNum[ c( "part", "full" ) ] ) )
> [1] -0.31
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( summary( estOProbitLin ) )[,1], xMeanLin, xPos = 2,
> + iPos = 4, seSimplify = FALSE, model = "oprobit" )$derivCoef
> kids age educ
> 0.0378 19.0203 0.6668 -0.0543 0.0000
> > urbinEla( coef( summary( estOProbitLin ) )[-5,1], xMeanLin[-5], xPos = 2,
> + iPos = 4, seSimplify = FALSE, model = "oprobit" )$derivCoef
> kids age educ
> 0.0378 19.0203 0.6668 -0.0543
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( summary( estOProbitLin ) )[,1],
> + allXVal = xMeanLin, xPos = 2, iPos = 4, model = "oprobit" ) )
> + }
> kids age educ no|part part|full
> [1,] 0.0378 19 0.667 -0.0543 0
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( summary( estOProbitLin ) )[-5,1],
> + allXVal = xMeanLin[-5], xPos = 2, iPos = 4, model = "oprobit" ) )
> + }
> kids age educ no|part
> [1,] 0.0378 19 0.667 -0.0543
> > # simplified partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( summary( estOProbitLin ) )[,1], xMeanLin, xPos = 2,
> + iPos = 4, model = "oprobit", seSimplify = TRUE )$derivCoef
> [1] 0.0 16.7 0.0 0.0 0.0
> > urbinEla( coef( summary( estOProbitLin ) )[-5,1], xMeanLin[-5], xPos = 2,
> + iPos = 4, model = "oprobit", seSimplify = TRUE )$derivCoef
> [1] 0.0 16.7 0.0 0.0
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinEla( coef( summary( estOProbitLin ) )[,1], xMeanLin, xPos = 2,
> + iPos = 4, model = "oprobit", vcov( estOProbitLin ) )
> semEla stdEr
> -0.310 0.105
> > urbinEla( coef( summary( estOProbitLin ) )[-5,1], xMeanLin[-5], xPos = 2,
> + iPos = 4, model = "oprobit", vcov( estOProbitLin )[-5,-5] )
> semEla stdEr
> -0.310 0.105
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinEla( coef( summary( estOProbitLin ) )[,1], xMeanLin,
> + xPos = 2, iPos = 4, model = "oprobit",
> + sqrt( diag( vcov( estOProbitLin ) ) ), seSimplify = FALSE )
> semEla stdEr
> -0.310 0.122
21,22c126,766
< In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
< there is no package called 'sampleSelection'
---
> In urbinEla(coef(summary(estOProbitLin))[, 1], xMeanLin, xPos = 2, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > urbinEla( coef( summary( estOProbitLin ) )[-5,1], xMeanLin[-5],
> + xPos = 2, iPos = 4, model = "oprobit",
> + sqrt( diag( vcov( estOProbitLin ) ) )[-5], seSimplify = FALSE )
> semEla stdEr
> -0.310 0.122
> Warning message:
> In urbinEla(coef(summary(estOProbitLin))[-5, 1], xMeanLin[-5], xPos = 2, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > # semi-elasticity of age with standard errors (only standard errors, simplified)
> > urbinEla( coef( summary( estOProbitLin ) )[,1], xMeanLin,
> + xPos = 2, iPos = 4, model = "oprobit",
> + sqrt( diag( vcov( estOProbitLin ) ) ) )
> semEla stdEr
> -0.310 0.105
> > urbinEla( coef( summary( estOProbitLin ) )[-5,1], xMeanLin[-5],
> + xPos = 2, iPos = 4, model = "oprobit",
> + sqrt( diag( vcov( estOProbitLin ) ) )[-5] )
> semEla stdEr
> -0.310 0.105
> >
> >
> > ### quadratic in age
> > estOProbitQuad <- polr( lfp3 ~ kids + age + I(age^2) + educ,
> + data = Mroz87, method = "probit", Hess = TRUE )
> > summary( estOProbitQuad )
> Call:
> polr(formula = lfp3 ~ kids + age + I(age^2) + educ, data = Mroz87,
> Hess = TRUE, method = "probit")
>
> Coefficients:
> Value Std. Error t value
> kids -0.48261 0.115793 -4.17
> age 0.17343 0.016741 10.36
> I(age^2) -0.00227 0.000272 -8.33
> educ 0.07863 0.019019 4.13
>
> Intercepts:
> Value Std. Error t value
> no|part 3.582 0.005 768.832
> part|full 4.313 0.045 95.317
>
> Residual Deviance: 1578.93
> AIC: 1590.93
> > # mean values of the explanatory variables and specification of the threshold
> > xMeanQuad <- c( xMeanLin[ 1:2 ], xMeanLin[2]^2, xMeanLin[3:5] )
> > # semi-elasticity of age without standard errors
> > urbinEla( coef( summary( estOProbitQuad ) )[,1], xMeanQuad,
> + xPos = c( 2, 3 ), iPos = 5, model = "oprobit" )
> semEla stdEr
> -0.313 NA
> > urbinEla( coef( summary( estOProbitQuad ) )[-6,1], xMeanQuad[-6],
> + xPos = c( 2, 3 ), iPos = 5, model = "oprobit" )
> semEla stdEr
> -0.313 NA
> > # semi-elasticity of age based on numerical derivation
> > Mroz87Lower <- as.data.frame(
> + t( xMeanQuad * c( 1, 0.995, 0.995^2, 1, 1, 1 ) ) )
> > Mroz87Upper <- as.data.frame(
> + t( xMeanQuad * c( 1, 1.005, 1.005^2, 1, 1, 1 ) ) )
> > elaQuadNum <- 100 * (
> + predict( estOProbitQuad, newdata = Mroz87Upper, type = "probs" ) -
> + predict( estOProbitQuad, newdata = Mroz87Lower, type = "probs" ) )
> > print( elaQuadNum )
> no part full
> 0.31283 -0.00936 -0.30347
> > print( sum( elaQuadNum[ c( "part", "full" ) ] ) )
> [1] -0.313
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( summary( estOProbitQuad ) )[,1], xMeanQuad,
> + xPos = c( 2, 3 ), iPos = 5, model = "oprobit", seSimplify = FALSE )$derivCoef
> kids age age educ
> 0.0705 20.4119 1553.2913 1.2444 -0.1013 0.0000
> > urbinEla( coef( summary( estOProbitQuad ) )[-6,1], xMeanQuad[-6],
> + xPos = c( 2, 3 ), iPos = 5, model = "oprobit", seSimplify = FALSE )$derivCoef
> kids age age educ
> 0.0705 20.4119 1553.2913 1.2444 -0.1013
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( summary( estOProbitQuad ) )[,1],
> + allXVal = xMeanQuad, xPos = c( 2, 3 ), iPos = 5, model = "oprobit" ) )
> + }
> kids age I(age^2) educ no|part part|full
> [1,] 0.0705 20.4 1553 1.24 -0.101 0
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( summary( estOProbitQuad ) )[-6,1],
> + allXVal = xMeanQuad[-6], xPos = c( 2, 3 ), iPos = 5, model = "oprobit" ) )
> + }
> kids age I(age^2) educ no|part
> [1,] 0.0705 20.4 1553 1.24 -0.101
> > # simplified partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( summary( estOProbitQuad ) )[,1], xMeanQuad,
> + xPos = c( 2, 3 ), iPos = 5, model = "oprobit", seSimplify = TRUE )$derivCoef
> [1] 0.0 16.1 1370.0 0.0 0.0 0.0
> > urbinEla( coef( summary( estOProbitQuad ) )[-6,1], xMeanQuad[-6],
> + xPos = c( 2, 3 ), iPos = 5, model = "oprobit", seSimplify = TRUE )$derivCoef
> [1] 0.0 16.1 1370.0 0.0 0.0
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinEla( coef( summary( estOProbitQuad ) )[,1], xMeanQuad,
> + xPos = c( 2, 3 ), iPos = 5, model = "oprobit",
> + vcov( estOProbitQuad ) )
> semEla stdEr
> -0.313 0.125
> > urbinEla( coef( summary( estOProbitQuad ) )[-6,1], xMeanQuad[-6],
> + xPos = c( 2, 3 ), iPos = 5, model = "oprobit",
> + vcov( estOProbitQuad )[-6,-6] )
> semEla stdEr
> -0.313 0.125
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinEla( coef( summary( estOProbitQuad ) )[,1], xMeanQuad,
> + xPos = c( 2, 3 ), iPos = 5, model = "oprobit",
> + sqrt( diag( vcov( estOProbitQuad ) ) ), seSimplify = FALSE )
> semEla stdEr
> -0.313 0.544
> Warning messages:
> 1: In urbinEla(coef(summary(estOProbitQuad))[, 1], xMeanQuad, xPos = c(2, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> 2: In urbinEla(allCoef = coef(summary(estOProbitQuad))[, 1], allXVal = xMeanQuad, xPos = c(2, 3), model = "oprobit", allCoefVcov = sqrt(diag(vcov(estOProbitQuad))), seSimplify = FALSE, iPos = 5) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEla( coef( summary( estOProbitQuad ) )[-6,1], xMeanQuad[-6],
> + xPos = c( 2, 3 ), iPos = 5, model = "oprobit",
> + sqrt( diag( vcov( estOProbitQuad ) ) )[-6], seSimplify = FALSE )
> semEla stdEr
> -0.313 0.544
> Warning messages:
> 1: In urbinEla(coef(summary(estOProbitQuad))[-6, 1], xMeanQuad[-6], :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> 2: In urbinEla(allCoef = coef(summary(estOProbitQuad))[-6, 1], allXVal = xMeanQuad[-6], xPos = c(2, 3), model = "oprobit", allCoefVcov = sqrt(diag(vcov(estOProbitQuad)))[-6], seSimplify = FALSE, iPos = 5) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # semi-elasticity of age with standard errors (only standard errors, simplified)
> > urbinEla( coef( summary( estOProbitQuad ) )[,1], xMeanQuad,
> + xPos = c( 2, 3 ),iPos = 5, model = "oprobit",
> + sqrt( diag( vcov( estOProbitQuad ) ) ) )
> semEla stdEr
> -0.313 0.460
> Warning message:
> In urbinEla(allCoef = coef(summary(estOProbitQuad))[, 1], allXVal = xMeanQuad, xPos = c(2, 3), model = "oprobit", allCoefVcov = sqrt(diag(vcov(estOProbitQuad))), iPos = 5) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEla( coef( summary( estOProbitQuad ) )[-6,1], xMeanQuad[-6],
> + xPos = c( 2, 3 ),iPos = 5, model = "oprobit",
> + sqrt( diag( vcov( estOProbitQuad ) ) )[-6] )
> semEla stdEr
> -0.313 0.460
> Warning message:
> In urbinEla(allCoef = coef(summary(estOProbitQuad))[-6, 1], allXVal = xMeanQuad[-6], xPos = c(2, 3), model = "oprobit", allCoefVcov = sqrt(diag(vcov(estOProbitQuad)))[-6], iPos = 5) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # semi-elasticity of age with standard errors (only standard errors, xMeanSd)
> > urbinEla( coef( summary( estOProbitQuad ) )[,1], xMeanQuad,
> + xPos = c( 2, 3 ), iPos = 5, model = "oprobit",
> + sqrt( diag( vcov( estOProbitQuad ) ) ),
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ),
> + seSimplify = FALSE )
> semEla stdEr
> -0.313 0.120
> Warning message:
> In urbinEla(coef(summary(estOProbitQuad))[, 1], xMeanQuad, xPos = c(2, :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > urbinEla( coef( summary( estOProbitQuad ) )[-6,1], xMeanQuad[-6],
> + xPos = c( 2, 3 ), iPos = 5, model = "oprobit",
> + sqrt( diag( vcov( estOProbitQuad ) ) )[-6],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ),
> + seSimplify = FALSE )
> semEla stdEr
> -0.313 0.120
> Warning message:
> In urbinEla(coef(summary(estOProbitQuad))[-6, 1], xMeanQuad[-6], :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > # semi-elasticity of age with standard errors (only standard errors, xMeanSd, simplified)
> > urbinEla( coef( summary( estOProbitQuad ) )[,1], xMeanQuad,
> + xPos = c( 2, 3 ), iPos = 5, model = "oprobit",
> + sqrt( diag( vcov( estOProbitQuad ) ) ),
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> semEla stdEr
> -0.313 0.111
> > urbinEla( coef( summary( estOProbitQuad ) )[-6,1], xMeanQuad[-6],
> + xPos = c( 2, 3 ), iPos = 5, model = "oprobit",
> + sqrt( diag( vcov( estOProbitQuad ) ) )[-6],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> semEla stdEr
> -0.313 0.111
> >
> >
> > ### age is interval-coded (age is in the range 30-60)
> > # create dummy variables for age intervals
> > Mroz87$age30.37 <- Mroz87$age >= 30 & Mroz87$age <= 37
> > Mroz87$age38.44 <- Mroz87$age >= 38 & Mroz87$age <= 44
> > Mroz87$age45.52 <- Mroz87$age >= 45 & Mroz87$age <= 52
> > Mroz87$age53.60 <- Mroz87$age >= 53 & Mroz87$age <= 60
> > all.equal(
> + Mroz87$age30.37 + Mroz87$age38.44 + Mroz87$age45.52 + Mroz87$age53.60,
> + rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > # estimation
> > estOProbitInt <- polr( lfp3 ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + data = Mroz87, method = "probit", Hess = TRUE )
> > summary( estOProbitInt )
> Call:
> polr(formula = lfp3 ~ kids + age30.37 + age38.44 + age53.60 +
> educ, data = Mroz87, Hess = TRUE, method = "probit")
>
> Coefficients:
> Value Std. Error t value
> kids -0.4291 0.1124 -3.82
> age30.37TRUE 0.1633 0.1139 1.43
> age38.44TRUE 0.1535 0.1220 1.26
> age53.60TRUE -0.4398 0.1485 -2.96
> educ 0.0798 0.0187 4.28
>
> Intercepts:
> Value Std. Error t value
> no|part 0.539 0.245 2.203
> part|full 1.267 0.247 5.129
>
> Residual Deviance: 1583.81
> AIC: 1597.81
> > # mean values of the explanatory variables and specification of the threshold
> > xMeanInt <- c( xMeanLin[1], mean( Mroz87$age30.37 ),
> + mean( Mroz87$age38.44 ), mean( Mroz87$age53.60 ), xMeanLin[3:5] )
> > # semi-elasticity of age without standard errors
> > urbinElaInt( coef( summary( estOProbitInt ) )[,1], xMeanInt,
> + c( 2, 3, 0, 4 ), iPos = 6, c( 30, 37.5, 44.5, 52.5, 60 ), model = "oprobit" )
> semEla stdEr
> -0.352 NA
> > urbinElaInt( coef( summary( estOProbitInt ) )[-7,1], xMeanInt[-7],
> + c( 2, 3, 0, 4 ), iPos = 6, c( 30, 37.5, 44.5, 52.5, 60 ), model = "oprobit" )
> semEla stdEr
> -0.352 NA
> > # semi-elasticities based on numerical derivation
> > Mroz87Lower <- Mroz87
> > Mroz87Lower$age <- Mroz87$age * 0.95
> > Mroz87Lower$age30.37 <- Mroz87Lower$age <= 37.5
> > Mroz87Lower$age38.44 <- Mroz87Lower$age > 37.5 & Mroz87Lower$age <= 44.5
> > Mroz87Lower$age45.52 <- Mroz87Lower$age > 44.5 & Mroz87Lower$age <= 52.5
> > Mroz87Lower$age53.60 <- Mroz87Lower$age > 52.5
> > all.equal(
> + Mroz87Lower$age30.37 + Mroz87Lower$age38.44 + Mroz87Lower$age45.52 +
> + Mroz87Lower$age53.60, rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > Mroz87Upper <- Mroz87
> > Mroz87Upper$age <- Mroz87$age * 1.05
> > Mroz87Upper$age30.37 <- Mroz87Upper$age <= 37.5
> > Mroz87Upper$age38.44 <- Mroz87Upper$age > 37.5 & Mroz87Upper$age <= 44.5
> > Mroz87Upper$age45.52 <- Mroz87Upper$age > 44.5 & Mroz87Upper$age <= 52.5
> > Mroz87Upper$age53.60 <- Mroz87Upper$age > 52.5
> > all.equal(
> + Mroz87Upper$age30.37 + Mroz87Upper$age38.44 + Mroz87Upper$age45.52 +
> + Mroz87Upper$age53.60, rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > elaIntNum <- 10 * ( colMeans(
> + predict( estOProbitInt, newdata = Mroz87Upper, type = "probs" ) ) -
> + colMeans(
> + predict( estOProbitInt, newdata = Mroz87Lower, type = "probs" ) ) )
> > print( elaIntNum )
> no part full
> 0.335 -0.053 -0.282
> > print( sum( elaIntNum[ c( "part", "full" ) ] ) )
> [1] -0.335
> > Mroz87LowerMean <- Mroz87Lower
> > Mroz87UpperMean <- Mroz87Upper
> > Mroz87LowerMean$kids <- Mroz87UpperMean$kids <- xMeanInt[ "kids" ]
> > Mroz87LowerMean$educ <- Mroz87UpperMean$educ <- xMeanInt[ "educ" ]
> > elaIntNumMean <- 10 * ( colMeans(
> + predict( estOProbitInt, newdata = Mroz87UpperMean, type = "probs" ) ) -
> + colMeans(
> + predict( estOProbitInt, newdata = Mroz87LowerMean, type = "probs" ) ) )
> > print( elaIntNumMean )
> no part full
> 0.3460 -0.0753 -0.2707
> > print( sum( elaIntNumMean[ c( "part", "full" ) ] ) )
> [1] -0.346
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinElaInt( coef( summary( estOProbitInt ) )[,1], xMeanInt,
> + c( 2, 3, 0, 4 ), iPos = 6, c( 30, 37.5, 44.5, 52.5, 60 ), model = "oprobit" )$derivCoef
> [1] 0.00210 -0.55574 -0.04940 0.55287 0.03714 -0.00302 0.00000
> > urbinElaInt( coef( summary( estOProbitInt ) )[-7,1], xMeanInt[-7],
> + c( 2, 3, 0, 4 ), iPos = 6, c( 30, 37.5, 44.5, 52.5, 60 ), model = "oprobit" )$derivCoef
> [1] 0.00210 -0.55574 -0.04940 0.55287 0.03714 -0.00302
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinElaInt( x, ... )$semEla },
> + t0 = coef( summary( estOProbitInt ) )[,1],
> + allXVal = xMeanInt, xPos = c( 2, 3, 0, 4 ), iPos = 6,
> + xBound = c( 30, 37.5, 44.5, 52.5, 60 ), model = "oprobit" ) )
> + }
> kids age30.37TRUE age38.44TRUE age53.60TRUE educ no|part part|full
> [1,] 0.0021 -0.556 -0.0494 0.553 0.0371 -0.00302 0
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinElaInt( x, ... )$semEla },
> + t0 = coef( summary( estOProbitInt ) )[-7,1],
> + allXVal = xMeanInt[-7], xPos = c( 2, 3, 0, 4 ), iPos = 6,
> + xBound = c( 30, 37.5, 44.5, 52.5, 60 ), model = "oprobit" ) )
> + }
> kids age30.37TRUE age38.44TRUE age53.60TRUE educ no|part
> [1,] 0.0021 -0.556 -0.0494 0.553 0.0371 -0.00302
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinElaInt( coef( summary( estOProbitInt ) )[,1], xMeanInt,
> + c( 2, 3, 0, 4 ), iPos = 6, c( 30, 37.5, 44.5, 52.5, 60 ), model = "oprobit",
> + allCoefVcov = vcov( estOProbitInt ) )
> semEla stdEr
> -0.3518 0.0926
> > urbinElaInt( coef( summary( estOProbitInt ) )[-7,1], xMeanInt[-7],
> + c( 2, 3, 0, 4 ), iPos = 6, c( 30, 37.5, 44.5, 52.5, 60 ), model = "oprobit",
> + allCoefVcov = vcov( estOProbitInt )[-7,-7] )
> semEla stdEr
> -0.3518 0.0926
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinElaInt( coef( summary( estOProbitInt ) )[,1], xMeanInt,
> + c( 2, 3, 0, 4 ), iPos = 6, c( 30, 37.5, 44.5, 52.5, 60 ), model = "oprobit",
> + allCoefVcov = sqrt( diag( vcov( estOProbitInt ) ) ) )
> semEla stdEr
> -0.352 0.104
> > urbinElaInt( coef( summary( estOProbitInt ) )[-7,1], xMeanInt[-7],
> + c( 2, 3, 0, 4 ), iPos = 6, c( 30, 37.5, 44.5, 52.5, 60 ), model = "oprobit",
> + allCoefVcov = sqrt( diag( vcov( estOProbitInt ) ) )[-7] )
> semEla stdEr
> -0.352 0.104
> >
> >
> > ### effect of age changing between discrete intervals
> > ### if age is used as linear explanatory variable
> > # mean values of the 'other' explanatory variables
> > xMeanLinInt <- c( xMeanLin[ 1 ], NA, xMeanLin[3:5] )
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # without standard errors
> > urbinEffInt( coef( summary( estOProbitLin ) )[,1], allXVal = xMeanLinInt,
> + xPos = 2, iPos = 4, refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "oprobit" )
> effect stdEr
> -0.146 NA
> > urbinEffInt( coef( summary( estOProbitLin ) )[-5,1], allXVal = xMeanLinInt[-5],
> + xPos = 2, iPos = 4, refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "oprobit" )
> effect stdEr
> -0.146 NA
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # based on predicted values
> > Mroz87Ref <- as.data.frame( t( replace( xMeanLin, 2, 35 ) ) )
> > Mroz87Int <- as.data.frame( t( replace( xMeanLin, 2, 55 ) ) )
> > effIntNum <- predict( estOProbitLin, newdata = Mroz87Int, type = "probs" ) -
> + predict( estOProbitLin, newdata = Mroz87Ref, type = "probs" )
> > print( effIntNum )
> no part full
> 0.1458 -0.0223 -0.1235
> > print( sum( effIntNum[ c( "part", "full" ) ] ) )
> [1] -0.146
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEffInt( coef( summary( estOProbitLin ) )[,1], xMeanLinInt,
> + xPos = 2, iPos = 4, c( 30, 40 ), c( 50, 60 ), model = "oprobit" )$derivCoef
> [1] 0.0130 8.6202 0.2295 -0.0187 0.0000
> > urbinEffInt( coef( summary( estOProbitLin ) )[-5,1], xMeanLinInt[-5],
> + xPos = 2, iPos = 4, c( 30, 40 ), c( 50, 60 ), model = "oprobit" )$derivCoef
> [1] 0.0130 8.6202 0.2295 -0.0187
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( summary( estOProbitLin ) )[,1],
> + allXVal = xMeanLinInt, xPos = 2, iPos = 4,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "oprobit" ) )
> + }
> kids age educ no|part part|full
> [1,] 0.013 8.62 0.23 -0.0187 0
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( summary( estOProbitLin ) )[-5,1],
> + allXVal = xMeanLinInt[-5], xPos = 2, iPos = 4,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "oprobit" ) )
> + }
> kids age educ no|part
> [1,] 0.013 8.62 0.23 -0.0187
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (full covariance matrix)
> > urbinEffInt( coef( summary( estOProbitLin ) )[,1], xMeanLinInt,
> + xPos = 2, iPos = 4, c( 30, 40 ), c( 50, 60 ), model = "oprobit",
> + allCoefVcov = vcov( estOProbitLin ) )
> effect stdEr
> -0.1458 0.0491
> > urbinEffInt( coef( summary( estOProbitLin ) )[-5,1], xMeanLinInt[-5],
> + xPos = 2, iPos = 4, c( 30, 40 ), c( 50, 60 ), model = "oprobit",
> + allCoefVcov = vcov( estOProbitLin )[-5,-5] )
> effect stdEr
> -0.1458 0.0491
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (only standard errors)
> > urbinEffInt( coef( summary( estOProbitLin ) )[,1], allXVal = xMeanLinInt,
> + xPos = 2, iPos = 4, refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "oprobit", allCoefVcov = sqrt( diag( vcov( estOProbitLin ) ) ) )
> effect stdEr
> -0.1458 0.0548
> > urbinEffInt( coef( summary( estOProbitLin ) )[-5,1], allXVal = xMeanLinInt[-5],
> + xPos = 2, iPos = 4, refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "oprobit", allCoefVcov = sqrt( diag( vcov( estOProbitLin ) ) )[-5] )
> effect stdEr
> -0.1458 0.0548
> >
> >
> > ### effect of age changing between discrete intervals
> > ### if age is used as linear and quadratic explanatory variable
> > # mean values of the 'other' explanatory variables
> > xMeanQuadInt <- c( xMeanLin[1], NA, NA, xMeanLin[3:5] )
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # without standard errors
> > urbinEffInt( coef( summary( estOProbitQuad ) )[,1], allXVal = xMeanQuadInt,
> + xPos = c( 2, 3 ), iPos = 5, refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "oprobit" )
> effect stdEr
> -0.24 NA
> > urbinEffInt( coef( summary( estOProbitQuad ) )[-6,1], allXVal = xMeanQuadInt[-6],
> + xPos = c( 2, 3 ), iPos = 5, refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "oprobit" )
> effect stdEr
> -0.24 NA
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # based on predicted values
> > Mroz87Ref <- as.data.frame( t( replace( xMeanQuad, 2:3, c( 35, 35^2 ) ) ) )
> > Mroz87Int <- as.data.frame( t( replace( xMeanQuad, 2:3, c( 55, 55^2 ) ) ) )
> > effIntQuadNum <- predict( estOProbitQuad, newdata = Mroz87Int, type = "probs" ) -
> + predict( estOProbitQuad, newdata = Mroz87Ref, type = "probs" )
> > print( effIntQuadNum )
> no part full
> 0.24 -0.05 -0.19
> > print( sum( effIntQuadNum[ c( "part", "full" ) ] ) )
> [1] -0.24
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffInt( coef( summary( estOProbitQuad ) )[,1], xMeanQuadInt,
> + xPos = c( 2, 3 ), iPos = 5, c( 30, 40 ), c( 50, 60 ), model = "oprobit" )$derivCoef
> [1] 0.00269 7.78730 693.44240 0.04753 -0.00387 0.00000
> > urbinEffInt( coef( summary( estOProbitQuad ) )[-6,1], xMeanQuadInt[-6],
> + xPos = c( 2, 3 ), iPos = 5, c( 30, 40 ), c( 50, 60 ), model = "oprobit" )$derivCoef
> [1] 0.00269 7.78730 693.44240 0.04753 -0.00387
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( summary( estOProbitQuad ) )[,1],
> + allXVal = xMeanQuadInt, xPos = c( 2, 3 ), iPos = 5,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "oprobit" ) )
> + }
> kids age I(age^2) educ no|part part|full
> [1,] 0.00269 7.79 693 0.0475 -0.00387 0
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( summary( estOProbitQuad ) )[-6,1],
> + allXVal = xMeanQuadInt[-6], xPos = c( 2, 3 ), iPos = 5,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "oprobit" ) )
> + }
> kids age I(age^2) educ no|part
> [1,] 0.00269 7.79 693 0.0475 -0.00387
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (full covariance matrix)
> > urbinEffInt( coef( summary( estOProbitQuad ) )[,1], xMeanQuadInt,
> + xPos = c( 2, 3 ), iPos = 5, c( 30, 40 ), c( 50, 60 ), model = "oprobit",
> + allCoefVcov = vcov( estOProbitQuad ) )
> effect stdEr
> -0.2403 0.0685
> > urbinEffInt( coef( summary( estOProbitQuad ) )[-6,1], xMeanQuadInt[-6],
> + xPos = c( 2, 3 ), iPos = 5, c( 30, 40 ), c( 50, 60 ), model = "oprobit",
> + allCoefVcov = vcov( estOProbitQuad )[-6,-6] )
> effect stdEr
> -0.2403 0.0685
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (only standard errors)
> > urbinEffInt( coef( summary( estOProbitQuad ) )[,1], allXVal = xMeanQuadInt,
> + xPos = c( 2, 3 ), iPos = 5, refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "oprobit", sqrt( diag( vcov( estOProbitQuad ) ) ) )
> effect stdEr
> -0.240 0.229
> Warning message:
> In urbinEffInt(allCoef = coef(summary(estOProbitQuad))[, 1], allXVal = xMeanQuadInt, xPos = c(2, 3), refBound = c(30, 40), intBound = c(50, 60), model = "oprobit", allCoefVcov = sqrt(diag(vcov(estOProbitQuad))), iPos = 5) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > urbinEffInt( coef( summary( estOProbitQuad ) )[-6,1], allXVal = xMeanQuadInt[-6],
> + xPos = c( 2, 3 ), iPos = 5, refBound = c( 30, 40 ), intBound = c( 50, 60 ),
> + model = "oprobit", sqrt( diag( vcov( estOProbitQuad ) ) )[-6] )
> effect stdEr
> -0.240 0.229
> Warning message:
> In urbinEffInt(allCoef = coef(summary(estOProbitQuad))[-6, 1], allXVal = xMeanQuadInt[-6], xPos = c(2, 3), refBound = c(30, 40), intBound = c(50, 60), model = "oprobit", allCoefVcov = sqrt(diag(vcov(estOProbitQuad)))[-6], iPos = 5) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (standard errors + mean value and standard deviation of age)
> > urbinEffInt( coef( summary( estOProbitQuad ) )[,1], xMeanQuadInt,
> + xPos = c( 2, 3 ), iPos = 5, c( 30, 40 ), c( 50, 60 ), model = "oprobit",
> + allCoefVcov = sqrt( diag( vcov( estOProbitQuad ) ) ),
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> effect stdEr
> -0.2403 0.0618
> > urbinEffInt( coef( summary( estOProbitQuad ) )[-6,1], xMeanQuadInt[-6],
> + xPos = c( 2, 3 ), iPos = 5, c( 30, 40 ), c( 50, 60 ), model = "oprobit",
> + allCoefVcov = sqrt( diag( vcov( estOProbitQuad ) ) )[-6],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> effect stdEr
> -0.2403 0.0618
> >
> >
> > ### grouping and re-basing categorical variables
> > ### effects of age changing from the 30-44 category to the 53-60 category
> > # without standard errors
> > urbinEffCat( coef( summary( estOProbitInt ) )[,1], xMeanInt,
> + xPos = c( 2:4 ), iPos = 6, xGroups = c( -1, -1, 1, 0 ), model = "oprobit" )
> effect stdEr
> -0.235 NA
> > urbinEffCat( coef( summary( estOProbitInt ) )[-7,1], xMeanInt[-7],
> + xPos = c( 2:4 ), iPos = 6, xGroups = c( -1, -1, 1, 0 ), model = "oprobit" )
> effect stdEr
> -0.235 NA
> > # effects calculated based on predicted values
> > names( xMeanInt ) <-
> + gsub( "TRUE|full:", "", rownames( coef( summary( estOProbitInt ) ) ) )
> > df30.37 <- df38.44 <- df45.52 <- df53.60 <- as.data.frame( t( xMeanInt ) )
> > df30.37[ , 2:4 ] <- c( TRUE, FALSE, FALSE )
> > df38.44[ , 2:4 ] <- c( FALSE, TRUE, FALSE )
> > df45.52[ , 2:4 ] <- c( FALSE, FALSE, FALSE )
> > df53.60[ , 2:4 ] <- c( FALSE, FALSE, TRUE )
> > effCatNum <- predict( estOProbitInt, newdata = df53.60, type = "probs" ) -
> + sum( Mroz87$age30.37 ) / sum( Mroz87$age30.37 + Mroz87$age38.44 ) *
> + predict( estOProbitInt, newdata = df30.37, type = "probs" ) -
> + sum( Mroz87$age38.44 ) / sum( Mroz87$age30.37 + Mroz87$age38.44 ) *
> + predict( estOProbitInt, newdata = df38.44, type = "probs" )
> > print( effCatNum )
> no part full
> 0.2355 -0.0531 -0.1824
> > print( sum( effCatNum[ c( "part", "full" ) ] ) )
> [1] -0.235
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffCat( coef( summary( estOProbitInt ) )[,1], xMeanInt,
> + c( 2:4 ), iPos = 6, c( -1, -1, 1, 0 ), model = "oprobit" )$derivCoef
> [1] 0.000246 -0.224116 -0.157149 0.381618 0.004343 -0.000353 0.000000
> > urbinEffCat( coef( summary( estOProbitInt ) )[-7,1], xMeanInt[-7],
> + c( 2:4 ), iPos = 6, c( -1, -1, 1, 0 ), model = "oprobit" )$derivCoef
> [1] 0.000246 -0.224116 -0.157149 0.381618 0.004343 -0.000353
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( summary( estOProbitInt ) )[,1],
> + allXVal = xMeanInt, xPos = c( 2:4 ), iPos = 6, xGroups = c( -1, -1, 1, 0 ),
> + model = "oprobit" ) )
> + }
> kids age30.37TRUE age38.44TRUE age53.60TRUE educ no|part
> [1,] 0.000246 -0.224 -0.157 0.382 0.00434 -0.000353
> part|full
> [1,] 0
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( summary( estOProbitInt ) )[-7,1],
> + allXVal = xMeanInt[-7], xPos = c( 2:4 ), iPos = 6, xGroups = c( -1, -1, 1, 0 ),
> + model = "oprobit" ) )
> + }
> kids age30.37TRUE age38.44TRUE age53.60TRUE educ no|part
> [1,] 0.000246 -0.224 -0.157 0.382 0.00434 -0.000353
> > # with full covariance matrix
> > urbinEffCat( coef( summary( estOProbitInt ) )[,1], xMeanInt, c( 2:4 ),
> + iPos = 6, c( -1, -1, 1, 0 ), vcov( estOProbitInt ),
> + model = "oprobit" )
> effect stdEr
> -0.2355 0.0601
> > urbinEffCat( coef( summary( estOProbitInt ) )[-7,1], xMeanInt[-7], c( 2:4 ),
> + iPos = 6, c( -1, -1, 1, 0 ), vcov( estOProbitInt )[-7,-7],
> + model = "oprobit" )
> effect stdEr
> -0.2355 0.0601
> > # with standard errors only
> > urbinEffCat( coef( summary( estOProbitInt ) )[,1], xMeanInt, c( 2:4 ),
> + iPos = 6, c( -1, -1, 1, 0 ), sqrt( diag( vcov( estOProbitInt ) ) ),
> + model = "oprobit" )
> effect stdEr
> -0.235 0.065
> > urbinEffCat( coef( summary( estOProbitInt ) )[-7,1], xMeanInt[-7], c( 2:4 ),
> + iPos = 6, c( -1, -1, 1, 0 ), sqrt( diag( vcov( estOProbitInt ) ) )[-7],
> + model = "oprobit" )
> effect stdEr
> -0.235 0.065
> >
> > ### effects of age changing from the 53-60 category to the 38-52 category
> > # without standard errors
> > urbinEffCat( coef( summary( estOProbitInt ) )[,1], xMeanInt, c( 2:4 ),
> + iPos = 6, c( 0, 1, -1, 1 ), model = "oprobit" )
> effect stdEr
> 0.2 NA
> > urbinEffCat( coef( summary( estOProbitInt ) )[-7,1], xMeanInt[-7], c( 2:4 ),
> + iPos = 6, c( 0, 1, -1, 1 ), model = "oprobit" )
> effect stdEr
> 0.2 NA
> > # effects calculated based on predicted values
> > effCat2Num <- sum( Mroz87$age38.44 ) / sum( Mroz87$age38.44 + Mroz87$age45.52 ) *
> + predict( estOProbitInt, newdata = df38.44, type = "probs" ) +
> + sum( Mroz87$age45.52 ) / sum( Mroz87$age38.44 + Mroz87$age45.52 ) *
> + predict( estOProbitInt, newdata = df45.52, type = "probs" ) -
> + predict( estOProbitInt, newdata = df53.60, type = "probs" )
> > print( effCat2Num )
> no part full
> -0.1995 0.0496 0.1499
> > print( sum( effCat2Num[ c( "part", "full" ) ] ) )
> [1] 0.199
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffCat( coef( summary( estOProbitInt ) )[,1], xMeanInt,
> + c( 2:4 ), iPos = 6, c( 0, 1, -1, 1 ), model = "oprobit" )$derivCoef
> [1] 0.00608 0.00000 0.16964 -0.38162 0.10743 -0.00874 0.00000
> > urbinEffCat( coef( summary( estOProbitInt ) )[-7,1], xMeanInt[-7],
> + c( 2:4 ), iPos = 6, c( 0, 1, -1, 1 ), model = "oprobit" )$derivCoef
> [1] 0.00608 0.00000 0.16964 -0.38162 0.10743 -0.00874
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( summary( estOProbitInt ) )[,1],
> + allXVal = xMeanInt, xPos = c( 2:4 ), iPos = 6, xGroups = c( 0, 1, -1, 1 ),
> + model = "oprobit" ) )
> + }
> kids age30.37TRUE age38.44TRUE age53.60TRUE educ no|part part|full
> [1,] 0.00608 0 0.17 -0.382 0.107 -0.00874 0
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( summary( estOProbitInt ) )[-7,1],
> + allXVal = xMeanInt[-7], xPos = c( 2:4 ), iPos = 6, xGroups = c( 0, 1, -1, 1 ),
> + model = "oprobit" ) )
> + }
> kids age30.37TRUE age38.44TRUE age53.60TRUE educ no|part
> [1,] 0.00608 0 0.17 -0.382 0.107 -0.00874
> > # with full covariance matrix
> > urbinEffCat( coef( summary( estOProbitInt ) )[,1], xMeanInt, c( 2:4 ),
> + iPos = 6, c( 0, 1, -1, 1 ), vcov( estOProbitInt ),
> + model = "oprobit" )
> effect stdEr
> 0.1997 0.0559
> > urbinEffCat( coef( summary( estOProbitInt ) )[-7,1], xMeanInt[-7], c( 2:4 ),
> + iPos = 6, c( 0, 1, -1, 1 ), vcov( estOProbitInt )[-7,-7],
> + model = "oprobit" )
> effect stdEr
> 0.1997 0.0559
> > # with standard errors only
> > urbinEffCat( coef( summary( estOProbitInt ) )[,1], xMeanInt, c( 2:4 ),
> + iPos = 6, c( 0, 1, -1, 1 ), sqrt( diag( vcov( estOProbitInt ) ) ),
> + model = "oprobit" )
> effect stdEr
> 0.1997 0.0604
> > urbinEffCat( coef( summary( estOProbitInt ) )[-7,1], xMeanInt[-7], c( 2:4 ),
> + iPos = 6, c( 0, 1, -1, 1 ), sqrt( diag( vcov( estOProbitInt ) ) )[-7],
> + model = "oprobit" )
> effect stdEr
> 0.1997 0.0604
> >
Running ‘probit.R’ [1s/1s]
Comparing ‘probit.Rout’ to ‘probit.Rout.save’ ...
22,24c22,98
< > proc.time()
< user system elapsed
< 0.732 0.092 0.847
---
> > options( digits = 4 )
> >
> > # load data set
> > data( "Mroz87", package = "sampleSelection" )
> >
> > # create dummy variable for kids
> > Mroz87$kids <- as.numeric( Mroz87$kids5 > 0 | Mroz87$kids618 > 0 )
> >
> > ### linear in age
> > estProbitLin <- glm( lfp ~ kids + age + educ,
> + family = binomial(link = "probit"),
> + data = Mroz87 )
> > summary( estProbitLin )
>
> Call:
> glm(formula = lfp ~ kids + age + educ, family = binomial(link = "probit"),
> data = Mroz87)
>
> Coefficients:
> Estimate Std. Error z value Pr(>|z|)
> (Intercept) -0.07161 0.45249 -0.16 0.8743
> kids -0.31563 0.12223 -2.58 0.0098 **
> age -0.01916 0.00698 -2.74 0.0061 **
> educ 0.10464 0.02124 4.93 8.3e-07 ***
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> (Dispersion parameter for binomial family taken to be 1)
>
> Null deviance: 1029.75 on 752 degrees of freedom
> Residual deviance: 993.43 on 749 degrees of freedom
> AIC: 1001
>
> Number of Fisher Scoring iterations: 4
>
> > # mean values of the explanatory variables
> > xMeanLin <- c( 1, colMeans( Mroz87[ , c( "kids", "age", "educ" ) ] ) )
> > # semi-elasticity of age without standard errors
> > urbinEla( coef( estProbitLin ), xMeanLin, xPos = 3, model = "probit" )
> semEla stdEr
> -0.3199 NA
> > # semi-elasticity of age based on numerical derivation
> > 100 * ( predict( estProbitLin,
> + newdata = as.data.frame( t( xMeanLin * c( 1, 1, 1.005, 1 ) ) ),
> + type = "response" ) -
> + predict( estProbitLin,
> + newdata = as.data.frame( t( xMeanLin * c( 1, 1, 0.995, 1 ) ) ),
> + type = "response" ) )
> 1
> -0.3199
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estProbitLin ), xMeanLin, 3, model = "probit",
> + seSimplify = FALSE )$derivCoef
> kids age educ
> 0.05743 0.03996 19.14172 0.70559
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estProbitLin ),
> + allXVal = xMeanLin, xPos = 3, model = "probit" ) )
> + }
> (Intercept) kids age educ
> [1,] 0.05743 0.03996 19.14 0.7056
> > # simplified partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estProbitLin ), xMeanLin, 3, model = "probit",
> + seSimplify = TRUE )$derivCoef
> [1] 0.0 0.0 16.7 0.0
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinEla( coef( estProbitLin ), xMeanLin, 3, model = "probit",
> + vcov( estProbitLin ) )
> semEla stdEr
> -0.3199 0.1166
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinEla( coef( estProbitLin ), xMeanLin, 3, model = "probit",
> + sqrt( diag( vcov( estProbitLin ) ) ), seSimplify = FALSE )
> semEla stdEr
> -0.3199 0.1371
26,27c100,669
< In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
< there is no package called 'sampleSelection'
---
> In urbinEla(coef(estProbitLin), xMeanLin, 3, model = "probit", sqrt(diag(vcov(estProbitLin))), :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > # semi-elasticity of age with standard errors (only standard errors, simplified)
> > urbinEla( coef( estProbitLin ), xMeanLin, 3, model = "probit",
> + sqrt( diag( vcov( estProbitLin ) ) ) )
> semEla stdEr
> -0.3199 0.1166
> > # semi-elasticity of age based on partial derivative calculated by the mfx package
> > if( mfxLoaded ) {
> + estProbitLinMfx <- probitmfx( lfp ~ kids + age + educ, data = Mroz87 )
> + print( estProbitLinMfx$mfxest[ "age", 1:2 ] * xMeanLin[ "age" ] )
> + }
> dF/dx Std. Err.
> -0.3199 0.1166
> > if( mfxLoaded ) {
> + print( urbinEla( estProbitLinMfx$mfxest[ "age", 1 ], xMeanLin["age"], 1, iPos = 0,
> + model = "lpm", estProbitLinMfx$mfxest[ "age", 2 ] ) )
> + }
> semEla stdEr
> -0.3199 0.1166
> > if( mfxLoaded ) {
> + print( urbinEla( estProbitLinMfx$mfxest[ , 1 ], xMeanLin[-1], 2, iPos = 0,
> + model = "lpm", estProbitLinMfx$mfxest[ , 2 ] ) )
> + }
> semEla stdEr
> -0.3199 0.1166
> >
> >
> > ### quadratic in age
> > estProbitQuad <- glm( lfp ~ kids + age + I(age^2) + educ,
> + family = binomial(link = "probit"),
> + data = Mroz87 )
> > summary( estProbitQuad )
>
> Call:
> glm(formula = lfp ~ kids + age + I(age^2) + educ, family = binomial(link = "probit"),
> data = Mroz87)
>
> Coefficients:
> Estimate Std. Error z value Pr(>|z|)
> (Intercept) -4.328938 1.394393 -3.10 0.00191 **
> kids -0.438760 0.129528 -3.39 0.00071 ***
> age 0.192165 0.065880 2.92 0.00354 **
> I(age^2) -0.002493 0.000773 -3.22 0.00126 **
> educ 0.107041 0.021411 5.00 5.8e-07 ***
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> (Dispersion parameter for binomial family taken to be 1)
>
> Null deviance: 1029.75 on 752 degrees of freedom
> Residual deviance: 982.88 on 748 degrees of freedom
> AIC: 992.9
>
> Number of Fisher Scoring iterations: 4
>
> > # mean values of the explanatory variables
> > xMeanQuad <- c( xMeanLin[ 1:3], xMeanLin[3]^2, xMeanLin[4] )
> > # semi-elasticity of age without standard errors
> > urbinEla( coef( estProbitQuad ), xMeanQuad, c( 3, 4 ), model = "probit" )
> semEla stdEr
> -0.3193 NA
> > # semi-elasticity of age based on numerical derivation
> > 100 * ( predict( estProbitQuad,
> + newdata = as.data.frame( t( xMeanQuad * c( 1, 1, 1.005, 1.005^2, 1 ) ) ),
> + type = "response" ) -
> + predict( estProbitQuad,
> + newdata = as.data.frame( t( xMeanQuad * c( 1, 1, 0.995, 0.995^2, 1 ) ) ),
> + type = "response" ) )
> 1
> -0.3193
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estProbitQuad ), xMeanQuad, c( 3, 4 ), model = "probit",
> + seSimplify = FALSE )$derivCoef
> kids age age educ
> 1.097e-01 7.634e-02 2.066e+01 1.560e+03 1.348e+00
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEla( x, ... )$semEla },
> + t0 = coef( estProbitQuad ),
> + allXVal = xMeanQuad, xPos = c( 3, 4 ), model = "probit" ) )
> + }
> (Intercept) kids age I(age^2) educ
> [1,] 0.1097 0.07634 20.66 1560 1.348
> > # simplified partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEla( coef( estProbitQuad ), xMeanQuad, c( 3, 4 ), model = "probit",
> + seSimplify = TRUE )$derivCoef
> [1] 0 0 16 1361 0
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinEla( coef( estProbitQuad ), xMeanQuad, c( 3, 4 ), model = "probit",
> + vcov( estProbitQuad ) )
> semEla stdEr
> -0.3193 0.1120
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinEla( coef( estProbitQuad ), xMeanQuad, c( 3, 4 ), model = "probit",
> + sqrt( diag( vcov( estProbitQuad ) ) ), seSimplify = FALSE )
> semEla stdEr
> -0.3193 1.8254
> Warning messages:
> 1: In urbinEla(coef(estProbitQuad), xMeanQuad, c(3, 4), model = "probit", :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> 2: In urbinEla(allCoef = coef(estProbitQuad), allXVal = xMeanQuad, xPos = c(3, 4), model = "probit", allCoefVcov = sqrt(diag(vcov(estProbitQuad))), seSimplify = FALSE) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # semi-elasticity of age with standard errors (only standard errors, simplified)
> > urbinEla( coef( estProbitQuad ), xMeanQuad, c( 3, 4 ), model = "probit",
> + sqrt( diag( vcov( estProbitQuad ) ) ) )
> semEla stdEr
> -0.3193 1.4895
> Warning message:
> In urbinEla(allCoef = coef(estProbitQuad), allXVal = xMeanQuad, xPos = c(3, 4), model = "probit", allCoefVcov = sqrt(diag(vcov(estProbitQuad)))) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # semi-elasticity of age with standard errors (only standard errors, xMeanSd)
> > urbinEla( coef( estProbitQuad ), xMeanQuad, c( 3, 4 ), model = "probit",
> + sqrt( diag( vcov( estProbitQuad ) ) ),
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ),
> + seSimplify = FALSE )
> semEla stdEr
> -0.3193 0.1105
> Warning message:
> In urbinEla(coef(estProbitQuad), xMeanQuad, c(3, 4), model = "probit", :
> the returned standard error is likely very imprecise; you can provide the full covariance matrix via argument 'allCoefVcov' or do NOT set argument 'seSimplify' to FALSE to obtain a more precise standard error
> > # semi-elasticity of age with standard errors (only standard errors, xMeanSd, simplified)
> > urbinEla( coef( estProbitQuad ), xMeanQuad, c( 3, 4 ), model = "probit",
> + sqrt( diag( vcov( estProbitQuad ) ) ),
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> semEla stdEr
> -0.3193 0.1352
> > # semi-elasticity of age based on partial derivatives calculated by the mfx package
> > # (differs from the above, because mean(age)^2 is not the same as mean(age^2))
> > if( mfxLoaded ) {
> + estProbitQuadMfx <- probitmfx( lfp ~ kids + age + I(age^2) + educ, data = Mroz87 )
> + print( estProbitQuadMfx$mfxest[ "age", 1:2 ] * xMeanQuad[ "age" ] +
> + 2 * estProbitQuadMfx$mfxest[ "I(age^2)", 1:2 ] * xMeanQuad[ "age" ]^2 )
> + }
> dF/dx Std. Err.
> -0.3332 2.1983
> > if( mfxLoaded ) {
> + print( urbinEla( estProbitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 1 ],
> + xMeanQuad["age"], 1:2, iPos = 0,
> + model = "lpm", estProbitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 2 ] ) )
> + }
> semEla stdEr
> -0.3332 1.5544
> Warning message:
> In urbinEla(allCoef = estProbitQuadMfx$mfxest[c("age", "I(age^2)"), 1], allXVal = xMeanQuad["age"], xPos = 1:2, model = "lpm", allCoefVcov = estProbitQuadMfx$mfxest[c("age", "I(age^2)"), 2], iPos = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > if( mfxLoaded ) {
> + print( urbinEla( estProbitQuadMfx$mfxest[ , 1 ],
> + xMeanQuad[-1], 2:3, iPos = 0,
> + model = "lpm", estProbitQuadMfx$mfxest[ , 2 ] ) )
> + }
> semEla stdEr
> -0.3332 1.5544
> Warning message:
> In urbinEla(allCoef = estProbitQuadMfx$mfxest[, 1], allXVal = xMeanQuad[-1], xPos = 2:3, model = "lpm", allCoefVcov = estProbitQuadMfx$mfxest[, 2], iPos = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > if( mfxLoaded ) {
> + print( urbinEla( estProbitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 1 ],
> + xMeanQuad["age"], 1:2, iPos = 0,
> + model = "lpm", estProbitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 2 ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) ) )
> + }
> semEla stdEr
> -0.3332 0.1411
> > if( mfxLoaded ) {
> + print( urbinEla( estProbitQuadMfx$mfxest[ , 1 ],
> + xMeanQuad[-1], 2:3, iPos = 0,
> + model = "lpm", estProbitQuadMfx$mfxest[ , 2 ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) ) )
> + }
> semEla stdEr
> -0.3332 0.1411
> >
> >
> > ### age is interval-coded (age is in the range 30-60)
> > # create dummy variables for age intervals
> > Mroz87$age30.37 <- Mroz87$age >= 30 & Mroz87$age <= 37
> > Mroz87$age38.44 <- Mroz87$age >= 38 & Mroz87$age <= 44
> > Mroz87$age45.52 <- Mroz87$age >= 45 & Mroz87$age <= 52
> > Mroz87$age53.60 <- Mroz87$age >= 53 & Mroz87$age <= 60
> > all.equal(
> + Mroz87$age30.37 + Mroz87$age38.44 + Mroz87$age45.52 + Mroz87$age53.60,
> + rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > # estimation
> > estProbitInt <- glm( lfp ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + family = binomial(link = "probit"),
> + data = Mroz87 )
> > summary( estProbitInt )
>
> Call:
> glm(formula = lfp ~ kids + age30.37 + age38.44 + age53.60 + educ,
> family = binomial(link = "probit"), data = Mroz87)
>
> Coefficients:
> Estimate Std. Error z value Pr(>|z|)
> (Intercept) -0.8916 0.2769 -3.22 0.0013 **
> kids -0.3775 0.1267 -2.98 0.0029 **
> age30.37TRUE 0.1351 0.1270 1.06 0.2876
> age38.44TRUE 0.1215 0.1360 0.89 0.3720
> age53.60TRUE -0.5142 0.1630 -3.15 0.0016 **
> educ 0.1080 0.0214 5.06 4.2e-07 ***
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> (Dispersion parameter for binomial family taken to be 1)
>
> Null deviance: 1029.75 on 752 degrees of freedom
> Residual deviance: 986.78 on 747 degrees of freedom
> AIC: 998.8
>
> Number of Fisher Scoring iterations: 4
>
> > # mean values of the explanatory variables
> > xMeanInt <- c( xMeanLin[1:2], mean( Mroz87$age30.37 ),
> + mean( Mroz87$age38.44 ), mean( Mroz87$age53.60 ), xMeanLin[4] )
> > # semi-elasticity of age without standard errors
> > urbinElaInt( coef( estProbitInt ), xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "probit" )
> semEla stdEr
> -0.3754 NA
> > # semi-elasticities based on numerical derivation
> > Mroz87Lower <- Mroz87
> > Mroz87Lower$age <- Mroz87$age * 0.95
> > Mroz87Lower$age30.37 <- Mroz87Lower$age <= 37.5
> > Mroz87Lower$age38.44 <- Mroz87Lower$age > 37.5 & Mroz87Lower$age <= 44.5
> > Mroz87Lower$age45.52 <- Mroz87Lower$age > 44.5 & Mroz87Lower$age <= 52.5
> > Mroz87Lower$age53.60 <- Mroz87Lower$age > 52.5
> > all.equal(
> + Mroz87Lower$age30.37 + Mroz87Lower$age38.44 + Mroz87Lower$age45.52 +
> + Mroz87Lower$age53.60, rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > Mroz87Upper <- Mroz87
> > Mroz87Upper$age <- Mroz87$age * 1.05
> > Mroz87Upper$age30.37 <- Mroz87Upper$age <= 37.5
> > Mroz87Upper$age38.44 <- Mroz87Upper$age > 37.5 & Mroz87Upper$age <= 44.5
> > Mroz87Upper$age45.52 <- Mroz87Upper$age > 44.5 & Mroz87Upper$age <= 52.5
> > Mroz87Upper$age53.60 <- Mroz87Upper$age > 52.5
> > all.equal(
> + Mroz87Upper$age30.37 + Mroz87Upper$age38.44 + Mroz87Upper$age45.52 +
> + Mroz87Upper$age53.60, rep( 1, nrow( Mroz87 ) ) )
> [1] TRUE
> > 10 * mean( predict( estProbitInt, newdata = Mroz87Upper, type = "response" ) -
> + predict( estProbitInt, newdata = Mroz87Lower, type = "response" ) )
> [1] -0.3517
> > Mroz87LowerMean <- Mroz87Lower
> > Mroz87UpperMean <- Mroz87Upper
> > Mroz87LowerMean$kids <- Mroz87UpperMean$kids <- xMeanInt[ "kids" ]
> > Mroz87LowerMean$educ <- Mroz87UpperMean$educ <- xMeanInt[ "educ" ]
> > 10 * mean( predict( estProbitInt, newdata = Mroz87UpperMean, type = "response" ) -
> + predict( estProbitInt, newdata = Mroz87LowerMean, type = "response" ) )
> [1] -0.3664
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinElaInt( coef( estProbitInt ), xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ), model = "probit" )$derivCoef
> [1] -0.004223 -0.002939 -0.555180 -0.049412 0.545345 -0.051890
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinElaInt( x, ... )$semEla },
> + t0 = coef( estProbitInt ), allXVal = xMeanInt,
> + xPos = c( 3, 4, 0, 5 ), xBound = c( 30, 37.5, 44.5, 52.5, 60 ),
> + model = "probit" ) )
> + }
> (Intercept) kids age30.37TRUE age38.44TRUE age53.60TRUE educ
> [1,] -0.004223 -0.002939 -0.5552 -0.04941 0.5453 -0.05189
> > # semi-elasticity of age with standard errors (full covariance matrix)
> > urbinElaInt( coef( estProbitInt ), xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ),
> + model = "probit", vcov( estProbitInt ) )
> semEla stdEr
> -0.3754 0.1010
> > # semi-elasticity of age with standard errors (only standard errors)
> > urbinElaInt( coef( estProbitInt ), xMeanInt,
> + c( 3, 4, 0, 5 ), c( 30, 37.5, 44.5, 52.5, 60 ),
> + model = "probit", sqrt( diag( vcov( estProbitInt ) ) ) )
> semEla stdEr
> -0.3754 0.1137
> > # semi-elasticity of age based on partial derivatives calculated by the mfx package
> > if( mfxLoaded ) {
> + estProbitIntMfx <- probitmfx( lfp ~ kids + age30.37 + age38.44 + age53.60 + educ,
> + data = Mroz87 )
> + print( urbinElaInt( estProbitIntMfx$mfxest[ 2:4, 1 ], xMeanInt[ 3:5 ],
> + c( 1, 2, 0, 3 ), iPos = 0, c( 30, 37.5, 44.5, 52.5, 60 ), model = "lpm",
> + estProbitIntMfx$mfxest[ 2:4, 2 ] ) )
> + }
> semEla stdEr
> -0.3770 0.1162
> > if( mfxLoaded ) {
> + print( urbinElaInt( estProbitIntMfx$mfxest[ , 1 ], xMeanInt[ -1 ],
> + c( 2, 3, 0, 4 ), iPos = 0, c( 30, 37.5, 44.5, 52.5, 60 ), model = "lpm",
> + estProbitIntMfx$mfxest[ , 2 ] ) )
> + }
> semEla stdEr
> -0.3770 0.1162
> >
> >
> > ### effect of age changing between discrete intervals
> > ### if age is used as linear explanatory variable
> > # mean values of the 'other' explanatory variables
> > xMeanLinInt <- c( xMeanLin[ 1:2 ], NA, xMeanLin[4] )
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # without standard errors
> > urbinEffInt( coef( estProbitLin ), xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "probit" )
> effect stdEr
> -0.1506 NA
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # based on predicted values
> > predict( estProbitLin,
> + newdata = as.data.frame( t( replace( xMeanLin, 3, 55 ) ) ),
> + type = "response" ) -
> + predict( estProbitLin,
> + newdata = as.data.frame( t( replace( xMeanLin, 3, 35 ) ) ),
> + type = "response" )
> 1
> -0.1506
> > # partial derivatives of the semi-elasticity wrt the coefficients
> > urbinEffInt( coef( estProbitLin ), xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "probit" )$derivCoef
> [1] 0.01969 0.01370 8.65401 0.24193
> > # numerically computed partial derivatives of the semi-elasticity wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estProbitLin ),
> + allXVal = xMeanLinInt, xPos = 3,
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "probit" ) )
> + }
> (Intercept) kids age educ
> [1,] 0.01969 0.0137 8.654 0.2419
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (full covariance matrix)
> > urbinEffInt( coef( estProbitLin ), xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "probit",
> + allCoefVcov = vcov( estProbitLin ) )
> effect stdEr
> -0.15062 0.05457
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (only standard errors)
> > urbinEffInt( coef( estProbitLin ), xMeanLinInt, 3,
> + c( 30, 40 ), c( 50, 60 ), model = "probit",
> + allCoefVcov = sqrt( diag( vcov( estProbitLin ) ) ) )
> effect stdEr
> -0.15062 0.06132
> > # semi-elasticity of age based on partial derivative calculated by the mfx package
> > if( mfxLoaded ) {
> + print( urbinEffInt( estProbitLinMfx$mfxest[ "age", 1 ], NULL, 1, iPos = 0,
> + c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estProbitLinMfx$mfxest[ "age", 2 ] ) )
> + }
> effect stdEr
> -0.15041 0.05482
> > if( mfxLoaded ) {
> + print( urbinEffInt( estProbitLinMfx$mfxest[ , 1 ], NULL, 2, iPos = 0,
> + c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estProbitLinMfx$mfxest[ , 2 ] ) )
> + }
> effect stdEr
> -0.15041 0.05482
> >
> >
> > ### effect of age changing between discrete intervals
> > ### if age is used as linear and quadratic explanatory variable
> > # mean values of the 'other' explanatory variables
> > xMeanQuadInt <- c( xMeanLin[ 1:2 ], NA, NA, xMeanLin[4] )
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # without standard errors
> > urbinEffInt( coef( estProbitQuad ), xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "probit" )
> effect stdEr
> -0.2528 NA
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # based on predicted values
> > predict( estProbitQuad,
> + newdata = as.data.frame( t( replace( xMeanQuad, 3:4, c( 55, 55^2 ) ) ) ),
> + type = "response" ) -
> + predict( estProbitQuad,
> + newdata = as.data.frame( t( replace( xMeanQuad, 3:4, c( 35, 35^2 ) ) ) ),
> + type = "response" )
> 1
> -0.2527
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffInt( coef( estProbitQuad ), xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "probit" )$derivCoef
> [1] 2.238e-03 1.557e-03 7.675e+00 6.865e+02 2.750e-02
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffInt( x, ... )$effect },
> + t0 = coef( estProbitQuad ),
> + allXVal = xMeanQuadInt, xPos = c( 3, 4 ),
> + refBound = c( 30, 40 ), intBound = c( 50, 60 ), model = "probit" ) )
> + }
> (Intercept) kids age I(age^2) educ
> [1,] 0.002238 0.001557 7.675 686.5 0.0275
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (full covariance matrix)
> > urbinEffInt( coef( estProbitQuad ), xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "probit",
> + allCoefVcov = vcov( estProbitQuad ) )
> effect stdEr
> -0.25282 0.06148
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (only standard errors)
> > urbinEffInt( coef( estProbitQuad ), xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "probit",
> + allCoefVcov = sqrt( diag( vcov( estProbitQuad ) ) ) )
> effect stdEr
> -0.2528 0.7332
> Warning message:
> In urbinEffInt(allCoef = coef(estProbitQuad), allXVal = xMeanQuadInt, xPos = c(3, 4), refBound = c(30, 40), intBound = c(50, 60), model = "probit", allCoefVcov = sqrt(diag(vcov(estProbitQuad)))) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > # effects of age changing from the 30-40 interval to the 50-60 interval
> > # (standard errors + mean value and standard deviation of age)
> > urbinEffInt( coef( estProbitQuad ), xMeanQuadInt, c( 3, 4 ),
> + c( 30, 40 ), c( 50, 60 ), model = "probit",
> + allCoefVcov = sqrt( diag( vcov( estProbitQuad ) ) ),
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) )
> effect stdEr
> -0.25282 0.07137
> > # semi-elasticity of age based on partial derivative calculated by the mfx package
> > if( mfxLoaded ) {
> + print( urbinEffInt( estProbitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 1 ], NULL, 1:2,
> + iPos = 0, c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estProbitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 2 ] ) )
> + }
> effect stdEr
> -0.2530 0.7523
> Warning message:
> In urbinEffInt(allCoef = estProbitQuadMfx$mfxest[c("age", "I(age^2)"), 1], allXVal = NULL, xPos = 1:2, refBound = c(30, 40), intBound = c(50, 60), model = "lpm", allCoefVcov = estProbitQuadMfx$mfxest[c("age", "I(age^2)"), 2], iPos = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > if( mfxLoaded ) {
> + print( urbinEffInt( estProbitQuadMfx$mfxest[ , 1 ], NULL, 2:3,
> + iPos = 0, c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estProbitQuadMfx$mfxest[ , 2 ] ) )
> + }
> effect stdEr
> -0.2530 0.7523
> Warning message:
> In urbinEffInt(allCoef = estProbitQuadMfx$mfxest[, 1], allXVal = NULL, xPos = 2:3, refBound = c(30, 40), intBound = c(50, 60), model = "lpm", allCoefVcov = estProbitQuadMfx$mfxest[, 2], iPos = 0) :
> the returned standard error is likely largely upward biased and, thus, in most cases meaningless; you can provide the full covariance matrix via argument 'allCoefVcov' to avoid this bias or use argument 'xMeanSd' to substantially reduce this bias
> > if( mfxLoaded ) {
> + print( urbinEffInt( estProbitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 1 ], NULL, 1:2,
> + iPos = 0, c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estProbitQuadMfx$mfxest[ c( "age", "I(age^2)" ), 2 ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) ) )
> + }
> effect stdEr
> -0.25303 0.07423
> > if( mfxLoaded ) {
> + print( urbinEffInt( estProbitQuadMfx$mfxest[ , 1 ], NULL, 2:3,
> + iPos = 0, c( 30, 40 ), c( 50, 60 ), model = "lpm",
> + estProbitQuadMfx$mfxest[ , 2 ],
> + xMeanSd = c( mean( Mroz87$age ), sd( Mroz87$age ) ) ) )
> + }
> effect stdEr
> -0.25303 0.07423
> >
> >
> > ### grouping and re-basing categorical variables
> > ### effects of age changing from the 30-44 category to the 53-60 category
> > # without standard errors
> > urbinEffCat( coef( estProbitInt ), xMeanInt, c( 3:5 ), c( -1, -1, 1, 0 ),
> + model = "probit" )
> effect stdEr
> -0.2524 NA
> > # effects calculated based on predicted values
> > names( xMeanInt ) <- sub( "TRUE", "", names( coef( estProbitInt ) ) )
> > df30.37 <- df38.44 <- df45.52 <- df53.60 <- as.data.frame( t( xMeanInt ) )
> > df30.37[ , 3:5 ] <- c( TRUE, FALSE, FALSE )
> > df38.44[ , 3:5 ] <- c( FALSE, TRUE, FALSE )
> > df45.52[ , 3:5 ] <- c( FALSE, FALSE, FALSE )
> > df53.60[ , 3:5 ] <- c( FALSE, FALSE, TRUE )
> > predict( estProbitInt, newdata = df53.60, type = "response" ) -
> + sum( Mroz87$age30.37 ) / sum( Mroz87$age30.37 + Mroz87$age38.44 ) *
> + predict( estProbitInt, newdata = df30.37, type = "response" ) -
> + sum( Mroz87$age38.44 ) / sum( Mroz87$age30.37 + Mroz87$age38.44 ) *
> + predict( estProbitInt, newdata = df38.44, type = "response" )
> 1
> -0.2524
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffCat( coef( estProbitInt ), xMeanInt, c( 3:5 ), c( -1, -1, 1, 0 ),
> + model = "probit" )$derivCoef
> [1] -0.004644 -0.003231 -0.224001 -0.157068 0.376426 -0.057056
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estProbitInt ),
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( -1, -1, 1, 0 ),
> + model = "probit" ) )
> + }
> (Intercept) kids age30.37TRUE age38.44TRUE age53.60TRUE educ
> [1,] -0.004644 -0.003231 -0.224 -0.1571 0.3764 -0.05706
> > # with full covariance matrix
> > urbinEffCat( coef( estProbitInt ), xMeanInt, c( 3:5 ), c( -1, -1, 1, 0 ),
> + model = "probit", allCoefVcov = vcov( estProbitInt ) )
> effect stdEr
> -0.25237 0.06538
> > # with standard errors only
> > urbinEffCat( coef( estProbitInt ), xMeanInt, c( 3:5 ), c( -1, -1, 1, 0 ),
> + model = "probit", allCoefVcov = sqrt( diag( vcov( estProbitInt ) ) ) )
> effect stdEr
> -0.25237 0.07097
> > # semi-elasticity of age based on partial derivative calculated by the mfx package
> > if( mfxLoaded ) {
> + print( urbinEffCat( estProbitIntMfx$mfxest[ 2:4, 1 ],
> + xMeanInt[ 3:5 ], c(1:3), iPos = 0, c( -1, -1, 1, 0 ), model = "lpm",
> + estProbitIntMfx$mfxest[ 2:4, 2 ] ) )
> + }
> effect stdEr
> -0.25340 0.07249
> > if( mfxLoaded ) {
> + print( urbinEffCat( estProbitIntMfx$mfxest[ , 1 ],
> + xMeanInt[ -1 ], c(2:4), iPos = 0, c( -1, -1, 1, 0 ), model = "lpm",
> + estProbitIntMfx$mfxest[ , 2 ] ) )
> + }
> effect stdEr
> -0.25340 0.07249
> >
> >
> > ### effects of age changing from the 53-60 category to the 38-52 category
> > # without standard errors
> > urbinEffCat( coef( estProbitInt ), xMeanInt, c( 3:5 ), c( 0, 1, -1, 1 ),
> + model = "probit" )
> effect stdEr
> 0.2228 NA
> > # effects calculated based on predicted values
> > sum( Mroz87$age38.44 ) / sum( Mroz87$age38.44 + Mroz87$age45.52 ) *
> + predict( estProbitInt, newdata = df38.44, type = "response" ) +
> + sum( Mroz87$age45.52 ) / sum( Mroz87$age38.44 + Mroz87$age45.52 ) *
> + predict( estProbitInt, newdata = df45.52, type = "response" ) -
> + predict( estProbitInt, newdata = df53.60, type = "response" )
> 1
> 0.2227
> > # partial derivatives of the effect wrt the coefficients
> > urbinEffCat( coef( estProbitInt ), xMeanInt, c( 3:5 ), c( 0, 1, -1, 1 ),
> + model = "probit" )$derivCoef
> [1] 0.012449 0.008663 0.000000 0.168992 -0.376426 0.152958
> > # numerically computed partial derivatives of the effect wrt the coefficients
> > if( maxLikLoaded ) {
> + print( numericGradient( function( x, ... ){ urbinEffCat( x, ... )$effect },
> + t0 = coef( estProbitInt ),
> + allXVal = xMeanInt, xPos = c( 3:5 ), xGroups = c( 0, 1, -1, 1 ),
> + model = "probit" ) )
> + }
> (Intercept) kids age30.37TRUE age38.44TRUE age53.60TRUE educ
> [1,] 0.01245 0.008663 0 0.169 -0.3764 0.153
> > # with full covariance matrix
> > urbinEffCat( coef( estProbitInt ), xMeanInt, c( 3:5 ), c( 0, 1, -1, 1 ),
> + model = "probit", allCoefVcov = vcov( estProbitInt ) )
> effect stdEr
> 0.2228 0.0607
> > # with standard errors only
> > urbinEffCat( coef( estProbitInt ), xMeanInt, c( 3:5 ), c( 0, 1, -1, 1 ),
> + model = "probit", allCoefVcov = sqrt( diag( vcov( estProbitInt ) ) ) )
> effect stdEr
> 0.22284 0.06572
> > # semi-elasticity of age based on partial derivative calculated by the mfx package
> > if( mfxLoaded ) {
> + print( urbinEffCat( estProbitIntMfx$mfxest[ 2:4, 1 ], xMeanInt[ 3:5 ], c(1:3),
> + c( 0, 1, -1, 1 ), iPos = 0, model = "lpm", estProbitIntMfx$mfxest[ 2:4, 2 ] ) )
> + }
> effect stdEr
> 0.22346 0.06683
> > if( mfxLoaded ) {
> + print( urbinEffCat( estProbitIntMfx$mfxest[ , 1 ], xMeanInt[ -1 ], c(2:4),
> + c( 0, 1, -1, 1 ), iPos = 0, model = "lpm", estProbitIntMfx$mfxest[ , 2 ] ) )
> + }
> effect stdEr
> 0.22346 0.06683
> >
> >
Flavor: r-devel-linux-x86_64-debian-gcc
Version: 0.1-16
Check: re-building of vignette outputs
Result: ERROR
Error(s) in re-building vignettes:
...
--- re-building ‘ExtendedAppendix.Rnw’ using knitr
--- finished re-building ‘ExtendedAppendix.Rnw’
--- re-building ‘Manuscript.Rnw’ using knitr
Quitting from Manuscript.Rnw:158-160 [dataLoad]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
there is no package called 'sampleSelection'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quitting from Manuscript.Rnw:158-160 [dataLoad]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
find.package(package, lib.loc, verbose = verbose)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quitting from Manuscript.Rnw:158-160 [dataLoad]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sampleSelection
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quitting from Manuscript.Rnw:158-160 [dataLoad]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/RtmpwBMltT/RLIBS_306b9ae289219 , /home/hornik/tmp/R.check/r-devel-gcc/Work/build/library
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: processing vignette 'Manuscript.Rnw' failed with diagnostics:
there is no package called 'sampleSelection'
--- failed re-building ‘Manuscript.Rnw’
SUMMARY: processing the following file failed:
‘Manuscript.Rnw’
Error: Vignette re-building failed.
Execution halted
Flavor: r-devel-linux-x86_64-debian-gcc