[R] Trendline for a subset of data

David Winsemius dwinsemius at comcast.net
Fri Oct 9 19:15:46 CEST 2009


You are emitting weird hex-stuff from your mail client. And from what  
I can tell that is not a reproducible example even if hex-ation  
problem gets fixed. There is a worked example in segments.

On Oct 9, 2009, at 10:45 AM, Steve Murray wrote:

>
> <CB247343-29EC-495A-BA8E-D5A466BABE53 at comcast.net>
> Content-Type: text/plain; charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
> MIME-Version: 1.0
>
>
> Thanks for flagging up the 'segments' command. However=2C I'm having  
> troubl=
> e getting it to work - this is probably due to me misunderstanding  
> the docu=
> mentation for this command.
>
> The plot section of my script appears as follows:
>
> test3 <- 36:45
> plot(data_means=2C type=3D"b"=2C pch=3D4=2C ylab=3D""=2C  
> xlab=3D""=2C xaxt=
> =3D"n"=2C yaxt=3D"n"=2C col=3D3=2C ylim=3Dc(250=2C380))
> abline(lm(data_means[36:45] ~ test3)=2C lty=3D2)
>
>
> As you can see=2C

I cannot "see" anything. If you are under the impression that there  
should have been an attachment, then (re-?)read the Posting Guide on  
that topic.


> I'm only plotting points 36 to 45 from the object 'data_m=
> eans'. This intentionally results in much white space along the x- 
> axis unti=
> l point 36 is reached. However=2C when inserting the trendline=2C  
> this runs=
> along the entire length of the x-axis instead of just through points  
> 36 to=
> 45. Ideally=2C a line which slightly overshoots the data subset  
> would look=
> the best=2C but one constrained to the extents of the 36:45 would  
> also do =
> the job just fine.
>
> So=2C my question is=2C how do I use 'segments' (or otherwise) to  
> create a =
> linear trendline which only extends through points 36:45? (and  
> overshoots a=
> t either end very slightly=2C if possible=2C rather than running  
> along the =
> entire length of the x-axis).

The basic strategy would be to calculate the x and y coordinates of  
the two points at the end of the desired segment and then "say"  
segments( x[1], y[1], x[2], y[2] )

>
> Many thanks again=2C
>
> Steve
>
> ----------------------------------------
>> CC: r-help at r-project.org
>> From: dwinsemius at comcast.net
>> To: smurray444 at hotmail.com
>> Subject: Re: [R] Trendline for a subset of data
>> Date: Fri=2C 9 Oct 2009 09:27:43 -0400
>>
>>
>> On Oct 9=2C 2009=2C at 5:50 AM=2C Steve Murray wrote:
>>
>>>
>>> Dear all=2C
>>>
>>> I am using abline(lm ...) to insert a linear trendline through a
>>> portion of my data (e.g. dataset[=2C36:45]). However=2C I am finding
>>> that whilst the trendline is correctly displayed and representative
>>> of the data portion I've chosen=2C the line continues to run beyond
>>> this data segment and continues until it intersects the vertical
>>> axes at each side of the plot.
>>>
>>> How do I display the line so that it only runs between point 36 and
>>> 45 (as shown in the example above) as doesn't continue to display a
>>> line throughout the rest of the plot space?
>>>
>>
>> ?segments


>>
> 		 	   		  =0A=
> _________________________________________________________________=0A=
> View your other email accounts from your Hotmail inbox. Add them  
> now.=0A=
> http://clk.atdmt.com/UKM/go/167688463/direct/01/=

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list