Re: [R] cdf in R give probability of random variable

2016-10-21 Thread peter dalgaard

> On 21 Oct 2016, at 20:23 , peter dalgaard  wrote:
> 
> In both cases it works out nicer if you do
> 
> names(px) <- x
> barplot(px)
> 

Um, unless of course you want the cdf as a step function, in which case check 
the help page for plot for possible values of the type= argument.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] cdf in R give probability of random variable

2016-10-21 Thread peter dalgaard
This looks like homework, but doing it in R might not be, so I'll give you the 
benefit of doubt...


> On 21 Oct 2016, at 18:30 , Ragia .  wrote:
> 
> 
> Dear Grooup
> 
> kindly
> 
> how can I plot  these  graphs in R..
> 
> 
> Suppose that X is a discrete random variable with P(X = 0) = .25, P(X = 1) =
> .125, P(X = 2) = .125, and P(X = 3) = .5. Graph the frequency function and
> the cumulative distribution function of X.
> 
> 
> 
> my solution was:
> 
> x=c(0,1,3)
> px=c(.25,.125,.5)
> plot( x,px ,type="h"  ) # to plot the frequency  , is it correct
> 

You forgot X=2 in there (check the sum). 

> how to plot the cdf?
> 

cumsum() is your friend.

In both cases it works out nicer if you do

names(px) <- x
barplot(px)

-pd

>   [[alternative HTML version deleted]]

Notice that plain text posting is strongly preferred in here. HTML messes up 
code badly sometimes.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] cdf in R give probability of random variable

2016-10-21 Thread Ragia .

Dear Grooup

kindly

how can I plot  these  graphs in R..


Suppose that X is a discrete random variable with P(X = 0) = .25, P(X = 1) =
.125, P(X = 2) = .125, and P(X = 3) = .5. Graph the frequency function and
the cumulative distribution function of X.



my solution was:

x=c(0,1,3)
px=c(.25,.125,.5)
plot( x,px ,type="h"  ) # to plot the frequency  , is it correct

 how to plot the cdf?



thanks in advance


Ragia



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] need help in customising function in stat_summary function ggplot2

2016-10-21 Thread Indhira, Anusha
Thanks  mark for pointing out my mistake and suggestion.I can get desired 
output now

-Original Message-
From: Mark Sharp [mailto:msh...@txbiomed.org]
Sent: 20 October 2016 17:21
To: Indhira, Anusha
Cc: r-help@r-project.org
Subject: Re: [R] need help in customising function in stat_summary function 
ggplot2

Indhira,

You have to assign cnt and new value in the loop if you want it to update in 
the loop. However, to count the number of values of x > median(x), there are 
multiple options. You are using a loop where none is needed in R, which has 
many implicit vector functions that run with relational operators and 
assignments.

x <- rnorm(10)
cnt <- sum(ifelse(x > median(x), 1, 0))

Because TRUE evaluates to 1 and FALSE evaluates to 0, you can also use cnt <- 
sum(x > median(x))

I cannot help you with the ggplot question directly since you have not provided 
a definition of the object st_chg_51.

Mark

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center Texas Biomedical Research Institute 
P.O. Box 760549 San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Oct 20, 2016, at 3:25 AM, Indhira, Anusha 
>  wrote:
>
> Hi,
>
> I would like to print percentage of points in a group which are greater than 
> median value in boxplot. I have tried below code but it always prints zero in 
> the graph. Can you let me know, how to modify code to get desired result?
>
>
> perc.greaterthan.median <- function(x){  cnt = 0  for(i in
> 1:length(x)){
>   ifelse(x[i] > median(x),cnt+1,cnt)
>  }
>  return(c(y = median(x)*1.7, label = round((cnt/length(x))*100,2))) }
>
> ggplot(st_chg_51, aes(x=factor(st_dv), P3))+
> #label=rownames(st_chg_51))) +  geom_boxplot(fill = "grey80", colour =
> "#3366FF") +  stat_summary(fun.data = perc.greaterthan.median, geom =
> "text", fun.y = median) +  theme_bw()+theme(axis.text =
> element_text(angle = 90, hjust = 1))
>
> Why does cnt in the function doesn't get incremented in the loop?
>
> Thanks,
> Anusha
>
> This e-mail (including attachments) contains contents owned by Rolls-Royce 
> plc and its subsidiaries, affiliated companies or customers and covered by 
> the laws of England and Wales, Brazil, US, or Canada (federal, state or 
> provincial). The information is intended to be confidential and may be 
> legally privileged. If you are not the intended recipient, you are hereby 
> notified that any retention, dissemination, distribution, interception or 
> copying of this communication is strictly prohibited and may subject you to 
> further legal action. Reply to the sender if you received this email by 
> accident, and then delete the email and any attachments.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:22}}

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] nls.lm

2016-10-21 Thread ProfJCNash
Berend's point is well-taken. It's a lot of work to re-jig a code, especially 
one more than
30 years old.

On the other hand, nlmrt is all-R, and it does more or less work on 
underdetermined systems as I
illustrated in a small script. The changes needed to treat the problem as Mike 
suggests are
pretty easy, but they imply that some aspects of the modeling computations have 
to be omitted.
Mike: If you give that a try, I'd be interested in outcomes, and am willing to 
answer questions
on how the code works.

Indeed, I want to include the sort of "diagnostics" that allow underdetermined 
systems
in my packages, so that some results are replaced with NA or NULL and helpful 
warnings rather
than "Failed m 
>> On 21 Oct 2016, at 06:00, Mike meyer <1101...@gmx.net> wrote:
>>
>> Let's take a different view of the problem.
>> Given f=(f_1,...,f_m):R^n -> R^m we want to minimize ||f(x)||.
>>
>> What distinguishes this from a general minimization problem is that you know 
>> the structure of the
>> objective function F(x)=||f(x)||² and have the individual constituents f_j.
>> Make use of that information as appropriate.
>>
>> This is more general than trying to solve the system f(x)=0 or fitting a 
>> model to data.
>> In this more general setting notions such as underdetermined/overdetermined 
>> system do not apply.
>>
>> The restricted view of model fitting serves only to confuse the issue.
>> For that reason it is (in my view) a bad idea to force the user to set up 
>> his problem in 
>> R-model notation.
>>
> 
> I assume that you have been referring to the R package minpack.lm.
> 
> I've had a look at the underlying Fortran code (from Minpack and developed by 
> More et.al.  made in a distant past) as used by the package.
> That underlying code returns an error when the condition:  number of 
> functions (m)  >=  the number of independent variables (n)
> is not satisfied i.e. when m < n.
> 
> Making that more general would entail a lot of thinking and reworking of the 
> code. As far as I can see it is not possible to just remove the condition 
> m>=n from the underlying Fortran. More (possibly many) changes would be 
> required. Blaming R and/or the package author/maintainer is unfair.
> 
> If you require a more general version of the algorithm or if you want 
> something else you will have to roll your own package/code.
> If you don't feel that minpack.lm is appropriate for your application and you 
> want changes you'll have to discuss matters with Moré 
> (http://www.mcs.anl.gov/~more/) if I got the correct link.
> 
> Berend
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] nls.lm

2016-10-21 Thread Berend Hasselman

> On 21 Oct 2016, at 06:00, Mike meyer <1101...@gmx.net> wrote:
> 
> Let's take a different view of the problem.
> Given f=(f_1,...,f_m):R^n -> R^m we want to minimize ||f(x)||.
> 
> What distinguishes this from a general minimization problem is that you know 
> the structure of the
> objective function F(x)=||f(x)||² and have the individual constituents f_j.
> Make use of that information as appropriate.
> 
> This is more general than trying to solve the system f(x)=0 or fitting a 
> model to data.
> In this more general setting notions such as underdetermined/overdetermined 
> system do not apply.
> 
> The restricted view of model fitting serves only to confuse the issue.
> For that reason it is (in my view) a bad idea to force the user to set up his 
> problem in 
> R-model notation.
> 

I assume that you have been referring to the R package minpack.lm.

I've had a look at the underlying Fortran code (from Minpack and developed by 
More et.al.  made in a distant past) as used by the package.
That underlying code returns an error when the condition:  number of functions 
(m)  >=  the number of independent variables (n)
is not satisfied i.e. when m < n.

Making that more general would entail a lot of thinking and reworking of the 
code. As far as I can see it is not possible to just remove the condition m>=n 
from the underlying Fortran. More (possibly many) changes would be required. 
Blaming R and/or the package author/maintainer is unfair.

If you require a more general version of the algorithm or if you want something 
else you will have to roll your own package/code.
If you don't feel that minpack.lm is appropriate for your application and you 
want changes you'll have to discuss matters with Moré 
(http://www.mcs.anl.gov/~more/) if I got the correct link.

Berend

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] Reg : : How to plot the live streaming graph in R ?

2016-10-21 Thread Ulrik Stervbo
Hi Manu,

I'm by far no expert, but if you use Shiny I believe you can refresh using
'reactiveTimer' and just plot the last n points

HTH
Ulrik

On Fri, 21 Oct 2016 at 08:53 Manohar Reddy  wrote:

> Hi,
>
>
>
>   I have a data which is stored in sql table and in every minute data
> inserting to this table .Now my requirement is I need to plot the live
> streaming  graph as per below link or PFA. Can anyone help out me how to do
> that in R ?
>
>   link : http://www.highcharts.com/studies/live-server.htm
>
>  Thanks in Advance !
>
> ​Note :
>
>   The graph will be keep on moving .​
>
> *Manu.*
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

[R] Reg : : How to plot the live streaming graph in R ?

2016-10-21 Thread Manohar Reddy
Hi,



  I have a data which is stored in sql table and in every minute data
inserting to this table .Now my requirement is I need to plot the live
streaming  graph as per below link or PFA. Can anyone help out me how to do
that in R ?

  link : http://www.highcharts.com/studies/live-server.htm

 Thanks in Advance !

​Note :

  The graph will be keep on moving .​

*Manu.*
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.