Computed theoretical power for N=100 and N=200 scenarios

This commit is contained in:
2024-02-19 18:35:26 +01:00
parent ac9189d26a
commit 238852b08b
704 changed files with 261610 additions and 187 deletions

View File

@ -0,0 +1,16 @@
*! version 1.0.0 TJS 9jun2000
program define nct
version 6.0
di _n in bl "nct is not an executable program."
di _n in bl "Available non-central t programs are:"
di _n in wh " nctprob t' delta df" in bl " /* yields p"
di _n in wh " nctinv p delta df" in bl " /* yields t'"
di _n in wh " nctncp t' p df" in bl " /* yields delta"
di _n in wh " nctn t' delta p" in bl " /* yields v2"
di _n in wh " nct2 t' delta df" in bl " /* yields two-sided p"
di _n in wh " nct2inv p delta df" in bl " /* yields two-sided t'"
di
exit 119
end

124
Modules/ado/plus/n/nct.hlp Normal file
View File

@ -0,0 +1,124 @@
.-
help for ^nct^
.-
Non-central t programs
----------------------
^nctprob^ t' delta df /* yields p
^nctinv^ p delta df /* yields t'
^nctncp^ t' p df /* yields delta
^nctn^ t' delta p /* yields df + 1
^nct2^ t' delta df /* yields two-sided p
^nct2inv^ p delta df /* yields two-sided t'
where
^t'^ is the observed t-value
^delta^ is the noncentrality parameter
^df^ is the degrees of freedom (^df^ is a positive integer)
^p^ is the probability (0 < ^p^ < 1)
For each program, entering the program name with no parameters displays
the command syntax.
Description
-----------
Let Y and Z be independent random variables, where
Z ~ N(delta,1) (Z is distributed Normal with mean delta and variance 1)
Y ~ ChiSq(n) (Y is distributed chi-square with degrees of freedom n).
Then, X = Z / sqrt(Y/n) is said to have a noncentral t distribution with
noncentrality delta and degrees of freedom n.
That is, X ~ t(delta, n).
^nct^xxxx is a family of immediate programs, all related to the noncentral t
distribution. Each one-sided program computes a missing parameter, given
the other parameters, such that P(t<=^t'^| ^delta^, ^df^) = ^p^.
for | use
------+--------------------------------------------------------
^p^ | ^nctprob^ -- Cumulative non-central t probabilities
^t'^ | ^nctinv^ -- Inverse cumulative non-central t values
^delta^ | ^nctncp^ -- Noncentrality parameter of the non-central t
^df^ | ^nctn^ -- Sample size for the cumulative non-central t
There are also two programs that yield two-sided values from a noncentral t,
defined such that P(|t|<=^t'^| ^delta^, ^df^) = 1 - ^p^.
for | use
------+--------------------------------------------------------
^p^ | ^nct2^ -- 2-sided non-central t probabilities
^t'^ | ^nct2inv^ -- Inverse 2-sided non-central t values
The core program, ^nctprob^, computes probabilities from the cumulative
non-central t distribution from negative infinity to ^t'^ for noncentrality
parameter, ^delta^, and positive, integer degrees of freedom, ^df^.
That is, ^nctprob^ computes ^p^ such that P(t<=^t'^| ^delta^, ^df^) = ^p^.
Each program prints its computed value and returns it in global ^S_1^ and in
a result ^r()^. The value computed and the name of the returned parameter
for each program are:
^nctprob^ -- ^r(p)^ -- the probability p
^nctinv^ -- ^r(t)^ -- the critical t'
^nctncp^ -- ^r(delta)^ -- the noncentrality parameter delta
^nctn^ -- ^r(n)^ -- the minimum n
^nct2^ -- ^r(p)^ -- the two-sided tail probability
^nct2inv^ -- ^r(t)^ -- the two-sided critical t'
^nctn^ computes the minimum ^n^ such that, for ^df^ = ^n^ - 1,
when ^p^ < 0.5, P(t<=^t'^|^delta^, ^df^) <= ^p^, and
when ^p^ > 0.5, 1 - P(t<=^t'^|^delta^, ^df^) <= ^p^.
Warning: Convergence time for ^nctn^ is a function of the computed minimum
^n^ and increases greatly when that ^n^ gets large. Because the limit of
the noncentral t (as n gets large) is the noncentral z, a comparison
of the desired probability ^p^ to P(z < ^t'^ - ^delta^) is informative.
If these values are within .005 of each other, convergence time will
be noticably non-negligible.
Notes
-----
These programs call ^integ^. The user is cautioned that the initial
Stata 6.0 release of ^integ^ (version 3.0.4) has a bug. Please install
version 3.0.5 or later.
Some of these programs require installation of programs ^ridder^
(see STB-24, insert ssi5.4 for ^ridder^).
Author
------
Thomas J. Steichen <steicht@@rjrt.com>
Examples
--------
. ^nctprob 3.6 3.0 11^ > gives p for t' = 3.6, delta = 3.0, df = 11
. ^nctinv .95 2.0 17^ > gives t' for p = .95, delta = 2.0, df = 17
. ^nctncp 4.045 .95 17^ > gives delta for t' = 4.045, p = .95, df = 17
. ^nctinv 4 2 .95^ > gives n for t' = 4, delta = 2, p = .95
. ^nct2 3.1 2.0 17^ > gives p for |t'| = 3.1, delta = 2.0, df = 17
. ^nct2inv .05 2.0 17^ > gives |t'| for p = .05, delta = 2.0, df = 17
. ^nctprob^ > displays the command syntax

View File

@ -0,0 +1,62 @@
*! version 1.0.0 TJS 9jun2000
program define nct2, rclass
version 6.0
args t delta df
tempname p1 p2 ps
if "`df'" == "" {
di in gr "Syntax for " in wh "nct2" in gr " is: " _n
di in wh " nct2 " in gr "t' delta df" _n
di in gr " where " in wh "t' " in gr "is the observed t"
di in wh " delta " in gr "is the noncentrality parameter"
di in wh " df " in gr "is the degrees of freedom" _n
di in wh " nct2 " in gr "computes " in wh "p" _c
di in gr " such that P(|t|<=" in wh "t'" in gr "| " in wh "delta" _c
di in gr ", " in wh "df" in gr ") = 1 - " in wh "p"
di in gr " and returns the value in result " _c
di in wh "r(p) " in gr "and global " in wh "S_1" in gr "."
global S_1 = .
return scalar p = .
exit 9
}
capture which nctprob
if _rc == 111 {
di in re "nct2 requires installation of program nctprob."
di in wh " (contact T. J. Steichen at steicht@rjrt.com for nctprob)."
global S_1 = .
return scalar p = .
exit 111
}
qui nctprob `t' `delta' `df'
if _rc == 198 {
di in re "nct2 requires version 3.0.5 or later of integ."
di in wh " (use " in ye "which integ " _c
di in wh "to check version number)."
global S_1 = .
return scalar p = .
exit 198
}
scalar `p2' = 1 - $S_1
local t = -`t'
qui nctprob `t' `delta' `df'
scalar `p1' = $S_1
scalar `ps' = `p2' + `p1'
global S_1 = `ps'
return scalar p = `ps'
local t = -`t'
di _n in gr " P( t <= " -`t' " | delta = " _c
di in gr `2' ", df = " `3' ") = " in ye `p1'
di in gr " P( t >= " `t' " | delta = " _c
di in gr `2' ", df = " `3' ") = " in ye `p2'
di in gr " P(|t| <= " `t' " | delta = " _c
di in gr `2' ", df = " `3' ") = " in ye `ps'
end

View File

@ -0,0 +1 @@
.h nct

View File

@ -0,0 +1,103 @@
*! version 1.0.0 TJS 9jun2000
program define nct2inv, rclass
version 6.0
args p delta df
di
if "`p'" == "" {
di in gr "Syntax for " in wh "nct2inv " in gr "is: " _n
di in wh " nct2inv " in gr "p delta df" _n
di in gr " where " in wh "p " _c
di in gr "is the desired total probability in the tails"
di in wh " delta " in gr "is the noncentrality parameter"
di in wh " df " in gr "is the degrees of freedom" _n
di in wh " nct2inv " in gr "computes " in wh "t'" _c
di in gr " such that P(|t| <= " in wh "t'" in gr " | " in wh "delta" _c
di in gr ", " in wh "df" in gr ") = 1 - " in wh "p"
di in gr " and returns the value in result " _c
di in wh "r(t) " in gr "and global " in wh "S_1" in gr "."
global S_1 = .
return scalar t = .
exit 9
}
if `p' < 0 | `p' > .5 {
di in re "p must be between 0 and .5"
global S_1 = .
return scalar t = .
exit 498
}
if `df' != int(`df') | `df' < 1 {
di in re "degrees of freedom must be a positive integer"
global S_1 = .
return scalar t = .
exit 498
}
capture which nct2
if _rc == 111 {
di in re "nct2inv requires installation of helper program nct2."
di in wh " (nct2 is included with the distribution files " _c
di in wh "for nct2inv"
di in wh " or can be obtained by contacting T. J. Steichen " _c
di in wh "at steicht@rjrt.com)."
global S_1 = .
return scalar t = .
exit 111
}
capture which ridder
if _rc == 111 {
di in re "nct2inv requires installation of program ridder."
di in wh " (see STB-24, insert ssi5.4 for ridder)."
global S_1 = .
return scalar t = .
exit 111
}
capture which nctprob
if _rc == 111 {
di in re "nct2inv requires installation of program nctprob."
di in wh " (contact T. J. Steichen at steicht@rjrt.com for nctprob)."
global S_1 = .
return scalar t = .
exit 111
}
local min = `delta'
local max = `delta' + 100 / sqrt(`df')
cap ridder nct2 X `delta' `df' returns macro S_1 = `p' /*
*/ from `min' to `max'
if _rc == 430 {
local min = $S_1 - 1
local max = $S_1 + 1
qui ridder nct2 X `delta' `df' returns macro S_1 = `p' /*
*/from `min' to `max'
}
if _rc == 409 {
di in re "internal error in guessing range: solution not bounded."
di in wh " (please report this error to T. J. Steichen at "
di in wh " steicht@rjrt.com, along with command attempted)."
global S_1 = .
return scalar t = .
exit 409
}
if _rc == 198 {
di in re "nct2inv requires version 3.0.5 or later of integ."
di in wh " (use " in ye "which integ " _c
di in wh "to check version number)."
global S_1 = .
return scalar t = .
exit 198
}
global S_1 = abs($S_1)
return scalar t = $S_1
di _n in gr " |t'| =" in ye %10.6f $S_1
di _n in gr " P(|t| <= " in ye $S_1 in gr " | delta = " _c
di in gr `delta' ", df = " `df' ") = 1 - " `p'
end

View File

@ -0,0 +1 @@
.h nct

View File

@ -0,0 +1,94 @@
*! version 1.0.1 TJS 9jun2000
program define nctinv, rclass
version 6.0
args p delta df
if "`p'" == "" {
di in gr "Syntax for " in wh "nctinv" _c
di in gr ", the inverse cumulative non-central t distribution, is:" _n
di in wh " nctinv " in gr "p delta df" _n
di in gr " where " in wh "p " in gr " is the probability"
di in wh " delta " in gr "is the noncentrality parameter"
di in wh " df " in gr " is the degrees of freedom" _n
di in wh " nctinv " in gr "computes " in wh "t'" in gr " such that" _c
di in gr " P(t<=" in wh "t'" in gr "| " in wh "delta" in gr ", " _c
di in wh "df" in gr ") = " in wh "p"
di in gr " and returns the value in result " _c
di in wh "r(t) " in gr "and global " in wh "S_1" in gr "."
global S_1 = .
return scalar t = .
exit 9
}
if `p' < 0 | `p' > 1 {
di in re "p must be between 0 and 1"
global S_1 = .
return scalar t = .
exit 498
}
if `df' != int(`df') | `df' < 1 {
di in re "degrees of freedom must be a positive integer"
global S_1 = .
return scalar t = .
exit 498
}
capture which ridder
if _rc == 111 {
di in re "nctinv requires installation of program ridder."
di in wh " (see STB-24, insert ssi5.4 for ridder)."
global S_1 = .
return scalar t = .
exit 111
}
capture which nctprob
if _rc == 111 {
di in re "nctinv requires installation of program nctprob."
di in wh " (contact T. J. Steichen at steicht@rjrt.com for nctprob)."
global S_1 = .
return scalar t = .
exit 111
}
local min = `delta' - 100 / (`df'^.44)
local max = `delta' + 100 / (`df'^.44)
if `p' < 0.5 { local max = `delta' }
else { local min = `delta' }
cap ridder nctprob X `delta' `df' returns macro S_1 = `p' /*
*/ from `min' to `max'
if _rc == 430 {
local min = $S_1 - 1
local max = $S_1 + 1
qui ridder nctprob X `delta' `df' returns macro S_1 = `p' /*
*/ from `min' to `max'
}
if _rc == 409 {
di in re "internal error in guessing range: solution not bounded."
di in wh " (please report this error to T. J. Steichen at "
di in wh " steicht@rjrt.com, along with command attempted)."
global S_1 = .
return scalar t = .
exit 409
}
if _rc == 198 {
di in re "nctinv requires version 3.0.5 or later of integ."
di in wh " (use " in ye "which integ " _c
di in wh "to check version number)."
global S_1 = .
return scalar t = .
exit 198
}
return scalar t = $S_1
di _n in gr " t' =" in ye %10.6f $S_1
di _n in gr " P(t <= " in ye $S_1 in gr " | delta = " _c
di in gr `delta' ", df = " `df' _c
di in gr ") = " `p'
end

View File

@ -0,0 +1 @@
.h nct

112
Modules/ado/plus/n/nctn.ado Normal file
View File

@ -0,0 +1,112 @@
*! version 1.0.0 TJS 9jun2000
program define nctn, rclass
version 6.0
args t delta p st
if "`st'" != "step" {local star "*"}
if lower("`st'") == "z" { local zstar " "}
else {local zstar "*"}
if "`p'" == "" {
di in gr "Syntax for " in wh "nctn" in gr " is:" _n
di in wh " nctn " in gr "t' delta p" _n
di in gr " where " in wh "t' " in gr "is the observed t"
di in wh " delta " in gr "is the noncentrality parameter"
di in wh " p " in gr "is the probability" _n
di in wh " nctn " in gr "computes the minimum " in wh "n" _c
di in gr " such that, for " in wh "df " in gr "= " in wh "n" _c
di in gr " - 1, "
di in gr " when " in wh "p" in gr " < 0.5," _c
di in gr " P(t<=" in wh "t'" in gr "|" in wh "delta" _c
di in gr ", " in wh "df" in gr ") <= " in wh "p" in gr ", and "
di in gr " when " in wh "p" in gr " > 0.5," _c
di in gr " 1 - P(t<=" in wh "t'" in gr "|" in wh "delta" _c
di in gr ", " in wh "df" in gr ") <= " in wh "p" in gr "." _n
di in gr " The minimum " in wh "n" in gr " is returned in result " _c
di in wh "r(n) " in gr "and global " in wh "S_1" in gr "."
global S_1 = .
return scalar n = .
exit 9
}
capture which nctprob
if _rc == 111 {
di in re "nctn requires installation of program nctprob."
di in wh " (contact T. J. Steichen at steicht@rjrt.com for nctprob)."
global S_1 = .
return scalar n = .
exit 111
}
local z = `t' - `delta'
qui nctprob `t' `delta' 1
local pr = r(p)
local zp = normprob(`z')
`star' di "nctprob(1):" `pr'
`star' di "z(inf):" `zp'
local mn = min(`pr', `zp')
local mx = max(`pr', `zp')
if `mn' > `p' | `mx' < `p' {
di in re "inconsistent parameters, no solution possible"
di in bl "note: permissible range for p given t' and delta is " _c
di in bl %6.4f `mn' " to " %6.4f `mx'
global S_1 = .
return scalar n = .
exit 459
}
`zstar' di in bl "note: if " in wh "p" in bl " = "_c
`zstar' di in ye %6.4f `p' in bl " approaches " _c
`zstar' di in ye %6.4f `zp' in bl " = P(z < " _c
`zstar' di in wh "t'" in bl " - " in wh "delta" in bl "),"
`zstar' di in wh "n " in bl "approaches infinity and " _c
`zstar' di in bl "convergence time increases greatly."
`zstar' global S_1 = .
`zstar' return scalar n = .
`zstar' exit 9
local sign "<"
local df = 1
local pr = 1
qui nctprob `t' `delta' 1
local pr1 = r(p)
qui nctprob `t' `delta' 2
local pr2 = r(p)
if `pr2' > `pr1' {
local sign ">"
local pr = 0
}
local step = int(abs(`zp' - `pr1') / abs(`zp' - `p'))
local df = `step'
local f 0
while `f' == 0 {
qui nctprob `t' `delta' `df'
local pr0 = `pr'
local pr = r(p)
`star' di "df: " `df' " step: " `step' " p: " `pr'
if `p' `sign' `pr' { local df = `df' + `step' }
else {
if `step' == 1 & sign((`pr'-`p')/(`pr0'-`p')) < 0 { local f 1 }
else {
local step = max(1, int(`step' / 2))
local df = `df' - `step'
}
}
}
di in gr "for n = " in ye `df' + 1 in gr ", df = " in ye `df' _c
if `pr' < `p' {
di in gr " and p = " `pr' _c
di in gr " <= " `p' "."
}
else {
di in gr " and 1 - p = " 1 - `pr' _c
di in gr " <= " 1 - `p' " = 1 - " `p' "."
}
global S_1 = `df'
return scalar n = `df'
end

View File

@ -0,0 +1,2 @@
.h nct

View File

@ -0,0 +1,92 @@
*! version 1.0.0 TJS 9jun2000
program define nctncp, rclass
version 6.0
args t p df
if "`p'" == "" {
di in gr "Syntax for " in wh "nctncp" in gr " is:" _n
di in wh " nctncp " in gr "t' p df" _n
di in gr " where " in wh "t' " in gr "is the observed t"
di in wh " p " in gr "is the probability"
di in wh " df " in gr "is the degrees of freedom" _n
di in wh " nctncp " in gr "computes " in wh "delta" _c
di in gr " such that P(t<=" in wh "t'" in gr "| " in wh "delta" _c
di in gr ", " in wh "df" in gr ") = " in wh "p"
di in gr " and returns the value in result " _c
di in wh "r(delta) " in gr "and global " in wh "S_1" in gr "."
global S_1 = .
return scalar delta = .
exit 9
}
if `p' < 0 | `p' > 1 {
di in re "p must be between 0 and 1"
global S_1 = .
return scalar delta = .
exit 498
}
if `df' != int(`df') | `df' < 1 {
di in re "degrees of freedom must be a positive integer"
global S_1 = .
return scalar delta = .
exit 498
}
capture which ridder
if _rc == 111 {
di in re "nctncp requires installation of program ridder."
di in wh " (see STB-24, insert ssi5.4 for ridder)."
global S_1 = .
return scalar delta = .
exit 111
}
capture which nctprob
if _rc == 111 {
di in re "nctncp requires installation of program nctprob."
di in wh " (contact T. J. Steichen at steicht@rjrt.com for nctprob)."
global S_1 = .
return scalar delta = .
exit 111
}
local min = `t' - 100 / (`df'^.44)
local max = `t' + 100 / (`df'^.44)
if `p' > 0.5 { local max = `t' }
else { local min = `t' }
cap ridder nctprob `t' X `df' returns macro S_1 = `p' /*
*/ from `min' to `max'
if _rc == 430 {
local min = $S_1 - 1
local max = $S_1 + 1
qui ridder nctprob `t' X `df' returns macro S_1 = `p' /*
*/ from `min' to `max'
}
if _rc == 409 {
di in re "internal error in guessing range: solution not bounded."
di in wh " (please report this error to T. J. Steichen at "
di in wh " steicht@rjrt.com, along with command attempted)."
global S_1 = .
return scalar delta = .
exit 409
}
if _rc == 198 {
di in re "nctncp requires version 3.0.5 or later of integ."
di in wh " (use " in ye "which integ " _c
di in wh "to check version number)."
global S_1 = .
return scalar delta = .
exit 198
}
return scalar delta = $S_1
di _n in gr " delta =" in ye %10.6f $S_1
di _n in gr " P(t <= " `t' " | delta = " _c
di in ye $S_1 in gr ", df = " `df' _c
di in gr ") = " `p'
end

View File

@ -0,0 +1 @@
.h nct

View File

@ -0,0 +1,198 @@
*! version 1.0.1 TJS 9jun2000
program define nctprob, rclass
version 6.0
args t delta df extra
if "`df'" == "" | "`extra'" != "" {
di in gr "Syntax for " in wh "nctprob" _c
di in gr ", the cumulative non-central t"
di in gr "distribution from negative infinity to t', is: " _n
di in wh " nctprob " in gr "t' delta df" _n
di in gr " where " in wh "t' " in gr "is the observed t"
di in wh " delta " in gr "is the noncentrality parameter"
di in wh " df " in gr "is the degrees of freedom" _n
di in wh " nctprob " in gr "computes " in wh "p" _c
di in gr " such that P(t<=" in wh "t'" in gr "| " in wh "delta" _c
di in gr ", " in wh "df" in gr ") = " in wh "p"
di in gr " and returns the value in result " _c
di in wh "r(p) " in gr "and global " in wh "S_1" in gr "."
global S_1 = .
return scalar p = .
exit 9
}
if `df' != int(`df') | `df' < 1 {
di in re "degrees of freedom must be a positive integer"
global S_1 = .
return scalar p = .
exit 498
}
local even = mod(`df',2) == 0
/* numerical calculation of C(h,a) requires -preserve-
but C(h,a) is only needed for odd df's */
if !`even' { preserve }
tempname A B h a p C M0 M1 M2 ak Mo Me k Mk
tempvar x y
scalar `A' = `t' / sqrt(`df')
scalar `B' = `df' / (`df' + (`t')^2)
scalar `h' = `delta' * sqrt(`B')
if `even' { scalar `p' = normprob(-(`delta')) }
else {
scalar `p' = normprob(-(`delta' * sqrt(`B')))
scalar `a' = abs(`A')
qui range `x' 0 `a' 1001
gen `y' = exp(-((`h')^2 / 2) * (1 + (`x')^2)) / (1 + (`x')^2)
qui integ `y' `x'
scalar `C' = r(integral)/ (2 * _pi)
scalar `p' = `p' + 2 * `C' * sign(`A')
}
if `df' == 1 {
di _n in gr " p =" in ye %10.6f `p'
di _n in gr " P(t <= " `t' " | delta = " _c
di in gr `delta' ", df = " `df' _c
di in gr ") = " in ye `p'
global S_1 = `p'
return scalar p = `p'
exit
}
scalar `M0' = `A' * sqrt(`B') * normd(`delta' * sqrt(`B'))
scalar `M0' = `M0' * normprob(`delta' * `A' * sqrt(`B'))
if `df' == 2 {
scalar `p' = `p' + sqrt(2 * _pi) * `M0'
di _n in gr " p =" in ye %10.6f `p'
di _n in gr " P(t <= " `t' " | delta = " _c
di in gr `delta' ", df = " `df' _c
di in gr ") = " in ye `p'
global S_1 = `p'
return scalar p = `p'
exit
}
scalar `M1' = `A' * normd(`delta') / sqrt(2 * _pi)
scalar `M1' = `B' * (`delta' * `A' * `M0' + `M1')
if `df' == 3 {
scalar `p' = `p' + 2 * `M1'
di _n in gr " p =" in ye %10.6f `p'
di _n in gr " P(t <= " `t' " | delta = " _c
di in gr `delta' ", df = " `df' _c
di in gr ") = " in ye `p'
global S_1 = `p'
return scalar p = `p'
exit
}
scalar `M2' = `B' * ( `delta' * `A' * `M1' + `M0') / 2
if `df' == 4 {
scalar `p' = `p' + sqrt(2 * _pi) * (`M0' + `M2')
di _n in gr " p =" in ye %10.6f `p'
di _n in gr " P(t <= " `t' " | delta = " _c
di in gr `delta' ", df = " `df' _c
di in gr ") = " in ye `p'
global S_1 = `p'
return scalar p = `p'
exit
}
* calculate Mk's for k = 3 to `df'-2 and sum odds and evens
scalar `ak' = 1
scalar `Mo' = `M1'
scalar `Me' = `M0' + `M2'
scalar `k' = 3
while `k' <= `df' - 2 {
scalar `ak' = 1 / ((`k' - 2) * `ak')
scalar `Mk' = `ak' * `delta' * `A' * `M2' + `M1'
scalar `Mk' = (`k'-1) * `B' * `Mk' / `k'
if mod(`k',2) == 0 { scalar `Me' = `Me' + `Mk' }
else { scalar `Mo' = `Mo' + `Mk' }
scalar `M1' = `M2'
scalar `M2' = `Mk'
scalar `k' = `k' + 1
}
if `even' { scalar `p' = `p' + sqrt(2 * _pi) * `Me' }
else { scalar `p' = `p' + 2 * `Mo' }
di _n in gr " p =" in ye %10.6f `p'
di _n in gr " P(t <= " `t' " | delta = " _c
di in gr `delta' ", df = " `df' _c
di in gr ") = " in ye `p'
global S_1 = `p'
return scalar p = `p'
exit
end
/* ------------------------------------------------------------
Note: formula implemented above is from
D. B. Owen (Technometrics 10(3):445-478, 1968)
Let
t be the observed t-value
d be the non-centrality parameter
v be the degrees of freedom
G(z) be the cumulative standard Normal distribution
G'(z) be the standard Normal density function
Define
A = t / sqrt(v)
B = v / (v + t^2)
then
M = 0
-1
M = A * sqrt(B) * G'(d * sqrt(B)) * G(d * A * sqrt(B))
0
M = B * [ d * A * M + A * G'(d) / sqrt(2 * pi)]
1 0
M = B * [ d * A * M + M ]
2 0 1
and, for k>= 3,
M = (k - 1) * B * [ a * d * A * M + M ] / k
k k k-1 k-2
where a = 1 / [(k - 2) * a ] and a = 1
k k-1 2
Finally, for even df's,
P{T <= t | d, v} =
G(-d) + sqrt(2 * pi) * [M + M + ... + M ]
0 2 v-2
and for odd df's,
P{T <= t | d, v} =
G(-d * sqrt(B)) + 2 * C(d * sqrt(B), A) + 2 * [M + M + ... + M ]
1 3 v-2
where
abs(a)
1 / exp[-h^2 / 2 * (1 + x^2)]
C(h,a) = sign(a) -------- | --------------------------- dx
2 * pi / 1 + x^2
x=0
Note: integral C(h,a) is computed numerically in this program.
------------------------------------------------------------ */

View File

@ -0,0 +1 @@
.h nct

View File

@ -0,0 +1,138 @@
*! version 1.1.0 11/4/94 (STB-25: dm28)
program define nicenum
version 4.0
local mac "`1'"
if "`2'" != "=" {
di in red /*
*/ "nicenum macroname = arglist [if expr] [in range], Number(#)"
error 198
}
mac shift 2
local remain "`*'"
parse "`*'", parse(",")
local arglist "`1'"
local opts "`3'"
parse "`arglist'", parse(" ")
while "`1'" != "" & "`1'" != "if" & "`1'" != "in" {
capture confirm var `1'
if _rc != 0 {
local numlist "`numlist' `1'"
}
else { local varlist "`varlist' `1'" }
mac shift
}
tempvar use
mark `use' `*'
markout `use' `varlist'
tempname gmin gmax
scalar `gmin' = . /* uninitialized state */
scalar `gmax' = .
if "`varlist'" != "" {
parse "`varlist'", parse(" ")
quietly summ `1' if `use'
scalar `gmin' = _result(5)
scalar `gmax' = _result(6)
mac shift
while "`1'" != "" {
quietly summ `1' if `use'
scalar `gmin'=cond(_result(5)<`gmin',_result(5),`gmin')
scalar `gmax'=cond(_result(6)>`gmax',_result(6),`gmax')
mac shift
}
}
parse "`numlist'", parse(" ")
while "`1'" != "" {
if `gmin'==. { scalar `gmin' = `1' }
if `gmax'==. { scalar `gmax' = `1' }
scalar `gmin' = cond(`1'<`gmin',`1',`gmin')
scalar `gmax' = cond(`1'>`gmax',`1',`gmax')
mac shift
}
local command "`*' , `opts'"
local varlist "opt"
local options "Number(int 4)"
parse "`command'"
if `number' < 1 | `number' > 19 {
di in red "number must be in [1,19]"
error 198
}
local inter = `number' + 1
local ntick = `inter'
quietly {
tempname gran exp d f nf tmp1 tmp2
scalar `gran' = `gmax'-`gmin'
scalar `exp' = log10(`gran')
scalar `exp' = int(`exp') - (`exp'<0.0)
scalar `f' = `gran'/(10^`exp')
if `f' <= 1. { scalar `nf' = 1. }
else if `f' <= 2. { scalar `nf' = 2. }
else if `f' <= 5. { scalar `nf' = 5. }
else { scalar `nf' = 10. }
scalar `gran' = `nf'*10^`exp'
scalar `d' = `gran'/(`ntick'-1)
scalar `exp' = log10(`d')
scalar `exp' = int(`exp')-(`exp'<0.0)
scalar `f' = `d'/(10^`exp')
if `f' < 1.5 { scalar `nf' = 1. }
else if `f' < 3. { scalar `nf' = 2. }
else if `f' < 7. { scalar `nf' = 5. }
else { scalar `nf' = 10. }
scalar `d' = `nf'*10^`exp'
scalar `gmin' = `gmin'/`d'
scalar `gmin' = (int(`gmin') - (`gmin'<0.0))*`d'
scalar `tmp1' = `gmax'/`d'
scalar `tmp2' = int(`tmp1')
if `tmp2' < float(`tmp1') { scalar `tmp2' = `tmp2'+1 }
scalar `gmax' = `tmp2'*`d'
scalar `tmp1' = log10(`d')
local nfrac = int(-`tmp1')+(`tmp1'<0.0)
if `nfrac'<=0 { local nfrac = 0 }
if `nfrac' > 20 {
noi di in red "numbers too small for nice labels"
error 198
}
global `mac' ""
if `nfrac' == 0 {
scalar `tmp1' = `gmin'
}
else {
scalar `tmp1' = `gmin' + 1/(10^(`nfrac'+1))
}
scalar `tmp2' = `gmax' + `d'/2
local comma ""
while `tmp1' <= `tmp2' {
local stub = int(`tmp1')
if `nfrac' {
local gminb = int(`tmp1'*(10^`nfrac'))
local stubb = int(`stub'*(10^`nfrac'))
local frac = `gminb'-`stubb'
local frst = "00000000000000000000" + /*
*/ string(`frac')
local fstr = substr("`frst'",-`nfrac',.)
global `mac' = "${`mac'}`comma'`stub'.`fstr'"
}
else {
local tstr = string(`tmp1')
global `mac' = "${`mac'}`comma'`tstr'"
}
scalar `tmp1' = `tmp1' + `d'
local comma ","
}
end

View File

@ -0,0 +1,55 @@
*! version 1.0.0 \ scott long 2007-08-05
// syntax: nmlab <list of variables>, column(for labels) number vl
// task: list variable names and labels
// project: workflow chapter 4
// author: scott long \ 2007-08-05
capture program drop nmlab
program define nmlab
version 8, missing
syntax [varlist] [, COLumn(integer 0) NUMber vl]
tokenize `varlist'
local stop : word count `varlist'
local len = 0
local i 1
while `i' <= `stop' {
local l = length("``i''")
if `l'>`len' local len = `l'
local i = `i' + 1
}
if `column'==0 local column = `len' + 3
display
local i 1
if "`number'"=="number" {
local column = `column' + 6
}
else {
local n ""
}
* value label location
if "`vl'"=="vl" {
local column2 = `column' + 11 // for labels
}
while `i' <= `stop' {
local varlbl : variable label ``i'' // grab var label
local vallbl : value label ``i'' // grab value label
if "`number'"=="number" {
local n = substr(string(`i',"%4.0f") + ". ",1,6)
}
if "`vl'"!="vl" {
display in green "`n'``i''" in y _col(`column') "`varlbl'"
}
else { // show value label
display in green "`n'``i''" in white _col(`column') ///
"`vallbl'" in y _col(`column2') "`varlbl'"
}
local i = `i' + 1
}
end
exit

View File

@ -0,0 +1,49 @@
.-
help for ^nmlab^ :: 2008-03-07
.-
Create a list of variable names and variable labels
---------------------------------------------------
^nmlab^ varlist^,^ [ ^num^ber ^col(^#^)^ ^vl^ ]
Description
-----------
^nmlab^ lists the names and variable labels for a list of variables
that you provide.
Options
-------
^number^ produces a numbered list.
^col(^#^)^ indicates the column in which the variable label will begin.
By default, the label begins in column 12.
^vl^ lists the value label assigned to each variable.
Examples
--------
. ^use wf-lfp^
(Data from 1976 PSID-T Mroz)
. ^nmlab lfp k5^
lfp In paid labor force? 1=yes 0=no
k5 # kids < 6
. ^nmlab lfp k5, num^
#1: lfp In paid labor force? 1=yes 0=no
#2: k5 # kids < 6
. ^nmlab lfp k5, num col(15)^
#1: lfp In paid labor force? 1=yes 0=no
#2: k5 # kids < 6
. ^nmlabel lfp k5, vl^
lfp lfp In paid labor force? 1=yes 0=no
k5 # kids < 6
.-
Author: Scott Long - www.indiana.edu/~jslsoc/workflow.htm