ä¸ã
æ大似ç¶ä¼°è®¡çåç
æ大似ç¶ç估计åçå¯ä»¥ç±ä¸é¢çç¨åºå¾å°è¯´æãæ们é¦å
çæ 10 个æä»
æ£æåå¸çæ»ä½ï¼æ¯ä¸ªæ»ä½çåå¼é½ä¸åï¼ä¾æ¬¡ä¸º 0ï¼1ï¼2ï¼3ï¼4ï¼5ï¼6ï¼7ï¼8ï¼
9ãæ¹å·®ç¸åï¼å为 1ãç¶åæ们éæºå°ååºä¸ä¸ªæ»ä½ï¼ä»ä¸æ½åº 10 ä¸ªæ ·æ¬ï¼å
为äºå
ä¸ç¥éæ¯ä»åªä¸ä¸ªæ»ä½ä¸æ½åºæ¥çï¼æ以æ们åå«ç¨å·²ç¥ç 10 个æ»ä½å
æ°å¼ä»£å
¥
ä¼¼ç¶å½æ°ï¼è®¡ç®åº 10 个似ç¶å½æ°å¼ï¼åå
¶ä¸æ大çä¼¼ç¶å¼ï¼è®¤ä¸ºè¯¥æ ·
æ¬æ¯ä»ç¸åºçæ»ä½ä¸ååºçï¼ä»èèå
æ¦çå¯åº¦ä¹æ大åï¼ãç¶åæ们让计ç®æº
åè¯æ们å®æ¯ä»ç¬¬å 个æ»ä½ä¸åæ ·çï¼å¹¶ä¸æ们çå¤æè¿è¡å¯¹æ¯ã
codeï¼================================================================
capt prog drop mle
prog mle
drawnorm double x0-x9,n(8) m(0,1,2,3,4,5,6,7,8,9) clear
global i=int(10*uniform()) //设å®ä¸ä¸ª
éæºæ°ï¼ç¨äºéæºååºä¸ä¸ªæ»ä½
forv j=0/9 {
gen lnf`j' =-0.5*ln(2*_pi)*8-sum(0.5*(x$i-`j')^2) //对ååºçæ»ä½è®¡ç®ä¼¼ç¶å¼
scalar lnf`j'=lnf`j'[_N] //æç»çä¼¼ç¶å¼
}
scalar list // æ¯è¾10个似ç¶å¼åªä¸ªæ大ï¼çæ³æ¯ä»ç¬¬å 个æ»ä½ååºæ¥çï¼
end
mle
di "ææ½ä¸çæ ·æ¬ä¸º" as error "X"$i
äºãæå°äºä¹ä¼°è®¡ OLS åç
ä¸æ大似ç¶ä¼°è®¡å¯»æ±æ ·æ¬å¯åº¦å½æ°å¯¹æ°å¼æ大ä¸åï¼æå°äºä¹ä¼°è®¡å¯»æ±æ ·æ¬
ç¹ä¸æ»ä½åæ°çè·ç¦»æå°ãè¿ç§è·ç¦»é常以平æ¹åæ¥è¡¨ç¤ºï¼å æ¤ç§°ä¸ºæå°äºä¹ä¼°
计ãæå°äºä¹ä¼°è®¡åçå¯ä»¥ç±ä¸é¢çç¨åºå¾å°è¯´æã
æ们é¦å
çæ 10 个æä»æ£æåå¸çæ»ä½ï¼æ¯ä¸ªæ»ä½çåå¼é½ä¸åï¼ä¾æ¬¡ä¸º
0ï¼1ï¼2ï¼3ï¼4ï¼5ï¼6ï¼7ï¼8ï¼9ãä½æ¹å·®ç¸åï¼å为 1ãç¶åæ们éæºå°ååºä¸
个æ»ä½ï¼ä»ä¸æ½åº 10 ä¸ªæ ·æ¬ï¼å 为ä¸ç¥éæ¯ä»åªä¸ä¸ªæ»ä½ä¸æ½åºæ¥çï¼æ以æ
们åå«è®¡ç®æ ·æ¬ç¹ä¸å·²ç¥ç 10 个æ»ä½åæ°å¼ï¼åå¼ï¼ä¹é´è·ç¦»çå¹³æ¹åï¼ç¶å
å使å¾å¹³æ¹åæå°çåªä¸ªåæ°å¼ï¼è®¤ä¸ºè¯¥æ ·æ¬æ¯ä»åªä¸ªæ»ä½ä¸ååºçãç¶åæ们
让计ç®æºåè¯æ们å®æ¯ä»ç¬¬å 个æ»ä½ä¸åæ ·çã
code:================================================================
capt prog drop ols
prog ols
drawnorm double x0-x9,n(8) m(0,1,2,3,4,5,6,7,8,9) clear
*çæ10个æ»ä½,æ¯ä¸ªæ»ä½å8ä¸ªæ ·æ¬
global i=int(10*uniform()) //设å®ä¸ä¸ªä¸ä½æ°çéæºæ°ï¼0ï¼1ï¼2ï¼â¦ï¼9
forv j=0/9 {
gen lnf`j' =sum((x$i-`j')^2) //对ææ»ä½è®¡ç®10个è§å¯å¼å°æ»ä½åå¼çå¹³æ¹å
scalar lnf`j'=lnf`j'[_N] //åå¹³æ¹åèµç»
æ é}
scalar list //æ¯è¾10个平æ¹ååªä¸ªæ大ï¼çæ³æ¯ä»ç¬¬å 个æ»ä½ååºæ¥çï¼
end
ols
*æ ¹æ®10个平æ¹åï¼çæ³æ¯ä»ç¬¬å 个æ»ä½ååºæ¥çï¼
di "ææ½ä¸çæ ·æ¬ä¸º" as error "X"$i //æ¾ç¤ºçæ£çåæ ·æ»ä½æ¯?
ä¸ãç©ä¼°è®¡MMåç
ç©ä¼°è®¡æ³ä¸éè¦ç¥éæ»ä½çåå¸ï¼åªè¦ç¥éæ»ä½çç©å³å¯ãç¶åç´æ¥æ±åºæ ·
æ¬ç©ï¼ä»£æ¿æ»ä½ç©å³å¯ãç©ä¼°è®¡åçå¯ä»¥ç±ä¸é¢çç¨åºå¾å°è¯´æã
æ们é¦å
çæ 10 个æ»ä½ï¼æ¯ä¸ªæ»ä½çåå¼é½ä¸åï¼ä¾æ¬¡ä¸º 0ï¼1ï¼2ï¼3ï¼4ï¼
5ï¼6ï¼7ï¼8ï¼9ãç¶åæ们éæºå°ååºä¸ä¸ªæ»ä½ï¼ä»ä¸æ½åº 8 ä¸ªæ ·æ¬ï¼å 为ä¸ç¥
éæ¯ä»åªä¸ä¸ªæ»ä½ä¸æ½åºæ¥çï¼æ以æ们åå«è®¡ç®æ ·æ¬çä¸é¶åç¹ç©ï¼å³åå¼ï¼
ç¶ååè¯¥æ ·æ¬åå¼ä½ä¸ºæ»ä½åå¼ç估计å¼ï¼æ¯è¾æ ·æ¬åå¼ä¸æ»ä½åå¼ï¼è®¤ä¸ºç¸è·
æè¿çåªä¸ªæ ·æ¬æ¯ä»ç¸åºæ»ä½ä¸ååºçã
codeï¼================================================================
cap prog drop mm
drawnorm double x0-x9,n(8) m(0,1,2,3,4,5,6,7,8,9) clear
*çæ10个æ»ä½,åæ ·ï¼å¾å°10ä¸ªæ ·æ¬
global i=int(10*uniform()) //设å®ä¸ä¸ªä¸ä½æ°çéæºæ°ï¼0ï¼1ï¼2ï¼â¦ï¼9
quietly sum x$i
di r(mean)
*æ ¹æ®æ ·æ¬åå¼ï¼çæ³æ¯ä»ç¬¬å 个æ»ä½ååºæ¥çï¼
di "ææ½ä¸çæ ·æ¬ä¸º" as error "X"$i //æ¾ç¤ºçæ£çåæ ·æ»ä½æ¯?
åãåºé´ä¼°è®¡åç
åºé´ä¼°è®¡ä¸ç¹ä¼°è®¡ä¸åï¼å®å¯»æ±ä¸ä¸ªåºé´ï¼è¯¥åºé´ä»¥ä¸å®çæ¦çä¿è¯çæ£çæ»
ä½åæ°å¼å
å«å¨å
¶ä¸ï¼å½ç¶ï¼å¯¹äºä¸ä¸ªç¹å®çæ ·æ¬ï¼å®å¯è½å
å«åæ°çå¼ï¼ä¹å¯
è½ä¸å
å«ã
codeï¼================================================================
capt prog drop bb
prog bb
drawnorm x,n(100) m(5) sds(10) d clear
quietly sum x
end
***å°ä¸è¿°æ½æ ·è¯éªè¿è¡100次ï¼å¾å°100ä¸ªæ ·æ¬åå¼meanåæ åå·®sd
simulate mean=r(mean) sd=r(sd), reps (100) nodots: bb
g n=_n
*å¨å·²ç¥æ»ä½æ¹å·®åæä¸ï¼
æ»ä½æ å差为10ï¼ï¼æ±100个åæ ·æ¬95%ç
置信åºé´g zlow=mean-invnorm(0.975)*10/sqrt(100)
g zhigh=mean+invnorm(0.975)*10/sqrt(100)
*å¨æ»ä½æ¹å·®æªç¥çåæä¸ï¼ç¨
æ ·æ¬æ åå·®sdæ¿ä»£ï¼éè¦åå©tç»è®¡é
g tlow=mean-invttail(99,0.025)*sd/sqrt(100)
g thigh=mean+invttail(99,0.025)*sd/sqrt(100)
*èå¯æ»ä½åå¼æ¯å¦å¨åæ ·æ¬ç95%置信åºé´å
ï¼å¦ä¸å¨åæ 记为1ï¼å¦å为é¶
g zsign=(zlow<5& zhigh>5)
g tsign=(tlow<5& thigh>5)
*ç»è®¡æ²¡æå
æ¬æ»ä½åå¼çåæ ·æ¬95%置信åºé´ä¸ªæ°
table zsign
table tsign
*å¾ç¤º
tw rcapsym thigh tlow n, yline(5) || rcapsym thigh tlow n if thigh<5 | tlow>5
äºãå设æ£éªåç
ç±äºï¼1ï¼æ们ä¸ç¥éçæ£çæ»ä½åå¼ï¼ï¼2ï¼åªè½æ½åä¸ä¸ªæ ·æ¬ï¼å æ¤ï¼å½
æä»¬æ ¹æ®å¯¹æ ·æ¬çç»è®¡ç»ææ¥å¯¹æ»ä½åå¼è¿è¡æ¨æçæ¶åå°±å¯è½åºéãä»ä¸æ¬¡æ½
æ ·æ¥æ¨ææ¶ï¼æ ·æ¬åå¼ç 95%置信åºé´å¯è½å«ææ»ä½åå¼ï¼ä¹å¯è½ä¸å«ææ»ä½å
å¼ï¼å«æçå¯è½æ§ä¸º 95%ï¼ä¸å«æçå¯è½æ§ä¸º 5%ãå¦ææ¬æ¥æ¯ä¸å«æççå¼çï¼
æ们认为å«æï¼å°±ç¯äºçº³ä¼ªé误ï¼å¦ææ¬æ¥æ¯å«æççå¼çï¼æ们认为ä¸å«æï¼
å°±ç¯äºå¼çé误ã
å½æ»ä½çæ¹å·®æªç¥æ¶ï¼ç¨
æ ·æ¬æ¹å·®æ¥æ¿ä»£æ»ä½æ¹å·®ï¼åæ ·æ¬åå¼åæ»ä½åå¼
æä»(n-1)ç t åå¸ã
æ
å½¢ 1ï¼æ»ä½åå¼å·²ç¥ï¼ä¸º u=5ãä½æ们åè£
ä¸ç¥éï¼å´ååºäºå¯¹æ»ä½åå¼æ£ç¡®
çåå设ï¼è®¤ä¸ºå®çäº u0=5ï¼åæ½æ ·è¿è¡å设æ£éªå¦ä¸
code1ï¼=================================================================
drawnorm x,n(100) m(5) sds(10) d clear
*çæä¸ä¸ªåå¼u=5,æ åå·®o=10çæ£æ
éæºåéï¼ä½ä¸ºç 究æ»ä½
quietly sum x
di as text "ä»æ ·æ¬è®¡ç®tç»è®¡å¼ä¸ºï¼" as error (r(mean)-5)/(sqrt(100)*r(sd))
di as text "æ ¹æ®tç»è®¡é临çå¼ä¸ºï¼" as error invttail(99,0.025)
di as result "对è¿æ¬¡å®éªï¼æç»è¿æ¯æ¥åï¼"
code2ï¼==================================================================
capt prog drop bb
prog bb
drawnorm x,n(100) m(5) sds(10) d clear
quietly sum x
scalar ref=(abs(sqrt(100)*(r(mean)-5)/r(sd))>invttail(99,0.025))
*å¦ææ ·æ¬ç»è®¡éï¼tï¼å¼å¤§äºä¸´çå¼ï¼åæç»åå设ä¸æ¬¡jud=1,å¦å为0
end
simulate ref,reps(100):bb
tab _sim //å
¶ä¸ç1表示å¨100次ä¸æç»åå设ç次æ°ã
æ
å½¢ 2ï¼æ»ä½åå¼å·²ç¥ï¼ä¸º u=5ãä½æ们åè£
ä¸ç¥éï¼å¹¶ååºäºå¯¹æ»ä½åå¼é误
çåå设ï¼å¦è®¤ä¸ºå®çäº u0=10ï¼åæ½æ ·è¿è¡å设æ£éªå¦ä¸
code3ï¼=================================================================
capt prog drop bb
prog bb
drawnorm x,n(100) m(5) sds(10) d clear
quietly sum x
scalar jud=(abs(sqrt(100)*(r(mean)-10)/r(sd))>invttail(99,0.025) ) //æ¯è¾ç»è®¡å¼ä¸ä¸´çå¼å¤§å°
end
simulate jud,reps(100):bb
tab _sim