|
Subroutines
Exported in the Windows 95/98/NT DLL
|
There are two main routines exported from the DLL,
one of which calculates the (general) one-sided confidence limits, and
the other calculates the two-sided limits. You should be able to call
these functions from just about anything in Windows 95/98/NT (an example
using Visual Basic in Microsoft Excel is included below).
The tables below summarize the argument lists; they are long since they
are both for the most general case.
|
Subroutine OneTail (WhichLimit,m, s, nu, alpha,
lambda, gammasquared, ArgTop, Tolerance, ResultTol, MaxNumberIterations,
returnTheH, returnConfLimit, returnTheTime, returnItNum)
|
|
Inputs
|
Type
|
Comment
|
Range/Suggested Value for Inputs
|
If Calculating Confidence Limits
for the Mean of a Lognormal Distribution, then you should use...
|
| WhichLimit |
Long |
1=Lower limit, 2=Upper limit |
|
|
| m |
Double |
Sample mean |
None |
Sample mean of natural logarithm of values |
| s |
Double |
Sample standard deviation |
0.1 to 10.0 |
Sample standard deviation of natural
logarithm of values |
| nu |
Double |
We are assuming that s2 is
distributed as s2/n times chi-square
with n degrees of freedom |
2 to 1000 |
Number of samples minus one |
| alpha |
Double |
Desired level of confidence |
Between 0 and 1 |
|
| lambda |
Double |
Calculated confidence limits are for
m + l
s2 |
None |
0.5 |
| gammasquared |
Double |
We are assuming that m is distributed
as a normal distribution with mean m and
standard deviation s2/g2 |
nu+1 |
Number of samples |
| ArgTop |
Double |
Upper bound for Bessel function evaluation |
800 |
800 |
| Tolerance |
Double |
Absolute tolerance for calculated limits |
1e-8 |
1e-8 |
| ResultTol |
Double |
Additional tolerance term used for concluding
convergence if |f(x)| is small enough in some cases; if less
than or equal to 0 then this is not used. |
-1 |
-1 |
| MaxNumberIterations |
Long |
Maximum number of iterations |
200 |
200 |
|
Outputs
|
|
|
|
|
| returnTheH |
Double |
Standardized upper one-sided limit of
level alpha |
|
|
| returnConfLimit |
Double |
Calculated upper one-sided
limit of level alpha (a lower one-sided limit of level alpha is an
upper one-sided limit of level 1-alpha) |
|
Upper Confidence limit for
the mean is exp(returnConfLimit) |
| returnTheTime |
Double |
Time required to calculate limits (seconds) |
|
|
| returnItNum |
Long |
Number of iterations required to calculate
confidence limit |
|
|
|
Subroutine TwoTail (m, s, nu, alpha, lambda,
gammasquared, LowerLimit, LowerTheH, UpperLimit, UpperTheH, TheTime,
LowerGuess1, LowerGuess2, UpperGuess1, UpperGuess2, ItNum1, ItNum2,
ArgTop, Tolerance, ResultTol, MaxNumberIterations)
|
|
Inputs
|
Type
|
Comment
|
Range/Suggested Value for Inputs
|
If Calculating Confidence Limits
for the Mean of a Lognormal Distribution, then you should use...
|
| m |
Double |
Sample mean |
None |
Sample mean of natural logarithm of values |
| s |
Double |
Sample standard deviation |
0.1 to 10.0 |
Sample standard deviation of natural
logarithm of values |
| nu |
Double |
We are assuming that s2 is
distributed as s2/n times chi-square
with n degrees of freedom |
2 to 1000 |
Number of samples minus one |
| alpha |
Double |
Desired level of confidence |
Between 0 and 1 |
|
| lambda |
Double |
Calculated confidence limits are for
m + l
s2 |
None |
0.5 |
| gammasquared |
Double |
We are assuming that m is distributed
as a normal distribution with mean m and
standard deviation s2/g2 |
nu+1 |
Number of samples |
| ArgTop |
Double |
Upper bound for Bessel function evaluation |
800 |
800 |
| Tolerance |
Double |
Absolute tolerance for calculated limits |
1e-8 |
1e-8 |
| ResultTol |
Double |
Additional tolerance term used for concluding
convergence if |f(x)| is small enough in some cases; if less
than or equal to 0 then this is not used. |
-1 |
-1 |
| MaxNumberIterations |
Long |
Maximum number of iterations |
200 |
200 |
|
Outputs
|
|
|
|
|
| returnLowerLimit |
Double |
Calculated lower two-sided limit of level
alpha |
|
Lower limit for the mean is exp(returnLowerLimit) |
| returnLowerTheH |
Double |
Standardized lower two-sided limit of
level alpha |
|
|
| returnUpperLimit |
Double |
Calculated upper two-sided limit of level
alpha |
|
Upper limit for the mean is exp(returnLowerLimit) |
| returnUpperTheH |
Double |
Standardized upper two-sided limit of
level alpha |
|
|
| returnTheTime |
Double |
Time required to calculate limits (seconds) |
|
|
| returnItNum1 |
Long |
Number of iterations required to calculate
lower limit |
|
|
| returnItNum2 |
Long |
Number of iterations required to calculate
upper limit |
|
|
Example Calling These Functions
Using Visual Basic in Microsoft Excel
In a Visual Basic module in Excel, add the code shown below the table.
It declares the DLLs (you'll need to probably change the path, depending
on where you put the DLL), and defines wrapper routines that pass some
of the default options through to the subroutines in the DLL. In a worksheet
in the workbook containing the module, you can call these functions by
using formulas of the form
| =upperconflimit(m,s,nu,alpha) |
Calculates upper one-sided confidence limit of level
alpha |
| =twosidedconflimit(m,s,nu,alpha,1) |
Calculates upper two-sided confidence limit of level
alpha |
| =twosidedconflimit(m,s,nu,alpha,2) |
Calculates lower two-sided confidence limit of level
alpha |
where the arguments can be constants (e.g., "=upperconflimit(0.0,
1.0, 10,0.95)") or references to other cells.
Option Explicit
' Declaring the DLLs; replace the path with whereever you put the dll. If you put the DLL in
' the windows\system directory, then you can use just the filename without the path.
Public Declare Sub TwoTail Lib "c:\ConfLimit\Program\Conf95DLL\Conf95DLL.dll" ( _
mu As Double, _
sigma As Double, _
nu As Double, _
alpha As Double, _
Lambda As Double, _
GammaSq As Double, _
argArgTop As Double, _
argTolerance As Double, _
argResultTol As Double, _
argNumIt As Long, _
returnLowerLimit As Double, _
returnLowerTheH As Double, _
returnUpperLimit As Double, _
returnUpperTheH As Double, _
returnTheTime As Double, _
returnItNum1 As Long, _
returnItNum2 As Long)
' returnLowerGuess1 As Double, _
returnLowerGuess2 As Double, _
returnUpperGuess1 As Double, _
returnUpperGuess2 As Double, _
Public Declare Sub OneTail Lib "c:\ConfLimit\Program\Conf95DLL\Conf95DLL.dll" ( _
WhichLimit As Long, _
mu As Double, _
sigma As Double, _
nu As Double, _
alpha As Double, _
Lambda As Double, _
GammaSq As Double, _
BesselFunctionArgTop As Double, _
Tolerance As Double, _
Tol As Double, _
MaximumIterations As Long, _
returnTheH As Double, _
returnConfLimit As Double, _
returnTheTime As Double, _
returnNumberofIterations As Long)
' A wrapper function for calling the routine that calculates the two-sided confidence limits for the case lambda=0.5; this returns the upper limit
Function TwoSidedConfLimit(m As Double, s As Double, nu As Double, alpha As Double, WhichLimit As Long) As Double
' m : sample mean
' s : sample standard deviation (s>0)
' nu : degrees of freedom (nu>0)
' alpha : desired confidence level (01 : return lower limit
Dim mu As Double, _
sigma As Double, _
Lambda As Double, _
GammaSq As Double, _
returnLowerLimit As Double, _
returnLowerTheH As Double, _
returnUpperLimit As Double, _
returnUpperTheH As Double, _
returnTheTime As Double, _
returnItNum1 As Long, _
returnItNum2 As Long
' returnLowerGuess1 As Double, _
returnLowerGuess2 As Double, _
returnUpperGuess1 As Double, _
returnUpperGuess2 As Double, _
Dim BesselFunctionArgTop As Double
Dim Tolerance As Double
Dim ResultTol As Double
Dim MaximumIterations As Long
BesselFunctionArgTop = 800#
Tolerance = 0.0001
ResultTol = -1#
MaximumIterations = 200
mu = m
sigma = s
Lambda = 0.5
GammaSq = (nu + 1#)
Call TwoTail(mu, _
sigma, _
nu, _
alpha, _
Lambda, _
GammaSq, _
BesselFunctionArgTop, Tolerance, ResultTol, MaximumIterations, _
returnLowerLimit, _
returnLowerTheH, _
returnUpperLimit, _
returnUpperTheH, _
returnTheTime, _
returnItNum1, _
returnItNum2)
'returnLowerGuess1, _
returnLowerGuess2, _
returnUpperGuess1, _
returnUpperGuess2, _
If WhichLimit = 1 Then
TwoSidedConfLimit = returnUpperLimit
Else
TwoSidedConfLimit = returnLowerLimit
End If
End Function 'Function TwoSidedConfLimit
' A wrapper function for calling the routine that calculates one-sided confidence limits in the
' special case lambda=0.5, gamma^2=nu+1
'
' If m and s are the sample mean and standard deviation of the natural logarithm of samples from a lognormal distribution, calculated from
' (nu+1) samples, then exp(UpperConfLimit) is an upper confidence limit of level alpha for the mean of the lognormal distrubution
'
Function UpperConfLimit(m As Double, s As Double, nu As Double, alpha As Double) As Double
' m : sample mean
' s : sample standard deviation (s>0)
' nu : degrees of freedom (nu>0)
' alpha : desired confidence level (0
|