2

我有一个逻辑回归,我想从 logit 曲线生成模拟数据。我的代码如下:

    #Begin Code        
    require(gld)

    runs<-100
    num.trees<-500
    p<-0.5

    trial.1<-rgl(num.trees,1859.75592, 0.02179, -0.09578, 0.24264, param = "fkml", lambda5 =    NULL)
    trial.1 <- floor(trial.1/10)*10+1

    minDecade <- min(trial.1)
    maxDecade <- max(trial.1)
    allDecades <- seq(minDecade-100, 2001, by=10) 

    x<-1:length(allDecades)
    y<-sample(trial.1, p*num.trees)


binTrees <- rep(0,length(allDecades))

for (i in 1:length(allDecades)) {

        binTrees[i] <- length(which(y==allDecades[i]))
    }
        binTrees


    binTrees<-cumsum(binTrees)/sum(binTrees)

    fit<-glm(binTrees~x,family=binomial(link='logit'))

    plot(binTrees)
    lines(fitted.values(fit))

    #End Code

基本上,从最后一点开始,如何从我的逻辑回归中生成模拟数据?与我交谈过的人建议使用 CDF 函数来执行此操作,但我不知道从哪里开始。我的目标是根据我的拟合曲线重新创建一个完整的数据集。

提前感谢您的任何建议!

4

1 回答 1

0

You would generally be drawing from a binomial distribution if you were doing a simulation experiment using logistic regression:

> set.seed(123)
> df1 <- data.frame(event=rbinom(n=20, size=1, prob=.4) )
> glm(event ~ . , df1, family="binomial")

Call:  glm(formula = event ~ ., family = "binomial", data = df1)

Coefficients:
(Intercept)  
    -0.4055  

Degrees of Freedom: 19 Total (i.e. Null);  19 Residual
Null Deviance:      26.92 
Residual Deviance: 26.92    AIC: 28.92 
> exp(-0.4055)/(1+exp(-0.4055))
[1] 0.3999916
> sum(df1$event)/length(df1$event)
[1] 0.4  # that degree of agreement with the simulated parameter is accidental.

The connection between your rgl functional result (based on an unnamed package) and the rest of the code seems obscure, so it would be better if you described in natural natural language what you are hoping to simulate.

于 2012-03-28T20:00:54.040 回答