Quantcast

Simple mean trajectory (ordinal variable)

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Simple mean trajectory (ordinal variable)

torvon
Hello.

I have 5 measurement points, my dependent variable is ordinal (0 - 3), and
I want to visualize my data. I'm pretty new to R.
What I want is to find out whether people with different baseline
covariates have different trajectories, so I want a plot with the means
trajectory of my dependent variable (the individual points do not make a
lot of sense in ordinal data) on each measurement point per group, e.g.
females vs. males.

I found different codes, but they don't work well for me. This one looks
promising, though:

> xyplot(phq4 ~ time, data = data, type = 'l',
>       panel=function(...){
>         panel.xyplot(...)
>         panel.loess(...,fun=mean,horizontal=FALSE,col='red',lwd=3)
>       }
>       )

Works and gives me the mean trajectory (I think), but also the individual
trajectories (so I'd like to get rid of them). Also, I would need a way to
build 2 trajectories in 2 graphs ("group=gender" only gives 1 mean
trajectory), + standard deviations or something similar that makes sense as
a measure of variance.

Thanks
-T

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Simple mean trajectory (ordinal variable)

David Winsemius

On Jun 28, 2012, at 1:50 PM, Eiko Fried wrote:

> Hello.
>
> I have 5 measurement points, my dependent variable is ordinal (0 -  
> 3), and
> I want to visualize my data. I'm pretty new to R.
> What I want is to find out whether people with different baseline
> covariates have different trajectories, so I want a plot with the  
> means
> trajectory of my dependent variable (the individual points do not  
> make a
> lot of sense in ordinal data) on each measurement point per group,  
> e.g.
> females vs. males.
>
> I found different codes, but they don't work well for me. This one  
> looks
> promising, though:
>
>> xyplot(phq4 ~ time, data = data, type = 'l',
>>      panel=function(...){
>>        panel.xyplot(...)

If you do not want to plot the points then you should drop the call to  
xyplot(...)

>>        panel.loess(...,fun=mean,horizontal=FALSE,col='red',lwd=3)
>>      }
>>      )
>
> Works and gives me the mean trajectory (I think), but also the  
> individual
> trajectories (so I'd like to get rid of them). Also, I would need a  
> way to
> build 2 trajectories in 2 graphs ("group=gender" only gives 1 mean
> trajectory), + standard deviations or something similar that makes  
> sense as
> a measure of variance.
>
> Thanks
> -T
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Simple mean trajectory (ordinal variable)

Frank Harrell
David - I didn't see a fun= argument to panel.loess
Frank
David Winsemius wrote
On Jun 28, 2012, at 1:50 PM, Eiko Fried wrote:

> Hello.
>
> I have 5 measurement points, my dependent variable is ordinal (0 -  
> 3), and
> I want to visualize my data. I'm pretty new to R.
> What I want is to find out whether people with different baseline
> covariates have different trajectories, so I want a plot with the  
> means
> trajectory of my dependent variable (the individual points do not  
> make a
> lot of sense in ordinal data) on each measurement point per group,  
> e.g.
> females vs. males.
>
> I found different codes, but they don't work well for me. This one  
> looks
> promising, though:
>
>> xyplot(phq4 ~ time, data = data, type = 'l',
>>      panel=function(...){
>>        panel.xyplot(...)

If you do not want to plot the points then you should drop the call to  
xyplot(...)

>>        panel.loess(...,fun=mean,horizontal=FALSE,col='red',lwd=3)
>>      }
>>      )
>
> Works and gives me the mean trajectory (I think), but also the  
> individual
> trajectories (so I'd like to get rid of them). Also, I would need a  
> way to
> build 2 trajectories in 2 graphs ("group=gender" only gives 1 mean
> trajectory), + standard deviations or something similar that makes  
> sense as
> a measure of variance.
>
> Thanks
> -T
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Frank Harrell
Department of Biostatistics, Vanderbilt University
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Simple mean trajectory (ordinal variable)

David Winsemius

On Jun 29, 2012, at 9:29 AM, Frank Harrell wrote:

> David - I didn't see a fun= argument to panel.loess
> Frank

I imagine that argument was just being thrown away. I wasn't paying  
any attention for the request for plotting means ... only addressing  
the request to get rid of the points.

I suppose one could have used panel.xyplot to plot the means, but the  
OP did not include a sample dataset, and I have gotten rather  
selective about what sorts of datasets I will build on the fly when  
posters fail to supply them.

--
David.

>
> David Winsemius wrote
>>
>> On Jun 28, 2012, at 1:50 PM, Eiko Fried wrote:
>>
>>> Hello.
>>>
>>> I have 5 measurement points, my dependent variable is ordinal (0 -
>>> 3), and
>>> I want to visualize my data. I'm pretty new to R.
>>> What I want is to find out whether people with different baseline
>>> covariates have different trajectories, so I want a plot with the
>>> means
>>> trajectory of my dependent variable (the individual points do not
>>> make a
>>> lot of sense in ordinal data) on each measurement point per group,
>>> e.g.
>>> females vs. males.
>>>
>>> I found different codes, but they don't work well for me. This one
>>> looks
>>> promising, though:
>>>
>>>> xyplot(phq4 ~ time, data = data, type = 'l',
>>>>     panel=function(...){
>>>>       panel.xyplot(...)
>>
>> If you do not want to plot the points then you should drop the call  
>> to
>> xyplot(...)
>>
>>>>       panel.loess(...,fun=mean,horizontal=FALSE,col='red',lwd=3)
>>>>     }
>>>>     )
>>>
>>> Works and gives me the mean trajectory (I think), but also the
>>> individual
>>> trajectories (so I'd like to get rid of them). Also, I would need a
>>> way to
>>> build 2 trajectories in 2 graphs ("group=gender" only gives 1 mean
>>> trajectory), + standard deviations or something similar that makes
>>> sense as
>>> a measure of variance.
>>>
>>> Thanks
>>> -T
>>>

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Simple mean trajectory (ordinal variable)

torvon
I'm sorry, but I wasn't aware that I should attach data (and can't, because I must not disclose them).

Thanks for helping me get rid of the individual points, I'm now trying to get standard errors and - more importantly - parallel lines for different values of a variable, e.g. history of depression YES=line1 , NO=line2.

Adding group=variable, in the xyplot argument doesn't have any effect.

Sorry, I really did read through the xyplot document and the help, and googled this problem, but found no solution.

-T


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Simple mean trajectory (ordinal variable)

David Winsemius

On Jun 29, 2012, at 8:48 PM, torvon wrote:

> I'm sorry, but I wasn't aware that I should attach data (and can't,  
> because I
> must not disclose them).

No one said you needed to offer confidential data, only that you  
needed to submit a test data.frame that had the same basic structure.  
You can sibsitute factors that are just letters and numbers that are  
generaterd with rnorm().
>
> Thanks for helping me get rid of the individual points, I'm now  
> trying to
> get standard errors and - more importantly - parallel lines for  
> different
> values of a variable, e.g. history of depression YES=line1 , NO=line2.
>
> Adding group=variable, in the xyplot argument doesn't have any effect.

There are two ways to do grouping: with the group= argument and with  
the bar "|" formula mechanism   .... but again, the expectation is  
that you will provide a sensible test dataset.
>
> Sorry, I really did read through the xyplot document and the help, and
> googled this problem, but found no solution.

The help page for xyplot is long and detailed. Sometimes is is better  
to start with

?Lattice

And don't forget:

?panel.xyplot

--
David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Loading...