I am using Stata 15.1.
This post refers to mixed, margins, lincom, mi estimate and mimrgns (from SSC). I have achieved my aim using mixed, margins & lincom & have now decided to use multiple imputation with one of my variables, my post refers to attempts to do this using mi estimate: & mimrgns (SSC) & possibly lincom.
I use a mixed-effect model with data in long-format. Data example using dataex follows at bottom of post.
Specific pieces of code are pasted thoughout the post but the whole code is pasted at the bottom of the post.
The aim is to model a laboratory test result (variable name: logRSLT) which decreases over time for two arms of a trial (XYstatus, stored as 0 or 1).
logRSLT is collected on up to 3 times on each of two days (maximum total of 6 logRSLT per participant). Each RSLT has a corresponding time (salivatime_hr) as samples were taken at a variety of times, but around 08:00, 12:00 & 16:00.
Therefore, each participant is represented by multiple observations, each observation represents a laboratory result taken at a specific time.
Random effects are specific at the cluster (clusternum), participant (childid) and day (daytext) level.
The mixed-effects model is:
After running this, I use the postestimation command margins to estimate RSLT at time 08:00,12:00 & 16:00 for each of trial arms X&Y and use coeflegend to identify appropriate tags for variables in the subsequent step.
I then use lincom to calculate the ‘area under the curve’ using simple mathematics (trapezoid formula 0.5*base*(a+b)) for each of arms X & Y and give me the difference between these along with a 95%CI & p-value.
This appears to work nicely.
Now I decide I want to multiply impute one of my variables (wakeuphr).
I first impute my data (mi set, mi register, mi impute)
Then add mi estimate: to my mixed: command and change margins to mimrgns
Now I want to use lincom again and type (exactly as previously):
There is no error message, however on typing ereturn list I see that my e(df_min_mi) is 295802954464.1576 with a similarly large e(df_max_mi) and this concerns me. I am also aware that there is concern that this approach is inappropriate in view of the imputed data (e.g https://www.statalist.org/forums/for...estimate-stcox) and according to the help file for mimrgns (SSC)
There are two questions that flow from the way I have structured my question:
But Stata, reasonable, does not understand my tags. Error message is:
Thank you for your time.
Sunil Bhopal
DATA EXAMPLE:
WHOLE CODE WITHOUT IMPUTATION:
WHOLE CODE WITH IMPUTATION:
This post refers to mixed, margins, lincom, mi estimate and mimrgns (from SSC). I have achieved my aim using mixed, margins & lincom & have now decided to use multiple imputation with one of my variables, my post refers to attempts to do this using mi estimate: & mimrgns (SSC) & possibly lincom.
I use a mixed-effect model with data in long-format. Data example using dataex follows at bottom of post.
Specific pieces of code are pasted thoughout the post but the whole code is pasted at the bottom of the post.
The aim is to model a laboratory test result (variable name: logRSLT) which decreases over time for two arms of a trial (XYstatus, stored as 0 or 1).
logRSLT is collected on up to 3 times on each of two days (maximum total of 6 logRSLT per participant). Each RSLT has a corresponding time (salivatime_hr) as samples were taken at a variety of times, but around 08:00, 12:00 & 16:00.
Therefore, each participant is represented by multiple observations, each observation represents a laboratory result taken at a specific time.
Random effects are specific at the cluster (clusternum), participant (childid) and day (daytext) level.
The mixed-effects model is:
Code:
mixed c.logRSLT i.XYstatus##c.salivatime_hr c.wakeuphr || clusternum: || childid: || daytext:, base
Code:
margins, at(XYstatus=(0 1) salivatime_hr=(8 12 16)) vsquish post margins, coeflegend . margins, at(XYstatus=(0 1) salivatime_hr=(8 12 16)) vsquish post Predictive margins Number of obs = 3,962 Expression : Linear prediction, fixed portion, predict() 1._at : XYstatus = 0 salivatime~r = 8 2._at : XYstatus = 0 salivatime~r = 12 3._at : XYstatus = 0 salivatime~r = 16 4._at : XYstatus = 1 salivatime~r = 8 5._at : XYstatus = 1 salivatime~r = 12 6._at : XYstatus = 1 salivatime~r = 16 ------------------------------------------------------------------------------ | Delta-method | Margin Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _at | 1 | -1.896906 .0276162 -68.69 0.000 -1.951033 -1.842779 2 | -1.972262 .0232784 -84.72 0.000 -2.017887 -1.926638 3 | -2.047619 .0278691 -73.47 0.000 -2.102242 -1.992997 4 | -1.9128 .0275298 -69.48 0.000 -1.966758 -1.858843 5 | -1.978063 .0231845 -85.32 0.000 -2.023504 -1.932623 6 | -2.043327 .0277203 -73.71 0.000 -2.097657 -1.988996 ------------------------------------------------------------------------------ . margins, coeflegend > om. Predictive margins Number of obs = 3,962 Expression : Linear prediction, fixed portion, predict() 1._at : XYstatus = 0 salivatime~r = 8 2._at : XYstatus = 0 salivatime~r = 12 3._at : XYstatus = 0 salivatime~r = 16 4._at : XYstatus = 1 salivatime~r = 8 5._at : XYstatus = 1 salivatime~r = 12 6._at : XYstatus = 1 salivatime~r = 16 ------------------------------------------------------------------------------ | Margin Legend -------------+---------------------------------------------------------------- _at | 1 | -1.896906 _b[1bn._at] 2 | -1.972262 _b[2._at] 3 | -2.047619 _b[3._at] 4 | -1.9128 _b[4._at] 5 | -1.978063 _b[5._at] 6 | -2.043327 _b[6._at] ------------------------------------------------------------------------------
Code:
lincom ( 0.5*4*(_b[4._at]+_b[5._at]) + 0.5*4*(_b[5._at]+_b[6._at]) ) - ( 0.5*4*(_b[1bn._at]+_b[2._at]) + 0.5*4*(_b[2._at]+_b[3._at]) ) . lincom ( 0.5*4*(_b[4._at]+_b[5._at]) + 0.5*4*(_b[5._at]+_b[6._at]) ) - ( 0.5*4*(_b[1bn._at]+_b[2._at]) + 0.5*4*(_b[2._at]+_b[3._at]) ) ( 1) - 2*1bn._at - 4*2._at - 2*3._at + 2*4._at + 4*5._at + 2*6._at = 0 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- (1) | -.0464077 .2628844 -0.18 0.860 -.5616517 .4688362 ------------------------------------------------------------------------------
Now I decide I want to multiply impute one of my variables (wakeuphr).
I first impute my data (mi set, mi register, mi impute)
Then add mi estimate: to my mixed: command and change margins to mimrgns
Code:
mi estimate: mixed c.RSLT i.XYstatus##c.salivatime_hr c.wakeuphr || clusternum: || childid: || daytext:, base mimrgns, at(XYstatus=(0 1) salivatime_hr=(8 12 16)) vsquish post mimrgns, coeflegend
Code:
lincom ( 0.5*4*(_b[4._at]+_b[5._at]) + 0.5*4*(_b[5._at]+_b[6._at]) ) - ( 0.5*4*(_b[1bn._at]+_b[2._at]) + 0.5*4*(_b[2._at]+_b[3._at]) ) . lincom ( 0.5*4*(_b[4._at]+_b[5._at]) + 0.5*4*(_b[5._at]+_b[6._at]) ) - ( 0.5*4*(_b[1bn._at]+_b[2._at]) + 0.5*4*(_b[2._at]+_b[3._at]) ) ( 1) - 2*1bn._at - 4*2._at - 2*3._at + 2*4._at + 4*5._at + 2*6._at = 0 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- (1) | -.0144249 .0386819 -0.37 0.709 -.09024 .0613901 ------------------------------------------------------------------------------
There are two questions that flow from the way I have structured my question:
- Could you advise on the validity of using lincom in this circumstance following mimrgns?
- Is there a way to incorporate the desired command into mi estimate? I have tried variations of:
Code:
mi estimate (( 0.5*4*(_b[4._at]+_b[5._at]) + 0.5*4*(_b[5._at]+_b[6._at]) ) - ( 0.5*4*(_b[1bn._at]+_b[2._at]) + 0.5*4*(_b[2._at]+_b[3._at]) )), coeflegend: mixed c.RSLT i.XYstatus##c.salivatime_hr c.wakeuphr || clusternum: || childid: || daytext:, base
incorrectly specified expression (( 0.5*4*(_b[4._at]+_b[5._at]) + 0.5*4*(_b[5._at]+_b[6._at]) ) - ( 0.5*4*(_b[1bn._at]+_b[2._at]) + 0.5*4*(_b[2._at]+_b[3._at]) )):Finally, question 3 is - perhaps you know a much better way of achieving my intended goal. Please do share if so.
[4._at] not found
an error occurred when mi estimate executed nlcom on m=1
Thank you for your time.
Sunil Bhopal
DATA EXAMPLE:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float childid2 byte XYstatus float wakeuphr int clusternum double RSLT float salivatime_hr 1 1 6.5 901 .14225 8.5 1 1 6.5 901 .16973 12.5 1 1 6 901 .16748 9 1 1 6 901 .21777 11.5 2 1 6 901 .16858 8.333333 2 1 6 901 .13563 11.583333 2 1 6 901 .12135 15.666667 2 1 6.5 901 .083026 8.85 2 1 6.5 901 .33422 11.25 2 1 6.5 901 .16747 15.75 end label values XYstatus arms3 label def arms3 1 "arm y", modify
Code:
mi estimate: mixed c.RSLT i.XYstatus##c.salivatime_hr c.wakeuphr || clusternum: || childid: || daytext:, base mimrgns, at(XYstatus=(0 1) salivatime_hr=(8 12 16)) vsquish post mimrgns, coeflegend // I had to do this to get the name tags used by stata to store the resulting mean cortisol volumes (usually starting with _b[…]). Use these tags to run below lincom. lincom ( 0.5*4*(_b[4._at]+_b[5._at]) + 0.5*4*(_b[5._at]+_b[6._at]) ) - ( 0.5*4*(_b[1bn._at]+_b[2._at]) + 0.5*4*(_b[2._at]+_b[3._at]) )
Code:
mi set mlong mi register imputed wakeuphr set seed 14214 //generated using random in excel on 26jan18 at 10am mi impute chained (regress) wakeuphr=day clusternum RSLT salivatime_hr childid2, add(20) mi estimate: mixed c.RSLT i.XYstatus##c.salivatime_hr c.wakeuphr || clusternum: || childid: || daytext:, base mimrgns, at(XYstatus=(0 1) salivatime_hr=(8 12 16)) vsquish post mimrgns, coeflegend // I had to do this to get the name tags used by stata to store the resulting mean cortisol volumes (usually starting with _b[…]). Use these tags to run below lincom. lincom ( 0.5*4*(_b[4._at]+_b[5._at]) + 0.5*4*(_b[5._at]+_b[6._at]) ) - ( 0.5*4*(_b[1bn._at]+_b[2._at]) + 0.5*4*(_b[2._at]+_b[3._at]) )
Comment