Description Usage Arguments Details Value References See Also Examples
This function implements the Tobit II family for the mgcv package.
1 2 |
link |
The link functions: Corresponds to |
censoring |
Vector of TRUE/FALSE values to denote censorship. TRUE values are censored |
rho |
Value of rho. If NULL, is estimated. |
eps |
Parameter to perturb rho in estimation if very close to -1 or 1. |
Under the Tobit II model, given a value sigma and a conditional mean of mu1, and a censoring parameter mu2, response values are censored if mu2 + epsilon2 < 0, and mu1 + sigma*epsilon1 otherwise.
Here epsilon1, epsilon2 are distributed Normal(0, 1) with correlated rho.
This function allows a non-linear relationship be estimated between mu1, mu2, sigma, rho and the covariates in a restricted maximum likelihood approach, via application of Wood (2016). Note that this allows for heteroskedastic errors.
Estimation of rho depends on the distributional qualities near the censorship boundary, and is hence typically very inaccurate for typical sample sizes. Hence in practice it is often better to supply a value of rho (for example 0 to imply independent censorship) instead. eps is used when estimating rho to avoid errors when rho is close to 1 or -1. Smaller values may produce more accurate results.
This method is still currently very *experimental*. It's not suggested to be used to important applications. Errors can occur if the default starting point for the function cause problems, consider changing the start
argument to gam
.
An object inheriting from class family
for use with the mgcv package.
Wood, S.N., N. Pya and B. Saefken (2016), Smoothing parameter and model selection for general smooth models. Journal of the American Statistical Association. <URL: http://arxiv.org/abs/1511.03864>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | # Generate a small example
set.seed(1)
x <- matrix(2*rnorm(400), 200)
yn <- x[,1]^2 + x[,2]
y <- yn + rnorm(200)
censored <- (rnorm(200) + 2*x[,2]+1) < 0 #censored according to x[,2]
ycensored <- replace(y, censored, 0)
m <- gam(c(ycensored ~ s(x[,1]) + s(x[,2]) , ~x[,1]+x[,2], ~1,~1),
family = tobit2(censoring = censored)) #estimated rho
par(mfrow = c(3,2))
plot(gam(y ~ s(x[,1]) + s(x[,2]) ), ylim=c(-5, 5), main = "True")
plot(m, ylim = c(-5, 5), main = "Tobit II estimated rho")
summary(m)
m$fitted #gives for each observation fitted mu1, mu2, sigma, rho
m2 <- gam(c(ycensored ~ s(x[,1]) + s(x[,2]) , ~x[,1]+x[,2], ~1),
family = tobit2(censoring = censored, rho=0)) #non estimated rho
plot(m2, ylim = c(-5, 5), main = "Tobit II fixed rho")
## Not run:
#Larger example
set.seed(1)
x <- matrix(2*rnorm(1500), 500)
yn <- 2*x[,3] + 4*cos(x[,1]*2)
y <- yn + 3*rnorm(500)
censored <- (rnorm(500) + 2*x[,2]) < 0 #censored according to x[,2]
ycensored <- replace(y, censored, 0)
par(mfrow = c(3,3))
# True model
plot(gam(y ~ s(x[,1]) + s(x[,2]) + s(x[, 3])), ylim=c(-5, 5), main = "True")
# Naive estimation
plot(gam(ycensored ~ s(x[,1]) + s(x[,2]) + s(x[, 3])), ylim=c(-5, 5), main = "Naive")
# Tobit II estimation
m <- gam(c(ycensored ~ s(x[,1]) + s(x[,2]) + s(x[, 3]), ~x[,1]+x[,2]+x[,3], ~1,~1),
family = tobit2(censoring = censored))
plot(m, ylim = c(-5, 5), main = "Tobit II")
#fitting with non-estimated rho
m2 <- gam(c(ycensored ~ s(x[,1]) + s(x[,2]) + s(x[, 3]), ~x[,1]+x[,2]+x[,3],~1),
family = tobit2(censoring = censored, rho=0))
## End(Not run)
|
Loading required package: mgcv
Loading required package: nlme
This is mgcv 1.8-25. For overview type 'help("mgcv-package")'.
Family: tobitlss
Link function: identity identity log logit2
Formula:
ycensored ~ s(x[, 1]) + s(x[, 2])
~x[, 1] + x[, 2]
~1
~1
Parametric coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.38743 0.56269 6.020 1.74e-09 ***
(Intercept).1 0.78975 0.14062 5.616 1.95e-08 ***
x[, 1].1 -0.07865 0.06522 -1.206 0.228
x[, 2].1 1.76381 0.21250 8.300 < 2e-16 ***
(Intercept).2 -0.02835 0.04549 -0.623 0.533
(Intercept).3 -0.09170 0.80694 -0.114 0.910
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Approximate significance of smooth terms:
edf Ref.df Chi.sq p-value
s(x[, 1]) 7.99 8.720 5622.7 <2e-16 ***
s(x[, 2]) 4.19 4.978 323.4 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Deviance explained = 98.6%
-REML = 231.45 Scale est. = 1 n = 200
[,1] [,2] [,3] [,4]
[1,] 1.98380556 2.33250098 0.9720454 -0.0458183
[2,] 4.44064534 6.71856959 0.9720454 -0.0458183
[3,] 5.85182751 6.51806966 0.9720454 -0.0458183
[4,] 9.83991988 -0.62848902 0.9720454 -0.0458183
[5,] -4.86828897 -7.32352074 0.9720454 -0.0458183
[6,] 7.89231383 9.72960531 0.9720454 -0.0458183
[7,] 1.96641937 3.06623926 0.9720454 -0.0458183
[8,] 2.64404923 2.58321680 0.9720454 -0.0458183
[9,] 1.45090314 0.65191763 0.9720454 -0.0458183
[10,] 1.28668480 2.63725490 0.9720454 -0.0458183
[11,] 9.09180902 -0.02789372 0.9720454 -0.0458183
[12,] 1.51799098 2.21248342 0.9720454 -0.0458183
[13,] 0.58528032 -0.52445184 0.9720454 -0.0458183
[14,] 13.89125635 -3.69546983 0.9720454 -0.0458183
[15,] 6.26523674 4.09752821 0.9720454 -0.0458183
[16,] 3.71833336 6.15790236 0.9720454 -0.0458183
[17,] -0.14910604 -0.29682171 0.9720454 -0.0458183
[18,] 0.17972787 -3.77983607 0.9720454 -0.0458183
[19,] 3.18209967 2.92616411 0.9720454 -0.0458183
[20,] 1.44624377 0.53861909 0.9720454 -0.0458183
[21,] -1.25755455 -5.46893208 0.9720454 -0.0458183
[22,] 2.28851973 0.67424870 0.9720454 -0.0458183
[23,] -0.92931998 -1.44543745 0.9720454 -0.0458183
[24,] 14.22413206 -0.10014955 0.9720454 -0.0458183
[25,] -1.26198067 -3.38768993 0.9720454 -0.0458183
[26,] 4.58825913 7.15937987 0.9720454 -0.0458183
[27,] -0.17788971 -0.35385167 0.9720454 -0.0458183
[28,] 4.88985313 -4.64255460 0.9720454 -0.0458183
[29,] 1.37451179 1.56058347 0.9720454 -0.0458183
[30,] 1.44411667 1.65239659 0.9720454 -0.0458183
[31,] 5.02461214 -2.90157904 0.9720454 -0.0458183
[32,] -6.84809354 -9.38509657 0.9720454 -0.0458183
[33,] -0.50080558 -1.53060228 0.9720454 -0.0458183
[34,] 1.12989388 2.81074862 0.9720454 -0.0458183
[35,] 7.62978542 0.79566912 0.9720454 -0.0458183
[36,] 0.76303565 0.50868876 0.9720454 -0.0458183
[37,] 1.50004654 2.83013207 0.9720454 -0.0458183
[38,] -2.42153311 -3.38629496 0.9720454 -0.0458183
[39,] 6.35594082 4.48574027 0.9720454 -0.0458183
[40,] 2.17968017 0.65085892 0.9720454 -0.0458183
[41,] 1.34529270 3.31075280 0.9720454 -0.0458183
[42,] 2.19524952 4.47754221 0.9720454 -0.0458183
[43,] 2.19606463 1.46847929 0.9720454 -0.0458183
[44,] -0.73342029 -2.39755369 0.9720454 -0.0458183
[45,] 3.69002233 5.00058367 0.9720454 -0.0458183
[46,] -3.25111679 -6.15478880 0.9720454 -0.0458183
[47,] -0.29567930 -1.18940910 0.9720454 -0.0458183
[48,] 1.66528014 -0.23304121 0.9720454 -0.0458183
[49,] 0.20112099 0.22141031 0.9720454 -0.0458183
[50,] 4.35537002 4.25097026 0.9720454 -0.0458183
[51,] 1.26764027 1.20767192 0.9720454 -0.0458183
[52,] 1.93478154 2.32235014 0.9720454 -0.0458183
[53,] 0.82620821 0.49038047 0.9720454 -0.0458183
[54,] 4.28176947 0.09372399 0.9720454 -0.0458183
[55,] 9.14515829 3.01798882 0.9720454 -0.0458183
[56,] 18.41403131 4.52171083 0.9720454 -0.0458183
[57,] -5.25656011 -7.62969930 0.9720454 -0.0458183
[58,] 4.58260832 2.97439182 0.9720454 -0.0458183
[59,] 1.89340043 2.02202496 0.9720454 -0.0458183
[60,] -0.43426619 -0.68918898 0.9720454 -0.0458183
[61,] 25.02594491 3.76681075 0.9720454 -0.0458183
[62,] -0.36084048 -0.57715768 0.9720454 -0.0458183
[63,] 1.24057855 -0.32174913 0.9720454 -0.0458183
[64,] 1.61615738 3.80996293 0.9720454 -0.0458183
[65,] 5.79558012 6.97285361 0.9720454 -0.0458183
[66,] 1.06495842 1.71270708 0.9720454 -0.0458183
[67,] 12.00508085 -0.41565011 0.9720454 -0.0458183
[68,] 5.85326357 -3.63550748 0.9720454 -0.0458183
[69,] -0.07014462 -0.40211280 0.9720454 -0.0458183
[70,] 17.45920256 -2.86734188 0.9720454 -0.0458183
[71,] 0.66363378 -0.19845795 0.9720454 -0.0458183
[72,] 2.28058759 2.29263932 0.9720454 -0.0458183
[73,] -0.50579374 -2.31133889 0.9720454 -0.0458183
[74,] 8.87935321 10.28193130 0.9720454 -0.0458183
[75,] 6.43987705 1.53728632 0.9720454 -0.0458183
[76,] 2.70691755 4.73085155 0.9720454 -0.0458183
[77,] -4.79971607 -7.21568334 0.9720454 -0.0458183
[78,] 1.37171147 3.40354813 0.9720454 -0.0458183
[79,] -2.70173222 -3.86515521 0.9720454 -0.0458183
[80,] 2.61533489 4.12719569 0.9720454 -0.0458183
[81,] 1.79439777 2.28364969 0.9720454 -0.0458183
[82,] -0.38809548 -0.62659252 0.9720454 -0.0458183
[83,] 7.91386675 5.27593056 0.9720454 -0.0458183
[84,] 7.90879313 -1.44428469 0.9720454 -0.0458183
[85,] 0.14020897 -1.35185794 0.9720454 -0.0458183
[86,] -1.52654892 -2.79402144 0.9720454 -0.0458183
[87,] 2.67254816 -1.73454516 0.9720454 -0.0458183
[88,] 2.01860897 4.17185027 0.9720454 -0.0458183
[89,] 1.49087667 2.26148717 0.9720454 -0.0458183
[90,] 2.27723184 4.29355914 0.9720454 -0.0458183
[91,] 0.37338009 -0.50110585 0.9720454 -0.0458183
[92,] 6.15812548 1.92745612 0.9720454 -0.0458183
[93,] 5.54910601 1.46855161 0.9720454 -0.0458183
[94,] -1.67311970 -4.35168044 0.9720454 -0.0458183
[95,] 14.45248742 6.81378012 0.9720454 -0.0458183
[96,] 1.62933329 1.17618670 0.9720454 -0.0458183
[97,] 7.36156899 3.69129018 0.9720454 -0.0458183
[98,] 2.65909119 4.24928025 0.9720454 -0.0458183
[99,] 5.77436474 0.80399505 0.9720454 -0.0458183
[100,] 0.41004775 -0.21458786 0.9720454 -0.0458183
[101,] 2.64826152 4.03987081 0.9720454 -0.0458183
[102,] -2.02532373 -2.91134348 0.9720454 -0.0458183
[103,] 7.40221104 7.88716081 0.9720454 -0.0458183
[104,] -0.19966181 -0.58841369 0.9720454 -0.0458183
[105,] 5.24365166 6.72790808 0.9720454 -0.0458183
[106,] 16.28391316 5.84628530 0.9720454 -0.0458183
[107,] 2.10724518 0.96969127 0.9720454 -0.0458183
[108,] 3.65999469 2.64752915 0.9720454 -0.0458183
[109,] -1.49356934 -2.88489571 0.9720454 -0.0458183
[110,] 12.23147561 1.66460455 0.9720454 -0.0458183
[111,] 3.11240120 4.57121534 0.9720454 -0.0458183
[112,] 1.21340057 1.21187503 0.9720454 -0.0458183
[113,] 7.31851179 -1.03755634 0.9720454 -0.0458183
[114,] 0.02148548 -1.42124957 0.9720454 -0.0458183
[115,] 0.54306776 0.69564966 0.9720454 -0.0458183
[116,] 2.54381865 4.62313207 0.9720454 -0.0458183
[117,] -0.36974375 -0.86719662 0.9720454 -0.0458183
[118,] 0.46359143 0.40677548 0.9720454 -0.0458183
[119,] -1.96652950 -3.85321472 0.9720454 -0.0458183
[120,] 1.11021920 2.56139172 0.9720454 -0.0458183
[121,] 3.61713051 5.48311376 0.9720454 -0.0458183
[122,] 10.37704955 5.85949578 0.9720454 -0.0458183
[123,] 1.58623211 3.69746455 0.9720454 -0.0458183
[124,] -4.15329560 -5.77791116 0.9720454 -0.0458183
[125,] 1.05468281 2.50592741 0.9720454 -0.0458183
[126,] 2.45652004 2.28672854 0.9720454 -0.0458183
[127,] -0.26879888 -0.44533980 0.9720454 -0.0458183
[128,] 0.77636513 1.39709287 0.9720454 -0.0458183
[129,] -0.39948550 -2.15102060 0.9720454 -0.0458183
[130,] 1.50860884 3.23682430 0.9720454 -0.0458183
[131,] -0.15422990 -0.37359966 0.9720454 -0.0458183
[132,] -2.55155206 -4.65274728 0.9720454 -0.0458183
[133,] 0.52149089 -0.59007505 0.9720454 -0.0458183
[134,] 12.19322112 5.84178923 0.9720454 -0.0458183
[135,] 0.14828276 -0.43768528 0.9720454 -0.0458183
[136,] 10.58837115 3.61628477 0.9720454 -0.0458183
[137,] 2.01711179 4.17628681 0.9720454 -0.0458183
[138,] 1.23415976 0.88836181 0.9720454 -0.0458183
[139,] 0.81447125 -0.35053953 0.9720454 -0.0458183
[140,] -0.72777367 -1.06986409 0.9720454 -0.0458183
[141,] 15.01739600 3.69985255 0.9720454 -0.0458183
[142,] 2.76086062 -3.14678865 0.9720454 -0.0458183
[143,] 11.67894922 1.92017463 0.9720454 -0.0458183
[144,] 0.42746841 -0.15858352 0.9720454 -0.0458183
[145,] -1.07847451 -7.02439449 0.9720454 -0.0458183
[146,] -1.52593046 -4.06204132 0.9720454 -0.0458183
[147,] 19.51597709 3.69282735 0.9720454 -0.0458183
[148,] 0.15255210 0.11225554 0.9720454 -0.0458183
[149,] 7.55206258 3.82575282 0.9720454 -0.0458183
[150,] 15.34121791 7.70609689 0.9720454 -0.0458183
[151,] 4.20063217 5.91823415 0.9720454 -0.0458183
[152,] 1.26521699 3.18181664 0.9720454 -0.0458183
[153,] 1.20335362 2.18014460 0.9720454 -0.0458183
[154,] 2.64426831 0.25581178 0.9720454 -0.0458183
[155,] 12.53377920 6.58991842 0.9720454 -0.0458183
[156,] 4.89857206 3.06215677 0.9720454 -0.0458183
[157,] 0.82763080 -3.50747811 0.9720454 -0.0458183
[158,] 1.19034298 0.33842305 0.9720454 -0.0458183
[159,] 2.97312347 -5.76167637 0.9720454 -0.0458183
[160,] 14.31334734 -0.19307026 0.9720454 -0.0458183
[161,] -5.48819670 -8.42186105 0.9720454 -0.0458183
[162,] 3.11593114 5.46258904 0.9720454 -0.0458183
[163,] 2.71526893 -1.61869295 0.9720454 -0.0458183
[164,] 1.90414570 -0.86647709 0.9720454 -0.0458183
[165,] 1.15264116 0.28986173 0.9720454 -0.0458183
[166,] 20.99411106 2.60242468 0.9720454 -0.0458183
[167,] 1.39949297 3.22279128 0.9720454 -0.0458183
[168,] 8.94559439 3.01733021 0.9720454 -0.0458183
[169,] -0.81226311 -1.20724897 0.9720454 -0.0458183
[170,] -2.67080224 -4.05206665 0.9720454 -0.0458183
[171,] 21.21860404 -0.94453728 0.9720454 -0.0458183
[172,] 0.97297947 1.75348503 0.9720454 -0.0458183
[173,] -0.83058245 -2.18564824 0.9720454 -0.0458183
[174,] 0.40015453 0.55904200 0.9720454 -0.0458183
[175,] -2.10905787 -3.27678287 0.9720454 -0.0458183
[176,] 0.51508710 0.76590227 0.9720454 -0.0458183
[177,] 2.50940348 1.12041562 0.9720454 -0.0458183
[178,] 17.81985156 -0.05125977 0.9720454 -0.0458183
[179,] 3.64066839 0.04993612 0.9720454 -0.0458183
[180,] 9.67156119 6.82090017 0.9720454 -0.0458183
[181,] 6.81522839 3.67354290 0.9720454 -0.0458183
[182,] 5.38678990 4.55570031 0.9720454 -0.0458183
[183,] -1.50918187 -2.50156458 0.9720454 -0.0458183
[184,] 9.13282619 1.60027192 0.9720454 -0.0458183
[185,] 3.24647847 4.78158393 0.9720454 -0.0458183
[186,] 0.45990577 0.61533576 0.9720454 -0.0458183
[187,] 3.39402937 -6.95219100 0.9720454 -0.0458183
[188,] 2.48984558 2.12673389 0.9720454 -0.0458183
[189,] -3.84008944 -5.86253998 0.9720454 -0.0458183
[190,] 1.03813343 -1.92608052 0.9720454 -0.0458183
[191,] 3.08580460 5.48819267 0.9720454 -0.0458183
[192,] 1.72168746 2.89825151 0.9720454 -0.0458183
[193,] 3.63167688 4.75584219 0.9720454 -0.0458183
[194,] 2.93161689 1.74072664 0.9720454 -0.0458183
[195,] 5.46240539 0.59117337 0.9720454 -0.0458183
[196,] 1.74185416 -2.30603491 0.9720454 -0.0458183
[197,] 11.92345098 6.18226522 0.9720454 -0.0458183
[198,] 3.80237090 1.10831509 0.9720454 -0.0458183
[199,] -0.64616253 -1.79775015 0.9720454 -0.0458183
[200,] 1.96098322 3.90186964 0.9720454 -0.0458183
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.