Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: SE erroes for xtmixed-predict fitted


From   Steve Samuels <[email protected]>
To   [email protected]
Subject   Re: st: SE erroes for xtmixed-predict fitted
Date   Fri, 2 Mar 2012 17:00:28 -0500

No, those are the standard error for the fixed portion.

On Mar 2, 2012, at 9:13 AM, Ricardo Ovaldia wrote:

Thank you Steve.

Okay, I understand where you get the 17.312525 and the 7.067 ie:

di sqrt(14.51061^2+9.44276^2)/sqrt(6)
7.0678087

However, is this the SE for "fitted" as you stated in your post? It seems that it is only the SE for the fixed portion. Using the formula from your earlier postt I get:

gen se_fitted=  sqrt(se_fix^2 + se_u1^2 )
8.373251

So which is correct?

Thank you again.

Ricardo Ovaldia, MS
Statistician 
Oklahoma City, OK


--- On Thu, 3/1/12, Steve Samuels <[email protected]> wrote:

> From: Steve Samuels <[email protected]>
> Subject: Re: st: SE erroes for xtmixed-predict fitted
> To: [email protected]
> Date: Thursday, March 1, 2012, 5:44 PM
> Sorry, that was the square root of
> the following SDs in that model.
> 
> 
> ------------------------------------------------------------------------------
>   Random-effects Parameters 
> |   Estimate   Std. Err. 
>    [95% Conf. Interval]
> -----------------------------+------------------------------------------------
> id: Identity             
>    |
>                
>    sd(_cons)
> |   14.51061   4.639392 
>     7.754185     27.1541
> -----------------------------+------------------------------------------------
>                
> sd(Residual) |   
> 9.44276   1.573793     
> 6.811332    13.09079
> ------------------------------------------------------------------------------
> 
> On Mar 1, 2012, at 9:55 AM, Ricardo Ovaldia wrote:
> 
> Thank you Steve.
> I am sorry ti bother you again, but I do not understand how
> you got that the se_fixed was 17.3125 in the "no random
> slope model". Obviously I am doing some thing wrong whe
> calclating the SE_fitted for this simple model. By the way I
> am using Stata 12. Here is what I am doing:
> 
> clear
> input id str1 sex fat1 fat2 fat3 fat4
> 1  M 44.5 7.3 3.4 12.4 16.900
> 2  M 33.0 21.0 23.1 25.4 25.625
> 3  M 19.1 5.0 11.8 22.0 14.475
> 4  F 9.4 4.6 4.6 5.8 6.100
> 5  F 71.3 23.3 25.6 68.2 47.100
> 6  F 51.2 38.0 36.0 52.6 44.450
> end
> 
> reshape long fat ,i(id) j(pill)
> 
> xtmixed fat i.pill ||id:  , nolog
> predict fitted, fitted
> predict se_fix,  stdp
> predict se_u*, reses
> gen se_fitted=  sqrt(se_fix^2 + se_u1^2 )
> drop fitted se_fix se_u*
> tab pill, gen(pill)
> xtmixed fat pill1 pill2 pill3 pill4, nocons || id:, nolog
> predict fitted, fitted
> predict se_fix,  stdp
> predict se_u*, reses
> gen se_fitted2=  sqrt(se_fix^2 + se_u1^2 )
> 
> . sum se_fitted se_fitted2
> 
>    Variable |   
>    Obs        Mean 
>   Std. Dev.       Min 
>       Max
> -------------+--------------------------------------------------------
>   se_fitted |        24 
>   8.373251       
>    0   8.373251   8.373251
> se_fitted2 |        24   
> 8.373251       
>    0   8.373251   8.373251
> 
> 
> 
> Ricardo Ovaldia, MS
> Statistician 
> Oklahoma City, OK
> 
> 
> --- On Wed, 2/29/12, Steve Samuels <[email protected]>
> wrote:
> 
>> From: Steve Samuels <[email protected]>
>> Subject: Re: st: SE erroes for xtmixed-predict fitted
>> To: [email protected]
>> Date: Wednesday, February 29, 2012, 6:29 PM
>> 
>> This is exactly what I wished you'd shown us the first
> time,
>> Ricardo.
>> 
>> To answer your questions:
>> 
>> 1. Constant SEs for no random slope model?  Yes
>> 
>> You have a perfectly balanced data set: four pills with
> six
>> subjects per pill. Therefore the standard errors for
> the
>> fitted values will be identical, because they are based
> on
>> the same SDs and the same number of observations. 
> This
>> is easier to see if you run:
>> 
> ***********************************************************
>> tab pill, gen(pill)
>> xtmixed fat pill1 pill2 pill3 pill4, nocons || id:,
> nolog
>> 
> ***********************************************************
>> 
>> This is an equivalent model and fits the four fixed
> pill
>> means individually.
>> 
>> If you compute se_fitted as before, it will equal 
>> 17.3125, and
>> the constant standard error for the fitted pill means
>> 7.068  is se_fitted/sqrt(6), which you can
> verify.
>> 
>> If, on the other hand, some subjects did not get all
> the
>> pills, then you would expect standard errors for pill
>> effects would differ, because the denominator would
> not
>> always be sqrt(6). You can see this if you delete an
>> observation.
>> 
>> 2. Random "slope" model? 
>> 
>> *************************************
>> xtmixed fat i.pill ||id: pill , nolog
>> *************************************
>> 
>> Here you are off the track. Pill is a categorical
> variable,
>> but the "||id: pill" treats it as a continuous variable
> and
>> fits a slope coefficient.
>> 
>> If "i" indicates id and "j" is the value associated
> with
>> pill j you are fitting a model:
>> 
>> Y_ij = a  + a_j + u_i + b*j +
>> e_ij   where the a_j's are fixed and the
> u
>> and e terms are random
>> 
>> Formally, nothing prevents you from doing this, but it
>> doesn't make sense. Your standard error for even this
> model
>> was incorrect. The standard error for the fitted value
>> should contain a term for b^2*j^2.  A similar
> term
>> appeared in the post that I referred you to. For an
> example
>> of a random slope model, see the pig weight example in
> the
>> Manual.
>> 
>> 
>> Steve
>> [email protected]
>> 
>> On Feb 29, 2012, at 8:32 AM, Ricardo Ovaldia wrote:
>> 
>> Thank you Steve for your help and patience. I am sorry
> that
>> I was not clear with what I needed. What I was
> actually
>> looking for was an -ado- file that would do this
> instead of
>> what you had posted because I was not sure that I was
>> changing  your code correctly to fit my model.
> Again I
>> am sorry, I did not mean to upset you and I really
>> appreciate your help very much.
>> 
>> That said, here is a simple example that I am not sure
> it is
>> correct.
>> There are 6 cats each treated with 4 different pills:
>> 
>> clear
>> input id str1 sex fat1 fat2 fat3 fat4
>> 1  M 44.5 7.3 3.4 12.4 16.900
>> 2  M 33.0 21.0 23.1 25.4 25.625
>> 3  M 19.1 5.0 11.8 22.0 14.475
>> 4  F 9.4 4.6 4.6 5.8 6.100
>> 5  F 71.3 23.3 25.6 68.2 47.100
>> 6  F 51.2 38.0 36.0 52.6 44.450
>> end
>> 
>> reshape long fat ,i(id) j(pill)
>> <output omitted>
>> 
>> xtmixed fat i.pill ||id: , nolog
>> 
>> <output omitted>
>> 
>> . predict fitted, fitted
>> 
>> . predict se_fix,  stdp
>> 
>> . predict se_u*, reses
>> 
>> . gen se_fitted=  sqrt(se_fix^2 + se_u1^2 )
>> 
>> . sum se_fitted
>> 
>>     Variable |   
>>     Obs        Mean 
>>    Std. Dev.   
>    Min 
>>        Max
>> 
> -------------+--------------------------------------------------------
>>    se_fitted |       
> 24 
>>    8.373251   
>    
>>    
> 0   8.373251   8.373251
>> 
>> SE are the same for all observations.
>> 
>> Now for the random slope & intercept model:
>> 
>> . drop fitted se_fix se_u1 se_fitted
>> 
>> . xtmixed fat i.pill ||id: pill , nolog
>> 
>> <output omitted>
>> 
>> . predict fitted, fitted
>> 
>> . predict se_fix,  stdp
>> 
>> . predict se_u*, reses
>> 
>> . gen se_fitted=  sqrt(se_fix^2 + se_u1^2 +
> se_u2^2)
>> 
>> . sum se_fitted
>> 
>>     Variable |   
>>     Obs        Mean 
>>    Std. Dev.   
>    Min 
>>        Max
>> 
> -------------+--------------------------------------------------------
>>    se_fitted |       
> 24 
>>    8.655818   
>> 
> .0559801   8.592957   8.737734
>> 
>> Did I modify your code correctly?
>> 
>> Thank you again,
>> Ricardo
>> 
>> Ricardo Ovaldia, MS
>> Statistician
>> Oklahoma City, OK
>> 
>> --- On Tue, 2/28/12, Steve Samuels <[email protected]>
>> wrote:
>> 
>> From: Steve Samuels <[email protected]>
>> Subject: Re: st: SE erroes for xtmixed-predict fitted
>> To: [email protected]
>> Date: Tuesday, February 28, 2012, 8:06 PM
>> 
>> I don't know what you are looking at, but yes,I would
>> expect
>> the same or near identical  standard errors under
> many
>> circumstances.
>> 
>> When you averaged, you are  ignoring the fact
> that
>> Stata's linear predictors are "best". I don't see show
> you
>> thought you could improve upon them. I suggest that
> you
>> look
>> at a book on longitudinal data. Three good ones are:
>> 
>> Diggle, Heagerty, Liang and Zeger, Anal of Long data
> 2nd Ed
>> Verbeke and Molenbergs Linear mixed models for
>> longitudinal analysis
>> Fitzmaurice, Laird,Ware, Applied Longitudinal Data
>> 
>> but there are many others.
>> 
>> Finally, please follow the FAQ in the future and show
>> exactly what you did and what Stata replied.  It
> is
>> quite irritating to be told that you had searched and
> found
>> no answer to your question, when, apparently you had
> found
>> an answer, but just didn't like what it showed.
>> 
>> Steve
>> [email protected]
>> 
>> On Feb 28, 2012, at 7:46 PM, Ricardo Ovaldia wrote:
>> 
>> Thank you Steve.
>> 
>> I did see Steve's post, however when I tried doing
> this, I
>> got the same SE for every patient when I leave out the
>> random slope term i.e.:
>> 
>> xtmixed cholest i.drug month || patid
>> 
>> So I was not sure that it was working correctly. When
> I
>> included the random slope term, I get slightly
> different
>> values for each patient but still very similar to each
>> other. Is that what I should expect?
>> 
>> Ricardo
>> 
>> Ricardo Ovaldia, MS
>> Statistician
>> Oklahoma City, OK
>> 
>> --- On Tue, 2/28/12, Steve Samuels <[email protected]>
>> wrote:
>> 
>> From: Steve Samuels <[email protected]>
>> Subject: Re: st: SE erroes for xtmixed-predict fitted
>> To: [email protected]
>> Cc: [email protected]
>> Date: Tuesday, February 28, 2012, 4:37 PM
>> You must have missed http://www.stata.com/statalist/archive/2011-12/msg00852.html
>> 
>> where I tried to answer a related questionn. I'm not
>> sure
>> I'm right. If I'm not, I bet that Bobby Gutierrez
>> knows.
>> 
>> Steve
>> [email protected]
>> 
>> On Feb 28, 2012, at 3:50 PM, Ricardo Ovaldia wrote:
>> 
>> I searched the Statalist archives for the answer to
>> the
>> following query and could not find one. Can someone
>> please
>> help.
>> 
>> After using -xtmixed- to fit:
>> 
>> xtmixed cholest i.drug month || patid:month
>> 
>> I used -predict, fitted- to get predicted estimates
>> that
>> account for both the fixed and random effects.
>> I them average these over drug and month to get mean
>> predicted cholesterol values for each drug at each
>> time
>> point.
>> Is there a way to place a CI or to calculate SE for
>> these
>> estimates?
>> 
>> Thank you,
>> Ricardo.
>> 
>> 
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
>> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index