Re: [R] introducing R to high school students

2012-04-21 Thread Indrajit Sengupta
Bert,
 
What you are saying - is a problem with people who are using Excel. It is not 
Excel's problem that people are sending data in an unstructured way. I agree - 
Excel may not be the right tool when you are doing some complicated data 
analysis (like for e.g. statistical modeling) - but that is not what Excel was 
built for. The power of Excel lies in being able to use it to explore data, 
represent and present your analysis. When exploring data, yes it may not be 
very useful beyond univariates and bivariates - but that is your starting point 
in EDA where you need to generate hypotheses about your data. 
 
I have been in the field of analytics for almost 7 years now, though we have 
embraced technologies like SAS, R, SPSS, Spotfire, etc., the power and 
importance of Excel in our lives has never been lost to us. Its a question of 
whether are you capable enough to use it.
 
Regards,
Indrajit
 



From: Bert Gunter 

Cc: Rolf Turner  
Sent: Sunday, April 22, 2012 11:07 AM
Subject: Re: [R] introducing R to high school students

I would like to slightly clarify and echo  Rolf's comment:

Excel is a terrible tool for data analysis. Maybe it's a good tool for
keeping track of your car's repair history... but not for data
analysis.

I could go on at great length why, but let me just focus on one aspect
that drives me and other statisticians in my group crazy when we deal
with scientists who send us data in Excel: the data are frequently a
mess!  By this I mean that they are often stored in crazy ways, with
plots and summaries sprinkled around, capital letters and small
letters mixed, missing values coded arbitrarily e.g.(9 ), and so
forth. As someone I know once commented, it's a puzzle to get the data
extracted in a form susceptible to analysis.

Why is this? -- because Excel enforces no structure. It's
**cell-based** (du), so users can throw in the data anyway they
see fit, which frequently is pretty unfit.

This is not just a minor issue, imho. Not having data in a reasonable
structure limits what one can do for data analysis and graphics. This
promulgates the inadequate and frequently awful paradigms that one
sees throughout science (e.g. bar charts with 1 se bars sticking up
out of them).

The widespread use of Excel for "serious' scientific and engineering
data analysis is a near  tragedy. All IMHO, of course.

Cheers,
Bert

On Sat, Apr 21, 2012 at 9:45 PM, Indrajit Sengupta

> Why do you think Excel is a terrible tool? In what ways have you tried to use 
> Excel and it has failed you?
>
> Regards,
> Indrajit
>
>
> 
> From: Rolf Turner 
>
> Cc: R-help 
> Sent: Sunday, April 22, 2012 9:25 AM
> Subject: Re: [R] introducing R to high school students
>
> On 22/04/12 15:29, Indrajit Sengupta wrote:
>
> 
>> 1. At school we seldom deal with lot of data - the focus is more on 
>> concepts. Excel is an excellent tool
>     That is at best debatable, and IMHO just plain incorrect.  I firmly 
> believe
>     that Excel is a ***TERRIBLE*** tool.
>> and no matter how much we love or hate it - we will be using Excel a lot in 
>> our lives.
>
>     This is not (unfortunately IMHO) debatable.  It is all too sadly true.  
> For most
>     people at least.  (Not for my very good self.  I can get away with 
> eschewing
>     Excel.  Most people are not lucky enough to have that option.)
>
> 
>
>     I think much of the remainder of the post was highly disputable as well,
>     but I will desist at this point.
>
>         cheers,
>
>             Rolf Turner
>        [[alternative HTML version deleted]]
>
>
> __
> R-help@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@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.


Re: [R] Return dynamic array from C to R

2012-04-21 Thread Prof Brian Ripley

On 22/04/2012 04:52, Jaimin Dave wrote:

Hi Everyone,
I am new to R and I am trying to return array(dynamic) from C to R. But
when I print array(vector) in R it gives NA as output. When I print array
in C it gives correct o/p but some how it is not returned to R.

*Code in C:*
void test(double *vec,double *size){
vec = (double *)calloc(2 , sizeof(double));
 *(vec+0) = 1;
 *(vec+1) = 2;
 *size = 2;
}

*Code in R:*
test<-.C("test",vec=as.double(),size=as.integer())
print(test$vec[1:test$size])

Is there any other way to implement above thing?


Use .Call.  As the documentation tells you, you cannot do this in .C 
(and you are likely to cause segfaults by trying).




Any help would be appreciated
Thanks

[[alternative HTML version deleted]]

__
R-help@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.


Which does say this is the wrong list for programming questions 

--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@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.


Re: [R] introducing R to high school students

2012-04-21 Thread Indrajit Sengupta
Why do you think Excel is a terrible tool? In what ways have you tried to use 
Excel and it has failed you?
 
Regards,
Indrajit



From: Rolf Turner 

Cc: R-help  
Sent: Sunday, April 22, 2012 9:25 AM
Subject: Re: [R] introducing R to high school students

On 22/04/12 15:29, Indrajit Sengupta wrote:


> 1. At school we seldom deal with lot of data - the focus is more on concepts. 
> Excel is an excellent tool
    That is at best debatable, and IMHO just plain incorrect.  I firmly believe
    that Excel is a ***TERRIBLE*** tool.
> and no matter how much we love or hate it - we will be using Excel a lot in 
> our lives.

    This is not (unfortunately IMHO) debatable.  It is all too sadly true.  For 
most
    people at least.  (Not for my very good self.  I can get away with eschewing
    Excel.  Most people are not lucky enough to have that option.)



    I think much of the remainder of the post was highly disputable as well,
    but I will desist at this point.

        cheers,

            Rolf Turner
[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] predictOMatic for regression. Please try and advise me

2012-04-21 Thread William Dunlap
> newdataMaker <- function (model = NULL, fl = NULL){
> mf <- model.frame(model)
> mterms <- terms(model)
> mfnames <- colnames(mf)

I have not studied this carefully, but it looks like you are taking
the predictor variables to be the names of the columns of the
model.frame.  For a formula like
   y ~ poly(x1, 2) + sin(x2) + cos(x2)
that would give "y", "poly(x1, 2)", "sin(x2)", and "cos(x2)" where I'd expect
you would want the predictors to be "x1" and "x2".  You can get
the latter with by running all.vars() over the entries in the "variables"
attributes of the terms.  E.g.,
  > d <- data.frame(x1=1:10,x2=1:10,y=1:10)
  > fit <- lm(y ~ poly(x1,2) + sin(x2) + cos(x2), data=d)
  > unique(unlist(lapply(attr(delete.response(terms(fit)), "variables")[-1], 
all.vars)))
  [1] "x1" "x2"
There may be variables in there that are really constants, as with the "d"
in poly(x,d).  It can be tricky to completely automate eliminating those.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of Paul Johnson
> Sent: Friday, April 20, 2012 9:38 AM
> To: R-help; r-group...@googlegroups.com
> Subject: [R] predictOMatic for regression. Please try and advise me
> 
> I'm pasting below a working R file featuring a function I'd like to polish up.
> 
> I'm teaching regression this semester and every time I come to
> something that is very difficult to explain in class, I try to
> simplify it by writing an R function (eventually into my package
> "rockchalk").  Students have a difficult time with predict and newdata
> objects, so right now I'm concentrated on that problem.
> 
> Fitting regressions is pretty easy, but getting predicted values for
> particular combinations of input values can be difficult when the
> model is complicated. If you agree, please try out the following and
> let me know how its use could be enhanced, or what other features you
> might want.
> 
> I know folks are busy, so to save you the trouble of actually running
> the code, I also paste in a session demonstrating one run through.
> 
> Here's the code:
> 
> ##Paul Johnson
> ## 2012-04-20
> ## Facilitate creation of "newdata" objects for use in predict
> ## statements (for interpretation of regression models)
> 
> ## newdataMaker creates the newdata frame required in predict.
> ## It supplies a data frame with all input variables at a
> ## central value (mean, mode) except for some variables that
> ## the user wants to focus on. User should
> ## supply a fitted model "model" and a focus list "fl" of variable
> ## values. See examples below.  The list must be a named list,
> ## using names of variables from the regression formula.
> ## It is not needed to call this
> ## directly if one is satisfied with the results from
> ## predictOMatic
> 
> newdataMaker <- function (model = NULL, fl = NULL){
> mf <- model.frame(model)
> mterms <- terms(model)
> mfnames <- colnames(mf)
> modelcv <- centralValues(mf)
> if (sum(!names(fl) %in% mfnames) > 0) stop(cat(c("Error. The focus
> list (fl) requests variables that are not included in the original
> model. The names of the variables in the focus list be drawn from this
> list: ",  mfnames)))
> ## Consider "padding" range of fl for numeric variables so that we
> ## get newdata objects including the min and max values.
> mixAndMatch <- expand.grid(fl)
> mixAndMatch$combo <- 1:nrow(mixAndMatch)
> newdf <- cbind(mixAndMatch, modelcv[  ,!colnames(modelcv) %in%
> colnames(mixAndMatch)])
> newdf
> }
> 
> 
> 
> predictOMatic <- function(model = NULL, fl = NULL, ...){
> nd <- newdataMaker(model, fl)
> fit <- predict(model, newdata=nd, ...)
> cbind(fit, nd)
> }
> 
> 
> 
> set.seed(12345)
> x1 <- rnorm(100)
> x2 <- rnorm(100)
> x3 <- rnorm(100)
> x4 <- rnorm(100)
> x5 <- rpois(100, 5)
> x6 <- rgamma(100, 2,1)
> xcat1 <- gl(2,50, labels=c("M","F"))
> xcat2 <- cut(rnorm(100), breaks=c(-Inf, 0, 0.4, 0.9, 1, Inf),
> labels=c("R", "M", "D", "P", "G"))
> dat <- data.frame(x1, x2, x3, x4, x5, xcat1, xcat2)
> rm(x1, x2, x3, x4, xcat1, xcat2)
> dat$y <- with(dat, 0.03 + 0.1*x1 + 0.1*x2 + 0.4*x3 -0.1*x4 + 0.01*x5 +
> 0.1*x6 + 2*rnorm(100))
> 
> ##ordinary regression.
> m1 <- lm(y ~ x1 + x2 + x3 + x4 + x5 + x6 + xcat1 + xcat2, data=dat)
> summary(m1)
> ## Use the fitted model's data frame for analysis
> m1mf <- model.frame(m1)
> 
> ## If you have rockchalk 1.5.4, run these:
> library(rockchalk)
> summarize(m1mf)
> ## otherwise, run
> summary(m1mf)
> 
> ## First, overview for values of xcat1
> newdataMaker(m1, fl = list(xcat1 = levels(m1mf$xcat1)))
> 
> ## mix and match all combinations of xcat1 and xcat2
> newdataMaker(m1, fl = list(xcat1 = levels(m1mf$xcat2), xcat2 =
> levels(m1mf$xcat2)))
> 
> ## Pick some particular values for focus
> newdataMaker(m1, fl = list(x2 = c(0.25, 1.0), xcat2 = c("M","D")))
> 
> ## Generate a newdata frame and prediction

[R] Return dynamic array from C to R

2012-04-21 Thread Jaimin Dave
Hi Everyone,
I am new to R and I am trying to return array(dynamic) from C to R. But
when I print array(vector) in R it gives NA as output. When I print array
in C it gives correct o/p but some how it is not returned to R.

*Code in C:*
void test(double *vec,double *size){
vec = (double *)calloc(2 , sizeof(double));
*(vec+0) = 1;
*(vec+1) = 2;
*size = 2;
}

*Code in R:*
test<-.C("test",vec=as.double(),size=as.integer())
print(test$vec[1:test$size])

Is there any other way to implement above thing?

Any help would be appreciated
Thanks

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] introducing R to high school students

2012-04-21 Thread Rolf Turner

On 22/04/12 15:29, Indrajit Sengupta wrote:



1. At school we seldom deal with lot of data - the focus is more on concepts. 
Excel is an excellent tool
That is at best debatable, and IMHO just plain incorrect.  I firmly 
believe

that Excel is a ***TERRIBLE*** tool.

and no matter how much we love or hate it - we will be using Excel a lot in our 
lives.


This is not (unfortunately IMHO) debatable.  It is all too sadly 
true.  For most
people at least.  (Not for my very good self.  I can get away with 
eschewing

Excel.  Most people are not lucky enough to have that option.)



I think much of the remainder of the post was highly disputable as 
well,

but I will desist at this point.

cheers,

Rolf Turner

__
R-help@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.


Re: [R] contour algorithm

2012-04-21 Thread R. Michael Weylandt
The C implementation of the algorithm is here:

http://svn.r-project.org/R/trunk/src/main/plot3d.c

(grep filledcontour) but I don't see a reference other than to Ross Ihaka.

Hope this helps,
Michael

On Sat, Apr 21, 2012 at 9:21 PM, Stoch astic  wrote:
> First time user, so sorry if I don't understand protocol.. Anyway, I have
> created a data frame consisting of pearson's R values at various x and y
> coordinates and then plotted this using filled.contour. My data is similar
> to fMRI data except that it is a surface map reconstructed from
> histological sections. I like the results but would like to know how
> contours were detected. Google search provides me various sources claiming
> the algorithm used is undocumented. For example:
>
>
> http://wipaed.wiso.uni-goettingen.de/~holdenb1/R/library/base/html/contour.html
> "Draws contour lines for the desired levels. There is currently no
> documentation about the algorithm. The source code is in
> `$RHOME/src/main/plot.c'."
>
>
> Does anyone know where or how I can find the method by which contours are
> calculated?
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@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.

__
R-help@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.


Re: [R] introducing R to high school students

2012-04-21 Thread Indrajit Sengupta
Chris,
 
Don't get me wrong - I have nothing against learning R at an early age. 
However, I feel at a school level, the focus should be a bit more on 
programming. Here are some reasons why would not recommend R at school level:
 
1. At school we seldom deal with lot of data - the focus is more on concepts. 
Excel is an excellent tool and no matter how much we love or hate it - we will 
be using Excel a lot in our lives.
 
2. R language is a very high level language. To get a good grasp on programming 
- I would recommend any one of QBASIC, C or JAVA (Java might be a bit too much 
given OOP is not easy). Learn stuff the hard way - that way your fundamentals 
get strong. Even Excel VBA is a very powerful language - if you can incorporate 
that in your course - nothing like it. You will be churning out data scientists 
from your school.
 
3. The danger of introducing R too early - similar to introducing calculators 
to kids who are learning basic mental maths. They get too dependent on tools
 
Hope this clears my point of view.
 
Regards,
Indrajit
 



From: Christopher W. Ryan 
To: R-help  
Sent: Wednesday, April 18, 2012 7:55 PM
Subject: Re: [R] introducing R to high school students


Indrajit, I'm curious: given your preference for hand-drawn graphs for
learners (a very good point), why is Excel "fine" but R not?
[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Fwd: User defined panel functions in lattice

2012-04-21 Thread Duncan Mackay
Hi Mark

Thats why I did all the examples in Sweave to pick up anything I 
could not understand in practice but it did not help very much
It also gave me a quick reference as they are all bookmarked and are annotated

Duncan

At 00:01 22/04/2012, you wrote:
>Hi Duncan: Don't feel bad about it. I've read his book two or three times and
>STILL find it all terribly confusing with many things going unexplained.
>People say his book is so great but I don't have that opinion.
>
>   Mark
>
>
>On Sat, Apr 21, 2012 at 5:28 AM, Duncan Mackay 
><mac...@northnet.com.au> wrote:
>Bert
>I have read Deepayan's book and done all the examples but there is 
>no mention of panel.number and panel.groups in the books example.
>
>I just cannot get the fully meaning of what has been written 
>regarding passing arguments to panel functions.
>
>Regards
>
>Duncan
>
>
>
>At 14:31 21/04/2012, you wrote:
>A comment...
>
>On Fri, Apr 20, 2012 at 8:32 PM, Duncan Mackay 
><mac...@northnet.com.au> wrote:
> > Hi David, ilai
> >
> > The root cause of the problem is the passing of arguments to 
> panel functions
> > to me and my colleagues.
> > Just going through the archives there seems to be different ways for very
> > similar/same outcomes and
> > trying to get a pattern is hard to discern.
>
>Bad strategy!  Trying to infer the rules from examples in complex
>cases -- and as you said, different equivalent ways -- is nuts. You
>need to read the docs carefully (including Deepayan's book, possibly)
>and use the examples for understanding what is explained there.
>
>Finally, I don't know if this is relevant or helpful but:
>
>## this code works fine
>  xyplot(rnorm(5) ~ 1:5, type="l",
>  panel = function(...)panel.xyplot(...,lwd=2))
>
>## This code throws an error about repeat lwd arguments. Is it obvious why?
>  xyplot(rnorm(5) ~ 1:5,  lwd=1,type="l",
>  panel = function(...) panel.xyplot(...,lwd=2))
>
>-- Bert
>
> > I frequently have to use the subscripts or group.number to access other
> > data.
> > I thought I had things sorted out in my head with the panel.groups and
> > group.number but this has shattered it.
> >
> > Thanks
> >
> > Duncan
> >
> > At 12:15 21/04/2012, you wrote:
> >
> >> On Apr 20, 2012, at 9:14 PM, ilai wrote:
> >>
> >>> Oops - that is "reply all"
> >>> On Fri, Apr 20, 2012 at 5:29 PM, David Winsemius 
> <dwinsem...@comcast.net
> >>> > wrote:
> 
> 
>  I'm a bit puzzled by this exchange. I know there is a
>  'panel.locfit', but
>  you two are spelling it differently. Can you explain why you are
>  doing so?
> >>>
> >>>
> >>> Hi David,
> >>> Thanks for stepping in. panel.Locfit is the OP's local function (or
> >>> just a wrapper ?) which I believe is here
> >>> 
> http://www.mail-archive.com/r-help@r-project.org/msg167164.html
> >>>
> >>> Note the two errors OP encountered (solved down the thread) were
> >>> caused by the way he called the function in xyplot, not by
> >>> panel.Locfit itself, which I did not modify. I guess now the issue is
> >>> how to generalize panel.Locfit somehow, but I am not sure how. I
> >>> suspect the problem is not my understanding but that there really
> >>> isn't any one specific problem here for the list to solve, though,
> >>> again, I am known for misinterpreting OP requests... :)
> >>>
> > ?panel.locfit
> >>>
> >>>
> >>> As I said, I am unfamiliar with the package - but this doesn't
> >>> surprise me. Thank you for pointing it out, wish you've noticed the
> >>> exchange sooner...
> >>
> >>
> >> Another puzzle. In the original posting there was this segment:
> >> ---
> >> but gives an error message without par.settings if i want to add
> >>   panel.Locfit(x,y,nn= 0.9,lwd = c(1,2,3), ...)
> >>
> >> Error using packet 1
> >> formal argument "Iwd" matched by multiple actual arguments
> >> ---
> >>
> >> On my mailer that formal argument starts with a capital "I" but the
> >> code seemed to be attempting a lowercase "l".
> >>
> >> I could never see reason offered for defining a new panel.locfit, but
> >> I'm wondering if the sometimes similar representation of those two
> >> different letters could be causing an obscure conflict?
> >>
> >> --
> >> David.
> >>>
> >>>
> >>> Cheers
> >>>
> >>>
> > ?panel.Locfit
> 
>  No documentation for 'panel.Locfit' in specified packages and
>  libraries:
>  you could try '??panel.Locfit'
> 
> > ?panel.locfit
> 
> 
>  {locfit}R Documentation
>  Locfit panel function
> 
>  Description
> 
>  This panel function can be used to add locfit fits to plots
>  generated by
>  trellis.
> 
> 
> 
> > I am trying to construct a function/s to cover as many of the normal
> > situations as possible.
> > Usually

Re: [R] Fwd: User defined panel functions in lattice

2012-04-21 Thread Duncan Mackay

Hi Bert

Thank you for your comments.

I do use latticeExtra a lot - about 50% of my graphs at the moment 
have useOuterStrips some involving combineLimits .
Many are complicated - one I have just finished involves 
useOuterStrips in 8,3 (r,c) panels after

http://finzi.psych.upenn.edu/R/Rhelp02/archive/43626.html
+ 2 different panel.heights for some of the rows and that is just the start
I have used other functions when needed

I think that I will have to abandon a general function partly on 
arguments and the graphs I have done in the past an the possibilities 
in the future


I somebody would explain the rules 1 plus many others would be grateful


Duncan

At 00:19 22/04/2012, you wrote:

Oh ... one more thing.

You might explore the latticeExtra package. It permits use of a
layering paradigm -- like ggplot -- that largely obviates the need for
panel functions. There are also options in it to gracefully handle
(ignore) replicated arguments.

-- Bert

On Sat, Apr 21, 2012 at 2:28 AM, Duncan Mackay  wrote:
> Bert
> I have read Deepayan's book and done all the examples but there is no
> mention of panel.number and panel.groups in the books example.
>
> I just cannot get the fully meaning of what has been written regarding
> passing arguments to panel functions.
>
> Regards
>
> Duncan
>
>
>
> At 14:31 21/04/2012, you wrote:
>>
>> A comment...
>>
>> On Fri, Apr 20, 2012 at 8:32 PM, Duncan Mackay 
>> wrote:
>> > Hi David, ilai
>> >
>> > The root cause of the problem is the passing of arguments to panel
>> > functions
>> > to me and my colleagues.
>> > Just going through the archives there seems to be different ways for
>> > very
>> > similar/same outcomes and
>> > trying to get a pattern is hard to discern.
>>
>> Bad strategy!  Trying to infer the rules from examples in complex
>> cases -- and as you said, different equivalent ways -- is nuts. You
>> need to read the docs carefully (including Deepayan's book, possibly)
>> and use the examples for understanding what is explained there.
>>
>> Finally, I don't know if this is relevant or helpful but:
>>
>> ## this code works fine
>>  xyplot(rnorm(5) ~ 1:5, type="l",
>>  panel = function(...)panel.xyplot(...,lwd=2))
>>
>> ## This code throws an error about repeat lwd arguments. Is it obvious
>> why?
>>  xyplot(rnorm(5) ~ 1:5,  lwd=1,type="l",
>>  panel = function(...) panel.xyplot(...,lwd=2))
>>
>> -- Bert
>>
>> > I frequently have to use the subscripts or group.number to access other
>> > data.
>> > I thought I had things sorted out in my head with the panel.groups and
>> > group.number but this has shattered it.
>> >
>> > Thanks
>> >
>> > Duncan
>> >
>> > At 12:15 21/04/2012, you wrote:
>> >
>> >> On Apr 20, 2012, at 9:14 PM, ilai wrote:
>> >>
>> >>> Oops - that is "reply all"
>> >>> On Fri, Apr 20, 2012 at 5:29 PM, David Winsemius
>> >>> > >>> > wrote:
>> 
>> 
>>  I'm a bit puzzled by this exchange. I know there is a
>>  'panel.locfit', but
>>  you two are spelling it differently. Can you explain why you are
>>  doing so?
>> >>>
>> >>>
>> >>> Hi David,
>> >>> Thanks for stepping in. panel.Locfit is the OP's local function (or
>> >>> just a wrapper ?) which I believe is here
>> >>> http://www.mail-archive.com/r-help@r-project.org/msg167164.html
>> >>>
>> >>> Note the two errors OP encountered (solved down the thread) were
>> >>> caused by the way he called the function in xyplot, not by
>> >>> panel.Locfit itself, which I did not modify. I guess now the issue is
>> >>> how to generalize panel.Locfit somehow, but I am not sure how. I
>> >>> suspect the problem is not my understanding but that there really
>> >>> isn't any one specific problem here for the list to solve, though,
>> >>> again, I am known for misinterpreting OP requests... :)
>> >>>
>> > ?panel.locfit
>> >>>
>> >>>
>> >>> As I said, I am unfamiliar with the package - but this doesn't
>> >>> surprise me. Thank you for pointing it out, wish you've noticed the
>> >>> exchange sooner...
>> >>
>> >>
>> >> Another puzzle. In the original posting there was this segment:
>> >> ---
>> >> but gives an error message without par.settings if i want to add
>> >>   panel.Locfit(x,y,nn= 0.9,lwd = c(1,2,3), ...)
>> >>
>> >> Error using packet 1
>> >> formal argument "Iwd" matched by multiple actual arguments
>> >> ---
>> >>
>> >> On my mailer that formal argument starts with a capital "I" but the
>> >> code seemed to be attempting a lowercase "l".
>> >>
>> >> I could never see reason offered for defining a new panel.locfit, but
>> >> I'm wondering if the sometimes similar representation of those two
>> >> different letters could be causing an obscure conflict?
>> >>
>> >> --
>> >> David.
>> >>>
>> >>>
>> >>> Cheers
>> >>>
>> >>>
>> > ?panel.Locfit
>> 
>>  No documentation for 'panel.Locfit' in specified packages and
>>  libraries:
>>  you could try '??panel.Locfit'
>> 
>> > ?panel.locfit
>> 
>> 
>>  {locfit}R Documentat

[R] contour algorithm

2012-04-21 Thread Stoch astic
First time user, so sorry if I don't understand protocol.. Anyway, I have
created a data frame consisting of pearson's R values at various x and y
coordinates and then plotted this using filled.contour. My data is similar
to fMRI data except that it is a surface map reconstructed from
histological sections. I like the results but would like to know how
contours were detected. Google search provides me various sources claiming
the algorithm used is undocumented. For example:


http://wipaed.wiso.uni-goettingen.de/~holdenb1/R/library/base/html/contour.html
"Draws contour lines for the desired levels. There is currently no
documentation about the algorithm. The source code is in
`$RHOME/src/main/plot.c'."


Does anyone know where or how I can find the method by which contours are
calculated?

[[alternative HTML version deleted]]

__
R-help@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.


[R] Survreg

2012-04-21 Thread Val
Hi all,

I am trying to run Weibull PH model  in R.

Assume in the data set  I  have x1  a continuous variable and x2 a
categorical  variable with two classes (0= sick and 1= healthy).  I fit the
model in the following way.

Test=survreg(Surv(time,cens)~ x1+x2,dist="weibull")

My questions are

1. Is it Weibull PH model or Weibull AFT model?
Call:
survreg(formula = Surv(time, delta) ~ x1 + x2, data = nn,
dist = "weibull")
Value Std. Error  z  p
(Intercept)   5.6521553.54e-02159.8   0.00e+00
x10.4925921.92e-0225.7   3.65e-145
x2   -0.0002125.64e-06  -37.60.00e+00
Log(scale)  -0.269219 1.57e-02  -17.1   1.24e-65
Scale= 0.764

2. I am interested in comparing the two classes of x2 (short, medium and
long) using the Weibull PH model. So I used factor(x2) in the model

Call:
survreg(formula = Surv(time, delta) ~ factor(x1) + x2, data = nn
dist = "weibull")
Value Std. Error z p
(Intercept)  6.192157   2.35e-02  263.5   0.00e+00
factor(x1)2 0.324327   3.14e-02   10.34.51e-25
factor(x1)3 1.038423   4.13e-02   25.12.07e-139
x2 -0.000211   5.64e-06  -37.47.89e-306
Log(scale)-0.267627   1.57e-02   -17.05.63e-65

Scale= 0.765

How do I interpret those results?

Is there a relationship between Webull PH and AFT Model?




Thanks

Val

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] using "factor" to eliminate unused levels without dropping other variables

2012-04-21 Thread la mer
That did the trick! Thank you much, Richard Heiberger.

--
View this message in context: 
http://r.789695.n4.nabble.com/using-factor-to-eliminate-unused-levels-without-dropping-other-variables-tp4577123p4577206.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Date object

2012-04-21 Thread David Winsemius


On Apr 21, 2012, at 3:49 PM, Rui Barradas wrote:


Hello,


Veerappa Chetty wrote


HI,
I have to work with data objects. I have trouble. I would like to  
convert
date to a integer of Julian dates omitting hours, minutes etc. I  
tried as.

Date and also as.POSIXlt, ct etc.

Please help me to compute the following difference. I get an "NA" for
output.

1/14/2006 0:00:00 AM -1/9/2006 0:00:00 AM


Thanks.
Chetty
--
Professor of Family Medicine
Boston University
Tel: 617-414-6221, Fax:617-414-3345
emails: chettyvk@,vchetty@

[[alternative HTML version deleted]]
f-contained, reproducible code.



Maybe this is system dependent, but with me, unlike what the help for
'strptime' says,
the format character 'H' can be used with the am/pm indicator even  
if  'p'

is present.



It will not throw an error but it does ignore the am/pm indicator when  
%H is used.


> x <- c("1/14/2006 12:00:00 AM", "1/9/2006 2:00:00 PM")
> d <- strptime(x, format ="%m/%d/%Y %H:%M:%S %p")
> d
[1] "2006-01-14 12:00:00" "2006-01-09 02:00:00"

--
David.





x <- c("1/14/2006 0:00:00 AM", "1/9/2006 0:00:00 AM")
# With '%p' in format string
d <- strptime(x, format ="%m/%d/%Y %H:%M:%S %p")
d[1] - d[2]

Time difference of 5 days

# Without '%p'
d <- strptime(x, format ="%m/%d/%Y %H:%M:%S")
d[1] - d[2]

Time difference of 5 days


sessionInfo()

R version 2.14.1 (2011-12-22)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Portuguese_Portugal.1252   
LC_CTYPE=Portuguese_Portugal.1252

[3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C
[5] LC_TIME=Portuguese_Portugal.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

loaded via a namespace (and not attached):
[1] tools_2.14.1

And the minus operator works as expected.

Hope this helps,

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/Date-object-tp4576784p4577018.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


David Winsemius, MD
West Hartford, CT

__
R-help@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.


Re: [R] using "factor" to eliminate unused levels without dropping other variables

2012-04-21 Thread Richard M. Heiberger
replace the line

data.subset2 <- factor(data.subset1$Sample)

with

data.subset1$Sample <- factor(data.subset1$Sample)

I assume your intention is to change the levels of the Sample variable in
the
data.subset1 data.frame.


On Sat, Apr 21, 2012 at 3:54 PM, Melissa Rosenkranz <
melissarosenkr...@gmail.com> wrote:

> Hello,
>
> I have been banging my head against the wall trying to figure out this
> seemingly simple problem with no success. I'm hoping that one or some
> of you can help.
>
> Here is the code I am trying to use:
>
> #importing data
> data.file <-read.csv("/file/location", header=TRUE, sep = ",")
> #selecting a subset of data based on variable "Sample"
> data.subset1 <- subset(data.file,  subset=(Sample !='sample_x' &
> Sample !='sample_y')).
>
> **This leaves me a data file that has 8 levels of the variable
> "Sample" and 2 empty levels that correspond to sample_x and sample_y.
> I need to get rid of these two levels for plotting purposes, so I
> tried using the code below...
>
> data.subset2 <- factor(data.subset1$Sample)
>
> **This does get rid of the two empty levels, but also gets rid of all
> the other variables in the dataset, which I want to keep. So my
> question is, how do I accomplish getting rid of the empty levels,
> while retaining the other variables in the dataset?? I tried the
> drop.levels option of subset, but couldn't get it to do what I need to
> do.
>
> Many thanks!!
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] xyplot - ordering factors in graph

2012-04-21 Thread pip
Thanks very much

--
View this message in context: 
http://r.789695.n4.nabble.com/xyplot-ordering-factors-in-graph-tp4576013p4577025.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Date object

2012-04-21 Thread Rui Barradas
Hello,


Veerappa Chetty wrote
> 
> HI,
> I have to work with data objects. I have trouble. I would like to convert
> date to a integer of Julian dates omitting hours, minutes etc. I tried as.
> Date and also as.POSIXlt, ct etc.
> 
> Please help me to compute the following difference. I get an "NA" for
> output.
> 
> 1/14/2006 0:00:00 AM -1/9/2006 0:00:00 AM
> 
> 
> Thanks.
> Chetty
> -- 
> Professor of Family Medicine
> Boston University
> Tel: 617-414-6221, Fax:617-414-3345
> emails: chettyvk@,vchetty@
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@ 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.
> 

Maybe this is system dependent, but with me, unlike what the help for
'strptime' says,
the format character 'H' can be used with the am/pm indicator even if  'p'
is present.


> x <- c("1/14/2006 0:00:00 AM", "1/9/2006 0:00:00 AM")
> # With '%p' in format string
> d <- strptime(x, format ="%m/%d/%Y %H:%M:%S %p")
> d[1] - d[2]
Time difference of 5 days
> # Without '%p'
> d <- strptime(x, format ="%m/%d/%Y %H:%M:%S")
> d[1] - d[2]
Time difference of 5 days
> 
> sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Portuguese_Portugal.1252  LC_CTYPE=Portuguese_Portugal.1252   
[3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C
[5] LC_TIME=Portuguese_Portugal.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 

loaded via a namespace (and not attached):
[1] tools_2.14.1

And the minus operator works as expected.

Hope this helps,

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/Date-object-tp4576784p4577018.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] using "factor" to eliminate unused levels without dropping other variables

2012-04-21 Thread Melissa Rosenkranz
Hello,

I have been banging my head against the wall trying to figure out this
seemingly simple problem with no success. I'm hoping that one or some
of you can help.

Here is the code I am trying to use:

#importing data
data.file <-read.csv("/file/location", header=TRUE, sep = ",")
#selecting a subset of data based on variable "Sample"
data.subset1 <- subset(data.file,  subset=(Sample !='sample_x' &
Sample !='sample_y')).

**This leaves me a data file that has 8 levels of the variable
"Sample" and 2 empty levels that correspond to sample_x and sample_y.
I need to get rid of these two levels for plotting purposes, so I
tried using the code below...

data.subset2 <- factor(data.subset1$Sample)

**This does get rid of the two empty levels, but also gets rid of all
the other variables in the dataset, which I want to keep. So my
question is, how do I accomplish getting rid of the empty levels,
while retaining the other variables in the dataset?? I tried the
drop.levels option of subset, but couldn't get it to do what I need to
do.

Many thanks!!

__
R-help@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.


Re: [R] how to write html output (webscraped using RCurl package) into file?

2012-04-21 Thread Milan Bouchet-Valat
Le samedi 21 avril 2012 à 07:05 -0700, sagarnikam123 a écrit :
> i want
> "http://scop.berkeley.edu/astral/pdbstyle/?id=d1fjgc2&output=html",showing
> information in webpage to be written in .txt file as it is(i don't want any
> html tag)
> i am using "RCurl" package
> 
> >marathi<-htmlTreeParse("http://scop.berkeley.edu/astral/pdbstyle/?id=d1fjgc2&output=html";)
> >marathi
> >kasam<-marathi$children$html[["body"]][["pre"]][["text"]]
> >kasam
> > write(kasam,"papita.txt")
> Error in cat(list(...), file, sep, fill, labels, append) : 
>   argument 1 (type 'list') cannot be handled by 'cat
> 
> i want to write kasam, as shown on console into  .txt file
kasam is a list, not a character string:
> str(kasam)
 Named list()
 - attr(*, "class")= chr [1:5] "XMLTextNode" "XMLNode"
"RXMLAbstractNode" "XMLAbstractNode" ...

You need to convert it to a character vector first:
write(xmlValue(kasam), "papita.txt")


Regards

__
R-help@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.


Re: [R] Solve an ordinary or generalized eigenvalue problem in R?

2012-04-21 Thread Berend Hasselman

On 21-04-2012, at 20:20, peter dalgaard wrote:

> 
>> 
>> The eigenvalues are identical upto the printed 9 digits but the eigenvectors 
>> appear to be quite different.
>> Maybe this is what Luke meant.
>> 
>> Berend
>> 
> 
> 
> They look quite similar to me:
> 
>> ev <- eigen(solve(B,A) )$vectors
>> ge <- geigen(A, B, TRUE , TRUE)
>> ev / ge$vl
>  [,1] [,2]   [,3]
> [1,] 0.9324603 0.813422 -0.7423694
> [2,] 0.9324603 0.813422 -0.7423694
> [3,] 0.9324603 0.813422 -0.7423694
>> ev / ge$vr
>  [,1] [,2]   [,3]
> [1,] 0.9324603 0.813422 -0.7423694
> [2,] 0.9324603 0.813422 -0.7423694
> [3,] 0.9324603 0.813422 -0.7423694
> 
> (and of course, eigenvectors of any sort are only defined up to a constant 
> multiplier)

Correct. I should have checked  your way and not optically.

Berend

__
R-help@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.


Re: [R] Solve an ordinary or generalized eigenvalue problem in R?

2012-04-21 Thread peter dalgaard

On Apr 21, 2012, at 19:13 , Berend Hasselman wrote:

> 
> On 21-04-2012, at 16:40, peter dalgaard wrote:
> 
>> 
>> On Apr 21, 2012, at 15:22 , Luke Hartigan wrote:
>> 
>>> Hi all,
>>> 
>>> In my experience, using eigen to solve generalized eigenvalue / eigenvector
>>> problems only gives correct looking eigenvalues while the eigenvectors seem
>>> to be wrong (in comparison to results from MATLAB's 'eig' function for
>>> example).
>> 
>> Could you please document that? There are many misconceptions about when 
>> eigenvectors are "correct" and platform dependencies too. As far as I can 
>> tell, both R and Matlab use the same LAPACK routines.
> 
> 
> The OP posted two matrices:
> 
> A <- matrix(c(1457.738, 1053.181, 1256.953,
>  1053.181, 1213.728, 1302.838,
>  1256.953, 1302.838, 1428.269), nrow=3, byrow=TRUE)
> 
> B <- matrix(c(4806.033, 1767.480, 2622.744,
>  1767.480, 3353.603, 3259.680,
>  2622.744, 3259.680, 3476.790), nrow=3, byrow=TRUE)
> 
> I've tried
> 
> eigen(solve(B)%*%A) 
> 
> (which is probably not the best way to handle this problem numerically) to 
> approximate the generalized ev problem.
> And the geigen function
> 
> geigen(A,B,TRUE,TRUE)
> 
> The eigenvalues are identical upto the printed 9 digits but the eigenvectors 
> appear to be quite different.
> Maybe this is what Luke meant.
> 
> Berend
> 


They look quite similar to me:

> ev <- eigen(solve(B,A) )$vectors
> ge <- geigen(A, B, TRUE , TRUE)
> ev / ge$vl
  [,1] [,2]   [,3]
[1,] 0.9324603 0.813422 -0.7423694
[2,] 0.9324603 0.813422 -0.7423694
[3,] 0.9324603 0.813422 -0.7423694
> ev / ge$vr
  [,1] [,2]   [,3]
[1,] 0.9324603 0.813422 -0.7423694
[2,] 0.9324603 0.813422 -0.7423694
[3,] 0.9324603 0.813422 -0.7423694

(and of course, eigenvectors of any sort are only defined up to a constant 
multiplier)
-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@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.


Re: [R] xyplot - ordering factors in graph

2012-04-21 Thread Greg Snow
R works on the idea that factor level ordering is a property of the
data rather than a property of the graph.  So if you have the factor
levels ordered properly in the data, then the graph will take care of
itself.  To order the levels see functions like: factor, relevel, and
reorder.

On Sat, Apr 21, 2012 at 1:23 AM, pip  wrote:
> Hello - newbie
> Have created a lattice graph and want to know how to sort one of the
> elements which is a factor.
> The factor numbers in graph are - eg - 10   32  21
>                                                                      2
> 22  4 etc
>
> Regards
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/xyplot-ordering-factors-in-graph-tp4576013p4576013.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

__
R-help@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.


Re: [R] Date object

2012-04-21 Thread David Winsemius


On Apr 21, 2012, at 1:17 PM, Veerappa Chetty wrote:


HI,
I have to work with data objects. I have trouble. I would like to  
convert
date to a integer of Julian dates omitting hours, minutes etc. I  
tried as.

Date and also as.POSIXlt, ct etc.

Please help me to compute the following difference. I get an "NA" for
output.

1/14/2006 0:00:00 AM -1/9/2006 0:00:00 AM


I didn't realize this until I started experimenting with your example,  
but there is no 0 hour that is recognized by strptime when using the  
am/pm time format:


> strptime("1/14/2006 0:01:01 AM", format ="%m/%d/%Y %I:%M:%S %p")
[1] NA
> strptime("1/14/2006 12:01:01 AM", format ="%m/%d/%Y %I:%M:%S %p")
[1] "2006-01-14 00:01:01"


If you want to offer a reproducible example of your data (not just  
console output we can do more with it.) I suggest you take you vector  
and offer the output of dput() on it.


--
David.



Thanks.
Chetty
--
Professor of Family Medicine
Boston University
Tel: 617-414-6221, Fax:617-414-3345
emails: chett...@gmail.com,vche...@bu.edu

[[alternative HTML version deleted]]

__
R-help@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.


David Winsemius, MD
West Hartford, CT

__
R-help@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.


Re: [R] Solve an ordinary or generalized eigenvalue problem in R?

2012-04-21 Thread Berend Hasselman

On 21-04-2012, at 16:40, peter dalgaard wrote:

> 
> On Apr 21, 2012, at 15:22 , Luke Hartigan wrote:
> 
>> Hi all,
>> 
>> In my experience, using eigen to solve generalized eigenvalue / eigenvector
>> problems only gives correct looking eigenvalues while the eigenvectors seem
>> to be wrong (in comparison to results from MATLAB's 'eig' function for
>> example).
> 
> Could you please document that? There are many misconceptions about when 
> eigenvectors are "correct" and platform dependencies too. As far as I can 
> tell, both R and Matlab use the same LAPACK routines.


The OP posted two matrices:

A <- matrix(c(1457.738, 1053.181, 1256.953,
  1053.181, 1213.728, 1302.838,
  1256.953, 1302.838, 1428.269), nrow=3, byrow=TRUE)

B <- matrix(c(4806.033, 1767.480, 2622.744,
  1767.480, 3353.603, 3259.680,
  2622.744, 3259.680, 3476.790), nrow=3, byrow=TRUE)

I've tried

eigen(solve(B)%*%A) 

(which is probably not the best way to handle this problem numerically) to 
approximate the generalized ev problem.
And the geigen function

geigen(A,B,TRUE,TRUE)

The eigenvalues are identical upto the printed 9 digits but the eigenvectors 
appear to be quite different.
Maybe this is what Luke meant.

Berend

__
R-help@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.


[R] Date object

2012-04-21 Thread Veerappa Chetty
HI,
I have to work with data objects. I have trouble. I would like to convert
date to a integer of Julian dates omitting hours, minutes etc. I tried as.
Date and also as.POSIXlt, ct etc.

Please help me to compute the following difference. I get an "NA" for
output.

1/14/2006 0:00:00 AM -1/9/2006 0:00:00 AM


Thanks.
Chetty
-- 
Professor of Family Medicine
Boston University
Tel: 617-414-6221, Fax:617-414-3345
emails: chett...@gmail.com,vche...@bu.edu

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Script Help Or Excel Add-in

2012-04-21 Thread Tal Galili
Hi Ben,

1) Have a look at:
http://rcom.univie.ac.at/download.html

2) I do not know.

Good luck,
Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Sat, Apr 21, 2012 at 6:06 PM, bscully  wrote:

> Hello,
>
> I have been using R/S+ for years and love the software.  Still a novice but
> I can do what i need to.
>
> Anyway, I am working on a forecasting project and would like to create a
> script that automates the following steps:
> order data by X
> Create groupings 1...N
> Separate test data set
> run regression on each group
> Determine result.  (A mathematical formula is run on the forecasted output)
> Repeat for test set
> Review results
>
> I have no idea how to do this script in S+.  Working in excel would make
> this much easier so my question is twofold:
>
> 1) I am running windows 7, MS Office 2010 and i dont have an excel add-in
> for S+.  Does one exist?  Does one exist for R?  An installation link would
> be very helpful.
>
> 2) How can i create the above script in R/S+ to automate my research.
>
>
> Any help would be greatly appreciated!
>
> Thank you,
>
> Ben
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Script-Help-Or-Excel-Add-in-tp4576572p4576572.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Solve an ordinary or generalized eigenvalue problem in R?

2012-04-21 Thread Berend Hasselman

On 21-04-2012, at 17:37, Rui Barradas wrote:

> Hello,
> 
> 
> Berend Hasselman wrote
>> 
>> On 21-04-2012, at 11:40, Berend Hasselman wrote:
>> 
>>> 
>>> .
>>> See this:
>>> 
>>> 
>>> # This works on Mac OS X
>>> # Change as needed for other systems
>>> # or compile geigen into a standalone shared object.
>>> 
>>> dyn.load(file.path(R.home("lib"),"libRlapack.dylib"))
>>> 
>> 
>> Replacing the dyn.load line with
>> 
>> dyn.load(file.path(R.home("modules"),"lapack.so"))
>> 
>> lets run geigen1.R run on Mac OS X and Ubuntu unchanged.
>> Hopefully this is the proper way to load Lapack as provided by R.
>> How to do it on Windows, I can't test.
>> 
>> Berend
>> 
>> __
>> R-help@ 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.
>> 
> 
> My system is a Windows 7 and the following function solved the dyn.load.
> 
> 
> dynlib.load <- function(x, dir){
>   dynname <- paste(x, .Platform$dynlib.ext, sep="")
>   dynname <- file.path(R.home(dir), dynname)
>   dyn.load(dynname)
> }
> 
> # In windows it's these names
> dynlib.load("Rlapack", "bin")
> 
> 
> The rest worked at the first try.
> Note that this function is independent of the sub-architecture, like the
> help page for R.home() says:
> 
> "The return value for "modules" and on Windows "bin" is to a
> sub-architecture-specific location. "
> 
> (R.home("bin") returns .../bin/i386 or .../bin/x64)
> 

Thank you.
I've now changed the dyn.load line to this

if( .Platform$OS.type == "windows" ) {
Lapack.so <- file.path(R.home("bin"),paste0("Rlapack",.Platform$dynlib.ext))
} else {
Lapack.so <- 
file.path(R.home("modules"),paste0("lapack",.Platform$dynlib.ext))
}

dyn.load(Lapack.so)

Hopefully that will do.

BTW: lapack.so on Mac OS X is located in a sub-architecture-specific location.

Berend

__
R-help@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.


Re: [R] multi-machine parallel setup?

2012-04-21 Thread ivo welch
thx, guys, almost there.  This is good fodder for the vignette or ?parallel.

Steps:

(1) install package "snow" on all machines which you want to be part
of a cluster.
(2) run under R

library(parallel)
cl <- makeCluster(c("localhost", "calc.localdomain"), "SOCK")
result <- parLapply(cl=cl, X=1:100, function(x) {
paste(x,system("hostname", intern="TRUE")) } )
stopCluster(cl)

in my case, with two linux ubuntu machines and R 2.14...this hangs (!)
because I made a small mistake, using "TRUE" instead of TRUE.  if I
fix it, it works fine.  is there a way to have the slave signal "abort
the parLapply" job when it encounters an error?  [or is it something
with my setup that prevents the abort?  does it abort correctly on
your machines?]

(I run not R 2.15 but R 2.14.1 on ubuntu 12.04LTS beta, because in
/etc/apt/sources.list, deb http://cran.cnr.Berkeley.edu precise
multiverse still installs 2.14.1.)

regards,

/iaw

__
R-help@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.


Re: [R] unexpected plot behavior

2012-04-21 Thread Uwe Ligges



On 21.04.2012 16:49, Martin Renner wrote:

When plotting a numerical vector against a factor, 'type="n"' seems to have no 
affect, e.g.

plot (1:10~factor (1:10), type = "n")


looks just like

plot (1:10~factor (1:10))


This plots 10 boxplots and the data are passed from plot.formula. 
plot.formula does not accept a "type" argument. plot.default() does, but 
that is not used once your use a formula.


Uwe Ligges





Plotting a numerical against itself works as expected:

plot (1:10, type = "n")


I see the same behavior under debian gnu/linux, Mac OS X, and Win7 (all current 
versions, see below). Is this a bug?

Regards,
Martin



Martin Renner
Post-doctoral Fellowphone: 907-226 4672
University of Washington   or: 907-235 0728
School of Aquatic and Fishery Sciences  Seattle, USA




sessionInfo()

R version 2.15.0 (2012-03-30)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=C LC_NAME=C
  [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base
__
R-help@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.


__
R-help@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.


Re: [R] unexpected plot behavior

2012-04-21 Thread Marc Schwartz
On Apr 21, 2012, at 9:49 AM, Martin Renner wrote:

> When plotting a numerical vector against a factor, 'type="n"' seems to have 
> no affect, e.g. 
>> plot (1:10~factor (1:10), type = "n")
> 
> looks just like
>> plot (1:10~factor (1:10))
> 
> Plotting a numerical against itself works as expected: 
>> plot (1:10, type = "n")
> 
> I see the same behavior under debian gnu/linux, Mac OS X, and Win7 (all 
> current versions, see below). Is this a bug? 
> 
> Regards,
> Martin



This has to do with method dispatch. See ?plot.formula, which is the plot 
method called you pass a formula, as opposed to passing a vector as in your 
third example. 

In this case, ?plot.factor is called when the 'x' part of the formula (RHS) is 
a factor. When plot.factor is called, it internally calls ?boxplot and of 
course, there is no "type = 'n'" for boxplots, hence it is ignored.

Regards,

Marc Schwartz

__
R-help@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.


Re: [R] Solve an ordinary or generalized eigenvalue problem in R?

2012-04-21 Thread Rui Barradas
Hello,


Berend Hasselman wrote
> 
> On 21-04-2012, at 11:40, Berend Hasselman wrote:
> 
>> 
>> .
>> See this:
>> 
>> 
>> # This works on Mac OS X
>> # Change as needed for other systems
>> # or compile geigen into a standalone shared object.
>> 
>> dyn.load(file.path(R.home("lib"),"libRlapack.dylib"))
>> 
> 
> Replacing the dyn.load line with
> 
> dyn.load(file.path(R.home("modules"),"lapack.so"))
> 
> lets run geigen1.R run on Mac OS X and Ubuntu unchanged.
> Hopefully this is the proper way to load Lapack as provided by R.
> How to do it on Windows, I can't test.
> 
> Berend
> 
> __
> R-help@ 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.
> 

My system is a Windows 7 and the following function solved the dyn.load.


dynlib.load <- function(x, dir){
dynname <- paste(x, .Platform$dynlib.ext, sep="")
dynname <- file.path(R.home(dir), dynname)
dyn.load(dynname)
}

# In windows it's these names
dynlib.load("Rlapack", "bin")


The rest worked at the first try.
Note that this function is independent of the sub-architecture, like the
help page for R.home() says:

"The return value for "modules" and on Windows "bin" is to a
sub-architecture-specific location. "

(R.home("bin") returns .../bin/i386 or .../bin/x64)

Hope this helps

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/Solve-an-ordinary-or-generalized-eigenvalue-problem-in-R-tp4571823p4576615.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] Script Help Or Excel Add-in

2012-04-21 Thread bscully
Hello,

I have been using R/S+ for years and love the software.  Still a novice but
I can do what i need to.

Anyway, I am working on a forecasting project and would like to create a
script that automates the following steps:
order data by X
Create groupings 1...N
Separate test data set
run regression on each group
Determine result.  (A mathematical formula is run on the forecasted output)
Repeat for test set
Review results

I have no idea how to do this script in S+.  Working in excel would make
this much easier so my question is twofold:

1) I am running windows 7, MS Office 2010 and i dont have an excel add-in
for S+.  Does one exist?  Does one exist for R?  An installation link would
be very helpful.

2) How can i create the above script in R/S+ to automate my research. 


Any help would be greatly appreciated!

Thank you,

Ben

--
View this message in context: 
http://r.789695.n4.nabble.com/Script-Help-Or-Excel-Add-in-tp4576572p4576572.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] multi-machine parallel setup?

2012-04-21 Thread Joshua Wiley
On Sat, Apr 21, 2012 at 8:20 AM, ivo welch  wrote:
> hi uwe---my box is different:
>
> cl <- makeCluster(c("localhost", "welch", "calc"), "SOCK")
> Error in loadNamespace(name) : there is no package called 'snow'
>
> this seems to be part of snow, not parallel.  ok, install snow first,
> then rerun.
>
> library(snow)
> Attaching package: 'snow'
>
> The following object(s) are masked from 'package:parallel':
>
>    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
> clusterExport, clusterMap, clusterSplit, makeCluster, parApply,
> parCapply, parLapply,
>    parRapply, parSapply, splitIndices, stopCluster
>
> bash: /Library/Frameworks/R.framework/Resources/bin/Rscript: No such
> file or directory
>
> but if I use two linux machines, it works.
>
> now, how do I use parallel's mclapply with it?

parLapply(cl = cl, X = data, fun = mean)

AFAIK, mclapply() does not take a cluster argument, but the par* functions do.

Cheers,

Josh

>
> best,
>
> /iaw
>
> 
> Ivo Welch (ivo.we...@gmail.com)
> J. Fred Weston Professor of Finance
> Anderson School at UCLA, C519
> http://www.ivo-welch.info/
> Editor, Critical Finance Review, http://www.critical-finance-review.org/
>
>
>
> 2012/4/21 Uwe Ligges :
>>
>>
>> On 21.04.2012 06:34, ivo welch wrote:
>>>
>>> the vignette to the library(parallel) mentions snow repeatedly (esp
>>> differences in its implementation in parallel from the original).
>>> unfortunately, it doesn't give an example or tutorial for
>>> multi-machine use with sockets.
>>>
>>> could someone please point me to a simple working example, where a
>>> master just has both itself and a 4-core slave on a second machine
>>> (IP), and wants to execute an mclapply on a list on both machines,
>>> like
>>>
>>>    master.ip<- "localhost"
>>>    slave.ip<- "Rfriend@192.168.2.10"  ## has key ssh access
>>>    mclapply( 1:100, function(x) { cat(x); Sys.sleep(1); x } )  # on both,
>>> please
>>>
>>> iaw
>>
>>
>>
>>
>> With appropriate ssh keys that do not need passwords and with the same
>> username on all machines, it should work out of the box. At least, it does
>> for me:
>>
>> Say you want two, one on your own machine, the other one on your friends:
>>
>>  cl <- makeCluster(c("localhost", "192.168.2.10"), "SOCK")
>>
>> BEst,
>> Uwe Ligges
>>
>>
>>>
>>> On Wed, Apr 18, 2012 at 1:01 PM, ivo welch  wrote:

 Dear R experts:

 could someone please point me to a page that explains how to set up
 more than 1 machine for library parallel (which is quickly becoming my
 favorite!)
>>>
>>> ...
>>>
>>> __
>>> R-help@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.
>
> __
> R-help@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.



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

__
R-help@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.


[R] unexpected plot behavior

2012-04-21 Thread Martin Renner
When plotting a numerical vector against a factor, 'type="n"' seems to have no 
affect, e.g. 
> plot (1:10~factor (1:10), type = "n")

looks just like
> plot (1:10~factor (1:10))

Plotting a numerical against itself works as expected: 
> plot (1:10, type = "n")

I see the same behavior under debian gnu/linux, Mac OS X, and Win7 (all current 
versions, see below). Is this a bug? 

Regards,
Martin
 


Martin Renner
Post-doctoral Fellowphone: 907-226 4672
University of Washington   or: 907-235 0728
School of Aquatic and Fishery Sciences  Seattle, USA



> sessionInfo() 
R version 2.15.0 (2012-03-30)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C  
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=C LC_NAME=C 
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 
__
R-help@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.


Re: [R] multi-machine parallel setup?

2012-04-21 Thread Uwe Ligges



On 21.04.2012 17:20, ivo welch wrote:

hi uwe---my box is different:

cl<- makeCluster(c("localhost", "welch", "calc"), "SOCK")
Error in loadNamespace(name) : there is no package called 'snow'

this seems to be part of snow, not parallel.  ok, install snow first,
then rerun.



No, you just need snow to be installed, using the functions from 
parallel will load the snow Namespace, if installed.






library(snow)
Attaching package: 'snow'

The following object(s) are masked from 'package:parallel':

 clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, clusterSplit, makeCluster, parApply,
parCapply, parLapply,
 parRapply, parSapply, splitIndices, stopCluster

bash: /Library/Frameworks/R.framework/Resources/bin/Rscript: No such
file or directory

but if I use two linux machines, it works.

now, how do I use parallel's mclapply with it?



as I said.

As you seem to be under some heterogeneous setup (unstated before, as 
far as I remember), you may need to specify paths to the loaction of R 
etc. See the documentation for the parallel package.


Uwe




best,

/iaw


Ivo Welch (ivo.we...@gmail.com)
J. Fred Weston Professor of Finance
Anderson School at UCLA, C519
http://www.ivo-welch.info/
Editor, Critical Finance Review, http://www.critical-finance-review.org/



2012/4/21 Uwe Ligges:



On 21.04.2012 06:34, ivo welch wrote:


the vignette to the library(parallel) mentions snow repeatedly (esp
differences in its implementation in parallel from the original).
unfortunately, it doesn't give an example or tutorial for
multi-machine use with sockets.

could someone please point me to a simple working example, where a
master just has both itself and a 4-core slave on a second machine
(IP), and wants to execute an mclapply on a list on both machines,
like

master.ip<- "localhost"
slave.ip<- "Rfriend@192.168.2.10"  ## has key ssh access
mclapply( 1:100, function(x) { cat(x); Sys.sleep(1); x } )  # on both,
please

iaw





With appropriate ssh keys that do not need passwords and with the same
username on all machines, it should work out of the box. At least, it does
for me:

Say you want two, one on your own machine, the other one on your friends:

  cl<- makeCluster(c("localhost", "192.168.2.10"), "SOCK")

BEst,
Uwe Ligges




On Wed, Apr 18, 2012 at 1:01 PM, ivo welchwrote:


Dear R experts:

could someone please point me to a page that explains how to set up
more than 1 machine for library parallel (which is quickly becoming my
favorite!)


...

__
R-help@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.


__
R-help@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.


[R] help with rmeta package

2012-04-21 Thread Luca Braglia
Dear R users,

I'm trying figuring out with forest plot and rmeta. Here's my code...


library(rmeta)

tabletext <- structure(c("", NA, "Sex", "[F]", "[M]", NA,
 "Age class", "(0,60]", "(60,80]", NA,
 "Karnofsky class", "[70;90]",
 "(90;100]", NA, "Tumor dimension",
 "(0,5]", "(5,10]", "(10,30]", NA,
 "Primary tumor", "[T1]", "[T2]",
 "[T3a]", "[T3b-T3c]", NA, "Histology",
 "[ClearCell]", "[Papill-Chromo]",
 "[Others]", NA, "Grading", "[G1]",
 "[G2]", "[G3]", "[G4]", NA, "n", NA, NA,
 "105", "198", NA, NA, "161", "142", NA,
 NA, "39", "264", NA, NA, "121", "143",
 "39", NA, NA, "131", "51", "68", "53",
 NA, NA, "242", "34", "19", NA, NA, "53",
 "136", "68", "16", NA, "HR", NA, NA,
 "0.67", "0.92", NA, NA, "0.6", "0.98",
 NA, NA, "1.19", "0.72", NA, NA, "1.19",
 "0.5", "1.11", NA, NA, "0.82", "1.16",
 "0.56", "1.21", NA, NA, "0.82", "0.5",
 "0.95", NA, NA, "0", "0.52", "0.96",
 "1.17", NA, "95 CI", NA, NA,
 "[0.31-1.44]", "[0.53-1.62]", NA, NA,
 "[0.31-1.18]", "[0.53-1.82]", NA, NA,
 "[0.44-3.21]", "[0.43-1.21]", NA, NA,
 "[0.42-3.41]", "[0.27-0.93]",
 "[0.44-2.76]", NA, NA, "[0.28-2.46]",
 "[0.39-3.46]", "[0.26-1.25]",
 "[0.53-2.76]", NA, NA, "[0.49-1.37]",
 "[0.06-4.31]", "[0.27-3.39]", NA, NA,
 "[0-Inf]", "[0.25-1.1]", "[0.44-2.07]",
 "[0.31-4.38]", NA, "P-value", NA,
 "0.46", NA, NA, NA, "0.3", NA, NA, NA,
 "0.39", NA, NA, NA, "0.21", NA, NA, NA,
 NA, "0.63", NA, NA, NA, NA, NA, "0.85",
 NA, NA, NA, NA, "0.22", NA, NA, NA, NA,
 NA), .Dim = c(36L, 5L))

m <- c(NA, NA, NA, 0.67, 0.92, NA, NA, 0.6, 0.98, NA, NA, 1.19,
   0.72, NA, NA, 1.19, 0.5, 1.11, NA, NA, 0.82, 1.16, 0.56, 1.21,
   NA, NA, 0.82, 0.5, 0.95, NA, NA, 0, 0.52, 0.96, 1.17, NA)

l <- c(NA, NA, NA, 0.31, 0.53, NA, NA, 0.31, 0.53, NA, NA, 0.44,
   0.43, NA, NA, 0.42, 0.27, 0.44, NA, NA, 0.28, 0.39, 0.26, 0.53,
   NA, NA, 0.49, 0.06, 0.27, NA, NA, 0, 0.25, 0.44, 0.31, NA)

u <- c(NA, NA, NA, 1.44, 1.62, NA, NA, 1.18, 1.82, NA, NA, 3.21,
   1.21, NA, NA, 3.41, 0.93, 2.76, NA, NA, 2.46, 3.46, 1.25,
   2.76, NA, NA, 1.37, 4.31, 3.39, NA, NA, Inf, 1.1, 2.07,
   4.38, NA)


forestplot(labeltext=tabletext,
   m=m,
   l=l,
   u=u,
   zero=1,
   clip=c(0, 3.5),
   align=c("r",rep("c",ncol(tabletext)-1)),
   xlab="Hazard Ratio",
   xlog=FALSE,
   col=meta.colors(box="royalblue",line="darkblue",
 summary="royalblue"),
   boxsize=.4
   )

Not considering for the moment a few problems with grading
section estimation, on my linux box labeltext columns overlap in the
graph produced;
is there a way to prevent this? What did i miss?


Thank you
  Luca

__
R-help@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.


Re: [R] multi-machine parallel setup?

2012-04-21 Thread ivo welch
hi uwe---my box is different:

cl <- makeCluster(c("localhost", "welch", "calc"), "SOCK")
Error in loadNamespace(name) : there is no package called 'snow'

this seems to be part of snow, not parallel.  ok, install snow first,
then rerun.

library(snow)
Attaching package: 'snow'

The following object(s) are masked from 'package:parallel':

clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, clusterSplit, makeCluster, parApply,
parCapply, parLapply,
parRapply, parSapply, splitIndices, stopCluster

bash: /Library/Frameworks/R.framework/Resources/bin/Rscript: No such
file or directory

but if I use two linux machines, it works.

now, how do I use parallel's mclapply with it?

best,

/iaw


Ivo Welch (ivo.we...@gmail.com)
J. Fred Weston Professor of Finance
Anderson School at UCLA, C519
http://www.ivo-welch.info/
Editor, Critical Finance Review, http://www.critical-finance-review.org/



2012/4/21 Uwe Ligges :
>
>
> On 21.04.2012 06:34, ivo welch wrote:
>>
>> the vignette to the library(parallel) mentions snow repeatedly (esp
>> differences in its implementation in parallel from the original).
>> unfortunately, it doesn't give an example or tutorial for
>> multi-machine use with sockets.
>>
>> could someone please point me to a simple working example, where a
>> master just has both itself and a 4-core slave on a second machine
>> (IP), and wants to execute an mclapply on a list on both machines,
>> like
>>
>>    master.ip<- "localhost"
>>    slave.ip<- "Rfriend@192.168.2.10"  ## has key ssh access
>>    mclapply( 1:100, function(x) { cat(x); Sys.sleep(1); x } )  # on both,
>> please
>>
>> iaw
>
>
>
>
> With appropriate ssh keys that do not need passwords and with the same
> username on all machines, it should work out of the box. At least, it does
> for me:
>
> Say you want two, one on your own machine, the other one on your friends:
>
>  cl <- makeCluster(c("localhost", "192.168.2.10"), "SOCK")
>
> BEst,
> Uwe Ligges
>
>
>>
>> On Wed, Apr 18, 2012 at 1:01 PM, ivo welch  wrote:
>>>
>>> Dear R experts:
>>>
>>> could someone please point me to a page that explains how to set up
>>> more than 1 machine for library parallel (which is quickly becoming my
>>> favorite!)
>>
>> ...
>>
>> __
>> R-help@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.

__
R-help@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.


Re: [R] ANOVA in quantreg - faulty test for 'nesting'?

2012-04-21 Thread Roger Koenker
Yes, the models are nested, and yes I probably should have been more clever
about parsing formulae, for these cases.  I'll have a look at the code for glm, 
I
presume that lm() is also capable of groking this?   Meanwhile, I would like to
point out that any of these linear restrictions can be reformulated as an 
exclusion
restriction, see for example the remark on pages 5-6 of 

http://www.econ.uiuc.edu/~roger/research/ranks/ranktests.pdf

or the references cited there.  And using this sort of parameterization you can
use anova.rq().


Roger Koenker
rkoen...@illinois.edu




On Apr 20, 2012, at 7:59 PM, Galen Sher wrote:

> Thanks to Brian's suggestion of using the logLik() function, I've dug a
> little deeper. I definitely think f1 and f2 are nested models. For example,
> by adding x2 to fmla1, we obtain a formula that quite clearly nests fmla1
> and achieves the same log likelihood as that obtained for f2. Here is the
> extra code to show this:
> 
> fmla3 = y~I(x1+x2)+x2
> f3=glm(fmla3)
> logLik(f1); logLik(f2); logLik(f3)
> 
> If f2=f3, as the log likelihoods would suggest, then this gives us a
> workaround: define the intermediate formula fmla3 and the fit f3 as above,
> and then conduct the analysis of variance between models f1 and f3 instead
> of f1 and f2. This doesn't offend anova.rq() any longer:
> 
> f3.qr = rq(fmla3)
> anova(f1.qr,f3.qr) #this is actually anova(f1.qr, f2.qr) which resulted in
> an error earlier
> 
> -Galen
> 
> On Fri, Apr 20, 2012 at 6:47 PM, Brian S Cade  wrote:
> 
>> Galen:  Interesting, first time I tried it I couldn't get anova.glm to
>> compute the p-values (got a warning) but I tried it again and it worked.
>> Your larger (alternative hypothesis) model is  y = B0 + B1*x1 + B2*x2 + e
>> and your smaller (null hypotheisis) model is y = B0 + B3*(x1 + x2).  So  I
>> guess I see that what you're trying to test in this case is that B1 = B2.
>> I don't think Roger Koenker anticipated such a test with anova.rq.  Other
>> options besides using information criteria (AIC, BIC, etc) for comparing
>> nonnested models include the Vuong test.  But not sure how readily the
>> theory of Vuong's test (like a paired t-test) extends to quantile
>> regression.
>> 
>> Brian
>> 
>> Brian S. Cade, PhD
>> 
>> U. S. Geological Survey
>> Fort Collins Science Center
>> 2150 Centre Ave., Bldg. C
>> Fort Collins, CO  80526-8818
>> 
>> email:  brian_c...@usgs.gov
>> tel:  970 226-9326
>> 
>> 
>> From: Galen Sher  To: Brian S Cade 
>> Date: 04/20/2012 09:59 AM Subject: Re: [R] ANOVA in quantreg - faulty
>> test for 'nesting'?
>> --
>> 
>> 
>> 
>> Thanks Brian. I think anova.glm() requires the user to specify the
>> appropriate distribution. In the example above, if I use either of the
>> following commands
>> 
>> anova(f1,f2,test="Chisq") #or
>> anova(f1,f2,test="F")
>> 
>> then anova.glm() will compute and display p-values associated with the
>> deviance statistics. The reason I thought these models are nested is
>> because the first model can be thought of as the second model estimated
>> under an additional linear equality constraint. I suppose that's less of an
>> R question and more of a regression question.
>> 
>> Thanks for the logLik suggestion. In the absence of more information I'll
>> have to do that - I'm just wary of conducting the test myself!
>> 
>> Regards,
>> Galen
>> 
>> On Fri, Apr 20, 2012 at 4:31 PM, Brian S Cade 
>> <*ca...@usgs.gov*>
>> wrote:
>> Galen:  Actually don't see how the models are nested (ask yourself what
>> parameter in the model with 3 parameters is set to zero in the 2 parameter
>> model?) and indeed if I try your code anova.glm will compute the difference
>> in deviance between the two models but it does not compute a probability
>> value for that difference in deviance as that would not make sense for
>> models that aren't nested.   Koenker's implementation of anova.rq
>> immediately detects that the models aren't nested so doesn't even compute
>> the deviance difference.  You could use the logLik function on the rq
>> objects to get their log likelihoods or use AIC (BIC) to compare the
>> quantile regression models.
>> 
>> Brian
>> 
>> Brian S. Cade, PhD
>> 
>> U. S. Geological Survey
>> Fort Collins Science Center
>> 2150 Centre Ave., Bldg. C
>> Fort Collins, CO  80526-8818
>> 
>> email:  *brian_c...@usgs.gov* 
>> tel:  *970 226-9326* <970%20226-9326>
>> 
>>  From: galen <*galens...@gmail.com* >  To: *
>> r-help@r-project.org*   Date: 04/19/2012 02:40 PM
>> Subject: [R] ANOVA in quantreg - faulty test for 'nesting'?  Sent by: *
>> r-help-boun...@r-project.org* 
>> 
>> --
>> 
>> 
>> 
>> 
>> I am trying to implement an ANOVA on a pair of quantile regression models
>> in
>> R. The anova.rq() function performs a basic check to see whether the models
>> are nested, but I think this check is failing in my case. I think my models
>> are nested despite the anova.rqlist() function saying otherwise. Here is 

Re: [R] hdf library for windows

2012-04-21 Thread Prof Brian Ripley

On 21/04/2012 13:30, will smith wrote:

What question?  Please see what the posting guide has to say about context.


The question puzzled me at first, because of your use of "library". It
looks as if the hdf5 r "package" utilises the "windows hdf5 library"
binary.

My reading is that you will have to compile the package yourself after
you have downloaded the hdf windows dll from hdf.ncsa.uiuc.edu The
instructions are in win.readme.txt of the package source which you can
download at planetmirror or aarnet.

I think the use of the hdf dll is the reason a windows binary cannot be
made available for direct download.


Not quite: it is the unavailability of a working 64-bit version that 
means it is not distributed from CRAN.




Ciao, Tom

_

Tom Mulholland
Senior Policy Officer
WA Country Health Service
Tel: (08) 9222 4062

The contents of this e-mail transmission are confidentia...{{dropped:10}}

__
R-help@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.



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@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.


Re: [R] multi-machine parallel setup?

2012-04-21 Thread Uwe Ligges



On 21.04.2012 06:34, ivo welch wrote:

the vignette to the library(parallel) mentions snow repeatedly (esp
differences in its implementation in parallel from the original).
unfortunately, it doesn't give an example or tutorial for
multi-machine use with sockets.

could someone please point me to a simple working example, where a
master just has both itself and a 4-core slave on a second machine
(IP), and wants to execute an mclapply on a list on both machines,
like

master.ip<- "localhost"
slave.ip<- "Rfriend@192.168.2.10"  ## has key ssh access
mclapply( 1:100, function(x) { cat(x); Sys.sleep(1); x } )  # on both, 
please

iaw




With appropriate ssh keys that do not need passwords and with the same 
username on all machines, it should work out of the box. At least, it 
does for me:


Say you want two, one on your own machine, the other one on your friends:

 cl <- makeCluster(c("localhost", "192.168.2.10"), "SOCK")

BEst,
Uwe Ligges




On Wed, Apr 18, 2012 at 1:01 PM, ivo welch  wrote:

Dear R experts:

could someone please point me to a page that explains how to set up
more than 1 machine for library parallel (which is quickly becoming my
favorite!)

...

__
R-help@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.


__
R-help@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.


Re: [R] odbcConnectExcelpel() fails to fetch all columns

2012-04-21 Thread Andrew Roberts

Thanks for your help,

I have exported the worksheet to .csv and it imports fine. I then 
reloaded the .csv back into Excel and  ... (red face) all the columns 
came across. I have no idea as to what was in the Excel worksheet that 
tripped up RODBC. I very much take your point Jeff but I have to work 
with what I'm given.


Kind regards to you both

Andrew

On 20/04/2012 23:58, andrija djurovic wrote:

Hi.
I use RODBC for importing Excel files quiet often and never got the
similar problem.

Have you tried with sqlQuery?


z<- odbcConnectExcel("./BBaselinePtQaires_apr2011.xls")

BQ<- sqlQuery(z, "select * from [BBaselinePtQaires$]")

Andrija

On Fri, Apr 20, 2012 at 11:57 PM, Jeff Newmiller
  wrote:

Excel is not a database, and the Excel ODBC driver is extremely limited. Put 
your data in a CSV file or a SQL database (even a Jet database is a step up 
from Excel).

  http://www.stata.com/support/faqs/data/odbc_excel.html
---
Jeff NewmillerThe .   .  Go Live...
DCN:  Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

Andrew Roberts  wrote:


Folks,

Is there a parameter somewhere in RODBC that enables more columns to be

retrieved from an Excel worksheet?

# This next bit uses an undocumented call in RODBC
z<- odbcConnectExcel("./BBaselinePtQaires_apr2011.xls")
BQ<- sqlFetch(z, "BBaselinePtQaires")

Gives me:

z RODBC[1]

And

BQ 134 obs. of 59 variables

I have all the rows in the worksheet but only the first 59 out of a
total of 70 columns. I’m in RStudio 0.95.263 using RODBC 1.3-3 and R
version 2.12.2 (2011-02-25).

I'm puzzled - the worksheet seems ok. If the worst comes to the worst I

will have to split the worksheet and cbind to put it back together but
that seems inelegant. The worksheet contains 134 rows, 70 columns and
is
in a spreadsheet that weighs in at 154 KB in total.

Can you help unbaffle me?

Andrew

__
R-help@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.

__
R-help@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.


__
R-help@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.


Re: [R] Solve an ordinary or generalized eigenvalue problem in R?

2012-04-21 Thread peter dalgaard

On Apr 21, 2012, at 15:22 , Luke Hartigan wrote:

> Hi all,
> 
> In my experience, using eigen to solve generalized eigenvalue / eigenvector
> problems only gives correct looking eigenvalues while the eigenvectors seem
> to be wrong (in comparison to results from MATLAB's 'eig' function for
> example).

Could you please document that? There are many misconceptions about when 
eigenvectors are "correct" and platform dependencies too. As far as I can tell, 
both R and Matlab use the same LAPACK routines.

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

__
R-help@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.


[R] how to write html output (webscraped using RCurl package) into file?

2012-04-21 Thread sagarnikam123
i want
"http://scop.berkeley.edu/astral/pdbstyle/?id=d1fjgc2&output=html",showing
information in webpage to be written in .txt file as it is(i don't want any
html tag)
i am using "RCurl" package

>marathi<-htmlTreeParse("http://scop.berkeley.edu/astral/pdbstyle/?id=d1fjgc2&output=html";)
>marathi
>kasam<-marathi$children$html[["body"]][["pre"]][["text"]]
>kasam
> write(kasam,"papita.txt")
Error in cat(list(...), file, sep, fill, labels, append) : 
  argument 1 (type 'list') cannot be handled by 'cat

i want to write kasam, as shown on console into  .txt file


--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-write-html-output-webscraped-using-RCurl-package-into-file-tp4576476p4576476.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] hdf library for windows

2012-04-21 Thread will smith
The question puzzled me at first, because of your use of "library". It
looks as if the hdf5 r "package" utilises the "windows hdf5 library"
binary.

My reading is that you will have to compile the package yourself after
you have downloaded the hdf windows dll from hdf.ncsa.uiuc.edu The
instructions are in win.readme.txt of the package source which you can
download at planetmirror or aarnet.

I think the use of the hdf dll is the reason a windows binary cannot be
made available for direct download.

Ciao, Tom

_

Tom Mulholland
Senior Policy Officer
WA Country Health Service
Tel: (08) 9222 4062

The contents of this e-mail transmission are confidentia...{{dropped:10}}

__
R-help@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.


Re: [R] Solve an ordinary or generalized eigenvalue problem in R?

2012-04-21 Thread Berend Hasselman

On 21-04-2012, at 11:40, Berend Hasselman wrote:

> 
> .
> See this:
> 
> 
> # This works on Mac OS X
> # Change as needed for other systems
> # or compile geigen into a standalone shared object.
> 
> dyn.load(file.path(R.home("lib"),"libRlapack.dylib"))
> 

Replacing the dyn.load line with

dyn.load(file.path(R.home("modules"),"lapack.so"))

lets run geigen1.R run on Mac OS X and Ubuntu unchanged.
Hopefully this is the proper way to load Lapack as provided by R.
How to do it on Windows, I can't test.

Berend

__
R-help@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.


Re: [R] Solve an ordinary or generalized eigenvalue problem in R?

2012-04-21 Thread Luke Hartigan
Hi all,

In my experience, using eigen to solve generalized eigenvalue / eigenvector
problems only gives correct looking eigenvalues while the eigenvectors seem
to be wrong (in comparison to results from MATLAB's 'eig' function for
example).

However, I think it is possible to solve generalized eigenvalue /
eigenvectors problems in R. The way I found that works in my case is to use
the simultaneous diagonalization method which is effectively two
applications of the 'svd' function.

I have used this myself to get results effectively the same (down to 6th
decimal place for example) as those from MATLAB.

Kind regards,
Luke

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Package "demography" - calculating percentiles of survival probabilities distribution

2012-04-21 Thread David Winsemius


On Apr 21, 2012, at 6:05 AM, jolo999 wrote:


Hi David,

thanks for your patience and your comment. Unfortunately, your code  
- if I

understood it correctly - is still not what I am looking for. I try to
describe an example as you suggested:


I was asking for a working example (as implied by suggesting you could  
start with one of the examples in the package help pages.)  Not a hand- 
waving exercise.




I assume that the Lee-Carter-Forecast-Modell generates different  
sample

paths or simulation runs, e.g. 1000 simulations.


Produce the code that does this. I offered code that produced a L-C-M  
forecast and that object (as far as I can tell)  doesn't meet  
assumptions you are making. So you must be using different code (or  
you have  a deeper understanding than I.)


--
David.



Within each simulation, a
mortality table is generated for all covered ages (0-100 in my case)  
and a

forecast period for x years.

What I am looking for is a possibility to extract percentiles from  
these

sample paths or simulations, for example:

What is the 50%tile (or 75%tile, 80%tile, 95%tile etc.) survival  
probability
of a (for example) 65 year old person in the first forecast year  
(FCY1)

based on the 1000 simulations or sample paths.

Now I want to let this 65 year old person age for the next 10 years  
that

means

--> What is the 50%ile (or 75%tile, 80%tile, 95%tile etc.) survival
probability of a 66 year old person in FCY2
--> What is the 50%ile (or 75%tile, 80%tile, 95%tile etc.) survival
probability of a 67 year old person in FCY3
--> What is the 50%ile (or 75%tile, 80%tile, 95%tile etc.) survival
probability of a 68 year old person in FCY4
... and so on.

Sorry, I dodn't know better to describe my problem. Hope you can help!

Thanks in advance and have a nice weekend!

Best
Jonas

--
View this message in context: 
http://r.789695.n4.nabble.com/Package-demography-calculating-percentiles-of-survival-probability-distribution-tp4575145p4576203.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


David Winsemius, MD
West Hartford, CT

__
R-help@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.


Re: [R] Package "demography" - calculating percentiles of survival probabilities distribution

2012-04-21 Thread jolo999
Hi David,

thanks for your patience and your comment. Unfortunately, your code - if I
understood it correctly - is still not what I am looking for. I try to
describe an example as you suggested:

I assume that the Lee-Carter-Forecast-Modell generates different sample
paths or simulation runs, e.g. 1000 simulations. Within each simulation, a
mortality table is generated for all covered ages (0-100 in my case) and a
forecast period for x years.

What I am looking for is a possibility to extract percentiles from these
sample paths or simulations, for example:

What is the 50%tile (or 75%tile, 80%tile, 95%tile etc.) survival probability
of a (for example) 65 year old person in the first forecast year (FCY1)
based on the 1000 simulations or sample paths.

Now I want to let this 65 year old person age for the next 10 years that
means

--> What is the 50%ile (or 75%tile, 80%tile, 95%tile etc.) survival
probability of a 66 year old person in FCY2
--> What is the 50%ile (or 75%tile, 80%tile, 95%tile etc.) survival
probability of a 67 year old person in FCY3
--> What is the 50%ile (or 75%tile, 80%tile, 95%tile etc.) survival
probability of a 68 year old person in FCY4
... and so on.

Sorry, I dodn't know better to describe my problem. Hope you can help!

Thanks in advance and have a nice weekend!

Best
Jonas

--
View this message in context: 
http://r.789695.n4.nabble.com/Package-demography-calculating-percentiles-of-survival-probability-distribution-tp4575145p4576203.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] shape parameter in 'normalp'

2012-04-21 Thread R^2
hi,

i tried to fit the GED for my sample. when doing this without the package
normalp i received a shape parameter p of about 0.5, whereas 'paramp' told
me that p is 1 sharp. for a leptokurtic shape p should be in a range of
0http://r.789695.n4.nabble.com/shape-parameter-in-normalp-tp4576043p4576043.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Splitting a dataframe by character vector

2012-04-21 Thread Ben Neal
Thank you Jorge. 

I did get subset to work on a character vector last night, the only difference 
being I used two equals signs: 

(not working) > Site1 <- subset(Cover, Site = "PtaCaracol")
(working) > Site1 <- subset(Cover, Site = = "PtaCaracol")

I am unsure why this is, but it worked. I believe this was the error, causing 
my returned dataframes to contain all the original entries. 

Thanks again; I will explore the plyr package as well. Ben 


-Original Message-
From: Jorge I Velez [mailto:jorgeivanve...@gmail.com]
Sent: Fri 4/20/2012 8:17 PM
To: Ben Neal
Subject: Re: [R] Splitting a dataframe by character vector
 
Dear Ben,

Check ?tapply, ?aggregate, ?ave for some ways to accomplish this using the
base package.  Also, check and check the plyr package at
http://plyr.had.co.nz/ along with the examples and accompanying paper.

HTH,
Jorge.-


On Fri, Apr 20, 2012 at 9:52 PM, Ben Neal <> wrote:

> I am just trying to split a dataframe of 750 observations of 29 variables
> by "Site", which is a vector in the dataframe with five text names (ex.
> PtaCaracol). I just want to generate summary statistics for my other
> variables for each site individually.
>
> I know this should be simple, and I did read up on options, choosing to
> use "subset", but I am honestly confounded that this does not result in a
> new dataframe split by this factor. I tried "subset" with an argument based
> on my various other numeric vectors, and it worked just fine. My very
> simple code is below, and thank you for any responses. I apologize for
> asking such a simple question, but I wrote this out exactly as found it in
> an exactly similar question, which indicated this should work. Now I am
> confused! Thank you for any assistance. Ben Neal
>
> # Load data from CSV file
> Cover = read.csv ("/Users/benjaminneal/Documents/1110_Panama/Transect
> series /1210_BocasTransectSummary.csv",
>   header=T)
> # Divide dataframe by Site names
> Site1 <- subset(Cover, Site = "PtaCaracol")
>
> PS The csv loads fine, gives normal summary stats, and does not seem to be
> the issue. I thought about just renaming by hand all the sites in the file
> (i.e. "PtaCaracol"=1 . . but this seems like a weak solution).
>
> __
> R-help@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.
>

__
R-help@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.


[R] xyplot - ordering factors in graph

2012-04-21 Thread pip
Hello - newbie
Have created a lattice graph and want to know how to sort one of the
elements which is a factor.
The factor numbers in graph are - eg - 10   32  21
  2
22  4 etc

Regards

--
View this message in context: 
http://r.789695.n4.nabble.com/xyplot-ordering-factors-in-graph-tp4576013p4576013.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] symmetric matrix on both diagonals

2012-04-21 Thread David Winsemius


On Apr 21, 2012, at 1:13 AM, Petr Savicky wrote:


On Fri, Apr 20, 2012 at 10:52:47AM -0400, David Winsemius wrote:


On Apr 20, 2012, at 7:05 AM, Petr Savicky wrote:


On Fri, Apr 20, 2012 at 03:03:40AM -0700, juliane0212 wrote:


I'm  having some problems computing a matrix being symmetric on  
both

diagonals.

Does anyone know a way to get from this matrix


M <- matrix(c(1,0,0,0,2,7,0,0,3,4,0,0,6,0,0,0), ncol=4)

to this one

M_final <- matrix(c(1,2,3,6,2,7,4,3,3,4,7,2,6,3,2,1),
ncol=4)


Hi.

Try the following.

M[row(M) > col(M)] <- t(M)[row(M) > col(M)]
n <- nrow(M)
M[row(M) + col(M) > n + 1] <- M[n:1, n:1][row(M) + col(M) > n + 1]
all(M == M_final)

[1] TRUE


How about?


M[3:4, ] <- rev(M[1:2,])
M

[,1] [,2] [,3] [,4]
[1,]1236
[2,]2743
[3,]3472
[4,]6321


Hi.

I am not sure, which matrix did you start from.



You are right. I misunderstood the requested task. (...and then used  
the wrong starting matrix.) Sorry for the noise.


--
David.



If we start
from the original matrix, then we get

 M <- matrix(c(1,0,0,0,2,7,0,0,3,4,0,0,6,0,0,0), ncol=4)
 M[3:4, ] <- rev(M[1:2,])
 M

  [,1] [,2] [,3] [,4]
 [1,]1236
 [2,]0740
 [3,]0470
 [4,]6321

where the components 2 and 3 have two and not four copies.

Petr.

__
R-help@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.


David Winsemius, MD
West Hartford, CT

__
R-help@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.


Re: [R] error loading tcltk2

2012-04-21 Thread Philippe Grosjean
There is indeed a bug in tcltk2, while I introduced some changes 
targeting a better look of Tk widgets on Ubuntu. This new code is 
assuming 'cat' is available on all platforms. Indeed on Windows, it *is* 
available iff Rtools are installed, which is the case apparently on all 
test machines so far, but the code fails otherwise.


I'll solve this bug this week-end (just testing if the platform is 
Windows makes the job here) and submit a new version as soon as 
possible. Sorry to all of you for the inconvenience it may have brought 
to your workflow.


Waiting for this fix to propagated on all mirrors, if you urgently need 
tcltk2, you know that you still can install Rtools as a temporary 
work-around on one or the other test machine, which could be useful 
anyway, if you are developing/compiling R packages...


Best,

Philippe


On 20/04/12 17:21, peter dalgaard wrote:


On Apr 20, 2012, at 16:03 , Duncan Murdoch wrote:


On 20/04/2012 8:41 AM, Roberto Ugoccioni wrote:

Hello,
I just installed R-2.15.0 on windows XP and cannot load package tcltk2
(which I just downloaded from CRAN as tcltk2_1.2-1.zip; package install
reported no problems):


  library(tcltk2)

Carico il pacchetto richiesto: tcltk
Loading Tcl/Tk interface ... done
Error : .onLoad failed in loadNamespace() for 'tcltk2', details:
   call: system("cat /etc/issue", intern = TRUE, ignore.stderr = TRUE)
   error: 'cat' not found
Errore: package/namespace load failed for ‘tcltk2’
It seems .onLoad is trying to run a unix command 'cat' but i'm on a windows
platform:

  str(.Platform)

List of 8
  $ OS.type   : chr "windows"
  $ file.sep  : chr "/"
  $ dynlib.ext: chr ".dll"
  $ GUI   : chr "Rgui"
  $ endian: chr "little"
  $ pkgType   : chr "win.binary"
  $ path.sep  : chr ";"
  $ r_arch: chr "i386"

  sessionInfo()

R version 2.15.0 (2012-03-30)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=Italian_Italy.1252  LC_CTYPE=Italian_Italy.1252
[3] LC_MONETARY=Italian_Italy.1252 LC_NUMERIC=C
[5] LC_TIME=Italian_Italy.1252
attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base
I looked for an R file in the tcltk2 installed package tree containing the
above system() call but could not find it.
This looks like a bug to me but I'd like to ask for further advice before
reporting it as such, I might have overlooked something. Thanks for any
help.


I'd suggest you should contact the package maintainer. It's not hard to find a 
copy of the cat utility function (e.g. in the Rtools used for building R and 
packages), but the error does suggest the package may not be intended to be 
used on Windows.


It's intended for Windows alright... However, the nit seems to be this:


tcltk2:::.isUbuntu

function ()
return(grepl("^Ubuntu", suppressWarnings(system("cat /etc/issue",
 intern = TRUE, ignore.stderr = TRUE))[1]))

which gets called unconditionally in tcltk:::.onLoad(). It could at least check 
that there is room to swing a cat



Duncan Murdoch

__
R-help@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.




__
R-help@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.


Re: [R] Solve an ordinary or generalized eigenvalue problem in R?

2012-04-21 Thread Berend Hasselman

On 20-04-2012, at 21:18, Jonathan Greenberg wrote:

> Ok, I figured out a solution and I'd like to get some feedback on this from
> the R-helpers as to how I could modify the following to be "package
> friendly" -- the main thing I'm worried about is how to dynamically set the
> "dyn.load" statement below correctly (obviously, its hard coded to my
> particular install, and would only work with windows since I'm using a
> .dll):
> 
> Rdggev <- function(JOBVL=F,JOBVR=T,A,B)
> {
> # R implementation of the DGGEV LAPACK function (with generalized
> eigenvalue computation)
> # See http://www.netlib.org/lapack/double/dggev.f
> # coded by Jonathan A. Greenberg 
> dyn.load("C:\\Program Files\\R\\R-2.14.2\\bin\\x64\\Rlapack.dll")
> 
> if(JOBVL)
> {
> JOBVL="V"
> } else
> {
> JOBVL="N"
> }
> if(JOBVR)
> {
> JOBVR="V"
> } else
> {
> JOBVR="N"
> }
> # Note, no error checking is performed.
> # Input parameters
> N=dim(A)[[1]]
> LDA=N
> LDB=N
> LDVL=N
> LDVR=N
> LWORK=as.integer(max(1,8*N))
> Rdggev_out <- .Fortran("dggev", JOBVL, JOBVR, N, A, LDA, B, LDB,
> double(N), double(N), double(N),
> array(data=0,dim=c(LDVL,N)), LDVL, array(data=0,dim=c(LDVR,N)), LDVR,
> double(max(1,LWORK)), LWORK, integer(1))
> 
> names(Rdggev_out)=c("JOBVL","JOBVR","N","A","LDA","B","LDB","ALPHAR","ALPHAI",
> "BETA","VL","LDVL","VR","LDVR","WORK","LWORK","INFO")
> 
> Rdggev_out$GENEIGENVALUES=(Rdggev_out$ALPHAR+Rdggev_out$ALPHAI)/Rdggev_out$BETA
> return(Rdggev_out)
> }
> 

See this:


# This works on Mac OS X
# Change as needed for other systems
# or compile geigen into a standalone shared object.

dyn.load(file.path(R.home("lib"),"libRlapack.dylib"))

geigen <- function(A,B,jobvl=FALSE,jobvr=FALSE) {

# simplistic interface to Lapack dggev
# for generalized eigenvalue problem
# general matrices
# for symmetric matrices use dsygv

if(!is.matrix(A)) stop("Argument A should be a matrix")
if(!is.matrix(B)) stop("Argument B should be a matrix")
dimA <- dim(A)
if(dimA[1]!=dimA[2]) stop("A must be a square matrix")
dimB <- dim(B)
if(dimB[1]!=dimB[2]) stop("B must be a square matrix")
if(dimA[1]!=dimB[1]) stop("A and B must have the same dimensions")

if( is.complex(A) ) stop("A may not be complex")
if( is.complex(B) ) stop("B may not be complex")

jobvl.char <- if(jobvl) "V" else "N"
jobvr.char <- if(jobvr) "V" else "N"

n <- dimA[1]

# minimum amount of work memory
# for performance this needs to be set properly 
# (see source dggev)

lwork <- as.integer(8*n)
work <- numeric(lwork)

if( jobvl && jobvr )
z <- .Fortran("dggev", jobvl.char, jobvr.char, n, A, n, B, n, 
alphar=numeric(n), alphai=numeric(n),
  beta=numeric(n), vl=matrix(0,nrow=n,ncol=n), n, 
vr=matrix(0,nrow=n,ncol=n), n,
  work, lwork,info=integer(1L))
else if(jobvl && !jobvr )
z <- .Fortran("dggev", jobvl.char, jobvr.char, n, A, n, B, n, 
alphar=numeric(n), alphai=numeric(n),
  beta=numeric(n), vl=matrix(0,nrow=n,ncol=n), n, 
numeric(1), 1L,
  work, lwork,info=integer(1L))
else if(!jobvl && jobvr )
z <- .Fortran("dggev", jobvl.char, jobvr.char, n, A, n, B, n, 
alphar=numeric(n), alphai=numeric(n),
  beta=numeric(n), numeric(1),1L, 
vr=matrix(0,nrow=n,ncol=n), n,
  work, lwork,info=integer(1L))
else
z <- .Fortran("dggev", jobvl.char, jobvr.char, n, A, n, B, n, 
alphar=numeric(n), alphai=numeric(n),
  beta=numeric(n), numeric(1), 1L,  numeric(1), 1L,
  work, lwork,info=integer(1L))

if( z$info > 0 ) stop(paste("Lapack  dggev fails with info=",z$info))

# simplistic calculation of eigenvalues (see caveat in source dggev)
if( all(z$alphai==0) )
values <- z$alphar/z$beta
else
values <- complex(real=z$alphar, imaginary=z$alphai)/z$beta

if( jobvl && jobvr )
return(list(values=values, vl=z$vl, vr=z$vr))
else if( jobvl )
return(list(values=values, vl=z$vl))
else if( jobvr )
return(list(values=values, vr=z$vr))
else
return(list(values=values))   
}

A <- matrix(c(1457.738, 1053.181, 1256.953,
  1053.181, 1213.728, 1302.838,
  1256.953, 1302.838, 1428.269), nrow=3, byrow=TRUE)

B <- matrix(c(4806.033, 1767.480, 2622.744,
  1767.480, 3353.603, 3259.680,
  2622.744, 3259.680, 3476.790), nrow=3, byrow=TRUE)

A
B

geigen(A, B)
geigen(A, B, TRUE , TRUE)
geigen(A, B, TRUE , FALSE)
geigen(A, B, FALSE, TRUE)



Berend

__
R-help@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

Re: [R] Fwd: User defined panel functions in lattice

2012-04-21 Thread Duncan Mackay

Bert
I have read Deepayan's book and done all the examples but there is no 
mention of panel.number and panel.groups in the books example.


I just cannot get the fully meaning of what has been written 
regarding passing arguments to panel functions.


Regards

Duncan



At 14:31 21/04/2012, you wrote:

A comment...

On Fri, Apr 20, 2012 at 8:32 PM, Duncan Mackay  wrote:
> Hi David, ilai
>
> The root cause of the problem is the passing of arguments to 
panel functions

> to me and my colleagues.
> Just going through the archives there seems to be different ways for very
> similar/same outcomes and
> trying to get a pattern is hard to discern.

Bad strategy!  Trying to infer the rules from examples in complex
cases -- and as you said, different equivalent ways -- is nuts. You
need to read the docs carefully (including Deepayan's book, possibly)
and use the examples for understanding what is explained there.

Finally, I don't know if this is relevant or helpful but:

## this code works fine
 xyplot(rnorm(5) ~ 1:5, type="l",
  panel = function(...)panel.xyplot(...,lwd=2))

## This code throws an error about repeat lwd arguments. Is it obvious why?
 xyplot(rnorm(5) ~ 1:5,  lwd=1,type="l",
  panel = function(...) panel.xyplot(...,lwd=2))

-- Bert

> I frequently have to use the subscripts or group.number to access other
> data.
> I thought I had things sorted out in my head with the panel.groups and
> group.number but this has shattered it.
>
> Thanks
>
> Duncan
>
> At 12:15 21/04/2012, you wrote:
>
>> On Apr 20, 2012, at 9:14 PM, ilai wrote:
>>
>>> Oops - that is "reply all"
>>> On Fri, Apr 20, 2012 at 5:29 PM, David Winsemius >> > wrote:


 I'm a bit puzzled by this exchange. I know there is a
 'panel.locfit', but
 you two are spelling it differently. Can you explain why you are
 doing so?
>>>
>>>
>>> Hi David,
>>> Thanks for stepping in. panel.Locfit is the OP's local function (or
>>> just a wrapper ?) which I believe is here
>>> http://www.mail-archive.com/r-help@r-project.org/msg167164.html
>>>
>>> Note the two errors OP encountered (solved down the thread) were
>>> caused by the way he called the function in xyplot, not by
>>> panel.Locfit itself, which I did not modify. I guess now the issue is
>>> how to generalize panel.Locfit somehow, but I am not sure how. I
>>> suspect the problem is not my understanding but that there really
>>> isn't any one specific problem here for the list to solve, though,
>>> again, I am known for misinterpreting OP requests... :)
>>>
> ?panel.locfit
>>>
>>>
>>> As I said, I am unfamiliar with the package - but this doesn't
>>> surprise me. Thank you for pointing it out, wish you've noticed the
>>> exchange sooner...
>>
>>
>> Another puzzle. In the original posting there was this segment:
>> ---
>> but gives an error message without par.settings if i want to add
>>   panel.Locfit(x,y,nn= 0.9,lwd = c(1,2,3), ...)
>>
>> Error using packet 1
>> formal argument "Iwd" matched by multiple actual arguments
>> ---
>>
>> On my mailer that formal argument starts with a capital "I" but the
>> code seemed to be attempting a lowercase "l".
>>
>> I could never see reason offered for defining a new panel.locfit, but
>> I'm wondering if the sometimes similar representation of those two
>> different letters could be causing an obscure conflict?
>>
>> --
>> David.
>>>
>>>
>>> Cheers
>>>
>>>
> ?panel.Locfit

 No documentation for 'panel.Locfit' in specified packages and
 libraries:
 you could try '??panel.Locfit'

> ?panel.locfit


 {locfit}R Documentation
 Locfit panel function

 Description

 This panel function can be used to add locfit fits to plots
 generated by
 trellis.



> I am trying to construct a function/s to cover as many of the normal
> situations as possible.
> Usually I have to amend colours lines etc to distinguish the data.
>
> I want to cover a number of situations
> 1 Conditioned by panel no groups
> 2 Conditioned by panel and groups.
> 3 Multiple values for above - to show colleagues (EDA)
> 4 Conditioned by panel and groups + an overall fit for all the
> data within
> a panel
> 5 Several y values in a panel eg Y1+Y2 and outer = FALSE with a
> fit for
> each of Y1 and Y2
>
> I am trying to cover as many of the above situations in 1 function
> before
> resulting to trellis.focus or
> overlaying. The graphs that I normally create are not simple,
> generally
> involving useOuterStrips
> which may have different y scales for panel rows (combindeLimits/
> manual)
> and different panel row heights.
>
> locfit is like loess but 2 arguments for smoothing; the degree of
> smoothing produced by the defaults
> is approximately that of loess but I normally need less smoothing
> (the
> same would be apply for loess).
>
> Most

[R] Interval censorin

2012-04-21 Thread Christopher Kelvin
Hello,
May i know whether it is possible to generate data twice from Weibull 
distribution and use one as the start time and the 
other as the end time, below is my code.
Any suggestion on how to estimate the parameters of Weibull distribution with 
interval data will be highly appreciated.
Thank you

shape=2;scale=4;rr=5000
for(i in 1:rr){
x<-rweibull(50,shape,scale)
y=rweibull(50,shape,scale)
w=Surv(y,x,type="interval2")
}
w

Chris Guure
Researcher 
Institute for Mathematical Research
UPM

__
R-help@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.


Re: [R] Problem with Tukey test

2012-04-21 Thread danipaty13
sorry i uploaded the wrong file but with the one i uploaded happens the same
error, it was just as an example 

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-Tukey-test-tp4573945p4575946.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Problem with Tukey test

2012-04-21 Thread danipaty13
thank you s much i just tried the code you posted and worked perfectly

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-Tukey-test-tp4573945p4575943.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.