Keyword: 順位, 回帰, regression, rank, right-censored
概要
本サンプルは右打ち切りデータが観測値に含まれる場合の順位を使った回帰(Regression using ranks) を行うFortranによるサンプルプログラムです。 本サンプルは以下に示される標本、説明変数と打ち切り変数を分析対象とします。このサンプルでは回帰分析を行い、スコア統計量、スコア統計量の共分散行列、パラメータ推定、パラメータ推定の共分散行列、パラメータ推定の標準誤差やZ統計量を算出します。
※本サンプルはnAG Fortranライブラリに含まれるルーチン g08rbf() のExampleコードです。本サンプル及びルーチンの詳細情報は g08rbf のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本ルーチンの詳細はg08rbf のマニュアルページを参照)1 2 3 4 5 6 7 8 9 10 11
このデータをダウンロード |
G08RBF Example Program Data 1 1 0.00001 0.00001 40 143.0 0.0 0 164.0 0.0 0 188.0 0.0 0 188.0 0.0 0 190.0 0.0 0 192.0 0.0 0 206.0 0.0 0 209.0 0.0 0 213.0 0.0 0 216.0 0.0 0 220.0 0.0 0 227.0 0.0 0 230.0 0.0 0 234.0 0.0 0 246.0 0.0 0 265.0 0.0 0 304.0 0.0 0 216.0 0.0 1 244.0 0.0 1 142.0 1.0 0 156.0 1.0 0 163.0 1.0 0 198.0 1.0 0 205.0 1.0 0 232.0 1.0 0 232.0 1.0 0 233.0 1.0 0 233.0 1.0 0 233.0 1.0 0 233.0 1.0 0 239.0 1.0 0 240.0 1.0 0 261.0 1.0 0 280.0 1.0 0 280.0 1.0 0 296.0 1.0 0 296.0 1.0 0 323.0 1.0 0 204.0 1.0 1 344.0 1.0 1
- 1行目はタイトル行で読み飛ばされます。
- 2行目に標本の数(ns=1)、フィッティングされるパラメータ数(ip=1)、誤差分布のべき乗パラメータ(gamma=0.00001)、そして観測値の同順位(タイ)についての許容基準(tol=0.00001)を指定しています。
- 3行目に標本の観測値の数(nv=40)を指定しています。
- 4~11行目に標本の観測値(y)、説明変数(x)と打ち切り変数(icen)を指定しています。
出力結果
(本ルーチンの詳細はg08rbf のマニュアルページを参照)1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
この出力例をダウンロード |
G08RBF Example Program Results Number of samples = 1 Number of parameters fitted = 1 Distribution power parameter = 0.00001 Tolerance for ties = 0.00001 Score statistic 4.584 Covariance matrix of score statistic 7.653 Parameter estimates 0.599 Covariance matrix of parameter estimates 0.131 Chi-squared statistic = 2.746 with 1 d.f. Standard errors of estimates and approximate z-statistics 0.361 1.657
- 3行目には標本の数が出力されています。
- 4行目にはフィッティングされるパラメータ数が出力されています。
- 5行目には誤差分布のべき乗パラメータが出力されています。
- 6行目には観測値の同順位の許容基準が出力されています。
- 9行目にはスコア統計量が出力されています。
- 12行目にはスコア統計量の共分散行列が出力されています。
- 15行目にはパラメータ推定が出力されています。
- 18行目にはパラメータ推定の共分散行列が出力されています。
- 20行目には自由度1のカイ二乗統計量が出力されています。
- 24行目には推定値の標準誤差と近似Z統計量が出力されています。
ソースコード
(本ルーチンの詳細はg08rbf のマニュアルページを参照)
※本サンプルソースコードは科学技術・統計計算ライブラリである「nAG Fortranライブラリ」のルーチンを呼び出します。
サンプルのコンパイル及び実行方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
このソースコードをダウンロード |
PROGRAM g08rbfe ! G08RBF Example Program Text ! Mark 23 Release. nAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : g08rbf, nag_wp ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nin = 5, nout = 6 ! .. Local Scalars .. REAL (KIND=nag_wp) :: gamma, tol INTEGER :: i, ifail, ip, j, ldprvr, ldx, liwa, & lparest, lvapvec, lwork, nmax, ns, & nsum ! .. Local Arrays .. REAL (KIND=nag_wp), ALLOCATABLE :: eta(:), parest(:), prvr(:,:), & vapvec(:), work(:), x(:,:), y(:), & zin(:) INTEGER, ALLOCATABLE :: icen(:), irank(:), iwa(:), nv(:) ! .. Intrinsic Functions .. INTRINSIC maxval, sum ! .. Executable Statements .. WRITE (nout,*) 'G08RBF Example Program Results' WRITE (nout,*) ! Skip heading in data file READ (nin,*) ! Read number of samples, number of parameters to be fitted, ! distribution power parameter and tolerance criterion for ties. READ (nin,*) ns, ip, gamma, tol ALLOCATE (nv(ns)) ! Read the number of observations in each sample READ (nin,*) nv(1:ns) ! Calculate NSUM, NMAX and various array lengths nsum = sum(nv(1:ns)) nmax = maxval(nv(1:ns)) ldx = nsum ldprvr = ip + 1 lvapvec = nmax*(nmax+1)/2 lparest = 4*ip + 1 lwork = nmax*(ip+1) liwa = 4*nmax ALLOCATE (y(nsum),x(ldx,ip),icen(nsum),prvr(ldprvr,ip),irank(nmax), & zin(nmax),eta(nmax),vapvec(lvapvec),parest(lparest),work(lwork), & iwa(liwa)) ! Read in observations, design matrix and censoring variable READ (nin,*) (y(i),x(i,1:ip),icen(i),i=1,nsum) ! Display input information WRITE (nout,99999) 'Number of samples =', ns WRITE (nout,99999) 'Number of parameters fitted =', ip WRITE (nout,99998) 'Distribution power parameter =', gamma WRITE (nout,99998) 'Tolerance for ties =', tol ifail = 0 CALL g08rbf(ns,nv,nsum,y,ip,x,ldx,icen,gamma,nmax,tol,prvr,ldprvr, & irank,zin,eta,vapvec,parest,work,lwork,iwa,ifail) ! Display results WRITE (nout,*) WRITE (nout,*) 'Score statistic' WRITE (nout,99997) parest(1:ip) WRITE (nout,*) WRITE (nout,*) 'Covariance matrix of score statistic' DO j = 1, ip WRITE (nout,99997) prvr(1:j,j) END DO WRITE (nout,*) WRITE (nout,*) 'Parameter estimates' WRITE (nout,99997) parest((ip+1):(2*ip)) WRITE (nout,*) WRITE (nout,*) 'Covariance matrix of parameter estimates' DO i = 1, ip WRITE (nout,99997) prvr(i+1,1:i) END DO WRITE (nout,*) WRITE (nout,99996) 'Chi-squared statistic =', parest(2*ip+1), ' with', & ip, ' d.f.' WRITE (nout,*) WRITE (nout,*) 'Standard errors of estimates and' WRITE (nout,*) 'approximate z-statistics' WRITE (nout,99995) (parest(2*ip+1+i),parest(3*ip+1+i),i=1,ip) 99999 FORMAT (1X,A,I2) 99998 FORMAT (1X,A,F10.5) 99997 FORMAT (1X,F9.3) 99996 FORMAT (1X,A,F9.3,A,I2,A) 99995 FORMAT (1X,F9.3,F14.3) END PROGRAM g08rbfe