作者seablack (Water)
看板NCTU-STAT96G
標題Re: [心得] imsl chi-squar檢定
時間Fri Aug 3 13:15:52 2007
應該是這樣
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <stdarg.h>
#include "gcc_imsls.h"
//自己寫了一EXP(1)的產生器
float GEXP1(int seed)
{
float Y, u;
u = (rand()%seed/(1.0*seed));
//以下二個 if 是為了 void 丟進log會有問題
if(u <1.0E-5) u = 1.0E-5;
if(u >0.99999) u = 0.99999;
Y = -1.0*log(u);
return(Y);
}
//自己寫了一EXP(1)的CDF
float Gexp1_CDF(float Z)
{
float A = 1.0-exp(-Z);
return(A);
}
main()
{
int N_CATEGORIES = 10; //把data分10 grp
int N_OBSERVATIONS = 2000;//產生2000個DATA
int i, seed = 123457;
float *y;
float p_value ;
HINSTANCE hStatLib = LoadLibrary("cstat.dll");
IMSLS_F_CHI_SQUARED_TEST imsls_f_chi_squared_test;
imsls_f_chi_squared_test =(IMSLS_F_CHI_SQUARED_TEST)GetProcAddress(hStatLib,"imsls_f_chi_squared_test");
y=(float *)malloc(N_OBSERVATIONS*sizeof(float));
for(i=0;i<N_OBSERVATIONS ;i++){
y[i] = GEXP1((seed+i*1191) );
//printf("%2d\t%.3f\t%.3f\n",i,y[i],Gexp1_CDF(y[i]));
}
//Gexp1_CDF 自己寫的 CDF 副程式
p_value = imsls_f_chi_squared_test (Gexp1_CDF, N_OBSERVATIONS , N_CATEGORIES ,y , 0);
printf("pvalue = %f\n", p_value);
free(y);FreeLibrary(hStatLib);
}
$ gcc Chi_Unif.c
Chi_Unif.c: In function `main':
Chi_Unif.c:42: warning: passing arg 1 of pointer to function from incompatible pointer type
有一個 WARNING產生,別管它!!
$ ./a.exe
pvalue = 0.202269
以上是一個 利用 imsls_f_chi_squared_test()
檢定 自己產生的 EXP(1) 的 DEMO程式
請大家多多 討論一下!
TB
※ 引述《fr407041 (so sad so blue)》之銘言:
: 痾 我不知道我這樣跑對不對
: 但我讓它complier過了
: 所以想跟大家討論一下
: int N_CATEGORIES = 10;//我猜這應該是把分配分幾塊的意思
: IMSLS_F_CHI_SQUARED_TEST imsls_f_chi_squared_test;
: IMSLS_F_NORMAL_CDF imsls_f_normal_cdf;
: imsls_f_normal_cdf =
: (IMSLS_F_NORMAL_CDF)GetProcAddress(hStatLib,"imsls_f_normal_cdf");
: imsls_f_chi_squared_test =
: (IMSLS_F_CHI_SQUARED_TEST)GetProcAddress(hStatLib,"imsls_f_chi_squared_test");
: float p_value ;
: p_value = imsls_f_chi_squared_test ((float *)imsls_f_normal_cdf ,
: N_OBSERVATIONS , N_CATEGORIES ,y , 0);
: printf("pvalue = %f\n", p_value);
: 我出來的pvalue是0
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.230.193.237