Hi,
I found something funny in my analysis. I apply this
condlog macro in my data set and found some covariates
are significant but the regression SS is zero. I give
a sample data set with the macro program. Here you
also see the same result.
I also try considering only the significant covarites
in the model and again got them significant but the
Regression SS is zero.
I also try to set the initial values (those I got in
the previous analysis) in the macro peogram and again
got reg SS zero.
Would you pelase say me why... Sorry to bothering who
are not interested in SAS.
Thanks.
Zaman
%macro condlog(strata=,case=,variable=,data=_last_);
%*--------------------------------------------------------------*
* CONDLOG is a macro to perform conditional logistic
*
* regression with the NLIN procedure.
*
* It allows for arbitrary n:m matching.
*
*
*
* strata names the variables which define
the strata. *
* These must be numeric.
*
* case is the name of the variable
labeling *
* the cases (value must be 1) and
controls (0). *
* and a control value 0.
*
* variable lists the covariates.
*
* data names the input dataset.
*
*---------------------------------------------------------------;
%*----eliminate missing values and sort the
data----------;
data _clog1; set &data;
if nmiss( of &variable &case &strata) > 0 then
delete;
if &case=0 or &case=1 ;
keep &variable &case &strata ;
proc sort; by &strata &case;
%*----generate list of
variables--------------------------;
%let n=0;
%let old=;
%do %while(%scan(&variable,&n+1)~=);
%let n=%eval(&n+1);
%let var&n=%scan(&variable,&n);
%let old=&old _old&n;
%end;
%*----find name of last strata
variable---------------------;
%let i=1;
%do %while(%scan(&strata,&i)~=);
%let last=%scan(&strata,&i);
%let i=%eval(&i+1);
%end;
%*----find the within strata/case
counts--------------------;
proc means noprint;var &variable; by &strata &case;
output out=_clog2 n=n mean=&old;
%*----throw out invalid strata and count the
maximum--------;
data _clog2; set _clog2; by &strata;
if first.&last=last.&last then delete;
if &case=1;
data _clog1(rename=( %do i=1 %to &n; &&var&i =
_old&i %end; ));
merge _clog1 _clog2; by &strata;
array c &variable;
array m &old;
retain casemax 0;
if n>. ;
/* --- zero the sum of variables over the cases
--- */
do over c;
c = c - m;
end;
/* --- end of strata flag ---- */
_sflag = last.&last;
/* --- for array allocation --- */
if n > casemax then
do;
casemax=n;
call symput('casemax',casemax);
end;
keep &case &variable _sflag n;
proc nlin data=_clog1 sigsq=1 maxiter=20
method=marquardt;
%let casemax=%scan(&casemax,1);
%*----set parms statement with initial values
zero ------;
parms %do i=1 %to &n;
&&var&i = 0
%end; ;
array psi{ &casemax };
/* derivatives of psi */
%do i=1 %to &n;
array psid&i{ &casemax };
retain psid&i.1-psid&i&casemax 0;
%end;
retain psi1-psi&casemax 0 ;
%*----compute x b and put in the variable _z_
----;
_z_ = exp( %do i=1 %to &n; +&&var&i * _old&i
%end;) ;
%*----do the
recurrence---------------------------------;
s1=1;
do _i_=1 to n;
s2=psi{_i_};
psi{_i_}=psi{_i_}+_z_*s1;
s1=s2;
end;
if _sflag=0 then _loss_ = 0;
else _loss_ = log(psi{n}) / psi{n};
_weight_ = psi{n};
/* --- contribution only for each strata --- */
if _sflag = 0 then dummy = .;
else dummy = n-1;
model n = dummy;
_wgtjpj_ = psi{n} ** 2;
if ~_model_ then
do; /* derivatives */
%do i=1 %to &n;
d1=0;
s1=1;
do _i_=1 to n;
d2=psid&i {_i_};
psid&i {_i_}=psid&i {_i_}+_z_ * (d1 +
_old&i * s1);
d1=d2;
s1=psi{_i_};
end;
if _sflag=0 then der.&&var&i=0;
else
do;
der.&&var&i = -psid&i{n} / psi{n} ** 2;
do _i_=1 to n;
psid&i {_i_} = 0;
end;
end;
%end;
end;
if _sflag ~= 0 then do _i_=1 to n; psi{_i_}=0;
end;
run;
%mend condlog;
/*------------------------Birthweight Data
-------------------*/
/* Cases are mothers of low birthweight variables
*/
/* matched on age.
*/
/* Explanatory variables are smoking, hypertension
history, */
/* presence of uterine irritability, weight at last
menstrual */
/* period, and whether there was a previous preterm
delivery. */
/* From Hosmer and Lemeshow, ( 1989, Appendix 4 )
*/
/*------------------------------------------------------------*/
data oneto3 ;
input str obs age low lwt smoke ht ui ptd @@ ;
cards ;
1 1 16 1 130 0 0 0 0 1 2 16 0 112 0 0 0 0
1 3 16 0 135 1 0 0 0 1 4 16 0 95 0 0 0 0
2 1 17 1 130 1 0 1 1 2 2 17 0 103 0 0 0 0
2 3 17 0 122 1 0 0 0 2 4 17 0 113 0 0 0 0
3 1 17 1 120 0 0 0 0 3 2 17 0 113 0 0 0 0
3 3 17 0 119 0 0 0 0 3 4 17 0 119 0 0 0 0
4 1 18 1 148 0 0 0 0 4 2 18 0 100 1 0 0 0
4 3 18 0 90 1 0 1 0 4 4 18 0 229 0 0 0 0
5 1 18 1 110 1 0 0 1 5 2 18 0 107 1 0 1 0
5 3 18 0 100 1 0 0 0 5 4 18 0 90 1 0 1 0
6 1 19 1 91 1 0 1 1 6 2 19 0 138 1 0 0 0
6 3 19 0 189 0 0 0 0 6 4 19 0 147 1 0 0 0
7 1 19 1 102 0 0 0 0 7 2 19 0 150 0 0 0 0
7 3 19 0 235 1 1 0 0 7 4 19 0 184 1 1 0 0
8 1 19 1 112 1 0 1 0 8 2 19 0 182 0 0 1 0
8 3 19 0 95 0 0 0 0 8 4 19 0 132 0 0 0 0
9 1 20 1 150 1 0 0 0 9 2 20 0 120 0 0 1 0
9 3 20 0 105 1 0 0 0 9 4 20 0 141 0 0 1 1
10 1 20 1 120 1 0 0 0 10 2 20 0 103 0 0 0 0
10 3 20 0 127 0 0 0 0 10 4 20 0 170 1 0 0 0
11 1 20 1 121 1 0 1 1 11 2 20 0 169 0 0 1 1
11 3 20 0 121 1 0 0 0 11 4 20 0 120 0 0 0 0
12 1 21 1 200 0 0 1 0 12 2 21 0 108 1 0 1 0
12 3 21 0 124 0 0 0 0 12 4 21 0 185 1 0 0 0
13 1 21 1 100 0 0 0 1 13 2 21 0 160 0 0 0 0
13 3 21 0 110 1 0 1 0 13 4 21 0 115 0 0 0 0
14 1 22 1 130 1 0 1 1 14 2 22 0 85 1 0 0 0
14 3 22 0 130 1 0 0 0 14 4 22 0 125 0 0 0 0
15 1 22 1 130 1 0 0 0 15 2 22 0 120 0 1 0 0
15 3 22 0 112 1 0 0 1 15 4 22 0 169 0 0 0 0
16 1 23 1 97 0 0 1 0 16 2 23 0 130 0 0 0 0
16 3 23 0 119 0 0 0 0 16 4 23 0 123 0 0 0 0
17 1 23 1 110 1 0 0 1 17 2 23 0 128 0 0 0 0
17 3 23 0 190 0 0 0 0 17 4 23 0 110 0 0 0 0
18 1 24 1 132 0 1 0 0 18 2 24 0 115 0 0 0 0
18 3 24 0 115 0 0 0 0 18 4 24 0 110 0 0 0 0
19 1 24 1 138 0 0 0 0 19 2 24 0 90 1 0 0 1
19 3 24 0 133 0 0 0 0 19 4 24 0 116 0 0 0 0
20 1 25 1 85 0 0 1 0 20 2 25 0 118 1 0 0 0
20 3 25 0 125 0 0 0 0 20 4 25 0 120 0 0 0 0
21 1 25 1 92 1 0 0 0 21 2 25 0 120 0 0 1 0
21 3 25 0 140 0 0 0 0 21 4 25 0 241 0 1 0 0
22 1 25 1 105 0 0 0 1 22 2 25 0 155 0 0 0 0
22 3 25 0 95 1 0 1 1 22 4 25 0 130 0 0 0 0
23 1 26 1 190 1 0 0 0 23 2 26 0 113 1 0 0 0
23 3 26 0 168 1 0 0 0 23 4 26 0 160 0 0 0 0
24 1 28 1 120 1 0 1 1 24 2 28 0 140 0 0 0 0
24 3 28 0 250 1 0 0 0 24 4 28 0 134 0 0 0 0
25 1 28 1 95 1 0 0 0 25 2 28 0 120 1 0 0 0
25 3 28 0 120 0 0 0 0 25 4 28 0 130 0 0 0 0
26 1 29 1 130 0 0 1 0 26 2 29 0 150 0 0 0 0
26 3 29 0 135 0 0 0 0 26 4 29 0 130 1 0 0 0
27 1 30 1 142 1 0 0 1 27 2 30 0 107 0 0 1 1
27 3 30 0 153 0 0 0 0 27 4 30 0 137 0 0 0 0
28 1 31 1 102 1 0 0 1 28 2 31 0 100 0 0 1 0
28 3 31 0 150 1 0 0 0 28 3 41 0 120 0 0 0 0
29 1 32 1 105 1 0 0 0 29 2 32 0 121 0 0 0 0
29 3 32 0 132 0 0 0 0 29 4 32 0 134 1 0 0 1
;
%condlog(strata=str,case=low, variable=smoke ht ui
ptd lwt) ;
__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
|