[R] Scaling a "density".

David L Carlson dcarlson at tamu.edu
Tue Jun 19 20:31:47 CEST 2012


Is this what you are looking for?

newrec <- rep(recoveries[,1], recoveries[,2])
plot(density(newrec), ylim=c(0, 5))
lines(density(newrec*.67), col="red")
plot(ecdf(newrec), xlim=c(0,1), verticals=TRUE)
lines(ecdf(newrec*.67), verticals=TRUE, col="red")

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Keith Weintraub
> Sent: Tuesday, June 19, 2012 11:00 AM
> To: Bert Gunter
> Cc: r-help at r-project.org
> Subject: Re: [R] Scaling a "density".
> 
> Bert,
>   Thanks for your help and comments.
> 
> My inferior writing skills have failed to elucidate what I thought were
> implicit questions in the following:
> 
>   I would like to plot this:
> 
> > recoveries*matrix(c(.67,1),nrow = 11, ncol = 2, byrow = TRUE)
>        pcts counts
>  [1,] 0.000      0
>  [2,] 0.067      0
>  [3,] 0.134      0
>  [4,] 0.201      0
>  [5,] 0.268      0
>  [6,] 0.335      4
>  [7,] 0.402      0
>  [8,] 0.469      1
>  [9,] 0.536      2
> [10,] 0.603      2
> [11,] 0.670     12
> 
> using densityplot or an equivalent but on the original scale with pcts
> going from 0.0 to 1.0. Can someone give me an example or pointer to
> complete this task?
> 
>   In addition I would like to either "integrate" the density plot or
> come up with a smooth version of the CDF after the 67% contraction. How
> would I go about doing this?
> 
> In regards to your second point we are not looking to draw deep
> inferences, just a reasonable looking graph for a presentation to go
> along with the data table. Some folks just like to see pretty pictures.
> 
> Thanks so much for your time,
> KW
> 
> 
> --
> 
> On Jun 19, 2012, at 11:37 AM, Bert Gunter wrote:
> 
> > 1. You have not asked a question.
> >
> > 2. Your data set is too small to do anything more with it than show
> it in a table as you have done. (IMHO) anything more than that would be
> wild, foolish, unsupportable, and misleading "statisticizing" -- by
> which I mean creating the appearance of having more and more precise
> information than you actually have by employing complex (if possible)
> statistical methods. *
> >
> > -- Bert
> >
> > * A common practice in many scientific fields these days, I admit.
> One would hope that practical arenas like yours would avoid this,
> however.
> >
> >
> >
> > On Tue, Jun 19, 2012 at 8:22 AM, Keith Weintraub <kw1958 at gmail.com>
> wrote:
> > Folks,
> >  I have a small dataset of counts of recoveries on defaulted loans:
> >
> > recoveries<-structure(c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
> 0.9, 1,
> > 0, 0, 0, 0, 0, 4, 0, 1, 2, 2, 12), .Dim = c(11L, 2L), .Dimnames =
> list(
> >    NULL, c("pcts", "counts")))
> >
> > Here is the data in columnar form:
> >      pcts counts
> >  [1,]  0.0      0
> >  [2,]  0.1      0
> >  [3,]  0.2      0
> >  [4,]  0.3      0
> >  [5,]  0.4      0
> >  [6,]  0.5      4
> >  [7,]  0.6      0
> >  [8,]  0.7      1
> >  [9,]  0.8      2
> > [10,]  0.9      2
> > [11,]  1.0     12
> >
> > For example row [6,] means that in our historical sample we saw 50%
> recoveries 4 times.
> >
> > Now I would like to "stress" the recovery distribution by say 67% so
> that the counts would stay the same but the bins (pcts) would contract
> like so:
> >
> > > recoveries*matrix(c(.67,1),nrow = 11, ncol = 2, byrow = TRUE)
> >       pcts counts
> >  [1,] 0.000      0
> >  [2,] 0.067      0
> >  [3,] 0.134      0
> >  [4,] 0.201      0
> >  [5,] 0.268      0
> >  [6,] 0.335      4
> >  [7,] 0.402      0
> >  [8,] 0.469      1
> >  [9,] 0.536      2
> > [10,] 0.603      2
> > [11,] 0.670     12
> >
> > I would like to plot this using densityplot or an equivalent but on
> the original scale from 0.0 to 1.0.
> >
> > In addition I would like to either "integrate" the density plot or
> come up with a smooth version of the CDF after the 67% contraction.
> >
> > I hope this is clear,
> > Thanks for your time,
> > KW
> >
> >
> >
> > --
> >
> >
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org 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.
> >
> >
> >
> > --
> >
> > Bert Gunter
> > Genentech Nonclinical Biostatistics
> >
> > Internal Contact Info:
> > Phone: 467-7374
> > Website:
> > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-
> groups/pdb-biostatistics/pdb-ncb-home.htm
> >
> >
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org 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.



More information about the R-help mailing list