[R] Tobit Modelling

Cristian Montes cmontes at arauco.cl
Fri Aug 6 15:22:40 CEST 2010


Hi Patrick

Here is some code that might help you implement your tobit regression, if you don´t mind
using maximum likelihood.

#first declare a likelihood function with a censored model
#assume your x2 is censored for values below -1, and using a simple
#linear model in this case.  Our censoring threshold will be z.


YOURX1 = c(1,2,3,4,6,7,8,9,10,11)
YOURX2 = c(-1,-1,-1,-1,2.2,3.1,6.4,7, 7.2,8)

loglik <- function(param, x1, x2, z)
		{
		b0    <- param[1]
		b1    <- param[2]
		sigma <- param[3]

		result <-  ifelse(x2 >z, dnorm(x2, b0 + b1 * x1, sigma, log = T),
                      pnorm((z-b0+b1*x1)/sigma, log = T))
		return(sum(result))
		}


regression <- optim( par    = c(-3,1,1),
			   fn      = loglik,
			   method  = "L-BFGS-B",
			   lower   = c(-Inf, -Inf, 1e-10),  #bound solution for b0 and b1 to be any, but sigma >0
			   x1      = YOURX1,
			   x2      = YOURX2,
			   z       = -1,
                    control = list(fnscale = -1))  #maximize likelihood 
			   
			   
plot(YOURX2 ~ YOURX1)
abline(a=regression$par[1], b= regression$par[2])
abline(lm (YOURX2~YOURX1), lty= 2)


The key here is that you are analyzing the likelihood for your x2 with different probabilities.
The code above was implemented for nonlinear regression, so you can put any model you want with
minor changes and it will work identically.  

Cheers,

Cristian.

-------------------------------------
Cristian Montes
Site Productivity Division Head
Bioforest S.A.

-----Mensaje original-----
De: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] En nombre de Patrick Sessford
Enviado el: Jueves, 05 de Agosto de 2010 08:42 p.m.
Para: r-help at r-project.org
Asunto: [R] Tobit Modelling



Dear R-users,

I would like to model data where the response variable consists of many minus ones and many different positive values that seem to follow an apparently separate distribution (ie. -1, -1, 0.5, -1, 3, 3.5, 1.2, -1, -1, 0.4, etc); no values of the response can be less than minus one or between minus and zero (exclusive).

I am aware of tobit regression but unaware of exactly how to implement it in R. If anyone is able to help me on this issue I'd be extremely grateful; for example, if my (continuous) explanatory variables were x1 and x2, how should I define the model?

Thank you for your time.

Pat

 		 	   		  
	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list