Re: [R] bug in dev.copy2pdf output?

2011-07-28 Thread Prof Brian Ripley
This is all in the help page for pdf ... including a request not to 
falsely blame R and two workarounds for the broken viewers.


On Thu, 28 Jul 2011, Duncan Murdoch wrote:


On 11-07-28 1:22 PM, selwyn quan wrote:


Hi,

Am using R 2.13.1 on Linux (Fedora). Is anybody else having problems with
dev.copy2pdf xyplot output with the pch=1 (open circle) symbol? The
symbols come out as "q" in the PDF.  dev.copy2eps produces the correct
results as does cairo_pdf. Other symbols produced with dev.copy2pdf seem
ok.



There have been reports like this before that turned out to be problems in 
the viewer, which made inappropriate font substitutions.  How did you 
determine that the circles came out as q?


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.



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

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


[R] Different result on using apply.

2011-07-28 Thread Ashim Kapoor
Dear R-helpers,

In the following example I compute ret and returns the SAME way. In ret I
use compute returns for EACH column and in returns I do it for the whole
data frame. Could someone please tell me why I see a lagged result,by which
I mean ret and returns are different by one lag.


getSymbols("GOOG",src="yahoo")
ret<-apply(GOOG,2,function(x) diff(log(x)) / lag(x,1) )
returns<-diff(log(GOOG))/lag(GOOG,1)
tail(ret)
tail(returns)

> tail(ret)
   GOOG.Open GOOG.High  GOOG.LowGOOG.Close
2011-07-21  3.188905e-05  3.065345e-05  2.882942e-05  3.022824e-05
2011-07-22  2.160452e-05  1.532645e-05  2.373743e-05  1.961091e-06
2011-07-25  1.241901e-05  5.334479e-06  1.119182e-05  9.213213e-06
2011-07-26 -2.279176e-06 -1.672208e-05 -3.306823e-05 -3.997397e-05
2011-07-27 -3.178693e-05 -1.294157e-05 -4.791985e-06  1.005828e-05
2011-07-28  1.060350e-05  2.464065e-05  2.583624e-05  5.395451e-05
 GOOG.Volume GOOG.Adjusted
2011-07-21  4.835664e-09  3.022824e-05
2011-07-22 -3.379734e-08  1.961091e-06
2011-07-25 -9.265378e-08  9.213213e-06
2011-07-26  2.212510e-07 -3.997397e-05
2011-07-27 -5.989484e-08  1.005828e-05
2011-07-28  7.472583e-09  5.395451e-05
> tail(returns)
   GOOG.Open GOOG.High  GOOG.LowGOOG.Close
2011-07-21 -2.262875e-05  1.432963e-05 -3.784855e-06  3.252347e-05
2011-07-22  3.188905e-05  3.065345e-05  2.882942e-05  3.022824e-05
2011-07-25  2.160452e-05  1.532645e-05  2.373743e-05  1.961091e-06
2011-07-26  1.241901e-05  5.334479e-06  1.119182e-05  9.213213e-06
2011-07-27 -2.279176e-06 -1.672208e-05 -3.306823e-05 -3.997397e-05
2011-07-28 -3.178693e-05 -1.294157e-05 -4.791985e-06  1.005828e-05
 GOOG.Volume GOOG.Adjusted
2011-07-21  1.988491e-07  3.252347e-05
2011-07-22  4.835664e-09  3.022824e-05
2011-07-25 -3.379734e-08  1.961091e-06
2011-07-26 -9.265378e-08  9.213213e-06
2011-07-27  2.212510e-07 -3.997397e-05
2011-07-28 -5.989484e-08  1.005828e-05
>

Many thanks for your help.

[[alternative HTML version deleted]]

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


Re: [R] Looping through data sets to change column from character to numeric

2011-07-28 Thread Rolf Turner

On 29/07/11 11:09, Sarah Henderson wrote:

Greetings to all --

I am having a silly problem that I just can't solve.  Someone has given me
an .RData file will hundreds of data frames.  Each data frame has a column
named ResultValue, currently character when it should be numeric.  I want to
loop through all of the data frames to change the variable to numeric, but I
cannot figure out how to do it. My best guess was along the lines of:

frames = ls()
for (frame in frames){
  assign(frame, get(frame), .GlobalEnv)
  frame[,"ResultValue"] = as.numeric(frame[,"ResultValue"])
  }



Note that ``frame'' is an object the value of which is a character string
naming (successive) data frames. Your call to assign doesn't change the
value of ``frame''.  It *could* (but doesn't actually) change the value 
of the

object *named* by the character string stored in ``frame''.

Suppose that you have data frames clyde, melvin, and irving.  On your 
first pass

through the loop the value of frame is the character string ``clyde''.

Your assign() call in effect does ``clyde <- clyde'' which doesn't 
accomplish

much. :-)

The value of frame after the assign() is still the character string 
``clyde''.

I.e. frame is a character scalar, so frame[,"ResultValue"] doesn't make any
sense.

What you need to do is something like:

frames <- ls()
for(frame in frames) {
assign("temp",get(frame)) # Don't think you need the 
``.GlobalEnv'', although it doesn't hurt.

temp[,ResultValue"] <- as.numeric(temp[,"ResultValue"])
assign(frame,temp)
}

This is untested 

But I hope it helps.

cheers,

Rolf Turner

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


Re: [R] Lowest values in a vector of numbers

2011-07-28 Thread Dennis Murphy
> x <- rpois(50, 10)
> which(x <= quantile(x, 0.2))
 [1]  7 14 16 24 25 28 33 44 45 48
> x[which(x <= quantile(x, 0.2))]
 [1] 6 5 4 5 7 7 4 5 6 7
> quantile(x, 0.2)
20%
7.8

HTH,
Dennis

On Thu, Jul 28, 2011 at 9:42 PM, Jim Silverton  wrote:
> I have a vector of numbers, and I will like to find the positions of the
> lowest 20% of the values. Can anyhow point out how to do this. I tried the
> ecdf function but to no avail.
>
>
>
> --
> Thanks,
> Jim.
>
>        [[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] order a data frame after date and hour

2011-07-28 Thread Dennis Murphy
Hi:

On Thu, Jul 28, 2011 at 1:05 AM, anglor  wrote:
> Hi,
>
> I've got a dataframe looking like this:
>
>                DateHour TcuvInt.A TcuvInt.B TcuvInt.C
> 1757 2007-03-15 14:00:00                7.83      
> 1758 2007-03-15 14:30:00      7.42      7.69      
> 1759 2007-03-15 15:00:00      7.53      7.75      
> 1760 2007-03-15 15:30:00      7.65      7.73      
>
>
> and I need to sort it after the DateHour variable. It is mostly sorted
> already except that in the end there is X dates that should be in the
> beginning. I tried to find a way to convert the datehour to a number, looked
> at format but it didn't work for me.

See ?DateTimeClasses for an overview of the various date/time classes
available in R. I'd suggest looking into as.POSIXct() and strptime()
for starters. Make sure you try several examples. If your library has
Phil Spector's book 'Data Manipulation with R', there is a very nice
chapter on dealing with date-time variables.
>
> Any suggestions?
>
> And also, I'm quite new at R and this forum, someone suggested I use
>
> df <- data.frame(x = 1:4, y = rnorm(4), z = rpois(4, 3))
> structure(list(x = 1:4, y = c(-0.24950486967999, 0.151728291232845,
> 1.24654200540763, 2.30868457813145), z = c(3, 5, 2, 5)), .Names = c("x",
> "y", "z"), row.names = c(NA, -4L), class = "data.frame")
> dput(df)
>
> for a better display of my problem but I don't understand what this does?

What it does is transfer the content and structure of your data into a
text form that people can copy and paste directly into their R
sessions, with the confidence that the data they're looking at is the
same as what you see. This matters especially for date/time, character
or factor data, where copying and pasting the contents of your R
console into an e-mail can well lose the structure of those types of
objects in translation.

For the example you gave, I can copy and paste the dput() output into
my session to get

df <- structure(list(x = 1:4, y = c(-0.24950486967999, 0.151728291232845,
 1.24654200540763, 2.30868457813145), z = c(3, 5, 2, 5)), .Names = c("x",
 "y", "z"), row.names = c(NA, -4L), class = "data.frame")
df
  x  y z
1 1 -0.2495049 3
2 2  0.1517283 5
3 3  1.2465420 2
4 4  2.3086846 5
str(df)
'data.frame':   4 obs. of  3 variables:
 $ x: int  1 2 3 4
 $ y: num  -0.25 0.152 1.247 2.309
 $ z: num  3 5 2 5

which should be exactly what you see if you type the above code into
your R console. This is what is meant by a 'reproducible example' (at
least the data side of it...)

Unfortunately, I don't know whether the DateHour variable you copied
and pasted into your e-mail is character, factor or one of several
possible date-time classes. Had you used dput() on that data, you
certainly would have had a satisfactory answer by now. Justin gave the
most probable solution, but even he was uncertain about the class of
the DateHour variable, with good reason.

HTH,
Dennis
>
> Thank you for help!
>
> Angelica
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/order-a-data-frame-after-date-and-hour-tp3700721p3700721.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] Lowest values in a vector of numbers

2011-07-28 Thread Jim Silverton
I have a vector of numbers, and I will like to find the positions of the
lowest 20% of the values. Can anyhow point out how to do this. I tried the
ecdf function but to no avail.



-- 
Thanks,
Jim.

[[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] apply is making me crazy...

2011-07-28 Thread Dennis Murphy
Hi Gene:

I would encourage you to take some time to write a general-purpose
function that does exception handling and deals with one-column
matrices properly. Since you have nested lists of matrices, operations
like lapply() and perhaps more usefully, rapply(), could well be
productive.

Dennis

On Thu, Jul 28, 2011 at 9:19 AM, Gene Leynes  wrote:
> Dennis,
> ninety
>
> Thanks, I did try almost exactly the same thing.  I decided it was too
> complicated, especially since I have a whole mess of functions I want to use
> this way.  You see, I usually work with lists of lists of matrices that are
> dimensioned by simulations X time, so there's usually a one column matrix at
> the bottom of the list.  So, I really want a general solution because I use
> it all the time.
>
> For now I'm going to stick with for loops, they work fine and are more clear
> in the unlikely event that anyone else ever looks at my code.   The loops
> just take up more space / are harder to read.
>
> for example:
>     for(i in 1:nrow(mat))
>         mat[i,] = cumsum(mat[i,])/(1:ncol(mat))
>
>
>
> On Wed, Jul 27, 2011 at 9:30 PM, Dennis Murphy  wrote:
>>
>> Hi:
>>
>> Try this:
>>
>> exampGood = lapply(2:4, function(x) matrix(rnorm(10 * x), ncol = x))
>> exampBad  = lapply(1:3, function(x) matrix(rnorm(10 * x), ncol = x))
>>
>> csfun <- function(m) {
>>    if(ncol(m) == 1L) {return(m)} else {
>>    t(as.matrix(apply(m, 1, cumsum)))
>>   }
>>  }
>>
>> lapply(exampGood, csfun)
>> lapply(exampBad, csfun)
>>
>> HTH,
>> Dennis
>>
>> On Wed, Jul 27, 2011 at 3:22 PM, Gene Leynes  wrote:
>> > I have tried a lot of ways around this, but I can't find a way to make
>> > apply
>> > work in a generalized way because it causes a failure whenever reduces
>> > the
>> > dimensions of its output.
>> > The following example is easier to understand than the question.
>> >
>> > I wish it had a "drop=TRUE/FALSE" option like the "["  (and I wish I had
>> > found the drop option a year ago, and I wish that I had 1e6 dollars...
>> > Oops,
>> > I mean euros).
>> >
>> >
>> >    ## Make three example matricies
>> >    exampGood = lapply(2:4, function(x)matrix(rnorm(1000*x),ncol=x))
>> >    exampBad  = lapply(1:3, function(x)matrix(rnorm(1000*x),ncol=x))
>> >    ## Two ways to see what was created:
>> >    for(k in 1:length(exampGood)) print(dim(exampGood[[k]]))
>> >    for(k in 1:length(exampBad)) print(dim(exampBad[[k]]))
>> >
>> >    ##  Take the cumsum of each row of each matrix
>> >    answerGood = lapply(exampGood, function(x) apply(x ,1,cumsum))
>> >    answerBad  = lapply(exampBad, function(x) apply(x ,1,cumsum))
>> >    str(answerGood)
>> >    str(answerBad)
>> >
>> >    ##  Take the first element of the final column of each answer
>> >    for(mat in answerGood){
>> >        LastColumn = ncol(mat)
>> >        print(mat[1,LastColumn])
>> >    }
>> >    for(mat in answerBad){
>> >        LastColumn = ncol(mat)
>> >        print(mat[1,LastColumn])
>> >    }
>> >
>> >        [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>
>

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


Re: [R] How to adjust the order of one-way table ?

2011-07-28 Thread David Winsemius


On Jul 28, 2011, at 10:51 PM, Jeff Zhang wrote:


Hi all,

I wan to make a bar chart for a one-way table, but it seems the bar  
is in
the order of alphabet which is my expectation, how can I adjust the  
order of

the one-way table.


Make it a factor with the desired order in its levels.

?factor


--
David Winsemius, MD
West Hartford, CT

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


Re: [R] hdf5 library install issue

2011-07-28 Thread Yitping Kok
I have had the same problem. It seems that you need to configure the
make option with a file. Create a file, ~/.R/Makevars, and insert
"LDFLAGS=-L/share/apps/HDF5/lib" (in your case) into it. It solved my
problem.

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


[R] How to adjust the order of one-way table ?

2011-07-28 Thread Jeff Zhang
Hi all,

I wan to make a bar chart for a one-way table, but it seems the bar is in
the order of alphabet which is my expectation, how can I adjust the order of
the one-way table.

Thanks


-- 
Best Regards

Jeff Zhang

[[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, ctree and categorical variables

2011-07-28 Thread seanstclair

   I am running the ctree function in R.



   My data has about 10 variables, many of which are categorical.  2 of the
   categorical variables have many levels (one has 900 levels, another has
   1,000 levels).  As an example, 1 of these variables is disease code and is
   structured as A, B, C, , AA, AB, AC



   Each time i've tried to run the ctree function, including these 2 variables
   in  the data, the function never stops running.  When i remove these 2
   variables from the data and run without them, the function returns in about
   3 seconds.



   Q:  Is there a limit to the amount of levels that a categorical variable can
   contain?  Is there something else that i may be overlooking?





   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] unlist?

2011-07-28 Thread David Winsemius


On Jul 28, 2011, at 8:59 PM, Penny Bilton wrote:

How do I unlist from the r-help email group? I have tried to follow  
the instrictions on the website with no success.


Really?. Describe in excruciating detail what you did, please. (It has  
worked for everyone else.)


I sent the password code from my confirmation email to   r-help-ow...@r-project.org 
   and received a return email with the message  "unprocessed".


Well, I'm fairly sure that is _not_ the method that is recommended at  
the website.



Thank you
Penny.



--
David Winsemius, MD
West Hartford, CT

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


Re: [R] cycling from x11 window in RCommander to graphics device window: Mac Os 10.6.8

2011-07-28 Thread John Fox
Dear Simon,

On Thu, 28 Jul 2011 17:32:45 -0400
 Simon Kiss  wrote:
> Dear John,
> The Command Tab does not work for me, but I have been able to get expose to 
> work. I.e. it does bring up all windows, including the x11 terminal.  It will 
> take a little getting used to, but it is functional.

I didn't understand that you're running R from an X11 terminal (if I now 
understand correctly and that's the case). If so, that's not necessary. You 
should be able to run the Rcmdr from R.app or R64.app, and X11, without a 
terminal window, will start automatically.

Best,
 John

> I apologize for cluttering the list with minutiae
> Thank you!
> Yours
> S.
> On 2011-07-28, at 5:21 PM, John Fox wrote:
> 
> > Dear Simon,
> > 
> > I'm sitting in front of a MacBook Pro and Command-tab works perfectly fine 
> > for me: Selecting X11 brings the R Commander Window to the front, and 
> > selecting R brings the Quartz graphics window to the front. I must admit 
> > that my habit in classroom demonstrations on a Mac is to use Expose to 
> > select Windows, but, unless I misunderstand your problem, Command-tab also 
> > works.
> > 
> > I'm using R 2.13.1 under Mac OS X 10.6.7 with XQuartz 2.3.6 and 
> > tcltk-8.5.5-x11.
> > 
> > I hope this helps,
> > John
> > 
> > 
> > John Fox
> > Sen. William McMaster Prof. of Social Statistics
> > Department of Sociology
> > McMaster University
> > Hamilton, Ontario, Canada
> > http://socserv.mcmaster.ca/jfox/
> > On Thu, 28 Jul 2011 13:40:11 -0400
> > Simon Kiss  wrote:
> >> Dear Colleagues, 
> >> I have recently installed R Commander on my Mac OS 10.6.8. I'd like to use 
> >> it for an undergraduate class this year.
> >> Everything appears to be working fine, except for one thing.  I cannot use 
> >> Command-tab to cycle from the X11 window in which RCommander is running to 
> >> any other window open in my workspace.  This is particularly important 
> >> because I cannot cycle to the graphics device window that is opened when I 
> >> call a new plot.  If I force quit the X11 window and Rcommander, R remains 
> >> running and I can see the graphics device window and the plot looks fine.
> >> But as you can imagine, this is quite laborious, having to restart.
> >> I've looked through the help documentation and tried reinstalling tcltk 
> >> prior to opening up Rcommander, but that does not address the problem.
> >> Any thoughts?
> >> Yours, Simon Kiss
> >> *
> >> Simon J. Kiss, PhD
> >> Assistant Professor, Wilfrid Laurier University
> >> 73 George Street
> >> Brantford, Ontario, Canada
> >> N3T 2C9
> >> Cell: +1 905 746 7606
> >> 
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide 
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> > 
> > 
> 
> *
> Simon J. Kiss, PhD
> Assistant Professor, Wilfrid Laurier University
> 73 George Street
> Brantford, Ontario, Canada
> N3T 2C9
> Cell: +1 905 746 7606
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] unlist?

2011-07-28 Thread Penny Bilton
How do I unlist from the r-help email group? I have tried to follow the 
instrictions on the website with no success.


I sent the password code from my confirmation email to   
r-help-ow...@r-project.org   and received a return email with the 
message  "unprocessed".



Thank you
Penny.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] smooth scatterplot and geo map

2011-07-28 Thread Leo Guelman
check smooth.ppp{spatstat}  which performs spatial smoothing based on a
Gaussian kernel...it has a plot method that may do what you are looking for

hope this helps,
Leo.

On Thu, Jul 28, 2011 at 4:09 PM, marco  wrote:

> Hello everybody,
> I'm trying to understand how to draw a smoothed scatterplot on a geographic
> map with R.
> Have a dataframe with point locations (long, lat) and was able to simply
> plot these points on a shp map by using the maptools package. However,
> instead of having simply the raw points on the map, I would like to have a
> "smoothed" scatterplot of the same superimposed on the map. Tried with the
> smoothScatter function, but really have no idea how to combine the map with
> the resulting graph.
> tx in adv
> marco
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/smooth-scatterplot-and-geo-map-tp3702374p3702374.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] Looping through data sets to change column from character to numeric

2011-07-28 Thread Sarah Henderson
Thanks for the explainable, Denes.  Your solution worked a charm.  I should
have seen things more clearly, but sometimes I just get stuck in a rut.

The help of this list is always appreciated -- such a fantastic resource.

Cheers,

Sarah



2011/7/28 "Dénes TÓTH" 

>
> Sorry, I was wrong. Of course you can assign a variable to itself, but it
> does not make much sense...
> What you misunderstood was that in the assignment you assign the data
> frame (e.g. "df1") to itself. You do not modify the frame object which
> remains a character string.
>
>
> >
> > The problem is that you can not assign a variable to itself.
> >
> > rm(list=ls())
> > df1 <- data.frame(ResultValue=as.character(1:5))
> > df2 <- data.frame(ResultValue=as.character(1:10))
> > frames = ls()
> > for (frame in frames){
> >  temp <- get(frame)
> >  temp[,"ResultValue"] = as.numeric(temp[,"ResultValue"])
> >  assign(frame,temp)
> > }
> >
> > HTH,
> >   Denes
> >
> >
> >
> >> Greetings to all --
> >>
> >> I am having a silly problem that I just can't solve.  Someone has given
> >> me
> >> an .RData file will hundreds of data frames.  Each data frame has a
> >> column
> >> named ResultValue, currently character when it should be numeric.  I
> >> want
> >> to
> >> loop through all of the data frames to change the variable to numeric,
> >> but
> >> I
> >> cannot figure out how to do it. My best guess was along the lines of:
> >>
> >> frames = ls()
> >> for (frame in frames){
> >>  assign(frame, get(frame), .GlobalEnv)
> >>  frame[,"ResultValue"] = as.numeric(frame[,"ResultValue"])
> >>  }
> >>
> >> It doesn't work.  After the assign() the frame object remains the
> >> character
> >> name of the dataframe I am trying to change.  If I do the following, the
> >> TEST object comes out just fine.
> >>
> >> frames = ls()
> >> for (frame in frames){
> >>  assign("TEST", get(frame), .GlobalEnv)
> >>  TEST[,"ResultValue"] = as.numeric(TEST[,"ResultValue"])
> >>  }
> >>
> >> Seems like it should be simple, but I am misunderstanding something and
> >> not
> >> following the logic.  Any insight?
> >>
> >> Thanks,
> >>
> >> Sarah
> >>
> >>  [[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.
> >
>
>

[[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] Looping through data sets to change column from character to numeric

2011-07-28 Thread Dénes TÓTH

Sorry, I was wrong. Of course you can assign a variable to itself, but it
does not make much sense...
What you misunderstood was that in the assignment you assign the data
frame (e.g. "df1") to itself. You do not modify the frame object which
remains a character string.


>
> The problem is that you can not assign a variable to itself.
>
> rm(list=ls())
> df1 <- data.frame(ResultValue=as.character(1:5))
> df2 <- data.frame(ResultValue=as.character(1:10))
> frames = ls()
> for (frame in frames){
>  temp <- get(frame)
>  temp[,"ResultValue"] = as.numeric(temp[,"ResultValue"])
>  assign(frame,temp)
> }
>
> HTH,
>   Denes
>
>
>
>> Greetings to all --
>>
>> I am having a silly problem that I just can't solve.  Someone has given
>> me
>> an .RData file will hundreds of data frames.  Each data frame has a
>> column
>> named ResultValue, currently character when it should be numeric.  I
>> want
>> to
>> loop through all of the data frames to change the variable to numeric,
>> but
>> I
>> cannot figure out how to do it. My best guess was along the lines of:
>>
>> frames = ls()
>> for (frame in frames){
>>  assign(frame, get(frame), .GlobalEnv)
>>  frame[,"ResultValue"] = as.numeric(frame[,"ResultValue"])
>>  }
>>
>> It doesn't work.  After the assign() the frame object remains the
>> character
>> name of the dataframe I am trying to change.  If I do the following, the
>> TEST object comes out just fine.
>>
>> frames = ls()
>> for (frame in frames){
>>  assign("TEST", get(frame), .GlobalEnv)
>>  TEST[,"ResultValue"] = as.numeric(TEST[,"ResultValue"])
>>  }
>>
>> Seems like it should be simple, but I am misunderstanding something and
>> not
>> following the logic.  Any insight?
>>
>> Thanks,
>>
>> Sarah
>>
>>  [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] Looping through data sets to change column from character to numeric

2011-07-28 Thread Dénes TÓTH

The problem is that you can not assign a variable to itself.

rm(list=ls())
df1 <- data.frame(ResultValue=as.character(1:5))
df2 <- data.frame(ResultValue=as.character(1:10))
frames = ls()
for (frame in frames){
 temp <- get(frame)
 temp[,"ResultValue"] = as.numeric(temp[,"ResultValue"])
 assign(frame,temp)
}

HTH,
  Denes



> Greetings to all --
>
> I am having a silly problem that I just can't solve.  Someone has given me
> an .RData file will hundreds of data frames.  Each data frame has a column
> named ResultValue, currently character when it should be numeric.  I want
> to
> loop through all of the data frames to change the variable to numeric, but
> I
> cannot figure out how to do it. My best guess was along the lines of:
>
> frames = ls()
> for (frame in frames){
>  assign(frame, get(frame), .GlobalEnv)
>  frame[,"ResultValue"] = as.numeric(frame[,"ResultValue"])
>  }
>
> It doesn't work.  After the assign() the frame object remains the
> character
> name of the dataframe I am trying to change.  If I do the following, the
> TEST object comes out just fine.
>
> frames = ls()
> for (frame in frames){
>  assign("TEST", get(frame), .GlobalEnv)
>  TEST[,"ResultValue"] = as.numeric(TEST[,"ResultValue"])
>  }
>
> Seems like it should be simple, but I am misunderstanding something and
> not
> following the logic.  Any insight?
>
> Thanks,
>
> Sarah
>
>   [[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] Reading name-value data

2011-07-28 Thread Hadley Wickham
Use plyr::rbind.fill?   That does match up columns by name.
Hadley

On Thu, Jul 28, 2011 at 5:23 PM, Stavros Macrakis  wrote:
> I have a file of data where each line is a series of name-value pairs, but
> where the names are not necessarily the same from line to line, e.g.
>    a=1,b=2,d=5
>    b=4,c=3,e=3
>    a=5,d=1
> I would like to create a data frame which lines up the data in the
> corresponding columns.  In this case, this would be
>    data.frame( a = (1, NA, 4), b = (2, 4, NA), c = (NA, 3, NA), d = (5, NA,
> 1), e = (NA, 3, 1) )
> One way I can think of doing this is to read in the data as one 'long' data
> frame per line with a unique ID, e.g. line one becomes
>      cbind(id=1,data.frame(variable=c('a','b','d'),value=c(1,2,5)))
> then rbind all the lines and use the reshape package function 'cast'.
> Is there a more straightforward way?  (I'd have thought rbind would line up
> columns by name, but it doesn't.)
>             -s
>
> --
> You received this message because you are subscribed to the Google Groups
> "manipulatr" group.
> To post to this group, send email to manipul...@googlegroups.com.
> To unsubscribe from this group, send email to
> manipulatr+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/manipulatr?hl=en.
>



-- 
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] not working yet: Re: lattice overlay

2011-07-28 Thread Duncan Mackay

At 21:50 28/07/2011, you wrote:

Hi Dieter and R community:

I tried both of these three versions with ylim as suggested, none work:  I
am getting only single (pch = 16) not overlayed (pch =3) everytime.

*vs 1*

require(lattice)

xyplot(Sepal.Length ~ Sepal.Width | Species , data= iris,

  panel= function(x, y, subscripts) {

panel.xyplot(x, y, pch=16, col = "green4", ylim = c(0, 10))

panel.lmline(x, y, lty=4, col = "green4")

panel.xyplot (iris$Petal.Length [subscripts],
iris$Petal.Width[subscripts], pch= 3, col = "red")

panel.lmline(iris$Petal.Length [subscripts], iris$Petal.Width
[subscripts], col = "red")

}, as.table=T, subscripts=T)


*vs 2*

require(lattice)

xyplot(Sepal.Length ~ Sepal.Width | Species , data= iris,

  panel= function(x, y, subscripts) {

panel.xyplot(x, y, pch=16, col = "green4", ylim = c(0, 10))

panel.lmline(x, y, lty=4, col = "green4")


panel.xyplot (iris$Petal.Length [subscripts], iris$Petal.Width[subscripts],
pch= 3, col = "red", ylim = c(0,10)

 )

panel.lmline(iris$Petal.Length [subscripts], iris$Petal.Width
[subscripts], col = "red")

}, as.table=T, subscripts=T)



*vs 3*

require(lattice)

xyplot(Sepal.Length ~ Sepal.Width | Species , data= iris,

  panel= function(x, y, subscripts) {

panel.xyplot(x, y, pch=16, col = "green4")

panel.lmline(x, y, lty=4, col = "green4")


panel.xyplot (iris$Petal.Length [subscripts], iris$Petal.Width[subscripts],
pch= 3, col = "red", ylim= c(0,10)

 )

panel.lmline(iris$Petal.Length [subscripts], iris$Petal.Width
[subscripts], col = "red")

}, as.table=T, subscripts=T)

Help please:


From: Dieter Menne 
> Date: Wed, Jul 27, 2011 at 8:44 AM
> Subject: Re: [R] lattice overlay
> To: r-help@r-project.org
>
>
>
>
> Ram H. Sharma wrote:
> >
> > I want to overlay lattice scatter plot: I do not know why the following
> > code
> > is not plotting subscripts ! Sorry if this question is too simple:
> >
> > Working example shortened:
> >
> > .panel.xyplot(x, y, pch=16, col = "green4", ylim = c(0, 10))
> >
> >
>
> Because they are out of range. Put ylim outside the panel, and it works.
>
> Dieter
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/lattice-overlay-tp3698303p3698357.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.
>
>


--

Ram H

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


I have come late to this and must now go but try below:
You may not have seen everything plotted because of panel limits in x 
and y and setting type to "r" will save a line + putting it in the 
main argument will need ...
If you want special axis limits check out the latticeExtra package or 
search for axis limits in previous posts eg ? 
http://finzi.psych.upenn.edu/R/Rhelp02/archive/43626.html


xyplot(Sepal.Length ~ Sepal.Width | Species , data= iris,
   as.table=T,
   subscripts=T,
   ylim = c(0,10),
   xlim = c(0,10),
   type = c("p","r"),
   panel= function(x, y, subscripts, ...) {

panel.xyplot(x, y, pch=16, col = "green4",...)

panel.xyplot(x=iris$Petal.Length[subscripts], 
y=iris$Petal.Width[subscripts], col = "red",...)



  }
)

Regards

Duncan Mackay

Regards

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
ARMIDALE NSW 2351
Email: home mac...@northnet.com.au

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Can R (without GUI) be compiled with static linking?

2011-07-28 Thread Duncan Murdoch

On 28/07/2011 5:54 PM, Jonathan Callahan wrote:

I have a potential client that is considering R for data analysis and
visualization modules within a larger framework. The host systems run either
Solaris or a version of Linux.


Hopefully this client will respect the R license, and license their 
larger framework in a compatible way.




One of their requirements (hard or soft?) is that each module in the
framework be compiled with statically linked libraries into a standalone
binary that can be run from the command line.

I intend to recommend using R for many of their analytical components. I
will recommend setting up a full R environment and packaging up new
functionality for easy deployment. Then they can simply use R in batch
mode:  R --vanilla  xyz.out

But if they insist on only using modules that are stand-alone, statically
linked binaries I will need answers to the following questions:

1) Are the distributed R binaries statically linked?


I think this depends on the target platform, but clearly the answer is: 
 just look at the one that interests you.



2) Is the R code that runs in batch mode statically linked? (i.e. Will it
break depending upon what shared libraries are installed?)


It will be the same as the rest of the install.


3) Is it possible to create a statically linked R that can be run "in batch
mode"?


I believe so.


4) If not, how much C (or python? ;-D) code do I have to write to get to the
point of having a stand-alone binary that can follow the instructions in an
R script?


See the "Writing R Extensions" manual chapter on front ends.

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] Looping through data sets to change column from character to numeric

2011-07-28 Thread Sarah Henderson
Greetings to all --

I am having a silly problem that I just can't solve.  Someone has given me
an .RData file will hundreds of data frames.  Each data frame has a column
named ResultValue, currently character when it should be numeric.  I want to
loop through all of the data frames to change the variable to numeric, but I
cannot figure out how to do it. My best guess was along the lines of:

frames = ls()
for (frame in frames){
 assign(frame, get(frame), .GlobalEnv)
 frame[,"ResultValue"] = as.numeric(frame[,"ResultValue"])
 }

It doesn't work.  After the assign() the frame object remains the character
name of the dataframe I am trying to change.  If I do the following, the
TEST object comes out just fine.

frames = ls()
for (frame in frames){
 assign("TEST", get(frame), .GlobalEnv)
 TEST[,"ResultValue"] = as.numeric(TEST[,"ResultValue"])
 }

Seems like it should be simple, but I am misunderstanding something and not
following the logic.  Any insight?

Thanks,

Sarah

[[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] bug in dev.copy2pdf output?

2011-07-28 Thread selwyn quan



On Fri, 29 Jul 2011, Rolf Turner wrote:


On 29/07/11 09:51, selwyn quan wrote:


On Thu, 28 Jul 2011, Duncan Murdoch wrote:


On 11-07-28 1:22 PM, selwyn quan wrote:


Hi,

Am using R 2.13.1 on Linux (Fedora). Is anybody else having problems 
with

dev.copy2pdf xyplot output with the pch=1 (open circle) symbol? The
symbols come out as "q" in the PDF.  dev.copy2eps produces the correct
results as does cairo_pdf. Other symbols produced with dev.copy2pdf 
seem

ok.



There have been reports like this before that turned out to be problems 
in the viewer, which made inappropriate font substitutions.  How did 
you determine that the circles came out as q?


Duncan Murdoch



You are right. Think it is a bug in Fedora's evince. Acrobat reader 
renders the PDF fine.


FWIW, evince on my Ubuntu system renders the points correctly as open 
circles.


   cheers,

   Rolf Turner



see this bug report for a more detailed explanation:

https://bugs.freedesktop.org/show_bug.cgi?id=18002

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 use as.Date (or something else) with "31-Jul-2010 23:59:00"

2011-07-28 Thread Eduardo M. A. M.Mendes
Hello

Many thanks.

Sorry for not replying earlier but I have followed advice and read as much
documentation as I could.

I managed to get a zoo object the way I want

dadoszoo : 'zoo' series from 2010-06-27 to 2010-08-05
  Data: num [1:56161, 1:14] 74 74.2 74.2 74.1 73.9 ...
  Index:  POSIXct[1:56161], format: "2010-06-27 00:00:00" "2010-06-27
00:01:00" ...

I did not manage to get  plot.zoo to give x-axis a nice format (I only got
Jun 30 Jul10 Jul 20 Jul 30).  I guess the way to change it is the
documentation too but I am yet to find it.

Many thanks

Ed


-Original Message-
From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] 
Sent: Tuesday, July 26, 2011 8:31 PM
To: Eduardo Mendes
Cc: r-help@r-project.org
Subject: Re: [R] How to use as.Date (or something else) with "31-Jul-2010
23:59:00"

On Tue, Jul 26, 2011 at 7:18 PM, Eduardo Mendes 
wrote:
> Hello  again
>
> I do apologize for the previous email without any useful information 
> that can lead to an answer.  To those who felt offended by "to no 
> avail", I do apologize again.  I guess I will be always a newbie as 
> far as R is concerned.
>
>
> The date format was wrong and although I have tried to use different 
> formats I could not get the result I wanted.  So I went back to the 
> file and changed to a format that R can understand (Please understand 
> that R is very likely to have package that I might be unaware of).  
> Now all dates are
>
>> class(data$TempDate)
> [1] "POSIXct" "POSIXt"
>> data$TempDate[1:2]
> [1] "2010-06-27 00:00:00 BRT" "2010-06-27 00:01:00 BRT"
>
> If I issue the command as.Date(data$TempDate[2]), the information on 
> hour, minute and second is lost
>
> as.Date(data$TempDate[2])
> [1] "2010-06-27"
>
> If I use data$TempDate in a zoo object, I got the following msg
>
> some methods for "zoo" objects do not work if the index entries in
'order.by'
> are not unique
>
> If I issue plot(zoo object), the result is a mess since many values do 
> not have an unique entry (as expected).
>
> How can I use the information on data$TempDate to create unique 
> indexes for zoo objects and the like?
>

Read R News 4/1 and its references to find out about R's date time classes
and then read the 5 vignettes (PDF documents) that come with zoo for many
examples.

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Why won't R CMD CHECK run configure?

2011-07-28 Thread Alexander James Rickett
I'm trying to get ready to submit a package to CRAN, but in order for the 
package to install on OS X, I need to temporarily set an environment variable.  
I put this in the  'configure' script, and 'R CMD INSTALL MyPackage' works 
fine, but when I do 'R CMD CHECK MyPackage', and it tests installation, the 
configure script doesn't run and consequently the installation fails.  Should I 
be setting the variable another way?  It passes all the other checks, and it 
will install outside of check, so could I just submit it as is?

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] grey colored lines and overwriting labels i qqplot2

2011-07-28 Thread Brian Diggs

On 7/25/2011 8:27 PM, Sigrid wrote:

Thank you Brian.

Sorry for being such a noob. I am not a programmer and just learning R by
myself. This is was I typed, but ended up with a couple error messages.


df<-structure(list(year = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,

+ 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
+ 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
+ 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
+ 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
+ 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L,
+ 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
+ 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
+ 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
+ 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
+ 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), treatment =
structure(c(1L,
+ 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L,
+ 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L,
+ 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L,
+ 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L,
+ 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L,
+ 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L,
+ 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L,
+ 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 2L,
+ 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L,
+ 7L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L,
+ 6L, 6L, 6L, 7L, 7L, 7L), .Label = c("A", "B", "C", "D", "E",
+ "F", "G"), class = "factor"), total = c(135L, 118L, 121L, 64L,
+ 53L, 49L, 178L, 123L, 128L, 127L, 62L, 129L, 126L, 99L, 183L,
+ 45L, 57L, 45L, 72L, 30L, 71L, 123L, 89L, 102L, 60L, 44L, 59L,
+ 124L, 145L, 126L, 103L, 67L, 97L, 66L, 76L, 108L, 36L, 48L, 41L,
+ 69L, 47L, 57L, 167L, 136L, 176L, 85L, 36L, 82L, 222L, 149L, 171L,
+ 145L, 122L, 192L, 136L, 164L, 154L, 46L, 57L, 57L, 70L, 55L,
+ 102L, 111L, 152L, 204L, 41L, 46L, 103L, 156L, 148L, 155L, 103L,
+ 124L, 176L, 111L, 142L, 187L, 43L, 52L, 75L, 64L, 91L, 78L, 196L,
+ 314L, 265L, 44L, 39L, 98L, 197L, 273L, 274L, 89L, 91L, 74L, 91L,
+ 112L, 98L, 140L, 90L, 121L, 120L, 161L, 83L, 230L, 266L, 282L,
+ 35L, 53L, 57L, 315L, 332L, 202L, 90L, 79L, 89L, 67L, 116L, 109L,
+ 44L, 68L, 75L, 29L, 52L, 52L, 253L, 203L, 87L, 105L, 234L, 152L,
+ 247L, 243L, 144L, 167L, 165L, 95L, 300L, 128L, 125L, 84L, 183L,
+ 88L, 153L, 185L, 175L, 226L, 216L, 118L, 118L, 94L, 224L, 259L,
+ 176L, 175L, 147L, 197L, 141L, 176L, 187L, 87L, 92L, 148L, 86L,
+ 139L, 122L), country = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L,
+ 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L,
+ 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
+ 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
+ 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
+ 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
+ 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
+ 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
+ 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
+ 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
+ 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
+ ), .Label = c("high", "low"), class = "factor")), .Names = c("year",
+ "treatment", "total", "country"), class = "data.frame", row.names = c(NA,
+ -167L))


OK, here you have created a data.frame named "df".  It has four columns: 
year, treatment, total, and country. year is 1, 2, 3, or 4. treatment is 
a factor with values "A", "B", "C", "D", "E", "F", or "G". total is a 
number (integer). country is a factor with values "high" or "low".




dput(lines)

Error: unexpected '>' in ">"


The ">" at the beginning of this line represented the prompt; it was not 
supposed to be typed in.



structure(list(`Line #` = 1:6, country = structure(c(2L, 2L,

+ 2L, 1L, 1L, 1L), .Label = c("High", "Low"), class = "factor"),
+  treatment = structure(c(1L, 2L, 3L, 1L, 2L, 3L), .Label = c("A",
+  "B", "C"), class = "factor"), Intercept = c(81.47, 31.809,
+  69.892, 67.024, 17.357, 105.107), Slope = c(47.267, 20.234,
+  33.717, 47.267, 20.234, 33.717)), .Names = c("Line #", "country",
+ "treatment", "Intercept", "Slope"), class = "data.frame", row.names =
c(NA,
+ -6L))


And this was the output of the dput command.  If you want to recreate 
lines, you need:



lines <-
structure(list(`Line #` = 1:6, country = structure(c(2L, 2L,
2L, 1L, 1L, 1L), .Label = c("High", "Low"), class = "factor"),
treatment = structure(c(1L, 2L, 3L, 1L, 2L, 3L), .Label = c("A",
"B", "C"), class = "factor"), Intercept = c(81.47, 31.809,
69.892, 67.024, 17.357, 105.107), Slope = c(47.267, 20.234,
33.717, 47.267, 20.234, 33.717)), .Names = c("Line #", "country",
"treatment", "Intercept", "Slope"), 

Re: [R] Data aggregation question

2011-07-28 Thread David Winsemius


On Jul 28, 2011, at 4:24 PM, David Warren wrote:


Hi all,

I'm working with a sizable dataset that I'd like to summarize,  
but I
can't find a tool or function that will do quite what I'd like.   
Basically,
I'd like to summarize the data by fully crossing three variables and  
getting

a count of the number of observations for every level of that 3-way
interaction.  For example, if factors A, B, and C each have 3 levels  
(all of
which were observed someplace in the dataset), I'd like to know how  
many
times A1, B1, and C1 co-occurred in the dataset.  Functions like  
aggregate
and summaryBy do a decent job when I sum a vector of ones of the  
same length
as the original dataset, but I'm getting stuck on the fact that  
neither will

return 0-count combinations of the three variables in question.


I think that may depend on what functions and arguments you use.

 I understand that this is a desirable outcome (if A1, B1, C2 didn't  
occur, it

shouldn't be counted and isn't), but I need to know both when these
combinations of factor did and did not occur.  I'm stuck on this  
one, and

would really appreciate any help.  Thanks in advance!


?xtabs



Dave Warren

PS A functional solution would be best; the original dataset  
contains about

2.3 million observations, so any looping is going to be very slow.


In general tabulations like these are very efficient.

--

David Winsemius, MD
West Hartford, CT

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


Re: [R] bug in dev.copy2pdf output?

2011-07-28 Thread Rolf Turner

On 29/07/11 09:51, selwyn quan wrote:


On Thu, 28 Jul 2011, Duncan Murdoch wrote:


On 11-07-28 1:22 PM, selwyn quan wrote:


Hi,

Am using R 2.13.1 on Linux (Fedora). Is anybody else having problems 
with

dev.copy2pdf xyplot output with the pch=1 (open circle) symbol? The
symbols come out as "q" in the PDF.  dev.copy2eps produces the correct
results as does cairo_pdf. Other symbols produced with dev.copy2pdf 
seem

ok.



There have been reports like this before that turned out to be 
problems in the viewer, which made inappropriate font substitutions.  
How did you determine that the circles came out as q?


Duncan Murdoch



You are right. Think it is a bug in Fedora's evince. Acrobat reader 
renders the PDF fine.


FWIW, evince on my Ubuntu system renders the points correctly as open 
circles.


cheers,

Rolf Turner

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


[R] Reading name-value data

2011-07-28 Thread Stavros Macrakis
I have a file of data where each line is a series of name-value pairs, but
where the names are not necessarily the same from line to line, e.g.

   a=1,b=2,d=5
   b=4,c=3,e=3
   a=5,d=1

I would like to create a data frame which lines up the data in the
corresponding columns.  In this case, this would be

   data.frame( a = (1, NA, 4), b = (2, 4, NA), c = (NA, 3, NA), d = (5, NA,
1), e = (NA, 3, 1) )

One way I can think of doing this is to read in the data as one 'long' data
frame per line with a unique ID, e.g. line one becomes

 cbind(id=1,data.frame(variable=c('a','b','d'),value=c(1,2,5)))

then rbind all the lines and use the reshape package function 'cast'.

Is there a more straightforward way?  (I'd have thought rbind would line up
columns by name, but it doesn't.)

-s

[[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] Fwd: Ploting gradient

2011-07-28 Thread Fernando Andreacci
I could not get Jim code to work (can't install colors in R 2.13). However
Alexander code seems what I want. Just a litle detail, I need all bars with
same size, the only difference between they are the colors.



On Thu, Jul 28, 2011 at 6:11 AM, Jim Lemon  wrote:

> On 07/28/2011 11:25 AM, Fernando Andreacci wrote:
>
>> I have a simple bar chart with annual precipitation (jan to dez).
>>
>> I want to plot, above each bar (on a line), a square wich is color based
>> on
>> a scale (0-100%). With 0 being white and 100 black, like a gradient. Is it
>> possible? How to?
>>
>
> Hi Fernando,
> I think you want the grayscale to reflect the values of the percentages, so
> here is one way to do it:
>
> # make up some values for the bars
> barvalues<-sample(0:9,10)
> # make up some values for the percentages
> pctvalues<-sample(0:100,10)
> # draw a barplot
> xpos<-barplot(barvalues,ylim=**c(0,10))
> # translate the percent values into grayscale
> pctcolors<-color.scale(**pctvalues)
> rect(xpos-0.3,barvalues+0.5,**xpos+0.3,barvalues+1,col=**pctcolors)
>
> Jim
>



-- 
Fernando Andreacci
Biólogo
Fone +55 47 9921 4015
+55 41 9921 3934
fandrea...@gmail.com




-- 
Fernando Andreacci
Biólogo
Fone +55 47 9921 4015
+55 41 9921 3934
fandrea...@gmail.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] Data aggregation question

2011-07-28 Thread William Dunlap
Have you tried using table()?

E.g.,
> df <- data.frame(x=c("A","A","B","C"), y=c("ii","ii","i","ii"), Age=2^(1:4))
> tab <- do.call("table", df[c("x","y")])
> tab
   y
x   i ii
  A 0  2
  B 1  0
  C 0  1
> as.data.frame(tab)
  x  y Freq
1 A  i0
2 B  i1
3 C  i0
4 A ii2
5 B ii0
6 C ii1
> str(.Last.value)
'data.frame':   6 obs. of  3 variables:
 $ x   : Factor w/ 3 levels "A","B","C": 1 2 3 1 2 3
 $ y   : Factor w/ 2 levels "i","ii": 1 1 1 2 2 2
 $ Freq: int  0 1 0 2 0 1

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of David Warren
> Sent: Thursday, July 28, 2011 1:25 PM
> To: r-help@r-project.org
> Subject: [R] Data aggregation question
> 
> Hi all,
> 
>  I'm working with a sizable dataset that I'd like to summarize, but I
> can't find a tool or function that will do quite what I'd like.  Basically,
> I'd like to summarize the data by fully crossing three variables and getting
> a count of the number of observations for every level of that 3-way
> interaction.  For example, if factors A, B, and C each have 3 levels (all of
> which were observed someplace in the dataset), I'd like to know how many
> times A1, B1, and C1 co-occurred in the dataset.  Functions like aggregate
> and summaryBy do a decent job when I sum a vector of ones of the same length
> as the original dataset, but I'm getting stuck on the fact that neither will
> return 0-count combinations of the three variables in question.  I
> understand that this is a desirable outcome (if A1, B1, C2 didn't occur, it
> shouldn't be counted and isn't), but I need to know both when these
> combinations of factor did and did not occur.  I'm stuck on this one, and
> would really appreciate any help.  Thanks in advance!
> 
> Dave Warren
> 
> PS A functional solution would be best; the original dataset contains about
> 2.3 million observations, so any looping is going to be very slow.
> 
> --
> Post-doctoral Fellow
> Neurology Department
> University of Iowa Hospitals and Clinics
> davideugenewar...@gmail.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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Data aggregation question

2011-07-28 Thread Sarah Goslee
You don't offer a reproducible example, but what do you need that table()
doesn't provide?

testdata <- data.frame(A=factor(sample(1:3, 20)), B=factor(sample(1:3,
20)), C=factor(sample(1:3, 20)))
table(testdata)

Sarah

On Thu, Jul 28, 2011 at 4:24 PM, David Warren
 wrote:
> Hi all,
>
>     I'm working with a sizable dataset that I'd like to summarize, but I
> can't find a tool or function that will do quite what I'd like.  Basically,
> I'd like to summarize the data by fully crossing three variables and getting
> a count of the number of observations for every level of that 3-way
> interaction.  For example, if factors A, B, and C each have 3 levels (all of
> which were observed someplace in the dataset), I'd like to know how many
> times A1, B1, and C1 co-occurred in the dataset.  Functions like aggregate
> and summaryBy do a decent job when I sum a vector of ones of the same length
> as the original dataset, but I'm getting stuck on the fact that neither will
> return 0-count combinations of the three variables in question.  I
> understand that this is a desirable outcome (if A1, B1, C2 didn't occur, it
> shouldn't be counted and isn't), but I need to know both when these
> combinations of factor did and did not occur.  I'm stuck on this one, and
> would really appreciate any help.  Thanks in advance!
>
> Dave Warren
>
> PS A functional solution would be best; the original dataset contains about
> 2.3 million observations, so any looping is going to be very slow.
>

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Can R (without GUI) be compiled with static linking?

2011-07-28 Thread Jonathan Callahan
I have a potential client that is considering R for data analysis and
visualization modules within a larger framework. The host systems run either
Solaris or a version of Linux.

One of their requirements (hard or soft?) is that each module in the
framework be compiled with statically linked libraries into a standalone
binary that can be run from the command line.

I intend to recommend using R for many of their analytical components. I
will recommend setting up a full R environment and packaging up new
functionality for easy deployment. Then they can simply use R in batch
mode:  R --vanilla  xyz.out

But if they insist on only using modules that are stand-alone, statically
linked binaries I will need answers to the following questions:

1) Are the distributed R binaries statically linked?
2) Is the R code that runs in batch mode statically linked? (i.e. Will it
break depending upon what shared libraries are installed?)
3) Is it possible to create a statically linked R that can be run "in batch
mode"?
4) If not, how much C (or python? ;-D) code do I have to write to get to the
point of having a stand-alone binary that can follow the instructions in an
R script?

Thanks in advance.

Jon

-- 
Jonathan Callahan, PhD
Mazama Science
206-708-5028
mazamascience.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] bug in dev.copy2pdf output?

2011-07-28 Thread selwyn quan


On Thu, 28 Jul 2011, Duncan Murdoch wrote:


On 11-07-28 1:22 PM, selwyn quan wrote:


Hi,

Am using R 2.13.1 on Linux (Fedora). Is anybody else having problems 
with

dev.copy2pdf xyplot output with the pch=1 (open circle) symbol? The
symbols come out as "q" in the PDF.  dev.copy2eps produces the correct
results as does cairo_pdf. Other symbols produced with dev.copy2pdf seem
ok.



There have been reports like this before that turned out to be problems in 
the viewer, which made inappropriate font substitutions.  How did you 
determine that the circles came out as q?


Duncan Murdoch



You are right. Think it is a bug in Fedora's evince. Acrobat reader 
renders the PDF fine.


Thanks for the feedback.
Selwyn

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] smooth scatterplot and geo map

2011-07-28 Thread marco
thanks a lot!!


--
View this message in context: 
http://r.789695.n4.nabble.com/smooth-scatterplot-and-geo-map-tp3702374p3702424.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] Data aggregation question

2011-07-28 Thread David Warren
Hi all,

 I'm working with a sizable dataset that I'd like to summarize, but I
can't find a tool or function that will do quite what I'd like.  Basically,
I'd like to summarize the data by fully crossing three variables and getting
a count of the number of observations for every level of that 3-way
interaction.  For example, if factors A, B, and C each have 3 levels (all of
which were observed someplace in the dataset), I'd like to know how many
times A1, B1, and C1 co-occurred in the dataset.  Functions like aggregate
and summaryBy do a decent job when I sum a vector of ones of the same length
as the original dataset, but I'm getting stuck on the fact that neither will
return 0-count combinations of the three variables in question.  I
understand that this is a desirable outcome (if A1, B1, C2 didn't occur, it
shouldn't be counted and isn't), but I need to know both when these
combinations of factor did and did not occur.  I'm stuck on this one, and
would really appreciate any help.  Thanks in advance!

Dave Warren

PS A functional solution would be best; the original dataset contains about
2.3 million observations, so any looping is going to be very slow.

-- 
Post-doctoral Fellow
Neurology Department
University of Iowa Hospitals and Clinics
davideugenewar...@gmail.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] bug in dev.copy2pdf output?

2011-07-28 Thread Duncan Murdoch

On 11-07-28 1:22 PM, selwyn quan wrote:


Hi,

Am using R 2.13.1 on Linux (Fedora). Is anybody else having problems with
dev.copy2pdf xyplot output with the pch=1 (open circle) symbol? The
symbols come out as "q" in the PDF.  dev.copy2eps produces the correct
results as does cairo_pdf. Other symbols produced with dev.copy2pdf seem
ok.



There have been reports like this before that turned out to be problems 
in the viewer, which made inappropriate font substitutions.  How did you 
determine that the circles came out as q?


Duncan Murdoch

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


Re: [R] bug in dev.copy2pdf output?

2011-07-28 Thread Rolf Turner

On 29/07/11 05:22, selwyn quan wrote:


Hi,

Am using R 2.13.1 on Linux (Fedora). Is anybody else having problems 
with dev.copy2pdf xyplot output with the pch=1 (open circle) symbol? 
The symbols come out as "q" in the PDF.  dev.copy2eps produces the 
correct results as does cairo_pdf. Other symbols produced with 
dev.copy2pdf seem ok.


I did a small experiment on my laptop running Ubuntu, and the plot 
symbols came out just fine.

I'm running R version 2.13.1 Patched (2011-07-17 r56404) currently.

cheers,

Rolf Turner

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


Re: [R] cycling from x11 window in RCommander to graphics device window: Mac Os 10.6.8

2011-07-28 Thread Simon Kiss
Dear John,
The Command Tab does not work for me, but I have been able to get expose to 
work. I.e. it does bring up all windows, including the x11 terminal.  It will 
take a little getting used to, but it is functional.
I apologize for cluttering the list with minutiae
Thank you!
Yours
S.
On 2011-07-28, at 5:21 PM, John Fox wrote:

> Dear Simon,
> 
> I'm sitting in front of a MacBook Pro and Command-tab works perfectly fine 
> for me: Selecting X11 brings the R Commander Window to the front, and 
> selecting R brings the Quartz graphics window to the front. I must admit that 
> my habit in classroom demonstrations on a Mac is to use Expose to select 
> Windows, but, unless I misunderstand your problem, Command-tab also works.
> 
> I'm using R 2.13.1 under Mac OS X 10.6.7 with XQuartz 2.3.6 and 
> tcltk-8.5.5-x11.
> 
> I hope this helps,
> John
> 
> 
> John Fox
> Sen. William McMaster Prof. of Social Statistics
> Department of Sociology
> McMaster University
> Hamilton, Ontario, Canada
> http://socserv.mcmaster.ca/jfox/
> On Thu, 28 Jul 2011 13:40:11 -0400
> Simon Kiss  wrote:
>> Dear Colleagues, 
>> I have recently installed R Commander on my Mac OS 10.6.8. I'd like to use 
>> it for an undergraduate class this year.
>> Everything appears to be working fine, except for one thing.  I cannot use 
>> Command-tab to cycle from the X11 window in which RCommander is running to 
>> any other window open in my workspace.  This is particularly important 
>> because I cannot cycle to the graphics device window that is opened when I 
>> call a new plot.  If I force quit the X11 window and Rcommander, R remains 
>> running and I can see the graphics device window and the plot looks fine.
>> But as you can imagine, this is quite laborious, having to restart.
>> I've looked through the help documentation and tried reinstalling tcltk 
>> prior to opening up Rcommander, but that does not address the problem.
>> Any thoughts?
>> Yours, Simon Kiss
>> *
>> Simon J. Kiss, PhD
>> Assistant Professor, Wilfrid Laurier University
>> 73 George Street
>> Brantford, Ontario, Canada
>> N3T 2C9
>> Cell: +1 905 746 7606
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
>   

*
Simon J. Kiss, PhD
Assistant Professor, Wilfrid Laurier University
73 George Street
Brantford, Ontario, Canada
N3T 2C9
Cell: +1 905 746 7606

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] cycling from x11 window in RCommander to graphics device window: Mac Os 10.6.8

2011-07-28 Thread John Fox
Dear Simon,

I'm sitting in front of a MacBook Pro and Command-tab works perfectly fine for 
me: Selecting X11 brings the R Commander Window to the front, and selecting R 
brings the Quartz graphics window to the front. I must admit that my habit in 
classroom demonstrations on a Mac is to use Expose to select Windows, but, 
unless I misunderstand your problem, Command-tab also works.

I'm using R 2.13.1 under Mac OS X 10.6.7 with XQuartz 2.3.6 and tcltk-8.5.5-x11.

I hope this helps,
 John


John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/
On Thu, 28 Jul 2011 13:40:11 -0400
 Simon Kiss  wrote:
> Dear Colleagues, 
> I have recently installed R Commander on my Mac OS 10.6.8. I'd like to use it 
> for an undergraduate class this year.
> Everything appears to be working fine, except for one thing.  I cannot use 
> Command-tab to cycle from the X11 window in which RCommander is running to 
> any other window open in my workspace.  This is particularly important 
> because I cannot cycle to the graphics device window that is opened when I 
> call a new plot.  If I force quit the X11 window and Rcommander, R remains 
> running and I can see the graphics device window and the plot looks fine.
> But as you can imagine, this is quite laborious, having to restart.
> I've looked through the help documentation and tried reinstalling tcltk prior 
> to opening up Rcommander, but that does not address the problem.
> Any thoughts?
> Yours, Simon Kiss
> *
> Simon J. Kiss, PhD
> Assistant Professor, Wilfrid Laurier University
> 73 George Street
> Brantford, Ontario, Canada
> N3T 2C9
> Cell: +1 905 746 7606
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Help Non-sequential ANOVAs

2011-07-28 Thread John Fox
Dear Ariane,

You must be referring to the Anova() function in the car package. The function 
doesn't have an appropriate method for gls objects. The error was produced by 
the default method, which is inappropriate for gls objects, as you discovered. 
I agree that it would be nice for Anova() to handle gls objects, and it 
shouldn't be too hard to do that. I'll consider this a request and put it on my 
to-do list.

On the other hand, it should not be difficult to do what you want, by dropping 
terms for the model and comparing alternative models by LR tests. It would 
likely make most sense to start with the interaction,

mod.1 <- gls(maturity~morph*month, 
weights = varIdent(form = ~ 1 |morph*month),
na.action=na.omit, method="ML")

mod.2 <- update(mod.1, . ~ . - morph:month)
anova(mod.1, mod.2)

Then, if the interaction is negligible, proceed to test the main effects:

mod.3 <- update(mod.2, . ~ . - morph)
anova(mod.2, mod.3)

mod.4 <- update(mod.2, . ~ . - month)
anova(mod.2, mod.4)

I hope this helps,
 John

On Thu, 28 Jul 2011 18:37:58 +
 Ariane Charaoui  wrote:
> 
> 
> 
> Hello,
> 
> I have data
> on the maturity of two morphs of fish. I want to test whether their maturity 
> is
> evolving differently or not on a temporal scale (month). The maturity 
> variable (independent
> variable) is continuous and the morph and month variables (dependant 
> variables)
> are categorical. Because the data show variance heterogeneity, I modeled it
> with the function gls:
> 
> kg1 =
> gls(maturity~morph*month, weights = varIdent(form = ~ 1 |morph*month) ,
> na.action=na.omit, method="ML")
> 
> Next, I
> want to test if the two effects “morph” and “month” are significant so I use
> the function anova
> 
> anova(kg1)
> 
> Denom. DF: 75 
> 
>numDFF-value  p-value
> 
> (Intercept)   1
>  174.20833   <.0001
> 
> morph 1  
>5.37109   0.0232
> 
> month 5  46.41181
>  <.0001
> 
> morph:month  5   2.85388 
> 0.0206
> 
>  
> 
> The problem is that I
> want the results of a non-sequential anova. I tried also the function Anova,
> but I get an error message:
> 
>  
> 
> Error in !factors[,
> term2] : invalid argument type
> 
>  
> 
> Is there a way to fix
> this problem or is it possible to specify a non-sequential anova?
> 
>  
> 
> Thank you
> 
>  
> 
> Ariane
> 
> 
> 
> 
> 
>   [[alternative HTML version deleted]]
> 


John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Animated gif or something similar in R?

2011-07-28 Thread Jean V Adams
Dale,

I do not have the same color problem when I run your code on my PC.  The 
colors in both devices look the same.  I'm running R version 2.13.0 on 
Windows.

I am not familiar with the rgl package, but I found a function that might 
be helpful to you when I searched for "gif" in the package reference 
manual.

?movie3d()

Hope this helps.

Jean


`·.,,  ><(((º>   `·.,,  ><(((º>   `·.,,  ><(((º>

Jean V. Adams
Statistician
U.S. Geological Survey
Great Lakes Science Center
223 East Steinfest Road
Antigo, WI 54409  USA



From:
Dale Coons 
To:
r-help@r-project.org
Date:
07/28/2011 03:22 PM
Subject:
[R] Animated gif or something similar in R?
Sent by:
r-help-boun...@r-project.org



I'm have a (minor) problem and a question.
Problem: The following code creates 5 clusters of dots of different 
colors.  However, I need the second call outside the data.frame call to 
get the colors to change for some reason.  I assume there's an error in 
the data.frame() call, but I don't know what.
Question: Is there is a way to cause the resulting graphic to rotate on 
it's own and to output to a animated gif or some other format that could 
be used in a powerpoint type presentation?  I work with a bunch of 
'drama queens'--they'd like it if there was some motion rather than a 
static display ;-)

Thanks in advance,
Dale.

library(rgl)
clusset<-data.frame(x=c(round(abs(rnorm(5,7,1)),1),round(abs(rnorm(5,11,2)),1),
 
round(abs(rnorm(5,16,2)),1),round(abs(rnorm(5,20,1.5)),1),round(abs(rnorm(5,5,2)),1)),
 
y=c(round(abs(rnorm(5,7,2)),1),round(abs(rnorm(5,11,2)),1),
 
round(abs(rnorm(5,16,2)),1),round(abs(rnorm(5,4,2)),1),round(abs(rnorm(5,7,2)),1)),
 
z=c(round(abs(rnorm(5,7,2)),1),round(abs(rnorm(5,12,2)),1),
 
round(abs(rnorm(5,16,1)),1),round(abs(rnorm(5,6,2)),1),round(abs(rnorm(5,17,2)),1)),
 
dotcol=c(rep('red2',5),rep('green2',5),rep('blue2',5),rep('yellow1',5),rep('purple2',5))
 )

#this call doesn't show the right colors--why?
plot3d(clusset, xlim=c(0,25), ylim=c(0,25), 
zlim=c(0,25),xlab='',ylab='',zlab='',  col=clusset$dotcol, radius=1, 
type='s')
#but if I redefine the colors again and call, it does
clusset$dotcol<-c(rep('red2',5),rep('green2',5),rep('blue2',5),rep('yellow1',5),rep('purple2',5))
plot3d(clusset, xlim=c(0,25), ylim=c(0,25), 
zlim=c(0,25),xlab='',ylab='',zlab='', col=clusset$dotcol, radius=1, 
type='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.



[[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] Animated gif or something similar in R?

2011-07-28 Thread Gene Leynes
It seems like you have two questions, one about color rendering, and another
about making animations.

For the second question :

I've found the animation package useful in similar situations, where I want
to share results with non-R users who want a static visualization.  By using
animation you can create a HTML page that you can view by simply opening the
html index page.  There are some simple controls that can let you step
through your animation manually or at a specific time interval.

I also find that the brute force method of saving files and stepping through
them is usually my best solution.

My favorite thing though has been to use the PBSmodelling package.  You can
make a graph and a slider, and then you can interactively change the graph
with the slider, they have many great demos in their package of how to
create sliders.

Also, the rpanel function is pretty nice for some simple work
http://chartsgraphs.wordpress.com/2009/05/08/rpanel-package-adds-interactive-capabilites-to-r/


On Thu, Jul 28, 2011 at 3:14 PM, Dale Coons  wrote:

> I'm have a (minor) problem and a question.
> Problem: The following code creates 5 clusters of dots of different colors.
>  However, I need the second call outside the data.frame call to get the
> colors to change for some reason.  I assume there's an error in the
> data.frame() call, but I don't know what.
> Question: Is there is a way to cause the resulting graphic to rotate on
> it's own and to output to a animated gif or some other format that could be
> used in a powerpoint type presentation?  I work with a bunch of 'drama
> queens'--they'd like it if there was some motion rather than a static
> display ;-)
>
> Thanks in advance,
> Dale.
>
> library(rgl)
> clusset<-data.frame(x=c(round(**abs(rnorm(5,7,1)),1),round(**
> abs(rnorm(5,11,2)),1),
>round(abs(rnorm(5,16,2)),1),**
> round(abs(rnorm(5,20,1.5)),1),**round(abs(rnorm(5,5,2)),1)),
>y=c(round(abs(rnorm(5,7,2)),1)**
> ,round(abs(rnorm(5,11,2)),1),
>round(abs(rnorm(5,16,2)),1),**
> round(abs(rnorm(5,4,2)),1),**round(abs(rnorm(5,7,2)),1)),
>z=c(round(abs(rnorm(5,7,2)),1)**
> ,round(abs(rnorm(5,12,2)),1),
>round(abs(rnorm(5,16,1)),1),**
> round(abs(rnorm(5,6,2)),1),**round(abs(rnorm(5,17,2)),1)),
>dotcol=c(rep('red2',5),rep('**
> green2',5),rep('blue2',5),rep(**'yellow1',5),rep('purple2',5))
>)
>
> #this call doesn't show the right colors--why?
> plot3d(clusset, xlim=c(0,25), ylim=c(0,25), zlim=c(0,25),xlab='',ylab='',*
> *zlab='',  col=clusset$dotcol, radius=1, type='s')
> #but if I redefine the colors again and call, it does
> clusset$dotcol<-c(rep('red2',**5),rep('green2',5),rep('blue2'**
> ,5),rep('yellow1',5),rep('**purple2',5))
> plot3d(clusset, xlim=c(0,25), ylim=c(0,25), zlim=c(0,25),xlab='',ylab='',*
> *zlab='', col=clusset$dotcol, radius=1, type='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.
>

[[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] Data frame to list

2011-07-28 Thread David Winsemius


On Jul 28, 2011, at 4:14 PM, Jonathan Greenberg wrote:

I'm hoping this is an easy problem that I'm missing something  
obvious.  Given:


x=c(1,1,1,2,2,3,3,3)
y=c(1:length(x))
dataframe=data.frame(x,y)

I would like to convert this to a list for use with certain functions,
where each entry of the list is a subsetted dataframe based on
dataframe$x


?split
> split(dataframe, x)
$`1`
  x y
1 1 1
2 1 2
3 1 3

$`2`
  x y
4 2 4
5 2 5

$`3`
  x y
6 3 6
7 3 7
8 3 8



I can do this "brute force" by a for-next loop:

unique_x=unique(dataframe$x)
unique_x_N=length(unique_x)
dataframe_to_list=vector(mode="list",length=unique_x_N)
for(i in 1:unique_x_N)
{
dataframe_to_list[[i]]=subset(dataframe,x==unique_x[i])

}

My R-gut is telling me there's a much more efficient way of doing this
-- is it right?

--j

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] Data frame to list

2011-07-28 Thread Jonathan Greenberg
Yep, my R-gut was right!  Thanks Jean and Greg!

--j

On Thu, Jul 28, 2011 at 1:29 PM, Jean V Adams  wrote:

>
> Try this:
>
> split(dataframe, dataframe$x)
>
> Jean
>
>
> `·.,,  ><(((º>   `·.,,  ><(((º>   `·.,,  ><(((º>
>
> Jean V. Adams
> Statistician
> U.S. Geological Survey
> Great Lakes Science Center
> 223 East Steinfest Road
> Antigo, WI 54409  USA
>
>
>  From: Jonathan Greenberg  To: r-help <
> r-help@r-project.org> Date: 07/28/2011 03:22 PM Subject:
> [R] Data frame to list
> Sent by: r-help-boun...@r-project.org
> --
>
>
>
> I'm hoping this is an easy problem that I'm missing something obvious.
>  Given:
>
> x=c(1,1,1,2,2,3,3,3)
> y=c(1:length(x))
> dataframe=data.frame(x,y)
>
> I would like to convert this to a list for use with certain functions,
> where each entry of the list is a subsetted dataframe based on
> dataframe$x
>
> I can do this "brute force" by a for-next loop:
>
> unique_x=unique(dataframe$x)
> unique_x_N=length(unique_x)
> dataframe_to_list=vector(mode="list",length=unique_x_N)
> for(i in 1:unique_x_N)
> {
> dataframe_to_list[[i]]=subset(dataframe,x==unique_x[i])
>
> }
>
> My R-gut is telling me there's a much more efficient way of doing this
> -- is it right?
>
> --j
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Unable to install packages on Mac OS X

2011-07-28 Thread David Winsemius


On Jul 28, 2011, at 3:08 PM, Miguel Leal wrote:


I'm having problems installing packages.

I'm working on the R version 2.13.1 in a Mac OS X version 10.6.8.

I'm not able to search or install packages. For instance, I have the  
following error message:



install.packages("lattice")

Warning: unable to access index for repository 
http://cran.pt.r-project.org/bin/macosx/leopard/contrib/2.13


Looks like a weird URL. How did you come up with that one? When I go  
to it with my browser it times out. Why not pick a working repository?



Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
 package 'lattice' is not available (for R version 2.13.1)


And I thought lattice was part of the default packages installation,  
so would not have expected any need to install it.


Have you just tried library(lattice) from the R console?

--

David Winsemius, MD
West Hartford, CT

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


Re: [R] Data frame to list

2011-07-28 Thread Jean V Adams
Try this:

split(dataframe, dataframe$x)

Jean


`·.,,  ><(((º>   `·.,,  ><(((º>   `·.,,  ><(((º>

Jean V. Adams
Statistician
U.S. Geological Survey
Great Lakes Science Center
223 East Steinfest Road
Antigo, WI 54409  USA



From:
Jonathan Greenberg 
To:
r-help 
Date:
07/28/2011 03:22 PM
Subject:
[R] Data frame to list
Sent by:
r-help-boun...@r-project.org



I'm hoping this is an easy problem that I'm missing something obvious. 
Given:

x=c(1,1,1,2,2,3,3,3)
y=c(1:length(x))
dataframe=data.frame(x,y)

I would like to convert this to a list for use with certain functions,
where each entry of the list is a subsetted dataframe based on
dataframe$x

I can do this "brute force" by a for-next loop:

unique_x=unique(dataframe$x)
unique_x_N=length(unique_x)
dataframe_to_list=vector(mode="list",length=unique_x_N)
for(i in 1:unique_x_N)
{
 dataframe_to_list[[i]]=subset(dataframe,x==unique_x[i])
 
}

My R-gut is telling me there's a much more efficient way of doing this
-- is it right?

--j

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Data frame to list

2011-07-28 Thread Greg Snow
?split

-- 
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-bounces@r-
> project.org] On Behalf Of Jonathan Greenberg
> Sent: Thursday, July 28, 2011 2:14 PM
> To: r-help
> Subject: [R] Data frame to list
> 
> I'm hoping this is an easy problem that I'm missing something obvious.
> Given:
> 
> x=c(1,1,1,2,2,3,3,3)
> y=c(1:length(x))
> dataframe=data.frame(x,y)
> 
> I would like to convert this to a list for use with certain functions,
> where each entry of the list is a subsetted dataframe based on
> dataframe$x
> 
> I can do this "brute force" by a for-next loop:
> 
> unique_x=unique(dataframe$x)
> unique_x_N=length(unique_x)
> dataframe_to_list=vector(mode="list",length=unique_x_N)
> for(i in 1:unique_x_N)
> {
>   dataframe_to_list[[i]]=subset(dataframe,x==unique_x[i])
> 
> }
> 
> My R-gut is telling me there's a much more efficient way of doing this
> -- is it right?
> 
> --j
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] smooth scatterplot and geo map

2011-07-28 Thread Greg Snow
The usual smoothed scatterplot assumes that the x variable (longitude) is fixed 
and that the y-variable (latitude) is observed with error, and that the mapping 
is 1 to 1 or 1 to many in that for each value of x you can have at most one y 
value.  These assumptions don't seem to make much sense with positional data.

You might consider using xsplines instead (see ?xspline).  This draws a curve 
from point to point in the order of the data and the smoothness (and closeness 
to the points) depends are the arguments that you specify.  This makes more 
sense for most applications that I can think of for plotting onto a map.

-- 
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-bounces@r-
> project.org] On Behalf Of marco
> Sent: Thursday, July 28, 2011 2:09 PM
> To: r-help@r-project.org
> Subject: [R] smooth scatterplot and geo map
> 
> Hello everybody,
> I'm trying to understand how to draw a smoothed scatterplot on a
> geographic
> map with R.
> Have a dataframe with point locations (long, lat) and was able to
> simply
> plot these points on a shp map by using the maptools package. However,
> instead of having simply the raw points on the map, I would like to
> have a
> "smoothed" scatterplot of the same superimposed on the map. Tried with
> the
> smoothScatter function, but really have no idea how to combine the map
> with
> the resulting graph.
> tx in adv
> marco
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/smooth-
> scatterplot-and-geo-map-tp3702374p3702374.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] apply is making me crazy...

2011-07-28 Thread Gene Leynes
Yes, I meant to say drop=FALSE

Also, I made a mistake in my "desired answer" structure example, sorry for
that confusion.

The apply results when margin=1 are very unintuitive.  That transposition
issue has caused me numerous headaches.  I think it's a design error, but
that changing it would be a disaster.


On Thu, Jul 28, 2011 at 2:45 PM, David Winsemius wrote:

>
> On Jul 28, 2011, at 3:13 PM, Gene Leynes wrote:
>
>  Very clever (as usual)…  It works, but since I wanted to switch the rows
>> and columns, which would require this:
>>  answer.slightly.clumsy  =
>> lapply(exampBad, function(x) matrix(apply(x ,1, cumsum),
>>  ncol=nrow(x)))
>>
>> However, with a slight modification of your code I can use a wrapper
>> function for apply.  This gives me the functionality, with clean syntax.  I
>> will probably add to my “standard” library.
>> apply1 = function(mat, fun){
>>matrix(apply(mat ,1, fun),  nrow=nrow(mat), byrow=T)
>> }
>> res = lapply(exampBad, function(x) apply1(x , cumsum))
>>
>
> Hmmm. I originally wrote nrow=nrow(mat) but changed it after it did not
> give your specified output. But `apply` typically transposes its results so
> you are using this matrix property: t(t(.)) == (.)
>
>
>
>> As I mentioned in my email to Dennis, I am typically dealing with highly
>> nested lists of matrices that have one thing in common: 1000 rows.  This
>> fact makes fact the lapply, sapply, apply, and do.call family extremely
>> effective, and makes this apply problem something that is worth solving.
>>
>> PS: I still wish that there were a drop=TRUE option in apply!
>>
>
> ITYM ..., drop=FALSE, since drop = TRUE is the default behavior that causes
> loss of matrix dimensions in "[".
>
> --
> david.
>
>
>
>> Thanks again,
>>
>> Gene
>>
>> On Thu, Jul 28, 2011 at 12:05 PM, David Winsemius 
>> wrote:
>>
>> On Jul 28, 2011, at 12:31 PM, Gene Leynes wrote:
>>
>> (As I mentioned in my other reply to Dennis, I think I'll stick with for
>> loops, but I wanted to respond.)
>>
>> By "almost does it" I meant that using as.matrix helps because it puts the
>> vector into a column, that "almost does it” because half the problem is that
>> the output is a non dimensional vector when apply is passed a matrix with
>> one column.
>>
>> However, since the output of the apply function is transposed when you’re
>> doing row margins, the as.matrix doesn’t help because it’s putting your
>> result into a column, while the apply function is putting everything else
>> into rows. I tried several combination of using t() before, after, and
>> during (changing margin=1 to margin=2) the function; but none did the trick.
>>
>> I was not as diligent about using your margin=1:1 suggestion in all my
>> trials, that didn't seem to be different from using margin=1.
>>
>> The problem is a bit hard to describe using a natural language, and I
>> think more apparent from the code.  Of course, that could my shortcoming.
>>
>> I still think that the structure of the proposed solution, which I think
>> makes the problem apparent.
>> > str(answerProposed)
>> List of 3
>>  $ : num [1:1000, 1] 0.5658 0.1759 1.2444 -0.0456 0.0236 ...
>>  $ : num [1:2, 1:1000] 0.0392 0.7047 0.1834 -0.6644 -0.6952 ...
>>  $ : num [1:3, 1:1000] -0.835 -0.0461 -0.1725 0.8365 0.7835 ...
>> >
>>
>> Sometimes I need to be hit over the head a few times for things to sink
>> in. I hadn't noticed the reversal of dimensions in the "1" row case:
>>
>>  answer.not.Bad  = lapply(exampBad, function(x) matrix(apply(x ,1,cumsum),
>>  ncol=nrow(x)))
>>
>> > str(answer.not.Bad)
>> List of 3
>>  $ : num [1, 1:1000] -0.159 -0.035 -0.386 -1.81 1.123 ...
>>  $ : num [1:2, 1:1000] -0.7801 0.6004 -0.0869 -0.1611 -0.3594 ...
>>  $ : num [1:3, 1:1000] -1.14 -2.81 -3.45 3.16 2.54 ...
>>
>> The 1:1 dodge was useless, anyway. And just to be sure, you did want the
>> row and col dimensions reversed? And you did want the first element to just
>> be a (transposed) copy of its argument?
>>
>> Are we good now?
>>
>> --
>> david.
>>
>> I want it to do this:
>> > str(answerDesired)
>> List of 3
>>  $ : num [1, 1:1000,] 0.5658 0.1759 1.2444 -0.0456 0.0236 ...
>>  $ : num [1:2, 1:1000] 0.0392 0.7047 0.1834 -0.6644 -0.6952 ...
>>  $ : num [1:3, 1:1000] -0.835 -0.0461 -0.1725 0.8365 0.7835 ...
>> >
>>
>> There are a lot of reasons why I would want the apply function to work
>> this way, or at least have an option to work this way.  One reason is so
>> that you could perform do.call(rbind, mylist) at the later
>>
>> I guess this behavior is described in the apply documentation:
>> “If each call to FUN returns a vector of length n, then apply returns an
>> array of dimension c(n, dim(X)[MARGIN]) if n > 1. If nequals 1, apply
>> returns a vector if MARGIN has length 1 and an array of dimension
>> dim(X)[MARGIN] otherwise. If n is 0, the result has length 0 but not
>> necessarily the ‘correct’ dimension.”
>>
>>
>> I just wish that it had an option to do return an array of dimension c(n,
>> dim(X)[M

[R] Data frame to list

2011-07-28 Thread Jonathan Greenberg
I'm hoping this is an easy problem that I'm missing something obvious.  Given:

x=c(1,1,1,2,2,3,3,3)
y=c(1:length(x))
dataframe=data.frame(x,y)

I would like to convert this to a list for use with certain functions,
where each entry of the list is a subsetted dataframe based on
dataframe$x

I can do this "brute force" by a for-next loop:

unique_x=unique(dataframe$x)
unique_x_N=length(unique_x)
dataframe_to_list=vector(mode="list",length=unique_x_N)
for(i in 1:unique_x_N)
{
dataframe_to_list[[i]]=subset(dataframe,x==unique_x[i])

}

My R-gut is telling me there's a much more efficient way of doing this
-- is it right?

--j

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Animated gif or something similar in R?

2011-07-28 Thread Dale Coons

I'm have a (minor) problem and a question.
Problem: The following code creates 5 clusters of dots of different 
colors.  However, I need the second call outside the data.frame call to 
get the colors to change for some reason.  I assume there's an error in 
the data.frame() call, but I don't know what.
Question: Is there is a way to cause the resulting graphic to rotate on 
it's own and to output to a animated gif or some other format that could 
be used in a powerpoint type presentation?  I work with a bunch of 
'drama queens'--they'd like it if there was some motion rather than a 
static display ;-)


Thanks in advance,
Dale.

library(rgl)
clusset<-data.frame(x=c(round(abs(rnorm(5,7,1)),1),round(abs(rnorm(5,11,2)),1),

round(abs(rnorm(5,16,2)),1),round(abs(rnorm(5,20,1.5)),1),round(abs(rnorm(5,5,2)),1)),

y=c(round(abs(rnorm(5,7,2)),1),round(abs(rnorm(5,11,2)),1),

round(abs(rnorm(5,16,2)),1),round(abs(rnorm(5,4,2)),1),round(abs(rnorm(5,7,2)),1)),

z=c(round(abs(rnorm(5,7,2)),1),round(abs(rnorm(5,12,2)),1),

round(abs(rnorm(5,16,1)),1),round(abs(rnorm(5,6,2)),1),round(abs(rnorm(5,17,2)),1)),

dotcol=c(rep('red2',5),rep('green2',5),rep('blue2',5),rep('yellow1',5),rep('purple2',5))

)

#this call doesn't show the right colors--why?
plot3d(clusset, xlim=c(0,25), ylim=c(0,25), 
zlim=c(0,25),xlab='',ylab='',zlab='',  col=clusset$dotcol, radius=1, 
type='s')

#but if I redefine the colors again and call, it does
clusset$dotcol<-c(rep('red2',5),rep('green2',5),rep('blue2',5),rep('yellow1',5),rep('purple2',5))
plot3d(clusset, xlim=c(0,25), ylim=c(0,25), 
zlim=c(0,25),xlab='',ylab='',zlab='', col=clusset$dotcol, radius=1, 
type='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] help with rpart

2011-07-28 Thread Sarah Goslee
Why repost after receiving a reply? Reposting is unnecessary. If the
first reply was unsatisfactory, why? More detail in your question
leads to a more useful and informative reply.

Just in case you didn't get it:

On Thu, Jul 28, 2011 at 11:52 AM,   wrote:
> 1. How can I plot the entire tree produced by rpart?

What is plot() not doing that you need?

> 2. How can I submit a vector of values to a tree produced by rpart and
> have
> it make an assignment?

What is predict() not doing that you need?

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] smooth scatterplot and geo map

2011-07-28 Thread marco
Hello everybody,
I'm trying to understand how to draw a smoothed scatterplot on a geographic
map with R.
Have a dataframe with point locations (long, lat) and was able to simply
plot these points on a shp map by using the maptools package. However,
instead of having simply the raw points on the map, I would like to have a
"smoothed" scatterplot of the same superimposed on the map. Tried with the
smoothScatter function, but really have no idea how to combine the map with
the resulting graph.
tx in adv
marco

--
View this message in context: 
http://r.789695.n4.nabble.com/smooth-scatterplot-and-geo-map-tp3702374p3702374.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] Executing for loop by grouping variable within dataframe

2011-07-28 Thread ssobek
Dear Dennis,

Thank you very much for your quick response! Your code does indeed solve
my problem. I figured I would have to define a function somehow to use
anything like ddply or similar, but couldn't wrap my head around how to
set it up properly.

I only started using R for anything more sophisticated than plain
statistics and plotting a couple of months ago, and I yet have to find a
good resource (book?) for teaching myself the basics of actual
programming, rather than plugging in commands. If anyone has a
recommendation, I would be thankful to hear about it!

It also doesn't help that I'm the only one in my work environment who
insists on using R, while everyone else still sticks with Matlab (but
people seem to get increasingly interested in R now), so if I get stuck
I'm at a complete loss.

To answer your question why temp.t[1] in the second group equalled -2.0
instead of -2.2 in my example- this is simply because it was running
through the loop row by row over the entire dataset, rather than for each
group separately as I intended, so it pulled information from the
preceding data.

Thanks again for your help! I greatly appreciate it, and I hope I can
improve my skill level soon.

Have a nice day,

Stephanie


> Hi:
>
> I don't get exactly the same results as you did in the second group
> (how does temp.t[1] = -2.0 instead of -2.2?) but try this:
>
> locality=c("USC00020958", "USC00020958", "USC00020958", "USC00020958",
> "USC00020958", "USC00021001","USC00021001", "USC00021001", "USC00021001",
> "USC00021001", "USC00021001")
> temp.a=c(-1.2, -1.2, -1.2, -1.2, -1.1, -2.2, -2.4, -2.6,-2.7, -2.8, -3.0)
> month= c(12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11)
> day= c(27, 28, 29, 30, 31, 1,  2,  3,  4,  5,  6)
> df=data.frame(locality, temp.a, month, day)
>
> f <- function(d) {
>k <- 0.8
>if(nrow(d) == 1L) {return(data.frame(d, temp.t = temp.a))} else {
>tmp <- rep(NA, nrow(d))
>tmp[1] <- d[1, 'temp.a']
>for(j in 2:length(tmp))
>   tmp[j] <- tmp[j - 1] + k * (d$temp.a[j] - tmp[j - 1])
>data.frame(d, temp.t = tmp)  }
>   }
>
> require('plyr')
> ddply(df, 'locality', f)
>   locality temp.a month daytemp.t
> 1  USC00020958   -1.212  27 -1.20
> 2  USC00020958   -1.212  28 -1.20
> 3  USC00020958   -1.212  29 -1.20
> 4  USC00020958   -1.212  30 -1.20
> 5  USC00020958   -1.112  31 -1.12
> 6  USC00021001   -2.211   1 -2.20
> 7  USC00021001   -2.411   2 -2.36
> 8  USC00021001   -2.611   3 -2.552000
> 9  USC00021001   -2.711   4 -2.670400
> 10 USC00021001   -2.811   5 -2.774080
> 11 USC00021001   -3.011   6 -2.954816
>
> If you want to round the result, substitute the last line in the function
> with
> data.frame(d, temp.t = round(tmp, 1))
>
> Related functions are ceiling() and floor() in case they are of interest.
>
> HTH,
> Dennis
>
>
> On Wed, Jul 27, 2011 at 10:38 AM,   wrote:
>> Dear list,
>>
>> I have a large dataset which is structured as follows:
>>
>> locality=c("USC00020958", "USC00020958", "USC00020958", "USC00020958",
>> "USC00020958", "USC00021001","USC00021001", "USC00021001",
>> "USC00021001",
>> "USC00021001", "USC00021001")
>>
>> temp.a=c(-1.2, -1.2, -1.2, -1.2, -1.1, -2.2, -2.4, -2.6,-2.7, -2.8,
>> -3.0)
>>
>> month= c(12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11)
>>
>> day= c(27, 28, 29, 30, 31, 1,  2,  3,  4,  5,  6)
>>
>> df=data.frame(locality,temp.a,month,day)
>>
>>>      locality temp.a month day
>>>1  USC00020958   -1.2    12  27
>>>2  USC00020958   -1.2    12  28
>>>3  USC00020958   -1.2    12  29
>>>4  USC00020958   -1.2    12  30
>>>5  USC00020958   -1.1    12  31
>>>6  USC00021001   -2.2    11   1
>>>7  USC00021001   -2.4    11   2
>>>8  USC00021001   -2.6    11   3
>>>9  USC00021001   -2.7    11   4
>>>10 USC00021001   -2.8    11   5
>>>11 USC00021001   -3.0    11   6
>>
>> I would like to calculate a 5th variable, temp.t, based on temp.a, and
>> temp.t for the preceding time step. I successfully created a for loop as
>> follows:
>>
>> temp.t=list()
>>
>> for(i in 2:nrow(df)){
>> k=0.8
>> temp.t[1]=df$temp.a[1]
>> temp.t[i]=(as.numeric(temp.t[i-1]))+k*(as.numeric(df$temp.a[i])-(as.numeric(temp.t[i-1])))
>> }
>>
>> temp.t <- unlist(temp.t)
>>
>>
>> df["temp.t"] <- round(temp.t,1)
>>
>> df
>>
>>>     locality temp.a month day temp.t
>>>1  USC00020958   -1.2    12  27   -1.2
>>>2  USC00020958   -1.2    12  28   -1.2
>>>3  USC00020958   -1.2    12  29   -1.2
>>>4  USC00020958   -1.2    12  30   -1.2
>>>5  USC00020958   -1.1    12  31   -1.1
>>>6  USC00021001   -2.2    11   1   -2.0
>>>7  USC00021001   -2.4    11   2   -2.3
>>>8  USC00021001   -2.6    11   3   -2.5
>>>9  USC00021001   -2.7    11   4   -2.7
>>>10 USC00021001   -2.8    11   5   -2.8
>>>11 USC00021001   -3.0    11   6   -3.0
>>
>> This worked fine as long as I was dealing with datasets that only
>> contained one locality. However, as you can see above, my current
>> dataset
>> contains more than one locality, and I ne

[R] bug in dev.copy2pdf output?

2011-07-28 Thread selwyn quan


Hi,

Am using R 2.13.1 on Linux (Fedora). Is anybody else having problems with 
dev.copy2pdf xyplot output with the pch=1 (open circle) symbol? The 
symbols come out as "q" in the PDF.  dev.copy2eps produces the correct 
results as does cairo_pdf. Other symbols produced with dev.copy2pdf seem 
ok.


Thanks,
Selwyn

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Life Cycle Assessment with R.

2011-07-28 Thread mason.earles
Hi there--

To avoid duplication, I would recommend looking at the OpenLCA efforts--see 
http://www.openlca.org/index.html http://www.openlca.org/index.html . One of
the limitations of this OpenLCA software, however, is a lack of statistical
tools with which to analyze the results. Perhaps an R module for statistical
analysis could be developed that works in conjunction to the OpenLCA tool?

Kindly,
Mason Earles

--
View this message in context: 
http://r.789695.n4.nabble.com/Life-Cycle-Assessment-with-R-tp3694838p3701867.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] Python difflib R equivalent?

2011-07-28 Thread Spencer Graves
There is a package "rJython", which claims to provide an "R interface to 
Python via Jython".  I haven't used it, but the lead author, Gabor 
Grothendieck, is well known in the R community.  Spencer



On 7/28/2011 9:15 AM, Prof Brian Ripley wrote:

On Thu, 28 Jul 2011, Bert Gunter wrote:


Paul:

1. I do not know if any such library exists.


Not to my knowledge, and we have contemplated providing such 
functions.  But for files see e.g. tools::Rdiff, and generally R will 
not be a good way to do this sort of thing on files (since the 
flexibility of R's i/o via connections does have a cost)



2. However, if I understand correctly, one usually does this sort of
thing in R with functions like ?match (or ?"%in%") and logical
comparison operations like ?"==" .  Of course, for numeric
comparisons, you need to be aware of R FAQ 7.31

If you are interested in comparing what in R are character vectors,
then various string operators, e.g. ?grep, ?regexp and character
operation packages (e.g. gsubfn, stringr) may be of use.

As usual, you are more likely to receive a helpful answer if you do as
the posting guide requests and provide a small, reproducible example
of the sort(s) of thing(s) you want to do.


Or at least a URI of examples you wish to emulate, which for difflib 
seem to be the sort of thing POSIX diff and friends are used for.



Cheers,
Bert

On Thu, Jul 28, 2011 at 4:05 AM, Paul  wrote:

Hi,

Does anyone know of a R library that is equivalent in functionality to
the Python standard libraries' difflib library? The python docs say
this about difflib:

"This module provides classes and functions for comparing sequences.
It can be used for example, for comparing files, and can produce
difference information in various formats, including HTML and context
and unified diffs."

http://docs.python.org/library/difflib.html

Thanks,

Paul

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.





--
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.






--
Spencer Graves, PE, PhD
President and Chief Technology Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567
web:  www.structuremonitoring.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] ggplot2 help/suggestions needed

2011-07-28 Thread Bruce Rex

Hello,

I have written a version of the Kohenen Self Organizing Map (in R) and wish
to use ggplot2 for the visualization. My results are RGB values in a matrix
[x,y,1:3] where x and y comprise the first two dimensions and the third
dimension is the RGB vector.

I am not sure whether to use geom_tile or geom_hex as there really is no
binning at the finest granularity. For testing, the matrix is 100, 100, 3 in
size. What approach would you suggest?

TIA,
DrX

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] apply is making me crazy...

2011-07-28 Thread Gene Leynes
Dennis,
ninety

Thanks, I did try almost exactly the same thing.  I decided it was too
complicated, especially since I have a whole mess of functions I want to use
this way.  You see, I usually work with lists of lists of matrices that are
dimensioned by simulations X time, so there's usually a one column matrix at
the bottom of the list.  So, I really want a general solution because I use
it all the time.

For now I'm going to stick with for loops, they work fine and are more clear
in the unlikely event that anyone else ever looks at my code.   The loops
just take up more space / are harder to read.

for example:
for(i in 1:nrow(mat))
mat[i,] = cumsum(mat[i,])/(1:ncol(mat))



On Wed, Jul 27, 2011 at 9:30 PM, Dennis Murphy  wrote:

> Hi:
>
> Try this:
>
> exampGood = lapply(2:4, function(x) matrix(rnorm(10 * x), ncol = x))
> exampBad  = lapply(1:3, function(x) matrix(rnorm(10 * x), ncol = x))
>
> csfun <- function(m) {
>if(ncol(m) == 1L) {return(m)} else {
>t(as.matrix(apply(m, 1, cumsum)))
>   }
>  }
>
> lapply(exampGood, csfun)
> lapply(exampBad, csfun)
>
> HTH,
> Dennis
>
> On Wed, Jul 27, 2011 at 3:22 PM, Gene Leynes  wrote:
> > I have tried a lot of ways around this, but I can't find a way to make
> apply
> > work in a generalized way because it causes a failure whenever reduces
> the
> > dimensions of its output.
> > The following example is easier to understand than the question.
> >
> > I wish it had a "drop=TRUE/FALSE" option like the "["  (and I wish I had
> > found the drop option a year ago, and I wish that I had 1e6 dollars...
> Oops,
> > I mean euros).
> >
> >
> >## Make three example matricies
> >exampGood = lapply(2:4, function(x)matrix(rnorm(1000*x),ncol=x))
> >exampBad  = lapply(1:3, function(x)matrix(rnorm(1000*x),ncol=x))
> >## Two ways to see what was created:
> >for(k in 1:length(exampGood)) print(dim(exampGood[[k]]))
> >for(k in 1:length(exampBad)) print(dim(exampBad[[k]]))
> >
> >##  Take the cumsum of each row of each matrix
> >answerGood = lapply(exampGood, function(x) apply(x ,1,cumsum))
> >answerBad  = lapply(exampBad, function(x) apply(x ,1,cumsum))
> >str(answerGood)
> >str(answerBad)
> >
> >##  Take the first element of the final column of each answer
> >for(mat in answerGood){
> >LastColumn = ncol(mat)
> >print(mat[1,LastColumn])
> >}
> >for(mat in answerBad){
> >LastColumn = ncol(mat)
> >print(mat[1,LastColumn])
> >}
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>

[[alternative HTML version deleted]]

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


[R] R: Re: Problem with anova.lmRob() "robust" package

2011-07-28 Thread m.fen...@libero.it
I'm sorry, maybe the question was bad posed. 
Ista has well described my problem. 

Thanks

Massimo





>Messaggio originale
>Da: iz...@psych.rochester.edu
>Data: 28/07/2011 17.52
>A: "David Winsemius"
>Cc: "m.fen...@libero.it", 
>Ogg: Re: [R] Problem with anova.lmRob() "robust" package
>
>I found the question really confusing as well, but see below.
>
>On Thu, Jul 28, 2011 at 11:42 AM, David Winsemius
> wrote:
>>
>> On Jul 28, 2011, at 9:13 AM, m.fen...@libero.it wrote:
>>
>>>
>>> Dear R users,
>>> I'd like to known your opinion about a problem with anova.lmRob() of
>>> "Robust" package that occurs when I run a lmRob() regression on my 
dataset.
>>> I check my univariate model by single object anova as anova(lmRob(y~x)).
>>> If I compare my model with the null model (y~1), I must obtain the same
>>> results,
>>> but not for my data.
>>> Is it possible?
>>>
>>> My example:
>>>
>>> x<-c(rep(0,8),rep(1,8),rep(2,7))
>>>
>>> y<-c(1,0.6,-0.8,0.7,1.6,-0.2,-1.2,-3.8,-1.8,-2.6,-1.7,-2.1,-0.3,-1.4,1.4,
-0.3,-0.3,0.5,0.4,-0.9,-1.6,0.4,0.4)
>>> library(robust)
>>> lmR<-lmRob(y~factor(x))
>>> anova(lmR)
>>> lmR0<-lmRob(y~1)
>>> anova(lmR,lmR0)
>>>
>>> If I run the code omitting the factor() (then treating "x" as continuous),
>>> the results are the same..
>>>
>>
>> I do not get the same results with that code. And the code does not appear
>> to track your description, since the second model does not have an "x" term
>> in it. Even when I create the model that it sounded as though you would 
have
>> written, namely lmR0 <- lmRob(y ~ x),  it is clearly _not_ the same result.
>>
>>> coef(lmR)
>> (Intercept)  factor(x)1  factor(x)2
>>  0.2428571  -1.3432007  -0.400
>>> coef(lmR0)
>>  (Intercept)            x
>> -0.509524217  0.005820355
>>>
>>> What is the explanation of these different results?
>>
>> Since you didn't post your results and since your complaint was that they
>> are "the same", it's hard to know what you are talking about.
>
>I think the question is why
>
>lm1 <- lm(y ~ factor(x))
>lm0 <- lm(y ~ 1)
>anova(lm1)
>anova(lm0, lm1)
>
>gives the same result, but
>
>lmR<-lmRob(y~factor(x))
>lmR0<-lmRob(y~1)
>anova(lmR)
>anova(lmR,lmR0)
>
>does not.
>
>I don't know the answer, but I think it is an interesting question.
>
>Best,
>Ista
>
>>
>> --
>> 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.
>>
>
>
>
>-- 
>Ista Zahn
>Graduate student
>University of Rochester
>Department of Clinical and Social Psychology
>http://yourpsyche.org
>

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


[R] help with rpart

2011-07-28 Thread mark
1. How can I plot the entire tree produced by rpart?

2. How can I submit a vector of values to a tree produced by rpart and
have
it make an assignment?

Mark


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Unable to install packages on Mac OS X

2011-07-28 Thread Miguel Leal
I'm having problems installing packages.

I'm working on the R version 2.13.1 in a Mac OS X version 10.6.8.

I'm not able to search or install packages. For instance, I have the following 
error message:

> install.packages("lattice")
Warning: unable to access index for repository 
http://cran.pt.r-project.org/bin/macosx/leopard/contrib/2.13
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
  package 'lattice' is not available (for R version 2.13.1)

Thank you in advance
Miguel
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 Non-sequential ANOVAs

2011-07-28 Thread Ariane Charaoui



Hello,

I have data
on the maturity of two morphs of fish. I want to test whether their maturity is
evolving differently or not on a temporal scale (month). The maturity variable 
(independent
variable) is continuous and the morph and month variables (dependant variables)
are categorical. Because the data show variance heterogeneity, I modeled it
with the function gls:

kg1 =
gls(maturity~morph*month, weights = varIdent(form = ~ 1 |morph*month) ,
na.action=na.omit, method="ML")

Next, I
want to test if the two effects “morph” and “month” are significant so I use
the function anova

anova(kg1)

Denom. DF: 75 

   numDFF-value  p-value

(Intercept)   1
 174.20833   <.0001

morph 1  
   5.37109   0.0232

month 5  46.41181
 <.0001

morph:month  5   2.85388 
0.0206

 

The problem is that I
want the results of a non-sequential anova. I tried also the function Anova,
but I get an error message:

 

Error in !factors[,
term2] : invalid argument type

 

Is there a way to fix
this problem or is it possible to specify a non-sequential anova?

 

Thank you

 

Ariane




  
[[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] filterMicroRna function: Sample replicates in preprocessing Agilent miRNA dataset

2011-07-28 Thread David Winsemius


On Jul 28, 2011, at 3:33 PM, Vickie S wrote:



Hi,
I have a question about filterMicroRna in AgiMicroRna package  
function for filtering probes in Agilent microRNA dataset.


ddPROC = filterMicroRna(ddNORM.micro, dd, control = TRUE,  
IsGeneDetected = TRUE, wellaboveNEG = FALSE, limIsGeneDetected =  
75, limNEG = 25, makePLOT = TRUE, target.micro, verbose = TRUE)


If in a dataset there are two or more sample replicates and in the  
step of filtering probes I want to exclude a probe only if  
gIsGeneDetected = 0 in all two or three sample replicates.


I don't think by 'filterMicroRna' function provides any option for  
this type of filtering.


Are there any suggestions ?


Are you sure these are not BioConductor questions? They have their own  
sandbox.


--

David Winsemius, MD
West Hartford, CT

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


Re: [R] apply is making me crazy...

2011-07-28 Thread David Winsemius


On Jul 28, 2011, at 3:13 PM, Gene Leynes wrote:

Very clever (as usual)…  It works, but since I wanted to switch the  
rows and columns, which would require this:

 answer.slightly.clumsy  =
 lapply(exampBad, function(x) matrix(apply(x ,1, cumsum),   
ncol=nrow(x)))


However, with a slight modification of your code I can use a wrapper  
function for apply.  This gives me the functionality, with clean  
syntax.  I will probably add to my “standard” library.

apply1 = function(mat, fun){
matrix(apply(mat ,1, fun),  nrow=nrow(mat), byrow=T)
}
res = lapply(exampBad, function(x) apply1(x , cumsum))


Hmmm. I originally wrote nrow=nrow(mat) but changed it after it did  
not give your specified output. But `apply` typically transposes its  
results so you are using this matrix property: t(t(.)) == (.)




As I mentioned in my email to Dennis, I am typically dealing with  
highly nested lists of matrices that have one thing in common: 1000  
rows.  This fact makes fact the lapply, sapply, apply, and do.call  
family extremely effective, and makes this apply problem something  
that is worth solving.


PS: I still wish that there were a drop=TRUE option in apply!


ITYM ..., drop=FALSE, since drop = TRUE is the default behavior that  
causes loss of matrix dimensions in "[".


--
david.



Thanks again,

Gene

On Thu, Jul 28, 2011 at 12:05 PM, David Winsemius > wrote:


On Jul 28, 2011, at 12:31 PM, Gene Leynes wrote:

(As I mentioned in my other reply to Dennis, I think I'll stick with  
for loops, but I wanted to respond.)


By "almost does it" I meant that using as.matrix helps because it  
puts the vector into a column, that "almost does it” because half  
the problem is that the output is a non dimensional vector when  
apply is passed a matrix with one column.


However, since the output of the apply function is transposed when  
you’re doing row margins, the as.matrix doesn’t help because it’s  
putting your result into a column, while the apply function is  
putting everything else into rows. I tried several combination of  
using t() before, after, and during (changing margin=1 to margin=2)  
the function; but none did the trick.


I was not as diligent about using your margin=1:1 suggestion in all  
my trials, that didn't seem to be different from using margin=1.


The problem is a bit hard to describe using a natural language, and  
I think more apparent from the code.  Of course, that could my  
shortcoming.


I still think that the structure of the proposed solution, which I  
think makes the problem apparent.

> str(answerProposed)
List of 3
 $ : num [1:1000, 1] 0.5658 0.1759 1.2444 -0.0456 0.0236 ...
 $ : num [1:2, 1:1000] 0.0392 0.7047 0.1834 -0.6644 -0.6952 ...
 $ : num [1:3, 1:1000] -0.835 -0.0461 -0.1725 0.8365 0.7835 ...
>

Sometimes I need to be hit over the head a few times for things to  
sink in. I hadn't noticed the reversal of dimensions in the "1" row  
case:


 answer.not.Bad  = lapply(exampBad, function(x) matrix(apply(x , 
1,cumsum),  ncol=nrow(x)))


> str(answer.not.Bad)
List of 3
 $ : num [1, 1:1000] -0.159 -0.035 -0.386 -1.81 1.123 ...
 $ : num [1:2, 1:1000] -0.7801 0.6004 -0.0869 -0.1611 -0.3594 ...
 $ : num [1:3, 1:1000] -1.14 -2.81 -3.45 3.16 2.54 ...

The 1:1 dodge was useless, anyway. And just to be sure, you did want  
the row and col dimensions reversed? And you did want the first  
element to just be a (transposed) copy of its argument?


Are we good now?

--
david.

I want it to do this:
> str(answerDesired)
List of 3
 $ : num [1, 1:1000,] 0.5658 0.1759 1.2444 -0.0456 0.0236 ...
 $ : num [1:2, 1:1000] 0.0392 0.7047 0.1834 -0.6644 -0.6952 ...
 $ : num [1:3, 1:1000] -0.835 -0.0461 -0.1725 0.8365 0.7835 ...
>

There are a lot of reasons why I would want the apply function to  
work this way, or at least have an option to work this way.  One  
reason is so that you could perform do.call(rbind, mylist) at the  
later


I guess this behavior is described in the apply documentation:
“If each call to FUN returns a vector of length n, then apply  
returns an array of dimension c(n, dim(X)[MARGIN]) if n > 1. If  
nequals 1, apply returns a vector if MARGIN has length 1 and an  
array of dimension dim(X)[MARGIN] otherwise. If n is 0, the result  
has length 0 but not necessarily the ‘correct’ dimension.”



I just wish that it had an option to do return an array of dimension  
c(n, dim(X)[MARGIN]) if n >= 1


On Wed, Jul 27, 2011 at 8:25 PM, David Winsemius > wrote:


On Jul 27, 2011, at 7:44 PM, Gene Leynes wrote:

David,

Thanks for the suggestion, but I think your answer only works  
because I was printing the wrong thing (because apply with margin=1  
transposes the results,


And if you want to change that,  then the t() function is readily at  
hand.


something I always forget).

Check this to see what I mean:
   str(answerGood)
   str(answerBad)

Adding "as.matrix" is interesting and almost does it,

"It" ... What is "it"? In a natural language,  ...  E

Re: [R] Tools for professional R developers

2011-07-28 Thread Michael Karol
Hi Uwe:

   You might want to take a look at RStudio (http://rstudio.org/).

Regards, 
Michael


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Bert Gunter
Sent: Thursday, July 28, 2011 3:24 PM
To: Uwe Ligges
Cc: r-help@r-project.org
Subject: Re: [R] Tools for professional R developers

+ ESS or some other reasonably capable text editor?

-- Bert

On Thu, Jul 28, 2011 at 12:14 PM, Uwe Ligges
 wrote:
>
>
> On 28.07.2011 21:04, Mark Alen wrote:
>>
>> Hi everyone,
>>
>> I was wondering what tools professional R users use so I went and posted
>> this question on stack overflow. I appreciate if you would please answer
>> this question too (either here or on stackoverflow)
>
> My preferred tool is R.
>
> If you ask me to elaborate: the package systems contains the tools for tests
> and R comes with debugging tools, that way I had never need for much more.
>
> Uwe Ligges
>
>
>>
>> Here is the link to the question
>>
>> http://stackoverflow.com/questions/6796490/tools-for-professional-r-developers
>>
>>
>> Best wishes,
>> Mark

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] filterMicroRna function: Sample replicates in preprocessing Agilent miRNA dataset

2011-07-28 Thread Vickie S

Hi,
I have a question about filterMicroRna in AgiMicroRna package function for 
filtering probes in Agilent microRNA dataset.

>ddPROC = filterMicroRna(ddNORM.micro, dd, control = TRUE, IsGeneDetected = 
>TRUE, wellaboveNEG = FALSE, limIsGeneDetected = 75, limNEG = 25, makePLOT = 
>TRUE, target.micro, verbose = TRUE)

If in a dataset there are two or more sample replicates and in the step of 
filtering probes I want to exclude a probe only if gIsGeneDetected = 0 in all 
two or three sample replicates. 

I don't think by 'filterMicroRna' function provides any option for this type of 
filtering. 

Are there any suggestions ? 

Thanks
Vickie S
  
[[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] Tools for professional R developers

2011-07-28 Thread Bert Gunter
+ ESS or some other reasonably capable text editor?

-- Bert

On Thu, Jul 28, 2011 at 12:14 PM, Uwe Ligges
 wrote:
>
>
> On 28.07.2011 21:04, Mark Alen wrote:
>>
>> Hi everyone,
>>
>> I was wondering what tools professional R users use so I went and posted
>> this question on stack overflow. I appreciate if you would please answer
>> this question too (either here or on stackoverflow)
>
> My preferred tool is R.
>
> If you ask me to elaborate: the package systems contains the tools for tests
> and R comes with debugging tools, that way I had never need for much more.
>
> Uwe Ligges
>
>
>>
>> Here is the link to the question
>>
>> http://stackoverflow.com/questions/6796490/tools-for-professional-r-developers
>>
>>
>> Best wishes,
>> Mark
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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.
>



-- 
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Tools for professional R developers

2011-07-28 Thread Steve Lianoglou
On Thu, Jul 28, 2011 at 3:14 PM, Uwe Ligges
 wrote:
>
>
> On 28.07.2011 21:04, Mark Alen wrote:
>>
>> Hi everyone,
>>
>> I was wondering what tools professional R users use so I went and posted
>> this question on stack overflow. I appreciate if you would please answer
>> this question too (either here or on stackoverflow)
>
> My preferred tool is R.
>
> If you ask me to elaborate: the package systems contains the tools for tests
> and R comes with debugging tools, that way I had never need for much more.

I actually thought this question was pretty ... uhm ... but when I
popped over to SO to see what was cooking there, I was kind of
surprised to see real helpful answers.

Hadley's response is pretty great and worth a read (looking forward to
helpr!), as well as Dirk's and others.

I'd encourage others to check them out.

-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] apply is making me crazy...

2011-07-28 Thread Gene Leynes
Very clever (as usual)…  It works, but since I wanted to switch the rows and
columns, which would require this:

 answer.slightly.clumsy  =
 lapply(exampBad, function(x) matrix(apply(x ,1, cumsum),
 ncol=nrow(x)))

 However, with a slight modification of your code I can use a wrapper
function for apply.  This gives me the functionality, with clean syntax.  I
will probably add to my “standard” library.

apply1 = function(mat, fun){

matrix(apply(mat ,1, fun),  nrow=nrow(mat), byrow=T)

}

res = lapply(exampBad, function(x) apply1(x , cumsum))



As I mentioned in my email to Dennis, I am typically dealing with highly
nested lists of matrices that have one thing in common: 1000 rows.  This
fact makes fact the lapply, sapply, apply, and do.call family extremely
effective, and makes this apply problem something that is worth solving.



PS: I still wish that there were a drop=TRUE option in apply!

 Thanks again,

Gene

On Thu, Jul 28, 2011 at 12:05 PM, David Winsemius wrote:

>
> On Jul 28, 2011, at 12:31 PM, Gene Leynes wrote:
>
>  (As I mentioned in my other reply to Dennis, I think I'll stick with for
>> loops, but I wanted to respond.)
>>
>> By "almost does it" I meant that using as.matrix helps because it puts the
>> vector into a column, that "almost does it” because half the problem is that
>> the output is a non dimensional vector when apply is passed a matrix with
>> one column.
>>
>> However, since the output of the apply function is transposed when you’re
>> doing row margins, the as.matrix doesn’t help because it’s putting your
>> result into a column, while the apply function is putting everything else
>> into rows. I tried several combination of using t() before, after, and
>> during (changing margin=1 to margin=2) the function; but none did the trick.
>>
>> I was not as diligent about using your margin=1:1 suggestion in all my
>> trials, that didn't seem to be different from using margin=1.
>>
>> The problem is a bit hard to describe using a natural language, and I
>> think more apparent from the code.  Of course, that could my shortcoming.
>>
>> I still think that the structure of the proposed solution, which I think
>> makes the problem apparent.
>> > str(answerProposed)
>> List of 3
>>  $ : num [1:1000, 1] 0.5658 0.1759 1.2444 -0.0456 0.0236 ...
>>  $ : num [1:2, 1:1000] 0.0392 0.7047 0.1834 -0.6644 -0.6952 ...
>>  $ : num [1:3, 1:1000] -0.835 -0.0461 -0.1725 0.8365 0.7835 ...
>> >
>>
>
> Sometimes I need to be hit over the head a few times for things to sink in.
> I hadn't noticed the reversal of dimensions in the "1" row case:
>
>  answer.not.Bad  = lapply(exampBad, function(x) matrix(apply(x ,1,cumsum),
>  ncol=nrow(x)))
>
> > str(answer.not.Bad)
> List of 3
>  $ : num [1, 1:1000] -0.159 -0.035 -0.386 -1.81 1.123 ...
>  $ : num [1:2, 1:1000] -0.7801 0.6004 -0.0869 -0.1611 -0.3594 ...
>  $ : num [1:3, 1:1000] -1.14 -2.81 -3.45 3.16 2.54 ...
>
> The 1:1 dodge was useless, anyway. And just to be sure, you did want the
> row and col dimensions reversed? And you did want the first element to just
> be a (transposed) copy of its argument?
>
> Are we good now?
>
> --
> david.
>
>  I want it to do this:
>> > str(answerDesired)
>> List of 3
>>  $ : num [1, 1:1000,] 0.5658 0.1759 1.2444 -0.0456 0.0236 ...
>>  $ : num [1:2, 1:1000] 0.0392 0.7047 0.1834 -0.6644 -0.6952 ...
>>  $ : num [1:3, 1:1000] -0.835 -0.0461 -0.1725 0.8365 0.7835 ...
>> >
>>
>> There are a lot of reasons why I would want the apply function to work
>> this way, or at least have an option to work this way.  One reason is so
>> that you could perform do.call(rbind, mylist) at the later
>>
>> I guess this behavior is described in the apply documentation:
>> “If each call to FUN returns a vector of length n, then apply returns an
>> array of dimension c(n, dim(X)[MARGIN]) if n > 1. If nequals 1, apply
>> returns a vector if MARGIN has length 1 and an array of dimension
>> dim(X)[MARGIN] otherwise. If n is 0, the result has length 0 but not
>> necessarily the ‘correct’ dimension.”
>>
>>
>> I just wish that it had an option to do return an array of dimension c(n,
>> dim(X)[MARGIN]) if n >= 1
>>
>> On Wed, Jul 27, 2011 at 8:25 PM, David Winsemius 
>> wrote:
>>
>> On Jul 27, 2011, at 7:44 PM, Gene Leynes wrote:
>>
>>  David,
>>>
>>> Thanks for the suggestion, but I think your answer only works because I
>>> was printing the wrong thing (because apply with margin=1 transposes the
>>> results,
>>>
>>
>> And if you want to change that,  then the t() function is readily at hand.
>>
>>  something I always forget).
>>>
>>> Check this to see what I mean:
>>>str(answerGood)
>>>str(answerBad)
>>>
>>> Adding "as.matrix" is interesting and almost does it,
>>>
>>
>> "It" ... What is "it"? In a natural language,  ...  English preferably.
>>
>> --
>> david.
>>
>>  however the results are still transposed.
>>>
>>> Sorry to be confusing with the initial example.
>>>
>>> Here's an updated example (adding as.matrix doesn't make

Re: [R] Tools for professional R developers

2011-07-28 Thread Uwe Ligges



On 28.07.2011 21:04, Mark Alen wrote:

Hi everyone,

I was wondering what tools professional R users use so I went and posted this 
question on stack overflow. I appreciate if you would please answer this 
question too (either here or on stackoverflow)


My preferred tool is R.

If you ask me to elaborate: the package systems contains the tools for 
tests and R comes with debugging tools, that way I had never need for 
much more.


Uwe Ligges




Here is the link to the question
http://stackoverflow.com/questions/6796490/tools-for-professional-r-developers


Best wishes,
Mark

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Tools for professional R developers

2011-07-28 Thread Mark Alen
Hi everyone,

I was wondering what tools professional R users use so I went and posted this 
question on stack overflow. I appreciate if you would please answer this 
question too (either here or on stackoverflow)

Here is the link to the question
http://stackoverflow.com/questions/6796490/tools-for-professional-r-developers


Best wishes,
Mark

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] cycling from x11 window in RCommander to graphics device window: Mac Os 10.6.8

2011-07-28 Thread David Winsemius


On Jul 28, 2011, at 1:51 PM, Ista Zahn wrote:


Hi Simon

On Thu, Jul 28, 2011 at 1:40 PM, Simon Kiss  wrote:

Dear Colleagues,
I have recently installed R Commander on my Mac OS 10.6.8. I'd like  
to use it for an undergraduate class this year.
Everything appears to be working fine, except for one thing.  I  
cannot use Command-tab to cycle from the X11 window in which  
RCommander is running to any other window open in my workspace.   
This is particularly important because I cannot cycle to the  
graphics device window that is opened when I call a new plot.  If I  
force quit the X11 window and Rcommander, R remains running and I  
can see the graphics device window and the plot looks fine.


In the Mac GUI, cmd-1 brings up the console window, cmd-3 brings up  
the last auartz window window. Don't know about RCmdr. X11 is its own  
application, so you should be able to cmd-tab to it from an R console  
window. I NEVER close X11() while running R after experiencing crashes  
upon doing so.


And this is probably more appropriate for the MacSIG list. I would  
suggest following up there.


--
David.



My Mac days are long behind me, but surely Command-tab is not the only
way to switch windows! Can't you use the dock, or expose or ...?

A couple of other thoughts. First, check to see if this is specific to
Rcommander, or if you have the same problem in other X11 applications.
Second, you might have better luck on the R-sig-mac mailing list.

Best,
Ista


But as you can imagine, this is quite laborious, having to restart.
I've looked through the help documentation and tried reinstalling  
tcltk prior to opening up Rcommander, but that does not address the  
problem.

Any thoughts?
Yours, Simon Kiss
*
Simon J. Kiss, PhD
Assistant Professor, Wilfrid Laurier University
73 George Street
Brantford, Ontario, Canada
N3T 2C9
Cell: +1 905 746 7606

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





--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] fitting a sinus curve

2011-07-28 Thread David Winsemius


On Jul 28, 2011, at 1:07 PM, Hans W Borchers wrote:


maaariiianne  ec.europa.eu> writes:


Dear R community!
I am new to R and would be very grateful for any kind of help. I am  
a PhD

student and need to fit a model to an electricity load profile of a
household (curve with two peaks). I was thinking of looking if a  
polynomial
of 4th order,  a sinus/cosinus combination or a combination of 3  
parabels
fits the data best. I have problems with the sinus/cosinus  
regression:


time <- c(
0.00, 0.15,  0.30,  0.45, 1.00, 1.15, 1.30, 1.45, 2.00, 2.15, 2.30,  
2.45,
3.00, 3.15, 3.30, 3.45, 4.00, 4.15, 4.30, 4.45, 5.00, 5.15, 5.30,  
5.45, 6.00,
6.15, 6.30, 6.45, 7.00, 7.15, 7.30, 7.45, 8.00, 8.15, 8.30, 8.45,  
9.00, 9.15,
9.30, 9.45, 10.00, 10.15, 10.30, 10.45, 11.00, 11.15, 11.30, 11.45,  
12.00,
12.15, 12.30, 12.45, 13.00, 13.15, 13.30, 13.45, 14.00, 14.15,  
14.30, 14.45,
15.00, 15.15, 15.30, 15.45, 16.00, 16.15, 16.30, 16.45, 17.00,  
17.15, 17.30,
17.45, 18.00, 18.15, 18.30, 18.45, 19.00, 19.15, 19.30, 19.45,  
20.00, 20.15,
20.30, 20.45, 21.00, 21.15, 21.30, 21.45, 22.00, 22.15, 22.30,  
22.45, 23.00,

23.15, 23.30, 23.45)
watt <- c(
94.1, 70.8, 68.2, 65.9, 63.3, 59.5, 55, 50.5, 46.6, 43.9, 42.3,  
41.4, 40.8,
40.3, 39.9, 39.5, 39.1, 38.8, 38.5, 38.3, 38.3, 38.5, 39.1, 40.3,  
42.4, 45.6,
49.9, 55.3, 61.6, 68.9, 77.1, 86.1, 95.7, 105.8, 115.8, 124.9,  
132.3, 137.6,
141.1, 143.3, 144.8, 146, 147.2, 148.4, 149.8, 151.5, 153.5, 156,  
159, 162.4,
165.8, 168.4, 169.8, 169.4, 167.6, 164.8, 161.5, 158.1, 154.9,  
151.8, 149,
146.5, 144.4, 142.7, 141.5, 140.9, 141.7, 144.9, 151.5, 161.9,  
174.6, 187.4,
198.1, 205.2, 209.1, 211.1, 212.2, 213.2, 213, 210.4, 203.9, 192.9,  
179,
164.4, 151.5, 141.9, 135.3, 131, 128.2, 126.1, 124.1, 121.6, 118.2,  
113.4,

107.4, 100.8)


df<-data.frame(time,  watt)
lmfit <- lm(time ~ watt + cos(time) + sin(time),  data = df)


Your regression formula does not make sense to me.
You seem to expect a periodic function within 24 hours, and if not  
it would
still be possible to subtract the trend and then look at a periodic  
solution.
Applying a trigonometric regression results in the following  
approximations:


   library(pracma)
   plot(2*pi*time/24, watt, col="red")
   ts  <- seq(0, 2*pi, len = 100)
   xs6 <- trigApprox(ts, watt, 6)
   xs8 <- trigApprox(ts, watt, 8)
   lines(ts, xs6, col="blue", lwd=2)
   lines(ts, xs8, col="green", lwd=2)
   grid()

where as examples the trigonometric fits of degree 6 and 8 are used.
I would not advise to use higher orders, even if the fit is not  
perfect.


Thank you ! That is a real gem of a worked example. Not only did it  
introduce me to a useful package I was not familiar with, but there  
was even a worked example in one of the help pages that might have  
specifically answered the question about getting a 2nd(?) order trig  
regression. If I understood the commentary on that page, this method  
might also be appropriate for an irregular time series, whereas  
trigApprox and trigPoly would not?


This is adapted from the trigPoly help page in Hans Werner's pracma  
package:


 A <- cbind(1, cos(pi*time/24), sin(pi*time/24), cos(2*pi*time/24),  
sin(2*pi*time/24))

ab <- qr.solve(A, watt)
ab
# [1] 127.29131 -26.88824 -10.06134 -36.22793 -38.56219
ts <- seq(0, pi, length.out = 100)
xs <- ab[1] + ab[2]*cos(ts) +
  ab[3]*sin(ts) + ab[4]*cos(2*ts) +ab[5]*sin(2*ts)
plot(pi*time/24, watt, col = "red", xlim=c(0, pi), ylim=range(watt),
   main = "Trigonometric Regression")
lines(ts, xs, col="blue")

Hans:  I corrected the spelling of "Trigonometric", but other than  
that I may well have introduced other errors for which I would be  
happy to be corrected. For instance, I'm unsure of the terminology  
regarding the ordinality of this model. I'm also not sure if my pi/24  
and 2*pi/24 factors were correct in normalizing the time scale,  
although the prediction seemed sensible.






Hans Werner


Thanks a lot,
Marianne



--
David Winsemius, MD
West Hartford, CT

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


Re: [R] cycling from x11 window in RCommander to graphics device window: Mac Os 10.6.8

2011-07-28 Thread Ista Zahn
Hi Simon

On Thu, Jul 28, 2011 at 1:40 PM, Simon Kiss  wrote:
> Dear Colleagues,
> I have recently installed R Commander on my Mac OS 10.6.8. I'd like to use it 
> for an undergraduate class this year.
> Everything appears to be working fine, except for one thing.  I cannot use 
> Command-tab to cycle from the X11 window in which RCommander is running to 
> any other window open in my workspace.  This is particularly important 
> because I cannot cycle to the graphics device window that is opened when I 
> call a new plot.  If I force quit the X11 window and Rcommander, R remains 
> running and I can see the graphics device window and the plot looks fine.

My Mac days are long behind me, but surely Command-tab is not the only
way to switch windows! Can't you use the dock, or expose or ...?

A couple of other thoughts. First, check to see if this is specific to
Rcommander, or if you have the same problem in other X11 applications.
Second, you might have better luck on the R-sig-mac mailing list.

Best,
Ista

> But as you can imagine, this is quite laborious, having to restart.
> I've looked through the help documentation and tried reinstalling tcltk prior 
> to opening up Rcommander, but that does not address the problem.
> Any thoughts?
> Yours, Simon Kiss
> *
> Simon J. Kiss, PhD
> Assistant Professor, Wilfrid Laurier University
> 73 George Street
> Brantford, Ontario, Canada
> N3T 2C9
> Cell: +1 905 746 7606
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] cycling from x11 window in RCommander to graphics device window: Mac Os 10.6.8

2011-07-28 Thread Simon Kiss
Dear Colleagues, 
I have recently installed R Commander on my Mac OS 10.6.8. I'd like to use it 
for an undergraduate class this year.
Everything appears to be working fine, except for one thing.  I cannot use 
Command-tab to cycle from the X11 window in which RCommander is running to any 
other window open in my workspace.  This is particularly important because I 
cannot cycle to the graphics device window that is opened when I call a new 
plot.  If I force quit the X11 window and Rcommander, R remains running and I 
can see the graphics device window and the plot looks fine.
But as you can imagine, this is quite laborious, having to restart.
I've looked through the help documentation and tried reinstalling tcltk prior 
to opening up Rcommander, but that does not address the problem.
Any thoughts?
Yours, Simon Kiss
*
Simon J. Kiss, PhD
Assistant Professor, Wilfrid Laurier University
73 George Street
Brantford, Ontario, Canada
N3T 2C9
Cell: +1 905 746 7606

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] fitting a sinus curve

2011-07-28 Thread Hans W Borchers
maaariiianne  ec.europa.eu> writes:

> Dear R community! 
> I am new to R and would be very grateful for any kind of help. I am a PhD
> student and need to fit a model to an electricity load profile of a
> household (curve with two peaks). I was thinking of looking if a polynomial
> of 4th order,  a sinus/cosinus combination or a combination of 3 parabels
> fits the data best. I have problems with the sinus/cosinus regression: 

time <- c(
0.00, 0.15,  0.30,  0.45, 1.00, 1.15, 1.30, 1.45, 2.00, 2.15, 2.30, 2.45, 
3.00, 3.15, 3.30, 3.45, 4.00, 4.15, 4.30, 4.45, 5.00, 5.15, 5.30, 5.45, 6.00, 
6.15, 6.30, 6.45, 7.00, 7.15, 7.30, 7.45, 8.00, 8.15, 8.30, 8.45, 9.00, 9.15, 
9.30, 9.45, 10.00, 10.15, 10.30, 10.45, 11.00, 11.15, 11.30, 11.45, 12.00, 
12.15, 12.30, 12.45, 13.00, 13.15, 13.30, 13.45, 14.00, 14.15, 14.30, 14.45, 
15.00, 15.15, 15.30, 15.45, 16.00, 16.15, 16.30, 16.45, 17.00, 17.15, 17.30, 
17.45, 18.00, 18.15, 18.30, 18.45, 19.00, 19.15, 19.30, 19.45, 20.00, 20.15, 
20.30, 20.45, 21.00, 21.15, 21.30, 21.45, 22.00, 22.15, 22.30, 22.45, 23.00, 
23.15, 23.30, 23.45) 
watt <- c(
94.1, 70.8, 68.2, 65.9, 63.3, 59.5, 55, 50.5, 46.6, 43.9, 42.3, 41.4, 40.8, 
40.3, 39.9, 39.5, 39.1, 38.8, 38.5, 38.3, 38.3, 38.5, 39.1, 40.3, 42.4, 45.6, 
49.9, 55.3, 61.6, 68.9, 77.1, 86.1, 95.7, 105.8, 115.8, 124.9, 132.3, 137.6, 
141.1, 143.3, 144.8, 146, 147.2, 148.4, 149.8, 151.5, 153.5, 156, 159, 162.4, 
165.8, 168.4, 169.8, 169.4, 167.6, 164.8, 161.5, 158.1, 154.9, 151.8, 149, 
146.5, 144.4, 142.7, 141.5, 140.9, 141.7, 144.9, 151.5, 161.9, 174.6, 187.4, 
198.1, 205.2, 209.1, 211.1, 212.2, 213.2, 213, 210.4, 203.9, 192.9, 179, 
164.4, 151.5, 141.9, 135.3, 131, 128.2, 126.1, 124.1, 121.6, 118.2, 113.4, 
107.4, 100.8)

> df<-data.frame(time,  watt) 
> lmfit <- lm(time ~ watt + cos(time) + sin(time),  data = df)

Your regression formula does not make sense to me.
You seem to expect a periodic function within 24 hours, and if not it would
still be possible to subtract the trend and then look at a periodic solution.
Applying a trigonometric regression results in the following approximations:

library(pracma)
plot(2*pi*time/24, watt, col="red")
ts  <- seq(0, 2*pi, len = 100)
xs6 <- trigApprox(ts, watt, 6)
xs8 <- trigApprox(ts, watt, 8)
lines(ts, xs6, col="blue", lwd=2)
lines(ts, xs8, col="green", lwd=2)
grid()

where as examples the trigonometric fits of degree 6 and 8 are used.
I would not advise to use higher orders, even if the fit is not perfect.

Hans Werner

> Thanks a lot,  
> Marianne

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] apply is making me crazy...

2011-07-28 Thread David Winsemius


On Jul 28, 2011, at 12:31 PM, Gene Leynes wrote:

(As I mentioned in my other reply to Dennis, I think I'll stick with  
for loops, but I wanted to respond.)


By "almost does it" I meant that using as.matrix helps because it  
puts the vector into a column, that "almost does it” because half  
the problem is that the output is a non dimensional vector when  
apply is passed a matrix with one column.


However, since the output of the apply function is transposed when  
you’re doing row margins, the as.matrix doesn’t help because it’s  
putting your result into a column, while the apply function is  
putting everything else into rows. I tried several combination of  
using t() before, after, and during (changing margin=1 to margin=2)  
the function; but none did the trick.


I was not as diligent about using your margin=1:1 suggestion in all  
my trials, that didn't seem to be different from using margin=1.


The problem is a bit hard to describe using a natural language, and  
I think more apparent from the code.  Of course, that could my  
shortcoming.


I still think that the structure of the proposed solution, which I  
think makes the problem apparent.

> str(answerProposed)
List of 3
 $ : num [1:1000, 1] 0.5658 0.1759 1.2444 -0.0456 0.0236 ...
 $ : num [1:2, 1:1000] 0.0392 0.7047 0.1834 -0.6644 -0.6952 ...
 $ : num [1:3, 1:1000] -0.835 -0.0461 -0.1725 0.8365 0.7835 ...
>


Sometimes I need to be hit over the head a few times for things to  
sink in. I hadn't noticed the reversal of dimensions in the "1" row  
case:


 answer.not.Bad  = lapply(exampBad, function(x) matrix(apply(x , 
1,cumsum),  ncol=nrow(x)))


> str(answer.not.Bad)
List of 3
 $ : num [1, 1:1000] -0.159 -0.035 -0.386 -1.81 1.123 ...
 $ : num [1:2, 1:1000] -0.7801 0.6004 -0.0869 -0.1611 -0.3594 ...
 $ : num [1:3, 1:1000] -1.14 -2.81 -3.45 3.16 2.54 ...

The 1:1 dodge was useless, anyway. And just to be sure, you did want  
the row and col dimensions reversed? And you did want the first  
element to just be a (transposed) copy of its argument?


Are we good now?

--
david.


I want it to do this:
> str(answerDesired)
List of 3
 $ : num [1, 1:1000,] 0.5658 0.1759 1.2444 -0.0456 0.0236 ...
 $ : num [1:2, 1:1000] 0.0392 0.7047 0.1834 -0.6644 -0.6952 ...
 $ : num [1:3, 1:1000] -0.835 -0.0461 -0.1725 0.8365 0.7835 ...
>

There are a lot of reasons why I would want the apply function to  
work this way, or at least have an option to work this way.  One  
reason is so that you could perform do.call(rbind, mylist) at the  
later


I guess this behavior is described in the apply documentation:
“If each call to FUN returns a vector of length n, then apply  
returns an array of dimension c(n, dim(X)[MARGIN]) if n > 1. If  
nequals 1, apply returns a vector if MARGIN has length 1 and an  
array of dimension dim(X)[MARGIN] otherwise. If n is 0, the result  
has length 0 but not necessarily the ‘correct’ dimension.”


I just wish that it had an option to do return an array of dimension  
c(n, dim(X)[MARGIN]) if n >= 1


On Wed, Jul 27, 2011 at 8:25 PM, David Winsemius > wrote:


On Jul 27, 2011, at 7:44 PM, Gene Leynes wrote:


David,

Thanks for the suggestion, but I think your answer only works  
because I was printing the wrong thing (because apply with margin=1  
transposes the results,


And if you want to change that,  then the t() function is readily at  
hand.



something I always forget).

Check this to see what I mean:
str(answerGood)
str(answerBad)

Adding "as.matrix" is interesting and almost does it,


"It" ... What is "it"? In a natural language,  ...  English  
preferably.


--
david.


however the results are still transposed.

Sorry to be confusing with the initial example.

Here's an updated example (adding as.matrix doesn't make a  
difference)



## Make three example matricies
exampGood = lapply(2:4, function(x)matrix(rnorm(1000*x),ncol=x))
exampBad  = lapply(1:3, function(x)matrix(rnorm(1000*x),ncol=x))
## Two ways to see what was created:
for(k in 1:length(exampGood)) print(dim(exampGood[[k]]))
for(k in 1:length(exampBad)) print(dim(exampBad[[k]]))

##  Take the cumsum of each row of each matrix
answerGood =  lapply(exampGood, function(x) apply(x ,1,cumsum))
answerBad  =  lapply(exampBad, function(x) apply(x ,1,cumsum))
answerProposed  = lapply(exampBad, function(x) as.matrix(apply(x , 
1:1,cumsum)))

str(answerGood)
str(answerBad)
str(answerProposed)

##  Take the first element of the final column of each answer
for(mat in answerGood){
mat = t(mat)  ## To get back to 1000 rows
LastColumn = ncol(mat)
print(mat[2,LastColumn])
}
for(mat in answerBad){
mat = t(mat)  ## To get back to 1000 rows
LastColumn = ncol(mat)
print(mat[2,LastColumn])
}
for(mat in answerProposed){
mat = t(mat)  ## To get back to 1000 rows
LastColumn = ncol(mat)
print(mat[2,LastColumn])
}



On Wed, Jul 27, 2011 at 5:45 PM, David Winsemius > wrote:


On Jul 27, 2011, at 6:22 PM, Gene Leynes wrote:

I have

Re: [R] Extend my code to run several data at once.

2011-07-28 Thread Daniel Malter
No, I may not. If you want somebody to check out your code, please adhere to
the posting guide (which you should in all your posts), which requires you
to provide minimally self-contained code (i.e., an example that we can
directly copy-paste to R-prompt). But I will give you an example:

Your llik() is a function just like mean() or sd() is. It's just more
complex.

If you want to apply a function over rows or columns of a matrix or data
frame, you use the apply function. For example: If you data is a matrix with
columns x, y, and z. You can get the row means or columns means by using
apply().

data<-cbind(x<-rnorm(100,0,1),y<-rnorm(100,2,1),z<-rnorm(100,-1,1))

#Row mean

apply(data,1,mean)

#Column mean

apply(data,2,mean)


In the same way you can apply your llik() function over rows or columns of a
data frame or matrix. And for future posts, please adhere to the posting
guide and provide a self-contained example like I just did. Everything else
is a pain for those who are trying to help you.

Best,
Daniel

p.s. Maybe you failed to do it because R doesn't run on your Blackberry. :D








EdBo wrote:
> 
> Hi Daniel,
> 
> I am still failing to do that? May you look at my look. It is calculating
> the estimates for one row. How do I incorporate the other data that has
> all other columns?
> 
> Thanks
> 
> Ed
> Sent from BlackBerry® wireless device
> 
> -Original Message-
> From: "Daniel Malter [via R]"
> 
> Date: Sat, 23 Jul 2011 14:43:30 
> To: EdBo
> Subject: Re: Extend my code to run several data at once.
> 
> 
> 
> If you just want to apply the function over successive columns of a data
> frame use
> 
> apply(name.of.data.frame, 2 , llik)
> 
> Daniel
> 
> 
> EdBo wrote:
>> 
>> Hi
>> 
>> I have a code that calculate maximisation using optimx and it is working
>> just fine. I want to extend the code to run several colomns of R_j where
>> j
>> runs from 1 to 200. If I am to run the code in its current state, it
>> means
>> I will have to run it 200 times manually. May you help me adjust it to
>> accomodate several rows of R_j and print the 200 results.
>> 
>> ***Please do not get intimidated by the maths in the code.***
>> 
>> my code
>> ##
>> afull=read.table("D:/hope.txt",header=T)
>> library(optimx) 
>> llik = function(x) 
>>{ 
>> al_j=x[1]; au_j=x[2]; sigma_j=x[3];  b_j=x[4]
>> sum(na.rm=T,
>> ifelse(a$R_j< 0, log(1 / ( sqrt(2*pi) * sigma_j) )-
>>(1/( 2*sigma_j^2 ) ) * ( 
>> (a$R_j+al_j-b_j*a$R_m)^2 ) , 
>> 
>>  ifelse(a$R_j>0 , log(1 / ( sqrt(2*pi) * sigma_j) )-
>>(1/( 2*sigma_j^2 ) ) * ( 
>> (a$R_j+al_j-b_j*a$R_m)^2 ) ,
>> 
>>  log(ifelse (( pnorm (au_j, mean=b_j * a$R_m, 
>> sd= sqrt(sigma_j^2))-
>>pnorm(al_j, mean=b_j * a$R_m, sd=sqrt
>> (sigma_j^2)) ) > 0,
>> 
>>  (pnorm (au_j,mean=b_j * a$R_m, sd= 
>> sqrt(sigma_j^2))-
>>pnorm(al_j, mean=b_j * a$R_m, sd=
>> sqrt(sigma_j^2) )),
>>  1) ) ) )
>>   )
>>} 
>> start.par = c(-0.01,0.01,0.1,1) 
>> 
>> #looping now
>> runs=133/20+1
>> 
>> 
>> out <- matrix(NA, nrow = runs, ncol = 4,
>> 
>> dimnames = list(paste("Qtr:", 1:runs , sep = ''),
>> 
>> c("al_j", "au_j", "sigma_j", "b_j"))) 
>> 
>>   
>> ## Estimate parameters based on rows 0-20, 21-40, 41-60 of afull
>> for (i in 1:runs) {
>>  index_start=20*(i-1)+1
>>  index_end= 20*i
>>  a=afull[index_start:index_end,]
>>  out[i, ] <- optimx(llik,par = start.par,method = "Nelder-Mead",
>> control=list(maximize=TRUE) )[[1]][[1]]
>>  } 
>> 
>> ## Yields 
>>> out
>>al_jau_j sigma_jb_j
>> Qtr:1  0.0012402032 0.001082986 0.012889809 1.14095125
>> Qtr:2  0.0011302178 0.582718275 0.009376083 0.06615565
>> Qtr:3  0.0013349347 0.417495301 0.013286103 0.60548903
>> Qtr:4 -0.0016659441 0.162250321 0.015088915 0.67395511
>> Qtr:5  0.0043159984 0.004315976 0.013153039 1.17341907
>> Qtr:6  0.0027333033 0.527280348 0.018423347 0.53905153
>> Qtr:7 -0.0009214064 0.749695104 0.008730072 0.02108032
>>>
>> 
> 
> ___
> If you reply to this email, your message will be added to the discussion
> below:
> http://r.789695.n4.nabble.com/Extend-my-code-to-run-several-data-at-once-tp3688823p3689534.html
> 
> To unsubscribe from Extend my code to run several data at once., visit
> http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3688823&code=bi5ib3dvcmFAZ21haWwuY29tfDM2ODg4MjN8LTEwOTc4OTY3Mw==
> 
Hi Daniel,

I am still failing to do that? May you look at my look. It is calculating
the estimates for one row. How do I incorporate the other data that has all
other columns?

Thanks

Ed
Sent from BlackBerry® wireless device

-Original Messa

Re: [R] apply is making me crazy...

2011-07-28 Thread Gene Leynes
(As I mentioned in my other reply to Dennis, I think I'll stick with for
loops, but I wanted to respond.)


By "almost does it" I meant that using as.matrix helps because it puts the
vector into a column, that "almost does it” because half the problem is that
the output is a non dimensional vector when apply is passed a matrix with
one column.



However, since the output of the apply function is transposed when you’re
doing row margins, the as.matrix doesn’t help because it’s putting your
result into a column, while the apply function is putting everything else
into rows. I tried several combination of using t() before, after, and
during (changing margin=1 to margin=2) the function; but none did the trick.


I was not as diligent about using your margin=1:1 suggestion in all my
trials, that didn't seem to be different from using margin=1.



The problem is a bit hard to describe using a natural language, and I think
more apparent from the code.  Of course, that could my shortcoming.


I still think that the structure of the proposed solution, which I think
makes the problem apparent.

> str(answerProposed)

List of 3

 $ : num [1:1000, 1] 0.5658 0.1759 1.2444 -0.0456 0.0236 ...

 $ : num [1:2, 1:1000] 0.0392 0.7047 0.1834 -0.6644 -0.6952 ...

 $ : num [1:3, 1:1000] -0.835 -0.0461 -0.1725 0.8365 0.7835 ...

>

I want it to do this:

> str(answerDesired)

List of 3

 $ : num [1, 1:1000,] 0.5658 0.1759 1.2444 -0.0456 0.0236 ...

 $ : num [1:2, 1:1000] 0.0392 0.7047 0.1834 -0.6644 -0.6952 ...

 $ : num [1:3, 1:1000] -0.835 -0.0461 -0.1725 0.8365 0.7835 ...

>


There are a lot of reasons why I would want the apply function to work this
way, or at least have an option to work this way.  One reason is so that you
could perform do.call(rbind, mylist) at the later



I guess this behavior is described in the apply documentation:

“If each call to FUN returns a vector of length n, then apply returns an
array of dimension c(n, dim(X)[MARGIN]) if n > 1. If n equals 1,
applyreturns a vector if
MARGIN has length 1 and an array of dimension dim(X)[MARGIN] otherwise. If nis
0, the result has length 0 but not necessarily the ‘correct’ dimension.”



I just wish that it had an option to do return an array of dimension c(n,
dim(X)[MARGIN]) if n >= 1

On Wed, Jul 27, 2011 at 8:25 PM, David Winsemius wrote:

>
> On Jul 27, 2011, at 7:44 PM, Gene Leynes wrote:
>
> David,
>
> Thanks for the suggestion, but I think your answer only works because I was
> printing the wrong thing (because apply with margin=1 transposes the
> results,
>
>
> And if you want to change that,  then the t() function is readily at hand.
>
> something I always forget).
>
> Check this to see what I mean:
> str(answerGood)
> str(answerBad)
>
> Adding "as.matrix" is interesting and almost does it,
>
>
> "It" ... What is "it"? In a natural language,  ...  English preferably.
>
> --
> david.
>
> however the results are still transposed.
>
> Sorry to be confusing with the initial example.
>
> Here's an updated example (adding as.matrix doesn't make a difference)
>
>
> ## Make three example matricies
> exampGood = lapply(2:4, function(x)matrix(rnorm(1000*x),ncol=x))
> exampBad  = lapply(1:3, function(x)matrix(rnorm(1000*x),ncol=x))
> ## Two ways to see what was created:
> for(k in 1:length(exampGood)) print(dim(exampGood[[k]]))
> for(k in 1:length(exampBad)) print(dim(exampBad[[k]]))
>
> ##  Take the cumsum of each row of each matrix
> answerGood =  lapply(exampGood, function(x) apply(x ,1,cumsum))
> answerBad  =  lapply(exampBad, function(x) apply(x ,1,cumsum))
> answerProposed  = lapply(exampBad, function(x) as.matrix(apply(x
> ,1:1,cumsum)))
> str(answerGood)
> str(answerBad)
> str(answerProposed)
>
> ##  Take the first element of the final column of each answer
> for(mat in answerGood){
> mat = t(mat)  ## To get back to 1000 rows
> LastColumn = ncol(mat)
> print(mat[2,LastColumn])
> }
> for(mat in answerBad){
> mat = t(mat)  ## To get back to 1000 rows
> LastColumn = ncol(mat)
> print(mat[2,LastColumn])
> }
> for(mat in answerProposed){
> mat = t(mat)  ## To get back to 1000 rows
> LastColumn = ncol(mat)
> print(mat[2,LastColumn])
> }
>
>
>
> On Wed, Jul 27, 2011 at 5:45 PM, David Winsemius 
> wrote:
>
>>
>> On Jul 27, 2011, at 6:22 PM, Gene Leynes wrote:
>>
>>  I have tried a lot of ways around this, but I can't find a way to make
>>> apply
>>> work in a generalized way because it causes a failure whenever reduces
>>> the
>>> dimensions of its output.
>>> The following example is easier to understand than the question.
>>>
>>> I wish it had a "drop=TRUE/FALSE" option like the "["  (and I wish I had
>>> found the drop option a year ago, and I wish that I had 1e6 dollars...
>>> Oops,
>>> I mean euros).
>>>
>>>
>>>   ## Make three example matricies
>>>   exampGood = lapply(2:4, function(x)matrix(rnorm(1000***x),ncol=x))
>>>   exampBad  = lapply(1:3, function(x)matrix(rnorm(1000***x),ncol=x))
>>>   ## Two way

Re: [R] Python difflib R equivalent?

2011-07-28 Thread Prof Brian Ripley

On Thu, 28 Jul 2011, Bert Gunter wrote:


Paul:

1. I do not know if any such library exists.


Not to my knowledge, and we have contemplated providing such 
functions.  But for files see e.g. tools::Rdiff, and generally R will 
not be a good way to do this sort of thing on files (since the 
flexibility of R's i/o via connections does have a cost)



2. However, if I understand correctly, one usually does this sort of
thing in R with functions like ?match (or ?"%in%") and logical
comparison operations like ?"==" .  Of course, for numeric
comparisons, you need to be aware of R FAQ 7.31

If you are interested in comparing what in R are character vectors,
then various string operators, e.g. ?grep, ?regexp and character
operation packages (e.g. gsubfn, stringr) may be of use.

As usual, you are more likely to receive a helpful answer if you do as
the posting guide requests and provide a small, reproducible example
of the sort(s) of thing(s) you want to do.


Or at least a URI of examples you wish to emulate, which for difflib 
seem to be the sort of thing POSIX diff and friends are used for.



Cheers,
Bert

On Thu, Jul 28, 2011 at 4:05 AM, Paul  wrote:

Hi,

Does anyone know of a R library that is equivalent in functionality to
the Python standard libraries' difflib library? The python docs say
this about difflib:

"This module provides classes and functions for comparing sequences.
It can be used for example, for comparing files, and can produce
difference information in various formats, including HTML and context
and unified diffs."

http://docs.python.org/library/difflib.html

Thanks,

Paul

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





--
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

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



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

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


Re: [R] R

2011-07-28 Thread David Winsemius


On Jul 28, 2011, at 11:35 AM, Bert Gunter wrote:


Homework?

We try not to do homework on this list.




-- Bert

On Thu, Jul 28, 2011 at 8:11 AM, Rui Oliveira  
 wrote:

Good afternoon.

I am a master student in University of Porto in Portugal. At this  
moment I’m

starting to use R, so I have some doubts.

The aim of my analysis is:  calculate a pairwise FST matrix from  
fasta file
and creat a principal component analyses with adegenet package (I  
use seqinr
and ape package to read this file, then I convert this file into a  
genind
object with DNA2genind function provide in adegenet package). After  
convert

my file the pairwise.fst function is not found.

If you could help me would be great.

Greetings: Rui Oliveira



David Winsemius, MD
West Hartford, CT

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


Re: [R] Calculating difference in variable values (e.g. elapsed time) in data frame

2011-07-28 Thread Sarah Goslee
Hi,

On Thu, Jul 28, 2011 at 11:38 AM, Philippe Hensel
 wrote:
> Hello,
>
> I have a data frame containing time (e.g. GMT), and I would like to
> create/add a new variable that would be the computation of the elapsed time
> since the first observation.  Does anyone have a suggestion for an easy way
> to do this?  I am having trouble creating a new variable that would contain
> just the first time observation (then I could take difference between actual
> time and initial time).
>
> e.g. - here's a brief representation of the data:
>
> time <-
>  c("19:36:11","19:36:12","19:36:13","19:36:14","19:36:15","19:36:16")
> strptime(time, "%H:%M:%S")
> y<-c(197,194,189,179,166,150)
> mydata<-data.frame(time=time,y=y)
>
> OK, now how do I create a new variable, say, time_el, that would calculate
> the elapsed time since 19:36:11?  I assume that I need the strptime()
> function to make sure R treats the character strings as time.

Thank you for providing a small reproducible example!

You missed one step, which is assigning the result of strptime() to a variable.
After that, you can just subtract.

time <-  c("19:36:11","19:36:12","19:36:13","19:36:14","19:36:15","19:36:16")
time <- strptime(time, "%H:%M:%S")
y<-c(197,194,189,179,166,150)
timeel <- time - time[1]
mydata<-data.frame(time=time, y=y, timeel=timeel)

Sarah
-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 with R

2011-07-28 Thread Sarah Goslee
Hi Mark,

On Thu, Jul 28, 2011 at 10:44 AM,   wrote:
>
>   1.  How can I plot the entire tree produced by rpart?

What does plot() not do that you are expecting?

>   2.  How can I submit a vector of values to a tree produced by rpart and have
>   it make an assignment?

What does predict() not do that you are expecting?


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] R

2011-07-28 Thread David Winsemius


On Jul 28, 2011, at 11:54 AM, David Winsemius wrote:

On Thu, Jul 28, 2011 at 8:11 AM, Rui Oliveira  
 wrote:

Good afternoon.

I am a master student in University of Porto in Portugal. At this  
moment I’m

starting to use R, so I have some doubts.

The aim of my analysis is:  calculate a pairwise FST matrix from  
fasta file
and creat a principal component analyses with adegenet package (I  
use seqinr
and ape package to read this file, then I convert this file into a  
genind
object with DNA2genind function provide in adegenet package).  
After convert

my file the pairwise.fst function is not found.


That suggests a problem in loading the adegenet package. You should  
post a copy of your console transcript and post sessionInfo() ... as  
is requested in the Posting Guide.




If you could help me would be great.

Greetings: Rui Oliveira


Sorry for the blank message. Meant to come back to edit it.

David Winsemius, MD
West Hartford, CT

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


Re: [R] Problem with anova.lmRob() "robust" package

2011-07-28 Thread Ista Zahn
I found the question really confusing as well, but see below.

On Thu, Jul 28, 2011 at 11:42 AM, David Winsemius
 wrote:
>
> On Jul 28, 2011, at 9:13 AM, m.fen...@libero.it wrote:
>
>>
>> Dear R users,
>> I'd like to known your opinion about a problem with anova.lmRob() of
>> "Robust" package that occurs when I run a lmRob() regression on my dataset.
>> I check my univariate model by single object anova as anova(lmRob(y~x)).
>> If I compare my model with the null model (y~1), I must obtain the same
>> results,
>> but not for my data.
>> Is it possible?
>>
>> My example:
>>
>> x<-c(rep(0,8),rep(1,8),rep(2,7))
>>
>> y<-c(1,0.6,-0.8,0.7,1.6,-0.2,-1.2,-3.8,-1.8,-2.6,-1.7,-2.1,-0.3,-1.4,1.4,-0.3,-0.3,0.5,0.4,-0.9,-1.6,0.4,0.4)
>> library(robust)
>> lmR<-lmRob(y~factor(x))
>> anova(lmR)
>> lmR0<-lmRob(y~1)
>> anova(lmR,lmR0)
>>
>> If I run the code omitting the factor() (then treating "x" as continuous),
>> the results are the same..
>>
>
> I do not get the same results with that code. And the code does not appear
> to track your description, since the second model does not have an "x" term
> in it. Even when I create the model that it sounded as though you would have
> written, namely lmR0 <- lmRob(y ~ x),  it is clearly _not_ the same result.
>
>> coef(lmR)
> (Intercept)  factor(x)1  factor(x)2
>  0.2428571  -1.3432007  -0.400
>> coef(lmR0)
>  (Intercept)            x
> -0.509524217  0.005820355
>>
>> What is the explanation of these different results?
>
> Since you didn't post your results and since your complaint was that they
> are "the same", it's hard to know what you are talking about.

I think the question is why

lm1 <- lm(y ~ factor(x))
lm0 <- lm(y ~ 1)
anova(lm1)
anova(lm0, lm1)

gives the same result, but

lmR<-lmRob(y~factor(x))
lmR0<-lmRob(y~1)
anova(lmR)
anova(lmR,lmR0)

does not.

I don't know the answer, but I think it is an interesting question.

Best,
Ista

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



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Fixed effects using Within transformation in PLM package

2011-07-28 Thread Peter Ehlers

On 2011-07-28 06:21, Luca Deckert wrote:

Dear R community,

I am trying to do my own fixed effects regression using the Within function
in PLM. I apply the Within function to all my pseries and then run OLS on
the transformed vectors using lm().

When I compare the results to those obtained via plm ("within"), the
estimates are not always the same. Specifically, if there are missing values
(NA), the parameter estimates are not the same. I am aware that standard
errors and degrees of freedom have to be corrected. However, as far as I
know the parameter estimates should be the same.

Is R doing any specific correction for the missing values?


?lm tells you what lm() is doing about missing values. I don't know
what the plm [sic] package does. If you post a *minimal*
example (*not* in HTML) showing the problem, you're likely to
get someone to offer assistance.

Peter Ehlers



I really appreciate any comments on this.

Regards,

Luca

[[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] create a index.date column

2011-07-28 Thread jose Bartolomei




Dear Dennis,
I appreciate your time.
I studied and implemented
your recommendation and is exactly what I needed.

I was in an unproductive
loop in this.

Thank you very much,
Jose
> Date: Wed, 27 Jul 2011 14:28:51 -0700
> Subject: Re: [R] create a index.date column
> From: djmu...@gmail.com
> To: surfpr...@hotmail.com
> CC: r-help@r-project.org
> 
> Hi:
> 
> I prefer to use one of the summarization packages for this sort of
> thing, but aggregate() works, too. Here are two versions of the same
> idea:
> 
> # Uses ddply() in the plyr package:
> index.date <- function(d) {
>  require('plyr')
>  out1 <- ddply(d, .(id, rcat), summarise, index = max(tdiff))
>  ndate <- as.numeric(as.Date('2002-09-01')) - out1[['index']]
>  out1$index.date <- as.Date(ndate, origin = '1970-01-01')
>  out1 <- out1[, -3]
>  out1
>}
> 
> # Uses aggregate() from the base package:
> index.date2 <- function(d) {
>  out <- aggregate(tdiff ~ id + rcat, data = d, FUN = max)
> ndate <- as.numeric(as.Date('2002-09-01')) - out[['tdiff']]
>  out$index.date <- as.Date(ndate, origin = '1970-01-01')
>  out <- out[, -3]
>  out
>}
> 
> index.date(test)
> index.date2(test)
> 
> In each function, I did the following:
> 
> (1) Found the maximum time difference from the reference date 2002-09-01.
> (2) Determined the numeric value of the date associated with the max
> time difference (ndate)
> (3) Determined the date associated with the maximum time difference
> and assigned it the variable name index.date in the output data frame.
> (4) Removed the variable computed in (1) from the output data frame.
> (5) Return the output data frame and exit.
> 
> HTH,
> Dennis
> 
> On Wed, Jul 27, 2011 at 6:38 AM, jose Bartolomei  
> wrote:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Dear
> > R users,
> >
> >
> >
> > I
> > created a matrix that tells me the first day of use of a category by
> > id.
> >
> >
> >
> > #Calculate
> > time difference
> > test$tdiff<-as.numeric(difftime(as.Date("2002-09-01"), test$ftime, units = 
> > "days"))
> >
> >
> >
> > #
> > obtain the index date per person and dcategory
> > index.date.test<-tapply(test$tdiff,
> > list(test$id, test$rcat), max)
> >
> >
> >
> > Nonetheless,
> > at the moment I think will be more useful to create a column in my
> > data that tells me which row is the index date.
> >
> >
> >
> >
> > Something
> > like:
> >
> >
> >
> > ti<-function(x){
> >ifelse(x==max(x),
> > "i", "n") # x = test$tdiff
> > }
> >
> >
> >
> > tapply(test$tdiff,
> > list(test$rcat, test$id), FUN=ti)
> >
> >
> >
> > I
> > have been testing different things for few days but I am in a loop
> > and I do not see my mistake.
> >
> >
> >
> > It
> > should be simple but I can't get it
> >
> >
> >
> > Bellow
> > a test data
> >
> >
> >
> > Thanks in advance for your time,
> > Jose
> > Back ground info:  I want to use the index.date to obtain information from 
> > other df for every id six month previous the index date.
> > Then I should normalize the ftime to a common time frame and look form 
> > patterns in that time frame.
> > (Do not know yet how I will do it. )
> >
> >
> >
> >
> >
> >
> > ###
> > test data 
> >
> >
> >
> > structure(list(id = c(1L, 1L, 1L, 46L, 80L, 80L, 80L, 80L, 88L,
> > 160L, 179L, 179L, 179L, 179L, 179L, 179L, 192L, 192L, 192L, 204L,
> > 204L, 204L, 204L, 205L, 211L, 233L, 233L, 272L, 272L, 272L, 272L,
> > 309L, 309L, 309L, 310L, 310L, 314L, 314L, 315L, 316L, 320L, 320L,
> > 320L, 320L, 324L, 324L, 324L, 329L, 329L, 339L, 354L, 354L, 354L,
> > 357L, 358L, 359L, 364L, 366L, 377L, 377L, 377L, 377L, 377L, 377L,
> > 377L, 377L, 377L, 377L, 377L, 377L, 379L, 383L, 383L, 387L, 387L,
> > 391L, 395L, 398L, 401L, 401L, 401L, 401L, 401L, 407L, 407L, 407L,
> > 409L, 414L, 414L, 414L, 434L, 434L, 434L, 437L, 437L, 437L, 437L,
> > 437L, 439L, 439L, 439L, 439L, 442L, 443L, 450L, 452L, 452L, 459L,
> > 459L, 468L, 472L, 472L, 472L, 478L, 478L, 484L, 484L, 484L, 484L,
> > 484L, 486L, 486L, 486L, 487L, 487L, 487L, 487L, 487L), ftime = 
> > structure(c(11761,
> > 11824, 11925, 11852, 11814, 11814, 11929, 11929, 11902, 11857,
> > 11779, 11779, 11807, 11841, 11871, 11899, 11831, 11894, 11925,
> > 11761, 11801, 11843, 11905, 11832, 11877, 11838, 11901, 11783,
> > 11783, 11818, 11850, 11750, 11782, 11905, 11852, 11877, 11852,
> > 11922, 11855, 11838, 11845, 11878, 11901, 11927, 11795, 11817,
> > 11837, 11901, 11928, 11853, 11751, 11751, 11877, 11922, 11760,
> > 11914, 11857, 11912, 11752, 11752, 11785, 11785, 11825, 11825,
> > 11862, 11862, 11891, 11891, 11926, 11926, 11919, 11907, 11907,
> > 11842, 11873, 11842, 11922, 11865, 11782, 11829, 11858, 11888,
> > 11912, 11750, 11803, 11897, 11871, 11787, 11787, 11787, 11764,
> > 11817, 11882, 11778, 11808, 11863, 11894, 11918, 11771, 11817,
> > 11851, 11907, 11799, 11766, 11794, 11765, 11828, 11788, 11884,
> > 11897, 11810, 11852, 11922, 11810, 11846, 11801, 11835, 11859,
> > 11891, 11922, 11771, 11884, 11925, 11765, 11765, 11801, 1184

Re: [R] construct a data set

2011-07-28 Thread nandan amar
Dear Michael and Vettorazzi,
Thanks.
It was really helpful.
I got the desired answer .
Actually I had some weekly data and i wanted to put in ts class for
some time series related test.
Thanks a lot :)

On Thu, Jul 28, 2011 at 8:20 PM, Eik Vettorazzi
 wrote:
> Hi Amar,
> you might have a look at ?ts, which creates time-series objects (as
> AirPassengers actually is, see class(AirPassengers)).
>
> hth
>
> Am 28.07.2011 11:27, schrieb nandan amar:
>> Hi,
>> i want to construct a data set similar to  "AirPassengers".
>> Its attributes are following.
>>
>>> attributes(AirPassengers)
>> $tsp
>> [1] 1949.000 1960.917   12.000
>>
>> $class
>> [1] "ts"
>>
>>
>> How Can I construct a data set similar to it having same class and 
>> attributes.
>> Thanks
>> --
>> Amar Kumar Nandan
>> ✉:nandan.a...@gmail.com
>> http://aknandan.co.nr
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
> --
> Eik Vettorazzi
> Institut für Medizinische Biometrie und Epidemiologie
> Universitätsklinikum Hamburg-Eppendorf
>
> Martinistr. 52
> 20246 Hamburg
>
> T ++49/40/7410-58243
> F ++49/40/7410-57790
>



-- 
Amar Kumar Nandan
Karnataka, India, 560100

☎:+91-9019054471

✉:nandan.a...@gmail.com

http://aknandan.co.nr

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


Re: [R] Problem with anova.lmRob() "robust" package

2011-07-28 Thread David Winsemius


On Jul 28, 2011, at 9:13 AM, m.fen...@libero.it wrote:



Dear R users,
I'd like to known your opinion about a problem with anova.lmRob() of  
"Robust" package that occurs when I run a lmRob() regression on my  
dataset.
I check my univariate model by single object anova as  
anova(lmRob(y~x)).
If I compare my model with the null model (y~1), I must obtain the  
same results,

but not for my data.
Is it possible?

My example:

x<-c(rep(0,8),rep(1,8),rep(2,7))
y<- 
c 
(1,0.6 
,-0.8,0.7,1.6 
,-0.2 
,-1.2 
,-3.8 
,-1.8 
,-2.6,-1.7,-2.1,-0.3,-1.4,1.4,-0.3,-0.3,0.5,0.4,-0.9,-1.6,0.4,0.4)

library(robust)
lmR<-lmRob(y~factor(x))
anova(lmR)
lmR0<-lmRob(y~1)
anova(lmR,lmR0)

If I run the code omitting the factor() (then treating "x" as  
continuous), the results are the same..




I do not get the same results with that code. And the code does not  
appear to track your description, since the second model does not have  
an "x" term in it. Even when I create the model that it sounded as  
though you would have written, namely lmR0 <- lmRob(y ~ x),  it is  
clearly _not_ the same result.


> coef(lmR)
(Intercept)  factor(x)1  factor(x)2
  0.2428571  -1.3432007  -0.400
> coef(lmR0)
 (Intercept)x
-0.509524217  0.005820355


What is the explanation of these different results?


Since you didn't post your results and since your complaint was that  
they are "the same", it's hard to know what you are talking about.


--
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] Calculating difference in variable values (e.g. elapsed time) in data frame

2011-07-28 Thread Philippe Hensel

Hello,

I have a data frame containing time (e.g. GMT), and I would like to 
create/add a new variable that would be the computation of the elapsed 
time since the first observation.  Does anyone have a suggestion for an 
easy way to do this?  I am having trouble creating a new variable that 
would contain just the first time observation (then I could take 
difference between actual time and initial time).


e.g. - here's a brief representation of the data:

time <-  
c("19:36:11","19:36:12","19:36:13","19:36:14","19:36:15","19:36:16")

strptime(time, "%H:%M:%S")
y<-c(197,194,189,179,166,150)
mydata<-data.frame(time=time,y=y)

OK, now how do I create a new variable, say, time_el, that would 
calculate the elapsed time since 19:36:11?  I assume that I need the 
strptime() function to make sure R treats the character strings as time.


Thank you very much for any & all assistance!

-Philippe

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] R

2011-07-28 Thread Bert Gunter
Homework?

We try not to do homework on this list.

-- Bert

On Thu, Jul 28, 2011 at 8:11 AM, Rui Oliveira  wrote:
> Good afternoon.
>
> I am a master student in University of Porto in Portugal. At this moment I’m
> starting to use R, so I have some doubts.
>
> The aim of my analysis is:  calculate a pairwise FST matrix from fasta file
> and creat a principal component analyses with adegenet package (I use seqinr
> and ape package to read this file, then I convert this file into a genind
> object with DNA2genind function provide in adegenet package). After convert
> my file the pairwise.fst function is not found.
>
> If you could help me would be great.
>
> Greetings: Rui Oliveira
>
> --
> ---
> Rui Manuel Oliveira
>
>        [[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.
>
>



-- 
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

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


[R] Help with modFit of FME package

2011-07-28 Thread Paola Lecca
Dear R users,

I'm trying to fit a set an ODE to an experimental time series. In the 
attachment you find the R code I wrote using modFit and modCost of FME package 
and the file of the time series.

When I run summary(Fit) I obtain this error message, and the values of the 
parameters are equal to the initial guesses I gave  to them.

The problem is not due to the fact that I have only one equation (I tried also 
with more equations, but I still obtain this error).

I would appreciate if someone could help me in understanding the reason of the 
error and in fixing it.

Thanks for your attention,
Paola Lecca.

Here the error:

> summary(Fit)

Parameters:
  Estimate Std. Error t value Pr(>|t|)
pro1_strength1 NA  NA   NA

Residual standard error: 2.124 on 10 degrees of freedom
Error in cov2cor(x$cov.unscaled) : 'V' is not a square numeric matrix
In addition: Warning message:
In summary.modFit(Fit) : Cannot estimate covariance; system is singular



timepp1_mrna
0   0
2   2.754
4   2.958
6   4.058
8   3.41
10  3.459
12  2.453
14  1.234
16  2.385
18  3.691
20  3.252
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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

2011-07-28 Thread Rui Oliveira
Good afternoon.

I am a master student in University of Porto in Portugal. At this moment I’m
starting to use R, so I have some doubts.

The aim of my analysis is:  calculate a pairwise FST matrix from fasta file
and creat a principal component analyses with adegenet package (I use seqinr
and ape package to read this file, then I convert this file into a genind
object with DNA2genind function provide in adegenet package). After convert
my file the pairwise.fst function is not found.

If you could help me would be great.

Greetings: Rui Oliveira

-- 
---
Rui Manuel Oliveira

[[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 with modFit of FME package

2011-07-28 Thread Paola Lecca
Dear R users,



I’m trying to fit a set an ODE to an experimental time series. In the
attachment you find the R code I wrote using modFit and modCost of FME
package and the file of the time series.



When I run summary(Fit) I obtain this error message, and the values of the
parameters are equal to the initial guesses I gave  to them.



The problem is not due to the fact that I have only one equation (I tried
also with more equations, but I still obtain this error).



I would appreciate if someone could help me in understanding the reason of
the error and in fixing it.



Thanks for your attention,

Paola.



Here the error:



> summary(Fit)



Parameters:

  Estimate Std. Error t value Pr(>|t|)

pro1_strength1 NA  NA   NA



Residual standard error: 2.124 on 10 degrees of freedom

Error in cov2cor(x$cov.unscaled) : 'V' is not a square numeric matrix

In addition: Warning message:

In summary.modFit(Fit) : Cannot estimate covariance; system is singular




-- 
*Paola Lecca, PhD*
*The Microsoft Research - University of Trento*
*Centre for Computational and Systems Biology*
*Piazza Manci 17 38123 Povo/Trento, Italy*
*Phome: +39 0461282843*
*Fax: +39 0461282814*
timepp1_mrna
0   0
2   2.754
4   2.958
6   4.058
8   3.41
10  3.459
12  2.453
14  1.234
16  2.385
18  3.691
20  3.252
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Help with R

2011-07-28 Thread mark

   1.  How can I plot the entire tree produced by rpart?

   2.  How can I submit a vector of values to a tree produced by rpart and have
   it make an assignment?

   Mark

   
   

References

   Visible links
   Hidden links:
   1. mailto:r-help@r-project.org
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] color of math annotation in legend

2011-07-28 Thread Peter Ehlers

On 2011-07-28 01:11, Zhongyi Yuan wrote:

Thank you Tyler.
I thought the problem was due to the use of expression(...).


Also note that you can simplify your legend text:

 c(expression(alpha == 1), expression(alpha == 2))

In general, I find that paste() is overused in plotmath.

Peter Ehlers



Best,
Zhongyi

On Thu, Jul 28, 2011 at 2:49 AM, Tyler Rinkerwrote:


  Use the text.col argument as below
?legend


x=y=1:100
z=seq(0.5,50,by=0.5)
plot(x,y,type='l',col='black')
lines(x,z,col='red')
legend('topleft',c(expression(paste(alpha," = ", 1)),
expression(paste(alpha," = ", 2))),text.col=c("black","red"))




  >  Date: Thu, 28 Jul 2011 02:32:04 -0500

From: zhongyi-y...@uiowa.edu
To: r-help@r-project.org
Subject: [R] color of math annotation in legend




Dear useRs,

Can someone help me to adjust the color of math annotation in a legend?

The

following code gives me a black "alpha = 2".

x=y=1:100
z=seq(0.5,50,by=0.5)
plot(x,y,type='l',col='black')
lines(x,z,col='red')
legend('topleft',c(expression(paste(alpha," = ", 1)),
expression(paste(alpha," = ", 2))),col=c('black','red'))

Is it possible to make it red? Thanks in advance for your help.

Best,
Zhongyi Yuan

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide

http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.




[[alternative HTML version deleted]]

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Python difflib R equivalent? -- Correction

2011-07-28 Thread Bert Gunter
Item 1 below should be changed to:

 1. I do not know if any such PACKAGE exists.

(A "library" in R is a file directory where R packages are stored)

-- Bert

On Thu, Jul 28, 2011 at 8:05 AM, Bert Gunter  wrote:
> Paul:
>
> 1. I do not know if any such library exists.
>
> 2. However, if I understand correctly, one usually does this sort of
> thing in R with functions like ?match (or ?"%in%") and logical
> comparison operations like ?"==" .  Of course, for numeric
> comparisons, you need to be aware of R FAQ 7.31
>
> If you are interested in comparing what in R are character vectors,
> then various string operators, e.g. ?grep, ?regexp and character
> operation packages (e.g. gsubfn, stringr) may be of use.
>
> As usual, you are more likely to receive a helpful answer if you do as
> the posting guide requests and provide a small, reproducible example
> of the sort(s) of thing(s) you want to do.
>
> Cheers,
> Bert

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Python difflib R equivalent?

2011-07-28 Thread Bert Gunter
Paul:

1. I do not know if any such library exists.

2. However, if I understand correctly, one usually does this sort of
thing in R with functions like ?match (or ?"%in%") and logical
comparison operations like ?"==" .  Of course, for numeric
comparisons, you need to be aware of R FAQ 7.31

If you are interested in comparing what in R are character vectors,
then various string operators, e.g. ?grep, ?regexp and character
operation packages (e.g. gsubfn, stringr) may be of use.

As usual, you are more likely to receive a helpful answer if you do as
the posting guide requests and provide a small, reproducible example
of the sort(s) of thing(s) you want to do.

Cheers,
Bert

On Thu, Jul 28, 2011 at 4:05 AM, Paul  wrote:
> Hi,
>
> Does anyone know of a R library that is equivalent in functionality to
> the Python standard libraries' difflib library? The python docs say
> this about difflib:
>
> "This module provides classes and functions for comparing sequences.
> It can be used for example, for comparing files, and can produce
> difference information in various formats, including HTML and context
> and unified diffs."
>
> http://docs.python.org/library/difflib.html
>
> Thanks,
>
> Paul
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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   >