Re: [R] finding components of an API

2017-05-28 Thread Spencer Graves



On 2017-05-28 8:16 PM, Erin Hodgess wrote:

I have actually just figured it out with some help from a JS website . Was 
going to post the solution but maybe I shouldn't ?



  Have you considered contacting them and asking at 
"https://spotcrime.com/contact.php;?



  The web site does not contain copyright information that I can 
find.  Their "Terms of Use" (https://spotcrime.com/tos) says, "You will 
not ... distribute any files ... where it is possible that ... any of 
the Website may be used to distribute copyrighted materials to or from 
persons who are not authorized to receive, copy, distribute or use 
them."  I suggest you contact them.  Explain this could make it easier 
for people to use their data and promote their web site.



  The "Ecfun" package contains various "read*" functions that 
scrape data from different web sites. If spotcrime.com says it's OK to 
access their web site as you have AND you'd like to add a function to do 
this to the "Ecfun" package, please go to R-Forge, find the "Ecdat" 
project, and "request to join"  I will approve.



  Spencer Graves


Sent from my iPhone


On May 28, 2017, at 7:51 PM, Robert Sherry  wrote:

Erin,

I do not think there is an R package that will enable you to get the data you 
would like from spotcrime.com.

You could write code, in R, or some other language, to extract the data you 
want but that is going to be a changeling  task and if
the website changes its format then your code may suddenly stop working. Also, 
the people who run spotcrime.com may not be happy if you do so.

Bob


On 5/28/2017 4:45 PM, Erin Hodgess wrote:
Sorry!!!

It's spotcrime.com, and I would like to use it via R for crimes.



On Sun, May 28, 2017 at 2:19 PM, Jeff Newmiller 
wrote:


Can you please be just a little less vague? What API are you talking
about, and how is this related to R?
--
Sent from my phone. Please excuse my brevity.

On May 28, 2017 11:48:42 AM PDT, Erin Hodgess 
wrote:

Hello!

I would like to use a particular API for crimes (spot crimes) but I
can't
find what components go into the API.  I have gone into the website,but
to
no avail

Has anyone used it please?

Thank you,
Sincerely,
Erin



__
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-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-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] finding components of an API

2017-05-28 Thread Erin Hodgess
I have actually just figured it out with some help from a JS website . Was 
going to post the solution but maybe I shouldn't ? 


Sent from my iPhone

> On May 28, 2017, at 7:51 PM, Robert Sherry  wrote:
> 
> Erin,
> 
> I do not think there is an R package that will enable you to get the data you 
> would like from spotcrime.com.
> 
> You could write code, in R, or some other language, to extract the data you 
> want but that is going to be a changeling  task and if
> the website changes its format then your code may suddenly stop working. 
> Also, the people who run spotcrime.com may not be happy if you do so.
> 
> Bob
> 
>> On 5/28/2017 4:45 PM, Erin Hodgess wrote:
>> Sorry!!!
>> 
>> It's spotcrime.com, and I would like to use it via R for crimes.
>> 
>> 
>> 
>> On Sun, May 28, 2017 at 2:19 PM, Jeff Newmiller 
>> wrote:
>> 
>>> Can you please be just a little less vague? What API are you talking
>>> about, and how is this related to R?
>>> --
>>> Sent from my phone. Please excuse my brevity.
>>> 
>>> On May 28, 2017 11:48:42 AM PDT, Erin Hodgess 
>>> wrote:
 Hello!
 
 I would like to use a particular API for crimes (spot crimes) but I
 can't
 find what components go into the API.  I have gone into the website,but
 to
 no avail
 
 Has anyone used it please?
 
 Thank you,
 Sincerely,
 Erin
>> 
>> 
> 
> __
> 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-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] finding components of an API

2017-05-28 Thread Robert Sherry

Erin,

I do not think there is an R package that will enable you to get the 
data you would like from spotcrime.com.


You could write code, in R, or some other language, to extract the data 
you want but that is going to be a changeling  task and if
the website changes its format then your code may suddenly stop working. 
Also, the people who run spotcrime.com may not be happy if you do so.


Bob

On 5/28/2017 4:45 PM, Erin Hodgess wrote:

Sorry!!!

It's spotcrime.com, and I would like to use it via R for crimes.



On Sun, May 28, 2017 at 2:19 PM, Jeff Newmiller 
wrote:


Can you please be just a little less vague? What API are you talking
about, and how is this related to R?
--
Sent from my phone. Please excuse my brevity.

On May 28, 2017 11:48:42 AM PDT, Erin Hodgess 
wrote:

Hello!

I would like to use a particular API for crimes (spot crimes) but I
can't
find what components go into the API.  I have gone into the website,but
to
no avail

Has anyone used it please?

Thank you,
Sincerely,
Erin





__
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] Spacing Between Elements in Lattice Legend

2017-05-28 Thread Bert Gunter
1. Always cc the list, which I have done here (unless you want to say
something that truly should be private).

2. Ahh... I see. I don't believe you can do it using auto.key, which
feeds it's list to the simpleKey() function: the price you pay for
keeping it simple is that you lack fine control over details such as
the rectangle height, which is (I believe) what you want. If you
replace the auto.key=  list via the following key= list, I think you
get what you want by controlling rectangle height to your taste: e.g.

key =   list(title = "Year",
   text = list(c("2015","2016")),
   rectangles = list(height=.5,
   col= c("blue","red")),
   columns=1,space="right",padding.text=3)


If this is *NOT* what you want, do cc the list in any reply.


Oh, and incidentally, your code mistakenly had the "main" argument replicated.


Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, May 28, 2017 at 1:06 PM, Lorenzo Isella
 wrote:
> Thanks for the suggestion, but it is not what I want.
> I do not want to have a separation of the rectangles in the main plot,
> but only in the legend generated by my example.
> Any idea about how to achieve that?
>
> Lorenzo
>
>
> On Sun, May 28, 2017 at 09:41:10AM -0700, Bert Gunter wrote:
>>
>> See the "border" and "lwd" arguments in ?panel.barchart (checking the
>> panel function help for your display is always a good idea for such
>> questions).
>>
>> Adding:
>>
>> border = "lightgray", lwd=1,
>>
>> to your call would seem to give what you want. (modify appropriately
>> to meet your aesthetic preferences).
>>
>> Cheers,
>> Bert
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming along
>> and sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>> On Sun, May 28, 2017 at 8:26 AM, Lorenzo Isella
>>  wrote:
>>>
>>> Dear All,
>>> Please consider the short code at the end of the email.
>>> It generates a barchart where everything is as I want, apart from some
>>> minor tuning of the legend.
>>> I can control the spacing between the text in the two rows of the
>>> legend, but how do I force some separation between the red and the
>>> blue rectangles in the legend?
>>> Any suggestion is welcome.
>>> Cheers
>>>
>>> Lorenzo
>>>
>>> ###
>>>
>>> library(lattice)
>>> library(latticeExtra)
>>>
>>>
>>> df_tot<-structure(list(country = structure(c(13L, 1L, 3L, 21L, 12L, 6L,
>>> 22L, 14L, 19L, 20L, 4L, 16L, 9L, 11L, 18L, 17L, 7L, 8L, 2L, 15L,
>>> 10L, 5L, 13L, 1L, 23L, 21L, 12L, 6L, 22L, 14L, 19L, 20L, 4L,
>>> 16L, 9L, 11L, 24L, 18L, 25L, 28L, 26L, 17L, 7L, 8L, 2L, 27L,
>>> 15L, 10L), .Label = c("BE", "PT", "CZ", "EL", "TR", "EE", "NO",
>>> "PL", "IE", "SI", "IL", "DK", "AT", "FI", "SE", "HU", "NL", "IT",
>>> "FR", "UK", "DE", "ES", "CY", "IS", "LT", "MT", "RS", "LV"), class =
>>> "factor"),
>>>number = c(12L, 1L, 2L, 42L, 11L, 4L, 78L, 12L, 35L, 41L,
>>>2L, 21L, 8L, 9L, 25L, 24L, 4L, 4L, 1L, 12L, 8L, 3L, 5L, 1L,
>>> 1L, 32L, 16L, 3L, 75L, 20L, 16L, 29L, 3L, 9L, 10L, 5L, 1L,
>>> 33L, 1L, 2L, 1L, 6L, 7L, 2L, 3L, 1L, 11L, 3L), year =
>>> c(2015,
>>> 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015,
>>> 2015, 2015,
>>> 2015, 2015, 2015, 2015, 2015, 2015, 2015,
>>> 2015, 2015, 2015,
>>> 2015, 2016, 2016, 2016, 2016, 2016, 2016,
>>> 2016, 2016, 2016,
>>> 2016, 2016, 2016, 2016, 2016, 2016,
>>> 2016, 2016, 2016, 2016,
>>> 2016, 2016, 2016, 2016, 2016,
>>> 2016, 2016)), .Names =
>>> c("country",
>>> "number", "year"), row.names =
>>> c(NA, -48L), class = "data.frame")
>>>
>>>
>>> p1 <- barchart(number ~ country ,
>>>  groups= as.factor(year),
>>>  data = df_tot## ,
>>> , origin=0, spect="fill",
>>>
>>> par.settings = c(ggplot2like(col=c("blue", "red"))),
>>> axis = axis.grid, xlab=list("Number of
>>> Beneficiaries", cex=1.2),
>>> ylab=list("Country", cex=1.2),##
>>> main=NULL,
>>>main=list(NULL),between =
>>> list(x = 1),
>>>   scales=list(cex=1), 

Re: [R] finding components of an API

2017-05-28 Thread Erin Hodgess
Sorry!!!

It's spotcrime.com, and I would like to use it via R for crimes.



On Sun, May 28, 2017 at 2:19 PM, Jeff Newmiller 
wrote:

> Can you please be just a little less vague? What API are you talking
> about, and how is this related to R?
> --
> Sent from my phone. Please excuse my brevity.
>
> On May 28, 2017 11:48:42 AM PDT, Erin Hodgess 
> wrote:
> >Hello!
> >
> >I would like to use a particular API for crimes (spot crimes) but I
> >can't
> >find what components go into the API.  I have gone into the website,but
> >to
> >no avail
> >
> >Has anyone used it please?
> >
> >Thank you,
> >Sincerely,
> >Erin
>



-- 
Erin Hodgess
Associate Professor
Department of Mathematical and Statistics
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

[[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] finding components of an API

2017-05-28 Thread Jeff Newmiller
Can you please be just a little less vague? What API are you talking about, and 
how is this related to R?
-- 
Sent from my phone. Please excuse my brevity.

On May 28, 2017 11:48:42 AM PDT, Erin Hodgess  wrote:
>Hello!
>
>I would like to use a particular API for crimes (spot crimes) but I
>can't
>find what components go into the API.  I have gone into the website,but
>to
>no avail
>
>Has anyone used it please?
>
>Thank you,
>Sincerely,
>Erin

__
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] finding components of an API

2017-05-28 Thread Erin Hodgess
Hello!

I would like to use a particular API for crimes (spot crimes) but I can't
find what components go into the API.  I have gone into the website,but to
no avail

Has anyone used it please?

Thank you,
Sincerely,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Mathematical and Statistics
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

[[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] Problem with Example with Lattice

2017-05-28 Thread Gerrit Draisma

Hallo Lorenzo,
In addition to Berts advice
try
> trellis.par.get("superpose.symbol")
which shows the default for superposed graphics
and set them with the par.settings parameter
> dotplot(VADeaths, type = "o",
+ auto.key = list(lines = TRUE, space = "right"),
+ main = "Death Rates in Virginia - 1940",
+ par.settings=list(superpose.symbol=list(pch=1:4)),
+ xlab = "Rate (per 1000)")

Gerrit

On 05/28/2017 12:00 PM, r-help-requ...@r-project.org wrote:

Re: Problem with Example with Lattice


__
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] rollapply() produces NAs

2017-05-28 Thread Jeff Newmiller
You will get better help if you read the Posting Guide mentioned at the foot if 
every posting including this one carefully and pay attention. 

A) You need to post in plain text, as your code came through the mailing list 
damaged.

B) You need to include sample data and make your code run from a clean R 
environment. See [1][2][3].

C) You need to make sure your function returns sensible results for short input 
vectors or input vectors with NA in them, as rollapply/embed need to be told 
how to handle the beginning/end of the series. 

[1] 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

[2] http://adv-r.had.co.nz/Reproducibility.html

[3] https://cran.r-project.org/web/packages/reprex/index.html
-- 
Sent from my phone. Please excuse my brevity.

On May 28, 2017 7:58:59 AM PDT, Sepp via R-help  wrote:
>This is exactly what I want. However, with my function it produces a
>vector of NAs ...
>
>
>Gabor Grothendieck  schrieb am 16:23 Sonntag,
>28.Mai 2017:
>
>
>
>Maybe you want this.It computes VaRfun(r[c(i-500, i-1)] for each i for
>which the argument to r makes sense.
>
>rollapply(r, width = list(c(-500, -1)), FUN = VaRfun),
>
>
>On Sat, May 27, 2017 at 5:29 PM, Sepp via R-help 
>wrote:
>> Hello,
>> I am fairly new to R and trying to calculate value at risk with
>exponentially decreasing weights.My function works for a single vector
>of returns but does not work with rollapply(), which is what I want to
>use. The function I am working on should assig exponentially decreasing
>weights to the K most recent returns and then order the returns in an
>ascending order. Subsequently it should pick the last return for which
>the cumulative sum of the weights is smaller or equal to a significance
>level. Thus, I am trying to construct a cumulative distribution
>function and find a quantile.
>> This is the function I wrote:
>> VaRfun <- function(x, lambda = 0.94) {
>> #create data.frame and order returns such that the lates return is
>the first  df <- data.frame(weight = c(1:length(x)), return = rev(x)) 
>K <- nrow(df)  constant <- (1-lambda)/(1-lambda^(K))#assign weights to
>the returnsfor(i in 1:nrow(df)) {df$weight[i] <- lambda^(i-1) *
>constant}#order returns in an ascending order  df <-
>df[order(df$return),]
>> #add the cumulative sum of the weights  df$cum.weight <-
>cumsum(df$weight)
>> #calculate value at risk  VaR <- -tail((df$return[df$cum.weight <=
>.05]), 1)  signif(VaR, digits = 3)}
>> It works for a single vector of returns but if I try to use it with
>rollapply(), such as
>> rollapply(r, width = list(-500, -1), FUN = VaRfun),
>> it outputs a vector of NAs and I don't know why.
>> Thank you for your help!
>> [[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-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] Fwd: Spacing Between Elements in Lattice Legend

2017-05-28 Thread Bert Gunter
(forgot to cc the list!)

-- Bert



-- Forwarded message --
From: Bert Gunter 
Date: Sun, May 28, 2017 at 9:41 AM
Subject: Re: [R] Spacing Between Elements in Lattice Legend
To: Lorenzo Isella 


See the "border" and "lwd" arguments in ?panel.barchart (checking the
panel function help for your display is always a good idea for such
questions).

Adding:

border = "lightgray", lwd=1,

to your call would seem to give what you want. (modify appropriately
to meet your aesthetic preferences).

Cheers,
Bert
Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, May 28, 2017 at 8:26 AM, Lorenzo Isella
 wrote:
> Dear All,
> Please consider the short code at the end of the email.
> It generates a barchart where everything is as I want, apart from some
> minor tuning of the legend.
> I can control the spacing between the text in the two rows of the
> legend, but how do I force some separation between the red and the
> blue rectangles in the legend?
> Any suggestion is welcome.
> Cheers
>
> Lorenzo
>
> ###
>
> library(lattice)
> library(latticeExtra)
>
>
> df_tot<-structure(list(country = structure(c(13L, 1L, 3L, 21L, 12L, 6L,
> 22L, 14L, 19L, 20L, 4L, 16L, 9L, 11L, 18L, 17L, 7L, 8L, 2L, 15L,
> 10L, 5L, 13L, 1L, 23L, 21L, 12L, 6L, 22L, 14L, 19L, 20L, 4L,
> 16L, 9L, 11L, 24L, 18L, 25L, 28L, 26L, 17L, 7L, 8L, 2L, 27L,
> 15L, 10L), .Label = c("BE", "PT", "CZ", "EL", "TR", "EE", "NO",
> "PL", "IE", "SI", "IL", "DK", "AT", "FI", "SE", "HU", "NL", "IT",
> "FR", "UK", "DE", "ES", "CY", "IS", "LT", "MT", "RS", "LV"), class =
> "factor"),
>number = c(12L, 1L, 2L, 42L, 11L, 4L, 78L, 12L, 35L, 41L,
>2L, 21L, 8L, 9L, 25L, 24L, 4L, 4L, 1L, 12L, 8L, 3L, 5L, 1L,
> 1L, 32L, 16L, 3L, 75L, 20L, 16L, 29L, 3L, 9L, 10L, 5L, 1L,
> 33L, 1L, 2L, 1L, 6L, 7L, 2L, 3L, 1L, 11L, 3L), year =
> c(2015,
> 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015,
> 2015, 2015,
> 2015, 2015, 2015, 2015, 2015, 2015, 2015,
> 2015, 2015, 2015,
> 2015, 2016, 2016, 2016, 2016, 2016, 2016,
> 2016, 2016, 2016,
> 2016, 2016, 2016, 2016, 2016, 2016,
> 2016, 2016, 2016, 2016,
> 2016, 2016, 2016, 2016, 2016,
> 2016, 2016)), .Names =
> c("country",
> "number", "year"), row.names =
> c(NA, -48L), class = "data.frame")
>
>
> p1 <- barchart(number ~ country ,
>  groups= as.factor(year),
>  data = df_tot## ,
> , origin=0, spect="fill",
>
> par.settings = c(ggplot2like(col=c("blue", "red"))),
> axis = axis.grid, xlab=list("Number of
> Beneficiaries", cex=1.2),
> ylab=list("Country", cex=1.2),##
> main=NULL,
>main=list(NULL),between =
> list(x = 1),
>   scales=list(cex=1), auto.key =
> list(title = "Year",
> columns=1,space="right",padding.text=3)
>)
>pdf("beneficiaries_all2.pdf",
> width=15, height=5)
> print(p1)
> dev.off()
>
> __
> 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-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] get the value of a biplane

2017-05-28 Thread Rui Barradas

Hello,

Since function splines::bs returns an object of class bs in order to 
read the help page for function predict you need


?predict.bs

The syntax would be

## S3 method for class 'bs'
predict(object, newx, ...)

Please read that help page and maybe you'll get the answer you need.

Hope this helps,

Rui Barradas

Em 28-05-2017 15:51, Glenn Schultz escreveu:

If is specify a spline basis as follows

knots <- c(6, 12, 22, 30, 35)
x <- c(0.0, .25, 1.0, 2.0, 3.0)
SCurve <- bs(x = x, knots = knots, intercept = FALSE, Boundary.knots =
c(0,3.5))

I would like to now get the spline value for new values of x.  However,
when I use predict the new basis is returned and I would like to get the
value.  Nothing has worked so far and ?predict plus examples only show
prediction from linear models.  Is there a way to extract the value from
a defined spline?

Best Regards,
Glenn
__
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-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] rollapply() produces NAs

2017-05-28 Thread Sepp via R-help
This is exactly what I want. However, with my function it produces a vector of 
NAs ...


Gabor Grothendieck  schrieb am 16:23 Sonntag, 28.Mai 
2017:



Maybe you want this.It computes VaRfun(r[c(i-500, i-1)] for each i for
which the argument to r makes sense.

rollapply(r, width = list(c(-500, -1)), FUN = VaRfun),


On Sat, May 27, 2017 at 5:29 PM, Sepp via R-help  wrote:
> Hello,
> I am fairly new to R and trying to calculate value at risk with exponentially 
> decreasing weights.My function works for a single vector of returns but does 
> not work with rollapply(), which is what I want to use. The function I am 
> working on should assig exponentially decreasing weights to the K most recent 
> returns and then order the returns in an ascending order. Subsequently it 
> should pick the last return for which the cumulative sum of the weights is 
> smaller or equal to a significance level. Thus, I am trying to construct a 
> cumulative distribution function and find a quantile.
> This is the function I wrote:
> VaRfun <- function(x, lambda = 0.94) {
> #create data.frame and order returns such that the lates return is the first  
> df <- data.frame(weight = c(1:length(x)), return = rev(x))  K <- nrow(df)  
> constant <- (1-lambda)/(1-lambda^(K))#assign weights to the returnsfor(i 
> in 1:nrow(df)) {df$weight[i] <- lambda^(i-1) * constant}#order 
> returns in an ascending order  df <- df[order(df$return),]
> #add the cumulative sum of the weights  df$cum.weight <- cumsum(df$weight)
> #calculate value at risk  VaR <- -tail((df$return[df$cum.weight <= .05]), 1)  
> signif(VaR, digits = 3)}
> It works for a single vector of returns but if I try to use it with 
> rollapply(), such as
> rollapply(r, width = list(-500, -1), FUN = VaRfun),
> it outputs a vector of NAs and I don't know why.
> Thank you for your help!
> [[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.



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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] get the value of a biplane

2017-05-28 Thread Glenn Schultz

If is specify a spline basis as follows

knots <- c(6, 12, 22, 30, 35)
x <- c(0.0, .25, 1.0, 2.0, 3.0)
SCurve <- bs(x = x, knots = knots, intercept = FALSE, Boundary.knots = c(0,3.5))

I would like to now get the spline value for new values of x.  However, when I 
use predict the new basis is returned and I would like to get the value.  
Nothing has worked so far and ?predict plus examples only show prediction from 
linear models.  Is there a way to extract the value from a defined spline?

Best Regards,
Glenn
__
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] Spacing Between Elements in Lattice Legend

2017-05-28 Thread Lorenzo Isella

Dear All,
Please consider the short code at the end of the email.
It generates a barchart where everything is as I want, apart from some
minor tuning of the legend.
I can control the spacing between the text in the two rows of the
legend, but how do I force some separation between the red and the
blue rectangles in the legend?
Any suggestion is welcome.
Cheers

Lorenzo

###

library(lattice)
library(latticeExtra)


df_tot<-structure(list(country = structure(c(13L, 1L, 3L, 21L, 12L, 6L,
22L, 14L, 19L, 20L, 4L, 16L, 9L, 11L, 18L, 17L, 7L, 8L, 2L, 15L,
10L, 5L, 13L, 1L, 23L, 21L, 12L, 6L, 22L, 14L, 19L, 20L, 4L,
16L, 9L, 11L, 24L, 18L, 25L, 28L, 26L, 17L, 7L, 8L, 2L, 27L,
15L, 10L), .Label = c("BE", "PT", "CZ", "EL", "TR", "EE", "NO",
"PL", "IE", "SI", "IL", "DK", "AT", "FI", "SE", "HU", "NL", "IT",
"FR", "UK", "DE", "ES", "CY", "IS", "LT", "MT", "RS", "LV"), class =
"factor"),
   number = c(12L, 1L, 2L, 42L, 11L, 4L, 78L, 12L, 35L, 41L,
   2L, 21L, 8L, 9L, 25L, 24L, 4L, 4L, 1L, 12L, 8L, 3L, 5L, 1L,
1L, 32L, 16L, 3L, 75L, 20L, 16L, 29L, 3L, 9L, 10L, 5L, 1L,
33L, 1L, 2L, 1L, 6L, 7L, 2L, 3L, 1L, 11L, 3L), year =
c(2015,
2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015,
2015, 2015,
2015, 2015, 2015, 2015, 2015, 2015, 2015,
2015, 2015, 2015,
2015, 2016, 2016, 2016, 2016, 2016, 2016,
2016, 2016, 2016,
2016, 2016, 2016, 2016, 2016, 2016,
2016, 2016, 2016, 2016,
2016, 2016, 2016, 2016, 2016,
2016, 2016)), .Names =
c("country",
"number", "year"), row.names =
c(NA, -48L), class = "data.frame")




p1 <- barchart(number ~ country ,
 groups= as.factor(year),
 data = df_tot## ,
, origin=0, spect="fill",

par.settings = c(ggplot2like(col=c("blue", "red"))),
axis = axis.grid, xlab=list("Number of
Beneficiaries", cex=1.2),
ylab=list("Country", cex=1.2),##
main=NULL,
   main=list(NULL),between =
list(x = 1),
  scales=list(cex=1), auto.key =
list(title = "Year",
columns=1,space="right",padding.text=3)
   )
   pdf("beneficiaries_all2.pdf",
width=15, height=5)
print(p1)
dev.off()

__
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] rollapply() produces NAs

2017-05-28 Thread Gabor Grothendieck
Maybe you want this.It computes VaRfun(r[c(i-500, i-1)] for each i for
which the argument to r makes sense.

rollapply(r, width = list(c(-500, -1)), FUN = VaRfun),

On Sat, May 27, 2017 at 5:29 PM, Sepp via R-help  wrote:
> Hello,
> I am fairly new to R and trying to calculate value at risk with exponentially 
> decreasing weights.My function works for a single vector of returns but does 
> not work with rollapply(), which is what I want to use. The function I am 
> working on should assig exponentially decreasing weights to the K most recent 
> returns and then order the returns in an ascending order. Subsequently it 
> should pick the last return for which the cumulative sum of the weights is 
> smaller or equal to a significance level. Thus, I am trying to construct a 
> cumulative distribution function and find a quantile.
> This is the function I wrote:
> VaRfun <- function(x, lambda = 0.94) {
> #create data.frame and order returns such that the lates return is the first  
> df <- data.frame(weight = c(1:length(x)), return = rev(x))  K <- nrow(df)  
> constant <- (1-lambda)/(1-lambda^(K))#assign weights to the returnsfor(i 
> in 1:nrow(df)) {df$weight[i] <- lambda^(i-1) * constant}#order 
> returns in an ascending order  df <- df[order(df$return),]
> #add the cumulative sum of the weights  df$cum.weight <- cumsum(df$weight)
> #calculate value at risk  VaR <- -tail((df$return[df$cum.weight <= .05]), 1)  
> signif(VaR, digits = 3)}
> It works for a single vector of returns but if I try to use it with 
> rollapply(), such as
> rollapply(r, width = list(-500, -1), FUN = VaRfun),
> it outputs a vector of NAs and I don't know why.
> Thank you for your help!
> [[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.



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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] Analysing the output from skmeans/clustering

2017-05-28 Thread Ashim Kapoor
Dear All,

Here is a small example:

library(skmeans)
library(tm)
data("crude")
#Examine the first document
inspect(crude[[1]])

dtm <- DocumentTermMatrix(crude, control =
   list(removePunctuation = TRUE,
   removeNumbers = TRUE,
stopwords = TRUE))
clus <- skmeans(dtm,3)
names(clus)

Is there any way I can get the document number of the  prototypes ? Also
can I get the 3 closest documents to each prototype ? By prototype I mean
the cluster centers.

I know can compare each row of the DocumentTermMatrix with the prototypes
to test for equality and I can manually compute the distance of each
Document from a prototypes,but I was wondering if such a tool already
exists.

Best Regards,
Ashim

[[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] Need Help To Solve An Equation In R

2017-05-28 Thread Kenneth Knoblauch
This looks an awful lot like you are trying to solve for d' in an 
m-alternative forced choice experiment for an unbiased observer.  Try 
the function dprime.mAFC from the psyphy package.  For comparison with 
your example, it's code is:


 psyphy:::dprime.mAFC
function (Pc, m)
{
m <- as.integer(m)
if (m < 2)
stop("m must be an integer greater than 1")
if (!is.integer(m))
stop("m must be an integer")
if (Pc <= 0 || Pc >= 1)
stop("Pc must be in (0,1)")
est.dp <- function(dp) {
pr <- function(x) dnorm(x - dp) * pnorm(x)^(m - 1)
Pc - integrate(pr, lower = -Inf, upper = Inf)$value
}
dp.res <- uniroot(est.dp, interval = c(-10, 10))
dp.res$root
}


Hope that helps,

best,

Ken


On Sat, May 27, 2017 at 9:16 AM, Neetu Shah  
wrote:

Dear Sir/Ma'am,

I am trying to make a function to solve an equation that is given 
below:

findH <- function(p_star, k){
fun <- function(y){
(pnorm(y+h))^(k-1)*dnorm(y)
}
lhs <- integrate(fun, -Inf, Inf)$value
return(uniroot(lhs, lower = -10, upper = 10,
tol = p_star)$root)
}
In lhs, I integrated a function with respect to y and there would be an
unknown h that I need to find.
I need to equate this lhs to p_star value in order to find h. Which
function should I use to solve this equation?
Please guide me regarding this.
Thank you.

--
With Regards,
Neetu Shah,
B.Tech.(CS),
3rd Year,
IIIT Vadodara.

--
Kenneth Knoblauch
Inserm U1208
Stem-cell and Brain Research Institute
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.sbri.fr/members/kenneth-knoblauch.html

__
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] creat contingency tables with fixed row and column margins

2017-05-28 Thread David Winsemius

> On May 27, 2017, at 1:54 PM, li li  wrote:
> 
> I meant that the post in your link above was NOT asked by me.
> 
> 2017-05-27 16:53 GMT-04:00 li li :
> Hi Dave,
>   Thanks for your reply but the post in your link above was certainly asked 
> by me.
>Hanna
> 

I really have no idea what either of those sentences above might mean. I 
offered what I thought was one obvious effort at searching for a method to 
accomplish the task set forth in you subject line, but was leaving it up to you 
to take steps forward to advance the process. It might also help to explain the 
purpose of this effort.

-- 
David.

> 2017-05-27 16:04 GMT-04:00 David Winsemius :
> 
> > On May 27, 2017, at 12:49 PM, li li  wrote:
> >
> > Hi all,
> >  Is there an R function that can be used to enumerate all the contingency
> > tables with fixed row and column margins. For example, can we list all 3 by
> > 3 tables with row margins 3,6,6 and column margins 5,5,5.
> 
> The Posting Guide suggests that you describe the results of your efforts at 
> searching:
> 
> https://www.google.com/search?q=use+r%3Alang+to+enumerate+contingency+tables+with+fixed+margins=use+r%3Alang+to+enumerate+contingency+tables+with+fixed+margins=chrome..69i57.35014j0j4=chrome=UTF-8
> 
> >   Thanks very much!
> >   Hanna
> >
> >   [[alternative HTML version deleted]]
> 
> And (yet again) you are asked to post in plain text.
> >
> > __
> > 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.
> 
> David Winsemius
> Alameda, CA, USA
> 
> 
> 

David Winsemius
Alameda, CA, USA

__
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.