Re: [R] symmetric matrix on both diagonals

2012-04-20 Thread Petr Savicky
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. 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.


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

2012-04-20 Thread Bert Gunter
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 of the questions to Rhelp are for 1 with just a small number
> for 5
> and they are not applicable here
> and understanding the requirements for passing arguments in these
> different situations I find difficult.
> I would like to reduce the number of panel functions to the
> minimu

Re: [R] multi-machine parallel setup?

2012-04-20 Thread ivo welch
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


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.


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

2012-04-20 Thread ilai
On Fri, Apr 20, 2012 at 8:15 PM, David Winsemius  wrote:
>
> 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?
>

If that is indeed what's happening, it will be the first time for me.
My mailer shows upper case "L" too, I assume that this is correct and
the OP's intention is exactly that - not redefine panel.locfit but
create his own (if that is good use of his/our time is another matter
altogether). Seems to me the source of this error was, as the error
message suggested, simply the "default" formals:

 panel.Locfit <-
 function(x,y, nn, h, col, col.line, lwd = lwd, lty = lty, ...){
...
}

Which is why this solved it:

  xyplot(y ~x,xx,
   groups = Farm,
   auto.key=TRUE,lwd=1:3,
   panel = panel.superpose,panel.groups=function(x,y,nn,...){
  panel.Locfit(x,y,nn=.9,...)
  panel.xyplot(x,y,...)
}
   )

With my new found understanding of the OP's real intentions, maybe a
call to trellis.par.get('superpose.line') inside panel.Locfit is the
answer?

Cheers

> --
> 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 of the questions to Rhelp are for 1 with just a small number for 5
 and they are not applicable here
 and understanding the requirements for passing arguments in these
 different situations I find difficult.
 I would like to reduce the number of panel functions to the minimum to
 cover the general situaltions because
 my graphs are usually not normal and then add to them for a particular
 situation.

 Regards

 Duncan


 At 01:38 21/04/2012, you wrote:
>
>
> Duncan,
> First off, I admit it is not clear to me what you are trying to
> achieve and more importantly, why? by "why" I mean 1) I don't see the
> advantage of writing one general panel function for completely
> different situations (one/multiple smoothers, grouping levels etc.) 2)
> your intended result as I understand it seems rather cluttered, google
> . 3) I am unfamiliar with locfit package, but are we
> reinventing the wheel here ? i.e. will modifying settings in xyplot(y
> ~x, xx, groups = Farm, type=c('p','smooth')) achieve the same ?
>
> With your initial reproducible example (thank you) it was easy to
> eliminate the errors, but clearly the resulting plots are not what you
> intended (continue inline):
>
> On Thu, Apr 19, 2012 at 4:23 PM, Duncan Mackay 
> wrote:
> 
>>
>> 3. What I want to be able to add in the above is extra lines with
>> different
>> values of nn.
>>  I think I will have to modify panel.Locfit so that it goes through
>> different values of nn in each of the panels and groups if I want
>> different
>> colours for extra lines with different nn values
>
>
> Yes you could. There are several options:
> add group.number to the arguments of panel.locfit and u

Re: [R] Splitting a dataframe by character vector

2012-04-20 Thread Rolf Turner

On 21/04/12 13:52, 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).


What about a ***reproducible*** example?

What isn't working?  What (if any) error message did you get?

I am at least 99% confident that numeric versus character values in 
Cover$Site

is completely irrelevant.

My ***guess*** (and it can only be a guess, given the vagueness and
lack of detail in your question) is that you need a double ("logical")
equals sign.  I.e. I suspect that

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

will work.

That being said --- since you want to *split* your  data frame by "Site" ---
why the  don't you use split()???

E.g.:

Splitz <- split(Cover,Cover$Site)

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] Fwd: User defined panel functions in lattice

2012-04-20 Thread Duncan Mackay

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.
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 of the questions to Rhelp are for 1 with just a small number
for 5
and they are not applicable here
and understanding the requirements for passing arguments in these
different situations I find difficult.
I would like to reduce the number of panel functions to the
minimum to
cover the general situaltions because
my graphs are usually not normal and then add to them for a
particular
situation.

Regards

Duncan


At 01:38 21/04/2012, you wrote:


Duncan,
First off, I admit it is not clear to me what you are trying to
achieve and more importantly, why? by "why" I mean 1) I don't see
the
advantage of writing one general panel function for completely
different situations (one/multiple smoothers, grouping levels
etc.) 2)
your intended result as I understand it seems rather cluttered,
google
. 3) I am unfamiliar with locfit package, but are we
reinventing the wheel here ? i.e. will modifying settings in
xyplot(y
~x, xx, groups = Farm, type=c('p','smooth')) achieve the same ?

With your initial reproducible example (thank you) it was easy to
eliminate the errors, but clearly the resulting plots are not
what you
intended (continue inline):

On Thu, Apr 19, 2012 at 4:23 PM, Duncan Mackay 
wrote:


3. What I want to be able to add in the above is extra lines with
different
values of nn.
  I think I will have to modify panel.Locfit so that it goes
through
different values of nn in each of the panels and groups if I want
different
colours for extra lines with different 

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

2012-04-20 Thread Duncan Mackay

Hi David

if you go

library(locfit)
? panel.locfit
The function will do contour/wireframe like plots using par.settings 
of region as well as normal 2D plots
I could not get panel.locfit to work using par.settings  and created 
my own panel function as panel.Locfit

at the time I did not think that I would be putting it on the web.
(I knew it would be confusing to some but forgot to change the name. 
[its been a long week]).


In the first instance I wanted a panel function to produce confidence 
bands which I cobbled up, but then wanted lines in another situation.


Duncan

At 09:29 21/04/2012, you wrote:


On Apr 20, 2012, at 6:36 PM, Duncan Mackay wrote:


Hi ilai

Thank you for your advice I think I can now get what I need from
what you have said here.
I think I may have to get involved in packet.number but the original
packet.number with its arguments has stuck in my mind and I have not
used it.
I find locfit better than loess etc for a lot of the data I work with.


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?

> ?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 of the questions to Rhelp are for 1 with just a small number
for 5 and they are not applicable here
and understanding the requirements for passing arguments in these
different situations I find difficult.
I would like to reduce the number of panel functions to the minimum
to cover the general situaltions because
my graphs are usually not normal and then add to them for a
particular situation.

Regards

Duncan


At 01:38 21/04/2012, you wrote:

Duncan,
First off, I admit it is not clear to me what you are trying to
achieve and more importantly, why? by "why" I mean 1) I don't see the
advantage of writing one general panel function for completely
different situations (one/multiple smoothers, grouping levels etc.)
2)
your intended result as I understand it seems rather cluttered,
google
. 3) I am unfamiliar with locfit package, but are we
reinventing the wheel here ? i.e. will modifying settings in xyplot(y
~x, xx, groups = Farm, type=c('p','smooth')) achieve the same ?

With your initial reproducible example (thank you) it was easy to
eliminate the errors, but clearly the resulting plots are not what
you
intended (continue inline):

On Thu, Apr 19, 2012 at 4:23 PM, Duncan Mackay 
 wrote:


> 3. What I want to be able to add in the above is extra lines with
different
> values of nn.
>   I think I will have to modify panel.Locfit so that it goes
through
> different values of nn in each of the panels and groups if I want
different
> colours for extra lines with different nn values

Yes you could. There are several options:
add group.number to the arguments of panel.locfit and use it to make
nn a vector, along the lines of
   panel.foo <- function(x,y,group.number,theta,...){
 smpar <- theta[group.number]
 panel.loess(x,y,smpar,...)
 panel.xyplot(x,y,...)
   }
xyplot (y ~ x ,xx ,group 
=Farm,theta=c(4,1,.4),panel=panel.superpose,panel.groups=panel.foo)


# or
xyplot(y~x|Farm,xx,group=Padd,theta=c(.6,1),
   panel=panel.superpose,panel.groups=panel.foo)

Here you will need to modify the Farm group to 6 levels - 3*two
smoothers.

You could make nn a list and loop over it inside the panel function.
Looks like you tried something like that with specifying 2
panel.Locfit, one suggestion to your code:

panel.Locfit(x,y,...) # default 0.7
   panel.Locfit(x,y,nn=0.9)   # i.e. remove the
... to avoid clashes

Finally, use ?trellis.focus to plot the second smoother "post-hoc".
also the latticeExtra package has many useful tools to create layers
of the same (or different) 

Re: [R] Barplot problem

2012-04-20 Thread Mark Lamias
Here is an example you can use:
 #Generate random normal variables to use as dummy data for Fisher's Alpha
alphaBCI<-rnorm(100)
 
#Assume you have 5 sites, each with 20 data points
sites<-rep(c("Site 1", "Site 2", "Site 3", "Site 4", "Site 5"), each=20)
 
#Making sites a factor will produce the stratified boxplots
sites<-as.factor(sites)
 
#Produce boxplot
boxplot(alphaBCI~sites)



From: André Silva 
To: r-help@r-project.org 
Sent: Friday, April 20, 2012 8:28 PM
Subject: [R] Barplot problem

Hello,
I have little experience with r, so I wonder if someone could help me?
I need to plot a diversity measure (Fisher`s alpha) for different sites. I
calculated the values using the following commands:

Data(BCI)
alphaBCI <- fisher.alpha(BCI)

I need boxplots showing the data variation between sites. Then I tried:
boxplot(as.data.frame(alphaBCI))

However, it does not appear the box plots for different sites but only the
boxplots for alpha, se, df. Residual and code?

Do anyone know the right expression?

Thank you very much,

Bert

    [[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.
[[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] Splitting a dataframe by character vector

2012-04-20 Thread Ben Neal
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.


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

2012-04-20 Thread Galen Sher
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 an
> example where the GLM ANOVA regards the models as nested, but the quantile
> regression ANOVA tells me the models aren't nested:
>
> y = rnorm(100)
> x1 = rnorm(100)
> x2 = rnorm(100)
>
> fmla1 = y~I(x1+x2)
> fmla2 = y~x1+x2
>
> f1 = glm(fmla1)
> f2 = glm(fmla2)
>
> anova(f1,f2) #This works
>
> f1.qr = rq(fmla1)
> f2.qr = rq(fmla2)
>
> anova(f1.qr,f2.qr) #Error!
> #Error in anova.rqlist(object, ...) : Models aren't nested
>
> Are the models in fact not nested? If they are nested, is there an easy
> workaround I could use? Many thanks in anticipation.
>
> --
> View this message in context: *
> http://r.789695.n4.nabble.com/ANOVA-in-quantreg-faulty-test-for-nesting-tp4571994p4571994.html
> *

[R] Barplot problem

2012-04-20 Thread André Silva
Hello,
I have little experience with r, so I wonder if someone could help me?
I need to plot a diversity measure (Fisher`s alpha) for different sites. I
calculated the values using the following commands:

Data(BCI)
alphaBCI <- fisher.alpha(BCI)

I need boxplots showing the data variation between sites. Then I tried:
boxplot(as.data.frame(alphaBCI))

However, it does not appear the box plots for different sites but only the
boxplots for alpha, se, df. Residual and code?

Do anyone know the right expression?

Thank you very much,

Bert

[[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] Problem with Tukey test

2012-04-20 Thread Alex_Ponce
HELLO

WELCOME TO R

here is your code:
I'm new using R im trying to do a tukey test, but when i see the results the
p value results in NA im guessing its because i have missing values but im
not sure how to fix it

AnovaModel.2 <- aov() 

If your original data.frame or your raw data have "NA's" you must to write
this part

AnovaModel.2 <- aov(area ~ trat, na.action=na.omit, , data=apilados)

I hope that work in this way

suerte!!!
Alex Ponce


--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-Tukey-test-tp4573945p4575738.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] Fwd: User defined panel functions in lattice

2012-04-20 Thread David Winsemius


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 of the questions to Rhelp are for 1 with just a small number  
for 5

and they are not applicable here
and understanding the requirements for passing arguments in these
different situations I find difficult.
I would like to reduce the number of panel functions to the  
minimum to

cover the general situaltions because
my graphs are usually not normal and then add to them for a  
particular

situation.

Regards

Duncan


At 01:38 21/04/2012, you wrote:


Duncan,
First off, I admit it is not clear to me what you are trying to
achieve and more importantly, why? by "why" I mean 1) I don't see  
the

advantage of writing one general panel function for completely
different situations (one/multiple smoothers, grouping levels  
etc.) 2)
your intended result as I understand it seems rather cluttered,  
google

. 3) I am unfamiliar with locfit package, but are we
reinventing the wheel here ? i.e. will modifying settings in  
xyplot(y

~x, xx, groups = Farm, type=c('p','smooth')) achieve the same ?

With your initial reproducible example (thank you) it was easy to
eliminate the errors, but clearly the resulting plots are not  
what you

intended (continue inline):

On Thu, Apr 19, 2012 at 4:23 PM, Duncan Mackay >

wrote:


3. What I want to be able to add in the above is extra lines with
different
values of nn.
  I think I will have to modify panel.Locfit so that it goes  
through

different values of nn in each of the panels and groups if I want
different
colours for extra lines with different nn values


Yes you could. There are several options:
add group.number to the arguments of panel.locfit and use it to  
make

nn a vector, along the lines of
  panel.foo <- function(x,y,group.number,theta,...){
smpar <- theta[group.number]
panel.loess(x,y,smpar,...)
panel.xyplot(x,y,...)
  }

xyplot 
(y 
~ 
x 
,xx 
,group 
=Farm,theta=c(4,1,.4),panel=panel.superpose,panel.groups=panel.foo)


# or
xyplot(y~x|Farm,xx,group=Padd,

[R] Paulo Sousa deixou uma mensagem para você...

2012-04-20 Thread Badoo
Paulo Sousa deixou uma mensagem para você...

Só você pode ler o conteúdo desta mensagem e ver quem a enviou. Delete a 
qualquer momento  ou responda imediatamente com o sistema de troca de 
mensagens. Para descobrir o que diz a mensagem, siga este link. 
http://eu1.badoo.com/0278107725/in/UF9TQJxYedg/?lang_id=61&m=63&mid=4f9211a5003d3d6bbb2a

Mais gente dessa região que está no Badoo
Photographer (Masquat, Omã)
Anna (Москва, Russia)
Matanmi (Ilorin, Nigéria)
Narillo (Valência, Espanha)
Wojtek (Varsóvia, Polônia)
... Quem mais?
http://eu1.badoo.com/0278107725/in/UF9TQJxYedg/?lang_id=61&m=63&mid=4f9211a5003d3d6bbb2a

Se o link desta mensagem não funcionar, copie e cole-o em seu navegador. 

Este email faz parte de nosso sistema de entrega para a mensagem enviada por 
Paulo Sousa. Se recebeu este email por engano, por favor ignore-o. A mensagem 
será deletada em breve. 

Divirta-se!
A Equipe Badoo

Este email foi enviado por Badoo Trading Limited (endereço postal abaixo). 
http://eu1.badoo.com/impersonation.phtml?lang_id=61&mail_code=63&email=r-help%40r-project.org&secret=&action=block&block_code=7ea63e&m=63&mid=4f9211a5003d3d6bbb2a
Badoo Trading Limited é uma empresa registrada na Inglaterra e País de Gales 
com CRN 7540255 e firma registrada no seguinte endereço 12 Red Lion Square, 
Londres, WC1R 4QD.
[[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-20 Thread ilai
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...

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 of the questions to Rhelp are for 1 with just a small number for 5
>> and they are not applicable here
>> and understanding the requirements for passing arguments in these
>> different situations I find difficult.
>> I would like to reduce the number of panel functions to the minimum to
>> cover the general situaltions because
>> my graphs are usually not normal and then add to them for a particular
>> situation.
>>
>> Regards
>>
>> Duncan
>>
>>
>> At 01:38 21/04/2012, you wrote:
>>>
>>> Duncan,
>>> First off, I admit it is not clear to me what you are trying to
>>> achieve and more importantly, why? by "why" I mean 1) I don't see the
>>> advantage of writing one general panel function for completely
>>> different situations (one/multiple smoothers, grouping levels etc.) 2)
>>> your intended result as I understand it seems rather cluttered, google
>>> . 3) I am unfamiliar with locfit package, but are we
>>> reinventing the wheel here ? i.e. will modifying settings in xyplot(y
>>> ~x, xx, groups = Farm, type=c('p','smooth')) achieve the same ?
>>>
>>> With your initial reproducible example (thank you) it was easy to
>>> eliminate the errors, but clearly the resulting plots are not what you
>>> intended (continue inline):
>>>
>>> On Thu, Apr 19, 2012 at 4:23 PM, Duncan Mackay 
>>> wrote:
>>> 
>>> > 3. What I want to be able to add in the above is extra lines with
>>> > different
>>> > values of nn.
>>> >   I think I will have to modify panel.Locfit so that it goes through
>>> > different values of nn in each of the panels and groups if I want
>>> > different
>>> > colours for extra lines with different nn values
>>>
>>> Yes you could. There are several options:
>>> add group.number to the arguments of panel.locfit and use it to make
>>> nn a vector, along the lines of
>>>   panel.foo <- function(x,y,group.number,theta,...){
>>>     smpar <- theta[group.number]
>>>     panel.loess(x,y,smpar,...)
>>>     panel.xyplot(x,y,...)
>>>   }
>>>
>>> xyplot(y~x,xx,group=Farm,theta=c(4,1,.4),panel=panel.superpose,panel.groups=panel.foo)
>>>
>>> # or
>>> xyplot(y~x|Farm,xx,group=Padd,theta=c(.6,1),
>>>   panel=panel.superpose,panel.groups=panel.foo)
>>>
>>> Here you will need to modify the Farm group to 6 levels - 3*two
>>> smoothers.
>>>
>>> You could make nn a list and loop over it inside the panel function.
>>> Looks like you tried something like that with specifying 2
>>> panel.Locfit, one suggestion to your code:
>>>
>>>                    panel.Locfit(x,y,...) # default 0.7
>>>                       panel.

Re: [R] lines on persp plot - proper depth ordering

2012-04-20 Thread Duncan Murdoch

On 20/04/2012 2:48 PM, Nate Cermak wrote:

Hello R-help!
I am trying to draw series of lines in 3d, and I am not sure how to get the
depth set up properly - lines that are in front of other lines appear to be
behind and vice versa. I've been doing this by first generating an empty
persp plot, then adding lines via the data into trans3d followed by lines
(this is probably a bad approach, but it was the first one I could get
working).


The only possibility with persp is for you to draw the ones that need to 
be behind first, the ones in front later. Persp can't do it, you have 
to.  The rgl package can do the sorting, but there are other limitations 
in it that you might not find acceptable, particularly in output formats.


Duncan Murdoch



Here is a semi-contrived minimal example of my problem:

###
#line 1
x1=0:10;
y1=rep(0,11);
z1 = rep(5,11);

#line 2
x2=y2=z2 = 0:10

# make empty persp plot (awful hack to make a surface out of view)
pmat = persp(x=c(-10.1,-10), y=c(-10.1,-10), z=matrix(c(0,.1,0,.1),
nrow=2),
 xlim=c(0,10), ylim=c(0,10), zlim=c(0,10), xlab='x', ylab='y', zlab='z')

# now draw the lines
lines( trans3d(x1, y1, z1,pmat), col="grey", lwd=3)
lines( trans3d(x2, y2, z2,pmat), col="red", lwd=3)
#

Ideally, the red line would occur behind the grey line (and in this
example, I could very simply switch the order and fix the problem), but I'm
not sure how to make this happen in the general case. I have a dataset of
more like a hundred lines, many of which sort of corkscrew around one
another. How can I ensure that the plotting of the lines respects the
depth? Is there a better function I could be using for this? I tried plot3d
in rgl and scatter3d in Rcmdr,  but both crash R on my system.

Thanks so much in advance!

-nate cermak

[[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] Fwd: User defined panel functions in lattice

2012-04-20 Thread David Winsemius


On Apr 20, 2012, at 6:36 PM, Duncan Mackay wrote:


Hi ilai

Thank you for your advice I think I can now get what I need from  
what you have said here.
I think I may have to get involved in packet.number but the original  
packet.number with its arguments has stuck in my mind and I have not  
used it.

I find locfit better than loess etc for a lot of the data I work with.


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?


> ?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 of the questions to Rhelp are for 1 with just a small number  
for 5 and they are not applicable here
and understanding the requirements for passing arguments in these  
different situations I find difficult.
I would like to reduce the number of panel functions to the minimum  
to cover the general situaltions because
my graphs are usually not normal and then add to them for a  
particular situation.


Regards

Duncan


At 01:38 21/04/2012, you wrote:

Duncan,
First off, I admit it is not clear to me what you are trying to
achieve and more importantly, why? by "why" I mean 1) I don't see the
advantage of writing one general panel function for completely
different situations (one/multiple smoothers, grouping levels etc.)  
2)
your intended result as I understand it seems rather cluttered,  
google

. 3) I am unfamiliar with locfit package, but are we
reinventing the wheel here ? i.e. will modifying settings in xyplot(y
~x, xx, groups = Farm, type=c('p','smooth')) achieve the same ?

With your initial reproducible example (thank you) it was easy to
eliminate the errors, but clearly the resulting plots are not what  
you

intended (continue inline):

On Thu, Apr 19, 2012 at 4:23 PM, Duncan Mackay > wrote:


> 3. What I want to be able to add in the above is extra lines with  
different

> values of nn.
>   I think I will have to modify panel.Locfit so that it goes  
through
> different values of nn in each of the panels and groups if I want  
different

> colours for extra lines with different nn values

Yes you could. There are several options:
add group.number to the arguments of panel.locfit and use it to make
nn a vector, along the lines of
   panel.foo <- function(x,y,group.number,theta,...){
 smpar <- theta[group.number]
 panel.loess(x,y,smpar,...)
 panel.xyplot(x,y,...)
   }
xyplot 
(y 
~ 
x 
,xx 
,group 
=Farm,theta=c(4,1,.4),panel=panel.superpose,panel.groups=panel.foo)


# or
xyplot(y~x|Farm,xx,group=Padd,theta=c(.6,1),
   panel=panel.superpose,panel.groups=panel.foo)

Here you will need to modify the Farm group to 6 levels - 3*two  
smoothers.


You could make nn a list and loop over it inside the panel function.
Looks like you tried something like that with specifying 2
panel.Locfit, one suggestion to your code:

panel.Locfit(x,y,...) # default 0.7
   panel.Locfit(x,y,nn=0.9)   # i.e. remove the
... to avoid clashes

Finally, use ?trellis.focus to plot the second smoother "post-hoc".
also the latticeExtra package has many useful tools to create layers
of the same (or different) plot with different settings.

> 4 Produce an extra line for a fit for all the groups in 1/2+  
panels.
>   As for 3 but I do not know how to group all the x and y's  for  
each of the

> panes using panel.groups

Why does it matter ? seems you have failed to learn the lesson from
the first post - the same functionality applies to 1 as to multiple
panels. Does each panel have a different grouping structure ? use
packet.number() for panels similar to group.number idea.

> I need to do this and then scale up for a panel function to include
> confid

[R] DIscrete choice mlogit

2012-04-20 Thread Andrea Cardenas
Hi

I am trying to estimate stated preferences for Tv sets by using mlogit. The
choice set is designed as with 4 attributes: [ brand(has 4 levels),
technology(has two levels), class[has 4 levels), price(has 4 levels)]

There are 16 choice sets with 4 alternatives each one (i.e. each respondent
has evaluated 64 cards in total). Therefore, there are 64 rows in the table
below.

The data in csv file looks like this:


 ModeBrandTechnology Class
Price  0 1 1 1 1  1 2 1 2 2  0 3 2 3 3  0 4
2 4 4  0 2 2 4 2  0 1 1 3 1  1 4 1 2 4  0 3 2 1 3  0 3 2 2 3  1 4 1 3 4  0 2
2 1 2  0 1 1 4 1  0 4 1 3 4  1 3 1 2 3  0 2 2 1 2  0 1 2 4 1  1 1 1 1 4  0 3
2 3 2  0 4 2 4 3  0 2 1 2 1  0 2 1 4 3  0 4 2 2 1  1 3 1 1 4  0 1 2 3 2  0 3
1 4 2  0 1 2 2 4  1 2 1 3 1  0 4 2 1 3  0 4 1 1 1  1 2 2 3 3  0 1 2 2 2  0 3
1 4 4  0 1 1 1 3  0 4 2 4 2  1 2 1 2 4  0 3 2 3 1  1 2 2 4 4  0 3 2 1 1  0 1
1 3 3  0 4 1 2 2  0 3 2 2 1  1 2 2 1 4  0 1 1 4 3  0 4 1 3 2  0 4 1 3 2  0 1
2 4 3  0 3 1 2 1  1 2 2 1 4  0 3 2 3 4  0 1 1 1 2  0 4 2 4 1  1 2 1 2 3  0 4
2 2 3  0 2 1 4 1  0 1 2 3 4  1 3 1 1 2  0 1 2 2 2  0 3 1 4 4  0 4 2 1 1  1 2
1 3 3  0 2 2 3 1  1 4 1 1 3  0 3 1 4 2  0 1 2 2 4


R has already read and save the data,but when I come to the line:

DataR$mode.ids<-factor(rep(1:64,1),labels=c("brand","technology","class","price"))


I get the following error: Error in factor(rep(1:64, 1), labels =
c("brand", "technology", "class",


I guess it has to do with the setting up of my file or the coding in R. How
can I do it right? Each respondent chose 16 times among 4 different cards
every time..

Kind regards,

Andrea

[[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] Problem with Tukey test

2012-04-20 Thread Peter Ehlers

On 2012-04-20 12:10, danipaty13 wrote:

Thanks for your answer well, I uploaded a file with my data, hope you can
help me to solve my problem since i'm using R for my thesis
http://r.789695.n4.nabble.com/file/n4574997/invgrosor.csv invgrosor.csv


Are you sure that's the data you're posting about?

Peter Ehlers

__
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-20 Thread Duncan Mackay

Hi ilai

Thank you for your advice I think I can now get what I need from what 
you have said here.
I think I may have to get involved in packet.number but the original 
packet.number with its arguments has stuck in my mind and I have not used it.

I find locfit better than loess etc for a lot of the data I work with.
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 of the questions to Rhelp are for 1 with just a small number for 
5 and they are not applicable here
and understanding the requirements for passing arguments in these 
different situations I find difficult.
I would like to reduce the number of panel functions to the minimum 
to cover the general situaltions because
my graphs are usually not normal and then add to them for a 
particular situation.


Regards

Duncan


At 01:38 21/04/2012, you wrote:

Duncan,
First off, I admit it is not clear to me what you are trying to
achieve and more importantly, why? by "why" I mean 1) I don't see the
advantage of writing one general panel function for completely
different situations (one/multiple smoothers, grouping levels etc.) 2)
your intended result as I understand it seems rather cluttered, google
. 3) I am unfamiliar with locfit package, but are we
reinventing the wheel here ? i.e. will modifying settings in xyplot(y
~x, xx, groups = Farm, type=c('p','smooth')) achieve the same ?

With your initial reproducible example (thank you) it was easy to
eliminate the errors, but clearly the resulting plots are not what you
intended (continue inline):

On Thu, Apr 19, 2012 at 4:23 PM, Duncan Mackay  wrote:

> 3. What I want to be able to add in the above is extra lines with different
> values of nn.
>   I think I will have to modify panel.Locfit so that it goes through
> different values of nn in each of the panels and groups if I want different
> colours for extra lines with different nn values

Yes you could. There are several options:
add group.number to the arguments of panel.locfit and use it to make
nn a vector, along the lines of
panel.foo <- function(x,y,group.number,theta,...){
  smpar <- theta[group.number]
  panel.loess(x,y,smpar,...)
  panel.xyplot(x,y,...)
}

xyplot(y~x,xx,group=Farm,theta=c(4,1,.4),panel=panel.superpose,panel.groups=panel.foo)

 # or
xyplot(y~x|Farm,xx,group=Padd,theta=c(.6,1),
panel=panel.superpose,panel.groups=panel.foo)

Here you will need to modify the Farm group to 6 levels - 3*two smoothers.

You could make nn a list and loop over it inside the panel function.
Looks like you tried something like that with specifying 2
panel.Locfit, one suggestion to your code:

 panel.Locfit(x,y,...) # default 0.7
panel.Locfit(x,y,nn=0.9)   # i.e. remove the
... to avoid clashes

Finally, use ?trellis.focus to plot the second smoother "post-hoc".
also the latticeExtra package has many useful tools to create layers
of the same (or different) plot with different settings.

> 4 Produce an extra line for a fit for all the groups in 1/2+ panels.
>   As for 3 but I do not know how to group all the x and y's  for 
each of the

> panes using panel.groups

Why does it matter ? seems you have failed to learn the lesson from
the first post - the same functionality applies to 1 as to multiple
panels. Does each panel have a different grouping structure ? use
packet.number() for panels similar to group.number idea.

> I need to do this and then scale up for a panel function to include
> confidence bands

than expand the xlim,ylim or scales in ?xyplot

>
> For the record making Farm and Padd factors. With 1 panel and groups = Farm
> works with the extra line the same colour for its group
> a similar situation for the three panels when conditioned by Farm 
and groups

> = Pad



Like I said I am a little lost on this problem but I hope this helps
giving some direction.
Cheers


>
>  xyplot(y ~x, xx,
> groups = Farm,
>
> par.settings = list(strip.background = list(col = "transparent"),
> 

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

2012-04-20 Thread andrija djurovic
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 Newmiller                        The     .       .  Go Live...
> DCN:        Basics: ##.#.       ##.#.  Live Go...
>                                      Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/Batteries            O.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] Package "demography" - calculating percentiles of survival probabilities distribution

2012-04-20 Thread David Winsemius


On Apr 20, 2012, at 4:13 PM, jolo999 wrote:


Hi,

I am using the package "demography" from Rob Hyndman for the
Lee-Carter-Model. It is an amazing powerful tool but I am struggling  
with

one issue:

I want to compute different percentiles of the survival probability
distribution derived from the Lee-Carter-Forecast (e.g. the 50%tile,
60%tile, 75%tile and 99%tile) for each of the next 10 years. Is  
there any

possibility to retrieve these "attachment points"?

I am sure the package possess this functionality but I didn't find  
any way

to calculate percentile values.


Even with your revised question I'm having trouble understanding  
exactly what you want. A survival function is a probability that is  
returned from input of a specified duration, i.e. a value between 0  
and 1 (or equivalently between 0 and 100%). Conversely, you could ask  
what time would be associated with a particular survival percentile  
for a particular age. But I am having trouble understanding what it  
means to ask for a "50th percentile for each of the next 10 years"?  
(It seems you are specifying both the input and the output.)


There are very few ages at which the 50th percentile would be reached  
in one year, or even ten years. Are you asking what initial ages would  
be associated with a 50% survival at 10 years when assuming a  
particular mortality structure? Can you offer a particular example for  
further discussion?


Looking at the returned object descriptions, it appears that they are  
in the form of mortality tables. Are you really asking how to produce  
survival estimates from a particular series of mortality predictions?  
Here is one formula for converting m's to S's


exp( -sum(m[i:(1+9)] ) #  for 'i' being the starting age index and m's  
being a series of annual mortalities .


(again, offering an example from the help pages might clarify this  
trans-Atlantic, trans-language exchange.)


france.LC1 <- lca(fr.mort,adjust="e0")
france.fcast <- forecast(france.LC1, 50)
str(france.fcast$rate$total[ , which(france.fcast$year == 2012)])
# num [1:101] 2.37e-03 1.04e-04 5.14e-05 4.19e-05 3.77e-05 ...
france.fcast$rate$total[ 90:101, which(france.fcast$year == 2012)]
# [1] 0.1571447 0.1774625 0.2004623 0.2261028 0.2546273 0.2838347  
0.3061775 0.3229046 0.3398724

# [10] 0.3465093 0.3362461 0.5371380
exp(- france.fcast$rate$total[ 90:101, which(france.fcast$year ==  
2012)] )
 [1] 0.8545804 0.8373924 0.8183523 0.7976361 0.7752053 0.7528911  
0.7362559 0.7240429 0.7118612

[10] 0.7071523 0.7144473 0.5844184

So at no age with assumed starting year of 2012 would there be an  
associated 50% probability.


These are the one year survival probabilities for ages 80-101 in year  
2012 (based on a forcast from 2006 data.)


> exp(- france.fcast$rate$total[ 80:101, which(france.fcast$year ==  
2012)] )
 [1] 0.9574380 0.9530564 0.9474982 0.9411758 0.9338487 0.9254885  
0.9150893 0.9022344 0.8882844
[10] 0.8719397 0.8545804 0.8373924 0.8183523 0.7976361 0.7752053  
0.7528911 0.7362559 0.7240429

[19] 0.7118612 0.7071523 0.7144473 0.5844184

--

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] lines crosses

2012-04-20 Thread Peter Langfelder
On Fri, Apr 20, 2012 at 2:48 PM, Ben quant  wrote:
>
> Hello,
>
> If the exact value does not exist in the vector, can I still get at the
> intersections? Is there a simple way to do this and avoid looping? Seems
> like there would be a simple R function to do this...
>
> Example:
> vec <- c(5,4,3,2,3,4,5)
> vec
> [1] 5 4 3 2 3 4 5
> intersect(vec,2.5)
> numeric(0)
>
> I want to get:
> 2.5 and 2.5

You want to get what? How many times the line crosses 2.5? That's easy:

vec = c(5,4,3,2,3,4,5)
query = 2.5
n = length(vec)
v1 = vec[-1]
v2 = vec[-n];

# this tells you where the line crosses your query going up
crossesUp = which(v2 < query & v1 > query)
# this tells you where the line crosses your query going down
crossesDown = which(v2 > query & v1 < query)

numberOfCrossings = length(crossesUp)  + length(crossesDown)

HTH

Peter

__
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] Select interval of time series object by date and time

2012-04-20 Thread Rui Barradas
Hello,


florian wrote
> 
> Hy,
> 
> I want to select an interval of a time series (containing intraday data)
> by the data and a certain time frame (e.g. 9 AM to 10 AM). However, I do
> not know how to specify the time during the day:
> 
> #load data
> library(RTAQ)
> data("sample_tdata")
> data=sample_tdata
> return=makeReturns(data$PRICE)
> 
> #I would like to use some command like this to get only the data between 9
> and 10
> window(return,start=as.Date("2008-01-04"),end=as.Date("2008-01-04"))
> 
> Thank you very much in advance
> Florian Walla
> University Groningen
> 

If you're working with time series, sooner or later you'll want package
'zoo'.
This example uses it.


library(zoo)
set.seed(1)
# Make some data
x <- as.POSIXct("2008-01-04 9:00:00")+ cumsum(sample(200, 100, T))
y <- rnorm(100)

start.hour <- as.POSIXct("2008-01-04 9:00:00")
end.hour <- as.POSIXct("2008-01-04 10:00:00")

# Create the 'zoo' object and extract the desired window
Z <- zoo(y, order.by=x)
w <- window(Z, start=start.hour, end=end.hour)
# Compute some statistics
sum(w)
mean(w)
sd(w)

Hope this helps,

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/Select-interval-of-time-series-object-by-date-and-time-tp4573220p4575440.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] odbcConnectExcel() fails to fetch all columns

2012-04-20 Thread Jeff Newmiller
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.


Re: [R] error loading tcltk2

2012-04-20 Thread drjes3bioc
I am having the same problem loading tcltk2


> local({pkg <- select.list(sort(.packages(all.available =
> TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
Loading required package: 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
Error: package/namespace load failed for ‘tcltk2’
> 

on a Windoze XP on Dell Intel dual core processor
running R version 2.14.2 (2012-02-29) just reinstalled


Its not clear to me how to solve the problem if tcltk2 is designed for
Ubuntu

thanks for any guidance how to proceed.

-John

--
View this message in context: 
http://r.789695.n4.nabble.com/error-loading-tcltk2-tp4574065p4575313.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] Numbers not numeric?

2012-04-20 Thread Peter Langfelder
On Fri, Apr 20, 2012 at 12:44 PM, Charles Determan Jr  wrote:
> Greetings R users,
>
> I have a curious problem.  I read in a csv file (subset shown below) as
> normal
> data=read.table("C:/Users/Chaz/Desktop/test.csv",sep=",",header=TRUE,
> na.strings=".")
>
> However, the numbers from the dataset are not registered as numeric:
>
> is.numeric(data$Mesh)
> [1] FALSE
>
> When I try as.numeric, it converts all the values to different integers.
> This changes the analysis as I would like calculate simple things such as
> the means and standard deviation.  Any thoughts would be appreciated.
>
>
>  Mesh SubQ Edge  90 10 55  60 25 45  60 12 85  50 50 90  45 80 70  40 45 45
> 80 40 65  100 65 58

Two issues:

1. Some of your data in the Mesh column are non-numeric (entries
"SubQ" and "Edge"). This causes the entire column to be read in as
character strings.

2. The columns gets read in as character strings and is by default
converted to a factor (see ?factor for information about factors). To
convert the actual character strings to numbers, you need to use
as.numeric(as.character(data$Mesh)). as.numeric returns the underlying
codes that factor uses for each level. You can disable converting
character strings into factors by using

options(stringsAsFactors = FALSE)

before the call to read.csv().

HTH,

Peter

__
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-20 Thread Paul Johnson
On Fri, Apr 20, 2012 at 2:18 PM, 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


There's documentation on this in the "Writing R Extensions" manual,
See 1.2.1 Using Makevars and Section 6.7 "Numerical analysis
subrouties." They recommend looking at the package fastICA. It appears
to me you will use some platform neutral Makefile variables.

If you give a full working example from windows--your function, data
to use it--I'll see what I can do on the Linux side.  I've never had
need to worry about this question before, but it is about time I
learned.

Before you think about packaging something like this, I'd say step one
is to clean up your code so it is easier to read.  R CMD check won't
let you get bye with T or F in place of TRUE and FALSE, and you seem
to mix <- and = in your code, which makes it difficult to read.

pj


> "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)
> }
>
>
>
> On Fri, Apr 20, 2012 at 12:01 PM, Jonathan Greenberg wrote:
>
>> Incidentally, if you want to test this out:
>>
>> > A
>>          [,1]     [,2]     [,3]
>> [1,] 1457.738 1053.181 1256.953
>> [2,] 1053.181 1213.728 1302.838
>> [3,] 1256.953 1302.838 1428.269
>>
>> > B
>>          [,1]     [,2]     [,3]
>> [1,] 4806.033 1767.480 2622.744
>> [2,] 1767.480 3353.603 3259.680
>> [3,] 2622.744 3259.680 3476.790
>>
>> I THINK this is correct for the other parameters:
>>         JOBVL="N"
>>         JOBVR="N"
>> N=dim(A)[[1]]
>>  LDA=N
>> LDB=N
>> LDVL=N
>>  LDVR=N
>> LWORK=max(1,8*N)
>>
>> .Call("La_dgeev", JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR=NA, ALPHAI=NA,
>> BETA=NA,
>>  VL=NA, LDVL, VR=NA, LDVR, WORK=NA, LWORK, INFO=NA, PACKAGE="base")
>>  LAPACK's documentation is:
>> http://www.netlib.org/lapack/double/dggev.f
>>
>> --j
>>
>> On Fri, Apr 20, 2012 at 11:58 AM, Jonathan Greenberg 
>> wrote:
>>
>>> So I am a complete noob at doing this type of linking.  When I write this
>>> statement (all the input values are assigned, but I have to confess I don't
>>> know what to do with the output variables -- in this call they are all
>>> assigned "NA"):
>>>
>>> .Call("La_dgeev", JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR=NA, ALPHAI=NA,
>>> BETA=NA,
>>> + VL=NA, LDVL, VR=NA, LDVR, WORK=NA, LWORK, INFO=NA, PACKAGE="base")
>>>
>>> I get:
>>>
>>> Error in .Call("La_dgeev", JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR = NA,
>>>  :
>>>   C symbol name "La_dgeev" not in DLL for package "base"
>>>
>>> I'm running this on Windows 7 x64 version of R 2.14.2.  The
>>> R_ext/Lapack.h file states:
>>>
>>> /* DGEEV - compute for an N-by-N real nonsymmetric matrix A, the */
>>> /* eigenvalues and, optionally, the left and/or right eigenvectors */
>>> La_extern void
>>> F77_NAME(dgeev)(const char* jobvl, const char* jobvr,
>>> const int* n, double* a, const int* lda,
>>> double* wr, double* wi, double* vl, const int* ldvl,
>>>  double* vr, const int* ldvr,
>>> double* work, const int* lwork, int* info);
>>>
>>> Any ideas?
>>>
>>> --j
>>>
>>>
>>>
>>> On Fri, Apr 20, 2012 at 1:37 AM, Berend Hasselman  wrote:
>>>

 On 19-04-2012, at 20:50, Jonathan Greenberg wrote:

 > Folks:
 >
 > I'm trying to port some code from python over to R, and I'm running
 into a
 > wall finding R code that can solve a generalized eigenvalue problem
 > following this function model:
 >
 >
 http://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eig.html
 >
 > Any ideas?  I don't want to call python from within R for various
 reasons,
 > I'd prefer a "native" R solution if one exists.  Thanks!

 An old thread is here:
 http://tolstoy.newcastle.edu.au/R/help/05/06/6802.html

 R does provid

Re: [R] pasting a formula string with double quotes in it

2012-04-20 Thread StellathePug

Yes, Rui, it did work. Thank you very much for your help. Or maybe I should say 
"muito obrigada!"

Rita
=
"If you think education is expensive, try ignorance."--Derek Bok



> Date: Fri, 20 Apr 2012 11:15:06 -0700 
> From: ml-node+s789695n457488...@n4.nabble.com 
> To: ritacarre...@hotmail.com 
> Subject: Re: pasting a formula string with double quotes in it 
>  
> Hello, 
>  
> StellathePug wrote 
> Hello everyone, 
> I have tried several ways of doing this and searched the documentation  
> and help lists and I have been unable to find an answer or even whether  
> it is possible to do it. I am pasting together a formula and I need to  
> insert double quotes around the strings. Here's an example: 
>  
>location <- c("AL", "AK", "MA", "PA") 
>v=2 
>test <-  cbind( 
> " <- cbind(df$DATE[df$LOCATION %in% c(", 
> location[v], 
> ")], df$WTD.AVG.PRICE[df$LOCATION %in% c(", 
> location[v], 
> ")])") 
>  
>test <- paste(test, collapse="") 
>test 
>  
> Solution: 
> [1] " <- cbind(df$DATE[df$LOCATION %in% c(AK)],  
> df$WTD.AVG.PRICE[df$LOCATION %in% c(AK)])" 
>  
> This does not produce an error message but it is obviously wrong  
> because I need double quotes around AK, i.e., 
> " <- cbind(df$DATE[df$LOCATION %in% c("AK")],  
> df$WTD.AVG.PRICE[df$LOCATION %in% c("AK")])" 
> And obviously, I gave R no indication whatsoever to use double quotes. 
>  
>  
> If I use 
>   test <- paste(test, collapse=""") 
> it does not work, which makes sense because the second double quote  
> closes the first and the third is left an orphan. 
>  
> Anyone have any ideas? 
>  
[[elided Hotmail spam]]
> Rita 
> Use single quotes instead, they don't close the double quotes and, for  
> this, the result is the same. 
> Look at the end/beginning of the lines before/after location[v] 
>  
> test2 <-  cbind( 
> " <- cbind(df$DATE[df$LOCATION %in% c('", 
> location[v], 
> "')], df$WTD.AVG.PRICE[df$LOCATION %in% c('", 
> location[v], 
> "')])") 
> test2 <- paste(test2, collapse="") 
> test2 
>  
> Hope this helps, 
>  
> Rui Barradas 
>  
>  
>  
> If you reply to this email, your message will be added to the  
> discussion below: 
> http://r.789695.n4.nabble.com/pasting-a-formula-string-with-double-quotes-in-it-tp4574419p4574888.html
>  
> To unsubscribe from pasting a formula string with double quotes in it,  
> click  
> here.
>  
> NAML
>  
  

--
View this message in context: 
http://r.789695.n4.nabble.com/pasting-a-formula-string-with-double-quotes-in-it-tp4574419p4575202.html
Sent from the R help mailing list archive at Nabble.com.
[[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] lines crosses

2012-04-20 Thread Ben quant
Hello,

If the exact value does not exist in the vector, can I still get at the
intersections? Is there a simple way to do this and avoid looping? Seems
like there would be a simple R function to do this...

Example:
vec <- c(5,4,3,2,3,4,5)
vec
[1] 5 4 3 2 3 4 5
intersect(vec,2.5)
numeric(0)

I want to get:
2.5 and 2.5

My real data is very large and I don't know the values of anything ahead of
time. The vec vector is produced by the gam function so it can be just
about any continuous line.

Thanks,

Ben

[[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] Numbers not numeric?

2012-04-20 Thread Charles Determan Jr
Greetings R users,

I have a curious problem.  I read in a csv file (subset shown below) as
normal
data=read.table("C:/Users/Chaz/Desktop/test.csv",sep=",",header=TRUE,
na.strings=".")

However, the numbers from the dataset are not registered as numeric:

is.numeric(data$Mesh)
[1] FALSE

When I try as.numeric, it converts all the values to different integers.
This changes the analysis as I would like calculate simple things such as
the means and standard deviation.  Any thoughts would be appreciated.


 Mesh SubQ Edge  90 10 55  60 25 45  60 12 85  50 50 90  45 80 70  40 45 45
80 40 65  100 65 58

[[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] Package "demography" - calculating percentiles of survival probabilities distribution

2012-04-20 Thread jolo999
Hi,

I am using the package "demography" from Rob Hyndman for the
Lee-Carter-Model. It is an amazing powerful tool but I am struggling with
one issue:

I want to compute different percentiles of the survival probability
distribution derived from the Lee-Carter-Forecast (e.g. the 50%tile,
60%tile, 75%tile and 99%tile) for each of the next 10 years. Is there any
possibility to retrieve these "attachment points"?

I am sure the package possess this functionality but I didn't find any way
to calculate percentile values.

Hope you can help me!

Thanks

Jonas 

--
View this message in context: 
http://r.789695.n4.nabble.com/Package-demography-calculating-percentiles-of-survival-probabilities-distribution-tp4575145p4575145.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] Solve an ordinary or generalized eigenvalue problem in R?

2012-04-20 Thread Jonathan Greenberg
My apologies:

When reviewing my initial email I made a typo -- what I needed was dggev,
not dgeev.  I have confirmed that my function reproduces the scipy outputs
I mentioned in my first email.  The function is part of lapack.  I'm not an
R noob, I just haven't dealt with external Fortran or C calls before.

The reason I need it is that I am trying to port an existing python/IDL
algorithm to R (iMad/RADCAL, located at
http://mcanty.homepage.t-online.de/software.html).  The algorithm is fairly
complex so I'm trying to reproduce it line-by-line as closely as possible
before going back and improving its efficiency using various R
functions  (checking the inputs and the outputs between R and the python
code each step).  This algorithm does a weighted canonical correlation
analysis which does not apparently exist in other CCA R packages.

So, my main question at this point is given I can call dggev via .Fortran()
and get the outputs I want, what is the best way to package this up with a
dyn.load() statement that would work on any R install that has the lapack
libraries available to it?

--j


> Yes. Stop this.
>
> You are completely on the wrong track and  getting yourself into a real
> muddle.
>
> 1. you are mixing up dgeev and dggev. You are using the dggev arguments to
> call dgeev. Even if you got it all correct this would result in nasty
> errors.
> 2. La_dgeev doesn't exist in the R sources (nor does it exist in Lapack)
> and you don't need to use dgeev. See below.
>
> Since you are a "noob" I would advise you to not try and interface with
> Fortran or C at this moment.
>
> It is possible to interface with dggev for generalized eigenvalues but it
> is not a straightforward and easy job to do.
> I've had a look at the R and C code used in the R sources to interface
> with dgeev. It would need a lot of TLC.
>
> As I told you before: R provides a function eigen for calculating "normal"
>  eigenvalues end eigenvectors.
>
> It's probably a good idea to explain why you need generalized eigenvalues.
> Then someone may be able to come up with suggestions and/or alternatives.
>
> Berend
>
>


-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
607 South Mathews Avenue, MC 150
Urbana, IL 61801
Phone: 415-763-5476
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
http://www.geog.illinois.edu/people/JonathanGreenberg.html

[[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] ggplot2: Legend title

2012-04-20 Thread Brian Diggs

On 4/20/2012 12:11 PM, Bush, Daniel P. DPI wrote:

I'm designing a set of plots intended for a general audience; here's
the code for one of them, using the latest version of ggplot:

plot.enr.all<-
   ggplot(data=df1, aes(x=HS_GRAD_YEAR, y=Percentage, group=Enrolled_by,
color=Enrolled_by, shape=Enrolled_by, 
fill=Enrolled_by)) +
   geom_line() + geom_point(size=3.5) +
   scale_y_continuous(breaks=seq(0, 100, 10), limits=c(0, 100),
  labels=paste(seq(0, 100, 10), "%", sep="")) +
   scale_color_manual(values=c("orange", "red"),
  breaks=c("PCT_ENR_FALL1", "PCT_ENR_FALL2"),
  labels=c("1st fall", "2nd fall")) +
   scale_fill_manual(values=c("orange", "red"),
 breaks=c("PCT_ENR_FALL1", "PCT_ENR_FALL2"),
 labels=c("1st fall", "2nd fall")) +
   scale_shape_manual(values=c(21, 22),
  breaks=c("PCT_ENR_FALL1", "PCT_ENR_FALL2"),
  labels=c("1st fall", "2nd fall")) +
   opts(title="Postsecondary Enrollment Rates of High School Graduates",
legend.position="bottom", axis.title.y=theme_blank()) +
   guides(fill=guide_legend(nrow=1)) + xlab("Graduation year")

The legend on the resulting plot uses "Enrolled_by" for a title. I'd
like it to be able to use "Enrolled by" without the underscore, but
thus far I've been unable to get ggplot to use a variable name
containing a space. Is there a straightforward way of doing so?


Easier than changing the variable name, change the legend title itself. 
This is the name argument, which needs to be passed to all of color, 
fill, and shape:


...
  scale_color_manual(name="Enrolled by",
 values=c("orange", "red"),
 breaks=c("PCT_ENR_FALL1", "PCT_ENR_FALL2"),
 labels=c("1st fall", "2nd fall")) +
  scale_fill_manual(name="Enrolled by",
values=c("orange", "red"),
breaks=c("PCT_ENR_FALL1", "PCT_ENR_FALL2"),
labels=c("1st fall", "2nd fall")) +
  scale_shape_manual(name="Enrolled by",
 values=c(21, 22),
 breaks=c("PCT_ENR_FALL1", "PCT_ENR_FALL2"),
 labels=c("1st fall", "2nd fall")) +
...



DB

Daniel Bush
Educational Measurement Consultant
Office of Educational Accountability
Wisconsin Department of Public Instruction
PO Box 7841 | Madison, WI 53707-7841
daniel.bush -at- dpi.wi.gov | www.dpi.wi.gov/oea/
Ph: 608-264-9321 | Fax: 608-266-8770


[[alternative HTML version deleted]]




--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

__
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] odbcConnectExcel() fails to fetch all columns

2012-04-20 Thread Andrew Roberts

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.


Re: [R] Quick question about princomp/biplot

2012-04-20 Thread Kevin Wright
See the help for 'biplot'.  For example:

require(graphics)
biplot(princomp(USArrests), xlabs=rep("+",nrow(USArrests)))


Kevin

On Fri, Apr 20, 2012 at 12:52 PM, Filoche  wrote:

> Hi everyone.
>
> I performing a simple PCA using the princomp function. Then, I use the
> biplot function to show it. However, the function use line number to
> represent samples. I would like to know if there's a way to use a dot
> (point) instead of the line number when using the biplot function.
>
> With regards,
> Phil
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Quick-question-about-princomp-biplot-tp4574831p4574831.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.
>



-- 
Kevin Wright

[[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-20 Thread Berend Hasselman

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

> So I am a complete noob at doing this type of linking.  When I write this 
> statement (all the input values are assigned, but I have to confess I don't 
> know what to do with the output variables -- in this call they are all 
> assigned "NA"):
> 
> .Call("La_dgeev", JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR=NA, ALPHAI=NA, 
> BETA=NA,
> + VL=NA, LDVL, VR=NA, LDVR, WORK=NA, LWORK, INFO=NA, 
> PACKAGE="base")
> 
> I get:
> 
> Error in .Call("La_dgeev", JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR = NA,  : 
>   C symbol name "La_dgeev" not in DLL for package "base"
> 
> I'm running this on Windows 7 x64 version of R 2.14.2.  The R_ext/Lapack.h 
> file states:
> 
> /* DGEEV - compute for an N-by-N real nonsymmetric matrix A, the */
> /* eigenvalues and, optionally, the left and/or right eigenvectors */
> La_extern void
> F77_NAME(dgeev)(const char* jobvl, const char* jobvr,
>   const int* n, double* a, const int* lda,
>   double* wr, double* wi, double* vl, const int* ldvl,
>   double* vr, const int* ldvr,
>   double* work, const int* lwork, int* info);
> 
> Any ideas?  
> 

Yes. Stop this.

You are completely on the wrong track and  getting yourself into a real muddle.

1. you are mixing up dgeev and dggev. You are using the dggev arguments to call 
dgeev. Even if you got it all correct this would result in nasty errors.
2. La_dgeev doesn't exist in the R sources (nor does it exist in Lapack) and 
you don't need to use dgeev. See below.

Since you are a "noob" I would advise you to not try and interface with Fortran 
or C at this moment.

It is possible to interface with dggev for generalized eigenvalues but it is 
not a straightforward and easy job to do.
I've had a look at the R and C code used in the R sources to interface with 
dgeev. It would need a lot of TLC.

As I told you before: R provides a function eigen for calculating "normal"  
eigenvalues end eigenvectors.

It's probably a good idea to explain why you need generalized eigenvalues.
Then someone may be able to come up with suggestions and/or alternatives.

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] Interactive stereoscopic 3d rendering with RGL plot3d?

2012-04-20 Thread Duncan Murdoch

On 20/04/2012 2:47 PM, Benedikt Orlowski wrote:

Dear R Users,

i' wondering, if there is any possibility to render interactive stereoscopic 3d 
plots in R and use the
functionality of those new 3d displays (e.g. with poarisation technology) like 
this one:

>  http://shop.fujitsu.com/de/displays/display-p23t-6p-fpr-3d

Does anyone know if there are developments toward this feature? Or perhaps 
someone
know how to implement such a function...

Perhaps it can be easily implemented by synchronizing
two windows with different view angles (RGL package plot3d) and send those two 
pictures towards
a screen driver. But i have now idea how to realize such thing.


There is a stereo display demo in rgl (see demo(stereo)).  It displays 
linked views of a scene in two windows, then constructs an anaglyph and 
a random dot stereogram from them.  But if you can figure out how to put 
the original two windows into that fancy display, it should work.


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.


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

2012-04-20 Thread Jonathan Greenberg
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)
}



On Fri, Apr 20, 2012 at 12:01 PM, Jonathan Greenberg wrote:

> Incidentally, if you want to test this out:
>
> > A
>  [,1] [,2] [,3]
> [1,] 1457.738 1053.181 1256.953
> [2,] 1053.181 1213.728 1302.838
> [3,] 1256.953 1302.838 1428.269
>
> > B
>  [,1] [,2] [,3]
> [1,] 4806.033 1767.480 2622.744
> [2,] 1767.480 3353.603 3259.680
> [3,] 2622.744 3259.680 3476.790
>
> I THINK this is correct for the other parameters:
> JOBVL="N"
> JOBVR="N"
> N=dim(A)[[1]]
>  LDA=N
> LDB=N
> LDVL=N
>  LDVR=N
> LWORK=max(1,8*N)
>
> .Call("La_dgeev", JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR=NA, ALPHAI=NA,
> BETA=NA,
>  VL=NA, LDVL, VR=NA, LDVR, WORK=NA, LWORK, INFO=NA, PACKAGE="base")
>  LAPACK's documentation is:
> http://www.netlib.org/lapack/double/dggev.f
>
> --j
>
> On Fri, Apr 20, 2012 at 11:58 AM, Jonathan Greenberg wrote:
>
>> So I am a complete noob at doing this type of linking.  When I write this
>> statement (all the input values are assigned, but I have to confess I don't
>> know what to do with the output variables -- in this call they are all
>> assigned "NA"):
>>
>> .Call("La_dgeev", JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR=NA, ALPHAI=NA,
>> BETA=NA,
>> + VL=NA, LDVL, VR=NA, LDVR, WORK=NA, LWORK, INFO=NA, PACKAGE="base")
>>
>> I get:
>>
>> Error in .Call("La_dgeev", JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR = NA,
>>  :
>>   C symbol name "La_dgeev" not in DLL for package "base"
>>
>> I'm running this on Windows 7 x64 version of R 2.14.2.  The
>> R_ext/Lapack.h file states:
>>
>> /* DGEEV - compute for an N-by-N real nonsymmetric matrix A, the */
>> /* eigenvalues and, optionally, the left and/or right eigenvectors */
>> La_extern void
>> F77_NAME(dgeev)(const char* jobvl, const char* jobvr,
>> const int* n, double* a, const int* lda,
>> double* wr, double* wi, double* vl, const int* ldvl,
>>  double* vr, const int* ldvr,
>> double* work, const int* lwork, int* info);
>>
>> Any ideas?
>>
>> --j
>>
>>
>>
>> On Fri, Apr 20, 2012 at 1:37 AM, Berend Hasselman  wrote:
>>
>>>
>>> On 19-04-2012, at 20:50, Jonathan Greenberg wrote:
>>>
>>> > Folks:
>>> >
>>> > I'm trying to port some code from python over to R, and I'm running
>>> into a
>>> > wall finding R code that can solve a generalized eigenvalue problem
>>> > following this function model:
>>> >
>>> >
>>> http://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eig.html
>>> >
>>> > Any ideas?  I don't want to call python from within R for various
>>> reasons,
>>> > I'd prefer a "native" R solution if one exists.  Thanks!
>>>
>>> An old thread is here:
>>> http://tolstoy.newcastle.edu.au/R/help/05/06/6802.html
>>>
>>> R does provide eigen().
>>> R has the Lapack routines dggev and dgges in its library.
>>> You'd have to write your own .Fortran interface to those routines.
>>>
>>> Berend
>>>
>>>
>>
>>
>> --
>> Jonathan A. Greenberg, PhD
>> Assistant Professor
>> Department of Geography and Geographic Information Science
>> University of Illinois at Urbana-Champaign
>> 607 South Mathews Avenue, MC 150
>> Urbana, IL 61801
>> Phone: 415-763-5476
>> AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
>> http://www.geog.illinois.edu/people/JonathanGreenberg.html
>>
>
>
>
> --
> Jonathan A. Greenberg, PhD
> Assistant Professor
> Department of Geography and Geographic Information Science
> University of Illinois at Urbana-Champaign
> 607 South Mathews Avenue, MC 150
> Urbana, IL 61801
> Phone: 415-763-5476
> AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
> http://www.geog.illinois.edu/people/JonathanGreenberg.html
>



-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Department of 

[R] ggplot2: Legend title

2012-04-20 Thread Bush, Daniel P. DPI
I'm designing a set of plots intended for a general audience; here's the code 
for one of them, using the latest version of ggplot:

plot.enr.all <-
  ggplot(data=df1, aes(x=HS_GRAD_YEAR, y=Percentage, group=Enrolled_by,
   color=Enrolled_by, shape=Enrolled_by, fill=Enrolled_by)) 
+
  geom_line() + geom_point(size=3.5) +
  scale_y_continuous(breaks=seq(0, 100, 10), limits=c(0, 100),
 labels=paste(seq(0, 100, 10), "%", sep="")) +
  scale_color_manual(values=c("orange", "red"),
 breaks=c("PCT_ENR_FALL1", "PCT_ENR_FALL2"),
 labels=c("1st fall", "2nd fall")) +
  scale_fill_manual(values=c("orange", "red"),
breaks=c("PCT_ENR_FALL1", "PCT_ENR_FALL2"),
labels=c("1st fall", "2nd fall")) +
  scale_shape_manual(values=c(21, 22),
 breaks=c("PCT_ENR_FALL1", "PCT_ENR_FALL2"),
 labels=c("1st fall", "2nd fall")) +
  opts(title="Postsecondary Enrollment Rates of High School Graduates",
   legend.position="bottom", axis.title.y=theme_blank()) +
  guides(fill=guide_legend(nrow=1)) + xlab("Graduation year")

The legend on the resulting plot uses "Enrolled_by" for a title. I'd like it to 
be able to use "Enrolled by" without the underscore, but thus far I've been 
unable to get ggplot to use a variable name containing a space. Is there a 
straightforward way of doing so?

DB

Daniel Bush
Educational Measurement Consultant
Office of Educational Accountability
Wisconsin Department of Public Instruction
PO Box 7841 | Madison, WI 53707-7841
daniel.bush -at- dpi.wi.gov | www.dpi.wi.gov/oea/
Ph: 608-264-9321 | Fax: 608-266-8770


[[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] Re : Sort out number on value

2012-04-20 Thread David Winsemius


On Apr 20, 2012, at 3:00 PM, Jeff Newmiller wrote:


I think

x[x>7.5]



> y <-c(1,1)
> y[y>2]
numeric(0)
> y[which(y>2)]
numeric(0)

gives more unsurprising results when none of the data meets the  
criteria than


x[which(x>7.5)]


I don't see a difference.

Look at:

> x <-c(NA, 1)
> x[which(x >2)]
numeric(0)
> x[x>0]
[1] NA  1
> x[which(x >0)]
[1] 1

> length( x[x>0])
[1] 2
> length( x[which(x>0)])
[1] 1


I hope reasonable people can disagree on this one.

Using 'which' gives more unsurprising results when the logical test is  
applied to a large dataset for which the number of NA's exceeds the  
number of targets by a large margin. There are differences of opinion  
as to which surprise is most undesirable. There are also gotcha's  
regarding the use of "-" in front of 'which'. I seem to have a false  
memory that there is an isTRUE function that is the _correct_ way of  
doing this, but I cannot recover that lost memory and it appears that  
isTRUE is not vectorized.


--
David.



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

David Winsemius  wrote:



On Apr 20, 2012, at 9:49 AM, Yellow wrote:


I now filtered the Na and Inf out of my data.
And the number is exactly the same als the output from the excel

file.


Thanks everyone. :)
Now I can finish my work.


In the future it might be safer to use subset() or perhaps
x[which(x>7.5)]. That would omit the NA or NaN values (although it
might not remove the Inf values, but I didn't realize the Excel had a
concept of Inf).

--

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.




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] Problem with Tukey test

2012-04-20 Thread danipaty13
Thanks for your answer well, I uploaded a file with my data, hope you can
help me to solve my problem since i'm using R for my thesis 
http://r.789695.n4.nabble.com/file/n4574997/invgrosor.csv invgrosor.csv 

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-Tukey-test-tp4573945p4574997.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] lines on persp plot - proper depth ordering

2012-04-20 Thread Nate Cermak
Hello R-help!
I am trying to draw series of lines in 3d, and I am not sure how to get the
depth set up properly - lines that are in front of other lines appear to be
behind and vice versa. I've been doing this by first generating an empty
persp plot, then adding lines via the data into trans3d followed by lines
(this is probably a bad approach, but it was the first one I could get
working).

Here is a semi-contrived minimal example of my problem:

###
#line 1
x1=0:10;
y1=rep(0,11);
z1 = rep(5,11);

#line 2
x2=y2=z2 = 0:10

# make empty persp plot (awful hack to make a surface out of view)
pmat = persp(x=c(-10.1,-10), y=c(-10.1,-10), z=matrix(c(0,.1,0,.1),
nrow=2),
xlim=c(0,10), ylim=c(0,10), zlim=c(0,10), xlab='x', ylab='y', zlab='z')

# now draw the lines
lines( trans3d(x1, y1, z1,pmat), col="grey", lwd=3)
lines( trans3d(x2, y2, z2,pmat), col="red", lwd=3)
#

Ideally, the red line would occur behind the grey line (and in this
example, I could very simply switch the order and fix the problem), but I'm
not sure how to make this happen in the general case. I have a dataset of
more like a hundred lines, many of which sort of corkscrew around one
another. How can I ensure that the plotting of the lines respects the
depth? Is there a better function I could be using for this? I tried plot3d
in rgl and scatter3d in Rcmdr,  but both crash R on my system.

Thanks so much in advance!

-nate cermak

[[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] Problem with Tukey test

2012-04-20 Thread danipaty13
http://r.789695.n4.nabble.com/file/n4574990/invgrosor.csv invgrosor.csv 
Thanks for your answer well, I uploaded a file with mi data, hope you can
solve my problem since i'm using R for my thesis 

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-Tukey-test-tp4573945p4574990.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] ggplot2: scale_shape_manual

2012-04-20 Thread Brian Diggs

On 4/19/2012 5:20 AM, Brian Smith wrote:

Thanks Brian. That worked. I also wanted to increase the size of the
'points' on the graph. Is there any way I can get rid of the 'legend' (in
this case '3') appearing on the plot?

=== code 
 library(ggplot2)

 leaves<- letters[1:8]
 mat<- matrix(sample(1:1000,32),nrow=16,ncol=2)
 colnames(mat)<- paste('t',1:2,sep='')
 df<- as.data.frame(cbind(mat,leaves))

 vals<- 1:length(leaves)
 names(vals)<- leaves

 p<- ggplot(df,aes(t1,t2))
 p + aes(shape = factor(leaves)) + geom_point(aes(colour =
factor(leaves),size=3)) + scale_shape_manual(values=vals)


Move the size=3 outside the aes. That way it is set rather than mapped 
(when mapped, a legend is needed to show the reverse mapping)


p + aes(shape = factor(leaves)) + geom_point(aes(colour =
factor(leaves)),size=3) + scale_shape_manual(values=vals)


=

thanks!


On Mon, Apr 16, 2012 at 3:09 PM, Brian Diggs  wrote:


On 4/16/2012 7:31 AM, Brian Smith wrote:


Hi,

I was trying to replicate one of the graphs given on the ggplot2 website.
I
have given a sample code below. I would like to combine the legends, since
each color is uniquely mapped to a shape.

###
 library(ggplot2)

 leaves<- letters[1:8]
 mat<- matrix(sample(1:1000,32),nrow=**16,ncol=2)
 colnames(mat)<- paste('t',1:2,sep='')
 df<- as.data.frame(cbind(mat,**leaves))

 vals<- 1:length(leaves)
 names(vals)<- leaves

 p<- ggplot(df,aes(t1,t2))
 p + aes(shape = factor(leaves)) + geom_point(aes(colour =
factor(leaves))) + scale_shape_manual("",values=**vals)



Which parameter do I need to change?



add scale_colour_discrete("") to your call. In order for scales to be
combined, the breaks, labels, and title must all be the same. You had
breaks and labels the same, but not the title.  Alternatively, change the
scale_shape_manual call to scale_shape_manual(values=**vals).


  thanks!





--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health&  Science University

__**
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]]




--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

__
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] Interactive stereoscopic 3d rendering with RGL plot3d?

2012-04-20 Thread Benedikt Orlowski
Dear R Users,

i' wondering, if there is any possibility to render interactive stereoscopic 3d 
plots in R and use the 
functionality of those new 3d displays (e.g. with poarisation technology) like 
this one:

> http://shop.fujitsu.com/de/displays/display-p23t-6p-fpr-3d

Does anyone know if there are developments toward this feature? Or perhaps 
someone
know how to implement such a function... 

Perhaps it can be easily implemented by synchronizing
two windows with different view angles (RGL package plot3d) and send those two 
pictures towards 
a screen driver. But i have now idea how to realize such thing. 

Best regards,
Bene




[[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] pasting a formula string with double quotes in it

2012-04-20 Thread Rui Barradas
Hello,


StellathePug wrote
> 
> Hello everyone,
> I have tried several ways of doing this and searched the documentation and
> help lists and I have been unable to find an answer or even whether it is
> possible to do it. I am pasting together a formula and I need to insert
> double quotes around the strings. Here's an example:
> 
>   location <- c("AL", "AK", "MA", "PA")
>   v=2
>   test <-  cbind(
>" <- cbind(df$DATE[df$LOCATION %in% c(",
>location[v], 
>")], df$WTD.AVG.PRICE[df$LOCATION %in% c(",
>location[v],   
>")])")
>   
>   test <- paste(test, collapse="")
>   test
>  
> Solution:
> [1] " <- cbind(df$DATE[df$LOCATION %in% c(AK)],
> df$WTD.AVG.PRICE[df$LOCATION %in% c(AK)])"
> 
> This does not produce an error message but it is obviously wrong because I
> need double quotes around AK, i.e.,
> " <- cbind(df$DATE[df$LOCATION %in% c("AK")], df$WTD.AVG.PRICE[df$LOCATION
> %in% c("AK")])"
> And obviously, I gave R no indication whatsoever to use double quotes.
> 
> 
> If I use 
>  test <- paste(test, collapse=""") 
> it does not work, which makes sense because the second double quote closes
> the first and the third is left an orphan.
> 
> Anyone have any ideas?
> 
> Thanks and have a great weekend!
> Rita
> 

Use single quotes instead, they don't close the double quotes and, for this,
the result is the same.
Look at the end/beginning of the lines before/after location[v]

test2 <-  cbind(
   " <- cbind(df$DATE[df$LOCATION %in% c('",
   location[v],
   "')], df$WTD.AVG.PRICE[df$LOCATION %in% c('",
   location[v],  
   "')])")
test2 <- paste(test2, collapse="")
test2

Hope this helps,

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/pasting-a-formula-string-with-double-quotes-in-it-tp4574419p4574888.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] Gamma Distribution - Goodness of Fit and Choice of Parameters

2012-04-20 Thread clangkamp
As a short disclaimer - I have read the previous posts on Fitting the Gamma
Distribution, but have two questions going beyond that:
1. Does anybody have a reference for the theory of fitting a gamma
distribution (i.e. whether to apply Kolmogorov-Smirnov, or similar)
2. Has anybody toyed around with the 3 Parameter Gamma Distribution of the
GAMLSS or VGAM package and what kind of accuracy gains of fitting a curve
can be be expected. I would love a bit more flexibility for a later
simulation study, but it seems a lot of hassle and a lot more theory
involved.
Best wishes
Christian

-
Christian Langkamp
christian.langkamp-at-gmxpro.de

--
View this message in context: 
http://r.789695.n4.nabble.com/Gamma-Distribution-Goodness-of-Fit-and-Choice-of-Parameters-tp4574940p4574940.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] Quick question about princomp/biplot

2012-04-20 Thread Filoche
Hi everyone. 

I performing a simple PCA using the princomp function. Then, I use the
biplot function to show it. However, the function use line number to
represent samples. I would like to know if there's a way to use a dot
(point) instead of the line number when using the biplot function.

With regards,
Phil

--
View this message in context: 
http://r.789695.n4.nabble.com/Quick-question-about-princomp-biplot-tp4574831p4574831.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] pasting a formula string with double quotes in it

2012-04-20 Thread StellathePug
Hello everyone,
I have tried several ways of doing this and searched the documentation and
help lists and I have been unable to find an answer or even whether it is
possible to do it. I am pasting together a formula and I need to insert
double quotes around the strings. Here's an example:

  location <- c("AL", "AK", "MA", "PA")
  v=2
  test <-  cbind(
   " <- cbind(df$DATE[df$LOCATION %in% c(",
   location[v], 
   ")], df$WTD.AVG.PRICE[df$LOCATION %in% c(",
   location[v],   
   ")])")
  
  test <- paste(test, collapse="")
  test
 
Solution:
[1] " <- cbind(df$DATE[df$LOCATION %in% c(AK)], df$WTD.AVG.PRICE[df$LOCATION
%in% c(AK)])"

This does not produce an error message but it is obviously wrong because I
need double quotes around AK, i.e.,
" <- cbind(df$DATE[df$LOCATION %in% c("AK")], df$WTD.AVG.PRICE[df$LOCATION
%in% c("AK")])"
And obviously, I gave R no indication whatsoever to use double quotes.


If I use 
 test <- paste(test, collapse=""") 
it does not work, which makes sense because the second double quote closes
the first and the third is left an orphan.

Anyone have any ideas?

Thanks and have a great weekend!
Rita


--
View this message in context: 
http://r.789695.n4.nabble.com/pasting-a-formula-string-with-double-quotes-in-it-tp4574419p4574419.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] Increase the size of the boxes but not the text in a legend

2012-04-20 Thread alles.khan
Although an old topic,

 To follow-up on the suggestion to alter the legend function. 

Type "legend" in R, copy-paste the appearing code into you code-editor and
search for the line 

points2(x1, y1, pch = pch[ok], col = col[ok], cex = pt.cex[ok],

the cex function controls the scaling, so you want the pt.cex become larger,
 
Change this line into, for example 
points2(x1, y1, pch = pch[ok], col = col[ok], cex = pt.cex[ok]+1.5, 

than you run in R
legend_large_box <- function (x, y etc.etc. the whole bunch of with the
altered legend code

and call the function legend_large_box within the plotting.

It worked for me.

--
View this message in context: 
http://r.789695.n4.nabble.com/Increase-the-size-of-the-boxes-but-not-the-text-in-a-legend-tp3759137p4574455.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] Re : Sort out number on value

2012-04-20 Thread Jeff Newmiller
I think

x[x>7.5]

gives more unsurprising results when none of the data meets the criteria than

 x[which(x>7.5)]

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

David Winsemius  wrote:

>
>On Apr 20, 2012, at 9:49 AM, Yellow wrote:
>
>> I now filtered the Na and Inf out of my data.
>> And the number is exactly the same als the output from the excel
>file.
>>
>> Thanks everyone. :)
>> Now I can finish my work.
>
>In the future it might be safer to use subset() or perhaps  
>x[which(x>7.5)]. That would omit the NA or NaN values (although it  
>might not remove the Inf values, but I didn't realize the Excel had a  
>concept of Inf).
>
>-- 
>
>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.

__
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] Re : Sort out number on value

2012-04-20 Thread David Winsemius


On Apr 20, 2012, at 9:49 AM, Yellow wrote:


I now filtered the Na and Inf out of my data.
And the number is exactly the same als the output from the excel file.

Thanks everyone. :)
Now I can finish my work.


In the future it might be safer to use subset() or perhaps  
x[which(x>7.5)]. That would omit the NA or NaN values (although it  
might not remove the Inf values, but I didn't realize the Excel had a  
concept of Inf).


--

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 quintiles of survival probabilities

2012-04-20 Thread David Winsemius


On Apr 20, 2012, at 7:16 AM, jolo999 wrote:


Hi,


I am using the package "demography" from Rob Hyndman for the
Lee-Carter-Model. It is an amazing powerful tool but I am struggling  
with

one issue:


*I want to compute different quintiles for the cumulative survival
probability derived from the Lee-Carter-Forecast (e.g. the 50%- 
quintile,

75%-quintile and 99%-quintile) for the next 10 years. *



The fact that you appear not to know the difference between the words  
'quantile' and 'quintile' makes me wonder whether what you are really  
asking for are confidence intervals at chosen significance levels?




I am sure the package possess this functionality but I didn't find  
any way

to calculate quintile values.


Hope you can help me!


Thanks

Jonas

--
View this message in context: 
http://r.789695.n4.nabble.com/Package-demography-calculating-quintiles-of-survival-probabilities-tp4573570p4573570.html
Sent from the R help mailing list archive at Nabble.com.
[[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] Ternaryplot as an inset graph

2012-04-20 Thread Greg Snow
The triplot function in the TeachingDemos package uses base graphics,
the subplot function (also in TeachingDemos) is another way to place a
plot within a plot (and triplot and subplot do work together).

If you want to stick to grid graphics then you can use viewports in
grid to insert one plot into another.

On Fri, Apr 20, 2012 at 10:05 AM, Ben Bolker  wrote:
> Young, Jennifer A  dfo-mpo.gc.ca> writes:
>
>> I am trying to add a ternary plot as a corner inset graph to a larger
>> main ternary plot. I have successfully used add.scatter in the past for
>> different kinds of plots but It doesn't seem to work for this particular
>> function. It overlays the old plot rather than plotting as an inset.
>>
>> Here is a simple version of what I'm trying. Note that if I change the
>> inset plot to be an ordinary scatter, for instance, it works as
>> expected.
>>
>> library(ade4)
>> library(vcd)
>> tdat <- data.frame(x=runif(20), y=rlnorm(20), z=rlnorm(20))
>> insetPlot <- function(data){
>>   ternaryplot(data)
>> }
>> ternaryplot(tdat)
>> add.scatter(insetPlot(tdat), posi="topleft", ratio=.2)
>>
>
>  I think the problem is that add.scatter assumes you're using base
> graphics, while ternaryplot() uses grid graphics.  Mixing and
> matching grid+base graphs is a little bit tricky.  You might try it with
> triax.plot() from the plotrix package, which I believe does ternary
> plots in base graphics ...
>
>  Ben Bolker
>
> __
> 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] Matrix multiplication by multple constants

2012-04-20 Thread Greg Snow
And another way is to remember properties of matrix multiplication:

y %*% diag(x)



On Fri, Apr 20, 2012 at 8:35 AM, David Winsemius  wrote:
>
> On Apr 20, 2012, at 4:57 AM, Dimitris Rizopoulos wrote:
>
>> try this:
>>
>> x  <- 1:3
>> y  <- matrix(1:12, ncol = 3, nrow = 4)
>>
>> y * rep(x, each = nrow(y))
>
>
> Another way with a function specifically designed for that purpose:
>
> sweep(y, 2, x, "*")
>
> -- David.
>
>
>>
>>
>> I hope it helps.
>>
>> Best,
>> Dimitris
>>
>>
>> On 4/20/2012 10:51 AM, Vincy Pyne wrote:
>>>
>>> Dear R helpers
>>>
>>> Suppose
>>>
>>> x<- c(1:3)
>>>
>>> y<- matrix(1:12, ncol = 3, nrow = 4)
>>>
 y
>>>
>>>     [,1] [,2] [,3]
>>> [1,]    1    5    9
>>> [2,]    2    6   10
>>> [3,]    3    7   11
>>> [4,]    4    8   12
>>>
>>> I wish to multiply 1st column of y by first element of x i.e. 1, 2nd
>>> column of y by 2nd element of x i.e. 2 an so on. Thus the resultant matrix
>>> should be like
>>>
 z
>>>
>>>
>>>     [,1]   [,2]    [,3]
>>>
>>> [1,]    1    10    27
>>>
>>> [2,]    2    12    30
>>>
>>> [3,]    3    14    33
>>>
>>> [4,]    4    16    36
>>>
>>>
>>> When I tried simple multiplication like x*y, y is getting multiplied
>>> column-wise
>>>
 x*z
>>>
>>>      [,1] [,2] [,3]
>>> [1,]    1    5    9
>>> [2,]    4   12   20
>>> [3,]    9   21   33
>>> [4,]   16   32   48
>>>
>>>
>>> Kindly guide
>>>
>>> Regards
>>>
>>> Vincy
>>>
>>>        [[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.
>>
>>
>> --
>> Dimitris Rizopoulos
>> Assistant Professor
>> Department of Biostatistics
>> Erasmus University Medical Center
>>
>> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
>> Tel: +31/(0)10/7043478
>> Fax: +31/(0)10/7043014
>> Web: http://www.erasmusmc.nl/biostatistiek/
>>
>> __
>> 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.



-- 
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] Print warning messages and save them automatically in a file

2012-04-20 Thread Greg Snow
Would using the 'sink' function with type='message' and split=TRUE do
what you want?

On Thu, Apr 19, 2012 at 2:00 AM, Alexander  wrote:
> Hello,
> I am working under R2.11.0 Windows and I would like to ask you if you know a
> way to save all warning messages obtained by the R function "warning" in a
> file and keeping the functionalities of the base-function warning. For
> example if I use external code, I don't want to replace all lines containing
> "warning(...)" by a selfwritten function. I want to execute it normally and
> everytime the external code makes a call to warning, I want the warnings
> message printed out in the console AND written in a file.
>
> My first solution is to redefine the function warning in the global
> environment such as:
>
> warning <- function(...){
>   write(...,"Warning.log",append=TRUE)
>   base::warning(...)
> #unfortunately the warning happens always in the function warning of the
> .GlobalEnv
> #and doesn't indicate anymore where the error happens :-(
> }
>
> This solution isn't very clean. I would like to try to redefine
> "warning.expression" in options. In last case, I don't understand how the
> passing of arguments works. I would like to do something like:
>
> options(warning.expression=quote({
>  write(...,"Warning.log",append=TRUE)
>  ?
>  }))
>
> I put the  because I don't know how I should call the function warning
> without being recursive and how I can pas arguments.
>
> Thank you
>
> Alexander
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Print-warning-messages-and-save-them-automatically-in-a-file-tp4570163p4570163.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] Error with Rcmd check library --as-cran

2012-04-20 Thread Duncan Murdoch

On 17/04/2012 7:23 PM, David Bapst wrote:

Hello all,

I was checking the newest update of my library before submitting it to
CRAN, using R 2.15.0 and Rtools for Windows 215 using Rcmd in the Command
Prompt, on my x64 Windows7 laptop. I recently heard that for checking
packages for CRAN submission one should use the option --as-cran;
previously I was submitting packages, so I was trying that for the first
time. The check proceeds fine until it tries running the examples, at which
point it produces the following error message:

>  pkgname<- "paleotree"
>  source(file.path(R.home("share"), "R", "examples-header.R"))
>  options(warn = 1)
>  options(pager = "console")
>  library('paleotree')
Loading required package: ape
Error in loadNamespace(i, c(lib.loc, .libPaths())) :
   there is no package called 'Matrix'
Error: package/namespace load failed for 'paleotree'
Execution halted

My package depends on ape, but not Matrix. Matrix is installed, though, on
my workstation, as are the other ape dependencies. The check works fine by
default and with the --timings option. What is different about --as-cran
that makes it unable to find Matrix?


This should now be fixed in R-patched and R-devel (revisions 59125 or 
larger), no need for the workaround I suggested yesterday.


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.


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

2012-04-20 Thread Jonathan Greenberg
Incidentally, if you want to test this out:

> A
 [,1] [,2] [,3]
[1,] 1457.738 1053.181 1256.953
[2,] 1053.181 1213.728 1302.838
[3,] 1256.953 1302.838 1428.269

> B
 [,1] [,2] [,3]
[1,] 4806.033 1767.480 2622.744
[2,] 1767.480 3353.603 3259.680
[3,] 2622.744 3259.680 3476.790

I THINK this is correct for the other parameters:
JOBVL="N"
JOBVR="N"
N=dim(A)[[1]]
LDA=N
LDB=N
LDVL=N
LDVR=N
LWORK=max(1,8*N)

.Call("La_dgeev", JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR=NA, ALPHAI=NA,
BETA=NA,
VL=NA, LDVL, VR=NA, LDVR, WORK=NA, LWORK, INFO=NA, PACKAGE="base")
LAPACK's documentation is:
http://www.netlib.org/lapack/double/dggev.f

--j

On Fri, Apr 20, 2012 at 11:58 AM, Jonathan Greenberg wrote:

> So I am a complete noob at doing this type of linking.  When I write this
> statement (all the input values are assigned, but I have to confess I don't
> know what to do with the output variables -- in this call they are all
> assigned "NA"):
>
> .Call("La_dgeev", JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR=NA, ALPHAI=NA,
> BETA=NA,
> + VL=NA, LDVL, VR=NA, LDVR, WORK=NA, LWORK, INFO=NA, PACKAGE="base")
>
> I get:
>
> Error in .Call("La_dgeev", JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR = NA,
>  :
>   C symbol name "La_dgeev" not in DLL for package "base"
>
> I'm running this on Windows 7 x64 version of R 2.14.2.  The R_ext/Lapack.h
> file states:
>
> /* DGEEV - compute for an N-by-N real nonsymmetric matrix A, the */
> /* eigenvalues and, optionally, the left and/or right eigenvectors */
> La_extern void
> F77_NAME(dgeev)(const char* jobvl, const char* jobvr,
> const int* n, double* a, const int* lda,
> double* wr, double* wi, double* vl, const int* ldvl,
>  double* vr, const int* ldvr,
> double* work, const int* lwork, int* info);
>
> Any ideas?
>
> --j
>
>
>
> On Fri, Apr 20, 2012 at 1:37 AM, Berend Hasselman  wrote:
>
>>
>> On 19-04-2012, at 20:50, Jonathan Greenberg wrote:
>>
>> > Folks:
>> >
>> > I'm trying to port some code from python over to R, and I'm running
>> into a
>> > wall finding R code that can solve a generalized eigenvalue problem
>> > following this function model:
>> >
>> >
>> http://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eig.html
>> >
>> > Any ideas?  I don't want to call python from within R for various
>> reasons,
>> > I'd prefer a "native" R solution if one exists.  Thanks!
>>
>> An old thread is here:
>> http://tolstoy.newcastle.edu.au/R/help/05/06/6802.html
>>
>> R does provide eigen().
>> R has the Lapack routines dggev and dgges in its library.
>> You'd have to write your own .Fortran interface to those routines.
>>
>> Berend
>>
>>
>
>
> --
> Jonathan A. Greenberg, PhD
> Assistant Professor
> Department of Geography and Geographic Information Science
> University of Illinois at Urbana-Champaign
> 607 South Mathews Avenue, MC 150
> Urbana, IL 61801
> Phone: 415-763-5476
> AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
> http://www.geog.illinois.edu/people/JonathanGreenberg.html
>



-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
607 South Mathews Avenue, MC 150
Urbana, IL 61801
Phone: 415-763-5476
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
http://www.geog.illinois.edu/people/JonathanGreenberg.html

[[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-20 Thread Jonathan Greenberg
So I am a complete noob at doing this type of linking.  When I write this
statement (all the input values are assigned, but I have to confess I don't
know what to do with the output variables -- in this call they are all
assigned "NA"):

.Call("La_dgeev", JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR=NA, ALPHAI=NA,
BETA=NA,
+ VL=NA, LDVL, VR=NA, LDVR, WORK=NA, LWORK, INFO=NA, PACKAGE="base")

I get:

Error in .Call("La_dgeev", JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR = NA,  :
  C symbol name "La_dgeev" not in DLL for package "base"

I'm running this on Windows 7 x64 version of R 2.14.2.  The R_ext/Lapack.h
file states:

/* DGEEV - compute for an N-by-N real nonsymmetric matrix A, the */
/* eigenvalues and, optionally, the left and/or right eigenvectors */
La_extern void
F77_NAME(dgeev)(const char* jobvl, const char* jobvr,
const int* n, double* a, const int* lda,
double* wr, double* wi, double* vl, const int* ldvl,
double* vr, const int* ldvr,
double* work, const int* lwork, int* info);

Any ideas?

--j



On Fri, Apr 20, 2012 at 1:37 AM, Berend Hasselman  wrote:

>
> On 19-04-2012, at 20:50, Jonathan Greenberg wrote:
>
> > Folks:
> >
> > I'm trying to port some code from python over to R, and I'm running into
> a
> > wall finding R code that can solve a generalized eigenvalue problem
> > following this function model:
> >
> >
> http://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eig.html
> >
> > Any ideas?  I don't want to call python from within R for various
> reasons,
> > I'd prefer a "native" R solution if one exists.  Thanks!
>
> An old thread is here:
> http://tolstoy.newcastle.edu.au/R/help/05/06/6802.html
>
> R does provide eigen().
> R has the Lapack routines dggev and dgges in its library.
> You'd have to write your own .Fortran interface to those routines.
>
> Berend
>
>


-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
607 South Mathews Avenue, MC 150
Urbana, IL 61801
Phone: 415-763-5476
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
http://www.geog.illinois.edu/people/JonathanGreenberg.html

[[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] Is there a overall calculation precision control in R

2012-04-20 Thread Jeff Newmiller
The straight answer is "no", there is plenty of precision available in a double 
precision float.  Nevertheless, keep in mind that some algorithms require 
iteration toward their solution and may have function arguments such as "tol" 
(tolerance) documented in the help files that define "good enough" for a 
particular calculation, and it is up to you to change these in the function 
call if the default doesn't work for your application. 

In other words, RTFM, and when that doesn't work Read The Source.
---
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.

"R. Michael Weylandt"  wrote:

>On the R level, I believe you're limited by the type of numeric
>representation being used: either 32-big integer or 64-bit double. See
>the storage.mode() of your objects. External code can make use of
>128-bit types if desired, but I don't believe those can be naturally
>represented back at the R level. Note, e.g.,:
>
>x <- 2147483647L
>storage.mode(x)
>x +1L
>
>which (for me) gives the same results on R32 and R64.
>
>One exception I know of is that Romain has done the hard work to
>provide a 64 bit integer here (package on CRAN):
>http://romainfrancois.blog.free.fr/index.php?post/2011/11/26/int64%3A-64-bit-integer-vectors-for-R
>but they aren't used in most packages so you'll have to make sure
>whatever algorithms you use play nice.
>
>Michael Weylandt
>
>On Fri, Apr 20, 2012 at 12:06 PM, Michael 
>wrote:
>> Hi all,
>>
>> I know the overall display precision can be changed in R...
>>
>> but what about overall calculation precision?
>>
>> Thank you!
>>
>>        [[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.

__
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] predictOMatic for regression. Please try and advise me

2012-04-20 Thread Paul Johnson
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 predictions in one step
predictOMatic(m1, fl = list(x2 = c(0.25, 1.0), xcat2 = c("M","D")))


predictOMatic(m1, fl = list(x2 = c(0.25, 1.0), xcat2 = c("M","D")),
interval="conf")

newdf <- predictOMatic(m1, fl = list(x2 = c(0.25, 1.0), xcat2 =
c("M","D"), x1=plotSeq(dat$x1)))

plot(y ~ x1, data= model.frame(m1))
by(newdf, list(newdf$x2, newdf$xcat2), function(x) {lines(x$x1, x$fit)})

newdataMaker(m1, fl = list(x2 = c(-1,0, 1), xcat2 = c("M","D")))

predictOMatic(m1, fl = list(x2 = range(dat$x2), xcat2 = c("M","D")))

newdf <- predictOMatic(m1, fl = list(x2 = quantile(dat$x2), xcat2 = c("M","D")))
plot(y ~ x2 , data=model.frame(m1))

lines(y ~ x2,  newdf)


predictOMatic(m1, fl = list(x2 = c(50, 60), xcat2 = c("M","D")),
interval="conf")

## just gets the new data
nd <- newdataMaker(m1, fl = list(x2 = c(50, 60), xcat2 = c("M","D")))

pr <- predictOMatic(m1, fl = list(x2 = c(50, 60), xcat2 = c("M","D")),
interval="conf")

##
m2 <- glm(xcat2 ~ x1 + x2 + x3 + xcat1, data=dat, family=binomial(logit))
summary(m2)
m2mf <- model.frame(m2)
summarize(m2mf)

predict(m2, newdata=data.frame(xcat1=c("M","F"), x1=c(1),
x2=mean(m2mf$x2), x3=mean(m2mf$x3)), se.fit=TRUE)

predictOMatic(m2, fl = list(x2 = c(-1, 1), xcat1 = c("M","F")),
interval="conf", type="response")



Now, the example session ###

> newdataMaker <- function (model = NULL, fl = NULL){
+ mf <- model.frame(model)
+ mterms <- terms(model)
+ mfnames <-

Re: [R] Is there a overall calculation precision control in R

2012-04-20 Thread R. Michael Weylandt
On the R level, I believe you're limited by the type of numeric
representation being used: either 32-big integer or 64-bit double. See
the storage.mode() of your objects. External code can make use of
128-bit types if desired, but I don't believe those can be naturally
represented back at the R level. Note, e.g.,:

x <- 2147483647L
storage.mode(x)
x +1L

which (for me) gives the same results on R32 and R64.

One exception I know of is that Romain has done the hard work to
provide a 64 bit integer here (package on CRAN):
http://romainfrancois.blog.free.fr/index.php?post/2011/11/26/int64%3A-64-bit-integer-vectors-for-R
but they aren't used in most packages so you'll have to make sure
whatever algorithms you use play nice.

Michael Weylandt

On Fri, Apr 20, 2012 at 12:06 PM, Michael  wrote:
> Hi all,
>
> I know the overall display precision can be changed in R...
>
> but what about overall calculation precision?
>
> Thank you!
>
>        [[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] How to make nice tiny sized figures on graphic devices producing scalable vector output?

2012-04-20 Thread Mikhail Titov
Hello!

I apologize for the previous e-mail that was unintentionally sent not as a
plain text and was unreadable.

Usually whenever I want a tiny plot, I just create it as is (or even large)
and then downscale it in the end application like LaTeX of MS Word. However,
all these graphic devices like postscript, pdf, win.metafile retain physical
sizes, so it would be natural if I can just insert graphics as is provided
those have proper physical sizes embedded.

The question is what is the best method to create plots in R with their
final physical sizes? I would like to create a good-looking figure by
starting with let’s say win.metafile(“some.emf”, 3.35, 2) .

Of course all defaults will produce something unreadable, so I have to scale
down everything with cex at least, and probably with lwd changes. I’ve tried
something like below. But dashed (and all other) lines are still too thick,
plotting symbols are undistinguishable etc. And in general it looks like a
mess to override all possible values.

Is there a better way to downscale whatever is being plotted on a device?

windowsFonts(Arial=windowsFont("TT Arial"))
cex <- .3
win.metafile("some.emf", 3.35, 2)
data <- data.frame(y=rep(c("a","b","c"), each=10), x=runif(30))
bwplot(y~x, data,
   par.settings = modifyList(
   simpleTheme(cex=cex, lwd=cex),
   c(
#   theme.nopadding,
   axis.line=list(lwd=cex))),
   panel=function(...) {
   panel.bwplot(..., pch="|")
#   panel.mean(..., pch=16)
   },
   cex=cex,
   ylab=list(label=expression(bold("my x label")), cex=cex),
   xlab=list(label=expression(bold("my y label")), cex=cex),
   scales=list(fontfamily="Arial", cex=cex),
   horizontal=TRUE)
dev.off()

Mikhail

__
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 make nice tiny sized figures on graphic devices producing scalable vector output?

2012-04-20 Thread Mikhail Titov
Hello!

 

Usually whenever I want a tiny plot, I just create it as is (or even large) and 
then downscale it in the end application like LaTeX of MS Word. However, all 
these graphic devices like postscript, pdf, win.metafile retain physical sizes, 
so it would be natural if I can just insert graphics as is provided those have 
proper physical sizes embedded.

 

The question is what is the best method to create plots in R with their final 
physical sizes? I would like to create a good-looking figure by starting with 
let’s say win.metafile(“some.emf”, 3.35, 2) .

 

Of course all defaults will produce something unreadable, so I have to scale 
down everything with cex at least, and probably with lwd changes. I’ve tried 
something like below. But dashed (and all other) lines are still too thick, 
plotting symbols are undistinguishable etc. And in general it looks like a mess 
to override all possible values.

 

Is there a better way to downscale whatever is being plotted on a device?

 

windowsFonts(Arial=windowsFont("TT Arial"))

cex <- .3

win.metafile("some.emf", 3.35, 2)

data <- data.frame(y=rep(c("a","b","c"), each=10), x=runif(30))

bwplot(y~x, data,

   par.settings = modifyList(

   simpleTheme(cex=cex, lwd=cex),

   c(

#   theme.nopadding,

   axis.line=list(lwd=cex))),

   panel=function(...) {

   panel.bwplot(..., pch="|")

#   panel.mean(..., pch=16)

   },

   cex=cex,

   ylab=list(label=expression(bold("my x label")), cex=cex),

   xlab=list(label=expression(bold("my y label")), cex=cex),

   scales=list(fontfamily="Arial", cex=cex),

   horizontal=TRUE)

dev.off()

 

Mikhail

 


[[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] Is there a overall calculation precision control in R

2012-04-20 Thread Michael
Hi all,

I know the overall display precision can be changed in R...

but what about overall calculation precision?

Thank you!

[[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] Ternaryplot as an inset graph

2012-04-20 Thread Ben Bolker
Young, Jennifer A  dfo-mpo.gc.ca> writes:

> I am trying to add a ternary plot as a corner inset graph to a larger
> main ternary plot. I have successfully used add.scatter in the past for
> different kinds of plots but It doesn't seem to work for this particular
> function. It overlays the old plot rather than plotting as an inset.
> 
> Here is a simple version of what I'm trying. Note that if I change the
> inset plot to be an ordinary scatter, for instance, it works as
> expected.
> 
> library(ade4)
> library(vcd)
> tdat <- data.frame(x=runif(20), y=rlnorm(20), z=rlnorm(20))
> insetPlot <- function(data){
>   ternaryplot(data)
> }
> ternaryplot(tdat)
> add.scatter(insetPlot(tdat), posi="topleft", ratio=.2)
> 

  I think the problem is that add.scatter assumes you're using base
graphics, while ternaryplot() uses grid graphics.  Mixing and
matching grid+base graphs is a little bit tricky.  You might try it with
triax.plot() from the plotrix package, which I believe does ternary
plots in base graphics ...

  Ben Bolker

__
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] Ternaryplot as an inset graph

2012-04-20 Thread Young, Jennifer A
Hello

I am trying to add a ternary plot as a corner inset graph to a larger
main ternary plot. I have successfully used add.scatter in the past for
different kinds of plots but It doesn't seem to work for this particular
function. It overlays the old plot rather than plotting as an inset.

Here is a simple version of what I'm trying. Note that if I change the
inset plot to be an ordinary scatter, for instance, it works as
expected.

library(ade4)
library(vcd)
tdat <- data.frame(x=runif(20), y=rlnorm(20), z=rlnorm(20))
insetPlot <- function(data){
  ternaryplot(data)
}
ternaryplot(tdat)
add.scatter(insetPlot(tdat), posi="topleft", ratio=.2)

Thanks very much,

Jennifer Young
Fisheries and Oceans Canada
jennifer.yo...@dfo-mpo.gc.ca


[[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-20 Thread ilai
Duncan,
First off, I admit it is not clear to me what you are trying to
achieve and more importantly, why? by "why" I mean 1) I don't see the
advantage of writing one general panel function for completely
different situations (one/multiple smoothers, grouping levels etc.) 2)
your intended result as I understand it seems rather cluttered, google
. 3) I am unfamiliar with locfit package, but are we
reinventing the wheel here ? i.e. will modifying settings in xyplot(y
~x, xx, groups = Farm, type=c('p','smooth')) achieve the same ?

With your initial reproducible example (thank you) it was easy to
eliminate the errors, but clearly the resulting plots are not what you
intended (continue inline):

On Thu, Apr 19, 2012 at 4:23 PM, Duncan Mackay  wrote:

> 3. What I want to be able to add in the above is extra lines with different
> values of nn.
>   I think I will have to modify panel.Locfit so that it goes through
> different values of nn in each of the panels and groups if I want different
> colours for extra lines with different nn values

Yes you could. There are several options:
add group.number to the arguments of panel.locfit and use it to make
nn a vector, along the lines of
panel.foo <- function(x,y,group.number,theta,...){
  smpar <- theta[group.number]
  panel.loess(x,y,smpar,...)
  panel.xyplot(x,y,...)
}
 
xyplot(y~x,xx,group=Farm,theta=c(4,1,.4),panel=panel.superpose,panel.groups=panel.foo)

 # or
xyplot(y~x|Farm,xx,group=Padd,theta=c(.6,1),
panel=panel.superpose,panel.groups=panel.foo)

Here you will need to modify the Farm group to 6 levels - 3*two smoothers.

You could make nn a list and loop over it inside the panel function.
Looks like you tried something like that with specifying 2
panel.Locfit, one suggestion to your code:

 panel.Locfit(x,y,...) # default 0.7
panel.Locfit(x,y,nn=0.9)   # i.e. remove the
... to avoid clashes

Finally, use ?trellis.focus to plot the second smoother "post-hoc".
also the latticeExtra package has many useful tools to create layers
of the same (or different) plot with different settings.

> 4 Produce an extra line for a fit for all the groups in 1/2+ panels.
>   As for 3 but I do not know how to group all the x and y's  for each of the
> panes using panel.groups

Why does it matter ? seems you have failed to learn the lesson from
the first post - the same functionality applies to 1 as to multiple
panels. Does each panel have a different grouping structure ? use
packet.number() for panels similar to group.number idea.

> I need to do this and then scale up for a panel function to include
> confidence bands

than expand the xlim,ylim or scales in ?xyplot

>
> For the record making Farm and Padd factors. With 1 panel and groups = Farm
> works with the extra line the same colour for its group
> a similar situation for the three panels when conditioned by Farm and groups
> = Pad



Like I said I am a little lost on this problem but I hope this helps
giving some direction.
Cheers


>
>  xyplot(y ~x, xx,
>         groups = Farm,
>
>         par.settings = list(strip.background = list(col = "transparent"),
>                             superpose.line   = list(col = c("black","grey"),
>                                                             lwd = c(1,2,3),
>                                                             lty = c(2,1,3)),
>                             superpose.symbol = list(cex = c(0.8, 0.7,0.7),
>                                                     col =
> c("red","black","blue"),
>                                                     pch = c(20,4,16))
>                   ),
>         auto.key=list(lines=T,points = T,rectangles=F),
>
>         panel  = panel.superpose,
>         panel.groups=function(x,y, ...){
>
>                        panel.xyplot(x,y,...)
>                        panel.Locfit(x,y,...) # default 0.7
>                        panel.Locfit(x,y,nn=0.9,...)
>
>                      }
>  ) ## xyplot
>
>
> Regards
>
> Duncan
>
>
> At 02:12 20/04/2012, you wrote:
>>
>> On Thu, Apr 19, 2012 at 2:30 AM, Duncan Mackay 
>> wrote:
>> > Hi
>> >
>> >  xyplot(y ~x|Farm,xx,
>> >         groups = Padd,
>> >         panel = panel.superpose,
>> >         panel.groups=function(x,y, ...){
>> >                        panel.Locfit(x,y,...)
>> >                        panel.xyplot(x,y,...)
>> >                      }
>> >  ) ## xyplot
>> >
>> > The above works nicely and also without par.setting giving lattice
>> > defaults.
>> > The par.setting is handy for a lot of graphs that I do.
>> >
>> > But when I tried a 1 panel plot I get the error message.
>> >
>> >  xyplot(y ~x,xx,
>> >         groups = Farm,
>> >         auto.key=TRUE,
>> >         panel = function(x,y, ...){
>> >
>> >                        panel.Locfit(x,y,...)
>> >                        panel.xyplot(x,y,...)
>> >                      }
>> >         )
>> >
>>
>> These two plots are NOT THE SAME. Did you want the same as the

Re: [R] error loading tcltk2

2012-04-20 Thread peter dalgaard

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.

-- 
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] PCA sensitive to outliers?

2012-04-20 Thread Kevin Wright
You can also have a look at the pcaMethods package on Bioconductor.

Kevin


On Thu, Apr 19, 2012 at 11:20 PM, Michael  wrote:

> Hi all,
>
> I found that the PCA gave chaotic results when there are big changes in a
> few data points.
>
> Are there "improved" versions of PCA in R that can help with this problem?
>
> Please give me some pointers...
>
> Thank you!
>
>[[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.
>



-- 
Kevin Wright

[[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] symmetric matrix on both diagonals

2012-04-20 Thread David Winsemius


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


> N <- matrix(c(1,2,3,6,2,7,4,3,3,4,7,2,6,3,2,1), ncol=4)
> N==M
 [,1] [,2] [,3] [,4]
[1,] TRUE TRUE TRUE TRUE
[2,] TRUE TRUE TRUE TRUE
[3,] TRUE TRUE TRUE TRUE
[4,] TRUE TRUE TRUE TRUE




Hope this helps.

Petr Savicky.

__
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] Problem with Tukey test

2012-04-20 Thread Tal Galili
Hi,
I can not reproduce your problem.

Can you use ?dput, and try to create a self contained example?

Here is my attempt:

warpbreaks1 <- warpbreaks
warpbreaks1[1,1] <- NA
fm1 <- aov(breaks ~ tension, data = warpbreaks1)
summary(fm1)
TukeyHSD(fm1)


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 Fri, Apr 20, 2012 at 4:21 PM, danipaty13  wrote:

> I'm new using R im trying to do a tukey test, but when i see the results
> the
> p value results in NA im guessing its because i have missing values but im
> not sure how to fix it
>
> AnovaModel.2 <- aov(area ~ trat, data=apilados)
>
> > summary(AnovaModel.2)
>Df Sum Sq Mean Sq F valuePr(>F)
> trat 4  11847 2961.76  9.9905 1.500e-06 ***
> Residuals   76  22531 296.46
> ---
> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
> 14 observations deleted due to missingness
>
> > numSummary(apilados$area , groups=apilados$trat, statistics=c("mean",
> > "sd"))
>   mean sd  n NA
> X1 79.29625 15.06667 16  3
> X2 77.43400 10.64849 15  4
> X3 71.19895 15.85500 19  0
> X4 77.80938 24.67359 16  3
> X5 45.97200 16.65112 15  4
>
> > TukeyHSD(AnovaModel.2)
>  Tukey multiple comparisons of means
>95% family-wise confidence level
>
> Fit: aov(formula = area ~ trat, data = apilados)
>
> $trat
> diff  lwr upr p adj
> X2-X1  -1.862250  NA  NANA
> X3-X1  -8.097303  NA  NANA
> X4-X1  -1.486875  NA  NANA
> X5-X1 -33.324250  NA  NANA
> X3-X2  -6.235053  NA  NANA
> X4-X2   0.375375  NA  NANA
> X5-X2 -31.462000  NA  NANA
> X4-X3   6.610428  NA  NANA
> X5-X3 -25.226947  NA  NANA
> X5-X4 -31.837375  NA  NANA
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Problem-with-Tukey-test-tp4573945p4573945.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] Forward of moderated message

2012-04-20 Thread David Winsemius


On Apr 20, 2012, at 6:57 AM, Adrian Duşa wrote:


One solution among many:

seq(970, 970 - 30*14, by=-30)


If you want to be fancy, a function can be easily written:
seqf <- function(startp, lengthv, byv) {
   seq(startp, startp + (lengthv - 1)*byv, by=byv)
}

seqf(970, 15, -30)
[1] 970 940 910 880 850 820 790 760 730 700 670 640 610 580 550



A slightly more verbose but potentially more generalizable solution:

> Reduce("-", rep(30, 15), init=1000, accumulate=TRUE)
 [1] 1000  970  940  910  880  850  820  790  760  730  700  670   
640  610  580  550


An application to construct a geometrically declining sequence of  
specific length:

> Reduce("*", rep(.75, 15), init=1000, accumulate=TRUE)
 [1] 1000.0  750.0  562.5  421.87500  316.40625   
237.30469  177.97852  133.48389
 [9]  100.11292   75.08469   56.31351   42.23514   31.67635
23.75726   17.81795   13.36346


--
David.



Hth,
Adrian

On Fri, Apr 20, 2012 at 13:45,   wrote:



-- Forwarded message --
From: uday 
To: r-help@r-project.org
Cc:
Date: Fri, 20 Apr 2012 02:14:03 -0700 (PDT)
Subject: vector subtraction
I would like to calculate vector from existing  value
e.g
v   <- 1000
s   <- 30
d1<- v-s
  d1<- 970
d2<- d1 -s
  d2<- 940
d 3   <- d2-s
  d3<- 910
:
:
d15   <- .

so how I should get vector of length 15 d < -  970,940 ,  
910 ,

...

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






--
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
   +40 21 3120210 / int.101
Fax: +40 21 3158391

__
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] Matrix multiplication by multple constants

2012-04-20 Thread David Winsemius


On Apr 20, 2012, at 4:57 AM, Dimitris Rizopoulos wrote:


try this:

x  <- 1:3
y  <- matrix(1:12, ncol = 3, nrow = 4)

y * rep(x, each = nrow(y))


Another way with a function specifically designed for that purpose:

sweep(y, 2, x, "*")

--  
David.





I hope it helps.

Best,
Dimitris


On 4/20/2012 10:51 AM, Vincy Pyne wrote:

Dear R helpers

Suppose

x<- c(1:3)

y<- matrix(1:12, ncol = 3, nrow = 4)


y

 [,1] [,2] [,3]
[1,]159
[2,]26   10
[3,]37   11
[4,]48   12

I wish to multiply 1st column of y by first element of x i.e. 1,  
2nd column of y by 2nd element of x i.e. 2 an so on. Thus the  
resultant matrix should be like



z


 [,1]   [,2][,3]

[1,]11027

[2,]21230

[3,]31433

[4,]41636


When I tried simple multiplication like x*y, y is getting  
multiplied column-wise



x*z

  [,1] [,2] [,3]
[1,]159
[2,]4   12   20
[3,]9   21   33
[4,]   16   32   48


Kindly guide

Regards

Vincy

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


--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/

__
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] depmixS4+transition

2012-04-20 Thread Ingmar Visser
Dear Nglthu,

Not sure what you mean by scale(x1,x2), this:

library(depmixS4)
data(speed)

x1 <- rnorm(nrow(speed))
x2 <- rnorm(nrow(speed))

scale(x1,x2)

produces an error ...

but, the use of two predictors or covariates on the transition matrix is
possible:

speed$x2 <- x2

 mod1 <- depmix(list(rt~1,corr~1),data=speed,transition=~Pacc+x2,nstates=2,
family=list(gaussian(),multinomial("identity")),ntimes=c(168,134,137))

set.seed(3)

fmod1 <- fit(mod1)

Above code produces sensible results.

Hth, Ingmar Visser

On Fri, Apr 20, 2012 at 5:14 AM, nglthu  wrote:

> Dear helpers,
> is there any possible that transition (in depmixS4) is in scale of two
> variable, e.g transition=~scale(x1,x2)?
> If it can be, how transition of two variable (covariate time) can be worked
> in depmixS4-hidden markov model for time series.
>
> Many thanks,
> nglthu
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/depmixS4-transition-tp4572726p4572726.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] error loading tcltk2

2012-04-20 Thread Duncan Murdoch

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.


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] Problem with Tukey test

2012-04-20 Thread danipaty13
I'm new using R im trying to do a tukey test, but when i see the results the
p value results in NA im guessing its because i have missing values but im
not sure how to fix it

AnovaModel.2 <- aov(area ~ trat, data=apilados)

> summary(AnovaModel.2)
Df Sum Sq Mean Sq F valuePr(>F)
trat 4  11847 2961.76  9.9905 1.500e-06 ***
Residuals   76  22531  296.46  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
14 observations deleted due to missingness

> numSummary(apilados$area , groups=apilados$trat, statistics=c("mean",
> "sd"))
   mean sd  n NA
X1 79.29625 15.06667 16  3
X2 77.43400 10.64849 15  4
X3 71.19895 15.85500 19  0
X4 77.80938 24.67359 16  3
X5 45.97200 16.65112 15  4

> TukeyHSD(AnovaModel.2)
  Tukey multiple comparisons of means
95% family-wise confidence level

Fit: aov(formula = area ~ trat, data = apilados)

$trat
 diff  lwr upr p adj
X2-X1  -1.862250  NA  NANA
X3-X1  -8.097303  NA  NANA
X4-X1  -1.486875  NA  NANA
X5-X1 -33.324250  NA  NANA
X3-X2  -6.235053  NA  NANA
X4-X2   0.375375  NA  NANA
X5-X2 -31.462000  NA  NANA
X4-X3   6.610428  NA  NANA
X5-X3 -25.226947  NA  NANA
X5-X4 -31.837375  NA  NANA


--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-Tukey-test-tp4573945p4573945.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] Re : Re : Sort out number on value

2012-04-20 Thread Pascal Oettli
What is the result with 
> x[x>7.5]




- Mail original -
De : Yellow 
À : r-help@r-project.org
Cc : 
Envoyé le : Vendredi 20 avril 2012 21h31
Objet : Re: [R] Re :  Sort out number on value

I found out something strange when I used the same thing on another data
file. 

In a excel file I have same data too and there I asked in a certain column
what values where above the 7.5. Result: 206. 
Now I have done the same thing in R and I get as result: 400. 

My code: 
# Find values above 7.5. 
C = x[x => 7.5]

# Calculate length. 
number = length[C]

# print outcome
number 

Or could it have something to do that I have calculated the log2 value from
a value dat was like: 7.84394 -01 However I don't think that was the problem
since I cheaked the first 10 log2 values, and they where correct. 

I just don't understand why the answer is now higer, 400 and not 206. 

--
View this message in context: 
http://r.789695.n4.nabble.com/Sort-out-number-on-value-tp4573467p4573764.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-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] error loading tcltk2

2012-04-20 Thread Roberto Ugoccioni
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.

[[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] Creating a point pattern with spatstat

2012-04-20 Thread AMFTom
The graphic produced was what I was after, except it was inverted. The
original tabular data represents a plot as oriented in the field i.e. with
North at the top, South at the bottom. The graphic from this had South at
the top and North at the bottom, so I input the data the other way around
i.e. instead of:

X12 = c(0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L)), 

I changed it to 

X12 = c(1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L)),

Is there a way that R can read these data as Cartesian co-ordinates to save
having to write out the whole table every time? 

--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-a-point-pattern-with-spatstat-tp4562047p4573538.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] Package "demography" - calculating quintiles of survival probabilities

2012-04-20 Thread jolo999
Hi,


I am using the package "demography" from Rob Hyndman for the
Lee-Carter-Model. It is an amazing powerful tool but I am struggling with
one issue: 


*I want to compute different quintiles for the cumulative survival
probability derived from the Lee-Carter-Forecast (e.g. the 50%-quintile,
75%-quintile and 99%-quintile) for the next 10 years. * 


I am sure the package possess this functionality but I didn't find any way
to calculate quintile values.


Hope you can help me!


Thanks

Jonas

--
View this message in context: 
http://r.789695.n4.nabble.com/Package-demography-calculating-quintiles-of-survival-probabilities-tp4573570p4573570.html
Sent from the R help mailing list archive at Nabble.com.
[[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] Re : Sort out number on value

2012-04-20 Thread Yellow
I now filtered the Na and Inf out of my data. 
And the number is exactly the same als the output from the excel file. 

Thanks everyone. :) 
Now I can finish my work. 

--
View this message in context: 
http://r.789695.n4.nabble.com/Sort-out-number-on-value-tp4573467p4574026.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] Trouble with [sv]apply

2012-04-20 Thread Bert Gunter
Worik:

On Fri, Apr 20, 2012 at 1:22 AM, Worik R  wrote:
> On Fri, Apr 20, 2012 at 4:42 PM, Jeff Newmiller
>  wrote:
>> If you read the help, it talks about compiling vectors into matrices, or 
>> scalars into vectors. It does not say anything about combining matrices.
>>
>> For the error about 14 elements, you should keep in mind that matrices are 
>> just vectors with dim attributes that indicate how the linear memory is to 
>> be "folded".
>>
>> As far as I know, the standard way to handle combining matrices as you want 
>> to would involve storing them in a list and using Reduce and rbind. If you 
>> can vectorize the whole process instead of segmenting it by groups of rows 
>> then you can speed things up considerably.
>
> Thank you.  That was helpful.  I did read the help on [vsl]apply.  But
> the idea that matrices are "folded vectors" was, of course not there.

It certainly is -- where it should be:
?matrix  says:

"is.matrix returns TRUE if x is a vector and has a "dim" attribute of
length 2) and FALSE otherwise."

and even

"If you just want to convert a vector to a matrix, something like

  dim(x) <- c(nx, ny)
  dimnames(x) <- list(row_names, col_names)

will avoid duplicating x. "

Please do not fault R for your errors.

-- Bert
>
> Worik
>
>> ---
>> Jeff Newmiller                        The     .       .  Go Live...
>> DCN:        Basics: ##.#.       ##.#.  Live Go...
>>                                      Live:   OO#.. Dead: OO#..  Playing
>> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
>> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
>> ---
>> Sent from my phone. Please excuse my brevity.
>>
>> Worik R  wrote:
>>
>>>Friends
>>>
>>>I clearly donot understand how sapply and vapply work.
>>>
>>>What I have is a function that returns a matrix with an indeterminate
>>>number of rows (some times zero) but a constant number of columns.  I
>>>cannot reliably use an apply function to assemble the matrices into a
>>>matrix.  I am not sure it is possible.
>>>
>>>I can demonstrate the core of my confusion with this simple code.
>>>
>>>A.f <- function(i){
>>>  ret <- matrix("a", i, 7)
>>>  cat(i, class(ret), dim(ret), "\n")
>>>  return(ret)
>>>}
>>>V.f <- function(){
>>>  SS <- vapply(c(1,2),
>>>                 A.f,
>>>                 rep('a', 7))
>>>  return(SS)
>>>}
>>>S.f <- function(){
>>>  SS <- sapply(c(1,2),
>>>                 A.f)
>>>  cat("SS", class(SS), dim(SS), "\n")
>>>  return(SS)
>>>}
>>>
>>>
>>>Calling V.f() fails:
>>>
 V.f()
>>>1 matrix 1 7
>>>2 matrix 2 7
>>>Error in vapply(c(1, 2), A.f, rep("a", 7)) :
>>>  values must be length 7,
>>> but FUN(X[[2]]) result is length 14

>>>
>>>
>>>Calling S.f() returns a list.
>>>
>>>
>>>Do I have to accept I am going to be getting a list and I have to
>>>assemble a matrix in a loop?
>>>
>>>cheers
>>>Worik
>>>
>>>__
>>>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.



-- 

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

__
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] Re : Sort out number on value

2012-04-20 Thread Petr PIKAL
Hi

Without data it is only a guess.
> 
> I found out something strange when I used the same thing on another data
> file. 
> 
> In a excel file I have same data too and there I asked in a certain 
column
> what values where above the 7.5. Result: 206. 
> Now I have done the same thing in R and I get as result: 400. 

I was tempted to assign it to FAQ 7.31 about finite precision of decimals. 
However such a big difference is rather strange.

> 
> My code: 
> # Find values above 7.5. 
> C = x[x => 7.5]
> 
> # Calculate length. 
> number = length[C]

Shouldn't it be length(C)? 

> 
> # print outcome
> number 

I personally suspect NA values which are retained after subsetting. Output 
from

str(your object)

could help.

Maybe you want only number of values. For that you shall to use

sum(!is.na(C))

But maybe I am on a wrong track.

Regards
Petr


> 
> Or could it have something to do that I have calculated the log2 value 
from
> a value dat was like: 7.84394 -01 However I don't think that was the 
problem
> since I cheaked the first 10 log2 values, and they where correct. 
> 
> I just don't understand why the answer is now higer, 400 and not 
206. 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Sort-out-
> number-on-value-tp4573467p4573764.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-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] Re : Sort out number on value

2012-04-20 Thread Yellow
I see the problem. 
There are 400, but there are Na and Inf is there for like 1/2, and I need to
get those out. 

Think I need to filter those out. 
Now that would make sense. LoL 

--
View this message in context: 
http://r.789695.n4.nabble.com/Sort-out-number-on-value-tp4573467p4573905.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] Survival, should I use (start,stop) and how?

2012-04-20 Thread Asa Johannesen
Dear R users,

I fear this is terribly trivial but I'm struggling to get my head around it.

First of all, I'm using the "survival" package in R 2.12.2 on Windows Vista 
with the RExcel plugin. You probably only need to know that I'm using 
"survival" for this.

I have data collected from 180 or so individuals that were checked 7 times 
throughout a trial with set start and end times. Once the event happens (death 
by predator) there are no more checks for that individual. This means that I 
check on each individual up to 7 times with either an event recorded or the 
final time being censored.

At the moment, I have a data sheet with one observation per individual; that is 
either the event time (the observation time when the individual had had an 
event) or the censored time. However, I'd like to add a time dependent factor 
and I also wonder if this data should be treated as interval censored.

The time dependent factor is like this. The individuals are grouped in "houses" 
and once one individual in a group has an event, it makes biological sense that 
the rest of them should be at greater risk, as the predator is likely to have 
discovered the others in the "house" as well (the predator is able to consume 
many individuals). At the moment I'm coding this as a normal two level factor 
(discovered) where all individuals alive after the first event in that house 
are "TRUE" and the first individuals in a house to be eaten are "FALSE". All 
individuals in houses that were not discovered at al are also "FALSE"l. 
Obviously, all individuals that were eaten, were first discovered, then eaten. 
However, the first individuals in a house to be eaten, had not been previously 
discovered by the predator (not observably so, anyway).

Should I write up this data set with a start and stop time for every check I 
made so each individual has up to 7 records, one for each time I checked?

Is there a quick and easy way to do this in R or would I have to go through the 
data set manually?

Does coding the "discovered" factor the way I have, make statistical sense? 

Should I worry about proportional hazards of the "discovered" factor? It seems 
to me that it would often turn out not proportional because of its nature.

Sorry, lots of stats questions. I don't mind if you don't answer all of these. 
Just knowing how to best feed this data into R would help me no end. The rest I 
can probably glean from the millions of survival analysis books I have lying 
about.

Cheers,

Freya

PS: Example data as it is: Treatment has 3 levels and House 6, though I don't 
normally include House in the analysis as it's not so much the house as whether 
the individuals were previously discovered that is interesting. I may include 
it as a random factor or stratify by it, but I want to get the basics sorted 
before I tackle that.


ID  Time  Event  Discovered   Treatment  House
1 10  1   FALSE  11
2 20  1   TRUE   11
3 90  0   TRUE   11
4 10  1   FALSE  25
5 10  1   FALSE  25
6 40  1   TRUE   25

Should ID 2 have two rows, one with no event at time 10? Should it be coded 
with start and end times as (first row) 0, 10, 0 (second row) 10, 20, 1?
__
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] Re : Sort out number on value

2012-04-20 Thread Yellow
I found out something strange when I used the same thing on another data
file. 

In a excel file I have same data too and there I asked in a certain column
what values where above the 7.5. Result: 206. 
Now I have done the same thing in R and I get as result: 400. 

My code: 
# Find values above 7.5. 
C = x[x => 7.5]

# Calculate length. 
number = length[C]

# print outcome
number 

Or could it have something to do that I have calculated the log2 value from
a value dat was like: 7.84394 -01 However I don't think that was the problem
since I cheaked the first 10 log2 values, and they where correct. 

I just don't understand why the answer is now higer, 400 and not 206. 

--
View this message in context: 
http://r.789695.n4.nabble.com/Sort-out-number-on-value-tp4573467p4573764.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] Manually reconstructing arima model from coefficients

2012-04-20 Thread R. Michael Weylandt
Ahh, I understand -- unfortunately, I'm not aware of an easy way to do
this so you'll have to hack your own: this doesn't look too hard
however, if you call

getAnywhere(predict.Arima)

you can get the prediction scheme R uses. It seems that most of the
heavy lifting is already in C so you'd probably be best served by
simply updating the residuals series.

Michael

On Tue, Apr 17, 2012 at 9:21 PM, Sergey Samsonov  wrote:
> Michael
>
> My final goal is to perform forecasting in real time. My historical data
> that is used for training consist of about 2000 samples. Fitting ARIMA model
> x.fit<-arima(x, order = c(5,0,0), seasonal = list(order=c(0,0,1))) takes
> about 3-5 minutes, often I do not have so much time between receiving new
> samples of data. Therefore, I want to re-create my arima model let's say
> only every 50 samples but I want to update my forecast every time new data
> sample arrives (in a real time).
>
> In other words I want to apply my arima model to forecasting future events
> that will occurre not right after the model was created but some time later
> after a few more intermediate samples were received. I think this problem is
> similar to applying already fitted arima forecasting to a new time series
> object that has similar statistical properties as a tested set, since these
> are the same series just shifted in the future.

__
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-20 Thread juliane0212


That is exactly what I was looking for.

Thank you

--
View this message in context: 
http://r.789695.n4.nabble.com/symmetric-matrix-on-both-diagonals-tp4573418p4573594.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-20 Thread Petr Savicky
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

Hope this helps.

Petr Savicky.

__
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] Forward of moderated message

2012-04-20 Thread Adrian Duşa
One solution among many:

seq(970, 970 - 30*14, by=-30)


If you want to be fancy, a function can be easily written:
seqf <- function(startp, lengthv, byv) {
seq(startp, startp + (lengthv - 1)*byv, by=byv)
}

seqf(970, 15, -30)
 [1] 970 940 910 880 850 820 790 760 730 700 670 640 610 580 550



Hth,
Adrian

On Fri, Apr 20, 2012 at 13:45,   wrote:
>
>
> -- Forwarded message --
> From: uday 
> To: r-help@r-project.org
> Cc:
> Date: Fri, 20 Apr 2012 02:14:03 -0700 (PDT)
> Subject: vector subtraction
> I would like to calculate vector from existing  value
> e.g
> v       <- 1000
> s       <- 30
> d1    <- v-s
>                   d1    <- 970
> d2    <- d1 -s
>                   d2    <- 940
> d 3   <- d2-s
>                   d3    <- 910
> :
> :
> d15   <- .
>
> so how I should get vector of length 15         d < -  970,940 , 910 ,
> ...
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/vector-subtraction-tp4573299p4573299.html
> Sent from the R help mailing list archive at Nabble.com.
>
>



-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
       +40 21 3120210 / int.101
Fax: +40 21 3158391

__
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] Intergration of a function

2012-04-20 Thread R. Michael Weylandt
whathaveyoutried.com

Michael

On Fri, Apr 20, 2012 at 5:47 AM, dcgf  wrote:
> I am trying to integrate this function
>
> f_x(x) = (1/(2pi))*(1+sin(2x)) for o < x < 2
>
> I know the answer is (x/(2*pi))-(cos(2x)/(4*pi)) but I must be doing
> something wrong..
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Intergration-of-a-function-tp4573362p4573362.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-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] vector subtraction

2012-04-20 Thread R. Michael Weylandt
You're thinking about it wrong. This is an arithmetic sequence:

seq(from = 1000, by = -30, length.out = 15)

Michael



On Fri, Apr 20, 2012 at 5:14 AM, uday  wrote:
> I would like to calculate vector from existing  value
> e.g
> v       <- 1000
> s       <- 30
> d1    <- v-s
>                   d1    <- 970
> d2    <- d1 -s
>                   d2    <- 940
> d 3   <- d2-s
>                   d3    <- 910
> :
> :
> d15   <- .
>
> so how I should get vector of length 15         d < -  970,940 , 910 ,
> ...
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/vector-subtraction-tp4573299p4573299.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-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] Re : Sort out number on value

2012-04-20 Thread Yellow
Thanks everyone. :) 


--
View this message in context: 
http://r.789695.n4.nabble.com/Sort-out-number-on-value-tp4573467p4573512.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] Intergration of a function

2012-04-20 Thread dcgf
I am trying to integrate this function

f_x(x) = (1/(2pi))*(1+sin(2x)) for o < x < 2

I know the answer is (x/(2*pi))-(cos(2x)/(4*pi)) but I must be doing
something wrong..

--
View this message in context: 
http://r.789695.n4.nabble.com/Intergration-of-a-function-tp4573362p4573362.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] vector subtraction

2012-04-20 Thread uday
I would like to calculate vector from existing  value 
e.g 
v   <- 1000 
s   <- 30 
d1<- v-s 
   d1<- 970 
d2<- d1 -s
   d2<- 940  
d 3   <- d2-s 
   d3<- 910 
:
:
d15   <- .

so how I should get vector of length 15 d < -  970,940 , 910 ,
... 

--
View this message in context: 
http://r.789695.n4.nabble.com/vector-subtraction-tp4573299p4573299.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] Re : Sort out number on value

2012-04-20 Thread Pascal Oettli
HI,

x[x>20]

Regards.


- Mail original -
De : Yellow 
À : r-help@r-project.org
Cc : 
Envoyé le : Vendredi 20 avril 2012 19h26
Objet : [R] Sort out number on value

Can anyone help me maybe with a question I can seem to find an answer on. 

I have this: x = c(1, 5, 70, 53, 7, 29, 75, 37, 30, 11) 

And I would like to have the numbers above 20 selected out. 
But I can't find what code I need for that 
I tried sort(), but then I can't fill in I only need those above 20. 

--
View this message in context: 
http://r.789695.n4.nabble.com/Sort-out-number-on-value-tp4573467p4573467.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-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] Sort out number on value

2012-04-20 Thread R. Michael Weylandt
This really has little to do with sorting, but can be much more easily
done with logical subscripting:

x[x < 20]

which I read as "x such that x is less than 20".

Hope this helps,
Michael

On Fri, Apr 20, 2012 at 6:26 AM, Yellow  wrote:
> Can anyone help me maybe with a question I can seem to find an answer on.
>
> I have this: x = c(1, 5, 70, 53, 7, 29, 75, 37, 30, 11)
>
> And I would like to have the numbers above 20 selected out.
> But I can't find what code I need for that
> I tried sort(), but then I can't fill in I only need those above 20.
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Sort-out-number-on-value-tp4573467p4573467.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-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] Trouble with [sv]apply

2012-04-20 Thread Petr PIKAL
Hi
 
> On Fri, Apr 20, 2012 at 4:42 PM, Jeff Newmiller
>  wrote:
> > If you read the help, it talks about compiling vectors into matrices, 
or
> scalars into vectors. It does not say anything about combining matrices.
> >
> > For the error about 14 elements, you should keep in mind that matrices 

> are just vectors with dim attributes that indicate how the linear memory 

> is to be "folded".
> >
> > As far as I know, the standard way to handle combining matrices as you 

> want to would involve storing them in a list and using Reduce and rbind. 

> If you can vectorize the whole process instead of segmenting it by 
groups 
> of rows then you can speed things up considerably.
> 
> Thank you.  That was helpful.  I did read the help on [vsl]apply.  But
> the idea that matrices are "folded vectors" was, of course not there.

Here is Details section of help page for array

An array in R can have one, two or more dimensions. It is simply a vector 
which is stored with additional attributes giving the dimensions 
(attribute "dim") and optionally names for those dimensions (attribute 
"dimnames"). 

and chapter 2.8 of R - intro
2.8 Other types of objects
Vectors are the most important type of object in R, but there are several 
others which we will
meet more formally in later sections.
 matrices or more generally arrays are multi-dimensional generalizations 
of vectors. In fact,
they are vectors that can be indexed by two or more indices and will be 
printed in special
ways. See Chapter 5 [Arrays and matrices], page 18.

Quite short and usefull chapter.

Regards
Petr



> 
> Worik
> 
> > 
---
> > 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.
> >
> > Worik R  wrote:
> >
> >>Friends
> >>
> >>I clearly donot understand how sapply and vapply work.
> >>
> >>What I have is a function that returns a matrix with an indeterminate
> >>number of rows (some times zero) but a constant number of columns.  I
> >>cannot reliably use an apply function to assemble the matrices into a
> >>matrix.  I am not sure it is possible.
> >>
> >>I can demonstrate the core of my confusion with this simple code.
> >>
> >>A.f <- function(i){
> >>  ret <- matrix("a", i, 7)
> >>  cat(i, class(ret), dim(ret), "\n")
> >>  return(ret)
> >>}
> >>V.f <- function(){
> >>  SS <- vapply(c(1,2),
> >> A.f,
> >> rep('a', 7))
> >>  return(SS)
> >>}
> >>S.f <- function(){
> >>  SS <- sapply(c(1,2),
> >> A.f)
> >>  cat("SS", class(SS), dim(SS), "\n")
> >>  return(SS)
> >>}
> >>
> >>
> >>Calling V.f() fails:
> >>
> >>> V.f()
> >>1 matrix 1 7
> >>2 matrix 2 7
> >>Error in vapply(c(1, 2), A.f, rep("a", 7)) :
> >>  values must be length 7,
> >> but FUN(X[[2]]) result is length 14
> >>>
> >>
> >>
> >>Calling S.f() returns a list.
> >>
> >>
> >>Do I have to accept I am going to be getting a list and I have to
> >>assemble a matrix in a loop?
> >>
> >>cheers
> >>Worik
> >>
> >>__
> >>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.


  1   2   >