Writing a R function to compute density function...1/2 - (1-| x |) for | x | <= 1 ?

5 views
Skip to first unread message

Stellium

unread,
Jul 20, 2010, 8:19:44 PM7/20/10
to MadUseR
Hello,

I need to write a R function to compute density function...1/2 - (1-|
x |) for | x | <= 1 ...and then plot it.

I really can't find out how in my 3 R books....

Can anyone show me how to do this?

Peter

Douglas Bates

unread,
Jul 21, 2010, 3:52:48 PM7/21/10
to mad...@googlegroups.com
On Tue, Jul 20, 2010 at 7:19 PM, Stellium <futur...@gmail.com> wrote:
> Hello,

> I need to write a R function to compute density function...1/2 - (1-|
> x |) for | x | <= 1 ...and then plot it.

The way that I read that expression it wouldn't be a density function.
At x == 0 it would have the value -1/2, wouldn't it?

As for creating a plot you could use the curve() function

curve(0.5 - (1-abs(x)), from = -1, to = 1)

Reply all
Reply to author
Forward
0 new messages