Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- How do i get a block diagonal covariance matrix, V, in SAS Proc Mixed ...

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

☑ This topic is **solved**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 4 weeks ago
(925 views)

Hi friends,

I am trying to estimate a linear mixed model for treatments arranged in CRD using SAS using proc mixed or proc glimmix. I have 3 categorical factors A, B and C where factor C is assumed random, and A,B are fixed. My data set looks like this:

The syntaxes that I am exploring are:

a) PROC GLIMMIX

```
proc glimmix data=FFRgroup outdesign=XZ;;
class factorA factorB factorC groupA groupB groupC rep;
model yield= groupA | groupB / ddfm=satterthwaite;
random factorC factorA*factorC factorB*factorC factorA*factorB*factorC / V;
lsmeans groupA | groupB / pdiff cl alpha=0.05 ;
Title "FFR Model";
run;
```

whch displays the following V matrix,

b) PROC MIXED:

```
proc mixed data=FFRgroup ;
class factorA factorB factorC groupA groupB groupC rep;
model yield= groupA | groupB / ddfm=satterthwaite;
random factorC factorA*factorC factorB*factorC factorA*factorB*factorC / V;
lsmeans groupA | groupB / pdiff cl alpha=0.05 ;
Title "FFR Model";
run;
```

displays the following V matrix,

What could be the problem with these two approaches not producing the covariance structure that aligns with the model in question (block diagonal)?

Thank you in advance for your assistance folks.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I agree with @Mike_N.

Your first log shows that the final Hessian is not positive definite.

Later, the Log shows that the G matrix is not positive definite.

Your model is likely to be overspecified. You need to take care of your modeling issue first, before attempting to interpret and compare the output.

Simplifying your model, especially your random effects, might be a good place to start.

Thanks,

Jill

12 REPLIES 12

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

If you rewrite your RANDOM statement below --

`random factorC factorA*factorC factorB*factorC factorA*factorB*factorC`

to the one that makes the model to be processed by subjects and is more numerically efficient --

`random int factorA factorB factorA*factorB / subject=factorC v;`

in both procedures, then you would probably see the V option displaying the first block (for the first level of FACTORC) of the variance covariance matrix. Do the two procedures give you the same output for the V matrix?

Also the values in the output you show from PROC MIXED look unusually large to me. What do you see in the Log from PROC MIXED? It might be a good idea to examine the logs from both procedures first.

Thanks,

Jill

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi Jill

Thanks for the response. However, I have run both PROC MIXED and PROC GLIMMIX, but the result hasn't changed. I still get a diagonal matrix with single values, part of which is pasted below:

Kindly clarify on the "Log" issue. I do not understand.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi Mike,

As suggested by Jil, I have used the following code:

proc mixed data=FFRgroup ;

class factorA factorB factorC groupA groupB groupC repA repB repC;

model yield= groupA | groupB / ddfm=satterthwaite;

random int factorA factorB factorA*factorB/subject=factorC v;

lsmeans groupA | groupB / pdiff cl alpha=0.05 ;

Title "FFR Model";

run;

And the results are as follows:

As suggested by Jil, I have used the following code:

proc mixed data=FFRgroup ;

class factorA factorB factorC groupA groupB groupC repA repB repC;

model yield= groupA | groupB / ddfm=satterthwaite;

random int factorA factorB factorA*factorB/subject=factorC v;

lsmeans groupA | groupB / pdiff cl alpha=0.05 ;

Title "FFR Model";

run;

And the results are as follows:

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

V still diagonal though,,,,

Fixed effects look good...

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi Jil & Mike,

I have created another variable "repA" through "repC" to capture the replications in each treatment cell, e.g., in the first cell I recorded "1, 1, 1, 1, 1" for the five replications in each of the rep variables. Then I had to define the "subject = " statement with repC, the random variable. Is this in order? the data set, code and output are as shown below:

proc mixed data=FFRgroup ;

class factorA factorB factorC groupA groupB groupC repA repB repC;

model yield= groupA | groupB / ddfm=satterthwaite;

random int factorA factorB factorA*factorB/subject=repC v;

lsmeans groupA | groupB / pdiff cl alpha=0.05 ;

Title "FFR Model";

run;

Looks like the V matrix is still a diagonal matrix by default in PROC mixed, as highlighted by Mike.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi Mike,

If I put back the original variable names in place of factor A, B and C, the code and output are as follows:

```
proc mixed data=FFRgroup ;
class Treat Depth Incorp repA repB repC;
model yield= Treat | Depth / ddfm=satterthwaite;
random Treat Depth Treat*Depth/subject=Incorp v;
lsmeans Treat | Depth / pdiff cl alpha=0.05 ;
Title "FFR Model";
run;
```

Similar results, but I notice the "G matrix not positive definite" issue. How can I improve these results around this issue, if at all it is another problem?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I don't think I completely understand what you mean by the 'original' variable names - but renaming the variables won't fix this issue, if that is your question. You should not ignore the warning about the G matrix and you should likewise take note of all of the zeros in the covariance parameter estimates table. I still suspect your subject effect is misspecified, but I can't tell exactly how without your data. I would suggest first trying to fit a simpler model, such as a random-intercept model. That is

`random int / subject = Incorp v;`

Once you get that working, start adding in other random factors.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I agree with @Mike_N.

Your first log shows that the final Hessian is not positive definite.

Later, the Log shows that the G matrix is not positive definite.

Your model is likely to be overspecified. You need to take care of your modeling issue first, before attempting to interpret and compare the output.

Simplifying your model, especially your random effects, might be a good place to start.

Thanks,

Jill

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@jiltao @Mike_N Thank you so much for the assistance. I finally got the diagonal V matrix in the other models. I will deal with the issue of the G matrix not positive definite by reducing the number of random levels and replications. I highly appreciate your assistance. The following two codes give the same results that I want:

```
proc glimmix data=RFRgroup outdesign=XZ;;
class Treat Depth Incorp ;
model yield= Depth / ddfm=satterthwaite;
random Treat|Incorp Treat*Depth Depth*Incorp Treat*Depth*Incorp / V ;
lsmeans Depth / pdiff cl alpha=0.05 ;
Title "RFR Model";
run;
```

```
proc mixed data=RFRgroup ;
class Treat Depth Incorp ;
model yield= Depth / ddfm=satterthwaite;
random Treat| Incorp Treat*Depth Depth*Incorp Treat*Depth*Incorp/ v;
lsmeans Depth / pdiff cl alpha=0.05 ;
Title "FFR Model";
run;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

From experience, I think you may not have enough data to be able to distinguish and correctly estimate your RANDOM effects in these models, which would lead to the G matrix issues. Covariance parameter = 0 means you will get the non-positive definite message in the output. So, except in certain regulatory situations, you should simplify the RANDOM statement.

SteveDenham

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.