Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- Graphics
- /
- Plot mean values by treatment group where time is continuous

Options

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

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

Posted 06-16-2018 06:56 PM
(2843 views)

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

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

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:

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

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

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

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

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

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

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

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;
```

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

@Melk wrote:

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

Paige Miller

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

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

@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

Paige Miller

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

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.

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

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

Paige Miller

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

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

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

Paige Miller

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

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

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

@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

Paige Miller

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

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.

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