```Date: Fri, 30 Apr 2004 09:31:06 -0700 Reply-To: Dale McLerran Sender: "SAS(r) Discussion" From: Dale McLerran Subject: Re: Setting up NLMIXED with class variables Comments: To: Gregor Gorjanc In-Reply-To: <20040430084430.GD10093@tori.bfro.uni-lj.si> Content-Type: text/plain; charset=us-ascii Gregor, How are your predictor variables recorded? There is nothing in the code below that informs us on SAS-L as to which variables are class variables, how many levels each class variable has, and whether those class variables are recorded as numeric or character variables. Thus, it is not possible to provide specific advice. However, let me demonstrate with manufactured data how one can construct the appropriate design matrix when you have a class variable. I present a very simple one-way ANOVA model. First, construct some data. We will have class variable A which takes on three levels. The third level will be the reference level. Observe that the class variable is recorded here as a numeric variable taking on values 1, 2, and 3. data test; b0 = 3; do a=1 to 3; if a=1 then a_eff=2; else if a=2 then a_eff=1; else a_eff=0; do i=1 to 25; y = b0 + a_eff + rannor(1234579); output; end; end; keep a y; run; Now, we will fit the one-way ANOVA model in NLMIXED. This requires constructing truth expressions. A truth expression has the form (VAR=val). When the value of VAR equals val, then the truth expression evaluates to 1. Otherwise, the truth expression evaluates to 0. This allows us to construct dummy variables representing levels of the class variable VAR. For the numeric variable A taking on values 1, 2, and 3, the following code will fit the one-way ANOVA model. proc nlmixed data=test; eta = b0 + a1*(a=1) + a2*(a=2); model y ~ normal(eta, var); run; Now, what happens if the class variable is character? Can we still use truth expressions? The following code demonstrates that the NLMIXED procedure does not allow truth expressions constructed with character variables. First, we will construct the class variable B from our numeric variable A. proc format; value a2charb 1 = 'B1' 2 = 'B2' 3 = 'B3'; run; data test; set test; b = put(a, a2charb.); run; proc freq data=test; tables a*b; run; OK, we have our character variable B. Now, let's modify our NLMIXED code so as to construct truth expressions employing the character variable B. proc nlmixed data=test; eta = b0 + b1*(b='B1') + b2*(b='B2'); model y ~ normal(eta, var); run; It doesn't work! Note to the SAS developers of the NLMIXED procedure: allow truth expressions involving character variables! I have examined other approaches to dealing with character variables as class variables in NLMIXED. None work. The only recourse is to employ a datastep prior to execution of the NLMIXED procedure in which you construct the design variables (or use PROC GLMMOD to construct the design matrix). Dale --- Gregor Gorjanc wrote: > Hi! > > Can anyone help me with setting up model in NLMIXED with > class variables. All examples that I have seen so far had > only continious variates. The code I thought might work > (but it did not :() is bellow. > > Any help would be appreciated. > With regards, Gregor > > proc nlmixed data = coal; > > array y[3] y1-y3; /* trait */ > array int[3] int1-int3; /* intercept */ > > array t [3] t1-t3; /* treatment */ > array in[3] in1-in3; /* intensity */ > array p[3] p1-p3; /* position */ > array tin[3] tin1-tin3; /* treatment*intensity */ > array tp[3] tp1-tp3; /* treatment*position */ > array inp[3] inp1-inp3; /* intensity*position */ > array tinp[3] tinp1-tinp3; /* treatment*intensity*position */ > array d[3] d1-d3; /* day of observation */ > > psum = 0; > do i = 1 to 3; > y[i] = int[i] > + t[i]*treatment > + in[i]*intensity > + p[i]*position > + tin[i]*treatment*intensity > + tp[i]*treatment*position > + inp[i]*intensity*position > + tinp[i]*treatment*intensity*position > + d[i]*day; > Psum = Psum + exp(y[i]); > end; > > do i = 1 to 3; > p[i] = exp(y[i]) / (1 + Psum); > if (yvar = i) then z = p[i]; > end; > > if (color_num = 4) then z = 1 - p1 - p2 - p3; > > if (z > 1e-8) then ll = log(z); > else ll = -1e100; > model color_num ~ general(ll); > run; > quit; ===== --------------------------------------- Dale McLerran Fred Hutchinson Cancer Research Center mailto: dmclerra@fhcrc.org Ph: (206) 667-2926 Fax: (206) 667-5977 --------------------------------------- __________________________________ Do you Yahoo!? Win a \$20,000 Career Makeover at Yahoo! HotJobs http://hotjobs.sweepstakes.yahoo.com/careermakeover ```

Back to: Top of message | Previous page | Main SAS-L page