Re: [R] substitute, expression and factors

2010-05-18 Thread baptiste auguie
Thank you for the explanation, and the fortune-ish quote,

“As the documentation for substitute() says, there is no guarantee
that the result makes sense.”

Best,

baptiste

On 19 May 2010 02:59, Duncan Murdoch  wrote:
> On 18/05/2010 4:36 PM, baptiste auguie wrote:
>>
>> Dear list,
>>
>> I am puzzled by this,
>>
>> substitute(expression(x), list(x = factor(letters[1:2])))
>> # expression(1:2)
>>
>> Why do I get back the factor levels inside the expression and not the
>> labels?
>
> As the documentation for substitute() says, there is no guarantee that the
> result makes sense.  Yours doesn't, and it confuses the deparser, which is
> not displaying what you really have:
>
>> y <- substitute(expression(x), list(x = factor(letters[1:2])))
>> y
> expression(1:2)
>> str(y)
> language expression(structure(1:2, .Label = c("a", "b"), class = "factor"))
>
> The problem is that expressions don't normally have attributes, and factors
> have both .Label and class attributes.  Put another way:  expressions don't
> normally include factors, they include names and calls and atomic vectors.
>  The deparser doesn't distinguish between the language "1:2" and the atomic
> vector that is the value of that expression, but it doesn't expect
> attributes, and doesn't go looking for them.
>
> Duncan Murdoch
>
>> The following work as I expected,
>>
>> substitute(expression(x), list(x = letters[1:2]))
>> # expression(c("a", "b"))
>>
>> substitute(x, list(x = factor(letters[1:2])))
>> # [1] a b
>> # Levels: a b
>>
>>  bquote(.(factor(letters[1:2])))
>> # [1] a b
>> # Levels: a b
>>
>>
>> All the best,
>>
>> baptiste
>>
>> __
>> 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] avoiding reinstall already installed *package*

2010-05-18 Thread Henrik Bengtsson
On Wed, May 19, 2010 at 7:20 AM, milton ruser  wrote:
> *but* going back to my question, is not true
> that already installed packages will not be
> reinstaled. I ran:
>
> install.packages(c("ggplot2"),dependencies=T)
> install.packages(c("mgcv","bbmle","akima","drc","sensitivity","tgp"),dependencies=T)
>
> and several packages installed during the first install.packages
> were reinstalled on the second install.packages.

I guess your question is, if I do

install.packages("fortunes");
install.packages("fortunes");

will the 'fortunes' package be installed twice?  Answer, yes.

It would probably not be too hard to add a 'force' argument so that:

# Install package first time
install.packages("fortunes");

# If package is already installed, skip it.
install.packages("fortunes", force=FALSE);

# If package is already installed, install it again.
install.packages("fortunes", force=TRUE);

If force=FALSE is the default, then

install.packages("fortunes");
install.packages("fortunes");

would install only once.  I can also imagine force="ask" an more.
Maybe there are better names for the argument, e.g. onExist=c("skip",
"install", "ask").

/Henrik

>
> cheers
>
> milton
>
> On Tue, May 18, 2010 at 5:38 PM, William Dunlap  wrote:
>
>> > -Original Message-
>> > From: r-help-boun...@r-project.org
>> > [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Maechler
>> > Sent: Tuesday, May 18, 2010 1:25 PM
>> > To: milton ruser
>> > Cc: r-help@r-project.org
>> > Subject: Re: [R] avoiding reinstall already installed *package*
>> >
>> > On Tue, May 18, 2010 at 18:06, milton ruser
>> >  wrote:
>> >
>> > > Hi Martin,
>> > >
>> > > thanks for your reply, and very thanks for your kind tips
>> > about "package"
>> > > and "library"
>> > > So, I was trying to understand *why* we load packages using
>> > library().
>> > >
>> >
>> > I've started to use and suggest using   require(.) instead
>> > {as my efforts to introduce  use() or usePackage() *and* deprecating
>> >  library()  where met with strong opposition}
>>
>> I hate to get into arguments over function names, but
>> I would have thought that require("pkg") would throw
>> an error if the required pkg was not available.  It seems
>> like require() can be used when pkg is not really required
>> but library("pkg") is easiest when pkg is required to
>> continue:
>>
>>  > { require("noSuchPackage"); functionFromNoSuchPackage() }
>>  Loading required package: noSuchPackage
>>  Error: could not find function "functionFromNoSuchPackage"
>>  In addition: Warning message:
>>  In library(package, lib.loc = lib.loc, character.only = TRUE,
>> logical.return = TRUE,  :
>>    there is no package called 'noSuchPackage'
>>  > { library("noSuchPackage"); functionFromNoSuchPackage() }
>>  Error in library("noSuchPackage") :
>>    there is no package called 'noSuchPackage'
>>
>> Bill Dunlap
>> Spotfire, TIBCO Software
>> wdunlap tibco.com
>>
>> >
>> >
>> > > I suggest that developers killl the problem on its root,
>> > deleting library
>> > > function :-)
>> > > Good to know already installed packages will not be reinstalled.
>> > >
>> > > cheers
>> > >
>> > > milton
>> > >
>> > > On Tue, May 18, 2010 at 12:49 PM, Martin Maechler <
>> > > maech...@stat.math.ethz.ch> wrote:
>> > >
>> > >> { I've modified the subject; I can't stand it hitting square into
>> > >>  my face ... }
>> > >>
>> > >> > "mr" == milton ruser 
>> > >> >     on Tue, 18 May 2010 12:36:23 -0300 writes:
>> > >>
>> > >>    mr> Dear R-experts,
>> > >>    mr> I am installing new libraries using
>> > >>    mr> install.packages("ggplot2",dependencies=T).
>> > >>    mr> But I perceive that many dependencies are already
>> > installed. As I
>> > >> am using
>> > >>    mr> a low-band internet, how can avoid reinstall
>> > installed libraries?
>> > >>
>> > >> There's no problem with installed libraries, as ...
>> > >> they DO NOT EXIST.
>> > >>
>> > >> These are *PACKAGES* !
>> > >> Why do you think are you talking about the function
>> > >>
>> > >>  install.packages()  
>> > >>         
>> > >>
>> > >> ---
>> > >> To answer the question you did want to ask:
>> > >>
>> > >> Do not be afraid:  Depedencies are only installed when needed,
>> > >> i.e., no package will be downloaded and installed if it already
>> > >> is there.
>> > >>
>> > >> Martin Maechler, ETH Zurich
>> > >>
>> > >>    mr> cheers
>> > >>
>> > >>    mr> milton
>> > >>
>> > >>    mr> [[alternative HTML version deleted]]
>> > >>        
>> > >> (another thing you should learn to avoid, please)
>> > >>
>> > >>
>> > >
>> >
>> >       [[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 

Re: [R] avoiding reinstall already installed *package*

2010-05-18 Thread milton ruser
*but* going back to my question, is not true
that already installed packages will not be
reinstaled. I ran:

install.packages(c("ggplot2"),dependencies=T)
install.packages(c("mgcv","bbmle","akima","drc","sensitivity","tgp"),dependencies=T)

and several packages installed during the first install.packages
were reinstalled on the second install.packages.

cheers

milton

On Tue, May 18, 2010 at 5:38 PM, William Dunlap  wrote:

> > -Original Message-
> > From: r-help-boun...@r-project.org
> > [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Maechler
> > Sent: Tuesday, May 18, 2010 1:25 PM
> > To: milton ruser
> > Cc: r-help@r-project.org
> > Subject: Re: [R] avoiding reinstall already installed *package*
> >
> > On Tue, May 18, 2010 at 18:06, milton ruser
> >  wrote:
> >
> > > Hi Martin,
> > >
> > > thanks for your reply, and very thanks for your kind tips
> > about "package"
> > > and "library"
> > > So, I was trying to understand *why* we load packages using
> > library().
> > >
> >
> > I've started to use and suggest using   require(.) instead
> > {as my efforts to introduce  use() or usePackage() *and* deprecating
> >  library()  where met with strong opposition}
>
> I hate to get into arguments over function names, but
> I would have thought that require("pkg") would throw
> an error if the required pkg was not available.  It seems
> like require() can be used when pkg is not really required
> but library("pkg") is easiest when pkg is required to
> continue:
>
>  > { require("noSuchPackage"); functionFromNoSuchPackage() }
>  Loading required package: noSuchPackage
>  Error: could not find function "functionFromNoSuchPackage"
>  In addition: Warning message:
>  In library(package, lib.loc = lib.loc, character.only = TRUE,
> logical.return = TRUE,  :
>there is no package called 'noSuchPackage'
>  > { library("noSuchPackage"); functionFromNoSuchPackage() }
>  Error in library("noSuchPackage") :
>there is no package called 'noSuchPackage'
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
> >
> >
> > > I suggest that developers killl the problem on its root,
> > deleting library
> > > function :-)
> > > Good to know already installed packages will not be reinstalled.
> > >
> > > cheers
> > >
> > > milton
> > >
> > > On Tue, May 18, 2010 at 12:49 PM, Martin Maechler <
> > > maech...@stat.math.ethz.ch> wrote:
> > >
> > >> { I've modified the subject; I can't stand it hitting square into
> > >>  my face ... }
> > >>
> > >> > "mr" == milton ruser 
> > >> > on Tue, 18 May 2010 12:36:23 -0300 writes:
> > >>
> > >>mr> Dear R-experts,
> > >>mr> I am installing new libraries using
> > >>mr> install.packages("ggplot2",dependencies=T).
> > >>mr> But I perceive that many dependencies are already
> > installed. As I
> > >> am using
> > >>mr> a low-band internet, how can avoid reinstall
> > installed libraries?
> > >>
> > >> There's no problem with installed libraries, as ...
> > >> they DO NOT EXIST.
> > >>
> > >> These are *PACKAGES* !
> > >> Why do you think are you talking about the function
> > >>
> > >>  install.packages()  
> > >> 
> > >>
> > >> ---
> > >> To answer the question you did want to ask:
> > >>
> > >> Do not be afraid:  Depedencies are only installed when needed,
> > >> i.e., no package will be downloaded and installed if it already
> > >> is there.
> > >>
> > >> Martin Maechler, ETH Zurich
> > >>
> > >>mr> cheers
> > >>
> > >>mr> milton
> > >>
> > >>mr> [[alternative HTML version deleted]]
> > >>
> > >> (another thing you should learn to avoid, please)
> > >>
> > >>
> > >
> >
> >   [[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.


Re: [R] scaling with relative units in plots or retrieving axes limits in plots

2010-05-18 Thread Greg Snow
Look at the grconvertX and grconvertY functions for a built in solution with 
much more flexibility.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Jannis
> Sent: Tuesday, May 18, 2010 8:50 AM
> To: r-h...@stat.math.ethz.ch
> Subject: Re: [R] scaling with relative units in plots or retrieving
> axes limits in plots
> 
> Thanks for the replies! If anybody  encounters a similar problem, the
> function that now does what I wanted is attached below.
> 
> 
> Best
> Jannis
> 
> 
> 
> trnsf.coords = function(array_x,array_y)
> 
> # This function transfers relative coordinates between 0 and 1 for two
> arrays with x
> # and y values into the coordinate system of the current plot.
> 
> {
> plot_extremes=par()$usr
> x_min=plot_extremes[1]
> x_max=plot_extremes[2]
> y_min=plot_extremes[3]
> y_max=plot_extremes[4]
> 
> x_trans=x_min+(array_x*x_max-x_min)
> y_trans=y_min+(array_y*y_max-y_min)
> output=list(x=x_trans,y=y_trans)
> return(output)
> 
> }
> 
> --- Jannis  schrieb am Di, 18.5.2010:
> 
> > Von: Jannis 
> > Betreff: [R] scaling with relative units in plots or retrieving axes
> limits in plots
> > An: r-h...@stat.math.ethz.ch
> > Datum: Dienstag, 18. Mai, 2010 14:23 Uhr
> > Dears,
> >
> >
> > a way to define x and y positions in plots in relative
> > numbers (e.g in fractions  between 0 and 1 referring to
> > relative positions inside the plot region) would really help
> > me. One example I would need this to would be to add text
> > via text() to a plot always at a defined spot, e.g the upper
> > left corner. Until now I always determined maximum x and y
> > values and used those, but defining relative positions
> > straight away would be much easier. Possible solutions:
> >
> > 1. Predefined function
> > Is there anything available that lets me run (for
> > example):
> >
> > text(0.5,0.5,'middle')
> >
> > which always puts text on these relative points?
> >
> >
> >
> > 2. Create my own function
> > It would be straightforward to create my own function that
> > translates the relative number to the axes values in the
> > actual plot, so that
> >
> > text(my.function(0.5,0.5),'middle')
> >
> > would do what I want. For this I would need to be able to
> > somehow retrieve the axis limits for x and y axes. Is there
> > any way I could do this after having called plot()?
> >
> >
> >
> > Thanks for your help!
> >
> >
> > Jannis
> >
> >
> >
> >
> > __
> > 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] Text positioning in pixel coordinates?

2010-05-18 Thread Greg Snow
?grconvertX 

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Oliver
> Sent: Monday, May 17, 2010 8:24 AM
> To: r-h...@stat.math.ethz.ch
> Subject: [R] Text positioning in pixel coordinates?
> 
> Hello,
> 
> 
> the positioning of text elements in a graphics is nortmally
> done via x/y coordin ates of the displayed data.
> 
> most of the time this is very helpful (and missing in other
> programs).
> 
> But when I want to set some text into a graphics always at the same
> position,
> this will not be easy...
> 
> I might use range() for locating the edges and then go down some
> percent of the
> range or so...
> 
> ...but maybe there is a better alternative to this approach?
> 
> 
> 
>   Oliver
> 
> __
> 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] GUI commands to call for a protein from protein data bank

2010-05-18 Thread Amitoj S. Chopra

Thank you it worked perfectly. I just needed to close the window that was
the problem. Do you know how to close the window automatically and why does
that matter? Thanks!


Amitoj

On Tue, May 18, 2010 at 12:10 PM, Amitoj Chopra  wrote:

> I tried doing that and this is what I go:
>
>
> dlg <- aDialog(items=list(
> ProtienCode=stringItem("")
>
> ),
> OK_handler=function(.) { # . is reference to dlg object
> values <- .$to_R()
> f <- function(ProtienCode)
>
> pdb <- read.pdb(.$get_ProteinCode())
> #cat("ProteinCode is",ProtienCode,"\n")
>
> do.call(f, values)
> }
> )
> dlg$make_gui()
>
>
> with this error message
>
> Error in function (ProtienCode)  : could not find function "read.pdb"
>
> Do you know how to get rid of this error?
>
>
> On Tue, May 18, 2010 at 5:53 AM, jverzaniNWBKZ [via R] <
> ml-node+2221226-858152228-140...@n4.nabble.com
> > wrote:
>
>> Amitoj S. Chopra  gmail.com> writes:
>>
>> >
>> >
>> > What I am trying to do is use GUI function, traitr, and to call for a
>> pdb
>> > file and save it and then display it. I want to call for it by taking it
>>
>> > from the user and then displaying it on the screen. I am having problems
>>
>> > with that. The line pdb <- read.pdb(""ProteinCode) where proteincode
>> should
>> > be the name of the protein, for example 1ly2, but it always ends up
>> being
>> > protein. My question is how to you make the input for read.pdb actually
>> be
>> > the input by the user and not protein code. I want to be able to type
>> 1ly2,
>> > and for the program to actually display the contents of 1ly2. Thanks!
>> >
>>
>> I'm just guessing, but you might try this for your OK_handler:
>>
>> OK_handler=function(.) {
>>   pdb <- read.pdb(.$get_ProteinCode())
>> }
>>
>> (Or use yours, but drop the quotes around "ProteinCode".)
>>
>> That doesn't modify pdb outside the scope of the handler, so likely you
>> need to
>> do something else with it.
>>
>> --John
>>
>>
>> > Code:
>> >
>> > dlg <- aDialog(items=list(
>> > ProteinCode=stringItem("")
>> > ),
>> > OK_handler=function(.) { # . is reference to dlg object
>> > values <- .$to_R()
>> > f <- function(ProteinCode)
>> > pdb <- read.pdb("ProteinCode")
>> > do.call(f, values)
>> > }
>> > )
>> > dlg$make_gui()
>>
>> __
>> [hidden email] 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.
>>
>>
>> --
>>  View message @
>> http://r.789695.n4.nabble.com/GUI-commands-to-call-for-a-protein-from-protein-data-bank-tp2220754p2221226.html
>> To unsubscribe from GUI commands to call for a protein from protein data
>> bank, click here< (link removed) >.
>>
>>
>>
>

-- 
View this message in context: 
http://r.789695.n4.nabble.com/GUI-commands-to-call-for-a-protein-from-protein-data-bank-tp2220754p088.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] issues with R Library on a Server

2010-05-18 Thread Daisy Englert Duursma
Hello,

Thanks for your help so far, I am still having the same problem but I
think I am getting closer. Just to recap, since setting up R on my
server, so that everyone shares a common Library, I have had issues
getting packages to load. Here is an example with the package
survival. I have the survival package in my library but

>library(survival)
Error in library.dynam(lib, package, package.lib) :
  shared library 'survival' not found
Error: package/namespace load failed for 'survival'

>utils:::menuInstallPkgs()
# downloaded survival
The downloaded packages are in
C:\Users\Daisy
Englert\AppData\Local\Temp\2\RtmpObE4EY\downloaded_packages

# load the package again
library(survival)
Error in get(Info[i, 1], envir = env) :
  cannot allocate memory block of size 3.0 Gb
Error: package/namespace load failed for 'survival'


This is were it gets weird. If I restart R and load survival it works
perfectly.  I do not get it.
There is one funny thing though and it has to do with forwards and back slashes.

> .libPaths()[1]
[1] "C:\\RLIBRARY"

#TWO BACK SLASHES

> packageDescription("survival")
Title: Survival analysis, including penalised likelihood.
#

-- File: C:\RLIBRARY/survival/Meta/package.rds

#ONE BACK SLASH AND THE REST ARE FORWARD SLASHES

In the environmental variable on the server I set R_LIBS to C:\RLIBRARY.
Is that correct?

Any ideas on what the problem may be and why it fixes itself if I restart R?


Thanks,
Daisy

__
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] Query on linear mixed model

2010-05-18 Thread Vijayan Padmanabhan

Thanks Ista..
I will take your suggestion.
Regards
Vijayan Padmanabhan


"What is expressed without proof can be denied
without proof" - Euclide.



  
 Ista 
 Zahn 
   n>   
 Sent  cc 
 by: r-help@r-project.org 
 istazah  Subject 
 n...@gmail Re: [R] Query on 
 .comlinear mixed model   
  
  
 05/18/2  
 010  
 06:39
 PM   
  




Hi Vijayan,
You are really asking for this list to serve as
your statistical
consultant, which is not its purpose. If you have
a specific problem
(and if you know how to ask for help -- see the
posting guide) this
list is a tremendous resource. But it is not a
replacement for a
statistician.

Best,
Ista

On Tue, May 18, 2010 at 7:52 AM, Vijayan
Padmanabhan
 wrote:
>
>
> Hi R Forum
> I am a newbie to R and I have been amazed by
what
> I can get my team to accomplish just by
> implementing Scripting routines of R in all my
> team's areas of interest..
> Recently i have been trying to adopt R scripting
> routine for some analysis with longitudanal
data..
> I am presenting my R script below that I have
> tried to make to automate data analysis for
> longitudanal data by employing functions from
> library(nlme) and library(multcomp)..
>
> I would be thankful for receiving inputs on this
> script and let me know if I have modeled the lme
> formula correctly.. If the formula i have used
is
> not the correct one i would appreciate receiving
> inputs on what is the correct formula for lme
that
> I should use given the context of this example
> study shown in the data..
>
> Just to give an introduction.. the data is about
> studying efficacy of 3 products for their impact
> in skin brightness over 3 time points of
> investigation .. The design is such that all the
> products are tried on patches made on each arm
> (left and right) for each volunteer and chromaL
is
> measured as the response over 3 time points
> Baseline (referred as T0), T1 and T2..
>
>
> The answers i am looking to get from the
analysis
> routine is as follows:
>
> Overall across different time points studied
which
> products is superior?
> For Each Product is their a significant
difference
> in the response variable across different time
> points of investigation?
> For Each Time Point is their a significant
> difference between the different products for
the
> measured response?
> Regards
> Vijayan Padmanabhan
> Research Scientist, ITC R&D, Phase I, Peenya,
> Bangalore - 58
>
> The Full R script is given below:
>
> MyData <- data.frame(Subj = factor(rep(c("S1",
> "S2", "S3"), 18)),
> Product = factor(rep(letters[1:3],each=3,54)),
> Arm = factor(rep(c("L","R"),each=9,54)),
> Attribute =
factor(rep(c("ChromaL"),each=54,54)),
> Time =
factor(rep(c("T0","T1","T2"),each=18,54)),
> value=as.numeric(c(43.52,
>
44.22,43.2,40.12,39.45,38.98,43.23,42.34,44.54,50.23,45.12,43.56,43.23,44.56,42.34,45.67,

>
43.23,44.54,43.52,44.22,43.2,40.12,39.45,38.98,43.23,42.34,44.54,50.23,45.12,43.56,

>  43.23, 44.56, 42.34, 45.67, 43.23,
> 44.54, 45.5, 46.45, 47.56, 46.98, 46.3, 43.1,
> 45.6, 44.2, 40.1, 49.8, 48, 46, 47.98, 46.9,
> 43.78, 47.35, 44.9, 48)))
> tapply(MyData$value,
> list(Attribute=MyData$Attribute,
>  Product=MyData$Product), mean, na.rm=TRUE)
>
>
> Time = factor(MyData$Time)
> Product = factor(MyData$Product)
> Subj = factor(MyData$Subj)
> Attribute=factor(MyData$Attribute)
> Arm=factor(MyData$Arm)
> ##library(reshape)
> ##data<-melt(data, id=c("Product",
> "Subject","Attribute"))
> ##data$Product<-as.character(Data$Product)
> library(nlme)
> library(multcomp)
>
>
> ##For ALL Product Comparison across All Time
> Points.
>
options(contrasts=c('contr.treatment','contr.poly'))

> data<-subset(MyData,Attribute=="ChromaL")
> tapply(data$value, list(Product=data$Product),
> mean,
>  na.rm=TRUE)
> model <- lme(value ~
>
Product+Time+Arm+Product*Arm+Product*Time+Product*Arm*Time,

>  random = ~1 | Subj,data =data)
> summary(model)
> x<-anova(model)
> x
> library(multcomp)
>
su<-summary(glht(model,linfct=mcp(Product="Tukey")))

> ##length(su)
> ##su[1:(length(su)-4)]
> x11()
>
plot(summary(glht(model,linfct=mcp(Product="Tukey"))),cex.axis=0.6)

>
>
> ##For Each Product Comparison across All Time
> Points.
> data<-MyData
> data<-subset(data,Product=="a")
> tapply(data$value, list(Time=data$Time), mean,
>  na.rm=TRUE)
> model <- lme(value ~ Time+Arm+Time*Arm, random =
> ~1 | Subj,data =data)
> summary(model)
> x<-

Re: [R] Query on linear mixed model

2010-05-18 Thread Vijayan Padmanabhan

Thanks Joshua..
It really helped in polishing my coding essentials
in R.
Thanks & Regards
Vijayan Padmanabhan


"What is expressed without proof can be denied
without proof" - Euclide.



  
 Joshua   
 Wiley
  n>   
   cc 
 05/18/2 r-help@r-project.org 
 010  Subject 
 07:18   Re: [R] Query on 
 PM  linear mixed model   
  
  
  
  
  
  




On Tue, May 18, 2010 at 4:52 AM, Vijayan
Padmanabhan
 wrote:


This does not answer your statistical question,
but I did include some
ideas to simplify your script.

> ##For ALL Product Comparison across All Time
> Points.
>
options(contrasts=c('contr.treatment','contr.poly'))

> data<-subset(MyData,Attribute=="ChromaL")
> tapply(data$value, list(Product=data$Product),
> mean,
>  na.rm=TRUE)
> model <- lme(value ~
>
Product+Time+Arm+Product*Arm+Product*Time+Product*Arm*Time,

>  random = ~1 | Subj,data =data)
> summary(model)

using '*' automatically crosses all the variables.
A more parsimonius form is:
lme(value ~ Product*Arm*Time, random = ~1 |
Subj,data =data)

there is only a slight reordering of effects, but
all estimates are the same.

> x<-anova(model)
> x
> library(multcomp)
>
su<-summary(glht(model,linfct=mcp(Product="Tukey")))

> ##length(su)
> ##su[1:(length(su)-4)]
> x11()
>
plot(summary(glht(model,linfct=mcp(Product="Tukey"))),cex.axis=0.6)

>
>
> ##For Each Product Comparison across All Time
> Points.
> data<-MyData
> data<-subset(data,Product=="a")
> tapply(data$value, list(Time=data$Time), mean,
>  na.rm=TRUE)
> model <- lme(value ~ Time+Arm+Time*Arm, random =
> ~1 | Subj,data =data)

again, simplified:

lme(value ~ Time*Arm, random = ~1 | Subj,data
=data)

(no reordering even this time)

> summary(model)
> x<-anova(model)
> x
> library(multcomp)
> summary(glht(model,linfct=mcp(Time="Tukey")))
> x11()
>
plot(summary(glht(model,linfct=mcp(Time="Tukey"))),cex.axis=0.6)

>
> data<-MyData
> data<-subset(data,Product=="b")
> tapply(data$value, list(Time=data$Time), mean,
>  na.rm=TRUE)
> model <- lme(value ~ Time+Arm+Time*Arm, random =
> ~1 | Subj,data =data)

lme(value ~ Time*Arm, random = ~1 | Subj,data
=data)

> summary(model)
> x<-anova(model)
> x
> library(multcomp)
> summary(glht(model,linfct=mcp(Time="Tukey")))
> x11()
>
plot(summary(glht(model,linfct=mcp(Time="Tukey"))),cex.axis=0.6)

>
> data<-MyData
> data<-subset(data,Product=="c")
> tapply(data$value, list(Time=data$Time), mean,
>  na.rm=TRUE)
> model <- lme(value ~ Time+Arm+Time*Arm, random =
> ~1 | Subj,data =data)

lme(value ~ Time*Arm, random = ~1 | Subj,data
=data)

> summary(model)
> x<-anova(model)
> x
> library(multcomp)
> summary(glht(model,linfct=mcp(Time="Tukey")))
> x11()
>
plot(summary(glht(model,linfct=mcp(Time="Tukey"))),cex.axis=0.6)

>
>
> ##For All Product Comparison at Each Time
Points.
> data<-MyData
> data<-subset(data, Time=="T0")
> tapply(data$value, list(Product=data$Product),
> mean,
>  na.rm=TRUE)
>
> model <- lme(value ~ Product+Arm+Product:Arm,
> random = ~1 | Subj,data =data)

here you used ':' so it is not redundant, but it
can still be simplified to:

lme(value ~ Product*Arm, random = ~1 | Subj,data
=data)

> summary(model)
> x<-anova(model)
> x
> library(multcomp)
> summary(glht(model,linfct=mcp(Product="Tukey")))
> x11()
>
plot(summary(glht(model,linfct=mcp(Product="Tukey"))),cex.axis=0.6)

>
>
> data<-MyData
> data<-subset(data, Time=="T1")
> tapply(data$value, list(Product=data$Product),
> mean,
>  na.rm=TRUE)
>
> model <- lme(value ~ Product+Arm+Product:Arm,
> random = ~1 | Subj,data =data)

lme(value ~ Product*Arm, random = ~1 | Subj,data
=data)

> summary(model)
> x<-anova(model)
> x
> library(multcomp)
> summary(glht(model,linfct=mcp(Product="Tukey")))
> x11()
>
plot(summary(glht(model,linfct=mcp(Product="Tukey"))),cex.axis=0.6)

>
>
> data<-MyData
> data<-subset(data, Time=="T2")
> tapply(data$value, list(Product=data$Product),
> mean,
>  na.rm=TRUE)
>
> model <- lme(value ~ Product+Arm+Product:Arm,
> random = ~1 | Subj,data =data)

lme(value ~ Product*Arm, random = ~1 | Subj,data
=data)

> summary(model)
> x<-anova(model)
> x
> library(multcomp)
> summary(glht(model,linfct=mcp(Product="Tukey")))
> x11()
>
plot(summary(glht(model,linfct=mcp(Product="Tukey"))),cex.axis=0.6)


Unless only parts of this script are being run in
a given session, I
cannot think of a good reason to keep calling
"library(multcomp)".  I
also notice that your script repeats the same

Re: [R] Box-Cox Transformation: Drastic differences when varying added constants

2010-05-18 Thread Frank E Harrell Jr

On 05/18/2010 10:41 PM, Greg Snow wrote:

Have you read the BoxCox paper?  It has the theory in there for dealing with an 
offset parameter (though I don't know of any existing functions that help in 
estimating both lambdas at the same time).  Though another important point (in 
the paper as well) is that the lambda values used should be based on sound 
science, not just what fits best.



Sensitivity of log-like and exponential transformations to the choice of 
origin is a significant limitation in my view.  If there is no subject 
matter theory to back up a particular origin, then either the origin 
should be a parameter to be estimated or you should consider a 
nonparametric transformation of Y.  avas is one such approach, based on 
variance stabilization.  The areg.boot function in the Hmisc package 
gives you confidence bands for various quantities using avas and ace 
transform-both-sides nonparametric regression approaches.


Frank

--
Frank E Harrell Jr   Professor and ChairmanSchool of Medicine
 Department of Biostatistics   Vanderbilt 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.


Re: [R] Box-Cox Transformation: Drastic differences when varying added constants

2010-05-18 Thread Greg Snow
Have you read the BoxCox paper?  It has the theory in there for dealing with an 
offset parameter (though I don't know of any existing functions that help in 
estimating both lambdas at the same time).  Though another important point (in 
the paper as well) is that the lambda values used should be based on sound 
science, not just what fits best. 

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Holger Steinmetz
> Sent: Sunday, May 16, 2010 6:22 AM
> To: r-help@r-project.org
> Subject: [R] Box-Cox Transformation: Drastic differences when varying
> added constants
> 
> 
> Dear experts,
> 
> I tried to learn about Box-Cox-transformation but found the following
> thing:
> 
> When I had to add a constant to make all values of the original
> variable
> positive, I found that
> the lambda estimates (box.cox.powers-function) differed dramatically
> depending on the specific constant chosen.
> 
> In addition, the correlation between the transformed variable and the
> original were not 1 (as I think it should be to use the transformed
> variable
> meaningfully) but much lower.
> 
> With higher added values (and a right skewed variable) the lambda
> estimate
> was even negative and the correlation between the transformed variable
> and
> the original varible was -.91!!?
> 
> I guess that is something fundmental missing in my current thinking
> about
> box-cox...
> 
> Best,
> Holger
> 
> 
> P.S. Here is what i did:
> 
> # Creating of a skewed variable X (mixture of two normals)
> x1 = rnorm(120,0,.5)
> x2 = rnorm(40,2.5,2)
> X = c(x1,x2)
> 
> # Adding a small constant
> Xnew1 = X +abs(min(X))+ .1
> box.cox.powers(Xnew1)
> Xtrans1 = Xnew1^.2682 #(the value of the lambda estimate)
> 
> # Adding a larger constant
> Xnew2 = X +abs(min(X)) + 1
> box.cox.powers(Xnew2)
> Xtrans2 = Xnew2^-.2543 #(the value of the lambda estimate)
> 
> #Plotting it all
> par(mfrow=c(3,2))
> hist(X)
> qqnorm(X)
> qqline(X,lty=2)
> hist(Xtrans1)
> qqnorm(Xtrans1)
> qqline(Xtrans1,lty=2)
> hist(Xtrans2)
> qqnorm(Xtrans2)
> qqline(Xtrans2,lty=2)
> 
> #correlation among original and transformed variables
> round(cor(cbind(X,Xtrans1,Xtrans2)),2)
> --
> View this message in context: http://r.789695.n4.nabble.com/Box-Cox-
> Transformation-Drastic-differences-when-varying-added-constants-
> tp2218490p2218490.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] p value

2010-05-18 Thread Greg Snow
An option similar to Bert's but looking more like a standard hypothesis test 
output is to use the function:
SnowsCorrectlySizedButOtherwiseUselessTestOfAnything from the TeachingDemos 
package.

If you want a more useful result then you will need to be less general and more 
specific.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Bert Gunter
> Sent: Sunday, May 16, 2010 9:26 AM
> To: 'Soham'; r-help@r-project.org
> Subject: Re: [R] p value
> 
> runif(1)
> 
> 
> Bert Gunter
> Genentech Nonclinical Statistics
> 
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On
> Behalf Of Soham
> Sent: Saturday, May 15, 2010 9:05 AM
> To: r-help@r-project.org
> Subject: [R] p value
> 
> 
> How to compute the p-value of a statistic generally?
> --
> View this message in context:
> http://r.789695.n4.nabble.com/p-value-tp2217867p2217867.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-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] abline limit constrain x-range how?

2010-05-18 Thread Greg Snow
The clip function will limit the area that other functions (including abline) 
plot to, so that is one option.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Giovanni Azua
> Sent: Saturday, May 15, 2010 8:03 AM
> To: r-help@r-project.org
> Subject: [R] abline limit constrain x-range how?
> 
> Hello,
> 
> I managed to "linearize" my LDA decision boundaries now I would like to
> call abline three times but be able to specify the exact x range. I was
> reading the doc but it doesn't seem to support this use-case? are there
> alternatives. The reason why I use abline is because I first call plot
> to plot all the three datasets and then call abline to "append" these
> decision boundary lines to the existing plot ...
> 
> Can anyone please advice?
> Thanks in advance,
> Best regards,
> Giovanni
> __
> 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] Maximization of quadratic forms

2010-05-18 Thread Ravi Varadhan
Hi Taki,

This should be doable with "gnls" by properly specifying the `weights' 
argument, although I cannot figure out how to do it without spending much time 
(someone like Doug Bates would know for sure).

But let me ask you:  did you try the straightforward nonlinear optimization 
(e.g. optim)?  Did you run into any convergence problems?  Did it take way too 
much time?   

If \mu(\beta) is not a nasty function, you should be able to provide analytic 
gradient for your objective function.  This would make nonlinear optimization 
quite efficient.  

Ravi.



Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu


- Original Message -
From: Russell Shinohara 
Date: Tuesday, May 18, 2010 2:38 pm
Subject: [R] Maximization of quadratic forms
To: r-help@r-project.org


> Dear R Help,
>  
>  I am trying to fit a nonlinear model for a mean function 
> $\mu(Data_i,\beta)$ for a fixed covariance matrix where $\beta$ and 
> $\mu$ are low-dimensional. More specifically, for fixed 
> variance-covariance matrices $\Sigma_{z=0}$ and $\Sigma_{z=1}$ 
> (according to a binary covariate $Z$), I am trying to minimize:
>  
>  $\sum_{i=1^n} (Y_i-\mu_(Data_i,\beta))' \Sigma_{z=z_i}^{-1} 
> (Y_i-\mu_(Data_i,\beta))$
>  
>  in terms of the parameter $\beta$. Is there a way to do this in R in 
> a more stable and efficient fashion than just using a general 
> optimization function such as optim? I have tried to use gnls, but I 
> was unsuccessful in specifying different values of the covariance 
> matrix according to the covariate $Z$.
>  
>  Thank you very much for your help,
>  Taki Shinohara
>  
>  
>  
>  
>  
>  Russell Shinohara, MSc
>  PhD Candidate and NIH Fellow
>  Department of Biostatistics
>  Bloomberg School of Public Health
>  The Johns Hopkins University
>  615 N. Wolfe St., Suite E3033
>  Baltimore, MD 21205
>  tel: (203) 499-8480
>  
>  
>  __
>  R-help@r-project.org mailing list
>  
>  PLEASE do read the posting guide 
>  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] automate curve drawing on nls() object

2010-05-18 Thread Shi, Tao
In this case, Ben's approach is the way to go.  

I'm curious how you fit nls without knowing the model formula beforehand?

...Tao





- Original Message 
> From: array chip 
> To: r-help@r-project.org; TaoShi 
> Sent: Tue, May 18, 2010 5:22:47 PM
> Subject: Re: [R] automate curve drawing on nls() object
> 
> well, this is not going automate enough because you have to know how the 
> model 
> (formula) looks like, and how many parameters there are in the model 
> beforehand 
> to do what you are suggesting.

Thanks


--- On Tue, 5/18/10, 
> Shi, Tao <
> href="mailto:shida...@yahoo.com";>shida...@yahoo.com> wrote:

> 
> From: Shi, Tao <
> href="mailto:shida...@yahoo.com";>shida...@yahoo.com>
> Subject: Re: 
> [R] automate curve drawing on nls() object
> To: "array chip" <
> ymailto="mailto:arrayprof...@yahoo.com"; 
> href="mailto:arrayprof...@yahoo.com";>arrayprof...@yahoo.com>, 
> ymailto="mailto:r-help@r-project.org"; 
> href="mailto:r-help@r-project.org";>r-help@r-project.org
> Date: 
> Tuesday, May 18, 2010, 7:42 PM
> I can't directly answer your 
> question
> regarding 'expression', but can you just replace b, c,d, 
> and
> e with coef(obj)[1], coef(obj)[2], ...
> etc.   You still can 
> automate the whole
> process this way, right?
> 
> 
> 
> 
> 
> 
> - Original Message 
> > From: array 
> chip <
> href="mailto:arrayprof...@yahoo.com";>arrayprof...@yahoo.com>
> > 
> To: 
> href="mailto:r-help@r-project.org";>r-help@r-project.org
> > Sent: 
> Tue, May 18, 2010 4:13:33 PM
> > Subject: [R] automate curve drawing on 
> nls() object
> > 
> > Hi, I would like to use the curve() 
> function to draw
> the predicted curve from an 
> > nls() object. 
> for 
> > example:
> 
> 
> dd<-read.table("dd.txt",sep='\t',header=T,row.names=1)
> 
> obj<-nls(y~c+(d-c)/(1+(x/e)^b),data=dd,start=list(b=-1,
> 
> > 
> c=0, d=100, e=150))
> coef(obj)
>   b  
> >
>   c   
>d
> >e 
> 
> -1.1416422   0.6987028 102.8613176 
> > 135.9373131
> 
> curve(0.699+(102.86-0.699)/(1+(x/135.94)^(-1.1416)),1,2)
> 
> 
> Now 
> > I am going to have a lot of datasets to do this, so
> 
> certainly I would like to 
> > automate this. Suppose that I can create 
> a character
> string for the formula, but 
> > I am not sure how 
> to pass that character string into
> the curve() to make it 
> > 
> work. The help page of curve() says the first argument
> is "an expression 
> written 
> > as a function of x, or alternatively the name of a
> 
> function which will be 
> > plotted". I tried the following, for 
> example:
> 
> substitute(expression(c + 
> > (d - c)/(1 + 
> (x/e)^b)),as.list(coef(obj)))
> will 
> > return:
> 
> "expression(0.698704171233635 + (102.861317499063 - 
> > 
> 0.698704171233635)/(1 +
> 
> (x/135.937317917920)^-1.14164217993857))"
> 
> so I 
> > 
> tried:
> curve(substitute(expression(c + (d - c)/(1 + (x/e)^b)), 
> 
> > as.list(coef(obj))), 1,2)
> 
> but it returns an 
> error:
> "Error in 
> > xy.coords(x, y, xlabel, ylabel, log) : 
> 
>   'x' and 'y' lengths 
> > differ"
> 
> Any 
> suggestions?
> 
> 
> A related question:
> 
> If I 
> do 
> > this:
> substitute(expression(c + (d - c)/(1 + 
> 
> > (x/e)^b)),as.list(coef(obj)))
> 
> I will get: 
> > 
> 
> "expression(0.698704171233635 + (102.861317499063 -
> 
> 0.698704171233635)/(1 + 
> > 
> (x/135.937317917920)^-1.14164217993857))"
> 
> But if I 
> 
> > do:
> 
> substitute(parse(text=as.character(obj$call$formula[3]),srcfile=NULL),as.list(coef(obj)))
> 
> 
> I 
> > only get:
> "parse(text = 
> as.character(obj$call$formula[3]), srcfile =
> NULL)" 
> > as a 
> result, not have b,c,d,e replaced by coefficient
> 
> > 
> values.
> 
> where
> 
> > 
> 
> parse(text=as.character(obj$call$formula[3]),srcfile=NULL)
> returns the 
> 
> > wanted expression:
> "expression(c + (d - c)/(1 + 
> (x/e)^b))"
> 
> Why is 
> > that?
> 
> 
> Thanks
> 
> John
> 
> 
> __
> 
> > 
> ymailto="mailto:
> href="mailto:R-help@r-project.org";>R-help@r-project.org"
> 
> 
> > href="mailto:
> href="mailto:R-help@r-project.org";>R-help@r-project.org">
> ymailto="mailto:R-help@r-project.org"; 
> href="mailto:R-help@r-project.org";>R-help@r-project.org
> mailing 
> list
> 
> > href="
> href="https://stat.ethz.ch/mailman/listinfo/r-help"; target=_blank 
> >https://stat.ethz.ch/mailman/listinfo/r-help";
> target=_blank 
> 
> > >
> target=_blank >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] substitute, expression and factors

2010-05-18 Thread Duncan Murdoch

On 18/05/2010 4:36 PM, baptiste auguie wrote:

Dear list,

I am puzzled by this,

substitute(expression(x), list(x = factor(letters[1:2])))
# expression(1:2)

Why do I get back the factor levels inside the expression and not the
labels? 


As the documentation for substitute() says, there is no guarantee that 
the result makes sense.  Yours doesn't, and it confuses the deparser, 
which is not displaying what you really have:


> y <- substitute(expression(x), list(x = factor(letters[1:2])))
> y
expression(1:2)
> str(y)
language expression(structure(1:2, .Label = c("a", "b"), class = "factor"))

The problem is that expressions don't normally have attributes, and 
factors have both .Label and class attributes.  Put another way:  
expressions don't normally include factors, they include names and calls 
and atomic vectors.  The deparser doesn't distinguish between the 
language "1:2" and the atomic vector that is the value of that 
expression, but it doesn't expect attributes, and doesn't go looking for 
them.


Duncan Murdoch


The following work as I expected,

substitute(expression(x), list(x = letters[1:2]))
# expression(c("a", "b"))

substitute(x, list(x = factor(letters[1:2])))
# [1] a b
# Levels: a b

 bquote(.(factor(letters[1:2])))
# [1] a b
# Levels: a b


All the best,

baptiste

__
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] automate curve drawing on nls() object

2010-05-18 Thread array chip
Sorry that I forgot to attach the data file. 

Indeed, this is a much simpler way to do this.

Thanks


--- On Tue, 5/18/10, Ben Bolker  wrote:

> From: Ben Bolker 
> Subject: Re: [R] automate curve drawing on nls() object
> To: r-h...@stat.math.ethz.ch
> Date: Tuesday, May 18, 2010, 7:33 PM
> array chip   yahoo.com> writes:
> 
> > Hi, I would like to use the curve() function to draw
> the 
> > predicted curve from an nls() object. for example:
> > 
> 
>   Is there a reason you don't want to use plot() and
> predict() ???
>   
> >
> dd<-read.table("dd.txt",sep='\t',header=T,row.names=1)
> 
>   note that this is not a reproducible example ...
> 
> >
> obj<-nls(y~c+(d-c)/(1+(x/e)^b),data=dd,start=list(b=-1,
> c=0, d=100, e=150))
> > coef(obj)
> >           b 
>          c     
>      d       
>    e 
> >  -1.1416422   0.6987028
> 102.8613176 135.9373131
> >
> curve(0.699+(102.86-0.699)/(1+(x/135.94)^(-1.1416)),1,2)
> > 
> 
>   predframe <-
> data.frame(x=seq(1,2,length.out=101))
>   predframe <-
> cbind(predframe,y=predict(obj,newdata=predframe))
>   with(predframe,plot(y~x,type="l"))
> 
> __
> 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] automate curve drawing on nls() object

2010-05-18 Thread array chip
well, this is not going automate enough because you have to know how the model 
(formula) looks like, and how many parameters there are in the model beforehand 
to do what you are suggesting.

Thanks


--- On Tue, 5/18/10, Shi, Tao  wrote:

> From: Shi, Tao 
> Subject: Re: [R] automate curve drawing on nls() object
> To: "array chip" , r-help@r-project.org
> Date: Tuesday, May 18, 2010, 7:42 PM
> I can't directly answer your question
> regarding 'expression', but can you just replace b, c,d, and
> e with coef(obj)[1], coef(obj)[2], ...
> etc.   You still can automate the whole
> process this way, right?
> 
> 
> 
> 
> 
> - Original Message 
> > From: array chip 
> > To: r-help@r-project.org
> > Sent: Tue, May 18, 2010 4:13:33 PM
> > Subject: [R] automate curve drawing on nls() object
> > 
> > Hi, I would like to use the curve() function to draw
> the predicted curve from an 
> > nls() object. for 
> > example:
> 
> dd<-read.table("dd.txt",sep='\t',header=T,row.names=1)
> obj<-nls(y~c+(d-c)/(1+(x/e)^b),data=dd,start=list(b=-1,
> 
> > c=0, d=100, e=150))
> coef(obj)
>           b  
> >          c   
>        d    
> >        e 
> -1.1416422   0.6987028 102.8613176 
> > 135.9373131
> curve(0.699+(102.86-0.699)/(1+(x/135.94)^(-1.1416)),1,2)
> 
> Now 
> > I am going to have a lot of datasets to do this, so
> certainly I would like to 
> > automate this. Suppose that I can create a character
> string for the formula, but 
> > I am not sure how to pass that character string into
> the curve() to make it 
> > work. The help page of curve() says the first argument
> is "an expression written 
> > as a function of x, or alternatively the name of a
> function which will be 
> > plotted". I tried the following, for example:
> 
> substitute(expression(c + 
> > (d - c)/(1 + (x/e)^b)),as.list(coef(obj)))
> will 
> > return:
> "expression(0.698704171233635 + (102.861317499063 - 
> > 0.698704171233635)/(1 +
> (x/135.937317917920)^-1.14164217993857))"
> 
> so I 
> > tried:
> curve(substitute(expression(c + (d - c)/(1 + (x/e)^b)), 
> > as.list(coef(obj))), 1,2)
> 
> but it returns an error:
> "Error in 
> > xy.coords(x, y, xlabel, ylabel, log) : 
>   'x' and 'y' lengths 
> > differ"
> 
> Any suggestions?
> 
> 
> A related question:
> 
> If I do 
> > this:
> substitute(expression(c + (d - c)/(1 + 
> > (x/e)^b)),as.list(coef(obj)))
> 
> I will get: 
> > 
> "expression(0.698704171233635 + (102.861317499063 -
> 0.698704171233635)/(1 + 
> > (x/135.937317917920)^-1.14164217993857))"
> 
> But if I 
> > do:
> substitute(parse(text=as.character(obj$call$formula[3]),srcfile=NULL),as.list(coef(obj)))
> 
> I 
> > only get:
> "parse(text = as.character(obj$call$formula[3]), srcfile =
> NULL)" 
> > as a result, not have b,c,d,e replaced by coefficient
> 
> > values.
> 
> where
>     
> > 
> parse(text=as.character(obj$call$formula[3]),srcfile=NULL)
> returns the 
> > wanted expression:
> "expression(c + (d - c)/(1 + (x/e)^b))"
> 
> Why is 
> > that?
> 
> Thanks
> 
> John
> 
> __
> 
> > ymailto="mailto:R-help@r-project.org";
> 
> > href="mailto:R-help@r-project.org";>R-help@r-project.org
> mailing list
> 
> > href="https://stat.ethz.ch/mailman/listinfo/r-help";
> target=_blank 
> > >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] automate curve drawing on nls() object

2010-05-18 Thread Shi, Tao
I can't directly answer your question regarding 'expression', but can you just 
replace b, c,d, and e with coef(obj)[1], coef(obj)[2], ... etc.   You still can 
automate the whole process this way, right?





- Original Message 
> From: array chip 
> To: r-help@r-project.org
> Sent: Tue, May 18, 2010 4:13:33 PM
> Subject: [R] automate curve drawing on nls() object
> 
> Hi, I would like to use the curve() function to draw the predicted curve from 
> an 
> nls() object. for 
> example:

dd<-read.table("dd.txt",sep='\t',header=T,row.names=1)
obj<-nls(y~c+(d-c)/(1+(x/e)^b),data=dd,start=list(b=-1, 
> c=0, d=100, e=150))
coef(obj)
  b  
>  c   d
>e 
-1.1416422   0.6987028 102.8613176 
> 135.9373131
curve(0.699+(102.86-0.699)/(1+(x/135.94)^(-1.1416)),1,2)

Now 
> I am going to have a lot of datasets to do this, so certainly I would like to 
> automate this. Suppose that I can create a character string for the formula, 
> but 
> I am not sure how to pass that character string into the curve() to make it 
> work. The help page of curve() says the first argument is "an expression 
> written 
> as a function of x, or alternatively the name of a function which will be 
> plotted". I tried the following, for example:

substitute(expression(c + 
> (d - c)/(1 + (x/e)^b)),as.list(coef(obj)))
will 
> return:
"expression(0.698704171233635 + (102.861317499063 - 
> 0.698704171233635)/(1 + (x/135.937317917920)^-1.14164217993857))"

so I 
> tried:
curve(substitute(expression(c + (d - c)/(1 + (x/e)^b)), 
> as.list(coef(obj))), 1,2)

but it returns an error:
"Error in 
> xy.coords(x, y, xlabel, ylabel, log) : 
  'x' and 'y' lengths 
> differ"

Any suggestions?


A related question:

If I do 
> this:
substitute(expression(c + (d - c)/(1 + 
> (x/e)^b)),as.list(coef(obj)))

I will get: 
> 
"expression(0.698704171233635 + (102.861317499063 - 0.698704171233635)/(1 + 
> (x/135.937317917920)^-1.14164217993857))"

But if I 
> do:
substitute(parse(text=as.character(obj$call$formula[3]),srcfile=NULL),as.list(coef(obj)))

I 
> only get:
"parse(text = as.character(obj$call$formula[3]), srcfile = NULL)" 
> as a result, not have b,c,d,e replaced by coefficient 
> values.

where

> 
parse(text=as.character(obj$call$formula[3]),srcfile=NULL)
returns the 
> wanted expression:
"expression(c + (d - c)/(1 + (x/e)^b))"

Why is 
> that?

Thanks

John

__

> ymailto="mailto:R-help@r-project.org"; 
> href="mailto:R-help@r-project.org";>R-help@r-project.org mailing list

> href="https://stat.ethz.ch/mailman/listinfo/r-help"; target=_blank 
> >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 display data values for points in a plot?

2010-05-18 Thread Greg Snow
It depends on what you mean by display values.  In addition to the other 
suggestions also look at the identify function as well as TkIdentify and 
HTKidentify in the TeachingDemos package.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Nish
> Sent: Thursday, May 13, 2010 10:33 AM
> To: r-help@r-project.org
> Subject: [R] How to display data values for points in a plot?
> 
> 
> Hello,
> 
> I would like to know how to display values for points in a plot
> funtion. For
> example,
> 
> plot( y=dat$a,
>   x=dat$b,
>   main="plot1",
>   ylab="a",
>   xlab="b",
>   ylim=c(-10, 10),
>   xlim=c(-10, 10),
>   type = "p",
>   pch=17,
>   col=,
>   cex=1.5
>  )
> 
> How can I add a label to each of points here, if I have a list of
> values
> associated with the point.
> 
> Thanks in advance.
> 
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-
> display-data-values-for-points-in-a-plot-tp2197796p2197796.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] automate curve drawing on nls() object

2010-05-18 Thread Ben Bolker
array chip  yahoo.com> writes:

> Hi, I would like to use the curve() function to draw the 
> predicted curve from an nls() object. for example:
> 

  Is there a reason you don't want to use plot() and predict() ???
  
> dd<-read.table("dd.txt",sep='\t',header=T,row.names=1)

  note that this is not a reproducible example ...

> obj<-nls(y~c+(d-c)/(1+(x/e)^b),data=dd,start=list(b=-1, c=0, d=100, e=150))
> coef(obj)
>   b   c   d   e 
>  -1.1416422   0.6987028 102.8613176 135.9373131
> curve(0.699+(102.86-0.699)/(1+(x/135.94)^(-1.1416)),1,2)
> 

  predframe <- data.frame(x=seq(1,2,length.out=101))
  predframe <- cbind(predframe,y=predict(obj,newdata=predframe))
  with(predframe,plot(y~x,type="l"))

__
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] Function that is giving me a headache- any help appreciated (automatic read )

2010-05-18 Thread Hadley Wickham
> precip.1 <- subset(DF, precipitation!="NA")
> b <- ddply(precip.1$precipitation, .(precip.1$gauge_name), cumsum)
> DF.precip <- precip.1
> DF.precip$precipitation <- b$.data

I suspect what you want here is

ddply(precip.1, "gauge_name", transform, precipitation = cumsum(precipitation))

Hadley


-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

__
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] A problem in allocation of vector of size

2010-05-18 Thread jim holtman
You have run out of memory.  What OS are you using, how much physical
memory do you have? how large are the objects you already have in your
data space?  Have you removed all extraneous objects and done 'gc()'?

The solution is to get better control of your data space and
understand what is using it up.

On Tue, May 18, 2010 at 12:58 AM, Yan Li  wrote:
> Hi, r-users
>
>
> I happen to a problem in allocation of vector of size. When I run my R
> script, an error appears:
>
>
> Error: cannot allocate vector of size 450 Mb
>
>
> Could anyone happen to the same problem? Thank you for your help.
>
>
> Lee
>
>        [[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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
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] automate curve drawing on nls() object

2010-05-18 Thread array chip
Hi, I would like to use the curve() function to draw the predicted curve from 
an nls() object. for example:

dd<-read.table("dd.txt",sep='\t',header=T,row.names=1)
obj<-nls(y~c+(d-c)/(1+(x/e)^b),data=dd,start=list(b=-1, c=0, d=100, e=150))
coef(obj)
  b   c   d   e 
 -1.1416422   0.6987028 102.8613176 135.9373131
curve(0.699+(102.86-0.699)/(1+(x/135.94)^(-1.1416)),1,2)

Now I am going to have a lot of datasets to do this, so certainly I would like 
to automate this. Suppose that I can create a character string for the formula, 
but I am not sure how to pass that character string into the curve() to make it 
work. The help page of curve() says the first argument is "an expression 
written as a function of x, or alternatively the name of a function which will 
be plotted". I tried the following, for example:

substitute(expression(c + (d - c)/(1 + (x/e)^b)),as.list(coef(obj)))
will return:
"expression(0.698704171233635 + (102.861317499063 - 0.698704171233635)/(1 + 
(x/135.937317917920)^-1.14164217993857))"

so I tried:
curve(substitute(expression(c + (d - c)/(1 + (x/e)^b)), as.list(coef(obj))), 
1,2)

but it returns an error:
"Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' and 'y' lengths differ"

Any suggestions?


A related question:

If I do this:
substitute(expression(c + (d - c)/(1 + (x/e)^b)),as.list(coef(obj)))

I will get: 
"expression(0.698704171233635 + (102.861317499063 - 0.698704171233635)/(1 + 
(x/135.937317917920)^-1.14164217993857))"

But if I do:
substitute(parse(text=as.character(obj$call$formula[3]),srcfile=NULL),as.list(coef(obj)))

I only get:
"parse(text = as.character(obj$call$formula[3]), srcfile = NULL)" as a result, 
not have b,c,d,e replaced by coefficient values.

where
 
parse(text=as.character(obj$call$formula[3]),srcfile=NULL)
returns the wanted expression:
"expression(c + (d - c)/(1 + (x/e)^b))"

Why is that?

Thanks

John

__
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] Dealing with 1000+ sequentially named vectors

2010-05-18 Thread jim holtman
This sounds like a perfect use of "list" and the 'sapply/lapply' functions:

> # list with 100 dataframes
> df.list <- lapply(1:100,function(x) data.frame(a=1:10, b=1:10))
> # create a new list with a random value of 'a'
> new.list <- sapply(df.list, function(x) sample(x$a, 1))
>
>
> new.list
  [1]  5  8 10  4  8 10  3  7  2  3  4  1  4  9  4  5  6  5  2  9  7  8  2
8  5  9  7  8  6  6  8  1  5  8  7
 [36]  5  9  5  3  1  1  4  6  7  5 10  3  5  4  7  3  5  8  1  9  4  9  4
4  5  9  9  4  8 10  5  8  4  4  8
 [71]  3  8  2  3  2  3  1  7  9  8  8  5  5  9  7  7  4  3 10  7  3  2  5
10  6 10  8  4  5  2
>


On Tue, May 18, 2010 at 5:28 PM, Q  wrote:

>
> Hello!
>
>
> I'm having trouble figuring out how to apply a function to a set of vectors
> or data frames, when that set is over 1000 large.
>
>
> I've created 1891 vectors named as follows:
>
>
> vector.names <- paste("vector",1:1891,sep="")
>
>
> These can be referred to easily by using get as follows:
>
>
> vector <- get(vector.names[1])
>
>
> The problem is, I can't figure out a way to refer to all of them as a
> group,
> and then apply a function to each one.  Basically, I have 5000 data frames,
> each with 1891 rows.  I want a vector for each row, and a cell from each
> data frame in each vector.  That would give me 1891 vectors with 5000
> members each.  The only way I know how to do this, is to use loops, which
> end up being really slow.
>
>
> So:
>
>
> for(a in 1:5000){
>
> data <- get(dataframes[a])
>
>
> for(b in 1:1891){
>
> vector <- get(vector.names[b]
>
> vector[a] <- data$value
>
> assign(vector.names[b], vector)
>
> }
>
>
> }
>
>
> Does anyone have any insight into dealing with large quantities of data
> like
> this?
>
>
> Thanks!
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Dealing-with-1000-sequentially-named-vectors-tp2221942p2221942.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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[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] Dealing with 1000+ sequentially named vectors

2010-05-18 Thread Q

Hello!


I'm having trouble figuring out how to apply a function to a set of vectors
or data frames, when that set is over 1000 large.


I've created 1891 vectors named as follows:


vector.names <- paste("vector",1:1891,sep="")


These can be referred to easily by using get as follows:


vector <- get(vector.names[1])


The problem is, I can't figure out a way to refer to all of them as a group,
and then apply a function to each one.  Basically, I have 5000 data frames,
each with 1891 rows.  I want a vector for each row, and a cell from each
data frame in each vector.  That would give me 1891 vectors with 5000
members each.  The only way I know how to do this, is to use loops, which
end up being really slow.


So:


for(a in 1:5000){

data <- get(dataframes[a])


for(b in 1:1891){

vector <- get(vector.names[b]

vector[a] <- data$value

assign(vector.names[b], vector)

}


}


Does anyone have any insight into dealing with large quantities of data like
this?


Thanks!
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Dealing-with-1000-sequentially-named-vectors-tp2221942p2221942.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] sem error "no variance or error-variance parameter"

2010-05-18 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Jan Schubert
> Sent: Tuesday, May 18, 2010 12:51 PM
> To: r-help@r-project.org
> Subject: [R] sem error "no variance or error-variance parameter"
> 
> 
> Hi,
> I am sorry to post the message again but I really need some advise on
> that.
> I am using the R version 2.11.0 and the version of sem package:
> sem_0.9-20
> under Windows XP.
> I read the questions:
> http://r.789695.n4.nabble.com/computationally-singular-and-lack-of-
> variance-parameters-in-SEM-td891081.html#a891082
> 
> and
> 
> http://r.789695.n4.nabble.com/computationally-singular-and-lack-of-
> variance-parameters-in-SEM-td891081.html#a891081
> 
> but it does not seem to be my problem. I try to replicate the sem model
> (see
> the attacheted image) but i got stuck with the problem while computing
> the
> estimates of the model:
> The error message:
> 
> Error in nlm(if (analytic.gradient) objective.2 else objective.1,
> start,  :
>   probable coding error in analytic gradient
> In addition: Warning message:
> In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names =
> vars,  :
>   The following variables have no variance or error-variance parameter
> (double-headed arrow):
>  Fugural1
> The model is almost surely misspecified; check also for missing
> covariances.
> 
> Here is my script:
> 
> cov.matrix <-
> matrix(c(56.21,0,0,0,0,0,0,0,0,31.55,75.55,0,0,0,0,0,0,0,23.27,28.30,44
> .45,0,0,0,0,0,0,24.48,32.24,22.56,84.64,0,0,0,0,0,22.51,29.54,20.61,57.
> 61,78.93,0,0,0,0,22.65,27.56,15.33,53.57,49.27,73.76,0,0,0,33.24,46.49,
> 31.44,67.81,54.76,54.58,141.77,0,0,32.56,40.37,25.58,55.82,55.33,47.74,
> 98.62,117.33,0,30.32,40.44,27.69,54.78,53.44,59.52,96.95,84.87,106.35),
> nrow=9,ncol=9,byrow=FALSE)
> rownames(cov.matrix) <- colnames(cov.matrix) <-
> c("IND1","IND2","IND3","FR11","FR12","FR13","FR21","FR22","FR23")
> 
> # options(nlm=(check.analyticals = TRUE)); I tried to set the nlm on
> different option, but did not work either
> 
> m1 <- specify.model()
> Induction -> IND1, NA, 1
> Induction -> IND2, y2, NA
> Induction -> IND3, y3, NA
> Fugural1 -> FR11, NA, 1
> Figural1 -> FR12, y5, NA
> Figural1 -> FR13, y6, NA
> Figural2 -> FR21, NA, 1
> Figural2 -> FR22, y8, NA
> Figural2 -> FR23, y9, NA
> Induction -> Figural1, x1, NA
> Figural1 -> Figural2,x2, NA
> Induction -> Figural2, x3, NA
> IND1 <-> IND1, e1, NA
> IND2 <-> IND2, e2, NA
> IND3 <-> IND3, e3, NA
> FR11 <-> FR11, e4, NA
> FR12 <-> FR12, e5, NA
> FR13 <-> FR13, e6, NA
> FR21 <-> FR21,e7, NA
> FR22 <-> FR22, e8, NA
> FR23 <-> FR23, e9, NA
> Figural1 <-> Figural1, e10, NA
> Figural2 <-> Figural2, e11, NA
> Induction <-> Induction, NA, 1
> 
> sem1 <- sem(m1,cov.matrix,N=220,debug=T)
> 
> # I added the Induction <-> Induction, NA, 1 fixed parametr after
> reading
> the help from John Fox, that every variable should have an error
> variance
> 
> 
> Can anybody please advise me what I am doing wrong?
> Many thanks!
> 
> Jan Schubert
> Institute of Social Science
> Charles University, Prague
> --

Jan,

I didn't go through your model in detail, but if you look carefully at the 
error message, you appear to have misspelled Figural1 as Fugural1.  When I 
corrected that problem, your example ran without error.

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


__
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] best polynomial approximation

2010-05-18 Thread Patrizio Frederic
Dear colleagues,
thank you so much for your help.
Hans, I think the Remez algorithm is what I need. I will brush up on
fortran language.
Ravi, thanks anyway, I appreciated.

All the best,

Patrizio



On Tue, May 18, 2010 at 12:10 PM, Hans W Borchers
 wrote:
>
> I guess you may be looking for the Remez algorithm. AFAIK there is no
> implementation in one of the R packages. You can find FORTRAN code in the
> Collected Algorithms of the ACM (no. 604) which probably could be called
> from R.
>
> There appears to exist a discrete, equi-distant(?) version as function
> 'remez' in the signal package, if that is of any help to you. I have never
> used it.
>
> Regards,  Hans Werner
>
> P.S.: The Chebyshev polynomials do not compute the "best polynomial
> approximation", but they provide a nice way to estimate the maximal distance
> to this best approximating polynomial.
>
>
>
> Patrizio Frederic wrote:
>>
>> Dear R-users,
>> I learned today that there exists an interesting topic in numerical
>> analysis names "best polynomial approximation" (BSA). Given a function
>> f  the BSA of degree k, say pk, is the polynomial such that
>>
>> pk=arginf sup(|f-pk|)
>>
>> Although given some regularity condition of f, pk is unique, pk IS NOT
>> calculated with least square. A quick google tour show a rich field of
>> research and many algorithms proposed for computing such a task.
>>
>> I was wondered if some of you knows about some R implementations
>> (packages) for computing BSA.
>>
>> Many thanks in advance,
>>
>> Patrizio
>>
>> as usual I apologize for my fragmented English
>>
>> --
>> +-
>> | Patrizio Frederic, PhD
>> | Assistant Professor,
>> | Department of Economics,
>> | University of Modena and Reggio Emilia,
>> | Via Berengario 51,
>> | 41100 Modena, Italy
>> |
>> | tel:  +39 059 205 6727
>> | fax:  +39 059 205 6947
>> | mail: patrizio.frede...@unimore.it
>> +-
>>
>> __
>> 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.
>>
>>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/best-polynomial-approximation-tp2220439p2221042.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.
>



-- 
+-
| Patrizio Frederic, PhD
| Assistant Professor,
| Department of Economics,
| University of Modena and Reggio Emilia,
| Via Berengario 51,
| 41100 Modena, Italy
|
| tel:  +39 059 205 6727
| fax:  +39 059 205 6947
| mail: patrizio.frede...@unimore.it
+-

__
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] Function that is giving me a headache- any help appreciated (automatic read )

2010-05-18 Thread Peter Ehlers

On 2010-05-18 11:00, John Kane wrote:


I don't think you can do this
precipitation!="NA")


Actually, that will work here, although it should always be avoided.
Do use is.na().

The main problem seems to be that the ddply() call doesn't work.
I would just use tapply() and unlist():

 b <- with(precip.1, tapply(precipitation, gauge_name, cumsum))
 b <- unlist(b)

You'll also find that you need to wrap your qplot() calls in print().

And your if/else logic (at the end of USGS) looks faulty.

 -Peter Ehlers



have a look at ?is.na

--- On Tue, 5/18/10, stephen sefick  wrote:


From: stephen sefick
Subject: [R] Function that is giving me a headache- any help appreciated 
(automatic read )
To: r-help@r-project.org
Received: Tuesday, May 18, 2010, 12:38 PM
note: whole function is below- I am
sure I am doing something silly.

when I use it like USGS(input="precipitation") it is
choking on the


precip.1<- subset(DF, precipitation!="NA")
b<- ddply(precip.1$precipitation,
.(precip.1$gauge_name), cumsum)
DF.precip<- precip.1
DF.precip$precipitation<- b$.data

part, but runs fine outside of the function:

days=7
input="precipitation"
require(chron)
require(gsubfn)
require(ggplot2)
require(plyr)
#021973269 is the Waynesboro Gauge on the Savannah River
Proper (SRS)
#02102908 is the Flat Creek Gauge (ftbrfcms)
#02133500 is the Drowning Creek (ftbrbmcm)
#02341800 is the Upatoi Creek Near Columbus (ftbn)
#02342500 is the Uchee Creek Near Fort Mitchell (ftbn)
#02203000 is the Canoochee River Near Claxton (ftst)
#02196690 is the Horse Creek Gauge at Clearwater, S.C.

a<- "http://waterdata.usgs.gov/nwis/uv?format=rdb&period=";
b<-
"&site_no=021973269,02102908,02133500,02341800,02342500,02203000,02196690"
z<- paste(a, days, b, sep="")
L<- readLines(z)

#look for the data with USGS in front of it (this take
advantage of
#the agency column)
L.USGS<- grep("^USGS", L, value = TRUE)
DF<- read.table(textConnection(L.USGS), fill = TRUE)
colnames(DF)<- c("agency", "gauge", "date", "time",
"time_zone",
"gauge_height",
"discharge", "precipitation")
pat<- "^# +USGS +([0-9]+) +(.*)"
L.DD<- grep(pat, L, value = TRUE)
library(gsubfn)
DD<- strapply(L.DD, pat, c, simplify = rbind)
DDdf<- data.frame(gauge = as.numeric(DD[,1]),
gauge_name = DD[,2])
both<- merge(DF, DDdf, by = "gauge", all.x = TRUE)

dts<- as.character(both[,"date"])
tms<- as.character(both[,"time"])
date_time<- as.chron(paste(dts, tms), "%Y-%m-%d
%H:%M")
DF<- data.frame(Date=as.POSIXct(date_time), both)
#change precip to numeric
DF[,"precipitation"]<-
as.numeric(as.character(DF[,"precipitation"]))

precip.1<- subset(DF, precipitation!="NA")
b<- ddply(precip.1$precipitation,
.(precip.1$gauge_name), cumsum)
DF.precip<- precip.1
DF.precip$precipitation<- b$.data

#discharge
if(input=="data"){

return(DF)

}else{

qplot(Date, discharge, data=DF,
geom="line", ylab="Date")+facet_wrap(~gauge_name,
scales="free_y")+coord_trans(y="log10")}

if(input=="precipitation"){
#precipitation
qplot(Date, precipitation, data=DF.precip,
geom="line")+facet_wrap(~gauge_name, scales="free_y")

}else{

qplot(Date, discharge, data=DF,
geom="line", ylab="Date")+facet_wrap(~gauge_name,
scales="free_y")+coord_trans(y="log10")}

below is the whole function:

USGS<- function(input="discharge", days=7){
require(chron)
require(gsubfn)
require(ggplot2)
require(plyr)
#021973269 is the Waynesboro Gauge on the Savannah River
Proper (SRS)
#02102908 is the Flat Creek Gauge (ftbrfcms)
#02133500 is the Drowning Creek (ftbrbmcm)
#02341800 is the Upatoi Creek Near Columbus (ftbn)
#02342500 is the Uchee Creek Near Fort Mitchell (ftbn)
#02203000 is the Canoochee River Near Claxton (ftst)
#02196690 is the Horse Creek Gauge at Clearwater, S.C.

a<- "http://waterdata.usgs.gov/nwis/uv?format=rdb&period=";
b<-
"&site_no=021973269,02102908,02133500,02341800,02342500,02203000,02196690"
z<- paste(a, days, b, sep="")
L<- readLines(z)

#look for the data with USGS in front of it (this take
advantage of
#the agency column)
L.USGS<- grep("^USGS", L, value = TRUE)
DF<- read.table(textConnection(L.USGS), fill = TRUE)
colnames(DF)<- c("agency", "gauge", "date", "time",
"time_zone",
"gauge_height",
"discharge", "precipitation")
pat<- "^# +USGS +([0-9]+) +(.*)"
L.DD<- grep(pat, L, value = TRUE)
library(gsubfn)
DD<- strapply(L.DD, pat, c, simplify = rbind)
DDdf<- data.frame(gauge = as.numeric(DD[,1]),
gauge_name = DD[,2])
both<- merge(DF, DDdf, by = "gauge", all.x = TRUE)

dts<- as.character(both[,"date"])
tms<- as.character(both[,"time"])
date_time<- as.chron(paste(dts, tms), "%Y-%m-%d
%H:%M")
DF<- data.frame(Date=as.POSIXct(date_time), both)
#change precip to numeric
DF[,"precipitation"]<-
as.numeric(as.character(DF[,"precipitation"]))

precip.1<- subset(DF, precipitation!="NA")
b<- ddply(precip.1$precipitation,
.(precip.1$gauge_name), cumsum)
DF.precip<- precip.1
DF.precip$precipitation<- b$.data

#discharge
if(input=="data"){

return(DF)

}else{

qplot(Date, discharge, data=DF,
geom="line", ylab="Date")+facet_wrap(~gauge_name,
scal

Re: [R] get the row sums

2010-05-18 Thread Joshua Wiley
Hello,

Can you run str() on your data and report the results?

str(en.id.pr)

I suspect that one of your variables that you are trying to sum over
is a factor.

HTH,

Josh

2010/5/18 Changbin Du :
>> head(en.id.pr)
>     valid.gene_id b.pred rf.pred svm.pred
> 1521    2500151211      0       0        0
> 366      639679745      0       0        0
> 1965    2502081603      1       1        1
> 1420     644148030      1       1        1
> 1565    2500626489      1       1        1
> 1816    2501711016      1       1        1
>
>
>> p.pred <- data.frame(en.id.pr, sum=apply(en.id.pr[,2:4], 1, sum)) # get
> the row sum for three variables.
> Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument
>
>
> HI, Dear R community,
>
> I am try use the above codes to get the row sums, but it gave me errors.
> CAN someone help me with this?
>
>
> --
> Sincerely,
> Changbin
> --
>
> Changbin Du
> DOE Joint Genome Institute
> Bldg 400 Rm 457
> 2800 Mitchell Dr
> Walnut Creet, CA 94598
> Phone: 925-927-2856
>
>        [[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.
>



-- 
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] get the row sums

2010-05-18 Thread Changbin Du
Thanks, David!
Yes, I found it just as you said. It works now after change to numeric.


On Tue, May 18, 2010 at 1:53 PM, David Winsemius wrote:

>
> On May 18, 2010, at 4:32 PM, Changbin Du wrote:
>
>  head(en.id.pr)
>>>
>>valid.gene_id b.pred rf.pred svm.pred
>> 15212500151211  0   00
>> 366  639679745  0   00
>> 19652502081603  1   11
>> 1420 644148030  1   11
>> 15652500626489  1   11
>> 18162501711016  1   11
>>
>>
>>  p.pred <- data.frame(en.id.pr, sum=apply(en.id.pr[,2:4], 1, sum)) # get
>>>
>> the row sum for three variables.
>> Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument
>>
>>
>> HI, Dear R community,
>>
>> I am try use the above codes to get the row sums, but it gave me errors.
>> CAN someone help me with this?
>>
>
> If you look at the results of str(en.id.pr) , I think you will find that
> one or more of those columns is of class character.
>
> (There is also a rowSums function, but if you have character variables It's
> not likely to be of much additional help.)
>
>
>
>>
>> --
>> Sincerely,
>> Changbin
>> --
>>
>> Changbin Du
>>
>
>
> David Winsemius, MD
> West Hartford, CT
>
>


-- 
Sincerely,
Changbin
--

Changbin Du
DOE Joint Genome Institute
Bldg 400 Rm 457
2800 Mitchell Dr
Walnut Creet, CA 94598
Phone: 925-927-2856

[[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] [R-pkgs] The npRmpi package (parallel np package for multi-core environments)

2010-05-18 Thread Jeffrey Racine
Dear R users,

A parallel implementation of the np package titled `npRmpi' is now available on 
CRAN. This package can take advantage of multiple core computing environments 
to reduce the run time associated with the methods contained in the np package. 

Kindly see the vignette for details and examples on modifying np code and 
running it in a parallel environment. You are requested to seek local 
assistance for configuring machines to support MPI aware programs.

Information on the npRmpi package:

This package provides a variety of nonparametric (and semiparametric) kernel 
methods that seamlessly handle a mix of continuous, unordered, and ordered 
factor data types. This package incorporates the Rmpi package (Hao Yu 
) with minor modifications and we are extremely grateful to 
Hao Yu for his contributions to the R community. We would like to gratefully 
acknowledge support from the Natural Sciences and Engineering Research Council 
of Canada (NSERC:www.nserc.ca), the Social Sciences and Humanities Research 
Council of Canada (SSHRC:www.sshrc.ca), and the Shared Hierarchical Academic 
Research Computing Network (SHARCNET:www.sharcnet.ca).

A thorough treatment of the subject matter can be found in Li, Q. and J. S. 
Racine (2007), Nonparametric Econometrics: Theory and Practice, Princeton 
University Press, ISBN: 0691121613 (768 Pages) for
those who might be interested (http://press.princeton.edu/titles/8355.html)

-- Jeffrey Racine & Tristen Hayfield.

Professor J. S. Racine Phone:  (905) 525 9140 x 23825
Department of EconomicsFAX:(905) 521-8232
McMaster Universitye-mail: raci...@mcmaster.ca
1280 Main St. W.,Hamilton, URL: www.economics.mcmaster.ca/racine
Ontario, Canada. L8S 4M4

`The generation of random numbers is too important to be left to chance'

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
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] get the row sums

2010-05-18 Thread David Winsemius


On May 18, 2010, at 4:32 PM, Changbin Du wrote:


head(en.id.pr)

valid.gene_id b.pred rf.pred svm.pred
15212500151211  0   00
366  639679745  0   00
19652502081603  1   11
1420 644148030  1   11
15652500626489  1   11
18162501711016  1   11


p.pred <- data.frame(en.id.pr, sum=apply(en.id.pr[,2:4], 1, sum)) #  
get

the row sum for three variables.
Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument


HI, Dear R community,

I am try use the above codes to get the row sums, but it gave me  
errors.

CAN someone help me with this?


If you look at the results of str(en.id.pr) , I think you will find  
that one or more of those columns is of class character.


(There is also a rowSums function, but if you have character variables  
It's not likely to be of much additional help.)






--
Sincerely,
Changbin
--

Changbin Du



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] Problem getting characters into a dataframe

2010-05-18 Thread Chris Strachan

Hi,

I am having a problem getting character (string) variables into a 
dataframe.  I seem to have no problem with numeric fields, but character 
fields are appearing as a "1".


In my problem I need to retrieve some information from an SQL database 
using RODBC one line at a time and then update the respective row.


I have tried converting the object returned from the query into various 
classes but to no avail.


Here is a selection of the code:

I am updating table2 in this case which only has two rows.
The query is executed for the row and stored in y.  The contents of y 
are then meant to update the various columns.



> for (x in c(1:2)) { y <- 
sqlQuery(EFXchannel,paste(getData,total2$TRAN_NUMBER[x]))


+ y <- as.list(y)

+total2$TRN_DT[x] <- as.numeric(y[1]) +ISOdatetime(1970,1,1,1,0,0)

+total2$CARDNUM[x] <- as.character(y[2])

+total2$TRN_AMT[x] <- as.double(y[3])

+total2$MER_CNTY_CD[x] <- as.numeric(y[4])

+total2$SIC_CD[x] <- as.numeric(y[5])

+total2$MER_NM[x] <- as.character(y[6])

+print(y[6])

+total2$TRN_POS_ENT_CD[x] <- as.character(y[7])

+total2$RULE_HIT[x] <- as.numeric(y[8])}

MER_NM

1 X RENT A CAR

MER_NM

1 HOTEL X

> total2

  TRAN_NUMBER TRN_DTTRN_AMT MER_CNTY_CD SIC_CD MER_NM 
TRN_POS_ENT_CD RULE_HIT


1   720001861 1272544032 600 724   7512  1  
11


2   720001377 1272493155  86 250   7011  1  
11


>

As you can see MER_NM and TRN_POS_ENT_CD do not update.

For information this is the type of information returned by the query

> z <- sqlQuery(EFXchannel,paste(getData,720001377))

> z

   TRN_DT TRN_AMT MER_CNTY_CD 
SIC_CD   MER_NM TRN_POS_ENT_CD RULE


1 2010-04-28 23:19:15  86 250   7011 HOTEL 
X  K1


> class(z)

[1] "data.frame"


Any assistance or alternate methodologies would be much appreciated.

Thanks,
Chris

__
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] Res: Using the zero-inflated binomial in experimental designs

2010-05-18 Thread Ben Bolker
Ivan Allaman  yahoo.com.br> writes:

> 
> 
> Hi Ben!
> 
> First I thank you for your attention. Unfortunately, the ANOVA does not work
with vglm. In
> another email, Rafael warned me that actually a lot of zeros does not
> necessarily imply a distribution of zeros binomail inflated. So how could I
test if my variable is or not a
> binomial zero inflated?

   For most modeling functions in R, anova() actually performs a
likelihood ratio test [its name is a historical accident/extension
from the linear models case].  If VGLM has a logLik() accessor method
you can do your own LRT as follows:

pchisq(-2*(logLik(fullModel)-logLik(reducedModel)),lower.tail=FALSE,
df=[difference in number of parameters])

if there is no logLik() accessor you can just read off the values
from the summary, or use str() to figure out how to extract the value
from the model fit.

To test whether zero-inflation is necessary you can compare the log-likelihood
of the zero-inflated model vs. the log-likelihood of a non-zero-inflated
model, with a couple of caveats: (1) check to make sure that the
different functions you are using [e.g. if you use glm() for non-inflated
and vglm() for inflated models] are including/excluding the same additive
constants from the log-likelihood; (2) the p-value may be somewhat 
conservative, if the null hypothesis (no zero-inflation) is on the
boundary of the feasible space of the parameter [e.g.see p. 330 of
http://people.biology.ufl.edu/bolker/emdbook/book.pdf ]

More easily but less specifically, you could see whether the binomial
model appears to be an adequate fit to the data, graphically (by
comparing observed vs expected frequencies of zeros) or by doing a
chi-squared test.

__
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] avoiding reinstall already installed *package*

2010-05-18 Thread William Dunlap
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Maechler
> Sent: Tuesday, May 18, 2010 1:25 PM
> To: milton ruser
> Cc: r-help@r-project.org
> Subject: Re: [R] avoiding reinstall already installed *package*
> 
> On Tue, May 18, 2010 at 18:06, milton ruser 
>  wrote:
> 
> > Hi Martin,
> >
> > thanks for your reply, and very thanks for your kind tips 
> about "package"
> > and "library"
> > So, I was trying to understand *why* we load packages using 
> library().
> >
> 
> I've started to use and suggest using   require(.) instead
> {as my efforts to introduce  use() or usePackage() *and* deprecating
>  library()  where met with strong opposition}

I hate to get into arguments over function names, but
I would have thought that require("pkg") would throw
an error if the required pkg was not available.  It seems
like require() can be used when pkg is not really required
but library("pkg") is easiest when pkg is required to
continue:

  > { require("noSuchPackage"); functionFromNoSuchPackage() }
  Loading required package: noSuchPackage
  Error: could not find function "functionFromNoSuchPackage"
  In addition: Warning message:
  In library(package, lib.loc = lib.loc, character.only = TRUE,
logical.return = TRUE,  :
there is no package called 'noSuchPackage'
  > { library("noSuchPackage"); functionFromNoSuchPackage() }
  Error in library("noSuchPackage") :
there is no package called 'noSuchPackage'

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> 
> 
> > I suggest that developers killl the problem on its root, 
> deleting library
> > function :-)
> > Good to know already installed packages will not be reinstalled.
> >
> > cheers
> >
> > milton
> >
> > On Tue, May 18, 2010 at 12:49 PM, Martin Maechler <
> > maech...@stat.math.ethz.ch> wrote:
> >
> >> { I've modified the subject; I can't stand it hitting square into
> >>  my face ... }
> >>
> >> > "mr" == milton ruser 
> >> > on Tue, 18 May 2010 12:36:23 -0300 writes:
> >>
> >>mr> Dear R-experts,
> >>mr> I am installing new libraries using
> >>mr> install.packages("ggplot2",dependencies=T).
> >>mr> But I perceive that many dependencies are already 
> installed. As I
> >> am using
> >>mr> a low-band internet, how can avoid reinstall 
> installed libraries?
> >>
> >> There's no problem with installed libraries, as ...
> >> they DO NOT EXIST.
> >>
> >> These are *PACKAGES* !
> >> Why do you think are you talking about the function
> >>
> >>  install.packages()  
> >> 
> >>
> >> ---
> >> To answer the question you did want to ask:
> >>
> >> Do not be afraid:  Depedencies are only installed when needed,
> >> i.e., no package will be downloaded and installed if it already
> >> is there.
> >>
> >> Martin Maechler, ETH Zurich
> >>
> >>mr> cheers
> >>
> >>mr> milton
> >>
> >>mr> [[alternative HTML version deleted]]
> >>
> >> (another thing you should learn to avoid, please)
> >>
> >>
> >
> 
>   [[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] substitute, expression and factors

2010-05-18 Thread baptiste auguie
Dear list,

I am puzzled by this,

substitute(expression(x), list(x = factor(letters[1:2])))
# expression(1:2)

Why do I get back the factor levels inside the expression and not the
labels? The following work as I expected,

substitute(expression(x), list(x = letters[1:2]))
# expression(c("a", "b"))

substitute(x, list(x = factor(letters[1:2])))
# [1] a b
# Levels: a b

 bquote(.(factor(letters[1:2])))
# [1] a b
# Levels: a b


All the best,

baptiste

__
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] get the row sums

2010-05-18 Thread Changbin Du
> head(en.id.pr)
 valid.gene_id b.pred rf.pred svm.pred
15212500151211  0   00
366  639679745  0   00
19652502081603  1   11
1420 644148030  1   11
15652500626489  1   11
18162501711016  1   11


> p.pred <- data.frame(en.id.pr, sum=apply(en.id.pr[,2:4], 1, sum)) # get
the row sum for three variables.
Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument


HI, Dear R community,

I am try use the above codes to get the row sums, but it gave me errors.
CAN someone help me with this?


-- 
Sincerely,
Changbin
--

Changbin Du
DOE Joint Genome Institute
Bldg 400 Rm 457
2800 Mitchell Dr
Walnut Creet, CA 94598
Phone: 925-927-2856

[[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] avoiding reinstall already installed *package*

2010-05-18 Thread Martin Maechler
On Tue, May 18, 2010 at 18:06, milton ruser  wrote:

> Hi Martin,
>
> thanks for your reply, and very thanks for your kind tips about "package"
> and "library"
> So, I was trying to understand *why* we load packages using library().
>

I've started to use and suggest using   require(.) instead
{as my efforts to introduce  use() or usePackage() *and* deprecating
 library()  where met with strong opposition}


> I suggest that developers killl the problem on its root, deleting library
> function :-)
> Good to know already installed packages will not be reinstalled.
>
> cheers
>
> milton
>
> On Tue, May 18, 2010 at 12:49 PM, Martin Maechler <
> maech...@stat.math.ethz.ch> wrote:
>
>> { I've modified the subject; I can't stand it hitting square into
>>  my face ... }
>>
>> > "mr" == milton ruser 
>> > on Tue, 18 May 2010 12:36:23 -0300 writes:
>>
>>mr> Dear R-experts,
>>mr> I am installing new libraries using
>>mr> install.packages("ggplot2",dependencies=T).
>>mr> But I perceive that many dependencies are already installed. As I
>> am using
>>mr> a low-band internet, how can avoid reinstall installed libraries?
>>
>> There's no problem with installed libraries, as ...
>> they DO NOT EXIST.
>>
>> These are *PACKAGES* !
>> Why do you think are you talking about the function
>>
>>  install.packages()  
>> 
>>
>> ---
>> To answer the question you did want to ask:
>>
>> Do not be afraid:  Depedencies are only installed when needed,
>> i.e., no package will be downloaded and installed if it already
>> is there.
>>
>> Martin Maechler, ETH Zurich
>>
>>mr> cheers
>>
>>mr> milton
>>
>>mr> [[alternative HTML version deleted]]
>>
>> (another thing you should learn to avoid, please)
>>
>>
>

[[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] Regarding the 'R' Load Command

2010-05-18 Thread Steve Lianoglou
Hi,

On Tue, May 18, 2010 at 2:49 PM, Godavarthi, Murali
 wrote:
> Hi,
>
> I'm new to 'R' and need some help on the "Load" command. Any responses
> will be highly appreciated. Thanks in advance!
>
> As per manuals, the "Load" command expects a binary file input that is
> saved using a "save" command.

Or a path to the file ...

> However it is required that we need to
> call the 'R' program from
>
> Java web application using RJava, and pass a string to the 'R" program
> instead of a binary file. Is it possible?

Yes, pay closer attention to the description for the "file" argument
in the load function (see ?load):

"""a (readable binary) connection **or a character string** giving the
name of the file to load"""

(emphasis mine)

> I was exploring the options of using TextConnections, file connections
> and other types of connections in order to read a stream of input
> (either from a file, stdin etc). I am able to read the string, but the
> Save and Load commands are not accepting the string input. Here is the
> sequence of commands I tried running, and the error received. There is
> no clue on this error, especially when trying to use the eval function
> in randomForest package, even on the internet. Can anyone help please!
>
>> library(randomForest)
>
> randomForest 4.5-34
>
> Type rfNews() to see new features/changes/bug fixes.
>
>
>
>> load("C://Program Files//R//R-2.10.1//bin//rfoutput")
>
>
>
>> zz <- file("ex.data", "w")
>
>
>
>> cat("\"imurder\" \"itheft\" \"irobbery\" \"iassault\" \"idrug\"
> \"iburglary\" \"igun\" \"psych\" \"Freq\" \"priors\" \"firstage\"
> \"intage\" \"sex\" \"race\" \"marstat\" \"empac\"
>
> \"educ\" \"zipcode\" \"suspendmn\" \"drugs\" \"alco\" \"probation\"
> \"parole\"",file = zz, sep = "\n", fill = TRUE)
>
>
>
>> cat("\"10\" 0 0 0 1 0 0 0 0 0 58 19 19 \"1\" \"BLACK\" \"SINGLE\"
> \"UNEMPLD\" 0 21215 0 0 0 1 0",file = zz, sep = "\n", fill = TRUE)

What are you trying to do here?
It looks like you want to save a table of sorts. First create your
data into a data.frame, then save that data.frame to a file using
write.table (or write.csv, etc).

>> save(zz, file = "testmurali", version = 2)

You're saving a file "object" here, not the contents of the file.
Once you successfully serialize your data into a text file, just load
it from "like normal" using read.table (or similar).

Anyway, I'm not sure what we're talking about here, but in short:

1. You need to make sure that you are correctly saving what you think
you're saving.
2. You can pass a character string to the `load` function, so you can
send it through (over from) java as  you wich.
3. I don't think you really want to deal with load/save here, because
it looks like you are dealing with some tab delimited file -- in which
case use read.table (or similar) and load it that way. You can, of
course, still use save/load, but make sure you save/load the right
thing (not a file object like you're doing here).

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] sem error "no variance or error-variance parameter"

2010-05-18 Thread Jan Schubert

Hi,
I am sorry to post the message again but I really need some advise on that.
I am using the R version 2.11.0 and the version of sem package: sem_0.9-20
under Windows XP.
I read the questions:
http://r.789695.n4.nabble.com/computationally-singular-and-lack-of-variance-parameters-in-SEM-td891081.html#a891082

and

http://r.789695.n4.nabble.com/computationally-singular-and-lack-of-variance-parameters-in-SEM-td891081.html#a891081

but it does not seem to be my problem. I try to replicate the sem model (see
the attacheted image) but i got stuck with the problem while computing the
estimates of the model:
The error message:

Error in nlm(if (analytic.gradient) objective.2 else objective.1, start,  :
  probable coding error in analytic gradient
In addition: Warning message:
In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names =
vars,  :
  The following variables have no variance or error-variance parameter
(double-headed arrow):
 Fugural1
The model is almost surely misspecified; check also for missing covariances.

Here is my script:

cov.matrix <-
matrix(c(56.21,0,0,0,0,0,0,0,0,31.55,75.55,0,0,0,0,0,0,0,23.27,28.30,44.45,0,0,0,0,0,0,24.48,32.24,22.56,84.64,0,0,0,0,0,22.51,29.54,20.61,57.61,78.93,0,0,0,0,22.65,27.56,15.33,53.57,49.27,73.76,0,0,0,33.24,46.49,31.44,67.81,54.76,54.58,141.77,0,0,32.56,40.37,25.58,55.82,55.33,47.74,98.62,117.33,0,30.32,40.44,27.69,54.78,53.44,59.52,96.95,84.87,106.35),nrow=9,ncol=9,byrow=FALSE)
rownames(cov.matrix) <- colnames(cov.matrix) <-
c("IND1","IND2","IND3","FR11","FR12","FR13","FR21","FR22","FR23")

# options(nlm=(check.analyticals = TRUE)); I tried to set the nlm on
different option, but did not work either

m1 <- specify.model()
Induction -> IND1, NA, 1
Induction -> IND2, y2, NA
Induction -> IND3, y3, NA
Fugural1 -> FR11, NA, 1
Figural1 -> FR12, y5, NA
Figural1 -> FR13, y6, NA
Figural2 -> FR21, NA, 1
Figural2 -> FR22, y8, NA
Figural2 -> FR23, y9, NA
Induction -> Figural1, x1, NA
Figural1 -> Figural2,x2, NA
Induction -> Figural2, x3, NA
IND1 <-> IND1, e1, NA
IND2 <-> IND2, e2, NA
IND3 <-> IND3, e3, NA
FR11 <-> FR11, e4, NA
FR12 <-> FR12, e5, NA
FR13 <-> FR13, e6, NA
FR21 <-> FR21,e7, NA
FR22 <-> FR22, e8, NA
FR23 <-> FR23, e9, NA
Figural1 <-> Figural1, e10, NA
Figural2 <-> Figural2, e11, NA
Induction <-> Induction, NA, 1

sem1 <- sem(m1,cov.matrix,N=220,debug=T)

# I added the Induction <-> Induction, NA, 1 fixed parametr after reading
the help from John Fox, that every variable should have an error variance


Can anybody please advise me what I am doing wrong?
Many thanks!

Jan Schubert
Institute of Social Science
Charles University, Prague 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/sem-error-no-variance-or-error-variance-parameter-tp2221804p2221804.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] looking for .. dec if vector if element > x

2010-05-18 Thread Knut Krueger

Thank you Adrian,

its working fine.

Knut

__
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] GUI commands to call for a protein from protein data bank

2010-05-18 Thread Amitoj S. Chopra

I tried doing that and this is what I go:


dlg <- aDialog(items=list(
ProtienCode=stringItem("")
),
OK_handler=function(.) { # . is reference to dlg object
values <- .$to_R()
f <- function(ProtienCode)
pdb <- read.pdb(.$get_ProteinCode())
#cat("ProteinCode is",ProtienCode,"\n")
do.call(f, values)
}
)
dlg$make_gui()


with this error message

Error in function (ProtienCode)  : could not find function "read.pdb"

Do you know how to get rid of this error?

On Tue, May 18, 2010 at 5:53 AM, jverzaniNWBKZ [via R] <
ml-node+2221226-858152228-140...@n4.nabble.com
> wrote:

> Amitoj S. Chopra  gmail.com> writes:
>
> >
> >
> > What I am trying to do is use GUI function, traitr, and to call for a pdb
>
> > file and save it and then display it. I want to call for it by taking it
> > from the user and then displaying it on the screen. I am having problems
> > with that. The line pdb <- read.pdb(""ProteinCode) where proteincode
> should
> > be the name of the protein, for example 1ly2, but it always ends up being
>
> > protein. My question is how to you make the input for read.pdb actually
> be
> > the input by the user and not protein code. I want to be able to type
> 1ly2,
> > and for the program to actually display the contents of 1ly2. Thanks!
> >
>
> I'm just guessing, but you might try this for your OK_handler:
>
> OK_handler=function(.) {
>   pdb <- read.pdb(.$get_ProteinCode())
> }
>
> (Or use yours, but drop the quotes around "ProteinCode".)
>
> That doesn't modify pdb outside the scope of the handler, so likely you
> need to
> do something else with it.
>
> --John
>
>
> > Code:
> >
> > dlg <- aDialog(items=list(
> > ProteinCode=stringItem("")
> > ),
> > OK_handler=function(.) { # . is reference to dlg object
> > values <- .$to_R()
> > f <- function(ProteinCode)
> > pdb <- read.pdb("ProteinCode")
> > do.call(f, values)
> > }
> > )
> > dlg$make_gui()
>
> __
> [hidden email] 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.
>
>
> --
>  View message @
> http://r.789695.n4.nabble.com/GUI-commands-to-call-for-a-protein-from-protein-data-bank-tp2220754p2221226.html
> To unsubscribe from GUI commands to call for a protein from protein data
> bank, click here< (link removed) >.
>
>
>

-- 
View this message in context: 
http://r.789695.n4.nabble.com/GUI-commands-to-call-for-a-protein-from-protein-data-bank-tp2220754p2221749.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] Regarding the 'R' Load Command

2010-05-18 Thread Godavarthi, Murali
Hi,

 

I'm new to 'R' and need some help on the "Load" command. Any responses
will be highly appreciated. Thanks in advance!

 

As per manuals, the "Load" command expects a binary file input that is
saved using a "save" command. However it is required that we need to
call the 'R' program from 

Java web application using RJava, and pass a string to the 'R" program
instead of a binary file. Is it possible?

 

I was exploring the options of using TextConnections, file connections
and other types of connections in order to read a stream of input
(either from a file, stdin etc). I am able to read the string, but the
Save and Load commands are not accepting the string input. Here is the
sequence of commands I tried running, and the error received. There is
no clue on this error, especially when trying to use the eval function
in randomForest package, even on the internet. Can anyone help please!

 

 

 

> library(randomForest)

randomForest 4.5-34

Type rfNews() to see new features/changes/bug fixes.

 

> load("C://Program Files//R//R-2.10.1//bin//rfoutput")

 

> zz <- file("ex.data", "w")

 

> cat("\"imurder\" \"itheft\" \"irobbery\" \"iassault\" \"idrug\"
\"iburglary\" \"igun\" \"psych\" \"Freq\" \"priors\" \"firstage\"
\"intage\" \"sex\" \"race\" \"marstat\" \"empac\" 

\"educ\" \"zipcode\" \"suspendmn\" \"drugs\" \"alco\" \"probation\"
\"parole\"",file = zz, sep = "\n", fill = TRUE)

 

> cat("\"10\" 0 0 0 1 0 0 0 0 0 58 19 19 \"1\" \"BLACK\" \"SINGLE\"
\"UNEMPLD\" 0 21215 0 0 0 1 0",file = zz, sep = "\n", fill = TRUE)

 

> save(zz, file = "testmurali", version = 2)

 

> predict(rfoutput,newdata="testmurali",type="response")

Error in eval(expr, envir, enclos) : object 'imurder' not found

 

>  

 

Best Regards,

Murali Godavarthi

mgodavar...@dpscs.state.md.us

 

 

 

 

 


[[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] survey package: weights used in svycoxph()

2010-05-18 Thread Thomas Lumley

On Tue, 18 May 2010, Vinh Nguyen wrote:


Binder's estimating equations are the usual way of applying weights to a Cox
model, so nothing special is done apart from calling coxph(). To quote the
author of the survival package, Terry Therneau, "Other formulae change in
the obvious way, eg, the weighted mean $\bar Z$ is changed to include both
the risk weights $r$ and the external weights $w$." [Mayo Clinic
Biostatistics technical report #52, section 6.2.2]


Don't see a section 6.2.2 in this technical report.


Sorry, #58

   -thomas


Thomas Lumley   Assoc. Professor, Biostatistics
tlum...@u.washington.eduUniversity of Washington, Seattle

__
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] Getting dates in an SPSS file in right format.

2010-05-18 Thread Frank E Harrell Jr

On 05/18/2010 11:52 AM, Chuck Cleland wrote:

On 5/18/2010 12:38 PM, Praveen Surendran wrote:

Dear all,



I am trying to read an SPSS file into a data frame in R using method
read.spss(),

sample<- read.spss(file.name,to.data.frame=TRUE)



But dates in the data.frame 'sample' are coming as integers and not in the
actual date format given in the SPSS file.

Appreciate if anyone can help me to solve this problem.


   Date variables in SPSS contain the number of seconds since
October 14, 1582.  You might try something like this:

sample$MYDATE<- as.Date(as.POSIXct(sample$MYDATE, origin="1582-10-14",
tz="GMT"))


Kind Regards,



Praveen Surendran

2G, Complex and Adaptive Systems Laboratory (UCD CASL)

School of Medicine and Medical Sciences

University College Dublin

Belfield, Dublin 4

Ireland.



Office : +353-(0)1716 5334

Mobile : +353-(0)8793 13071



The spss.get function in the Hmisc package handles SPSS dates.
Frank

--
Frank E Harrell Jr   Professor and ChairmanSchool of Medicine
 Department of Biostatistics   Vanderbilt 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] Maximization of quadratic forms

2010-05-18 Thread Russell Shinohara

Dear R Help,

I am trying to fit a nonlinear model for a mean function $\mu(Data_i, 
\beta)$ for a fixed covariance matrix where $\beta$ and $\mu$ are low- 
dimensional. More specifically, for fixed variance-covariance matrices  
$\Sigma_{z=0}$ and $\Sigma_{z=1}$ (according to a binary covariate $Z 
$), I am trying to minimize:


$\sum_{i=1^n} (Y_i-\mu_(Data_i,\beta))' \Sigma_{z=z_i}^{-1} (Y_i- 
\mu_(Data_i,\beta))$


in terms of the parameter $\beta$. Is there a way to do this in R in a  
more stable and efficient fashion than just using a general  
optimization function such as optim? I have tried to use gnls, but I  
was unsuccessful in specifying different values of the covariance  
matrix according to the covariate $Z$.


Thank you very much for your help,
Taki Shinohara





Russell Shinohara, MSc
PhD Candidate and NIH Fellow
Department of Biostatistics
Bloomberg School of Public Health
The Johns Hopkins University
615 N. Wolfe St., Suite E3033
Baltimore, MD 21205
tel: (203) 499-8480
http://biostat.jhsph.edu/~rshinoha

__
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] C function call in R

2010-05-18 Thread Dan Davison
John Lande  writes:

> dear all,
>
> we am trying to improve the performance of my R code, with the implentation
> of some function with custom C code.
> we found difficult to import and export/import data structure such us
> matrices or data.frame into the external C functions.

Please give a *very simple* example of what you're trying and failing to
do.

Use the .C() interface, forget about the .Call interface. Then it is not
that hard. Start with the convolve example on p.69 and 70 of Writing R
Extensions. Get that working and then turn it into your problem.

Forget about lists and data frames: everything is going to be a simple
vector. That includes arrays and matrices: you can pass them in, but C
will know nothing about their dimensions until you tell it. Of course,
you can pass the dimension vectors in as a separate vector. So, if you
use arrays, you need to understand the order in which R stores the
elements of the array. If your problem cannot be solved with the .C
interface then you should consider whether it is worthwhile to proceed
as the .Call interface repays those who use it frequently but has a
considerably steeper learning (and forgetting) curve.

Dan


>
> we already tried the solution from "Writing R Extensions" form  the R
> webpage.
>
> do you have any other solution or more advanced documentation on that point?
>
> looking forward your answer
>
>   [[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] Res: Using the zero-inflated binomial in experimental designs

2010-05-18 Thread Ivan Allaman

Hi Ben!

First I thank you for your attention. Unfortunately, the ANOVA does not work 
with vglm. In
another email, Rafael warned me that actually a lot of zeros does not
necessarily imply a distribution of zeros binomail inflated. So how could I 
test if my variable is or not a binomial zero inflated?

Thanks.

 
M.Sc Ivan Bezerra Allaman 
Zootecnista
Doutorando em Produção Animal/Aquicultura - UFLA 
email e msn - ivanala...@yahoo.com.br 
Tel: (35)3826-6608/9925-6428





De: Ben Bolker [via R] 

Enviadas: Terça-feira, 18 de Maio de 2010 13:34:01
Assunto: Re: Using the zero-inflated binomial in experimental designs

 Ivan Allaman  yahoo.com.br> writes: 


> 
> 
> I'm trying to use the inflated binomial distribution of zeros (since 75% of 
> the values are zeros) in a randomized block experiment with four 
> quantitative treatments (0, 0.5, 1, 1.5), but I'm finding it difficult, 
> since the examples available in VGAM packages like for example, leave us
> unsure of how it should be the data.frame for such analysis. Unfortunately 
> the function glm does not have an option to place a family of this kind I'm 
> about, because if I had, it would be easy, made that my goal is simple, just 
> wanting to compare the treatments. For that you have an idea, here is an
> example of my database. 
> 
> BLOCK NIVNT   MUMI 
> Inicial   0  18 0 
[snip] 

> 
> where: NIV are the treatments; NT is the total number of piglets born; Mumi 
> is the number of mummified piglets NT. Mumi The variable is of interest. If 
> someone can tell me some stuff on how I can do these tests in R, similar to 
> what I would do using the function glm, I'd be grateful. 
> I thank everyone's attention. 

something like comparing the likelihoods of 

m1 <- vglm(cbind(MUMI,NT-MUMI)~NIV*BLOCK,zibinomial,data=mydata) 
m2 <- vglm(cbind(MUMI,NT-MUMI)~NIV+BLOCK,zibinomial,data=mydata) 
m3 <- vglm(cbind(MUMI,NT-MUMI)~BLOCK,zibinomial,data=mydata) 

I don't know whether the anova() method works for VGLM objects 
or not. 

  By the way, 75% zeroes doesn't necessarily imply zero-inflation -- 
perhaps it just means a low incidence? 

__ 
[hidden email] 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. 




View message @ 
http://r.789695.n4.nabble.com/Using-the-zero-inflated-binomial-in-experimental-designs-tp2221254p2221578.html
 
To unsubscribe from Using the zero-inflated binomial in experimental designs, 
click here. 




-- 
View this message in context: 
http://r.789695.n4.nabble.com/Using-the-zero-inflated-binomial-in-experimental-designs-tp2221254p2221635.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] Glasso question

2010-05-18 Thread daysixty

The "glassolist" function says that if rholist is set to NULL, then "10
values in a (hopefully reasonable) range are used". I'm trying to figure out
how these 10 values are chosen, I can't find this in any documentation.
Thanks for your help!
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Glasso-question-tp2221587p2221587.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] (no subject)

2010-05-18 Thread David Winsemius


On May 18, 2010, at 12:07 PM, Arantzazu Blanco Bernardeau wrote:



Hello
Well, the problem is, that arcilla is the percentage of clay in the  
soil sample. So, for linear model, I need to work with that number  
or value. Now, R thinks that arcilla (arcilla means clay in  
spanish), is a factor, and gives me the value as a factor, so the  
output of the linear model is

Call:
lm(formula = formula, data = caperf)


Would help if you also displayed the value for "formula", so we might  
have an idea what you are calling your "y"-variable   and it would  
be wise not to continue to name your formulas "formula."


require(fortunes)
fortune("dog")

What happens when you create a new variable in caperf with the numeric  
equivalant of the arcilla levels?


caperf$claynum <- as.numeric(as.character(arcilla))

lm(y ~ claynum + limo + CO_gkg1 + C03Ca  , data=caperf)

--
David.




Residuals:
   Min 1Q Median 3QMax
-1.466e+01 -1.376e-15  1.780e-16  2.038e-15  1.279e+01

Coefficients:
  Estimate Std. Error t value Pr(>|t|)
(Intercept)1.689646.33889   0.267 0.790221
arcilla0.9 1.902288.90888   0.214 0.831239
arcilla10  1.263717.96734   0.159 0.874212
arcilla10.3   15.700819.05141   1.735 0.085090 .
arcilla10.47.275177.72806   0.941 0.348183
arcilla10.45   7.038799.02600   0.780 0.436853
arcilla10.52.412418.90827   0.271 0.786954
arcilla10.65  15.442989.03879   1.709 0.089838 .
arcilla10.7   19.356519.04675   2.140 0.034185 *
arcilla10.93.559479.18501   0.388 0.698974

[...]

arcilla9.9 6.319497.35724   0.859 0.391892
arcilla#N/A   24.179598.87201   2.725 0.007274 **
limo   0.249200.04605   5.412 2.76e-07 ***
CO_gkg10.210150.03931   5.346 3.73e-07 ***
C03Ca  0.017110.02727   0.628 0.531337
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 6.249 on 135 degrees of freedom
  (50 observations deleted due to missingness)
Multiple R-squared: 0.9736,Adjusted R-squared: 0.9014
F-statistic: 13.47 on 370 and 135 DF,  p-value: < 2.2e-16

So, in the desired linear model, arcilla should be just a line, with  
the valors of the linear model.
I hope you understand better more. If not, I could make an english  
version of the file to send, so you can try the commands.

Thanks a lot for your help!



Arantzazu Blanco Bernardeau
Dpto de Química Agrícola, Geología y Edafología
Universidad de Murcia-Campus de Espinardo











Date: Tue, 18 May 2010 11:54:20 -0400
Subject: Re: [R] (no subject)
From: mailinglist.honey...@gmail.com
To: aramu...@hotmail.com
CC: r-help@r-project.org

Hi,

Sorry, I'm not really getting what going on here ... perhaps having
more domain knowledge would help me make better sense of our  
question.


In particular:

On Tue, May 18, 2010 at 11:35 AM, Arantzazu Blanco Bernardeau
wrote:


Hello
I have a data array with soil variables (caperf), in which the  
variable "clay" is factor (as I see entering str(caperf)) . I need  
to do a regression model, so I need to have arcilla (=clay) as a  
numeric variable.  For that I have entered


as.numeric(as.character(arcilla))

and even entering
'as.numeric(levels(arcilla))[arcilla]'


The above code doesn't make sense to me ...

Perhaps cleaning up your question and providing some reproducible
example we can use to help show you the light (just describing what a
variable has isn't enough -- give us minimal code we can paste into R
that reproduces your problem).

Alternatively, depending no what your "levels" mean, you might want  
to

recode your data using "dummy variables" (I'm not sure if that's the
official term) .. this is what I mean:

http://dss.princeton.edu/online_help/analysis/dummy_variables.htm

In your example, let's say you have four levels for "clay" ... maybe
"soft", "hard", "smooth", "red"

Instead of only using 1 variable with values 1-4, you would recode
this into 4 variables with values 0,1

So, if one example has a value of "smooth" for clay. Instead of  
coding it like:

clay: 3

You would do:
soft: 0
hard: 0
smooth: 1
red : 0

-steve
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact


_
Consejos para seducir ¿Puedes conocer gente nueva a través de  
Internet? ¡Regístrate ya!


__
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

Re: [R] Sweave counter

2010-05-18 Thread Benno Pütz
Under UNIX I usually write something like

system(paste("echo '",...,"'", sep=sep))

where I replace the '...' with whatever I need to show.


This would need some adjustments for non-scalars, though.

Benno

Am 18.Mai.2010 um 19:10 schrieb Jimmy Söderly:

> Dear R users,
> 
> I am using the Sweave package and I am doing some MCMC. I have a loop
> function for my MCMC. Every 100 iterations, I want the number of iterations
> already done to appear on my screen (but not on the final document). Is that
> possible ?
> 
> Usually I can rely on
> 
>> if (i%%100==0) cat(i, "\n")
> 
> but not when using Sweave.
> 
> Thanks for your help,
> Jimmy
> 
>   [[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] Sweave counter

2010-05-18 Thread Ista Zahn
Hi Jimmy,
You can use message() instead of cat():

if (i%%100==0) message(i)

Best,
Ista

On Tuesday 18 May 2010 1:10:51 pm Jimmy Söderly wrote:
> Dear R users,
> 
> I am using the Sweave package and I am doing some MCMC. I have a loop
> function for my MCMC. Every 100 iterations, I want the number of iterations
> already done to appear on my screen (but not on the final document). Is
> that possible ?
> 
> Usually I can rely on
> 
> > if (i%%100==0) cat(i, "\n")
> 
> but not when using Sweave.
> 
> Thanks for your help,
> Jimmy
> 
>   [[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] unsigned 4 byte number

2010-05-18 Thread William Dunlap
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of tetonedge
> Sent: Tuesday, May 18, 2010 9:14 AM
> To: r-help@r-project.org
> Subject: [R] unsigned 4 byte number
> 
> 
> Does anybody know how to read in a unsigned 4 byte number 
> from a binary file?
> According to the help for readBin, the signed argument only applies to
> size=1 or 2. But if you declare any size larger it assumes it 
> is signed?

R cannot properly represent unsigned 4 byte C ints with its
type "integer" (which is a 4 byte signed C int).  It can store
them as doubles with the desired values.

You can use readBin to read them as signed 4 byte C ints, stored
in R "integers",  with

i <- readBin(file, what="integer", size=4)

and then convert them to doubles with the following function

unsignedFourByteIntToDouble <- function(i) {
   d <- as.numeric(i)
   d[d<0] <- d[d<0] + 2^32
   d
}

If you had S+ you could do this in one step using readBin's
output="double" argument.   In S+'s readBin(), output=type
means to override the default mapping of C types to S+ types.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> Thanks
> -- 
> View this message in context: 
> http://r.789695.n4.nabble.com/unsigned-4-byte-number-tp2221555
p2221555.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] proportion of treatment effect by a surrogate (fitting multivariate survival model)

2010-05-18 Thread Vinh Nguyen
On Mon, May 17, 2010 at 7:42 PM, Vinh Nguyen  wrote:
> Dear R-help,
>
> I would like to compute the variance for the proportion of treatment
> effect by a surrogate in a survival model (Lin, Fleming, and De
> Gruttola 1997 in Statistics in Medicine).  The paper mentioned that
> the covariance matrix matches that of the covariance matrix estimator
> for the marginal hazard modelling of multiple events data (Wei, Lin,
> and Weissfeld 1989 JASA), and is implemented in Lin's MULCOX2, SAS,
> and S-plus.
>
> Is this the way to fit such a model in R?
> Suppose I have variables: time, delta, treatment, and surrogate.
>
> Should I repeat the dataset (2x) and stack, creating the variables:
> time1 (time repeated 2x), delta1 (delta repeated 2x), treatment1 (same
> as treatment, but 0's for the 2nd set), treatment2 (0's in first set,
> then same as treatment), and surrogate2 (0's in first set, then same
> as treatment), and id (label the subject, so each id should have 2
> observations).
>
> Thus, a dataset with n observations will become 2n observations.  To fit, do
> fit <- coxph(Surv(time1,delta1) ~ treatment1 + teatment2 + surrogate2
> + strata(id)
> ?
>

I think I figured it out.  I should use m <- rep(0:1, each=n) for
strata.  The point estimates matches that of the adjust and unadjusted
models when fitting separately (jointly fit to obtain covariances).

Thank you and let me know if I've done anything wrong.

> From here, I can obtain the variance and covariance terms for the
> coefficients of treatment1 and treatment2.  Is this the same as
> fitting 2 separate models but also obtaining the covariances of the
> two estimates?
>
> Let me know, thanks.
>
> Vinh

__
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] Sweave counter

2010-05-18 Thread Jimmy Söderly
Dear R users,

I am using the Sweave package and I am doing some MCMC. I have a loop
function for my MCMC. Every 100 iterations, I want the number of iterations
already done to appear on my screen (but not on the final document). Is that
possible ?

Usually I can rely on

> if (i%%100==0) cat(i, "\n")

but not when using Sweave.

Thanks for your help,
Jimmy

[[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] avoiding reinstall already installed *package*

2010-05-18 Thread Ted Harding
On 18-May-10 16:42:40, Peter Ehlers wrote:
> On 2010-05-18 10:05, (Ted Harding) wrote:
>> On 18-May-10 15:49:37, Martin Maechler wrote:
>>> { I've modified the subject; I can't stand it hitting square into
>>>my face ... }
 "mr" == milton ruser
  on Tue, 18 May 2010 12:36:23 -0300 writes:
>>>  mr>  Dear R-experts,
>>>  mr>  I am installing new libraries using
>>>  mr>  install.packages("ggplot2",dependencies=T).
>>>  mr>  But I perceive that many dependencies are already
>>>  installed.
>>>  mr>  As I am using a low-band internet, how can avoid reinstall
>>>  mr>  installed libraries?
>>>
>>> There's no problem with installed libraries, as ...
>>> they DO NOT EXIST.
>>>
>>> These are *PACKAGES* !
>>> Why do you think are you talking about the function
>>>
>>>   install.packages()  
>>>   
>>
>> Ah, Martin! I know that "package" is the official terminology,
>> but R itself tempts the naive user into deviating from the
>> True Path. Indeed, I had my fingers burned by this myself,
>> a long time ago (I'm still licking them ... ).
>>
>> One might ask: "Why do you think we use the function library()?"
>> when loading add-on packages into R. Indeed, the very directory
>> tree of R itself stores packages under /usr/lib/R/library.
>>
>> So, once in a while, someone gets it wrong, and has to find it
>> out the hard way!
> 
> Well, I don't know if I've ever disagreed with Ted before,
> but here I would (somewhat) disagree. It seems a bit odd that
> nobody confuses 'book' with 'library', yet the package/library
> problem is persistent. It may have something to do with the
> use of 'library' in other computer languages.
> 
> Anyway, not long ago there was a suggestion (Rolf Turner's?)
> to rename the library() function to something like use(),
> but, as I recall, a number of nontrivial objections were
> raised.
> 
> Of course R stores packages in libraries. That's were books
> *should* reside. And it's a good idea to have Martin remind
> us now and again that books themselves are not libraries.
> 
> But I must confess that I'm no longer much bothered by the
> misuse. If it ever leads someone astray in their code, then,
> well, they have only themselves to blame.
> 
> Cheers,
> Peter Ehlers

Well, I don't think you're disagreeing with me, Peter!
My point (which you're not disputing) is that the naive user
will think "library" because of using the function library().
Perhaps my remark about /usr/lib/R/library was a bit superfluous
(and indeed that path supports your "book" vs "library" point).
Nevertheless, it would still reinforce users who think "library".

I suppose, to take your analogy, the semantics of, say,
library(Hmisc) could be spelled out as "Go to the library
and take out the book called Hmisc". On the other hand, the
naive user will tend to read it as "get library Hmisc".

While "library" is conspicuous to all users because of the
function, the fact that packages should be called packages does
not jump out into your face (until someone on the list does).

That said, I again agree with you that I'm not much bothered
by the question. I see it as one of the various little things
in R which one happily learns (in the end ... ) to live with!

Best wishes,
Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 18-May-10   Time: 18:03:45
-- XFMail --

__
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] Function that is giving me a headache- any help appreciated (automatic read )

2010-05-18 Thread John Kane

I don't think you can do this
precipitation!="NA")

have a look at ?is.na

--- On Tue, 5/18/10, stephen sefick  wrote:

> From: stephen sefick 
> Subject: [R] Function that is giving me a headache- any help appreciated 
> (automatic read )
> To: r-help@r-project.org
> Received: Tuesday, May 18, 2010, 12:38 PM
> note: whole function is below- I am
> sure I am doing something silly.
> 
> when I use it like USGS(input="precipitation") it is
> choking on the
> 
> 
> precip.1 <- subset(DF, precipitation!="NA")
> b <- ddply(precip.1$precipitation,
> .(precip.1$gauge_name), cumsum)
> DF.precip <- precip.1
> DF.precip$precipitation <- b$.data
> 
> part, but runs fine outside of the function:
> 
> days=7
> input="precipitation"
> require(chron)
> require(gsubfn)
> require(ggplot2)
> require(plyr)
> #021973269 is the Waynesboro Gauge on the Savannah River
> Proper (SRS)
> #02102908 is the Flat Creek Gauge (ftbrfcms)
> #02133500 is the Drowning Creek (ftbrbmcm)
> #02341800 is the Upatoi Creek Near Columbus (ftbn)
> #02342500 is the Uchee Creek Near Fort Mitchell (ftbn)
> #02203000 is the Canoochee River Near Claxton (ftst)
> #02196690 is the Horse Creek Gauge at Clearwater, S.C.
> 
> a <- "http://waterdata.usgs.gov/nwis/uv?format=rdb&period=";
> b <-
> "&site_no=021973269,02102908,02133500,02341800,02342500,02203000,02196690"
> z <- paste(a, days, b, sep="")
> L <- readLines(z)
> 
> #look for the data with USGS in front of it (this take
> advantage of
> #the agency column)
> L.USGS <- grep("^USGS", L, value = TRUE)
> DF <- read.table(textConnection(L.USGS), fill = TRUE)
> colnames(DF) <- c("agency", "gauge", "date", "time",
> "time_zone",
> "gauge_height",
> "discharge", "precipitation")
> pat <- "^# +USGS +([0-9]+) +(.*)"
> L.DD <- grep(pat, L, value = TRUE)
> library(gsubfn)
> DD <- strapply(L.DD, pat, c, simplify = rbind)
> DDdf <- data.frame(gauge = as.numeric(DD[,1]),
> gauge_name = DD[,2])
> both <- merge(DF, DDdf, by = "gauge", all.x = TRUE)
> 
> dts <- as.character(both[,"date"])
> tms <- as.character(both[,"time"])
> date_time <- as.chron(paste(dts, tms), "%Y-%m-%d
> %H:%M")
> DF <- data.frame(Date=as.POSIXct(date_time), both)
> #change precip to numeric
> DF[,"precipitation"] <-
> as.numeric(as.character(DF[,"precipitation"]))
> 
> precip.1 <- subset(DF, precipitation!="NA")
> b <- ddply(precip.1$precipitation,
> .(precip.1$gauge_name), cumsum)
> DF.precip <- precip.1
> DF.precip$precipitation <- b$.data
> 
> #discharge
> if(input=="data"){
> 
> return(DF)
> 
> }else{
> 
> qplot(Date, discharge, data=DF,
> geom="line", ylab="Date")+facet_wrap(~gauge_name,
> scales="free_y")+coord_trans(y="log10")}
> 
> if(input=="precipitation"){
> #precipitation
> qplot(Date, precipitation, data=DF.precip,
> geom="line")+facet_wrap(~gauge_name, scales="free_y")
> 
> }else{
> 
> qplot(Date, discharge, data=DF,
> geom="line", ylab="Date")+facet_wrap(~gauge_name,
> scales="free_y")+coord_trans(y="log10")}
> 
> below is the whole function:
> 
> USGS <- function(input="discharge", days=7){
> require(chron)
> require(gsubfn)
> require(ggplot2)
> require(plyr)
> #021973269 is the Waynesboro Gauge on the Savannah River
> Proper (SRS)
> #02102908 is the Flat Creek Gauge (ftbrfcms)
> #02133500 is the Drowning Creek (ftbrbmcm)
> #02341800 is the Upatoi Creek Near Columbus (ftbn)
> #02342500 is the Uchee Creek Near Fort Mitchell (ftbn)
> #02203000 is the Canoochee River Near Claxton (ftst)
> #02196690 is the Horse Creek Gauge at Clearwater, S.C.
> 
> a <- "http://waterdata.usgs.gov/nwis/uv?format=rdb&period=";
> b <-
> "&site_no=021973269,02102908,02133500,02341800,02342500,02203000,02196690"
> z <- paste(a, days, b, sep="")
> L <- readLines(z)
> 
> #look for the data with USGS in front of it (this take
> advantage of
> #the agency column)
> L.USGS <- grep("^USGS", L, value = TRUE)
> DF <- read.table(textConnection(L.USGS), fill = TRUE)
> colnames(DF) <- c("agency", "gauge", "date", "time",
> "time_zone",
> "gauge_height",
> "discharge", "precipitation")
> pat <- "^# +USGS +([0-9]+) +(.*)"
> L.DD <- grep(pat, L, value = TRUE)
> library(gsubfn)
> DD <- strapply(L.DD, pat, c, simplify = rbind)
> DDdf <- data.frame(gauge = as.numeric(DD[,1]),
> gauge_name = DD[,2])
> both <- merge(DF, DDdf, by = "gauge", all.x = TRUE)
> 
> dts <- as.character(both[,"date"])
> tms <- as.character(both[,"time"])
> date_time <- as.chron(paste(dts, tms), "%Y-%m-%d
> %H:%M")
> DF <- data.frame(Date=as.POSIXct(date_time), both)
> #change precip to numeric
> DF[,"precipitation"] <-
> as.numeric(as.character(DF[,"precipitation"]))
> 
> precip.1 <- subset(DF, precipitation!="NA")
> b <- ddply(precip.1$precipitation,
> .(precip.1$gauge_name), cumsum)
> DF.precip <- precip.1
> DF.precip$precipitation <- b$.data
> 
> #discharge
> if(input=="data"){
> 
> return(DF)
> 
> }else{
> 
> qplot(Date, discharge, data=DF,
> geom="line", ylab="Date")+facet_wrap(~gauge_name,
> scales="free_y")+coord_trans(y="log10")}
> 
> if(input=="precipitation"){
> #precipitation
> qplot(Da

Re: [R] Getting dates in an SPSS file in right format.

2010-05-18 Thread Chuck Cleland
On 5/18/2010 12:38 PM, Praveen Surendran wrote:
> Dear all,
> 
>  
> 
> I am trying to read an SPSS file into a data frame in R using method
> read.spss(),
> 
> sample <- read.spss(file.name,to.data.frame=TRUE)
> 
>  
> 
> But dates in the data.frame 'sample' are coming as integers and not in the
> actual date format given in the SPSS file.
> 
> Appreciate if anyone can help me to solve this problem.

  Date variables in SPSS contain the number of seconds since
October 14, 1582.  You might try something like this:

sample$MYDATE <- as.Date(as.POSIXct(sample$MYDATE, origin="1582-10-14",
tz="GMT"))

> Kind Regards,
> 
>  
> 
> Praveen Surendran
> 
> 2G, Complex and Adaptive Systems Laboratory (UCD CASL)
> 
> School of Medicine and Medical Sciences
> 
> University College Dublin
> 
> Belfield, Dublin 4
> 
> Ireland.
> 
>  
> 
> Office : +353-(0)1716 5334
> 
> Mobile : +353-(0)8793 13071
> 
>  
> 
> 
>   [[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.

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
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] survey package: weights used in svycoxph()

2010-05-18 Thread Vinh Nguyen
On Tue, May 18, 2010 at 8:50 AM, Thomas Lumley  wrote:
>
>  > I
>>
>> don't believe so since svycoxph() calls coxph() of the survival
>> package and weights are applied once in the estimating equation.  If
>> the weights are implemented in the ratio, could you point me to where
>> in the code this is done?  I would like to estimate as in Binder but
>> with custom weights.  Thanks.
>
> It happens inside the C code called by coxph(), eg, in
> survival/src/coxfit2.c
>

Thank you for your clarification.  I mistakenly assumed weights only
appeared once in the estimating equation, creating a weighted sum of
the score equation.  Thinking in retrospect if the weights are to be
used as case weights they better be in the ratio term as well
(wherever there is an at risk indicator).

> Binder's estimating equations are the usual way of applying weights to a Cox
> model, so nothing special is done apart from calling coxph(). To quote the
> author of the survival package, Terry Therneau, "Other formulae change in
> the obvious way, eg, the weighted mean $\bar Z$ is changed to include both
> the risk weights $r$ and the external weights $w$." [Mayo Clinic
> Biostatistics technical report #52, section 6.2.2]

Don't see a section 6.2.2 in this technical report.

__
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] avoiding reinstall already installed *package*

2010-05-18 Thread Peter Ehlers

On 2010-05-18 10:05, (Ted Harding) wrote:

On 18-May-10 15:49:37, Martin Maechler wrote:

{ I've modified the subject; I can't stand it hitting square into
   my face ... }

"mr" == milton ruser
 on Tue, 18 May 2010 12:36:23 -0300 writes:

 mr>  Dear R-experts,
 mr>  I am installing new libraries using
 mr>  install.packages("ggplot2",dependencies=T).
 mr>  But I perceive that many dependencies are already installed.
 mr>  As I am using a low-band internet, how can avoid reinstall
 mr>  installed libraries?

There's no problem with installed libraries, as ...
they DO NOT EXIST.

These are *PACKAGES* !
Why do you think are you talking about the function

  install.packages()  
  


Ah, Martin! I know that "package" is the official terminology,
but R itself tempts the naive user into deviating from the
True Path. Indeed, I had my fingers burned by this myself,
a long time ago (I'm still licking them ... ).

One might ask: "Why do you think we use the function library()?"
when loading add-on packages into R. Indeed, the very directory
tree of R itself stores packages under /usr/lib/R/library.

So, once in a while, someone gets it wrong, and has to find it
out the hard way!


Well, I don't know if I've ever disagreed with Ted before,
but here I would (somewhat) disagree. It seems a bit odd that
nobody confuses 'book' with 'library', yet the package/library
problem is persistent. It may have something to do with the
use of 'library' in other computer languages.

Anyway, not long ago there was a suggestion (Rolf Turner's?)
to rename the library() function to something like use(),
but, as I recall, a number of nontrivial objections were
raised.

Of course R stores packages in libraries. That's were books
*should* reside. And it's a good idea to have Martin remind
us now and again that books themselves are not libraries.

But I must confess that I'm no longer much bothered by the
misuse. If it ever leads someone astray in their code, then,
well, they have only themselves to blame.

Cheers,
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.


[R] Getting dates in an SPSS file in right format.

2010-05-18 Thread Praveen Surendran
Dear all,

 

I am trying to read an SPSS file into a data frame in R using method
read.spss(),

sample <- read.spss(file.name,to.data.frame=TRUE)

 

But dates in the data.frame 'sample' are coming as integers and not in the
actual date format given in the SPSS file.

Appreciate if anyone can help me to solve this problem.

 

Kind Regards,

 

Praveen Surendran

2G, Complex and Adaptive Systems Laboratory (UCD CASL)

School of Medicine and Medical Sciences

University College Dublin

Belfield, Dublin 4

Ireland.

 

Office : +353-(0)1716 5334

Mobile : +353-(0)8793 13071

 


[[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] FW: "Re: Change class factor to numeric"

2010-05-18 Thread Arantzazu Blanco Bernardeau

Hello everybody
the problem has been solved. It was my mistake not to be ensured that any N/A 
had dissapeared. I do apologize for the inconveniences caused ;)
friendly greeting sfrom Spain! 



Arantzazu Blanco Bernardeau
Dpto de Química Agrícola, Geología y Edafología
Universidad de Murcia-Campus de Espinardo










> From: aramu...@hotmail.com
> To: ivan.calan...@uni-hamburg.de
> Subject: RE: [R] "Re: Change class factor to numeric"
> Date: Tue, 18 May 2010 16:36:55 +
>
>
> Hallo Ivan
> I do thank you a lot, but as you have read in the last email, I did think 
> that maybe one erroneus typing was indicating R to take it as a factor. I did 
> look again the original dataframe and did find the mistake, and now it works 
> OK. Sorry, but I had done so many reviews of the data frame, that did not 
> think on it before.
> Schon wieder danke schön, und freundliche Grüsse aus Spanien ;)
>
>
>
>
> Arantzazu Blanco Bernardeau
> Dpto de Química Agrícola, Geología y Edafología
> Universidad de Murcia-Campus de Espinardo
>
>
>
>
>
>
>
>
>
> 
>> Date: Tue, 18 May 2010 18:28:45 +0200
>> From: ivan.calan...@uni-hamburg.de
>> To: aramu...@hotmail.com
>> Subject: Re: [R] "Re: Change class factor to numeric"
>>
>> As you can notice, I'm writing off list for you to send me your data (as
>> csv).
>> But do it fast, I'll be leaving soon. If not it might have to wait until
>> tomorrow!
>>
>> In any case, I'm no expert, so I'm not sure I'll be able to help you.
>> And I don't think NAs should be problematic. It might be solved by some
>> arguments into the read.table() call.
>>
>> Can you also send me the line of code you used to import your csv?
>>
>> Ivan
>>
>> Le 5/18/2010 18:25, Arantzazu Blanco Bernardeau a écrit :
>>>
>>> Hi again!
>>> could it be that NA was introduced in the variable for not available 
>>> values, and being NA a character, it takes everything as factor??
>>> is the only idea I have, because it is the first time I have this problem
>>> Thanks a lot, I am really learning! :)
>>>
>>>
>>> Arantzazu Blanco Bernardeau
>>> Dpto de Química Agrícola, Geología y Edafología
>>> Universidad de Murcia-Campus de Espinardo
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> 
>>>
 Date: Tue, 18 May 2010 18:17:02 +0200
 From: ivan.calan...@uni-hamburg.de
 To: r-help@r-project.org
 Subject: Re: [R] "Re: Change class factor to numeric"

 Hi again,

 If you used the function read.table() to read from a csv file into a
 data.frame, it is weird that numeric data are converted into factors.
 I would check in the original data that you don't have a typo somewhere.
 I don't know all the possibilities, but a special character can
 definitely make R interpret this variable differently.

 For Drenaje, it is normal. In that case you can just use:
 caperf$Drenaje<- factor(caperf$Drenaje)

 HTH
 Ivan

 Le 5/18/2010 17:59, Arantzazu Blanco Bernardeau a écrit :

> Hello
> so, here you have the output of the data frame. The data frame comes from 
> a csv file.
> I could take Gr_2 instead of arcilla, because it is the same value... but 
> curiously, it is a factor as well.
>
>
>> str(caperf)
>>
>>
> 'data.frame': 556 obs. of 38 variables:
> $ Hoja : int 818 818 818 818 818 818 818 818 818 818 ...
> $ idmuestra : Factor w/ 555 levels "1015-I","1015-II",..: 26 27 28 29 31 
> 32 33 34 30 35 ...
> $ Año : int 1994 1994 1994 1994 1994 1994 1994 1994 1994 1994 ...
> $ x : int 655500 633050 632200 635000 637150 643700 655300 648000 653400 
> 646200 ...
> $ y : int 4285800 4283050 4298150 429 4294800 4288850 4282700 4290350 
> 4298450 4296650 ...
> $ CO_gkg1 : num 3.7 6.5 6.3 2.6 12.1 6.9 3.5 10.8 10.3 3.3 ...
> $ NTgkg_1 : num 0.53 1.01 0.66 0.42 1.3 0.82 0.43 1.31 0.85 0.51 ...
> $ C_Nratio : num 6.98 6.46 9.55 6.18 9.33 ...
> $ C03Ca : num 53.6 38 1.2 1.1 21.1 ...
> $ pHw : num 8 8.4 8.3 8.4 8.45 8.2 8.4 8.4 8.1 8.4 ...
> $ pHClK : num 7.5 7.4 7.2 7.4 8.3 7.5 7.8 7.4 7.4 7.5 ...
> $ CCC : num 9.7 14.4 10.5 7.2 12.8 ...
> $ CEdSm : num 0.62 0.72 0.38 0.36 19.35 ...
> $ pF1_3atm : num 25.4 21.3 9.1 12.8 24.1 ...
> $ pF15atm : num 15.3 10.6 5.8 6.1 8.45 11 3.7 18.8 10 14.3 ...
> $ Gr_2 : Factor w/ 391 levels "0","0.71","0.9",..: 200 31 158 36 142 60 
> 377 263 140 151 ...
> $ Gr2_20 : num 19.1 39.1 2.9 5.2 NA 12.5 5.7 29.5 17.3 10.5 ...
> $ Gr20_50 : num 17.6 9.8 4.7 4 NA 10.4 4.2 13.3 12.5 7.8 ...
> $ Gr50_100 : num 14.1 12.2 7.6 9 NA 9.1 6.1 8.5 9.1 18.9 ...
> $ Gr100_250 : num 13.4 17.1 28.7 46.2 NA 20.8 28.7 13.6 16.8 32.9 ...
> $ Gr250_500 : num 7.1 5.7 28.8 15.2 NA 24.7 23.4 3.8 11.4 6.9 ...
> $ Gr500_1000 : num 4 1.8 5 3.9 NA 4.2 14.3 0.9 8.9 2.1 ...
> $ Gr1000_2000 : num 1.4 2 1.9 4 NA 

[R] Function that is giving me a headache- any help appreciated (automatic read )

2010-05-18 Thread stephen sefick
note: whole function is below- I am sure I am doing something silly.

when I use it like USGS(input="precipitation") it is choking on the


precip.1 <- subset(DF, precipitation!="NA")
b <- ddply(precip.1$precipitation, .(precip.1$gauge_name), cumsum)
DF.precip <- precip.1
DF.precip$precipitation <- b$.data

part, but runs fine outside of the function:

days=7
input="precipitation"
require(chron)
require(gsubfn)
require(ggplot2)
require(plyr)
#021973269 is the Waynesboro Gauge on the Savannah River Proper (SRS)
#02102908 is the Flat Creek Gauge (ftbrfcms)
#02133500 is the Drowning Creek (ftbrbmcm)
#02341800 is the Upatoi Creek Near Columbus (ftbn)
#02342500 is the Uchee Creek Near Fort Mitchell (ftbn)
#02203000 is the Canoochee River Near Claxton (ftst)
#02196690 is the Horse Creek Gauge at Clearwater, S.C.

a <- "http://waterdata.usgs.gov/nwis/uv?format=rdb&period=";
b <- "&site_no=021973269,02102908,02133500,02341800,02342500,02203000,02196690"
z <- paste(a, days, b, sep="")
L <- readLines(z)

#look for the data with USGS in front of it (this take advantage of
#the agency column)
L.USGS <- grep("^USGS", L, value = TRUE)
DF <- read.table(textConnection(L.USGS), fill = TRUE)
colnames(DF) <- c("agency", "gauge", "date", "time", "time_zone",
"gauge_height",
"discharge", "precipitation")
pat <- "^# +USGS +([0-9]+) +(.*)"
L.DD <- grep(pat, L, value = TRUE)
library(gsubfn)
DD <- strapply(L.DD, pat, c, simplify = rbind)
DDdf <- data.frame(gauge = as.numeric(DD[,1]), gauge_name = DD[,2])
both <- merge(DF, DDdf, by = "gauge", all.x = TRUE)

dts <- as.character(both[,"date"])
tms <- as.character(both[,"time"])
date_time <- as.chron(paste(dts, tms), "%Y-%m-%d %H:%M")
DF <- data.frame(Date=as.POSIXct(date_time), both)
#change precip to numeric
DF[,"precipitation"] <- as.numeric(as.character(DF[,"precipitation"]))

precip.1 <- subset(DF, precipitation!="NA")
b <- ddply(precip.1$precipitation, .(precip.1$gauge_name), cumsum)
DF.precip <- precip.1
DF.precip$precipitation <- b$.data

#discharge
if(input=="data"){

return(DF)

}else{

qplot(Date, discharge, data=DF,
geom="line", ylab="Date")+facet_wrap(~gauge_name,
scales="free_y")+coord_trans(y="log10")}

if(input=="precipitation"){
#precipitation
qplot(Date, precipitation, data=DF.precip,
geom="line")+facet_wrap(~gauge_name, scales="free_y")

}else{

qplot(Date, discharge, data=DF,
geom="line", ylab="Date")+facet_wrap(~gauge_name,
scales="free_y")+coord_trans(y="log10")}

below is the whole function:

USGS <- function(input="discharge", days=7){
require(chron)
require(gsubfn)
require(ggplot2)
require(plyr)
#021973269 is the Waynesboro Gauge on the Savannah River Proper (SRS)
#02102908 is the Flat Creek Gauge (ftbrfcms)
#02133500 is the Drowning Creek (ftbrbmcm)
#02341800 is the Upatoi Creek Near Columbus (ftbn)
#02342500 is the Uchee Creek Near Fort Mitchell (ftbn)
#02203000 is the Canoochee River Near Claxton (ftst)
#02196690 is the Horse Creek Gauge at Clearwater, S.C.

a <- "http://waterdata.usgs.gov/nwis/uv?format=rdb&period=";
b <- "&site_no=021973269,02102908,02133500,02341800,02342500,02203000,02196690"
z <- paste(a, days, b, sep="")
L <- readLines(z)

#look for the data with USGS in front of it (this take advantage of
#the agency column)
L.USGS <- grep("^USGS", L, value = TRUE)
DF <- read.table(textConnection(L.USGS), fill = TRUE)
colnames(DF) <- c("agency", "gauge", "date", "time", "time_zone",
"gauge_height",
"discharge", "precipitation")
pat <- "^# +USGS +([0-9]+) +(.*)"
L.DD <- grep(pat, L, value = TRUE)
library(gsubfn)
DD <- strapply(L.DD, pat, c, simplify = rbind)
DDdf <- data.frame(gauge = as.numeric(DD[,1]), gauge_name = DD[,2])
both <- merge(DF, DDdf, by = "gauge", all.x = TRUE)

dts <- as.character(both[,"date"])
tms <- as.character(both[,"time"])
date_time <- as.chron(paste(dts, tms), "%Y-%m-%d %H:%M")
DF <- data.frame(Date=as.POSIXct(date_time), both)
#change precip to numeric
DF[,"precipitation"] <- as.numeric(as.character(DF[,"precipitation"]))

precip.1 <- subset(DF, precipitation!="NA")
b <- ddply(precip.1$precipitation, .(precip.1$gauge_name), cumsum)
DF.precip <- precip.1
DF.precip$precipitation <- b$.data

#discharge
if(input=="data"){

return(DF)

}else{

qplot(Date, discharge, data=DF,
geom="line", ylab="Date")+facet_wrap(~gauge_name,
scales="free_y")+coord_trans(y="log10")}

if(input=="precipitation"){
#precipitation
qplot(Date, precipitation, data=DF.precip,
geom="line")+facet_wrap(~gauge_name, scales="free_y")

}else{

qplot(Date, discharge, data=DF,
geom="line", ylab="Date")+facet_wrap(~gauge_name,
scales="free_y")+coord_trans(y="log10")}

}


-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
R-help

Re: [R] Using the zero-inflated binomial in experimental designs

2010-05-18 Thread Ben Bolker
Ivan Allaman  yahoo.com.br> writes:

> 
> 
> I'm trying to use the inflated binomial distribution of zeros (since 75% of
> the values are zeros) in a randomized block experiment with four
> quantitative treatments (0, 0.5, 1, 1.5), but I'm finding it difficult,
> since the examples available in VGAM packages like for example, leave us
> unsure of how it should be the data.frame for such analysis. Unfortunately
> the function glm does not have an option to place a family of this kind I'm
> about, because if I had, it would be easy, made that my goal is simple, just
> wanting to compare the treatments. For that you have an idea, here is an
> example of my database.
> 
> BLOCK NIVNT   MUMI
> Inicial   0  18 0 

[snip]

> 
> where: NIV are the treatments; NT is the total number of piglets born; Mumi
> is the number of mummified piglets NT. Mumi The variable is of interest. If
> someone can tell me some stuff on how I can do these tests in R, similar to
> what I would do using the function glm, I'd be grateful.
> I thank everyone's attention.

something like comparing the likelihoods of

m1 <- vglm(cbind(MUMI,NT-MUMI)~NIV*BLOCK,zibinomial,data=mydata)
m2 <- vglm(cbind(MUMI,NT-MUMI)~NIV+BLOCK,zibinomial,data=mydata)
m3 <- vglm(cbind(MUMI,NT-MUMI)~BLOCK,zibinomial,data=mydata)

I don't know whether the anova() method works for VGLM objects
or not.

  By the way, 75% zeroes doesn't necessarily imply zero-inflation --
perhaps it just means a low incidence?

__
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] (no subject)

2010-05-18 Thread Peter Ehlers

Arantzazu,

Your problem is that the data were probably imported
from Excel where you had at least one cell containing "#N/A".
You need to replace those cases in your dataframe with NA.
Then you should be able to do as.numeric(as.character(arcilla)).

 -Peter Ehlers

On 2010-05-18 10:07, Arantzazu Blanco Bernardeau wrote:


Hello
Well, the problem is, that arcilla is the percentage of clay in the soil 
sample. So, for linear model, I need to work with that number or value. Now, R 
thinks that arcilla (arcilla means clay in spanish), is a factor, and gives me 
the value as a factor, so the output of the linear model is
Call:
lm(formula = formula, data = caperf)

Residuals:
Min 1Q Median 3QMax
-1.466e+01 -1.376e-15  1.780e-16  2.038e-15  1.279e+01

Coefficients:
   Estimate Std. Error t value Pr(>|t|)
(Intercept)1.689646.33889   0.267 0.790221
arcilla0.9 1.902288.90888   0.214 0.831239
arcilla10  1.263717.96734   0.159 0.874212
arcilla10.3   15.700819.05141   1.735 0.085090 .
arcilla10.47.275177.72806   0.941 0.348183
arcilla10.45   7.038799.02600   0.780 0.436853
arcilla10.52.412418.90827   0.271 0.786954
arcilla10.65  15.442989.03879   1.709 0.089838 .
arcilla10.7   19.356519.04675   2.140 0.034185 *
arcilla10.93.559479.18501   0.388 0.698974

[...]

arcilla9.9 6.319497.35724   0.859 0.391892


===> arcilla#N/A   24.179598.87201   2.725 0.007274 **


limo   0.249200.04605   5.412 2.76e-07 ***
CO_gkg10.210150.03931   5.346 3.73e-07 ***
C03Ca  0.017110.02727   0.628 0.531337
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 6.249 on 135 degrees of freedom
   (50 observations deleted due to missingness)
Multiple R-squared: 0.9736,Adjusted R-squared: 0.9014
F-statistic: 13.47 on 370 and 135 DF,  p-value:<  2.2e-16

So, in the desired linear model, arcilla should be just a line, with the valors 
of the linear model.
I hope you understand better more. If not, I could make an english version of 
the file to send, so you can try the commands.
Thanks a lot for your help!



Arantzazu Blanco Bernardeau
Dpto de Química Agrícola, Geología y Edafología
Universidad de Murcia-Campus de Espinardo



[snip]

__
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] unsigned 4 byte number

2010-05-18 Thread tetonedge

Does anybody know how to read in a unsigned 4 byte number from a binary file?
According to the help for readBin, the signed argument only applies to
size=1 or 2. But if you declare any size larger it assumes it is signed?
Thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/unsigned-4-byte-number-tp2221555p2221555.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] (no subject)

2010-05-18 Thread Steve Lianoglou
One last thing:

before you take my advice on how to recode your nominal/categorical
"clay" variable for your regression model, take some time to see how
other people talk about this and do some searching on phrases like
"regression model with nominal variables" (that's just the one I
used).

You'll find more (and better) advice on how to do it correctly.

-steve

On Tue, May 18, 2010 at 11:54 AM, Steve Lianoglou
 wrote:
> Hi,
>
> Sorry, I'm not really getting what going on here ... perhaps having
> more domain knowledge would help me make better sense of our question.
>
> In particular:
>
> On Tue, May 18, 2010 at 11:35 AM, Arantzazu Blanco Bernardeau
>  wrote:
>>
>> Hello
>> I have a data array with soil variables (caperf), in which the variable 
>> "clay" is factor (as I see entering str(caperf)) . I need to do a regression 
>> model, so I need to have arcilla (=clay) as a numeric variable.  For that I 
>> have entered
>>
>> as.numeric(as.character(arcilla))
>>
>> and even entering
>>  'as.numeric(levels(arcilla))[arcilla]'
>
> The above code doesn't make sense to me ...
>
> Perhaps cleaning up your question and providing some reproducible
> example we can use to help show you the light (just describing what a
> variable has isn't enough -- give us minimal code we can paste into R
> that reproduces your problem).
>
> Alternatively, depending no what your "levels" mean, you might want to
> recode your data using "dummy variables" (I'm not sure if that's the
> official term) .. this is what I mean:
>
> http://dss.princeton.edu/online_help/analysis/dummy_variables.htm
>
> In your example, let's say you have four levels for "clay" ... maybe
> "soft", "hard", "smooth", "red"
>
> Instead of only using 1 variable with values 1-4, you would recode
> this into 4 variables with values 0,1
>
> So, if one example has a value of "smooth" for clay. Instead of coding it 
> like:
> clay: 3
>
> You would do:
> soft: 0
> hard: 0
> smooth: 1
> red : 0
>
> -steve
> --
> Steve Lianoglou
> Graduate Student: Computational Systems Biology
>  | Memorial Sloan-Kettering Cancer Center
>  | Weill Medical College of Cornell University
> Contact Info: http://cbio.mskcc.org/~lianos/contact
>



-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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: Change class factor to numeric"

2010-05-18 Thread Ivan Calandra

Hi again,

If you used the function read.table() to read from a csv file into a 
data.frame, it is weird that numeric data are converted into factors.
I would check in the original data that you don't have a typo somewhere. 
I don't know all the possibilities, but a special character can 
definitely make R interpret this variable differently.


For Drenaje, it is normal. In that case you can just use:
caperf$Drenaje <- factor(caperf$Drenaje)

HTH
Ivan

Le 5/18/2010 17:59, Arantzazu Blanco Bernardeau a écrit :

Hello
so, here you have the output of the data frame. The data frame comes from a csv 
file.
I could take Gr_2 instead of arcilla, because it is the same value... but 
curiously, it is a factor as well.
   

str(caperf)
 

'data.frame':556 obs. of  38 variables:
  $ Hoja: int  818 818 818 818 818 818 818 818 818 818 ...
  $ idmuestra   : Factor w/ 555 levels "1015-I","1015-II",..: 26 27 28 29 31 32 
33 34 30 35 ...
  $ Año : int  1994 1994 1994 1994 1994 1994 1994 1994 1994 1994 ...
  $ x   : int  655500 633050 632200 635000 637150 643700 655300 648000 
653400 646200 ...
  $ y   : int  4285800 4283050 4298150 429 4294800 4288850 4282700 
4290350 4298450 4296650 ...
  $ CO_gkg1 : num  3.7 6.5 6.3 2.6 12.1 6.9 3.5 10.8 10.3 3.3 ...
  $ NTgkg_1 : num  0.53 1.01 0.66 0.42 1.3 0.82 0.43 1.31 0.85 0.51 ...
  $ C_Nratio: num  6.98 6.46 9.55 6.18 9.33 ...
  $ C03Ca   : num  53.6 38 1.2 1.1 21.1 ...
  $ pHw : num  8 8.4 8.3 8.4 8.45 8.2 8.4 8.4 8.1 8.4 ...
  $ pHClK   : num  7.5 7.4 7.2 7.4 8.3 7.5 7.8 7.4 7.4 7.5 ...
  $ CCC : num  9.7 14.4 10.5 7.2 12.8 ...
  $ CEdSm   : num  0.62 0.72 0.38 0.36 19.35 ...
  $ pF1_3atm: num  25.4 21.3 9.1 12.8 24.1 ...
  $ pF15atm : num  15.3 10.6 5.8 6.1 8.45 11 3.7 18.8 10 14.3 ...
  $ Gr_2: Factor w/ 391 levels "0","0.71","0.9",..: 200 31 158 36 142 
60 377 263 140 151 ...
  $ Gr2_20  : num  19.1 39.1 2.9 5.2 NA 12.5 5.7 29.5 17.3 10.5 ...
  $ Gr20_50 : num  17.6 9.8 4.7 4 NA 10.4 4.2 13.3 12.5 7.8 ...
  $ Gr50_100: num  14.1 12.2 7.6 9 NA 9.1 6.1 8.5 9.1 18.9 ...
  $ Gr100_250   : num  13.4 17.1 28.7 46.2 NA 20.8 28.7 13.6 16.8 32.9 ...
  $ Gr250_500   : num  7.1 5.7 28.8 15.2 NA 24.7 23.4 3.8 11.4 6.9 ...
  $ Gr500_1000  : num  4 1.8 5 3.9 NA 4.2 14.3 0.9 8.9 2.1 ...
  $ Gr1000_2000 : num  1.4 2 1.9 4 NA 4.1 8.9 0.4 4.8 0.9 ...
  $ arcilla : Factor w/ 391 levels "0","0.71","0.9",..: 201 32 158 37 NA 61 
377 263 141 151 ...
  $ limo: num  36.7 48.9 7.6 9.2 0 22.9 9.9 42.8 29.8 18.3 ...
  $ arena   : num  40 38.8 72 78.3 0 62.9 81.4 27.2 51 61.7 ...
  $ SUMA: Factor w/ 15 levels "0","100","100.2",..: 2 2 2 2 1 2 2 2 2 2 
...
  $ codusosuelo : logi  NA NA NA NA NA NA ...
  $ pendiente   : Factor w/ 9 levels "0","1","2","3",..: 3 2 3 3 2 4 3 2 2 3 ...
  $ profutil: logi  NA NA NA NA NA NA ...
  $ profutil.1  : int  50 110 120 40 80 52 30 120 37 80 ...
  $ pedregosidad: int  0 0 0 2 0 4 4 0 3 3 ...
  $ Drenaje : int  4 4 4 4 1 4 5 3 4 4 ...
  $ codsuelo: num  1.1 2.1 3.1 2.1 12.3 2.5 2.5 4.1 2.5 2.1 ...
  $ textura : logi  NA NA NA NA NA NA ...
  $ m.original  : Factor w/ 7 levels "Calizas . dolomías y areniscas",..: 4 7 7 
2 2 7 7 7 7 7 ...
  $ GRUPOPPAL   : Factor w/ 13 levels "Arenosoles","Calcisoles",..: 11 2 3 2 12 
2 2 4 2 2 ...
  $ SUELO   : Factor w/ 40 levels "Arenosol calcárico",..: 30 3 8 3 36 7 7 
10 7 3 ...

In the other side, the variable Drenaje (drainage) that is factor mode, appears 
as integer.
Thanks a lot!


Arantzazu Blanco Bernardeau
Dpto de Química Agrícola, Geología y Edafología
Universidad de Murcia-Campus de Espinardo










   

Date: Tue, 18 May 2010 17:49:54 +0200
From: ivan.calan...@uni-hamburg.de
To:
Subject: Re: [R] "Re: Change class factor to numeric"

Hi,

I think that providing the output from str(data array or whatever you
have) would help.
Because, for now, we don't have much idea of what you really have.
Moreover, some sample data is always welcomed (using the function dput
for example)

Ivan


Le 5/18/2010 17:36, Arantzazu Blanco Bernardeau a écrit :
 

sorry I had a mistake sending my question without a subject. I do resend again. 
Please excuse me.

   

Hello
I have a data array with soil variables (caperf), in which the variable "clay" 
is factor (as I see entering str(caperf)) . I need to do a regression model, so I need to 
have arcilla (=clay) as a numeric variable. For that I have entered

as.numeric(as.character(arcilla))

and even entering
'as.numeric(levels(arcilla))[arcilla]'the variable is resting as factor, and 
the linear model is not valid (for my purposes).
The decimal commas have been converted to decimal points, so I have no idea of 
what to do.
Thanks a lot


Arantzazu Blanco Bernardeau
Dpto de Química Agrícola, Geología y Edafología
Universidad de Murcia-Campus de Espinardo







Re: [R] avoiding reinstall already installed *package*

2010-05-18 Thread milton ruser
Hi Martin,

thanks for your reply, and very thanks for your kind tips about "package"
and "library"
So, I was trying to understand *why* we load packages using library().
I suggest that developers killl the problem on its root, deleting library
function :-)
Good to know already installed packages will not be reinstalled.

cheers

milton

On Tue, May 18, 2010 at 12:49 PM, Martin Maechler <
maech...@stat.math.ethz.ch> wrote:

> { I've modified the subject; I can't stand it hitting square into
>  my face ... }
>
> > "mr" == milton ruser 
> > on Tue, 18 May 2010 12:36:23 -0300 writes:
>
>mr> Dear R-experts,
>mr> I am installing new libraries using
>mr> install.packages("ggplot2",dependencies=T).
>mr> But I perceive that many dependencies are already installed. As I am
> using
>mr> a low-band internet, how can avoid reinstall installed libraries?
>
> There's no problem with installed libraries, as ...
> they DO NOT EXIST.
>
> These are *PACKAGES* !
> Why do you think are you talking about the function
>
>  install.packages()  
> 
>
> ---
> To answer the question you did want to ask:
>
> Do not be afraid:  Depedencies are only installed when needed,
> i.e., no package will be downloaded and installed if it already
> is there.
>
> Martin Maechler, ETH Zurich
>
>mr> cheers
>
>mr> milton
>
>mr> [[alternative HTML version deleted]]
>
> (another thing you should learn to avoid, please)
>
>

[[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] timing a function

2010-05-18 Thread Gustave Lefou
Dear all,

Just one last question. There seems to be no problem in writing

> z = system.time(y <- f(x))

or

> z <- system.time(y <- f(x))

Then z contains the named vector of the elapsed times, and y the value of
the function f(x).

Am I right ?

Thank you very much,
Gustave

2010/5/17 Alexander Shenkin 

> You could also put the call to system.time inside the function itself:
>
> f = function(x) {
>system.time({
>... #function's code
>ret_val = ...
>}); flush.console();
>return ret_val;
> }
>
> i s'pose you'd miss out on the time taken to jump to the function code,
> return the value, etc, but for functions that are heavy at all, that
> wouldn't trip you up.
>
> allie
>
> On 5/17/2010 2:06 PM, Barry Rowlingson wrote:
> > On Mon, May 17, 2010 at 6:24 PM, Peter Ehlers 
> wrote:
> >
> >
> >> Try
> >>  system.time(y <- f(x))
> >>
> >> and see ?"=".
> >>
> >>  -Peter Ehlers
> >>
> >  Ah ha. That explains the curly brackets I saw in a posting with
> > system.time on stack overflow just now:
> >
> >  system.time({y=f(x)})
> >
> >  works as expected since the {} pair make a new code block. Also you
> > can then time more than one statement:
> >
> >  system.time({y=f(x);z=g(y)})
> >
> >  - gives the total time for f(x) and g(y).
> >
> > Barry
> >
>  > __
> > 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.
>

[[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] (no subject)

2010-05-18 Thread Arantzazu Blanco Bernardeau

Hello
Well, the problem is, that arcilla is the percentage of clay in the soil 
sample. So, for linear model, I need to work with that number or value. Now, R 
thinks that arcilla (arcilla means clay in spanish), is a factor, and gives me 
the value as a factor, so the output of the linear model is
Call:
lm(formula = formula, data = caperf)

Residuals:
   Min 1Q Median 3Q    Max 
-1.466e+01 -1.376e-15  1.780e-16  2.038e-15  1.279e+01 

Coefficients:
  Estimate Std. Error t value Pr(>|t|)    
(Intercept)    1.68964    6.33889   0.267 0.790221    
arcilla0.9 1.90228    8.90888   0.214 0.831239    
arcilla10  1.26371    7.96734   0.159 0.874212    
arcilla10.3   15.70081    9.05141   1.735 0.085090 .  
arcilla10.4    7.27517    7.72806   0.941 0.348183    
arcilla10.45   7.03879    9.02600   0.780 0.436853    
arcilla10.5    2.41241    8.90827   0.271 0.786954    
arcilla10.65  15.44298    9.03879   1.709 0.089838 .  
arcilla10.7   19.35651    9.04675   2.140 0.034185 *  
arcilla10.9    3.55947    9.18501   0.388 0.698974    

[...]

arcilla9.9 6.31949    7.35724   0.859 0.391892    
arcilla#N/A   24.17959    8.87201   2.725 0.007274 ** 
limo   0.24920    0.04605   5.412 2.76e-07 ***
CO_gkg1    0.21015    0.03931   5.346 3.73e-07 ***
C03Ca  0.01711    0.02727   0.628 0.531337    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 6.249 on 135 degrees of freedom
  (50 observations deleted due to missingness)
Multiple R-squared: 0.9736,    Adjusted R-squared: 0.9014 
F-statistic: 13.47 on 370 and 135 DF,  p-value: < 2.2e-16 

So, in the desired linear model, arcilla should be just a line, with the valors 
of the linear model.
I hope you understand better more. If not, I could make an english version of 
the file to send, so you can try the commands.
Thanks a lot for your help!



Arantzazu Blanco Bernardeau
Dpto de Química Agrícola, Geología y Edafología
Universidad de Murcia-Campus de Espinardo










> Date: Tue, 18 May 2010 11:54:20 -0400
> Subject: Re: [R] (no subject)
> From: mailinglist.honey...@gmail.com
> To: aramu...@hotmail.com
> CC: r-help@r-project.org
>
> Hi,
>
> Sorry, I'm not really getting what going on here ... perhaps having
> more domain knowledge would help me make better sense of our question.
>
> In particular:
>
> On Tue, May 18, 2010 at 11:35 AM, Arantzazu Blanco Bernardeau
>  wrote:
>>
>> Hello
>> I have a data array with soil variables (caperf), in which the variable 
>> "clay" is factor (as I see entering str(caperf)) . I need to do a regression 
>> model, so I need to have arcilla (=clay) as a numeric variable.  For that I 
>> have entered
>>
>> as.numeric(as.character(arcilla))
>>
>> and even entering
>>  'as.numeric(levels(arcilla))[arcilla]'
>
> The above code doesn't make sense to me ...
>
> Perhaps cleaning up your question and providing some reproducible
> example we can use to help show you the light (just describing what a
> variable has isn't enough -- give us minimal code we can paste into R
> that reproduces your problem).
>
> Alternatively, depending no what your "levels" mean, you might want to
> recode your data using "dummy variables" (I'm not sure if that's the
> official term) .. this is what I mean:
>
> http://dss.princeton.edu/online_help/analysis/dummy_variables.htm
>
> In your example, let's say you have four levels for "clay" ... maybe
> "soft", "hard", "smooth", "red"
>
> Instead of only using 1 variable with values 1-4, you would recode
> this into 4 variables with values 0,1
>
> So, if one example has a value of "smooth" for clay. Instead of coding it 
> like:
> clay: 3
>
> You would do:
> soft: 0
> hard: 0
> smooth: 1
> red : 0
>
> -steve
> --
> Steve Lianoglou
> Graduate Student: Computational Systems Biology
> | Memorial Sloan-Kettering Cancer Center
> | Weill Medical College of Cornell University
> Contact Info: http://cbio.mskcc.org/~lianos/contact
  
_
Consejos para seducir ¿Puedes conocer gente nueva a través de Internet? 
¡Regístrate ya!

__
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] Repeating Name for Rows

2010-05-18 Thread Wu Gong

If I perceive the issue:

Day <- c(rep(97, each = 11), rep(98:278, each = 12)) 

-
A R learner.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Repeating-Name-for-Rows-tp2221457p2221492.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] avoiding reinstall already installed *package*

2010-05-18 Thread Ted Harding
On 18-May-10 15:49:37, Martin Maechler wrote:
> { I've modified the subject; I can't stand it hitting square into
>   my face ... }
>> "mr" == milton ruser 
>> on Tue, 18 May 2010 12:36:23 -0300 writes:
> mr> Dear R-experts,
> mr> I am installing new libraries using
> mr> install.packages("ggplot2",dependencies=T).
> mr> But I perceive that many dependencies are already installed.
> mr> As I am using a low-band internet, how can avoid reinstall
> mr> installed libraries?
> 
> There's no problem with installed libraries, as ... 
> they DO NOT EXIST.
> 
> These are *PACKAGES* !
> Why do you think are you talking about the function
> 
>  install.packages()  
>  

Ah, Martin! I know that "package" is the official terminology,
but R itself tempts the naive user into deviating from the
True Path. Indeed, I had my fingers burned by this myself,
a long time ago (I'm still licking them ... ).

One might ask: "Why do you think we use the function library()?"
when loading add-on packages into R. Indeed, the very directory
tree of R itself stores packages under /usr/lib/R/library.

So, once in a while, someone gets it wrong, and has to find it
out the hard way!

Best wishes,
Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 18-May-10   Time: 17:05:57
-- XFMail --

__
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: Change class factor to numeric"

2010-05-18 Thread Arantzazu Blanco Bernardeau

Hello
so, here you have the output of the data frame. The data frame comes from a csv 
file. 
I could take Gr_2 instead of arcilla, because it is the same value... but 
curiously, it is a factor as well. 
> str(caperf)
'data.frame':    556 obs. of  38 variables:
 $ Hoja    : int  818 818 818 818 818 818 818 818 818 818 ...
 $ idmuestra   : Factor w/ 555 levels "1015-I","1015-II",..: 26 27 28 29 31 32 
33 34 30 35 ...
 $ Año : int  1994 1994 1994 1994 1994 1994 1994 1994 1994 1994 ...
 $ x   : int  655500 633050 632200 635000 637150 643700 655300 648000 
653400 646200 ...
 $ y   : int  4285800 4283050 4298150 429 4294800 4288850 4282700 
4290350 4298450 4296650 ...
 $ CO_gkg1 : num  3.7 6.5 6.3 2.6 12.1 6.9 3.5 10.8 10.3 3.3 ...
 $ NTgkg_1 : num  0.53 1.01 0.66 0.42 1.3 0.82 0.43 1.31 0.85 0.51 ...
 $ C_Nratio    : num  6.98 6.46 9.55 6.18 9.33 ...
 $ C03Ca   : num  53.6 38 1.2 1.1 21.1 ...
 $ pHw : num  8 8.4 8.3 8.4 8.45 8.2 8.4 8.4 8.1 8.4 ...
 $ pHClK   : num  7.5 7.4 7.2 7.4 8.3 7.5 7.8 7.4 7.4 7.5 ...
 $ CCC : num  9.7 14.4 10.5 7.2 12.8 ...
 $ CEdSm   : num  0.62 0.72 0.38 0.36 19.35 ...
 $ pF1_3atm    : num  25.4 21.3 9.1 12.8 24.1 ...
 $ pF15atm : num  15.3 10.6 5.8 6.1 8.45 11 3.7 18.8 10 14.3 ...
 $ Gr_2    : Factor w/ 391 levels "0","0.71","0.9",..: 200 31 158 36 142 60 
377 263 140 151 ...
 $ Gr2_20  : num  19.1 39.1 2.9 5.2 NA 12.5 5.7 29.5 17.3 10.5 ...
 $ Gr20_50 : num  17.6 9.8 4.7 4 NA 10.4 4.2 13.3 12.5 7.8 ...
 $ Gr50_100    : num  14.1 12.2 7.6 9 NA 9.1 6.1 8.5 9.1 18.9 ...
 $ Gr100_250   : num  13.4 17.1 28.7 46.2 NA 20.8 28.7 13.6 16.8 32.9 ...
 $ Gr250_500   : num  7.1 5.7 28.8 15.2 NA 24.7 23.4 3.8 11.4 6.9 ...
 $ Gr500_1000  : num  4 1.8 5 3.9 NA 4.2 14.3 0.9 8.9 2.1 ...
 $ Gr1000_2000 : num  1.4 2 1.9 4 NA 4.1 8.9 0.4 4.8 0.9 ...
 $ arcilla : Factor w/ 391 levels "0","0.71","0.9",..: 201 32 158 37 NA 61 
377 263 141 151 ...
 $ limo    : num  36.7 48.9 7.6 9.2 0 22.9 9.9 42.8 29.8 18.3 ...
 $ arena   : num  40 38.8 72 78.3 0 62.9 81.4 27.2 51 61.7 ...
 $ SUMA    : Factor w/ 15 levels "0","100","100.2",..: 2 2 2 2 1 2 2 2 2 2 
...
 $ codusosuelo : logi  NA NA NA NA NA NA ...
 $ pendiente   : Factor w/ 9 levels "0","1","2","3",..: 3 2 3 3 2 4 3 2 2 3 ...
 $ profutil    : logi  NA NA NA NA NA NA ...
 $ profutil.1  : int  50 110 120 40 80 52 30 120 37 80 ...
 $ pedregosidad: int  0 0 0 2 0 4 4 0 3 3 ...
 $ Drenaje : int  4 4 4 4 1 4 5 3 4 4 ...
 $ codsuelo    : num  1.1 2.1 3.1 2.1 12.3 2.5 2.5 4.1 2.5 2.1 ...
 $ textura : logi  NA NA NA NA NA NA ...
 $ m.original  : Factor w/ 7 levels "Calizas . dolomías y areniscas",..: 4 7 7 
2 2 7 7 7 7 7 ...
 $ GRUPOPPAL   : Factor w/ 13 levels "Arenosoles","Calcisoles",..: 11 2 3 2 12 
2 2 4 2 2 ...
 $ SUELO   : Factor w/ 40 levels "Arenosol calcárico",..: 30 3 8 3 36 7 7 
10 7 3 ...

In the other side, the variable Drenaje (drainage) that is factor mode, appears 
as integer. 
Thanks a lot!


Arantzazu Blanco Bernardeau
Dpto de Química Agrícola, Geología y Edafología
Universidad de Murcia-Campus de Espinardo










> Date: Tue, 18 May 2010 17:49:54 +0200
> From: ivan.calan...@uni-hamburg.de
> To:
> Subject: Re: [R] "Re: Change class factor to numeric"
>
> Hi,
>
> I think that providing the output from str(data array or whatever you
> have) would help.
> Because, for now, we don't have much idea of what you really have.
> Moreover, some sample data is always welcomed (using the function dput
> for example)
>
> Ivan
>
>
> Le 5/18/2010 17:36, Arantzazu Blanco Bernardeau a écrit :
>>
>> sorry I had a mistake sending my question without a subject. I do resend 
>> again. Please excuse me.
>>
>>> Hello
>>> I have a data array with soil variables (caperf), in which the variable 
>>> "clay" is factor (as I see entering str(caperf)) . I need to do a 
>>> regression model, so I need to have arcilla (=clay) as a numeric variable. 
>>> For that I have entered
>>>
>>> as.numeric(as.character(arcilla))
>>>
>>> and even entering
>>> 'as.numeric(levels(arcilla))[arcilla]'the variable is resting as factor, 
>>> and the linear model is not valid (for my purposes).
>>> The decimal commas have been converted to decimal points, so I have no idea 
>>> of what to do.
>>> Thanks a lot
>>>
>>>
>>> Arantzazu Blanco Bernardeau
>>> Dpto de Química Agrícola, Geología y Edafología
>>> Universidad de Murcia-Campus de Espinardo
>>>
>>>
>>>
>>>
>>>
>>>
>>> _
>>> Diseñar aplicaciones tiene premio. ¡Si eres desarrollador no esperes más!
>>> http://www.imaginemobile.es
>>>
>>
>> _
>> Recibe en tu HOTMAIL los emails de TODAS tus CUENTAS. + info
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the pos

Re: [R] (no subject)

2010-05-18 Thread Steve Lianoglou
Hi,

Sorry, I'm not really getting what going on here ... perhaps having
more domain knowledge would help me make better sense of our question.

In particular:

On Tue, May 18, 2010 at 11:35 AM, Arantzazu Blanco Bernardeau
 wrote:
>
> Hello
> I have a data array with soil variables (caperf), in which the variable 
> "clay" is factor (as I see entering str(caperf)) . I need to do a regression 
> model, so I need to have arcilla (=clay) as a numeric variable.  For that I 
> have entered
>
> as.numeric(as.character(arcilla))
>
> and even entering
>  'as.numeric(levels(arcilla))[arcilla]'

The above code doesn't make sense to me ...

Perhaps cleaning up your question and providing some reproducible
example we can use to help show you the light (just describing what a
variable has isn't enough -- give us minimal code we can paste into R
that reproduces your problem).

Alternatively, depending no what your "levels" mean, you might want to
recode your data using "dummy variables" (I'm not sure if that's the
official term) .. this is what I mean:

http://dss.princeton.edu/online_help/analysis/dummy_variables.htm

In your example, let's say you have four levels for "clay" ... maybe
"soft", "hard", "smooth", "red"

Instead of only using 1 variable with values 1-4, you would recode
this into 4 variables with values 0,1

So, if one example has a value of "smooth" for clay. Instead of coding it like:
clay: 3

You would do:
soft: 0
hard: 0
smooth: 1
red : 0

-steve
-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] survey package: weights used in svycoxph()

2010-05-18 Thread Thomas Lumley

On Mon, 17 May 2010, Vinh Nguyen wrote:


Dear R-help,

Let me know if I should email r-devel instead of this list.  This
message is addressed to Professor Lumley or anyone familiar with the
survey package.

Does svycoxph() implement the method outlined in Binder 1992 as
referenced in the help file?


Yes. That's why it's referenced.


That is, are weights incorporated in the
ratio term (numerator and denominator) of the estimating equation?


Yes.

 > I

don't believe so since svycoxph() calls coxph() of the survival
package and weights are applied once in the estimating equation.  If
the weights are implemented in the ratio, could you point me to where
in the code this is done?  I would like to estimate as in Binder but
with custom weights.  Thanks.


It happens inside the C code called by coxph(), eg, in survival/src/coxfit2.c

Binder's estimating equations are the usual way of applying weights to a Cox model, so 
nothing special is done apart from calling coxph(). To quote the author of the survival 
package, Terry Therneau, "Other formulae change in the obvious way, eg, the weighted 
mean $\bar Z$ is changed to include both the risk weights $r$ and the external weights 
$w$." [Mayo Clinic Biostatistics technical report #52, section 6.2.2]



This is mentioned in the help file but I don't quite understand:
The main difference between svycoxph function and the robust=TRUE
option to coxph in the
survival package is that this function accounts for the reduction in
variance from stratified sampling
and the increase in variance from having only a small number of clusters.


The point estimates from coxph() are the same as those from svycoxph() (with 
the same weights).  The standard errors are almost the same.  There are two 
differences.  The first is the use of 1/(nclusters -1) rather than 1/nclusters 
as a divisor.  The second is that svycoxph() computes variances using 
estimating functions centered at zero in each *sampling* stratum whereas 
coxph() centers them at zero in each baseline hazard stratum, as supplied in 
the strata() argument to coxph().

 -thomas

Thomas Lumley   Assoc. Professor, Biostatistics
tlum...@u.washington.eduUniversity of Washington, Seattle

__
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: Change class factor to numeric"

2010-05-18 Thread Ivan Calandra

Hi,

I think that providing the output from str(data array or whatever you 
have) would help.

Because, for now, we don't have much idea of what you really have.
Moreover, some sample data is always welcomed (using the function dput 
for example)


Ivan


Le 5/18/2010 17:36, Arantzazu Blanco Bernardeau a écrit :


sorry I had a mistake sending my question without a subject. I do resend again. 
Please excuse me.
   

Hello
I have a data array with soil variables (caperf), in which the variable "clay" 
is factor (as I see entering str(caperf)) . I need to do a regression model, so I need to 
have arcilla (=clay) as a numeric variable.  For that I have entered

as.numeric(as.character(arcilla))

and even entering
'as.numeric(levels(arcilla))[arcilla]'the variable is resting as factor, and 
the linear model is not valid (for my purposes).
The decimal commas have been converted to decimal points, so I have no idea of 
what to do.
Thanks a lot


Arantzazu Blanco Bernardeau
Dpto de Química Agrícola, Geología y Edafología
Universidad de Murcia-Campus de Espinardo






_
Diseñar aplicaciones tiene premio. ¡Si eres desarrollador no esperes más!
http://www.imaginemobile.es
 


_
Recibe en tu HOTMAIL los emails de TODAS tus CUENTAS. + info

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

   


--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php

__
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] BRugs under Linux?

2010-05-18 Thread Uwe Ligges



On 17.05.2010 18:46, Kevin E. Thorpe wrote:

Hello.

In this post:

http://finzi.psych.upenn.edu/Rhelp10/2010-March/233815.html

Uwe Ligges suggests using BRugs rather than R2WinBUGS under windows. He
also notes that it is not in the main CRAN repository, but it is in
"extras" which is a default repository under windows.

I have OpenBUGS 3.1.0 (the latest that has a native Linux version which
is no longer called linBUGS) installed on my Linux box and would like to
interact with it from R. I see posts on this from 2009, but these
predate the 3.1.0 version, so I'm wonering if there is anything new here.

Is BRugs the recommended approach from Linux? If so, the required
repository is not a default on my installation. What is the address of
the repository where this will be found? If BRugs is not the best
solution from Linux, can anyone suggest a better alternative?



OpenBUGS 3.0.3 (which is linked in BRugs) did not work under Linux (at 
least not on arbitrary Linux systems, some people claim to got it 
working), hence there is no such BRugs version for Linux.


Currently, BRugs is being restructured for the new OpenBUGS version 
(thanks to the great help by Chris Jackson) and I am rather confident 
that we get a new BRugs version out within a month or two that *may* 
work under Linux as well. But I cannot yet promise the latter.


Best wishes,
Uwe





Note that I also know about jags and have that installed also, but until
I become a bit more familiar with this software I'm starting from BUGS.

Kevin



__
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] avoiding reinstall already installed *package*

2010-05-18 Thread Martin Maechler
{ I've modified the subject; I can't stand it hitting square into
  my face ... }

> "mr" == milton ruser 
> on Tue, 18 May 2010 12:36:23 -0300 writes:

mr> Dear R-experts,
mr> I am installing new libraries using
mr> install.packages("ggplot2",dependencies=T).
mr> But I perceive that many dependencies are already installed. As I am 
using
mr> a low-band internet, how can avoid reinstall installed libraries?

There's no problem with installed libraries, as ... 
they DO NOT EXIST.

These are *PACKAGES* !
Why do you think are you talking about the function

 install.packages()  
 

---
To answer the question you did want to ask:

Do not be afraid:  Depedencies are only installed when needed,
i.e., no package will be downloaded and installed if it already
is there.

Martin Maechler, ETH Zurich

mr> cheers

mr> milton

mr> [[alternative HTML version deleted]]

(another thing you should learn to avoid, please)

__
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: Change class factor to numeric"

2010-05-18 Thread milton ruser
Try

arcilla<-as.numeric(as.character(clay))

best

milton

On Tue, May 18, 2010 at 12:36 PM, Arantzazu Blanco Bernardeau <
aramu...@hotmail.com> wrote:

>
>
> sorry I had a mistake sending my question without a subject. I do resend
> again. Please excuse me.
> > Hello
> > I have a data array with soil variables (caperf), in which the variable
> "clay" is factor (as I see entering str(caperf)) . I need to do a regression
> model, so I need to have arcilla (=clay) as a numeric variable.  For that I
> have entered
> >
> > as.numeric(as.character(arcilla))
> >
> > and even entering
> > 'as.numeric(levels(arcilla))[arcilla]'the variable is resting as factor,
> and the linear model is not valid (for my purposes).
> > The decimal commas have been converted to decimal points, so I have no
> idea of what to do.
> > Thanks a lot
> >
> >
> > Arantzazu Blanco Bernardeau
> > Dpto de Química Agrícola, Geología y Edafología
> > Universidad de Murcia-Campus de Espinardo
> >
> >
> >
> >
> >
> >
> > _
> > Diseñar aplicaciones tiene premio. ¡Si eres desarrollador no esperes más!
> > http://www.imaginemobile.es
>
> _
> Recibe en tu HOTMAIL los emails de TODAS tus CUENTAS. + info
>
> __
> 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] avoiding reinstall already installed library

2010-05-18 Thread Steve Lianoglou
Hi,

On Tue, May 18, 2010 at 11:36 AM, milton ruser  wrote:
> Dear R-experts,
>
> I am installing new libraries using
> install.packages("ggplot2",dependencies=T).
> But I perceive that many dependencies are already installed. As I am using
> a low-band internet, how can avoid reinstall installed libraries?

Look at the description of the "dependencies" argument in the
?instal.packages help:

"""logical indicating to also install uninstalled packages on which
these packages ..."""

It looks like your concern is already taken care of.

-steve
-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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: Change class factor to numeric"

2010-05-18 Thread Arantzazu Blanco Bernardeau


sorry I had a mistake sending my question without a subject. I do resend again. 
Please excuse me.
> Hello
> I have a data array with soil variables (caperf), in which the variable 
> "clay" is factor (as I see entering str(caperf)) . I need to do a regression 
> model, so I need to have arcilla (=clay) as a numeric variable.  For that I 
> have entered
>
> as.numeric(as.character(arcilla))
>
> and even entering
> 'as.numeric(levels(arcilla))[arcilla]'the variable is resting as factor, and 
> the linear model is not valid (for my purposes).
> The decimal commas have been converted to decimal points, so I have no idea 
> of what to do.
> Thanks a lot
>
>
> Arantzazu Blanco Bernardeau
> Dpto de Química Agrícola, Geología y Edafología
> Universidad de Murcia-Campus de Espinardo
>
>
>
>
>
>
> _
> Diseñar aplicaciones tiene premio. ¡Si eres desarrollador no esperes más!
> http://www.imaginemobile.es
  
_
Recibe en tu HOTMAIL los emails de TODAS tus CUENTAS. + info

__
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] Counting Frequencies in Data Frame

2010-05-18 Thread William Dunlap
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of M.Ribeiro
> Sent: Tuesday, May 18, 2010 7:13 AM
> To: r-help@r-project.org
> Subject: [R] Counting Frequencies in Data Frame
> 
> 
> Hi,
> I am sure there is an easy way to do it, but I can't find it.
> I have a data frame that has 15 columns and 7000 rows.
> 
> The only values inside the data.frame are "aa", "ab", "bb" as 
> you can see an
> example bellow.
> 
>1  2  3
> 1 aa ab ab
> 2 ab ab ab
> 3 aa aa aa
> 4 bb bb bb
> 
> What I would like to do, is to generate a vector (or another 
> data.frame)
> with 7000 rows, and 3 columns. In the first column, the 
> information about
> how many aa, the second about how many ab, and the third 
> about how many bb
> are there in each line
>   aa  ab  bb
> 1  1   2   0
> 2  0   2   0
-->  3?  <--
> 3  3   0   0
> 4  0   0   3

You could make a "table" (a sort of "matrix") of the
data entries and their row numbers:
  
  > tmp <- read.table(header=TRUE, check.names=FALSE, textConnection("
  +1  2  3
  + 1 aa ab ab
  + 2 ab ab ab
  + 3 aa aa aa
  + 4 bb bb bb
  + "))
  > table(row(tmp), as.matrix(tmp))
 
  aa ab bb
1  1  2  0
2  0  3  0
3  3  0  0
4  0  0  3

The as.matrix() is needed to force all the columns of the
data.frame into one vector.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 
> 
> Thank you very much
> Cheers
> -- 
> View this message in context: 
> http://r.789695.n4.nabble.com/Counting-Frequencies-in-Data-Fra
me-tp2221342p2221342.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] avoiding reinstall already installed library

2010-05-18 Thread milton ruser
Dear R-experts,

I am installing new libraries using
install.packages("ggplot2",dependencies=T).
But I perceive that many dependencies are already installed. As I am using
a low-band internet, how can avoid reinstall installed libraries?

cheers

milton

[[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] (no subject)

2010-05-18 Thread Arantzazu Blanco Bernardeau

Hello
I have a data array with soil variables (caperf), in which the variable "clay" 
is factor (as I see entering str(caperf)) . I need to do a regression model, so 
I need to have arcilla (=clay) as a numeric variable.  For that I have entered

as.numeric(as.character(arcilla))

and even entering
 'as.numeric(levels(arcilla))[arcilla]'the variable is resting as factor, and 
the linear model is not valid (for my purposes).
The decimal commas have been converted to decimal points, so I have no idea of 
what to do.
Thanks a lot


Arantzazu Blanco Bernardeau
Dpto de Química Agrícola, Geología y Edafología  
Universidad de Murcia-Campus de Espinardo





  
_
Diseñar aplicaciones tiene premio. ¡Si eres desarrollador no esperes más!

__
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] Counting Frequencies in Data Frame

2010-05-18 Thread Ista Zahn
Hi,
Others will have fancier solutions, but is the way I would do it:

dat <- read.table(textConnection("1  2  3
1 aa ab ab
2 ab ab ab
3 aa aa aa
4 bb bb bb"), header=TRUE)
closeAllConnections()

countAB <- function(x) {
  aa <- length(which(x == "aa"))
  ab <- length(which(x == "ab"))
  bb <- length(which(x == "bb"))
  Result <- c(aa, ab, bb)
  return(Result)
}

Counts <- as.data.frame(t(apply(dat, 1, countAB)))
names(Counts) <- c("aa", "ab", "bb")

Best,
Ista

On Tuesday 18 May 2010 10:12:49 am M.Ribeiro wrote:
> Hi,
> I am sure there is an easy way to do it, but I can't find it.
> I have a data frame that has 15 columns and 7000 rows.
> 
> The only values inside the data.frame are "aa", "ab", "bb" as you can see
> an example bellow.
> 
>1  2  3
> 1 aa ab ab
> 2 ab ab ab
> 3 aa aa aa
> 4 bb bb bb
> 
> What I would like to do, is to generate a vector (or another data.frame)
> with 7000 rows, and 3 columns. In the first column, the information about
> how many aa, the second about how many ab, and the third about how many bb
> are there in each line
>   aa  ab  bb
> 1  1   2   0
> 2  0   2   0
> 3  3   0   0
> 4  0   0   3
> 
> Thank you very much
> Cheers

__
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] Fatal error that doesn't let me start R

2010-05-18 Thread Steve Lianoglou
Hi,

On Tue, May 18, 2010 at 10:51 AM,   wrote:
> Hi, all.
>
> I have R installed in my computer.  I guess I did something in my previous
> session, and now every time I start R, I find the following message:
>
> "Fatal error: unable to restore saved data in .RData"
>
> I uninstalled R and installed it again and I'm still getting this message.
>
> Can anyone help me?

It looks like you have an .Rdata file that is corrupt -- you just have
to remove it.

When you quit R, you should have noticed a prompt that asks you if you
want to "Save workspace image". When answer "yes", it will save your
workspace into an ".RData" file.

Anyway, it's not a problem with your R install, which is why
reinstalling R didn't work, you just have to remove this file. Without
any more details with respect to how you launched R, what type of cpu
you have, etc., my first guess would be that this file resides in your
home directory.

-steve
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] Fatal error that doesn't let me start R

2010-05-18 Thread Duncan Murdoch

On 18/05/2010 10:51 AM, gbre...@ssc.wisc.edu wrote:

Hi, all.

I have R installed in my computer.  I guess I did something in my previous
session, and now every time I start R, I find the following message:

"Fatal error: unable to restore saved data in .RData"

I uninstalled R and installed it again and I'm still getting this message.

Can anyone help me?



You likely have an object in the .RData file which can't be loaded, 
because it relies on a package you no longer have.  You can run R with 
the --vanilla command line option and it won't try to load .RData, then 
reinstall all of your packages, and that might fix things.  
Alternatively, just delete the .RData file, and the problem will go away 
(but so will your data.)


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] Repeating Name for Rows

2010-05-18 Thread ecvetano

Hello,
I have a large data frame (47:2186), where i want to label every 12th row.
This command works,
Day <-rep(97:278, each = 12)
However i need 97 to only labeled 11 rows and then from 98:278 can be  
labeled every 12 times.


Thanks!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] C function call in R

2010-05-18 Thread Steve Lianoglou
Hi,

On Tue, May 18, 2010 at 10:50 AM, John Lande  wrote:
> dear all,
>
> we am trying to improve the performance of my R code, with the implentation
> of some function with custom C code.
> we found difficult to import and export/import data structure such us
> matrices or data.frame into the external C functions.
>
> we already tried the solution from "Writing R Extensions" form  the R
> webpage.

Perhaps:
(i) you can show us what you've tried and someone can tell help steer
you in a better direction
(ii) you can check out the Rcpp library. A new version was just
released that you can read up on:

http://romainfrancois.blog.free.fr/index.php?category/R-package/Rcpp

It has lots of examples of how it should be used in its unit tests, etc.

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] Fatal error that doesn't let me start R

2010-05-18 Thread gbrenes
Hi, all.

I have R installed in my computer.  I guess I did something in my previous
session, and now every time I start R, I find the following message:

"Fatal error: unable to restore saved data in .RData"

I uninstalled R and installed it again and I'm still getting this message.

Can anyone help me?


Gilbert

__
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] C function call in R

2010-05-18 Thread John Lande
dear all,

we am trying to improve the performance of my R code, with the implentation
of some function with custom C code.
we found difficult to import and export/import data structure such us
matrices or data.frame into the external C functions.

we already tried the solution from "Writing R Extensions" form  the R
webpage.

do you have any other solution or more advanced documentation on that point?

looking forward your answer

[[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] looking for .. dec if vector if element > x

2010-05-18 Thread Knut Krueger

Henrique Dallazuanna schrieb:

Try this also:

pmax(test - 1, 1)

O

test  <- c(1,3,5,7,9,11,12,13,14)
test
test <- pmax(test - 1, 1)
test

This works for 1
what about if  I would dec 11: to 14  to close the gap between 9 and 10 ?
I did not find the answer with the help file

Thank you Knut

__
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] Counting Frequencies in Data Frame

2010-05-18 Thread M.Ribeiro

Hi,
I am sure there is an easy way to do it, but I can't find it.
I have a data frame that has 15 columns and 7000 rows.

The only values inside the data.frame are "aa", "ab", "bb" as you can see an
example bellow.

   1  2  3
1 aa ab ab
2 ab ab ab
3 aa aa aa
4 bb bb bb

What I would like to do, is to generate a vector (or another data.frame)
with 7000 rows, and 3 columns. In the first column, the information about
how many aa, the second about how many ab, and the third about how many bb
are there in each line
  aa  ab  bb
1  1   2   0
2  0   2   0
3  3   0   0
4  0   0   3

Thank you very much
Cheers
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Counting-Frequencies-in-Data-Frame-tp2221342p2221342.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] sample

2010-05-18 Thread Wu Gong

Sorry, I made two mistakes. The first was matching the female with the male.
The second was 2 variables should be selected randomly every time.

Followed is a revised copy:

## Import data.
moms <- read.delim("females.txt", sep =" ", stringsAsFactors = FALSE, header
= TRUE)
dads <- read.delim("males.txt", sep =" ", stringsAsFactors = FALSE, header =
TRUE) 

## Mate.
## Each male doesn't mate twice.
parents <- cbind(moms, dads[sample(nrow(dads), nrow(moms)),])

## Assign output data frame.
## The matrix "resultscheck" will be used to check the random selections.
output_offspring <- as.data.frame(matrix("", nrow = nrow(moms), ncol = 6),
stringsAsFactors = FALSE) 
resultscheck <- as.data.frame(matrix("", nrow = nrow(moms), ncol = 6),
stringsAsFactors = FALSE) 

## Randomly select two variables both from moms and dads.
for(i in 1:nrow(parents)) {
selection <- c(1, sample((2:5),2), 6, sample((7:10),2)) 
output_offspring[i,] <- parents[1,selection]
resultscheck[i,] <- selection
}

## Show the random selections.
resultscheck

## Output.
write.table(output_offspring,"offspring_7.txt",row.names=F,col.names=c("momID","A1","A2","dadID","A3","A4"),quote=F)
 



-
A R learner.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/sample-tp2218361p2221328.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] help color coding map in R

2010-05-18 Thread Anderson, Chris
Thank you this was helpful

Chris Anderson
Data Analyst
Medical Affairs
wk: 925-677-4870
cell: 707-315-8486
Fax:925-677-4670


-Original Message-
From: foolish.andr...@gmail.com [mailto:foolish.andr...@gmail.com] On Behalf Of 
Felix Andrews
Sent: Monday, May 17, 2010 5:55 PM
To: Anderson, Chris
Cc: R-help Forum
Subject: Re: [R] help color coding map in R

Sorry, I was talking nonsense.

The actual problem was in your panel function, where you extract the
state boundaries, and then draw them using panel.polygon: the order of
states from map() is arbitrary, and does not correspond to the color
palette that you set up.

I suggest using mapplot(). This matches the region names you provide
to the names from the map.  However (as in your original case) you do
need to ensure that they match exactly, including case and sub-region
names...

i.e. you need to match up
NatSTSummaryHigh.abi$JurisdtnStateName  with
map("state", regions=NatSTSummaryHigh.abi$JurisdtnStateName)$names
(exactly).


nclr <- 4
plotclr <- brewer.pal(nclr,"PuRd")
class <- classIntervals(NatSTSummaryHigh.abi$STMean, nclr, style="fisher" )

mapplot(tolower(JurisdtnStateName) ~ STMean, data = NatSTSummaryHigh.abi,
map = us.map, breaks = class$brks, colramp = colorRampPalette(plotclr))


-Felix


On 18 May 2010 02:37, Anderson, Chris  wrote:
> Flex,
>
> I apologize for not sending the data. I have attached the Rdata set and an 
> excel version and I've attached the graph. I have not use mapplot before is 
> that a better option if so then will you pass along the syntax I would use. 
> As far as using the current logic, I tried adding your suggesting to the 
> groups variable and I get the same result. I also have a field within my data 
> called BdgtGrp, which I placed in the groups option, but the state colors 
> don’t match the levels I have in the legend. Idealy, I would like those 
> states that I have identified with BdgtGrp=="Significanlty high" be in "red", 
> purple for those identified as "Mid-High" and light blue for those identified 
> as "High". If not by these flags then I would want the colors be for the 
> ranges specified within the class level.
>
> In any case, I expect Ohio, followed by New Mexico, and Arizona to be in 
> "red". In order for me to get the states highlighted in the proper color are 
> you suggesting I do a reorder on  this section of the code 
> "core.states=map("state", 
> regions=NatSTSummaryHigh.abi$JurisdtnStateName[subscripts],
>  plot=FALSE, fill=TRUE)" ?
>
>
>
>
> Chris Anderson
> Data Analyst
> Medical Affairs
> wk: 925-677-4870
> cell: 707-315-8486
> Fax:925-677-4670
>
>
> -Original Message-
> From: foolish.andr...@gmail.com [mailto:foolish.andr...@gmail.com] On Behalf 
> Of Felix Andrews
> Sent: Saturday, May 15, 2010 6:41 AM
> To: Anderson, Chris
> Cc: r-help@R-project.org
> Subject: Re: [R] help color coding map in R
>
> The 'groups' argument should be a factor, which explicitly defines the
> ordering of its levels. Otherwise it is converted to a factor using
> the default ordering which is alphabetical. You can make a factor
> ordered by occurence as, eg., factor(z, levels = unique(z)). Or use
> reorder().
>
> Note that data attachments don't work on this list. After constructing
> a minimal example, it is best to dump the required objects in a
> pastable form using dput().
>
> I'm guessing you have some reason that you are not using mapplot()...
>
> -Felix
>
> On Saturday, May 15, 2010, Anderson, Chris
>  wrote:
>> I am trying to create a map with selected states based on highest to lowest 
>> mean cost. The following code properly selects the correct states, and the 
>> legend is properly color coded with ranges, but the colors per range does 
>> not match the state colors. I need help getting the state colors to match 
>> the ranges outlined in the legend. I have tried ordering the mean amounts 
>> and this correctly creates the vector of colors in the correct order, but 
>> when applied to the map the colors don't match. Attached is the R dataset of 
>> my data. Please help me tweak the map so the colors are properly assigned.
>>
>> # Get the entire US map for use later.
>> us.map <- map("state", plot = FALSE, fill = TRUE)
>>
>> # Calculate the range of the map (with extra margins).
>> xl <- extendrange(us.map$range[1:2])
>> yl <- extendrange(us.map$range[3:4])
>>
>> library(maps)
>> library(lattice)
>> library(latticeExtra)
>> library(RColorBrewer) # creates nice color schemes
>> library(classInt)
>>
>>
>> plotclr <- brewer.pal(nclr,"PuRd")
>> class <- classIntervals(NatSTSummaryHigh.abi$STMean, nclr, style="fisher" )
>> colcode <- findColours(class, plotclr)
>>
>>
>> # Plot a multi-panel map of all the states, and colour
>> xyplot(y~x | NatSTSummaryHigh.abi$PrimaryDX, data = 
>> state.center,groups=names(attr(colcode, "table")),
>>     main="High Cost States by Diagnosis ( > National Avg)",
>>     xlim = xl, ylim = yl, scales = list(draw=FALSE),
>>     aspect = "iso",
>

Re: [R] scaling with relative units in plots or retrieving axes limits in plots

2010-05-18 Thread Jannis
Thanks for the replies! If anybody  encounters a similar problem, the function 
that now does what I wanted is attached below.


Best
Jannis



trnsf.coords = function(array_x,array_y)

# This function transfers relative coordinates between 0 and 1 for two arrays 
with x
# and y values into the coordinate system of the current plot.

{
plot_extremes=par()$usr
x_min=plot_extremes[1]
x_max=plot_extremes[2]
y_min=plot_extremes[3]
y_max=plot_extremes[4]

x_trans=x_min+(array_x*x_max-x_min)
y_trans=y_min+(array_y*y_max-y_min)
output=list(x=x_trans,y=y_trans)
return(output)

}

--- Jannis  schrieb am Di, 18.5.2010:

> Von: Jannis 
> Betreff: [R] scaling with relative units in plots or retrieving axes limits 
> in plots
> An: r-h...@stat.math.ethz.ch
> Datum: Dienstag, 18. Mai, 2010 14:23 Uhr
> Dears,
> 
> 
> a way to define x and y positions in plots in relative
> numbers (e.g in fractions  between 0 and 1 referring to
> relative positions inside the plot region) would really help
> me. One example I would need this to would be to add text
> via text() to a plot always at a defined spot, e.g the upper
> left corner. Until now I always determined maximum x and y
> values and used those, but defining relative positions
> straight away would be much easier. Possible solutions:
> 
> 1. Predefined function
> Is there anything available that lets me run (for
> example):
> 
> text(0.5,0.5,'middle')
> 
> which always puts text on these relative points?
> 
> 
> 
> 2. Create my own function
> It would be straightforward to create my own function that
> translates the relative number to the axes values in the
> actual plot, so that 
> 
> text(my.function(0.5,0.5),'middle')
> 
> would do what I want. For this I would need to be able to
> somehow retrieve the axis limits for x and y axes. Is there
> any way I could do this after having called plot()?
> 
> 
> 
> Thanks for your help!
> 
> 
> Jannis
> 
> 
> 
> 
> __
> 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] scaling with relative units in plots or retrieving axes limits in plots

2010-05-18 Thread Jannis
Dears,


a way to define x and y positions in plots in relative numbers (e.g in 
fractions  between 0 and 1 referring to relative positions inside the plot 
region) would really help me. One example I would need this to would be to add 
text via text() to a plot always at a defined spot, e.g the upper left corner. 
Until now I always determined maximum x and y values and used those, but 
defining relative positions straight away would be much easier. Possible 
solutions:

1. Predefined function
Is there anything available that lets me run (for example):

text(0.5,0.5,'middle')

which always puts text on these relative points?



2. Create my own function
It would be straightforward to create my own function that translates the 
relative number to the axes values in the actual plot, so that 

text(my.function(0.5,0.5),'middle')

would do what I want. For this I would need to be able to somehow retrieve the 
axis limits for x and y axes. Is there any way I could do this after having 
called plot()?



Thanks for your help!


Jannis




__
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] scaling with relative units in plots or retrieving axes limits in plots

2010-05-18 Thread Ivan Calandra

Hi,

For 2., I don't know if it's possible to retrieve the axis limits, but 
you can surely specify them in your call to plot (with arguments xlim 
and ylim).

That's a cheap solution and others probably have better ones.

Ivan

Le 5/18/2010 16:23, Jannis a écrit :

Dears,


a way to define x and y positions in plots in relative numbers (e.g in 
fractions  between 0 and 1 referring to relative positions inside the plot 
region) would really help me. One example I would need this to would be to add 
text via text() to a plot always at a defined spot, e.g the upper left corner. 
Until now I always determined maximum x and y values and used those, but 
defining relative positions straight away would be much easier. Possible 
solutions:

1. Predefined function
Is there anything available that lets me run (for example):

text(0.5,0.5,'middle')

which always puts text on these relative points?



2. Create my own function
It would be straightforward to create my own function that translates the 
relative number to the axes values in the actual plot, so that

text(my.function(0.5,0.5),'middle')

would do what I want. For this I would need to be able to somehow retrieve the 
axis limits for x and y axes. Is there any way I could do this after having 
called plot()?



Thanks for your help!


Jannis




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

   


--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php

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