BookmarkSubscribeRSS Feed
Melk
Lapis Lazuli | Level 10

I have some longitudinal data and I would like to plot the mean value of y by treatment group across time. My time value is continuous, so it may be 1.2 months 4.8 months and 6.9 months for subject 1, 1.1 months 4.4 months and 7.7 months for subject 2, etc. I am confused on how I can calculate means to use in sgplot series since the times are not all equivalent.

14 REPLIES 14
Reeza
Super User

Can you post some more sample data (as text and in data step) and an example of what type of graph you're looking to create?

 

Can you standardize your times by using a simplistic approach, ie first measure, second measure, third measure? Rather than look at the times as well, I would verify the distance between the times is consistent, ie second measurement is approximately 3 months after first and third is 7 after first month. 

 


@Melk wrote:

I have some longitudinal data and I would like to plot the mean value of y by treatment group across time. My time value is continuous, so it may be 1.2 months 4.8 months and 6.9 months for subject 1, 1.1 months 4.4 months and 7.7 months for subject 2, etc. I am confused on how I can calculate means to use in sgplot series since the times are not all equivalent.


 

Melk
Lapis Lazuli | Level 10

ID         TIME            TX            Y

1           0.34             0              6.9

1           0.78             0              6.4

1           1.17             0              6.6

2           0.25             1              5.9

2           0.74             1              6.2

2           1.50              1             5.3

2           1.94             1              5.1

 

pau13rown
Lapis Lazuli | Level 10

you could see brown and prescott's book which gives sas examples: https://onlinelibrary.wiley.com/doi/book/10.1002/9781118778210

 

consider a random coefficients model, brown and prescott say "random coefficient models can be used whether or not time points are measured at pre-determined intervals. they are often the best choice of model when time intervals and the number of obs vary between patients, ...." etc

 

regarding the plot, how many subjects do you have? you might define some timepoints and windows and for each patient take the value that falls within the specified window for each timepoint

Melk
Lapis Lazuli | Level 10

I have over 200 subjects who came in for assessment at rather random intervals.

Reeza
Super User

As others have mentioned this probably is not statistically valid. 

 

But it's possible. Considering the time point approach:

 

data have;
    input ID TIME TX Y;
    cards;
1           0.34             0              6.9
1           0.78             0              6.4
1           1.17             0              6.6
2           0.25             1              5.9
2           0.74             1              6.2
2           1.50              1             5.3
2           1.94             1              5.1
;
run;

*add counter values;

data have_grouped;
    set have;
    by id;

    if first.id then
        counter=1;
    else
        counter+1;
run;

*Summarize data;

proc means data=have_grouped noprint nway;
    class counter tx;
    var y;
    output out=average mean(y)=avg_y;
run;

*graph per treatment;

proc sgplot data=average;
    series x=counter y=avg_y / group=tx markers;
    xaxis values=(1 to 5 by 1);
    label counter='Counter' avg_y='Average Y' tx="Treatment";
run;

 

PaigeMiller
Diamond | Level 26

@Melk wrote:

I have some longitudinal data and I would like to plot the mean value of y by treatment group across time. My time value is continuous, so it may be 1.2 months 4.8 months and 6.9 months for subject 1, 1.1 months 4.4 months and 7.7 months for subject 2, etc. I am confused on how I can calculate means to use in sgplot series since the times are not all equivalent.


I don't think you want to plot the means by time as you just described, you want to fit a model of some sort that will predict the value of y at each time value.

--
Paige Miller
Melk
Lapis Lazuli | Level 10

I used a random intercept and slope mode in proc mixed. So, would I output the predicted and use that in sgplot?

PaigeMiller
Diamond | Level 26

@Melk, you haven't given us any information on why you are using a random intercept model. Where did that come from? Can you explain?

 

But yes, whenever you have fit a model that you are satisfied with, plot the predicted values at each level of X (in this case months).

--
Paige Miller
Melk
Lapis Lazuli | Level 10

But when I plot the predicted, it still will plot by observation. I just want treatment means across time.

 

random slope intercept model for a randomized control trial with 2 groups measured rate of change of y across time. We hypothesis the rate of change for tx=1 will be less than rate of change for tx=0.

PaigeMiller
Diamond | Level 26

If I am understanding you properly, you have a "fixed" part of a random slope and intercept model, and a "random" part. You use the "fixed" part of the model to obtain the predicted value at each month number. See, for example, slide 7 of this presentation: http://courses.education.illinois.edu/EdPsy587/lectures/RandomSlopes-beamer-online.pdf

--
Paige Miller
Melk
Lapis Lazuli | Level 10

That is correct, but when I use outp= pred it just gives me predicted values for each observation. Is there another way to plot the group means across time when time is continuous ?

PaigeMiller
Diamond | Level 26

As I said, you need to use the "Fixed" part of the model, not the entire model (which is what OUTP is giving you)

--
Paige Miller
Melk
Lapis Lazuli | Level 10

how can i output just the fixed part? I am not sure I know that sas option.

PaigeMiller
Diamond | Level 26

@Melk wrote:

how can i output just the fixed part? I am not sure I know that sas option.


You just fit the fixed part of the model in a different call of the PROC; you don't fit the random intercept and slope part.

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 14 replies
  • 2825 views
  • 15 likes
  • 4 in conversation