怎么利用r语言做em算法估计混合双参数指数分布的数值模拟

Python014

怎么利用r语言做em算法估计混合双参数指数分布的数值模拟,第1张

建议你先看一下这本书:

Modeling Survival Data Using Frailty Models

chap 2. Some Parametric Methods

2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 19

2.2 Exponential Distribution . . . . . . . . . . . . . . . . . . . 20

2.3 Weibull Distribution . . . . . . . . . . . . . . . . . . . . . 21

2.4 Extreme Value Distributions . . . . . . . . . . . . . . . . 23

2.5 Lognormal . . . . . . . . . . . . . . . . . . . . . . . . . . 25

2.6 Gamma . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

2.7 Loglogistic . . . . . . . . . . . . . . . . . . . . . . . . . 29

2.8 Maximum Likelihood Estimation . . . . . . . . . . . . . 30

2.9 Parametric Regression Models

chap 6. Estimation Methods for Shared Frailty Models

6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . .105

6.2 Inference for the Shared Frailty Model . . . . . . . . . . 106

6.3 The EM Algorithm . . . . . . . . . . . . . . . . . . . . . . .108

6.4 The Gamma Frailty Model . . . . . . . . . . . . . . . . . . . 110

6.5 The Positive Stable Frailty Model . . . . . . . . . . . . . . 111

6.6 The Lognormal Frailty Model . . . . . . . . . . . . . . . . . 113

6.6.1 Application to Seizure Data . . . . . . . . . . . . . . . 113

6.7 Modified EM (MEM) Algorithm for Gamma Frailty Models 114

6.8 Application

然后用最基本的package "survival"

并参考你的模型可能用到的一些functions:

survreg(formula, data, weights, subset,na.action, dist="weibull",....)

survreg.distributions include "weibull", "exponential", "gaussian",

"logistic","lognormal" and "loglogistic"

frailty(x, distribution="gamma", ...)

distribution: either the gamma, gaussian or t distribution may be specified.

frailty.gamma(x, sparse = (nclass >5), theta, df, eps = 1e-05,

method = c("em","aic", "df", "fixed"),...)

这个直接读到R中就可以取log了,

dat <- read.xls("filename")# 最好使用CSV

dat <- dat # 去掉行名

dat <- dat# 去掉列名

ndat <- log(dat)

write.xls("filename")

大体就这样 ,可能读进来 需要调整

根据传入参数,返回维度为 (d0, d1, ..., dn) 的 ndarray 的伪随机数,值的范围为标准正态分布

Example code:

根据参数调整正态分布的均值,宽度,以及返回的是几维的 ndarray

只设置 size , loc 和 scale 为默认,则数值范围为标准正态分布,与 randn 类似。 size 传入整数N,则生成长度N的一维 ndarray ,传入元组,则根据元组创建相应维度的 ndarray

Example code:

Draw samples from a log-normal distribution with specified mean, standard deviation, and array shape. Note that the mean and standard deviation are not the values for the distribution itself, but of the underlying normal distribution it is derived from.

lognormal 对数正态分布

与 normal 类似,但一个为正态分布,一个为对数正态分布。