Does R code for logit generate values ​​greater than 1?

The logical transformation is supposed to generate the values ​​in (0,1). But if you look at the following logical transformation, you will see that it creates values ​​greater than 1. Where am I mistaken?

lambda1=0
out=matrix(NA,400,1)
for (i in 1:400){
  lambda1[i+1]=((exp(0.8*lambda1[i]+rnorm(1)))/(1+exp(0.8*lambda1[i]+rnorm(1))))
  out[i]=lambda1[i]
}
+4
source share
2 answers

Each time you call rnorm(1), you get a different random draw, so the random value in the numerator and denominator may differ.

Note that this is exp(x) / (1+exp(x))equivalent 1 / (1 + exp(-x)), so you can:

lambda1=0
out=matrix(NA,400,1)
for (i in 1:400){
  lambda1[i+1]=(1/(1+exp(-(0.8*lambda1[i]+rnorm(1)))))
  out[i]=lambda1[i]
}
summary(lambda1)
#    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#  0.0000  0.4523  0.6352  0.6119  0.7719  0.9682 

: , , lambda1 out (, , 2 401 out 1 400):

lambda1 <- rep(0, 401)
for (i in 1:400) lambda1[i+1]=(1/(1+exp(-(0.8*lambda1[i]+rnorm(1)))))
out <- matrix(tail(lambda1, -1))
+3

, . , [0,1], , rnorm(), .

( , () , ),

lambda1[i+1]=((exp(0.8*lambda1[i]+rnorm(1)))/(1+exp(0.8*lambda1[i]+rnorm(1))))

r = exp(0.8*lambda1[i] + rnorm(1))
lambda1[i+1] = r/(1+r)
+1

All Articles