GMACRO

CASE16_1.MAC

 

#Assign values to k1

#and k2 before running

#k101 counts non-convergences

 

let k101=0

let c5=exp(k1+k2*c1)

let c6=c5/(1+c5)

 

let k3=0  # counter for while loop

 

let k11 = 0  

# updating mean intercept

let k12 = 0    # used in updating

# standard deviation of intercept

let k14 = 0   # updating mean slope

let k15 = 0  

# used in updating standard

# deviation of slope

 

#####

## use a WHILE loop to  ensure that the

# number of runs rises to 1000 even

# if some runs are rejected

# because of  non-convergence

 

while k3 lt 1000

 

## random number generation for survive

do k9=1:6

let k22=c2(k9)

let k66=c6(k9)

random 1 c100;

binomial k22 k66.

let c3(k9)=c100

erase c100

enddo

 

#####

## binary logistic regression with default

#   of 20 iterations

## store coefficients in column 7

## Brief 0 suppresses output of results

 

BLogistic C3 C2 = C1;

ST;

Logit;

Coefficients c7;

Brief 0.

 

 

 

## run the 21st iteration

## store coefficients in column 8

 

BLogistic C3 C2 = C1;

ST;

Logit;

Coefficients c8;

Brief 0;

Iteration 21.

 

## k4 = difference between intercepts

#   iterations 20 and 21

 

let k4 = abso(c7(1) - c8(1))

 

## if the difference is small, accept the

#  result and add intercept and slope

#  values  to the running mean and

#  variance calculations

 

if k4 <0.05 #something small

let k3 = k3 + 1

else k101=k101+1

endif

 

 

## calculate running mean and variance

## intercept

let k13 = c7(1) - k11

let k11 = ((k3 - 1)* k11 + c7(1))/k3

let k12 = k12  +k13*k13*(k3-1)/k3

 

## slope

let k16 = c7(2) - k14

let k14 = ((k3 - 1)* k14 + c7(2))/k3

let k15 = k15  +k16*k16*(k3-1)/k3

 

endif

 

endwhile

 

let c11(1) = k11  ## mean of intercept

let c12(1) = sqrt(k12/(k3-1)) 

## SD of intercept

let c13(1) = k14  ## mean of slope

let c14(1) = sqrt(k15/(k3-1)) 

## SD of slope

 

name c11 'intMean'

name c12 'intSD'

name c13 'slopeMean'

name c14 'slopeSD'

 

print ‘number non-convergences in 1000’

print k101

 

ENDMACRO