Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Weibull simulation-parametrization


From   Antoine Terracol <[email protected]>
To   [email protected]
Subject   Re: st: Weibull simulation-parametrization
Date   Tue, 06 May 2003 18:31:29 +0200

n p wrote:

I would appreciate any other ideas for a Weibull
simulation or even better a Weibull with frailties
simulation.

Thanks in advance for any comments.

Nikos Pantazis

Nikos,

the following piece of code will generate weibull random variables (my alpha stands for your gamma).
------------------------------------------
cap prog drop draweib
program define draweib
syntax newvarlist [if] [in] , LAmbda(string) ALpha(string) [double]
tokenize "`varlist'"
while "`1'"!="" {
tempname vlambda
tempvar `vlambda'
gen `vlambda' = exp(ln(`lambda')/`alpha')
g `double' `1' = ((log(1/uniform()))^(1/`alpha'))/`vlambda' `if' `in'
mac shift
}
end
------------------------------------------

You can also use it to simulate durations that depend on some independant variables as in the output below.

. clear

. set obs 1000
obs was 0, now 1000

. drawnorm x1 x2

. draweib time, lambda(exp(1+x1+x2)) alpha(0.6)

. stset time

failure event: (assumed to fail at time=time)
obs. time interval: (0, time]
exit on or before: failure

------------------------------------------------------------------------------
1000 total obs.
0 exclusions
------------------------------------------------------------------------------
1000 obs. remaining, representing
1000 failures in single record/single failure data
4534.04 total analysis time at risk, at risk from t = 0
earliest observed entry t = 0
last observed exit t = 1827.592

. streg x1 x2, dist(weib) nohr nolog

failure _d: 1 (meaning all fail)
analysis time _t: time

Weibull regression -- log relative-hazard form

No. of subjects = 1000 Number of obs = 1000
No. of failures = 1000
Time at risk = 4534.03956
LR chi2(2) = 1069.97
Log likelihood = -2084.7593 Prob > chi2 = 0.0000

------------------------------------------------------------------------------
_t | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
x1 | 1.030093 .041635 24.74 0.000 .9484899 1.111696
x2 | 1.012599 .0394268 25.68 0.000 .9353235 1.089874
_cons | 1.079722 .0357241 30.22 0.000 1.009704 1.14974
-------------+----------------------------------------------------------------
/ln_p | -.4970151 .0248969 -19.96 0.000 -.5458122 -.448218
-------------+----------------------------------------------------------------
p | .6083438 .0151459 .579371 .6387654
1/p | 1.643807 .0409258 1.56552 1.72601
------------------------------------------------------------------------------



Hope this helps,
Antoine.



--
Ce message a subi une analyse antivirus par MailScanner ; il est vraisemblablement
sans danger.

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index