|
下面一个计算单比例置信区间的例子:
实现效果:
程序如下(参考附件):数据与程序下载 http://www.kuaipan.cn/file/id_186398518334717989.htm
- //*********************************************
- // 此程序是用来计算单比例样本的比例估计和对应置信区间。计算基于正态分布,当样本小于30时,计算结果有偏差。
- // 此程序仅用来展示JSL用法,不对算法进行深入研究,如需更精确计算,请参考相关公式。
- // Skyfree
- // 2013.08
- //**********************************************
- Clear Globals();
- :: pConf = Function( {y = ., n = .},
- confVal = Num( conf << get selected );
- z = Normal Quantile( confVal + ((1 - confVal) / 2) );
- perc = (y / n);
- UCL = ((perc + (z ^ 2 / (2 * n))) + z * (Root( ((perc * (1 - perc) / n) + (z ^ 2) / (4 * n ^ 2)), 2 ))) / (1 + z ^ 2 / n);
- LCL = ((perc + (z ^ 2 / (2 * n))) - z * (Root( ((perc * (1 - perc) / n) + (z ^ 2) / (4 * n ^ 2)), 2 ))) / (1 + z ^ 2 / n);
- Show( UCL );
- Show( LCL );
- Show(perc);
- If( Or( y > n, y < 0, n < 0 ),
- UCLanswer << set text( "成功次数不能小于实验总次数/数值不能小于0. 请重试!" );
- LCLanswer << set text( "" );
- UCLanswer << font color( 3 );
- UCLanswer << set font size( 10 );
- ,
- Meananswer << set text( "比例估计: " || Char( Round( perc, 5 ) ) );
- Meananswer << font color( 0 );
- Meananswer << set font size( 10 );
- UCLanswer << set text( "置信区间上限UCL: " || Char( Round( UCL, 5 ) ) );
- UCLanswer << font color( 0 );
- UCLanswer << set font size( 10 );
- LCLanswer << set text( "置信区间下限LCL: " || Char( Round( LCL, 5 ) ) );
- LCLanswer << font color( 0 );
- LCLanswer << set font size( 10 );
- );
- );
- PropCalc = New Window ( "单比例置信区间",
- Panel Box( "比例置信区间计算",
- Lineup Box(
- N Col( 1 ),
- Text Box( "成功次数: " ), yIn = Text Edit Box( 1 ),
- Text Box( "总实验次数: " ), nIn = Text Edit Box( 10 ),
- Text Box( "置信水平: " ), Conf = Combo Box({"0.95", "0.99", "0.90"} ),
- V List Box(
- Border Box(
- Top( 10 ),
- Left( 10 ),
- Bottom( 15 ),
- sides( 143 ),
- V List Box( UCLanswer = Text Box( "置信区间上限UCL: " ),Meananswer = Text Box( "比例估计: " ), LCLanswer = Text Box( "信区间下限LCL: " ),
- Text Box( "注:当样本量小于30,计算结果将不精确 " ),)
- ),
- H List Box(
- Button Box( "确认",
- y = Num( yIn << get text );
- n = Num( nIn << get text );
- ::pConf( y = Num( yIn << get text ), n = Num( nIn << get text ) );
- )
- ),
- Button Box( "退出",
- PropCalc << CloseWindow;
- Clear Globals();
- )
- )
- )
- )
- );
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|