Re: [R] number of zeros in a matrix -row by row

2009-04-06 Thread Dimitris Rizopoulos

well, you said you tried

rowSums(M == 0)

but according to the error message it seems that you tried

rowSums[M == 0]

Try to use parenthesis '(' instead of brackets '['.


Best,
Dimitris

onyourmark wrote:

Dear Dimitris,

Thanks very much. I tried dim(M) and get:
[1] 5030 2142

which I thought meant that my matrix M is actually a matrix, but
I tried  str(M) and get:

 int [1:5030, 1:2142] 2 1 2 0 1 0 2 1 2 -1 ...

When I tried 
rowSums(M == 0)


I got:
Error in rowSums[M == 0] : 
  object of type 'closure' is not subsettable



What am I doing wrong?

Thanks so much.



Dimitris Rizopoulos-4 wrote:

if 'M' is your matrix, then try this:

rowSums(M == 0)


I hope it helps.

Best,
Dimitris


onyourmark wrote:

Hi. I have an n x m matrix M some of who's entries are zeros. I want to
know
how many zeros there are in each row-perhaps stored in a 1 x n vector
which lists the number of zeros for each row of M.

Before I had a vector V and I was able to get the number of zeros in V by
doing length(V[ V==0]) but when I try something similar for M, like M[
M==0]
it creates a vector not a matrix and so this does not work. Does anyone
have
a solution to this?

Thank you.

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

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

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






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

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] line argument in mtext for axis ?

2009-04-06 Thread Uwe Ligges



Daren Tan wrote:

Is there a similar argument for axis that controls the position of
labels via line argument in mtext ?


At least in my version of the help page of mtext() everything about that 
is described. What is your problem with ?mtext and the "line" argument?


Uwe Ligges


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

2009-04-06 Thread Ryan Boyko
Hi,

Are there any packages or functions that calculate the McKelvey-Zavoina
Pseudo-R2 or the Aldrich-Nelson Pseudo-R2?

Thanks,
Ryan

-- 
Ryan Boyko
Graduate Student, UC Davis Evolutionary Anthropology and Graduate Group in
Ecology
Research Assistant to Cornell Village Dog Diversity Project

[[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] how to sort and plot data?

2009-04-06 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 06.04.2009 05:01:56:

> hi Erin,
> Thanks for your reply to my problems. I tried and it works, but it 
sorted
> all the column. In my case, I want it to sort d user_id column and 
another
> information in other column will follow it. Now, after I sorted, the
> information which website viewed by user was wrong. I want to as how we 
can
> sort or filter in excel.

If you want to sort and filter like in excel why not using excel

rowSums(table(test$user_id, test$website))

gives you info how many of websites were visited by each user_id. It is 
not clear how days are coded so it is difficult to come with any 
reasonable way how to compute numbers per day.

I would try to split/lapply way but there could be better means.

Regards
Petr

> 
> Thank you.
> 
> regards,
> hema
> 
> On Fri, Apr 3, 2009 at 4:44 PM, Umesh Srinivasan 
 > wrote:
> 
> > Hi,
> > There is definitely a more elegant way of doing this which I don't 
know
> > about (without a for loop), but try this:
> >
> > mat <- matrix(NA, nrow = max(user_id), ncol = 2)
> > mat[,1] <- 1:max(user_id) # 1st column of matrix is the user ID
> >
> > for (i in 1:max(user_id)){
> > temp1 <- subset(data, user_id = i)
> > temp2 <- unique(temp1$website)
> > mat[2,i] <- length(temp2)
> > }
> >
> > The matrix will give you user id and number of sites visited, provided 
user
> > id ranges from 1 to the number of users. There must be a way to do 
this
> > using table, but I cant figure it out.
> >
> > Cheers,
> > Umesh
> >
> > On Fri, Apr 3, 2009 at 1:42 PM, Dieter Menne
> > wrote:
> >
> > >
> > >
> > >
> > > Hem wrote:
> > > >
> > > > user_id  website  time
> > > > 20google0930
> > > > 21yahoo0935
> > > > 20facebook1000
> > > > 25facebook1015
> > > > 61google0940
> > > > ...
> > > > My problem is how to sort the data? So that, I can get information
> > about
> > > > one
> > > > user_id viewed how many website perday?
> > > >
> > > >
> > >
> > > Maybe you were looking at the wrong item, because what you want is 
not
> > > sorting, but a table.
> > >
> > > Check the documentation of table or ftable.
> > >
> > > Dieter
> > >
> > > --
> > > View this message in context:
> > >
> > 
http://www.nabble.com/how-to-sort-and-plot-data--tp22861661p22863918.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.
> >
> 
>[[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] line argument in mtext for axis ?

2009-04-06 Thread Daren Tan
Previously, I wasn't aware that axis() supports "las" arguments, and
as a result, I used axis() for the ticks and mtext() to rotate the
labels perpendicular to the axis. Now, I hope to cleanup my codes by
combining the axis() and mtext() codes into a single axis(), the only
issue is that much of my mtext() codes set the "line" argument to some
values. The "line" argument in axis() doesn't work the same way
according to the help page, is there an equivalent argument in axis()
that functions identically to the "line" argument in mtext() ?


2009/4/6 Uwe Ligges :
>
>
> Daren Tan wrote:
>>
>> Is there a similar argument for axis that controls the position of
>> labels via line argument in mtext ?
>
> At least in my version of the help page of mtext() everything about that is
> described. What is your problem with ?mtext and the "line" argument?
>
> Uwe Ligges
>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] How to save the variables in R to a file

2009-04-06 Thread Cetinyürek Aysun
Dear list members,

I have f.mean matrix of size 500 X 83 in R, and I want to save this into a
file.
I used the command
save("f.mean.Rdata",file="D:/Users/Ays/Documents/Results")
it saves but when I open the file in notepad it is just some characters
meaningless.

Thank you in advance,

Kind Regards,

Aysun

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

2009-04-06 Thread Jim Lemon

johnhj wrote:

Hii,

Can anybody help me to put a text under the barplots. I will describe the
percental between six grouped barplots. I tried to do it with mtext but
without success.

...
I tired to do it with 
mtext(side=1,at=x, text =c("Mean", "","","","","rere"), col = "red"),

line = 1, cex = 0.75) but without success, I get this example from a R
tutorial...
  

Hi John,
The horizontal bar positions are returned invisibly by the barplot 
function, so:


xpos<-barplot(...)
mtext(side=1,at=xpos,...)

should do what you want.

Jim

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


[R] Need Help with StatET Error/Bug? on Ubuntu 8.10 amd64

2009-04-06 Thread Ken-JP

Hi,

I posted this message on the StatET-user board last week, but it looks like
a ghost-town...

I have a bad feeling that there is some code in the plug-in which doesn't
work well with my environment, but if I am lucky, maybe other users have
worked around this problem somehow - I am hoping that my setup is the issue.  

Note: very similar StatET setups on 32-bit XP Pro and Vista run flawlessly.

Has anyone else run into this problem and/or found a way around it?

Ubuntu 8.10 intrepid amd64
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) 64-Bit Server VM (build 11.3-b02, mixed mode)
R 2.8.1
Eclipse 3.4.2
StatET 0.7.2.b200812051430sw


 

When I start up the R Console, I get a java.lang.NullPointerException inside
Eclipse in the form of a popup warning.

Six icons right of the Console-tab fail to appear:

Cancel the current task
Terminate
Remove Launch
Remove All Terminated Launches
Clear Console
Scroll Lock

Every time the Console gets focus, I get the NullPointerError exception -
probably an attempt to refresh the icons.  After a while, the Eclipse IDE
loses focus and becomes unusable.

Looks like it's happening around:

at org.eclipse.ui.SubActionBars.updateActionBars(SubActionBars.java:610)


 

Session Data:
eclipse.buildId=M20090211-1700
java.version=1.6.0_13
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Command-line arguments:  -os linux -ws gtk -arch x86_64

Exception Stack Trace:
java.lang.NullPointerException
at
org.eclipse.jface.resource.URLImageDescriptor.getFilePath(URLImageDescriptor.java:138)
at
org.eclipse.jface.resource.URLImageDescriptor.createImage(URLImageDescriptor.java:157)
at
org.eclipse.jface.resource.ImageDescriptor.createResource(ImageDescriptor.java:165)
at
org.eclipse.jface.resource.DeviceResourceManager.allocate(DeviceResourceManager.java:56)
at
org.eclipse.jface.resource.AbstractResourceManager.create(AbstractResourceManager.java:88)
at
org.eclipse.jface.resource.LocalResourceManager.allocate(LocalResourceManager.java:82)
at
org.eclipse.jface.resource.AbstractResourceManager.create(AbstractResourceManager.java:88)
at
org.eclipse.jface.resource.ResourceManager.createImage(ResourceManager.java:172)
at
de.walware.eclipsecommons.ui.HandlerContributionItem.updateIcons(HandlerContributionItem.java:648)
at
de.walware.eclipsecommons.ui.HandlerContributionItem.fill(HandlerContributionItem.java:383)
at
org.eclipse.jface.action.SubContributionItem.fill(SubContributionItem.java:77)
at 
org.eclipse.jface.action.ToolBarManager.update(ToolBarManager.java:349)
at org.eclipse.ui.internal.ViewPane.updateActionBars(ViewPane.java:449)
at
org.eclipse.ui.internal.ViewActionBars.updateActionBars(ViewActionBars.java:59)
at org.eclipse.ui.SubActionBars.updateActionBars(SubActionBars.java:610)
at
de.walware.statet.nico.ui.console.NIConsolePage$6.handleEvent(NIConsolePage.java:599)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1158)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1182)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1163)
at org.eclipse.swt.widgets.Control.sendFocusEvent(Control.java:3284)
at org.eclipse.swt.widgets.Control.gtk_event_after(Control.java:2684)
at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1538)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4506)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4099)
at org.eclipse.swt.internal.gtk.OS._gtk_widget_grab_focus(Native Method)
at org.eclipse.swt.internal.gtk.OS.gtk_widget_grab_focus(OS.java:9106)
at org.eclipse.swt.widgets.Control.forceFocus(Control.java:2107)
at org.eclipse.swt.widgets.Composite.forceFocus(Composite.java:494)
at org.eclipse.swt.widgets.Control.forceFocus(Control.java:2101)
at org.eclipse.swt.widgets.Control.setFocus(Control.java:3646)
at org.eclipse.swt.widgets.Composite.setFocus(Composite.java:1254)
at
org.eclipse.swt.widgets.Composite.gtk_button_press_event(Composite.java:656)
at 
org.eclipse.swt.widgets.Canvas.gtk_button_press_event(Canvas.java:155)
at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1531)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4506)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4099)
at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:5792)
at org.eclipse.swt.widgets.Display.eventProc(Displa

Re: [R] bigglm "update" with ff

2009-04-06 Thread Thomas Lumley

On Thu, 2 Apr 2009, Yue Sheng wrote:


Hi, since bigglm doesn't have update, I was wondering how to achieve
something like (similar to the example in ff package manual using biglm):


bigglm() doesn't have update because it needs to iterate over the data and 
update() couldn't do that.


Instead of calling update(), you have to supply a function that will load 
the next chunk of data, and that can be reset to start again at the 
beginning.  There is an example on the help page, and the code for 
bigglm.data.frame gives another example, as do the SQLiteConnection 
and RODBC methods.


-thomas




first <- TRUE
ffrowapply ({
 if (first) {
  first <- FALSE
  fit <- bigglm(eqn, as.data.frame(bigdata[i1:i2,,drop=FALSE]), chunksize =
1, family = binomial())
 } else {
  fit <- update(fit, as.data.frame(bigdata[i1:i2,,drop=FALSE]), chunksize =
1, family = binomial())
 }
}, X=bigdata, VERBOSE = TRUE, BATCHSIZE = nmax)

Many thanks.
Yuesheng

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



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

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


[R] GarchOxFit output

2009-04-06 Thread Vasileios Ismyrlis
Dear Sirs,
I have a problem with the garchOxFit output. I want to display only
the value of max.like.est and the information criteria. How can I do
that; I enclose a part of GarchOxFit output, which is what I want to
display.
Best regards,
Vasilios Ismyrlis

GarchOxFit output
No. Observations :  1000  No. Parameters  : 2
Mean (Y) :  -0.05511  Variance (Y):   1.06869
Skewness (Y) :  -0.01496  Kurtosis (Y):   3.49490
Log Likelihood   : -1453.572  Alpha[1]+Beta[1]:  -0.00021

Information Criterium (to be minimized)
Akaike  2.911144  Shibata 2.911136
Schwarz 2.920960  Hannan-Quinn2.914875

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] line argument in mtext for axis ?

2009-04-06 Thread Daren Tan
Thanks, I should learn to read deeper into the help page next time. :)

On Mon, Apr 6, 2009 at 4:56 PM, Annette Heisswolf
 wrote:
> Hei,
>
> As far as I understand your question, you might want to check the settings
> of par(mgp), which has three elements. According to ?par mgp sets  "The
> margin line (in mex units) for the axis title, axis labels and axis line.
> Note that mgp[1] affects title whereas mgp[2:3] affect axis. The default is
> c(3, 1, 0)." According to ?axis the value of par("mgp")[2] is used to place
> the tick labels. Thus, changing the default to the value of your choice
> might do what you want.
>
> Hope that helps,
> Annette
>
> Daren Tan schrieb:
>>
>> Previously, I wasn't aware that axis() supports "las" arguments, and
>> as a result, I used axis() for the ticks and mtext() to rotate the
>> labels perpendicular to the axis. Now, I hope to cleanup my codes by
>> combining the axis() and mtext() codes into a single axis(), the only
>> issue is that much of my mtext() codes set the "line" argument to some
>> values. The "line" argument in axis() doesn't work the same way
>> according to the help page, is there an equivalent argument in axis()
>> that functions identically to the "line" argument in mtext() ?
>>
>>
>> 2009/4/6 Uwe Ligges :
>>>
>>> Daren Tan wrote:

 Is there a similar argument for axis that controls the position of
 labels via line argument in mtext ?
>>>
>>> At least in my version of the help page of mtext() everything about that
>>> is
>>> described. What is your problem with ?mtext and the "line" argument?
>>>
>>> Uwe Ligges
>
> --
> Annette Heisswolf
> Section of Ecology
> Department of Biology
> University of Turku
> 20014 Turku, Finland
>
> phone   + 358 2 333 6006
> fax     + 358 2 333 6550
> mail    annette.heissw...@utu.fi
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Code of sample() in C

2009-04-06 Thread Ranjan Maitra
Hi Paul,

I believe that you may need to set seed differently when you call the R
math library as standalone. Specifically, you need to do the following
(or rather, the following works):

unsigned int seed1, seed2;
FILE *fran;

fran = fopen("random.seed","r");
fscanf(fran, "%u %u", &seed1, &seed2);
fclose(fran); 

set_seed(seed1, seed2);

where random.seed is the file containing two large integers. 

and after I am done, I usually add the following towards the end of the
main program

get_seed(&seed1, &seed2);

fran=fopen("random.seed", "w");
fprintf(fran, "%d %d\n", seed1, seed2);
fclose(fran);

You will again need to include Rmath.h and declare the standalone parameter in 
the calling program also.


HTH!

Best wishes,
Ranjan


On Mon, 6 Apr 2009 10:41:19 +0100 Paul Smith  wrote:

> Thanks, Ranjan! I have tried to use the function SampleNoReplace in
> random.c, which seems to work, except that I get always the same
> random numbers (with your code the same happens). (My code is below.).
> 
> I have read the documentation ("Writing R extensions"), where it is advised:
> 
> «The interface to R’s internal random number generation routines is
> 
> double unif_rand();
> double norm_rand();
> double exp_rand();
> 
> giving one uniform, normal or exponential pseudo-random variate.
> However, before these are used, the user must call
> 
> GetRNGstate();
> 
> and after all the required variates have been generated, call
> 
> PutRNGstate();»
> 
> However, when I use GetRNGstate() and PutRNGstate(), I get the following 
> errors:
> 
> $ gcc -I/usr/include/R -o myprog myprog.c -lRmath -lm
> /tmp/cc6CMnlh.o: In function `main':
> myprog.c:(.text+0x30): undefined reference to `GetRNGstate'
> myprog.c:(.text+0x57): undefined reference to `PutRNGstate'
> collect2: ld returned 1 exit status
> $
> 
> Any ideas?
> 
> Paul
> 
> --
> 
> #include 
> #include 
> #include 
> #include 
> #define MATHLIB STANDALONE
> #include 
> 
> void snr(int k, int n, int *y, int *x);
> 
> int main()
> {
> 
>   int *x = malloc(50*sizeof(int));
>   int *y = malloc(5*sizeof(int));
>   int i;
> 
>   GetRNGstate();
>   snr(5,50,y,x);
>   PutRNGstate();
> 
>   for(i=0;i<5;++i)
> printf("%d ",y[i]);
> 
>   free(x);
>   free(y);
> 
>   return 0;
> 
> }
> 
> 
> void snr(int k, int n, int *y, int *x)
> {
> int i, j;
> for (i = 0; i < n; i++)
> x[i] = i;
> for (i = 0; i < k; i++) {
> j = n * unif_rand();
> y[i] = x[j] + 1;
> x[j] = x[--n];
> }
> }
> 
> --
> 
> 
> 
> On Sun, Apr 5, 2009 at 11:00 PM, Ranjan Maitra  wrote:
> > I presume you mean sampling without replacement? The following
> > (adapted from the file you asked for) will do it, but you will need to
> > incorporate Rmath as standalone in order to get runif to work.
> >
> > This function will give you k indices from n, sampled WOR. Thus, n = 50
> > for you and k = 5. You will get a vector y of length 5 (a pointer of int
> > actually) which will contain these indices.
> >
> > Thus you will define a vector z (of length 50) which is 1:50, and then
> > using the function, your SRWOR sample will be z[y[i]] where i = 0,
> > 1,...4.
> >
> > I haven't tried this function out much myself, so YMMV.
> >
> > HTH!
> >
> > Best wishes,
> > Ranjan
> >
> >
> >
> > #include 
> > #ifndef USING_RLIB
> > #define MATHLIB_STANDALONE 1 /*It is essential to have this before the call
> >                               to the Rmath's header file because this 
> > decides
> >                               the definitions to be set. */
> > #endif
> > #include 
> >
> > /* Note that use of this function involves a prior call to the Rmath 
> > library to
> >   get the seeds in place. It is assumed that this is done in the calling
> >   function. */
> >
> > /* Equal probability sampling; without-replacement case */
> > /* Adapted from the R function called SampleNoReplace */
> >
> > /**
> >  * Stores k out of n indices sampled at random without replacement
> >  * in y.
> >  */
> > int srswor(int n, int k, int *y)
> > {
> >  if (k > n) {
> >    return 1;
> >  }
> >  else {
> >    const double len = (double) n;
> >    int i;
> >    int* x = malloc(n * sizeof(int));
> >    if (!x) {
> >      return 2;
> >    }
> >
> >    for (i = 0; i < n; ++i)     x[i] = i;
> >
> >    for (i = 0; i < k; ++i) {
> >      const int j = (int)(len * runif(0.0, 1.0));
> >      y[i] = x[j];
> >      x[j] = x[--n];
> >    }
> >    free(x);
> >  }
> >  return 0;
> > }
> >
> >
> >
> > On Sun, 5 Apr 2009 20:11:04 +0100 Paul Smith  wrote:
> >
> >> Thanks, Ranjan. Got it!
> >>
> >> I am now wondering whether there is some simpler way of implementing
> >> the following in C:
> >>
> >> sample(1:50,5)
> >>
> >> Paul
> >>
> >>
> >> On Sun, Apr 5, 2009 at 4:10 PM, Ranjan Maitra  wrote:
> >> > Hi Paul,
> >> >
> >> > It is in the main/src/random

[R] political maps world maps in R, wrld_simpl

2009-04-06 Thread Patrizio Frederic
dear all,
I'm a newbie in map tools. I was asking to perform an apparently very
simple task.
I have a list of countries (about fifty all over in the world) scored
with a real positive value. Eg

Country score
Italy   .56
UK  .58
Korea   .41
Mexico  .63
...

I wish to plot geographical maps where every country is filled with a
color depending on his score.

Using maptools library and wrld_simpl I can easily perform the world
map. Here my code:

#
###plot the world map

patramp = colorRamp(c(rgb(0,0,.7),"red"))# my personal ramp color palette

library(maptools)
load(url("http://spatial.nhh.no/R/etc/TM_WORLD_BORDERS_SIMPL-0.2.RData";))

country2= c("Albania", "Argentina", "Australia", "Austria", "Belgium",
"Belarus", "Brazil", "Bulgaria", "Canada", "China", "Colombia",
"Croatia", "Denmark", "Egypt", "United.Arab.Emirates", "Estonia",
"Philippines", "Finland", "France", "Germany", "Japan", "Jordan",
"Greece", "India", "Indonesia", "Iran", "Ireland", "Israel",
"Italy", "Latvia", "Libya", "Lithuania", "Malaysia", "Mexico",
"Morocco", "Norway", "Netherlands", "Pakistan", "Poland", "Portugal",
"United.Kingdom", "Czech.Republic", "Romania", "Russia", "Serbia",
"Singapore", "Syrian.Arab.Republic", "Slovak.Republic", "Slovenia",
"Spain", "United.States", "South.Africa", "Korea.South", "Sweden",
"Switzerland", "Thailand", "Taiwan.Province.of.China", "Tunisia",
"Turkey", "Ukraine", "Hungary", "Venezuela", "Vietnam") # The my
countries' names

country.all = wrld_simpl$NAME # countries' names as coded in wrld_simpl
n.all   = length(country.all)
col.map = numeric(n.all)

# grep country2 in country.all
for (i in 1:length(country2)){
  col.map[grep(country2[i],country.all)] = runif(1) # assign a random
score to country i
}
# it certainly exists a cleaner coding for this but it's not my first
thought now

c2  = col.map!=0# set countries with score != 0 is not listed
in country2
col.map2=col.map
col.map2[!c2]=rgb(.95,.96,.97)  # be grey the countries not listed in
country2 object
col.map2[c2]= rgb(patramp(col.map[c2])/255) # ramp the remaining
plot(wrld_simpl,col=col.map2,axes=T) # nice plot

###   end of program
#

Now what if I wish to zoom on some sub world regions such as Eastern
Europe or America or any other user defined contiguous sub group?

Russia is a large country I could be interested in cutting it in two
peaces eastern and western. Can I do it using wrld_simpl or should I
search for other data? If so where can I find free maps data?

Some documentation exists but it seems sparse to me.
Any hints will be appreciated.
Thanks in advance,

Patrizio

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Code of sample() in C

2009-04-06 Thread Paul Smith
Thanks, Ranjan! I have tried to use the function SampleNoReplace in
random.c, which seems to work, except that I get always the same
random numbers (with your code the same happens). (My code is below.).

I have read the documentation ("Writing R extensions"), where it is advised:

«The interface to R’s internal random number generation routines is

double unif_rand();
double norm_rand();
double exp_rand();

giving one uniform, normal or exponential pseudo-random variate.
However, before these are used, the user must call

GetRNGstate();

and after all the required variates have been generated, call

PutRNGstate();»

However, when I use GetRNGstate() and PutRNGstate(), I get the following errors:

$ gcc -I/usr/include/R -o myprog myprog.c -lRmath -lm
/tmp/cc6CMnlh.o: In function `main':
myprog.c:(.text+0x30): undefined reference to `GetRNGstate'
myprog.c:(.text+0x57): undefined reference to `PutRNGstate'
collect2: ld returned 1 exit status
$

Any ideas?

Paul

--

#include 
#include 
#include 
#include 
#define MATHLIB STANDALONE
#include 

void snr(int k, int n, int *y, int *x);

int main()
{

  int *x = malloc(50*sizeof(int));
  int *y = malloc(5*sizeof(int));
  int i;

  GetRNGstate();
  snr(5,50,y,x);
  PutRNGstate();

  for(i=0;i<5;++i)
printf("%d ",y[i]);

  free(x);
  free(y);

  return 0;

}


void snr(int k, int n, int *y, int *x)
{
int i, j;
for (i = 0; i < n; i++)
x[i] = i;
for (i = 0; i < k; i++) {
j = n * unif_rand();
y[i] = x[j] + 1;
x[j] = x[--n];
}
}

--



On Sun, Apr 5, 2009 at 11:00 PM, Ranjan Maitra  wrote:
> I presume you mean sampling without replacement? The following
> (adapted from the file you asked for) will do it, but you will need to
> incorporate Rmath as standalone in order to get runif to work.
>
> This function will give you k indices from n, sampled WOR. Thus, n = 50
> for you and k = 5. You will get a vector y of length 5 (a pointer of int
> actually) which will contain these indices.
>
> Thus you will define a vector z (of length 50) which is 1:50, and then
> using the function, your SRWOR sample will be z[y[i]] where i = 0,
> 1,...4.
>
> I haven't tried this function out much myself, so YMMV.
>
> HTH!
>
> Best wishes,
> Ranjan
>
>
>
> #include 
> #ifndef USING_RLIB
> #define MATHLIB_STANDALONE 1 /*It is essential to have this before the call
>                               to the Rmath's header file because this decides
>                               the definitions to be set. */
> #endif
> #include 
>
> /* Note that use of this function involves a prior call to the Rmath library 
> to
>   get the seeds in place. It is assumed that this is done in the calling
>   function. */
>
> /* Equal probability sampling; without-replacement case */
> /* Adapted from the R function called SampleNoReplace */
>
> /**
>  * Stores k out of n indices sampled at random without replacement
>  * in y.
>  */
> int srswor(int n, int k, int *y)
> {
>  if (k > n) {
>    return 1;
>  }
>  else {
>    const double len = (double) n;
>    int i;
>    int* x = malloc(n * sizeof(int));
>    if (!x) {
>      return 2;
>    }
>
>    for (i = 0; i < n; ++i)     x[i] = i;
>
>    for (i = 0; i < k; ++i) {
>      const int j = (int)(len * runif(0.0, 1.0));
>      y[i] = x[j];
>      x[j] = x[--n];
>    }
>    free(x);
>  }
>  return 0;
> }
>
>
>
> On Sun, 5 Apr 2009 20:11:04 +0100 Paul Smith  wrote:
>
>> Thanks, Ranjan. Got it!
>>
>> I am now wondering whether there is some simpler way of implementing
>> the following in C:
>>
>> sample(1:50,5)
>>
>> Paul
>>
>>
>> On Sun, Apr 5, 2009 at 4:10 PM, Ranjan Maitra  wrote:
>> > Hi Paul,
>> >
>> > It is in the main/src/random.c file of the source code.
>> >
>> > HTH!
>> > Best wishes,
>> > Ranjan
>> >
>> > On Sun, 5 Apr 2009 15:35:25 +0100 Paul Smith  wrote:
>> >
>> >> Dear All,
>> >>
>> >> I would like to use the function sample() in a program written in C.
>> >> Is there somewhere the code of sample() written in C?
>> >>
>> >> Thanks in advance,
>> >>
>> >> 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.
>> >>
>> >
>> > __
>> > R-help@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/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-cont

Re: [R] time-series data and time-invariant missing values

2009-04-06 Thread Gabor Grothendieck
Check out na.locf in the zoo package.  Here we fill in
NAs going forward and just in case there were NAs
right at the beginning we fill them in backward as well.

library(zoo)
x <- as.Date(c(NA, "2000-01-01", NA))
x2 <- na.locf(x, na.rm = FALSE)
x2 <- na.locf(x2, fromLast = TRUE, na.rm = FALSE)

gives:

> x2
[1] "2000-01-01" "2000-01-01" "2000-01-01"


On Mon, Apr 6, 2009 at 7:13 AM, Kunzler, Andreas  wrote:
> Dear list,
>
> I have some problems with time-series data and missing values of 
> time-invariant informations like sex or the birth-date.
>
> Assume a data (d) structure like
>
> id      birth           sex     year of observation
> 1       NA              NA      2006
> 1       1976-01-01      male    2007
> 1       NA              NA      2008
>
> I am looking for a way to replace the missing values.
>
> Right know my answer to this problem slows down R
>
>
>
> for (i in 1:length(d[,1])){ # for all observations
>
>        if (is.na(d$birth)[i])==F){ # Check if birth of observation(i) is 
> missing
>            d$birth_2[i] <- as.Date(birth[i],"%d.%m.%Y")
>        }else{
>            d$birth2[i]  <- d$birth[id[i]==d$id & 
> is.na(d$birth)==F],"%d.%m.%Y")[1] # if birth of observation (i) is missing, 
> take a observation of another year
>        }
>    }
> }
>
> Result:
>
>
> id      birth           sex     year of observation     birth2
> 1       NA              NA      2006                    1976-01-01
> 1       01.01.1976      male    2007                    1976-01-01
> 1       NA              NA      2008                    1976-01-01
>
> unfortunately the data consists of over 2 observations a year.
>
> Does anybody know a better way?
>
> Thanks
>
> Mit freundlichen Grüßen
>
> Andreas Kunzler
> 
> Bundeszahnärztekammer (BZÄK)
> Chausseestraße 13
> 10115 Berlin
>
> Tel.: 030 40005-113
> Fax:  030 40005-119
>
> E-Mail: a.kunz...@bzaek.de
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Grouping of data frames to calculate means

2009-04-06 Thread Thomas Lumley

On Mon, 6 Apr 2009, Steve Murray wrote:



Dear R Users,

I have 120 data frames of the format table_198601, table_198602... 
table_198612, table_198701, table_198702... table_198712 through to 
table_199512 (ie. the first 4 digits are years which vary from 1986 to 
1995, and the final two digits are months which vary from 01 to 12 for 
each year).


I simply hope to find the means of column 3 of each of the 120 tables 
without having to type out mean(table_198601[3]) etc etc each time. How 
would I go about doing this? And how would I go about finding the mean 
of all the January months (01) from say 1986 to 1990?


Put all the tables in a list, then you can iterate over them, eg
 lapply(the_list, function(table) mean(table[,3))

You might also want a list of lists to maintain the annual structure, so 
that


januaries <- lapply(list_list, function(year) mean(year[[1]][,3]))

-thomas


Finally, I hope to be able to plot (as a scatter graph) the values of 
column 1 against the mean of those from column 3 for all the months in 
the period 1989 to 1990 and then 1991 to 1995.


Any help offered would be very much appreciated.

Thanks,

Steve

_
[[elided Hotmail spam]]

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



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

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


Re: [R] Survey Package with Binary Data (no Standard Errors reported)

2009-04-06 Thread Thomas Lumley

On Fri, 3 Apr 2009, Paul Jones wrote:


Hi,

I'm trying to get standard errors for some of the variables in my data frame. 
One of the questions on my survey is whether faculty coordinate across 
curriculum to include Arts Education as subject matter. All the responses are 
coded in zeros and ones obviously. For some of the other variables I have a 2 
for those that responded with "Don't Know".


I'm getting NA for mean and standard deviations from svymean. Am I doing 
something wrong of can the survey package not handle this type of data?


Are you sure you don't have any NA values in the data? If you do, the 
na.rm=TRUE option to svymean() will fix your problem. If you don't, 
something mysterious is happening. You could try svytable(~Curriculum, 
survey), which will give a tabulation and might show up what is strange 
about your data.


As a separate issue, you might want to look at svyciprop() if some of your 
proportions are close to 0 or 1, to get better confidence intervals.




Here's my code.


Nothing obviously wrong with it.

-thomas


survey <- svydesign(id=~1, data=General, strata=~Grade.Level)

Warning message:
In svydesign.default(id = ~1, data = General, strata = ~Grade.Level) :
No weights or probabilities supplied, assuming equal probability


summary(survey)

Stratified Independent Sampling design (with replacement)
svydesign(id = ~1, data = General, strata = ~Grade.Level)
Probabilities:
 Min. 1st Qu.  MedianMean 3rd Qu.Max.
1   1   1   1   1   1
Stratum Sizes:
 Elementary High Middle
obs   312  236156
design.PSU312  236156
actual.PSU312  236156
Data variables:
[1] "Grade.Level"  "Curriculum" [3] 
"Field.Trips"  "Residencies"[5] "PTA.Support" 
"Community.Open.Performances"
[7] "Visual.Arts.Attendance"   "Literary.Arts.Attendance"   [9] 
"Arts.Organization.Membership" "Arts.Essential"

> svymean(~Curriculum, survey)
 mean SE
Curriculum   NA NA

???

PJ

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



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

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


Re: [R] How to save the variables in R to a file

2009-04-06 Thread Christian Ruckert

Cetinyürek Aysun schrieb:

Dear list members,

I have f.mean matrix of size 500 X 83 in R, and I want to save this into a
file.
I used the command
save("f.mean.Rdata",file="D:/Users/Ays/Documents/Results")
it saves but when I open the file in notepad it is just some characters
meaningless.


The purpose of save is to save R objects to a file so you can retrieve 
them later or on another system via the load command.


I think what you are looking for is the write.table command. See 
help(write.table).


Greetings,
Christian

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

2009-04-06 Thread Thomas Lumley


If you actually want to find the best subsets, you can get a good 
approximation by using leaps on the weighted least squares fit that is the 
last iteration of the IWLS algorithm for fitting the glm.


Running regsubsets witha reasonably large value of nbest and then 
refitting the top models as glms afterwards will fairly realiably give the 
best glms.


Whether this is better than lasso depends on what you are trying to do - 
IMO the only point of all-subsets regression is to get many best models 
rather than a single one, and lasso doesn't do at all well at that.


-thomas

On Sat, 4 Apr 2009, Harald von Waldow wrote:




Of all the dangerous ways of doing this and getting confusing results,
gl1ce in lasso2 should be the least risky.


Thanks Dieter. In case an exhaustive search (all subsets) remains
infeasible, I'll include a shrinkage method for sure. Looks like
glmpath could be useful here.

Best,
Harald

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



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

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


Re: [R] line argument in mtext for axis ?

2009-04-06 Thread Annette Heisswolf

Hei,

As far as I understand your question, you might want to check the settings of par(mgp), which has three elements. According to ?par mgp sets 
 "The margin line (in mex units) for the axis title, axis labels and axis line. Note that mgp[1] affects title whereas mgp[2:3] affect 
axis. The default is c(3, 1, 0)." According to ?axis the value of par("mgp")[2] is used to place the tick labels. Thus, changing the default 
to the value of your choice might do what you want.


Hope that helps,
Annette

Daren Tan schrieb:

Previously, I wasn't aware that axis() supports "las" arguments, and
as a result, I used axis() for the ticks and mtext() to rotate the
labels perpendicular to the axis. Now, I hope to cleanup my codes by
combining the axis() and mtext() codes into a single axis(), the only
issue is that much of my mtext() codes set the "line" argument to some
values. The "line" argument in axis() doesn't work the same way
according to the help page, is there an equivalent argument in axis()
that functions identically to the "line" argument in mtext() ?


2009/4/6 Uwe Ligges :


Daren Tan wrote:

Is there a similar argument for axis that controls the position of
labels via line argument in mtext ?

At least in my version of the help page of mtext() everything about that is
described. What is your problem with ?mtext and the "line" argument?

Uwe Ligges


--
Annette Heisswolf
Section of Ecology
Department of Biology
University of Turku
20014 Turku, Finland

phone   + 358 2 333 6006
fax + 358 2 333 6550
mailannette.heissw...@utu.fi

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

2009-04-06 Thread Benedikt Niesterok
Hello everyone,
I would like to test two regression slopes:do they differ significantly?The 
data and commands I've used so far:
x<-8.5:32.5   #Vektor x
y<-c(   NA ,  NA , 5.67 , 6.53 , 6.83,  7.41 , 7.93 ,  8.5 , 8.86,  9.46 , 9.82 
,   10 ,10.35 , 10.7 ,11.03 ,11.37 ,11.61 ,11.84, 12.12, 12.39 ,12.67 ,12.96, 
13.28 ,13.47, 13.65) #Vektor y

(regression<-lm(y~x))
summary(regression)   Regression model 1

x<-8.5:32.5   #Vektor x
y<-c(  NA, 5.88  ,6.95 ,  7.2  ,7.66 , 8.02,  8.44,  9.06 , 9.65, 10.22 ,10.63, 
11.06, 11.37, 11.91, 12.28 ,12.69 ,13.07 , 13.5 , 13.3 ,14.14 ,   NA  ,  NA  ,  
NA  ,  NA   , NA) #Vektor y

(regression<-lm(y~x))
summary(regression) Regression model 2

Now I don't know how to continue as I want to test the slopes only ,not the 
regression lines in total.

Another problem I have is rather a formal one:
y<-c(   NA ,  NA , 5.67 , 6.53 , 6.83,  7.41 , 7.93 ,  8.5 , 8.86,  9.46 , 9.82 
,   10 ,10.35 , 10.7 ,11.03 ,11.37 ,11.61 ,11.84, 12.12, 12.39 ,12.67 ,12.96, 
13.28 ,13.47, 13.65) #Vektor y

that is my y-vector; I always need to copy and paste this line originating
from:
  X8.5 X9.5 X10.5 X11.5 X12.5 X13.5 X14.5 X15.5 X16.5 X17.5
SD24   NA   NA  5.67  6.53  6.83  7.41  7.93   8.5  8.86  9.46

  X18.5 X19.5 X20.5 X21.5 X22.5 X23.5 X24.5 X25.5 X26.5 X27.5 X28.5 
   9.8210 10.35  10.7 11.03 11.37 11.61 11.84 12.12 12.39 12.67

  X29.5 X30.5 X31.5 X32.5
   12.96 13.28 13.47 13.65
R always considers the original data as different variables(as matrix).
I already tried: y<-as.vector(SD24)
It doesn't work.   SD24 is the object giving me the original data you see.


sorry for writing so long; hope it is clear what I wrote.

Thanks for your efforts,   Benedikt

--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Grouping of data frames to calculate means

2009-04-06 Thread Steve Murray

Dear R Users,

I have 120 data frames of the format table_198601, table_198602... 
table_198612, table_198701, table_198702... table_198712 through to 
table_199512 (ie. the first 4 digits are years which vary from 1986 to 1995, 
and the final two digits are months which vary from 01 to 12 for each year).

I simply hope to find the means of column 3 of each of the 120 tables without 
having to type out mean(table_198601[3]) etc etc each time. How would I go 
about doing this? And how would I go about finding the mean of all the January 
months (01) from say 1986 to 1990?

Finally, I hope to be able to plot (as a scatter graph) the values of column 1 
against the mean of those from column 3 for all the months in the period 1989 
to 1990 and then 1991 to 1995.

Any help offered would be very much appreciated.

Thanks,

Steve

_
[[elided Hotmail spam]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Curve fitting,FDA for biological data

2009-04-06 Thread trias

There are a couple of different goals for this projects

 *identify periodicities at different timescales (ie different dT)
 *fit data into discrete number of curves, ie 6 different basic functions
should be enough to describe the basic repeating elements in this data (ie 6
different categories of peaks)
 *comapre data from different experiments of the same "time" reference (in
my case this is location on chromosome) for changes in the underlying basic
elements (ie changes of the basic funtions,periodicity etc)

 I think if I can find a strategy to answer some of these question I be in a
good position to explore this data analysis further if needed.

 Thanks a lot



stephen sefick wrote:
> 
> What is your end goal?  If it is to try and account for the
> variability of the "timeseries" you may want to look at ?spectrum
> If it is to model the periodicity...
> 
> Stephen Sefick
> 
> On Fri, Apr 3, 2009 at 11:30 AM, trias  wrote:
>>
>> Here is the gif that didn't come through earlier
>> http://www.nabble.com/file/p22870832/signal.gif signal.gif
>> --
>> View this message in context:
>> http://www.nabble.com/Curve-fitting%2CFDA-for-biological-data-tp22868069p22870832.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.
>>
> 
> 
> 
> -- 
> Stephen Sefick
> 
> Let's not spend our time and resources thinking about things that are
> so little or so large that all they really do for us is puff us up and
> make us feel like gods.  We are mammals, and have not exhausted the
> annoying little problems of being mammals.
> 
>   -K. Mullis
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Curve-fitting%2CFDA-for-biological-data-tp22868069p22906065.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] Odp: Comparing 2 slopes of 2 regression lines

2009-04-06 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 06.04.2009 12:28:35:

> Hello everyone,
> I would like to test two regression slopes:do they differ 
significantly?The 
> data and commands I've used so far:
> x<-8.5:32.5   #Vektor x
> y<-c(   NA ,  NA , 5.67 , 6.53 , 6.83,  7.41 , 7.93 ,  8.5 , 8.86,  9.46 
, 9.
> 82 ,   10 ,10.35 , 10.7 ,11.03 ,11.37 ,11.61 ,11.84, 12.12, 12.39 ,12.67 
,12.
> 96, 13.28 ,13.47, 13.65) #Vektor y
> 
> (regression<-lm(y~x))
> summary(regression)   Regression model 1
> 
> x<-8.5:32.5   #Vektor x
> y<-c(  NA, 5.88  ,6.95 ,  7.2  ,7.66 , 8.02,  8.44,  9.06 , 9.65, 10.22 
,10.
> 63, 11.06, 11.37, 11.91, 12.28 ,12.69 ,13.07 , 13.5 , 13.3 ,14.14 ,   NA 
 , 
> NA  ,  NA  ,  NA   , NA) #Vektor y
> 
> (regression<-lm(y~x))
> summary(regression) Regression model 2
> 
> Now I don't know how to continue as I want to test the slopes only ,not 
the 
> regression lines in total.

Here is one approach
http://tolstoy.newcastle.edu.au/R/e6/help/09/01/2632.html

> 
> Another problem I have is rather a formal one:
> y<-c(   NA ,  NA , 5.67 , 6.53 , 6.83,  7.41 , 7.93 ,  8.5 , 8.86,  9.46 
, 9.
> 82 ,   10 ,10.35 , 10.7 ,11.03 ,11.37 ,11.61 ,11.84, 12.12, 12.39 ,12.67 
,12.
> 96, 13.28 ,13.47, 13.65) #Vektor y
> 
> that is my y-vector; I always need to copy and paste this line 
originating
> from:
>   X8.5 X9.5 X10.5 X11.5 X12.5 X13.5 X14.5 X15.5 X16.5 X17.5
> SD24   NA   NA  5.67  6.53  6.83  7.41  7.93   8.5  8.86  9.46
> 
>   X18.5 X19.5 X20.5 X21.5 X22.5 X23.5 X24.5 X25.5 X26.5 X27.5 X28.5 
>9.8210 10.35  10.7 11.03 11.37 11.61 11.84 12.12 12.39 12.67
> 
>   X29.5 X30.5 X31.5 X32.5
>12.96 13.28 13.47 13.65

You probably read SD24 from some source by read.delim which suppose the 
first line is header and subsequent lines (in your case only one) are 
data.

I would try to read it with header = FALSE option. You shall get data 
frame with 2 lines and you could then use

t(your.reed.data)

to transpose it to more convenient form.

Or you can use
x <- your.read.data[1,]
y <- your.read.data[2,]

to get x, y.

Regards
Petr

> R always considers the original data as different variables(as matrix).
> I already tried: y<-as.vector(SD24)
> It doesn't work.   SD24 is the object giving me the original data you 
see.
> 
> 
> sorry for writing so long; hope it is clear what I wrote.
> 
> Thanks for your efforts,   Benedikt
> 
> --
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Eclipse and StatET Howto (also added Subversion, Rtools)

2009-04-06 Thread Ken-JP

UPDATE on StatET and Ubuntu 8.10 amd64:

StatET also works perfectly on Ubuntu 8.10 amd64, but the installation
procedure takes a lot more effort than on XP Pro 32-bit or Vista 32-bit (at
least from my experience).  

But I am very happy to have more RAM and having StatET working definitely
helps the R-development experience.  I also love the power of *nix, but like
my experiences in the past, getting things to work right can be a big
time-sink - it was the case with getting StatET working here.

Some things to watch out for on Ubuntu 8.10 amd64 (you may or may not have
the same issues):

1. Eclipse should be installed according to this procedure:

  http://flurdy.com/docs/eclipse/install.html

You may get away with just setting ECLIPSE_HOME, but if you do nothing but
unzip and run it, you may run into some weird run-time issues with StatET as
described here:

 
http://www.nabble.com/-SOLVED--Need-Help-with-StatET-Error-Bug--on-Ubuntu-8.10-amd64-td22905352.html

2. Follow my earlier post on this thread wrt rJava, -Drjava.path, and Sun
JDK.

Of course, there may be many different ways to get StatET working, but the
steps in this thread worked for me.  

I posted these messages for others in appreciation of help that I got from
other posted messages, but also for my future reference when I need to get
StatET working on a newly-upgraded system.

I hope someone finds this thread useful.

- Ken



-- 
View this message in context: 
http://www.nabble.com/Eclipse-and-StatET-Howto-%28also-added-Subversion%2C-Rtools%29-tp22764049p22907519.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] time-series data and time-invariant missing values

2009-04-06 Thread Kunzler, Andreas
Dear list,

I have some problems with time-series data and missing values of time-invariant 
informations like sex or the birth-date.

Assume a data (d) structure like

id  birth   sex year of observation
1   NA  NA  2006
1   1976-01-01  male2007
1   NA  NA  2008

I am looking for a way to replace the missing values.

Right know my answer to this problem slows down R



for (i in 1:length(d[,1])){ # for all observations

if (is.na(d$birth)[i])==F){ # Check if birth of observation(i) is 
missing
d$birth_2[i] <- as.Date(birth[i],"%d.%m.%Y") 
}else{
d$birth2[i]  <- d$birth[id[i]==d$id & 
is.na(d$birth)==F],"%d.%m.%Y")[1] # if birth of observation (i) is missing, 
take a observation of another year
}
}
}

Result:


id  birth   sex year of observation birth2
1   NA  NA  20061976-01-01
1   01.01.1976  male20071976-01-01
1   NA  NA  20081976-01-01

unfortunately the data consists of over 2 observations a year.

Does anybody know a better way?

Thanks

Mit freundlichen Grüßen

Andreas Kunzler

Bundeszahnärztekammer (BZÄK)
Chausseestraße 13
10115 Berlin

Tel.: 030 40005-113
Fax:  030 40005-119

E-Mail: a.kunz...@bzaek.de 

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

2009-04-06 Thread Dieter Menne
Mohammad Sabr  yahoo.com> writes:
> I am facing a problem when I am installing the dynamo-package and loading it.
After I installed the package,
> I received the following warning message:
> "In file.create(f.tg) :
>   cannot create file 'C:\PROGRA~2\R\R-28~1.1/doc/html/packages.html', reason
'Permission denied'"
> 
> and when I load the package, an error message pops up saying that "the
application failed to start because
> libgsl.dll was not found. Re-installing the application may fix the problem" 

This is probably on Vista. See the sections on Vista in the R Windows FAQ.

Dieter

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] DierckxSpline fitting with different sets of y-values in one time

2009-04-06 Thread Jonckers Elisabeth
Dear,

So What I'm looking at is the effect of age on the functional connectivity in a 
certain brain network. I have the ages of different subjects as x-values and 
values representing this functional connectivity with a region of intrest. This 
values are always for one voxel. But I found a whole cluster with higher 
connectivity in younger peoply so I wanted to use the values of different 
voxels of this cluster except of only the values of the voxel with the biggest 
t-value.
The script I used is described below (short version with only 5 subjects). The 
reason whe used DierckSpline is that when you just fit a line it looks like a 
line with a "knot" would better fit the data.

Age<-c(23,24,25,25,25)
Connectivity<-c(0.453,0.628,0.518,-0.060,0.384)

DF<-data.frame(cbind(Age,Connectivity))
plot(Age,Connectivity)
splinefit<-with(DF, curfit.free.knot(Age, Connectivity, k=1, g=1, prior=NULL))

splinefit

xfit1<-c(Age[1],splinefit$knots[3])   
xfit2<-c(splinefit$knots[3],Age[length(Age)])

yfit1<-c(splinefit$coef[1],splinefit$coef[2])
yfit2<-c(splinefit$coef[2],splinefit$coef[3])

lines(xfit1,yfit1)
lines(xfit2,yfit2)

I already tried to add some sets of y-values in the script but I always get 
errors. Such as "invalid plot type".
 The problem is that I'm not at all familiar with the "language" used for this 
scripts so it's very difficult to find the right sollution.
I also looked at the information about thin plate splines but I don't think 
that's what I need.

Thank you already for helping me in the right direction, I hope is a little 
easier to understand now what I'm doing.

Elisabeth Jonckers

  





Dear Elisabeth: 

  Have you tried it?  I have not, but I suspect the answer is "no". 

  What problem are you trying to solve?  You might get more useful 
suggestions from this list if you provide commented, minimal, 
self-contained, reproducible code describing your problem and what 
you've tried to solve it, as suggested in the posting guide 
"www.R-project.org/posting-guide.html". 

  With fmri images, I might look first at the "fields" package, 
because it is explicitly designed for "curve, surface and function 
fitting with an emphasis on splines, spatial data and spatial 
statistics. The major methods include cubic, robust, and thin plate 
splines, multivariate Kriging and Kriging for large data sets."  I have 
not used it, but it sounds to me like you might want thin plate 
splines.  Paul Dierckx (1993) Curve and Surface Fitting with Splines 
(Oxford Science Publications) discusses thin plate splines, and Dierckx 
wrote Fortran to fit them.  However, the "DierckxSpline" package does 
not currently connect to those capabilities. 

  If univariate splines would do, I might start with the "fda" 
package.  The theory behind that is documented in two books by Ramsay 
and Silverman. 

  Hope this helps. 
  Spencer Graves

Jonckers Elisabeth wrote:
> Dear "R" users,
>
> I have a question about the Package DierckxSpline. I have tried to find the 
> answer by myself but it didn't worked out.
>
> I wondered if Dierckxspline can use different sets of y values in one time to 
> fit a line with knot. I have different sets of Y values representing the same 
> thing for different voxels (in an fmri image). I have already fitted the data 
> in different graphs and I know now that the plots are comparable for the 
> different data sets (so for the different voxels) but I wanted to include all 
> the information in one plot, If it's possible. So I want to know the best 
> fitting line for the whole cluster of voxels except for one voxel.
> If there is no possibility to do this I tought it would be an option to take 
> the mean of the different y-values and use those values but I don't know if 
> this is mathematical right to do.
> I hope someone can help me with this.
>
> Thank you very much,
> Elisabeth Jonckers
> GIfMI
> Ghent University Hospital
> Belgium
>
>   [[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] problem with svyglm()

2009-04-06 Thread Thomas Lumley

On Thu, 2 Apr 2009, Federico Calboli wrote:


Hello,

I'm trying to use the function svyglm in the library survey.

I create a data survey object:

data_svy<- svydesign(id=~PSU, strata=~sample_domain,
weights=~sample_weight, data=data, nest=TRUE)

and I try to use svyglm() with little success:

R<-svyglm(data_svy[,4]~(data_svy[,iCol]==listModality[[iVar]]
[iMod]),design=data_svy, family=binomial(link="logit")

Error in svyglm.survey.design(data_svy[, 4] ~ (data_svy[, iCol] ==
listModality[[iVar]][iMod]),  :
all variables must be in design= argument


I don't know what you are trying to do here, but svyglm() wants a formula 
where the variables are all in the design object. Also, data_svy[,iCol] 
won't do what you probably expect, since data_svy isn't a data frame.




Puzzlingly the following code works:

R<-glm(data[,4]~(data[,iCol]==listModality[[iVar]][iMod]),
family=binomial(link="logit")



There are two differences here. The first is that glm() doesn't require 
variables to be in the data= argument, because it doesn't have to carry 
around the design meta-data.  The second is that data[,4] is a 
well-defined variable, whereas data_svy[,4] is meaningless.


It's hard to guess exactly what you are trying to do here. If you are 
trying to do a loop over regression models then you have to do something 
like


for(v in vnames) {
  models[[v]] <- eval(bquote( svyglm(y~x+.(as.name(v)), design=data_svy)))
}

-thomas

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

2009-04-06 Thread fayssal

Hi There,

There seems to be a way for calling R from .net. However, is there anyway
for calling .net/C# code from R? Something similar to the RJava package for
.net?


Thanks a mil!

Fayssal
-- 
View this message in context: 
http://www.nabble.com/R-and-.net-C--tp22904715p22904715.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] package: maps and spatstat question

2009-04-06 Thread Laura Chihara


I would like to use the output from the map function
in the package maps for use in, say, the spatstat
package. I don't quite understand the coordinates
for the border of the state:
Example:

library(maps)
iowa<-map("region","iowa)

x<-iowa$x
y<-iowa$y

There are NA's and duplicated coordinates.
What would I need to do to use this in the
spatstat owin command?
owin(poly= ?)

Thank you.

-- Laura


Laura Chihara
Professor of Mathematics  507-222-4065 (office)
Dept of Mathematics   507-222-4312 (fax)
Carleton College
1 North College Street
Northfield MN 55057

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

2009-04-06 Thread Mollet, Fabian
Dear R-expert
 
I'm fitting a non linear model (energy allocation model to individual
growth data) using your nlme routine. For each individual I have thus a
number of observations (age and size) to which I fit the nonlinear
function, with random effects for the individuals on the estimated
parameters (individual as the grouping factor). The sampling of these
individuals was stratified (size stratified) and the observations are
thus not representative for the population. But as we know the true size
distributions over the strata, we can compute a statistical weight for
each individual, given by the frequency of the size at age of that
individual in the true population distribution. To obtain representative
estimates in the nlme, I would therefore preferably weight the fitting
by these statistical weights. In each group (which is the individual) a
different weighting factor would apply (I guess that the individual
estimation will not be much affected by these weights, but the
population mean). I don't quite see how to do this weighting by
nlme-group. 
 
I think what I need is something that multiplies these weights to the
residual variance. My first hint would be something as it is described
by the function varIdent or varFixed, but it is not quite clear to me
what is being done by these (e.g. what is meant by variance covariate
etc.?).
 
I thank you very much in advance if you could briefly comment on that
and point out the function for the weighting that should be applied.
 
All the best
 
Fabian Mollet 
 
 

[[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] SUM,COUNT,AVG

2009-04-06 Thread calpeda

Hi,
I ve been searching a lot in internet..but I can t find a solution
Attached, you find a file.
I need for each (Materiale, tpdv, UM) to find sum,avg and count
My idea was to aggregate for the 3 parameters ..but I don t know how to get
the numeric value (SUM,COUNT,AVG) I need.
Can you help me?
thank you

http://www.nabble.com/file/p22905322/ordini2008_ex.txt ordini2008_ex.txt 
-- 
View this message in context: 
http://www.nabble.com/SUM%2CCOUNT%2CAVG-tp22905322p22905322.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] re ad.table

2009-04-06 Thread calpeda

Hi,
I ve been searching a lot in internet..but I can t find a solution
Attached, you find a file.
I need for each (Materiale, tpdv, UM) to find sum,avg and count
My idea was to aggregate for the 3 parameters ..but I don t know how to get
the numeric value (SUM,COUNT,AVG) I need.
Can you help me?
thank you

http://www.nabble.com/file/p22905601/ordini2008_ex.txt ordini2008_ex.txt 
-- 
View this message in context: 
http://www.nabble.com/read.table-tp22905601p22905601.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] Boxplots in Barplots

2009-04-06 Thread johnhj

Hii,

Is it possible to put Boxplots at the top of the Barplots ? I will describe
the standard derivation with a Boxplot at the of the Barplots. It could also
be "line" instead of Boxplot...

Can anybody help me how to do it ?

greetings, 
j. 
-- 
View this message in context: 
http://www.nabble.com/Boxplots-in-Barplots-tp22907174p22907174.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] SUM,COUNT,AVG

2009-04-06 Thread Gabor Grothendieck
I gather you have an SQL background since those are SQL functions.
Check out the sqldf R package and the many examples on the home
page:

http://sqldf.googlecode.com

and in ?sqldf

That may ease the transition from SQL to R.

On Mon, Apr 6, 2009 at 5:37 AM, calpeda  wrote:
>
> Hi,
> I ve been searching a lot in internet..but I can t find a solution
> Attached, you find a file.
> I need for each (Materiale, tpdv, UM) to find sum,avg and count
> My idea was to aggregate for the 3 parameters ..but I don t know how to get
> the numeric value (SUM,COUNT,AVG) I need.
> Can you help me?
> thank you
>
> http://www.nabble.com/file/p22905322/ordini2008_ex.txt ordini2008_ex.txt
> --
> View this message in context: 
> http://www.nabble.com/SUM%2CCOUNT%2CAVG-tp22905322p22905322.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


[R] Odp: re ad.table

2009-04-06 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 06.04.2009 11:54:27:

> 
> Hi,
> I ve been searching a lot in internet..but I can t find a solution
> Attached, you find a file.
> I need for each (Materiale, tpdv, UM) to find sum,avg and count
> My idea was to aggregate for the 3 parameters ..but I don t know how to 
get
> the numeric value (SUM,COUNT,AVG) I need.

?sum
?mean
?length

Aggregate works with one value only but you can try doBy package or 
split/lapply approach.

Regards
Petr

> Can you help me?
> thank you
> 
> http://www.nabble.com/file/p22905601/ordini2008_ex.txt ordini2008_ex.txt 

> -- 
> View this message in context: 
http://www.nabble.com/read.table-tp22905601p22905601.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] package: maps and spatstat question

2009-04-06 Thread hadley wickham
Hi Laura,

You might find the map_data function from the ggplot2 package helpful:

library(ggplot2)
library(maps)
head(map_data("state", "iowa"))

It formats the output of the map command into a self-documenting data frame.

Hadley

On Mon, Apr 6, 2009 at 7:00 AM, Laura Chihara  wrote:
>
> I would like to use the output from the map function
> in the package maps for use in, say, the spatstat
> package. I don't quite understand the coordinates
> for the border of the state:
> Example:
>
> library(maps)
> iowa<-map("region","iowa)
>
> x<-iowa$x
> y<-iowa$y
>
> There are NA's and duplicated coordinates.
> What would I need to do to use this in the
> spatstat owin command?
> owin(poly= ?)
>
> Thank you.
>
> -- Laura
>
> 
> Laura Chihara
> Professor of Mathematics  507-222-4065 (office)
> Dept of Mathematics       507-222-4312 (fax)
> Carleton College
> 1 North College Street
> Northfield MN 55057
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
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] Need Help with StatET Error/Bug? on Ubuntu 8.10 amd64

2009-04-06 Thread John Fox
Dear Ken-JP,

I'm not sure that this is relevant, but I posted a question recently to the
StatET list about using StatET with 64 bit Vista (I don't yet have the
machine), and was told that it would work, but only with 32-bit versions of
Eclipse and Java.

I hope this helps,
 John

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On
> Behalf Of Ken-JP
> Sent: April-06-09 5:39 AM
> To: r-help@r-project.org
> Subject: [R] Need Help with StatET Error/Bug? on Ubuntu 8.10 amd64
> 
> 
> Hi,
> 
> I posted this message on the StatET-user board last week, but it looks
like
> a ghost-town...
> 
> I have a bad feeling that there is some code in the plug-in which doesn't
> work well with my environment, but if I am lucky, maybe other users have
> worked around this problem somehow - I am hoping that my setup is the
issue.
> 
> Note: very similar StatET setups on 32-bit XP Pro and Vista run
flawlessly.
> 
> Has anyone else run into this problem and/or found a way around it?
> 
> Ubuntu 8.10 intrepid amd64
> Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
> Java HotSpot(TM) 64-Bit Server VM (build 11.3-b02, mixed mode)
> R 2.8.1
> Eclipse 3.4.2
> StatET 0.7.2.b200812051430sw
> 
>

-
> ---
> 
> When I start up the R Console, I get a java.lang.NullPointerException
inside
> Eclipse in the form of a popup warning.
> 
> Six icons right of the Console-tab fail to appear:
> 
> Cancel the current task
> Terminate
> Remove Launch
> Remove All Terminated Launches
> Clear Console
> Scroll Lock
> 
> Every time the Console gets focus, I get the NullPointerError exception -
> probably an attempt to refresh the icons.  After a while, the Eclipse IDE
> loses focus and becomes unusable.
> 
> Looks like it's happening around:
> 
> at org.eclipse.ui.SubActionBars.updateActionBars(SubActionBars.java:610)
> 
>

-
> ---
> 
> Session Data:
> eclipse.buildId=M20090211-1700
> java.version=1.6.0_13
> java.vendor=Sun Microsystems Inc.
> BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
> Command-line arguments:  -os linux -ws gtk -arch x86_64
> 
> Exception Stack Trace:
> java.lang.NullPointerException
>   at
>
org.eclipse.jface.resource.URLImageDescriptor.getFilePath(URLImageDescriptor
.
> java:138)
>   at
>
org.eclipse.jface.resource.URLImageDescriptor.createImage(URLImageDescriptor
.
> java:157)
>   at
>
org.eclipse.jface.resource.ImageDescriptor.createResource(ImageDescriptor.ja
v
> a:165)
>   at
>
org.eclipse.jface.resource.DeviceResourceManager.allocate(DeviceResourceMana
g
> er.java:56)
>   at
>
org.eclipse.jface.resource.AbstractResourceManager.create(AbstractResourceMa
n
> ager.java:88)
>   at
>
org.eclipse.jface.resource.LocalResourceManager.allocate(LocalResourceManage
r
> .java:82)
>   at
>
org.eclipse.jface.resource.AbstractResourceManager.create(AbstractResourceMa
n
> ager.java:88)
>   at
>
org.eclipse.jface.resource.ResourceManager.createImage(ResourceManager.java:
1
> 72)
>   at
>
de.walware.eclipsecommons.ui.HandlerContributionItem.updateIcons(HandlerCont
r
> ibutionItem.java:648)
>   at
>
de.walware.eclipsecommons.ui.HandlerContributionItem.fill(HandlerContributio
n
> Item.java:383)
>   at
>
org.eclipse.jface.action.SubContributionItem.fill(SubContributionItem.java:7
7
> )
>   at
> org.eclipse.jface.action.ToolBarManager.update(ToolBarManager.java:349)
>   at
org.eclipse.ui.internal.ViewPane.updateActionBars(ViewPane.java:449)
>   at
>
org.eclipse.ui.internal.ViewActionBars.updateActionBars(ViewActionBars.java:
5
> 9)
>   at
> org.eclipse.ui.SubActionBars.updateActionBars(SubActionBars.java:610)
>   at
>
de.walware.statet.nico.ui.console.NIConsolePage$6.handleEvent(NIConsolePage.
j
> ava:599)
>   at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
>   at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1158)
>   at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1182)
>   at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1163)
>   at org.eclipse.swt.widgets.Control.sendFocusEvent(Control.java:3284)
>   at
org.eclipse.swt.widgets.Control.gtk_event_after(Control.java:2684)
>   at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1538)
>   at org.eclipse.swt.widgets.Control.windowProc(Control.java:4506)
>   at org.eclipse.swt.widgets.Display.windowProc(Display.java:4099)
>   at org.eclipse.swt.internal.gtk.OS._gtk_widget_grab_focus(Native
> Method)
>   at
org.eclipse.swt.internal.gtk.OS.gtk_widget_grab_focus(OS.java:9106)
>   at org.eclipse.swt.widgets.Control.forceFocus(Control.java:2107)
>   at org.eclipse.swt.widgets.Composite.forceFocus(Composite.java:494)
>   at org.eclipse.swt.widgets.Control.forceFocus(Control.java:2101)
>   at org.ec

Re: [R] Code of sample() in C

2009-04-06 Thread Paul Smith
Thanks again, Ranjan. I am wondering whether the seed can be set
(renewed) with GetRNGstate(). Furthermore, I would like to understand
why I am getting the reported compilation errors when I insert
GetRNGstate() in my code.

Paul


On Mon, Apr 6, 2009 at 12:17 PM, Ranjan Maitra  wrote:
> Hi Paul,
>
> I believe that you may need to set seed differently when you call the R
> math library as standalone. Specifically, you need to do the following
> (or rather, the following works):
>
>        unsigned int seed1, seed2;
>        FILE *fran;
>
>        fran = fopen("random.seed","r");
>        fscanf(fran, "%u %u", &seed1, &seed2);
>        fclose(fran);
>
>        set_seed(seed1, seed2);
>
> where random.seed is the file containing two large integers.
>
> and after I am done, I usually add the following towards the end of the
> main program
>
>        get_seed(&seed1, &seed2);
>
>        fran=fopen("random.seed", "w");
>        fprintf(fran, "%d %d\n", seed1, seed2);
>        fclose(fran);
>
> You will again need to include Rmath.h and declare the standalone parameter 
> in the calling program also.
>
>
> HTH!
>
> Best wishes,
> Ranjan
>
>
> On Mon, 6 Apr 2009 10:41:19 +0100 Paul Smith  wrote:
>
>> Thanks, Ranjan! I have tried to use the function SampleNoReplace in
>> random.c, which seems to work, except that I get always the same
>> random numbers (with your code the same happens). (My code is below.).
>>
>> I have read the documentation ("Writing R extensions"), where it is advised:
>>
>> «The interface to R’s internal random number generation routines is
>>
>> double unif_rand();
>> double norm_rand();
>> double exp_rand();
>>
>> giving one uniform, normal or exponential pseudo-random variate.
>> However, before these are used, the user must call
>>
>> GetRNGstate();
>>
>> and after all the required variates have been generated, call
>>
>> PutRNGstate();»
>>
>> However, when I use GetRNGstate() and PutRNGstate(), I get the following 
>> errors:
>>
>> $ gcc -I/usr/include/R -o myprog myprog.c -lRmath -lm
>> /tmp/cc6CMnlh.o: In function `main':
>> myprog.c:(.text+0x30): undefined reference to `GetRNGstate'
>> myprog.c:(.text+0x57): undefined reference to `PutRNGstate'
>> collect2: ld returned 1 exit status
>> $
>>
>> Any ideas?
>>
>> Paul
>>
>> --
>>
>> #include 
>> #include 
>> #include 
>> #include 
>> #define MATHLIB STANDALONE
>> #include 
>>
>> void snr(int k, int n, int *y, int *x);
>>
>> int main()
>> {
>>
>>   int *x = malloc(50*sizeof(int));
>>   int *y = malloc(5*sizeof(int));
>>   int i;
>>
>>   GetRNGstate();
>>   snr(5,50,y,x);
>>   PutRNGstate();
>>
>>   for(i=0;i<5;++i)
>>     printf("%d ",y[i]);
>>
>>   free(x);
>>   free(y);
>>
>>   return 0;
>>
>> }
>>
>>
>> void snr(int k, int n, int *y, int *x)
>> {
>>     int i, j;
>>     for (i = 0; i < n; i++)
>>         x[i] = i;
>>     for (i = 0; i < k; i++) {
>>         j = n * unif_rand();
>>         y[i] = x[j] + 1;
>>         x[j] = x[--n];
>>     }
>> }
>>
>> --
>>
>>
>>
>> On Sun, Apr 5, 2009 at 11:00 PM, Ranjan Maitra  wrote:
>> > I presume you mean sampling without replacement? The following
>> > (adapted from the file you asked for) will do it, but you will need to
>> > incorporate Rmath as standalone in order to get runif to work.
>> >
>> > This function will give you k indices from n, sampled WOR. Thus, n = 50
>> > for you and k = 5. You will get a vector y of length 5 (a pointer of int
>> > actually) which will contain these indices.
>> >
>> > Thus you will define a vector z (of length 50) which is 1:50, and then
>> > using the function, your SRWOR sample will be z[y[i]] where i = 0,
>> > 1,...4.
>> >
>> > I haven't tried this function out much myself, so YMMV.
>> >
>> > HTH!
>> >
>> > Best wishes,
>> > Ranjan
>> >
>> >
>> >
>> > #include 
>> > #ifndef USING_RLIB
>> > #define MATHLIB_STANDALONE 1 /*It is essential to have this before the call
>> >                               to the Rmath's header file because this 
>> > decides
>> >                               the definitions to be set. */
>> > #endif
>> > #include 
>> >
>> > /* Note that use of this function involves a prior call to the Rmath 
>> > library to
>> >   get the seeds in place. It is assumed that this is done in the calling
>> >   function. */
>> >
>> > /* Equal probability sampling; without-replacement case */
>> > /* Adapted from the R function called SampleNoReplace */
>> >
>> > /**
>> >  * Stores k out of n indices sampled at random without replacement
>> >  * in y.
>> >  */
>> > int srswor(int n, int k, int *y)
>> > {
>> >  if (k > n) {
>> >    return 1;
>> >  }
>> >  else {
>> >    const double len = (double) n;
>> >    int i;
>> >    int* x = malloc(n * sizeof(int));
>> >    if (!x) {
>> >      return 2;
>> >    }
>> >
>> >    for (i = 0; i < n; ++i)     x[i] = i;
>> >
>> >    for (i = 0; i < k; ++i) {
>> >      const int j = (int)(len * runif(0.0, 1.0));
>> >      y[i] = x[j];
>> >      x[

Re: [R] Need Help with StatET Error/Bug? on Ubuntu 8.10 amd64

2009-04-06 Thread Ken-JP


Thank you, John, for this bit of information - it will be useful when I move
to 64 bit Vista one of these days.

FWIW, the Ubuntu 8.10 amd64 install I attempted was on 64-bit versions of
everything (except possibly StatET itself).  

64-bit R, JDK, and Eclipse.

If someone does get StatET working on a 64-bit Windoze system, do please let
us know.
Thank you.

- Ken


John Fox-6 wrote:
> 
> Dear Ken-JP,
> 
> I'm not sure that this is relevant, but I posted a question recently to
> the
> StatET list about using StatET with 64 bit Vista (I don't yet have the
> machine), and was told that it would work, but only with 32-bit versions
> of
> Eclipse and Java.
> 
> I hope this helps,
>  John
> 

-- 
View this message in context: 
http://www.nabble.com/-SOLVED--Need-Help-with-StatET-Error-Bug--on-Ubuntu-8.10-amd64-tp22905352p22908497.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] R package: Where to put code to Run Once Only?

2009-04-06 Thread Ken-JP


Is there a specific place where we can place code to run once only in a
package?

I have code that switches based on Sys.info()[["nodename"]] - but since this
just about never changes, I would like to run it only once when someone
runs:

require( mypackage ) or library( vte )

I'm tempted to have some free-floating code in global space (in one of my
package's .R files), but it just seems so wrong/hacky to do it this way.

Where is the proper place to put this code?

- Ken



-- 
View this message in context: 
http://www.nabble.com/R-package%3A-Where-to-put-code-to-Run-Once-Only--tp22908592p22908592.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] How to preserve NULL in vector

2009-04-06 Thread Daren Tan
I have a vector containing NULL. Referencing to that NULL gives me NA
instead, which disrupt my codes. How can i preserve NULL as it is ?

> res <- c(1,2,NULL)
> res[1]
[1] 1
> res[2]
[1] 2
> res[3]
[1] NA

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

2009-04-06 Thread Duncan Murdoch

On 4/6/2009 9:24 AM, Daren Tan wrote:

I have a vector containing NULL. Referencing to that NULL gives me NA
instead, which disrupt my codes. How can i preserve NULL as it is ?


NULL is not a numeric value, so you can't put it in a numeric vector. 
When you tried, it got converted to the numeric value NA.


You can have a list containing NULL, and lists are vectors, but 
functions that expect *numeric* vectors generally won't work with them.


Duncan Murdoch




res <- c(1,2,NULL)
res[1]

[1] 1

res[2]

[1] 2

res[3]

[1] NA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Maintain proportions while reducing graphic output size

2009-04-06 Thread Jason Pare
Hello,

Is there a combination of par() settings or other commands that will allow
me to uniformly reduce the size of graphics outputs? It appears that the
png() device outputs 5-inch by 5-inch  images, and I am trying to change my
whole script to produce 4x4 images with the same proportions. I tried
specifying parameters within each png(), but it reduced the size of the file
without refitting the contents so the graph title went off the margin. This
is an example of the code I used:

png("graph2.png",height=432, width=432, units="px", res=96)

What would be the best way to generate 4x4, proportional graphs?

Thanks!

[[alternative HTML version deleted]]

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


[R] update() a LME-with correlated errors object

2009-04-06 Thread Christian Salas

Hi there

I cannot update a fitted LME-with spatially correlated errors object, 
please check the example. Data from an R book, only 281 rows, the 
provided code download the data from my website.


I use R 2.8.1 under linux-ubuntu, For this session i was using the 
following packages

Package Version
1  nlme  3.1-90
2  datasets   2.8.1
3  MASS  7.2-46
4 utils   2.8.1
5 stats   2.8.1
6  graphics   2.8.1
7 grDevices   2.8.1
8   methods   2.8.1
9  base   2.8.1


The code!!

# Fitting a LME with correlated errors
# Example and data from Book: Bivand et al 2008 "Applied spatial
# data analysis with R"
###

#example
#1. read data
#data from the book, i built the .csv file
dbase <- 
read.csv(url("http://environment.yale.edu/salas/data/spatDataBivandetal08.csv";),

 header = TRUE)

head(dbase)
dim(dbase)

#fit a linear model (just for fun)
nylm <- lm(Z~PEXPOSURE+PCTAGE65P+PCTOWNHOME, data=dbase)
summary(nylm)

#fit a mixed-effect model [p.288 of Bivand et al] with correlated
# errros depending on the distance between the centroids of the areas
library(nlme)

#specify correlation structure [also explained in Pinheiro&Bates, p.238]
sp1 <- corSpatial(1, form = ~ x + y, type = "gaussian")
scor<-Initialize(sp1, dbase[,c("x", "y")], nugget=FALSE)

#fit the LME with correlated errors
spmodel<-lme(Z~PEXPOSURE+PCTAGE65P+PCTOWNHOME,
 random=~1|AREAKEY,
 data=dbase, correlation=scor, method="ML")

summary(spmodel)

#the problem
#I want to fit the same mixed-effect model with correlated structure
# for a different havin n-i observations and of course the same columns
dbnew=dbase[-1,]
nrow(dbnew) #one less observation than before

#here is the error, or bug?
update(spmodel, data=dbnew) #here is the error!, why?
#after running this, appear a large message, summarized here
#
#*** glibc detected *** /usr/lib/R/bin/exec/R: free(): invalid next size 
(normal): 0x0950f090 ***

#=== Backtrace: =
#/lib/tls/i686/cmov/libc.so.6[0xb7b6e454]
#/lib/tls/i686/cmov/libc.so.6(cfree+0x96)[0xb7b704b6]
#b6ddb000-b6ddc000 r--p 00633000 08:05 1574
#Process R aborted at Mon Apr  6 09:12:41 2009

#I did also check this in a Windows OS, and I obtained the same problem.
#I did also check with an older version of nlme, and I obtained the same 
#problem.



any suggestion?

thanks in advance


--
---
Christian Salas E-mail:christian.sa...@yale.edu
PhD candidate   http://environment.yale.edu/salas
School of Forestry and Environmental Studies
Yale University Tel: +1-(203)-432 5126
360 Prospect St Fax:+1-(203)-432 3809
New Haven, CT 06511-2189Office: Room 35, Marsh Hall
USA

Yale Biometrics Lab  http://environment.yale.edu/biometrics

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

2009-04-06 Thread Daniel Brewer
Hello,

What is the best way to turn a list into a data.frame?

I have a list with something like:
$`3845`
 [1] "04010" "04012" "04360"

$`1029`
[1] "04110" "04115"

And I would like to get a data frame like the following:

3845 "04010"
3845 "04012"
3845 "04360"
1029 "04110"
1029 "04115"

Any ideas?

Dan

-- 
**
Daniel Brewer, Ph.D.

Institute of Cancer Research
Molecular Carcinogenesis
Email: daniel.bre...@icr.ac.uk
**

The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company 
Limited by Guarantee, Registered in England under Company No. 534147 with its 
Registered Office at 123 Old Brompton Road, London SW7 3RP.

This e-mail message is confidential and for use by the a...{{dropped:2}}

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


[R] [R-pkgs] New package: ascii version 0.1

2009-04-06 Thread David Hajage
Hi,

ascii is a new R package for writing asciidoc or txt2tags document with
embeded R commands.

It provides:
 - a generic method for common R objects: ascii(). Default argument depends
of R object.
 - two Sweave drivers: Sweave("yourfile.Rnw", RweaveAsciidoc) or
Sweave("yourfile.Rnw",
RweaveT2t).
This package is very similar to xtable or R2HTML. It is very interesting if
you want to produce multiple output from one source.

You could find some examples on http://eusebe.github.com/ascii/.

Comments and suggestions are welcome !

Best,

David

[[alternative HTML version deleted]]

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

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


Re: [R] number of zeros in a matrix -row by row

2009-04-06 Thread Luc Villandre

Hi,

Try

/rowSums(M==0)/

This should work just fine.

Cheers,

Luc

onyourmark wrote:

Hi. I have an n x m matrix M some of who's entries are zeros. I want to know
how many zeros there are in each row-perhaps stored in a 1 x n vector
which lists the number of zeros for each row of M.

Before I had a vector V and I was able to get the number of zeros in V by
doing length(V[ V==0]) but when I try something similar for M, like M[ M==0]
it creates a vector not a matrix and so this does not work. Does anyone have
a solution to this?

Thank you.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Need Help with StatET Error/Bug? on Ubuntu 8.10 amd64

2009-04-06 Thread John Fox
Dear Ken,

The thread on the StatET email list to which I referred
 indicates that StatET does work under 64-bit Vista using 32-bit
Eclipse and Java.

Best,
 John


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On
> Behalf Of Ken-JP
> Sent: April-06-09 9:13 AM
> To: r-help@r-project.org
> Subject: Re: [R] Need Help with StatET Error/Bug? on Ubuntu 8.10 amd64
> 
> 
> 
> Thank you, John, for this bit of information - it will be useful when I
move
> to 64 bit Vista one of these days.
> 
> FWIW, the Ubuntu 8.10 amd64 install I attempted was on 64-bit versions of
> everything (except possibly StatET itself).
> 
> 64-bit R, JDK, and Eclipse.
> 
> If someone does get StatET working on a 64-bit Windoze system, do please
let
> us know.
> Thank you.
> 
> - Ken
> 
> 
> John Fox-6 wrote:
> >
> > Dear Ken-JP,
> >
> > I'm not sure that this is relevant, but I posted a question recently to
> > the
> > StatET list about using StatET with 64 bit Vista (I don't yet have the
> > machine), and was told that it would work, but only with 32-bit versions
> > of
> > Eclipse and Java.
> >
> > I hope this helps,
> >  John
> >
> 
> --
> View this message in context:
http://www.nabble.com/-SOLVED--Need-Help-with-
> StatET-Error-Bug--on-Ubuntu-8.10-amd64-tp22905352p22908497.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] Best way to turn a list into a data.frame

2009-04-06 Thread hadley wickham
On Mon, Apr 6, 2009 at 8:49 AM, Daniel Brewer  wrote:
> Hello,
>
> What is the best way to turn a list into a data.frame?
>
> I have a list with something like:
> $`3845`
>  [1] "04010" "04012" "04360"
>
> $`1029`
> [1] "04110" "04115"
>
> And I would like to get a data frame like the following:
>
> 3845 "04010"
> 3845 "04012"
> 3845 "04360"
> 1029 "04110"
> 1029 "04115"
>
> Any ideas?

l <- list("3845" = c("a", "b", "c"), "1029" = c("d", "e","f"))

libary(reshape)
melt(l)

Hadley

-- 
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] R package: Where to put code to Run Once Only?

2009-04-06 Thread Uwe Ligges



Ken-JP wrote:


Is there a specific place where we can place code to run once only in a
package?

I have code that switches based on Sys.info()[["nodename"]] - but since this
just about never changes, I would like to run it only once when someone
runs:

require( mypackage ) or library( vte )

I'm tempted to have some free-floating code in global space (in one of my
package's .R files), but it just seems so wrong/hacky to do it this way.

Where is the proper place to put this code?


That fine, in principle, convention is to have code in zzz.R, see 
Writing R Extzensions.


Uwe Ligges



- Ken





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


Re: [R] Best way to turn a list into a data.frame

2009-04-06 Thread Luc Villandre

Hi Daniel,

In your case, I guess you could use:

col1 = rep(attributes(my.list)$names,lapply(my.list,length)) ;
col2 = unlist(my.list,use.names=FALSE) ;
my.data.frame = as.data.frame(cbind(col1,col2)) ;

This should work well.

Cheers,

Luc

Daniel Brewer wrote:

Hello,

What is the best way to turn a list into a data.frame?

I have a list with something like:
$`3845`
 [1] "04010" "04012" "04360"

$`1029`
[1] "04110" "04115"

And I would like to get a data frame like the following:

3845 "04010"
3845 "04012"
3845 "04360"
1029 "04110"
1029 "04115"

Any ideas?

Dan




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Search for a graph package - see link

2009-04-06 Thread Knut Krueger

Hi to all,
does anybody knows whether there is a package to plot those
http://www.equine-science.de/temp/graph.jpg
graphs.
the thickness of the points and/or the lines should be represent the 
numbers of behaviours


With kind regards Knut

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


Re: [R] Best way to turn a list into a data.frame

2009-04-06 Thread Daniel Brewer
Thanks thats marvellous.  Does the trick beautifully.

Dan

hadley wickham wrote:
> On Mon, Apr 6, 2009 at 8:49 AM, Daniel Brewer  wrote:
>> Hello,
>>
>> What is the best way to turn a list into a data.frame?
>>
>> I have a list with something like:
>> $`3845`
>>  [1] "04010" "04012" "04360"
>>
>> $`1029`
>> [1] "04110" "04115"
>>
>> And I would like to get a data frame like the following:
>>
>> 3845 "04010"
>> 3845 "04012"
>> 3845 "04360"
>> 1029 "04110"
>> 1029 "04115"
>>
>> Any ideas?
> 
> l <- list("3845" = c("a", "b", "c"), "1029" = c("d", "e","f"))
> 
> libary(reshape)
> melt(l)
> 
> Hadley
> 

-- 
**
Daniel Brewer, Ph.D.

Institute of Cancer Research
Molecular Carcinogenesis
Email: daniel.bre...@icr.ac.uk
**

The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company 
Limited by Guarantee, Registered in England under Company No. 534147 with its 
Registered Office at 123 Old Brompton Road, London SW7 3RP.

This e-mail message is confidential and for use by the a...{{dropped:2}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Search for a graph package - see link

2009-04-06 Thread Gábor Csárdi
Yes, the 'igraph' package can do this (http://igraph.sf.net), and I
think 'network' can do it, too. Maybe others as well.

Best,
Gabor

On Mon, Apr 6, 2009 at 4:26 PM, Knut Krueger  wrote:
> Hi to all,
> does anybody knows whether there is a package to plot those
> http://www.equine-science.de/temp/graph.jpg
> graphs.
> the thickness of the points and/or the lines should be represent the numbers
> of behaviours
>
> With kind regards Knut
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

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

2009-04-06 Thread Stavros Macrakis
There are various ways to do this in R.

# sample data
dd <- data.frame(a=1:10,b=sample(3,10,replace=T),c=sample(3,10,replace=T))

Using the standard built-in functions, you can use:

*** aggregate ***

aggregate(dd,list(b=dd$b,c=dd$c),sum)
  b c  a b c
1 1 1 10 2 2
2 2 1  3 2 1


*** tapply ***

tapply(dd$a,interaction(dd$b,dd$c),sum)
  1.1   2.1   3.1   1.2   2.2   3.2   1.3
2.3
 5.00  3.00 10.00  5.00NANA  5.00
...

But the nicest way is probably to use the plyr package:

> library(plyr)
> ddply(dd,~b+c,sum)
  b c V1
1 1 1 14
2 2 1  6




Unfortunately, none of these approaches allows you do return more than one
result from the function, so you'll need to write

> ddply(dd,~b+c,length)   # count
> ddply(dd,~b+c,sum)
> ddply(dd,~b+c,mean)   # arithmetic average

There is an 'each' function in plyr, but it doesn't seem to be compatible
with ddply.

   -s

On Mon, Apr 6, 2009 at 5:37 AM, calpeda  wrote:

>
> Hi,
> I ve been searching a lot in internet..but I can t find a solution
> Attached, you find a file.
> I need for each (Materiale, tpdv, UM) to find sum,avg and count
> My idea was to aggregate for the 3 parameters ..but I don t know how to get
> the numeric value (SUM,COUNT,AVG) I need.
> Can you help me?
> thank you
>
> http://www.nabble.com/file/p22905322/ordini2008_ex.txt ordini2008_ex.txt
> --
> View this message in context:
> http://www.nabble.com/SUM%2CCOUNT%2CAVG-tp22905322p22905322.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.


[R] Collapse data matrix with extra info separated by commas

2009-04-06 Thread Daniel Brewer
Hello,

I would like to reshape my data for presentation purposes from something
like this:
> test <-
data.frame(a=c("A","A","A","A","B","B","B"),b=c(1,1,2,2,1,1,1),c=1:7)
> test
  a b c
1 A 1 1
2 A 1 2
3 A 2 3
4 A 2 4
5 B 1 5
6 B 1 6
7 B 1 7

to something like this:
  a b c
1 A 1 1,2
3 A 2 3,4
5 B 1 5,6,7

This seems to be the sort of the thing that the reshape library should
be able to do, but I just can't work out how to do it.

Many thanks

Dan

-- 
**
Daniel Brewer, Ph.D.

Institute of Cancer Research
Molecular Carcinogenesis
Email: daniel.bre...@icr.ac.uk
**

The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company 
Limited by Guarantee, Registered in England under Company No. 534147 with its 
Registered Office at 123 Old Brompton Road, London SW7 3RP.

This e-mail message is confidential and for use by the a...{{dropped:2}}

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

2009-04-06 Thread Luc Villandre

Hi,

Pretty hard to say. It really depends on what you want to.

MASS, nlme, lme4 and Hmisc are packages I use on a daily basis.

I guess you could also ask for those.

David Scott wrote:

On Wed, 1 Apr 2009, Eamonn O'Brien wrote:

The company I work for require users to request what packages they 
want from

the IT department (user cannot download themselves). I intend to request
installation of the latest version of R plus the 23 Cran task views. 
As a

statistician what are the recommended packages or packages that
statisticians using R recommend to install. I have started a new 
position
and want to (greedily) get everything that I may or may not use as I 
want to

avoid multiple requests to our IT dept.
Thanks




I haven't seen a response, so I will make a start.

It all depends on the area you are in, and the sort of work you do. If 
you are in finance, you will likely require different packages than if 
you are in biostat or whatever. There are no clues in your email, not 
even an informative address or signature.


There are a few general packages that you might consider though: Frank 
Harrell's packages; ggplot2 for graphics; a bootstrap package; 
depending on the users maybe a gui package such as Rcmdr ...

There are around 2000 packages now I believe.


David Scott 
_

David ScottDepartment of Statistics
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 373 7599 ext 85055Fax: +64 9 373 7018
Email:d.sc...@auckland.ac.nz

Graduate Officer, Department of Statistics
Director of Consulting, Department of Statistics

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

2009-04-06 Thread J. R. M. Hosking

Abelian wrote:

Dear ALL
I have a list of data below
0.80010 0.72299 0.69893 0.99597 0.89200 0.69312 0.73613 1.13559
0.85009 0.85804 0.73324 1.04826 0.84002
1.76330 0.71980 0.89416 0.89450 0.98670 0.83571 0.73833 0.66549
0.93641 0.80418 0.95285 0.76876 0.82588
1.09394 1.00195 1.14976 0.80008 1.11947 1.09484 0.81494 0.68696
0.82364 0.84390 0.71402 0.80293 1.02873
all of them are ninty.
Nowaday, i try to find a distribution to fit those data.
Firstly, I normalize the data, i.e.. (x-mean(X))/(sd(X))
i utilize the SAS to fit my data. Then i obtain the result below
##-
 Parameters for Lognormal
Distribution

 Parameter   Symbol
Estimate

 Threshold   Theta
-1.51062
 Scale
Zeta  0.237283
 Shape   Sigma
0.593481
 
Mean

0.001321
 Std
Dev   0.982435
##---
however, i confuse about the threshold parameter..
How to get it? Does it be able to be calculated by R?



Function pelln3 in package lmom will estimate all 3 parameters
of the 3-parameter lognormal distribution, including the threshold ...

> x <- scan(textConnection("
+ 0.80010 0.72299 0.69893 0.99597 0.89200 0.69312 0.73613 1.13559
+ 0.85009 0.85804 0.73324 1.04826 0.84002
+ 1.76330 0.71980 0.89416 0.89450 0.98670 0.83571 0.73833 0.66549
+ 0.93641 0.80418 0.95285 0.76876 0.82588
+ 1.09394 1.00195 1.14976 0.80008 1.11947 1.09484 0.81494 0.68696
+ 0.82364 0.84390 0.71402 0.80293 1.02873
+ "))
Read 39 items
>
> y <- (x-mean(x))/sd(x)
>
> library(lmom)
> pelln3(samlmu(y))
  zeta mu  sigma
-1.5362134  0.2554631  0.5896735



J. R. M. Hosking

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

2009-04-06 Thread Stavros Macrakis
Actually, ddply does this perfectly ... I had made a mistake in using
'each'.  The correct code is:

ddply(dd,~b+c,function(x)each(count=length,sum=sum,avg=mean)(x$a))

  b c count sum   avg
1 1 1 2  10  5.00
2 2 1 1   3  3.00
3 3 1 1  10 10.00
4 1 2 2  10  5.00
5 1 3 1   5  5.00
6 3 3 3  17  5.67

Hope this helps,

 -s



On Mon, Apr 6, 2009 at 10:34 AM, Stavros Macrakis wrote:

> There are various ways to do this in R.
>
> # sample data
> dd <- data.frame(a=1:10,b=sample(3,10,replace=T),c=sample(3,10,replace=T))
>
> Using the standard built-in functions, you can use:
>
> *** aggregate ***
>
> aggregate(dd,list(b=dd$b,c=dd$c),sum)
>   b c  a b c
> 1 1 1 10 2 2
> 2 2 1  3 2 1
> 
>
> *** tapply ***
>
> tapply(dd$a,interaction(dd$b,dd$c),sum)
>   1.1   2.1   3.1   1.2   2.2   3.2   1.3
> 2.3
>  5.00  3.00 10.00  5.00NANA  5.00
> ...
>
> But the nicest way is probably to use the plyr package:
>
> > library(plyr)
> > ddply(dd,~b+c,sum)
>   b c V1
> 1 1 1 14
> 2 2 1  6
> 
>
> 
>
> Unfortunately, none of these approaches allows you do return more than one
> result from the function, so you'll need to write
>
> > ddply(dd,~b+c,length)   # count
> > ddply(dd,~b+c,sum)
> > ddply(dd,~b+c,mean)   # arithmetic average
>
> There is an 'each' function in plyr, but it doesn't seem to be compatible
> with ddply.
>
>-s
>
> On Mon, Apr 6, 2009 at 5:37 AM, calpeda  wrote:
>
>>
>> Hi,
>> I ve been searching a lot in internet..but I can t find a solution
>> Attached, you find a file.
>> I need for each (Materiale, tpdv, UM) to find sum,avg and count
>> My idea was to aggregate for the 3 parameters ..but I don t know how to
>> get
>> the numeric value (SUM,COUNT,AVG) I need.
>> Can you help me?
>> thank you
>>
>> http://www.nabble.com/file/p22905322/ordini2008_ex.txt ordini2008_ex.txt
>> --
>> View this message in context:
>> http://www.nabble.com/SUM%2CCOUNT%2CAVG-tp22905322p22905322.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] SUM,COUNT,AVG

2009-04-06 Thread hadley wickham
On Mon, Apr 6, 2009 at 9:34 AM, Stavros Macrakis  wrote:
> There are various ways to do this in R.
>
> # sample data
> dd <- data.frame(a=1:10,b=sample(3,10,replace=T),c=sample(3,10,replace=T))
>
> Using the standard built-in functions, you can use:
>
> *** aggregate ***
>
> aggregate(dd,list(b=dd$b,c=dd$c),sum)
>  b c  a b c
> 1 1 1 10 2 2
> 2 2 1  3 2 1
> 
>
> *** tapply ***
>
> tapply(dd$a,interaction(dd$b,dd$c),sum)
>      1.1       2.1       3.1       1.2       2.2       3.2       1.3
> 2.3
>  5.00  3.00 10.00  5.00        NA        NA  5.00
> ...
>
> But the nicest way is probably to use the plyr package:
>
>> library(plyr)
>> ddply(dd,~b+c,sum)
>  b c V1
> 1 1 1 14
> 2 2 1  6
> 
>
> 
>
> Unfortunately, none of these approaches allows you do return more than one
> result from the function, so you'll need to write
>
>> ddply(dd,~b+c,length)   # count
>> ddply(dd,~b+c,sum)
>> ddply(dd,~b+c,mean)   # arithmetic average
>
> There is an 'each' function in plyr, but it doesn't seem to be compatible
> with ddply.

That's because ddply applies the function to the whole data frame, not
just the columns that aren't participating in the split.  One way
around it is:

ddply(dd, ~ b + c, function(df) each(length, sum, mean)(df$a))

I haven't figured out a more elegant way to specify this yet.

Hadley

-- 
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] number of zeros in a matrix -row by row

2009-04-06 Thread onyourmark

oh boy, what a mistake. Ok, I will try that and look up what it means
afterward.
Thank you.

MUHC-Research wrote:
> 
> Hi,
> 
> Try
> 
> /rowSums(M==0)/
> 
> This should work just fine.
> 
> Cheers,
> 
> Luc
> 
> onyourmark wrote:
>> Hi. I have an n x m matrix M some of who's entries are zeros. I want to
>> know
>> how many zeros there are in each row-perhaps stored in a 1 x n vector
>> which lists the number of zeros for each row of M.
>>
>> Before I had a vector V and I was able to get the number of zeros in V by
>> doing length(V[ V==0]) but when I try something similar for M, like M[
>> M==0]
>> it creates a vector not a matrix and so this does not work. Does anyone
>> have
>> a solution to this?
>>
>> Thank you.
>>
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/number-of-zeros-in-a-matrix--row-by-row-tp22893147p22909577.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] SUM,COUNT,AVG

2009-04-06 Thread Karl Ove Hufthammer
calpeda:

> I need for each (Materiale, tpdv, UM) to find sum,avg and count
> My idea was to aggregate for the 3 parameters ..but I don t know how to
> get the numeric value (SUM,COUNT,AVG) I need.

If I have understood what you’re trying to accomplish, this should work:

$ library(Hmisc)
$ d=read.table("http://www.nabble.com/file/p22905322/ordini2008_ex.txt";)
$ sumfun=function(x) c(sum=sum(x), count=length(x), avg=mean(x))
$ with(d, summarize(qta, Materiale, sumfun, stat.name=NULL))
  Materiale sum count  avg
1  1400185   10 1 10,0
2  16006082 1  2,0
3  30100301 1  1,0
4  41SD0803 3  1,0
5  44029742 1  2,0
6  63210003 3  1,0
7  604017210001 1  1,0
8  609007610002 1  2,0
9  70020032 2  1,0
10 70310012 2  1,0
11 707300400183 2  1,5
12 717100400141 1  1,0

-- 
Karl Ove Hufthammer

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

2009-04-06 Thread Terry Therneau
Laura Bonnett was kind enough to send me a copy of the data that caused the 
plotting error, since it was an error I had not seen before.

1. The latest version of survival gives a nicer error message:
 
> fit <- coxph(Surv(rem.Remtime, rem.Rcens) ~ all.sex, nearma)
> cfit <- cox.zph(fit)
> plot(cfit)
Error in plot.cox.zph(cfit) : 
   Spline fit is singular, try a smaller degrees of freedom

2. What's the problem?
  There are 1085 events in the data set (rem.Rcens==1), and of these 502 are 
tied events on exactly day 365.  The plot.cox.zph function tries to fit a 
smoothing spline to the data to help the eye; the fit gives weight 1 to each 
death and having this high a proportion of ties creates problems for the 
underlying regression.
  
3. 
> plot(cfit, df=2)
  Warning messages:
1: In approx(xx, xtime, seq(min(xx), max(xx), length = 17)[2 * (1:8)]) :
  collapsing to unique 'x' values
2: In approx(xtime, xx, temp) : collapsing to unique 'x' values

  These warning messages are ignorable.  I'll work on making them go away.


4. A shot in the dark -- is perchance the variable rem.Rcens=1 a marker of a 
censored observation, and the events are 0?  (A whole lot of events at 1 year 
is 
suspicious, but half censored at one year is believable.) Then the proper coxph 
code is

> fit2 <-  coxph(Surv(rem.Remtime, rem.Rcens==0) ~ all.sex, nearma)

Terry Therneau

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

2009-04-06 Thread Martin Maechler
> "LV" == Luc Villandre 
> on Mon, 06 Apr 2009 10:42:34 -0400 writes:

LV> Hi,
LV> Pretty hard to say. It really depends on what you want to.

LV> MASS, nlme, lme4 and Hmisc are packages I use on a daily basis.

Note that MASS is part of the VR bundle, and that and nlme are
already formally 'Recommended' and hence part of every R installation.

The same applies to  'boot'  as David (below) recommends
"a bootstrap package".


LV> I guess you could also ask for those.

LV> David Scott wrote:
>> On Wed, 1 Apr 2009, Eamonn O'Brien wrote:
>> 
>>> The company I work for require users to request what packages they 
>>> want from
>>> the IT department (user cannot download themselves). I intend to request
>>> installation of the latest version of R plus the 23 Cran task views. 
>>> As a
>>> statistician what are the recommended packages or packages that
>>> statisticians using R recommend to install. I have started a new 
>>> position
>>> and want to (greedily) get everything that I may or may not use as I 
>>> want to
>>> avoid multiple requests to our IT dept.
>>> Thanks
>>> 
>> 
>> 
>> I haven't seen a response, so I will make a start.
>> 
>> It all depends on the area you are in, and the sort of work you do. If 
>> you are in finance, you will likely require different packages than if 
>> you are in biostat or whatever. There are no clues in your email, not 
>> even an informative address or signature.
>> 
>> There are a few general packages that you might consider though: Frank 
>> Harrell's packages; ggplot2 for graphics; a bootstrap package; 
>> depending on the users maybe a gui package such as Rcmdr ...
>> There are around 2000 packages now I believe.
>> 
>> 
>> David Scott 
>> _
>> David ScottDepartment of Statistics
>> The University of Auckland, PB 92019
>> Auckland 1142,NEW ZEALAND
>> Phone: +64 9 373 7599 ext 85055Fax: +64 9 373 7018
>> Email:d.sc...@auckland.ac.nz
>> 
>> Graduate Officer, Department of Statistics
>> Director of Consulting, Department of Statistics
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide 
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

LV> __
LV> R-help@r-project.org mailing list
LV> https://stat.ethz.ch/mailman/listinfo/r-help
LV> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
LV> 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] Collapse data matrix with extra info separated by commas

2009-04-06 Thread baptiste auguie
Here's one attempt with plyr, hopefully Hadley will give you a better  
solution ( I could not get cast() to do it either)


test <-  
data 
.frame 
(a=c("A","A","A","A","B","B","B"),b=c(1,1,2,2,1,1,1),c=sample(1:7))

ddply(test,.(a,b),.fun=function(.) paste(.)[3])

  a b V1
1 A 1c(2, 4)
2 B 1 c(7, 1, 6)
3 A 2c(3, 5)

# note that with your example R seems to use some magic

test <-

data.frame(a=c("A","A","A","A","B","B","B"),b=c(1,1,2,2,1,1,1),c=1:7)



  a b  V1
1 A 1 1:2
2 B 1 5:7
3 A 2 3:4

I have no idea how this happens!


HTH,

baptiste



On 6 Apr 2009, at 15:38, Daniel Brewer wrote:


Hello,

I would like to reshape my data for presentation purposes from  
something

like this:

test <-

data.frame(a=c("A","A","A","A","B","B","B"),b=c(1,1,2,2,1,1,1),c=1:7)

test

 a b c
1 A 1 1
2 A 1 2
3 A 2 3
4 A 2 4
5 B 1 5
6 B 1 6
7 B 1 7

to something like this:
 a b c
1 A 1 1,2
3 A 2 3,4
5 B 1 5,6,7

This seems to be the sort of the thing that the reshape library should
be able to do, but I just can't work out how to do it.

Many thanks

Dan

--
**
Daniel Brewer, Ph.D.

Institute of Cancer Research
Molecular Carcinogenesis
Email: daniel.bre...@icr.ac.uk
**

The Institute of Cancer Research: Royal Cancer Hospital, a  
charitable Company Limited by Guarantee, Registered in England under  
Company No. 534147 with its Registered Office at 123 Old Brompton  
Road, London SW7 3RP.


This e-mail message is confidential and for use by the...{{dropped:26}}


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

2009-04-06 Thread Irene Schreiber
Hello,

 

Does anyone know about an R-package on multivariate ARMA-GARCH models? Or in
Matlab?

 

I would be very grateful if someone could help!

Thanks a lot!

 

 


[[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] R package: Where to put code to Run Once Only?

2009-04-06 Thread Martin Morgan
Hi Ken --

Ken-JP wrote:
> 
> Is there a specific place where we can place code to run once only in a
> package?
> 
> I have code that switches based on Sys.info()[["nodename"]] - but since this
> just about never changes, I would like to run it only once when someone
> runs:
> 
> require( mypackage ) or library( vte )
> 
> I'm tempted to have some free-floating code in global space (in one of my
> package's .R files), but it just seems so wrong/hacky to do it this way.
> 
> Where is the proper place to put this code?

in a function named .onLoad (or, rarely, .onAttach) when your package
has a name space, or .First.lib when it does not. See the help pages for
each.

Martin

> - Ken
> 
> 
>

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

2009-04-06 Thread bruno joly

Hi everyone,

I am new to the list.
My problem is to change the color of the label in a contour plot. The 
plot is quite dark and I'd like to have the line and label white, it 
works for the line with a simple "col", but for the labels I need to 
pass throught a panel call and :


> contourplot(Prob ~ D.CSW * 
D.CS,data=grid,region=TRUE,col="white",panel=function(x,y,z,...){panel.contourplot(...,labels=list(col="white"),...)})


give me the answer "the argument 'label' may correspond to other 
variables" (I translate the error message from my  french version)


Thanks in advance for any help

--
-
Bruno JOLY

Météo-France 
CNRM/GMAP/RECYF

42, avenue G. Coriolis
31057 Toulouse, France

Tél: (33) (0)5 61 07 99 09
Fax: (33) (0)5 61 07 84 53
email:bruno.j...@meteo.fr

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Collapse data matrix with extra info separated by commas

2009-04-06 Thread jim holtman
try this:

> x <- lapply(split(test, list(test$a, test$b), drop=TRUE), function(.data){
+ data.frame(a=.data$a[1], b=.data$b[1], c=paste(.data$c, collapse=','))
+ })
> do.call(rbind, x)
a b c
A.1 A 1   1,2
B.1 B 1 5,6,7
A.2 A 2   3,4
>


On Mon, Apr 6, 2009 at 10:38 AM, Daniel Brewer  wrote:
> Hello,
>
> I would like to reshape my data for presentation purposes from something
> like this:
>> test <-
> data.frame(a=c("A","A","A","A","B","B","B"),b=c(1,1,2,2,1,1,1),c=1:7)
>> test
>  a b c
> 1 A 1 1
> 2 A 1 2
> 3 A 2 3
> 4 A 2 4
> 5 B 1 5
> 6 B 1 6
> 7 B 1 7
>
> to something like this:
>  a b c
> 1 A 1 1,2
> 3 A 2 3,4
> 5 B 1 5,6,7
>
> This seems to be the sort of the thing that the reshape library should
> be able to do, but I just can't work out how to do it.
>
> Many thanks
>
> Dan
>
> --
> **
> Daniel Brewer, Ph.D.
>
> Institute of Cancer Research
> Molecular Carcinogenesis
> Email: daniel.bre...@icr.ac.uk
> **
>
> The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company 
> Limited by Guarantee, Registered in England under Company No. 534147 with its 
> Registered Office at 123 Old Brompton Road, London SW7 3RP.
>
> This e-mail message is confidential and for use by the...{{dropped:19}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 find the cost relationship with a few factors and a few numeric sizes?

2009-04-06 Thread guox
I have a small data set (see attachment valve.txt or valve.csv), in which
there are a few facors: Type, ValveBody,Manufacturer
and a few numeric sizes: FlangeSize, Port.Size, Pressure and Cost.

I would like to find a statistics model that shows how Cost is related to
these factors and numeric sizes.
It seems to me that it is hard to find the relationship between Cost and a
few factors using regression models.

Could you please direct me on how to approach it? Thanks,

-james

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

2009-04-06 Thread Mohammad Sabr
Hi Jim,

In fact I faced this message when I installed several other packages but I 
didn't face any problem loading them except the Dynamo-Package. I tried to 
install it on an another computer and I faced the same problem, the package 
failed to load.

Any help will be appreciated.

Mohammad





From: Jim Lemon 

Sent: Monday, April 6, 2009 5:31:44 AM
Subject: Re: [R] Problem with Dynamo-Package

Mohammad Sabr wrote:
> Good day,
>
> I am facing a problem when I am installing the dynamo-package and loading it. 
> After I installed the package, I received the following warning message:
> "In file.create(f.tg) :
>  cannot create file 'C:\PROGRA~2\R\R-28~1.1/doc/html/packages.html', reason 
>'Permission denied'"
>
> and when I load the package, an error message pops up saying that "the 
> application failed to start because libgsl.dll was not found. Re-installing 
> the application may fix the problem" 
>
>  
Hi Mohammad,
Seems like you need administrator privileges to install the package.
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] Maintain proportions while reducing graphic output size

2009-04-06 Thread Glen Sargeant



lawnboy34 wrote:
> 
> Hello,
> 
> Is there a combination of par() settings or other commands that will allow
> me to uniformly reduce the size of graphics outputs? It appears that the
> png() device outputs 5-inch by 5-inch  images, and I am trying to change
> my
> whole script to produce 4x4 images with the same proportions. I tried
> specifying parameters within each png(), but it reduced the size of the
> file
> without refitting the contents so the graph title went off the margin.
> This
> is an example of the code I used:
> 
> png("graph2.png",height=432, width=432, units="px", res=96)
> 
> What would be the best way to generate 4x4, proportional graphs?
> 
> Thanks!
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

See the helpfile for png().

If you change the width and height of your output, you should rescale the
pointsize of plotted text accordingly.  For example: 

#Without rescaling pointsize for text
png("temp1.png",width=200,height=200)
plot(rnorm(100),rnorm(100),main="A title of some sort")
dev.off()

#With pointsize for text rescaled
png("temp2.png",width=200,height=200, pointsize=6)
plot(rnorm(100),rnorm(100),main="A title of some sort")
dev.off()
-- 
View this message in context: 
http://www.nabble.com/Maintain-proportions-while-reducing-graphic-output-size-tp22909007p22913130.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] enscript states file for R scripts?

2009-04-06 Thread Thomas Liebig

Hi,

enclosed is an enscript states file for R scripts.

regards,
Thomas

Peter Dalgaard schrieb:

Dirk Eddelbuettel wrote:

On 15 July 2008 at 17:23, hadley wickham wrote:
| An alternative to enscript is highlight,
| http://www.andre-simon.de/doku/highlight/en/highlight.html, which does
| come with R highlighting built in.

Another alternative is GNU a2ps which has definitions for R source,
documentation and transcripts.  As it says the bottom of the page at
http://cran.r-project.org/other-software.html (with links)

   GNU a2ps is a fairly versatile text-to-anything processor, 
useful for

   typsetting source code from a wide variety of programming
   languages. s.ssh, rd.ssh and st.ssh are a2ps style sheets for S 
code,
   Rd documentation format, and S transscripts, respectively. 
(These will

   be included in the next a2ps release.)

and indeed, these files have been part of a2ps' upstream releases for 
a long time.


Dirk
  
Unfortunately, a2ps doesn't support Unicode (and afaics u2ps does not do 
indentation...).


--
Thomas Liebig
Fraunhofer-Institut für Intelligente Analyse- und
Informationssysteme (IAIS)

Schloss Birlinghoven, D-53754 Sankt Augustin, Germany
Email:  thomas.lie...@iais.fraunhofer.de
Phone:  +49 2241 142050
Fax:+49 2241 142072

/**
 * Name: r
 * Description: CRAN-R programming language.
 * Author: Thomas Liebig 
 */

state r extends HighlightEntry
{
  /* Comments. */
  /#/ {
comment_face (true);
language_print ($0);
call (eat_one_line);
comment_face (false);
  }

  /* String constants. */
  /\"/ {
string_face (true);
language_print ($0);
call (c_string);
string_face (false);
  }

  /* Keywords. */
  
/\b(break|next|re(turn|peat)|i(n|f)|else|for|requires|while|LETTERS|l(ibrary|etters)|pi|NULL|FALSE|TRUE|NULL|NA)\b/
 {
keyword_face (true);
language_print ($0);
keyword_face (false);
  }

  /* Types. */
  
/\b(character|rType|array|complex|double|function|integer|list|logical|matrix|numeric|vector|data.frame)\b/
 {
type_face (true);
language_print ($0);
type_face (false);
  }

  /* Delimiter. */
  /(,|;|:|\(|\))/ {
keyword_face (true);
language_print ($0);
keyword_face (false);
  }

}


/*
Local variables:
mode: c
End:
*/
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 sort and plot data?

2009-04-06 Thread Jun Shen
Hema,

This may work:
aggregate(hema[1],hema[2],function(x)length(unique(x))) to calculate how
many different websites each id visited. hema[1] is the website column,
hema[2] is user_id. You can always add more index columns like days to
aggregate().

Jun

On Thu, Apr 2, 2009 at 11:06 PM, Hemavathi Ramulu wrote:

> hi,
> Previously my email very simple and less information. Let say I have raw
> data as below:-
>
> user_id  website  time
> 20google0930
> 21yahoo0935
> 20facebook1000
> 25facebook1015
> 61google0940
> 60yahoo1050
> 40friendster1115
> 61google1200
> 40friendster1215
> 25google1030
> 28youtube  0830
> 30facebook0945
>
> This data described about particular website viewed by particular ID  in
> one
> day.
>
> My problem is how to sort the data? So that, I can get information about
> one
> user_id viewed how many website perday?
>
> secondly, I want to plotted above data where x-axis (user_id) and
> y-axis(website).
>
> Actually, im new to R-project and still in learning process. So, I really
> want you all help.
> Thank you and I really appreciate everyone feedback.
>
> regards,
> Hema.
>
>[[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.
>



-- 
Jun Shen PhD
PK/PD Scientist
BioPharma Services
Millipore Corporation
15 Research Park Dr.
St Charles, MO 63304
Direct: 636-720-1589

[[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] Boxplots in Barplots

2009-04-06 Thread Greg Snow
Well, the symbols function will add boxplots to an existing plot wherever you 
want.  But, you should really consider what question(s) your are trying to 
answer.  As a general rule, adding things to a barplot will do more to distort 
the barplot than add additional information.  If the boxplot contains the info 
you need, why even use the barplot?  If you need the barplot, why add to it?  
Maybe a different plot would better be able to answer the question(s) of 
interest, but you need to be clear (at least to yourself) what the question(s) 
is/are.

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


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of johnhj
> Sent: Monday, April 06, 2009 5:46 AM
> To: r-help@r-project.org
> Subject: [R] Boxplots in Barplots
> 
> 
> Hii,
> 
> Is it possible to put Boxplots at the top of the Barplots ? I will
> describe
> the standard derivation with a Boxplot at the of the Barplots. It could
> also
> be "line" instead of Boxplot...
> 
> Can anybody help me how to do it ?
> 
> greetings,
> j.
> --
> View this message in context: http://www.nabble.com/Boxplots-in-
> Barplots-tp22907174p22907174.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] How to find the cost relationship with a few factors and a few numeric sizes? (Resending with datasets)

2009-04-06 Thread guox
I have a small data set (see attachment valve.txt or valve.csv), in which
there are a few facors: Type, ValveBody,Manufacturer
and a few numeric sizes: FlangeSize, Port.Size, Pressure and Cost.

I would like to find a statistics model that shows how Cost is related to
these factors and numeric sizes.
It seems to me that it is hard to find the relationship between Cost and a
few factors using regression models.

Could you please direct me on how to approach it? Thanks,

-james
DateTypeValveBody   ManufacturerFlangeSize  Port.Size   
PressureFaceTypeCost
8/30/2005   Pipeline Protection System  BallBettis  4   4   
600 RF  11206.3
8/30/2005   Pipeline Protection System  BallBettis  2   2   
1500RF  10480.89
1/20/2006   Pipeline Protection System  BallBettis  4   4   
600 RF  10335.56
1/20/2006   Pipeline Protection System  BallBettis  2   2   
600 RF  7988.56
11/16/2005  Pipeline Protection System  BallBettis  2   2   
900 RTJ 4406.06
12/22/2005  On/Off ValveBallEl-o-Matic  2   2   1500
RTJ 5325
12/9/2005   Pipeline Protection System  BallEl-o-Matic  2   
2   1500RTJ 6416.81
11/17/2005  On/Off ValveBallEl-o-Matic  4   3   600 
RF  6222
2/15/2006   Pipeline Protection System  BallCameron 6   NA  
600 RF  14465
12/13/2005  Pipeline Protection System  BallCameron 6   NA  
600 RF  14900
10/25/2005  Control Valve   Globe   Fisher  2   NA  600 RF  
3675.5
11/16/2005  Control Valve   unsure  Fisher  2   NA  600 RF  
5316.48
12/9/2005   Control Valve   unsure  Fisher  2   NA  600 RF  
4935.87
11/29/2005  On/Off ValveBallCameron 6   NA  600 RF  
14900
11/21/2005  On/Off ValveBallBettis  2   2   300 RF  
4762
11/21/2005  Pipeline Protection System  BallBettis  2   2   
300 RF  6391.85
11/23/2005  Control Valve   Globe   Fisher  2   NA  150 RF  
3713.46
12/22/2005  Control Valve   unsure  Fisher  2   NA  600 RF  
5077.78
6/21/2007   Control Valve   Globe   Fisher  2   NA  300 
3950
1/13/2006   On/Off ValveBallBettis  2   2   600 RF  
4352.91
1/13/2006   On/Off ValveBallBettis  2   2   600 RF  
5905
1/13/2006   On/Off ValveBallBettis  4   4   600 RF  
6073.07
1/13/2006   On/Off ValveBallBettis  4   4   600 RF  
8571
2/1/2007On/Off ValveBallBettis  6   6   600 RF  
13816.34
2/1/2007On/Off ValveBallBettis  8   8   600 RF  
18335.5
2/1/2007On/Off ValveBallBettis  10  10  600 RF  
25080.34
12/1/2006   On/Off ValveBallBettis  2   2   600 RF  
3670.44
12/1/2006   On/Off ValveBallBettis  4   4   600 RF  
4805.67
11/21/2005  On/Off ValveBallEl-o-Matic  4   NA  600 
RF  6222
11/18/2005  Control Valve   unsure  Fisher  2   NA  600 RF  
5316.48
11/18/2005  Pipeline Protection System  BallEl-o-Matic  2   
NA  900 RTJ 6005.7
11/25/2005  Pipeline Protection System  BallBettis  2   NA  
300 RF  6391.85
11/25/2005  Pipeline Protection System  BallBettis  2   NA  
300 RF  6391.85
10/12/2005  Pipeline Protection System  BallEl-o-Matic  2   
NA  900 RTJ 7669
10/5/2005   Control Valve   Globe   Fisher  2   NA  600 RF  
3675.2
8/23/2005   On/Off ValveBallBettis  4   4   600 RF  
8033
8/23/2005   On/Off ValveBallBettis  2   2   600 RF  
5323
8/23/2005   On/Off ValveBallBettis  2   2   1500RF  
7347
9/15/2005   Control Valve   Globe   Fisher  2   NA  1500RTJ 
4161.8
4/21/2005   Pipeline Protection System  BallBettis  4   4   
600 RF  9754
3/21/2005   Pipeline Protection System  BallBettis  2   2   
1500RF  9902
3/22/2005   Pipeline Protection System  BallBettis  2   2   
900 RF  8827
3/7/2005Pipeline Protection System  BallBettis  6   6   
600 RF  15446
7/7/2004Control Valve   Globe   Fisher  1   NA  NA  
530
6/9/2004Control Valve   unsure  Fisher  8   NA  600 RF  
19321.43
7/8/2004Control Valve   Globe   Fisher  2   NA  600 RF  
1833.33
6/11/2004   On/Off ValveBall   

Re: [R] R package: Where to put code to Run Once Only?

2009-04-06 Thread Dieter Menne
Uwe Ligges  statistik.tu-dortmund.de> writes:

> That fine, in principle, convention is to have code in zzz.R, see 
> Writing R Extzensions.

Finally I got it, zzz comes from Extzensions. In the fields I normally work in,
zzz mean the LAST thing to do before going to sleep or to crash the system.

Dieter

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


[R] Problem with Extracting Fitted Values from fGarch package

2009-04-06 Thread Mohammad Sabr
Good day everyone,

I fitted a GARCH model to a time series and R estimated the model and provide 
me with the estimates. However, when I tried to extract the fitted values from 
the estimated model I got the following error message:

"Error in .local(object, ...) : object "fit" not found"
 
I used the following to extract the fitted values 

fitted_TASI <- fitted(garchFit(~ garch(1,1), residuals_TASI, trace = TRUE, 
include.mean = FALSE))
 
Can someone please advice me with the reason that I am getting this error 
message.
 
Best regards,
 
Mohammad

[[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] nlme weighted

2009-04-06 Thread Dieter Menne
Mollet, Fabian  wur.nl> writes:

> I'm fitting a non linear model (energy allocation model to individual
> growth data) using your nlme routine. For each individual I have thus a
> number of observations (age and size) to which I fit the nonlinear
> function, with random effects for the individuals on the estimated
> parameters (individual as the grouping factor). The sampling of these
...
> I think what I need is something that multiplies these weights to the
> residual variance. My first hint would be something as it is described
> by the function varIdent or varFixed, but it is not quite clear to me
> what is being done by these (e.g. what is meant by variance covariate
> etc.?).

In most other R regression packages, most notably lm, weights works 
the way you think it should, but the philosophy is different in lme, 
where a function is executed to compute weights, for example to 
handle heteroscedasticity.

I found this strange in the beginning, but as often Douglas Bates has 
a hidden agenda telling his users: don't do that. Don't average first 
and it later, use the raw data instead, and all the weights will be 
correct. And use the liberated parameter for more important things.

Dieter

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] dput and getOptions('width')

2009-04-06 Thread Stavros Macrakis
dput appears to ignore the value of getOptions('width')

Is there some other way to control the line width it uses? or to get it to
observe getOptions('width')?

If I wanted infinite line width, I could send the output to a textConnection
and paste the pieces together, but putting line breaks back in correctly
would require re-parsing the output(!).

-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] Collapse data matrix with extra info separated by commas

2009-04-06 Thread hadley wickham
On Mon, Apr 6, 2009 at 10:40 AM, baptiste auguie  wrote:
> Here's one attempt with plyr, hopefully Hadley will give you a better
> solution ( I could not get cast() to do it either)
>
> test <-
> data.frame(a=c("A","A","A","A","B","B","B"),b=c(1,1,2,2,1,1,1),c=sample(1:7))
> ddply(test,.(a,b),.fun=function(.) paste(.)[3])

This is a problem that currently isn't very easy to solve in plyr (but
I'm working on it).  About the best you can do is:

ddply(test, ~ a + b, colwise(paste, .(c)), collapse =",")

(this is basically equivalent to your suggestion)

Hadley


-- 
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] SUM,COUNT,AVG

2009-04-06 Thread Christian

A good package for this sort of questions is doBy, too.

library(doBy)
summaryBy( tpdv + UM + qta ~ Materiale ,data=data,FUN=c(sum,length,mean))

regards, Christian


Hi,
I ve been searching a lot in internet..but I can t find a solution
Attached, you find a file.
I need for each (Materiale, tpdv, UM) to find sum,avg and count
My idea was to aggregate for the 3 parameters ..but I don t know how to get
the numeric value (SUM,COUNT,AVG) I need.
Can you help me?
thank you

http://www.nabble.com/file/p22905322/ordini2008_ex.txt ordini2008_ex.txt 



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 subsample all possible combinations of n species taken 1:n at a time?

2009-04-06 Thread jasper slingsby

Hello

I apologise for the length of this entry but please bear with me.

In short:
I need a way of subsampling communities from all possible communities of n
taxa taken 1:n at a time without having to calculate all possible
combinations (because this gives me a memory error - using 
combn() or expand.grid() at least). Does anyone know of a function? Or can
you help me edit the 
combn
or 
expand.grid 
functions to generate subsamples?

In long:
I have been creating all possible communities of n taxa taken 1:n at a time
to get a presence/absence matrix of species occurrence in communities as
below...

Rows are samples, columns are species:

ABC   D . ...
101110001 1 1 1 0 0
0 0
011110001 1 1 1 0 0
0 0
111110001 1 1 1 0 0
0 0
000001001 1 1 1 0 0
0 0
100001001 1 1 1 0 0
0 0
010001001 1 1 1 0 0
0 0
110001001 1 1 1 0 0
0 0
001001001 1 1 1 0 0
0 0

...but the number of possible communities increases exponentially with each
added taxon. 

n<-11 #number of taxa
sum(for (i in 0:n) choose(i, k = 0:i)) #number of combos

So all possible combinations of 11 taxa taken 1:11 at a time is 2048, all
combos of 12 taken 1:12 is 4096, 13 taken 1:13 = 8192...etc etc such that
when I reach about 25 taken 1:25 the number of combos is 33554432 and I get
a memory error.

I have found that the number of combos of x taxa taken from a pool of n
creates a very kurtotic unimodal distribution,... 

x<-vector("integer",20)
for (i in 1:20) {x[i]<-choose(20,i)}
plot(x)

...but have found that limiting the number of samples for any community size
to 1000 is good enough for the further analyses I wish to do.
My problem lies in sampling all possible combos without having to calculate
all possible combos. I have tried two methods but both give memory errors at
about 25 taxa.

The expand.grid() method:

n <- 11 
toto <- vector("list",n)
titi <- lapply(toto,function(x) c(0,1))
tutu <- expand.grid(titi)

The combn() method (a slightly lengthlier function):

samplecommunityD<- function(n,numsamples)
{
super<-mat.or.vec(,n)
for (numspploop in 1:n)
{
  minor<-t(combn(n,numspploop))
  if (dim(minor)[1]n-1&!rowSums(super)<2,]
return(super)
}

samplecommunityD(11,1000)


So unless anyone knows of another function I could try my next step would be
to modify the combn or expand.grid functions to generate subsamples, but
their coding beyond me at this stage (I'm a 3.5 month newbie). Can anyone
identify where in the code I would need to introduce a sampling term or
skipping sequence?

Thanks for your time
Jasper

-- 
View this message in context: 
http://www.nabble.com/how-to-subsample-all-possible-combinations-of-n-species-taken-1%3An-at-a-time--tp22911399p22911399.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] contourplot label color

2009-04-06 Thread Deepayan Sarkar
On Mon, Apr 6, 2009 at 9:00 AM, bruno joly  wrote:
> Hi everyone,
>
> I am new to the list.
> My problem is to change the color of the label in a contour plot. The plot
> is quite dark and I'd like to have the line and label white, it works for
> the line with a simple "col", but for the labels I need to pass throught a
> panel call and :
>
>> contourplot(Prob ~ D.CSW *
>> D.CS,data=grid,region=TRUE,col="white",panel=function(x,y,z,...){panel.contourplot(...,labels=list(col="white"),...)})
>
> give me the answer "the argument 'label' may correspond to other variables"
> (I translate the error message from my  french version)

You don't need a panel function; just use

 contourplot(Prob ~ D.CSW * D.CS,data=grid,region=TRUE,
 col="white",labels=list(labels = TRUE, col="white"))

(the documentation suggests that the 'labels=TRUE' is unnecessary, but
that is not so).

-Deepayan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 package: Where to put code to Run Once Only?

2009-04-06 Thread Uwe Ligges



Dieter Menne wrote:

Uwe Ligges  statistik.tu-dortmund.de> writes:

That fine, in principle, convention is to have code in zzz.R, see 
Writing R Extzensions.


Finally I got it, zzz comes from Extzensions. In the fields I normally work in,
zzz mean the LAST thing to do before going to sleep or to crash the system.


Dieter,

in fact the code in zzz.R is processed if zzz.R will be processed 
according to sorting in a C locale. But since all other code regularly 
consists of function definition or definition of methods and therelike, 
the ordering is irrelevant (and if your code to be processed dierectly 
depends on functions defined in your package, then it becomes relevant 
not to happen in the very beginning.


Best,
Uwe




Dieter

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Bonpower Crashes Trying Sparse Matrix (Igraph)

2009-04-06 Thread Surendar Swaminathan
Hello All,

I have been trying to do bonpow for a while now.Bonpow works for few graphs
and for few others it goes out of memory.

I did see reply to one of the posting Alph Centrality Crashed in Igraph
memory error.

The solution in the posting was to use sparse matrix. This is the link of
the message.

http://lists.gnu.org/archive/html/igraph-help/2008-04/msg00071.html
I was able to obtain edgelist for the graph and I do not know how to convert
that to sparse matrix and obtain bonpow.
Can someone help me.
 This is what I tried

Summary(g)

Vertices: 8047
Edges: 99060
Directed: FALSE
No graph attributes.
Vertex attributes: name.
No edge attributes.
I use get.adjacency( graph,Sparse=TR

UE) to obtain the sparse matrix.Converted the sparse matrix to graph and fed
the graph object to bonpow.
Can someone help me with this.I know I am making a big mistake but I do not
know how to solve them.

Please find the attached graph object along with this mail.

Nathan.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Need help in calculating studentized residuals/leverage values of non-linear model [nls()]

2009-04-06 Thread rkevinburton
Is the output of residuals() the studentized residuals or just the residuals?

 Dieter Menne  wrote: 
> Giam Xingli  nus.edu.sg> writes:
> 
> >I hope I can get advice regarding the calculation of leverage values or
> >studentized residual values of a non-linear regression model. It seems 
> > like
> >rstudent() does not work on a nls object.
> 
> residuals() should work for nls.
> 
> Dieter
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] "bucketing" observations

2009-04-06 Thread Dan Dube
is there a better way to bucket observations into more-or-less evenly
sized buckets than this?  it seems like this must be a common operation:

dt = data.frame(points=rnorm(1000),bucket=NA)

breaks = quantile(dt$points,seq(0:1,.1))
for (i in 2:length(breaks)) {
if (i == 2) {
ind = which(dt$points >= breaks[i-1] & dt$points <=
breaks[i])
} else {
ind = which(dt$points > breaks[i-1] & dt$points <=
breaks[i])
}
dt$bucket[ind] = i-1
}

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] "bucketing" observations

2009-04-06 Thread Bert Gunter
?cut
?quantile (perhaps, to define the breaks) 


Bert Gunter
Genentech Nonclinical Biostatistics
650-467-7374

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Dan Dube
Sent: Monday, April 06, 2009 12:45 PM
To: r-help@r-project.org
Subject: [R] "bucketing" observations

is there a better way to bucket observations into more-or-less evenly
sized buckets than this?  it seems like this must be a common operation:

dt = data.frame(points=rnorm(1000),bucket=NA)

breaks = quantile(dt$points,seq(0:1,.1))
for (i in 2:length(breaks)) {
if (i == 2) {
ind = which(dt$points >= breaks[i-1] & dt$points <=
breaks[i])
} else {
ind = which(dt$points > breaks[i-1] & dt$points <=
breaks[i])
}
dt$bucket[ind] = i-1
}

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.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 subsample all possible combinations of n species taken 1:n at a time?

2009-04-06 Thread jim holtman
Are you just trying to obtain a combination from 25 possible terms?
If so, then just sample the number you want and convert the number to
binary:

> sample(33554432,100)
  [1]  6911360  5924262 23052661 12888381 25831589 16700013 24079278
33282839 12751862 26086726 31363494  7118320 21866536  4212929
 [15]  8966435 12955834   449305 12830805 29181967 11420211 16175915
20118079 16560488  6248422 27762022 22430005 26650247  3621985
 [29] 24283690 13800068 27546362 21711718 26270840 18556802 17774422
26486373   782865 16013167 24572344 23244187 16026237 28897360
 [43] 14700082  8214024  2371593  3337527 10612303 17402454 22213173
13650936 30630988  9851680 15403666 11153297 21839554  8657593
 [57] 16057288 25713076  2826853 29370859 11377380 28166893 11632747
11199608 15983665 29937151 29002363 13085852 26082502 32232925
 [71] 14584722 23907975 13421556 10916983 25403574  6801209 23861215
4083294  8237209  4808486  8040610  1977505 21551566 29402643
 [85] 26135975 26753178 15276437 13760103 27208220 20298140 21968831
11851302  9068401 33308858 21256448  7154058  4341004 16042933
 [99] 31006704 20091025

This is a 100 samples and you can convert each of the numbers to
binary and the bits will tell you might elements to combine.

On Mon, Apr 6, 2009 at 11:39 AM, jasper slingsby  wrote:
>
> Hello
>
> I apologise for the length of this entry but please bear with me.
>
> In short:
> I need a way of subsampling communities from all possible communities of n
> taxa taken 1:n at a time without having to calculate all possible
> combinations (because this gives me a memory error - using
> combn() or expand.grid() at least). Does anyone know of a function? Or can
> you help me edit the
> combn
> or
> expand.grid
> functions to generate subsamples?
>
> In long:
> I have been creating all possible communities of n taxa taken 1:n at a time
> to get a presence/absence matrix of species occurrence in communities as
> below...
>
> Rows are samples, columns are species:
>
>    A    B    C   D     .     .    .    .
>    1    0    1    1    1    0    0    0    1     1     1     1     0     0
> 0     0
>    0    1    1    1    1    0    0    0    1     1     1     1     0     0
> 0     0
>    1    1    1    1    1    0    0    0    1     1     1     1     0     0
> 0     0
>    0    0    0    0    0    1    0    0    1     1     1     1     0     0
> 0     0
>    1    0    0    0    0    1    0    0    1     1     1     1     0     0
> 0     0
>    0    1    0    0    0    1    0    0    1     1     1     1     0     0
> 0     0
>    1    1    0    0    0    1    0    0    1     1     1     1     0     0
> 0     0
>    0    0    1    0    0    1    0    0    1     1     1     1     0     0
> 0     0
>
> ...but the number of possible communities increases exponentially with each
> added taxon.
>
> n<-11     #number of taxa
> sum(for (i in 0:n) choose(i, k = 0:i)) #number of combos
>
> So all possible combinations of 11 taxa taken 1:11 at a time is 2048, all
> combos of 12 taken 1:12 is 4096, 13 taken 1:13 = 8192...etc etc such that
> when I reach about 25 taken 1:25 the number of combos is 33554432 and I get
> a memory error.
>
> I have found that the number of combos of x taxa taken from a pool of n
> creates a very kurtotic unimodal distribution,...
>
> x<-vector("integer",20)
> for (i in 1:20) {x[i]<-choose(20,i)}
> plot(x)
>
> ...but have found that limiting the number of samples for any community size
> to 1000 is good enough for the further analyses I wish to do.
> My problem lies in sampling all possible combos without having to calculate
> all possible combos. I have tried two methods but both give memory errors at
> about 25 taxa.
>
> The expand.grid() method:
>
> n <- 11
> toto <- vector("list",n)
> titi <- lapply(toto,function(x) c(0,1))
> tutu <- expand.grid(titi)
>
> The combn() method (a slightly lengthlier function):
>
> samplecommunityD<- function(n,numsamples)
> {
> super<-mat.or.vec(,n)
> for (numspploop in 1:n)
> {
>  minor<-t(combn(n,numspploop))
>  if (dim(minor)[1]  {
>    minot<-mat.or.vec(dim(minor)[1],n)
>    for (loopi in 1:dim(minor)[1])
>    {
>      for (loopbi in 1:dim(minor)[2])
>      {
>        minot[loopi,minor[loopi,loopbi]] <- 1
>      }
>    }
>    super<-rbind(super,minot)
>    rm(minot)
>  }
>  else
>  {
>   minot<-mat.or.vec(numsamples,n)
>   for (loopii in 1:numsamples)
>   {
>     thousand<-sample(dim(minor)[1],numsamples)
>       for (loopbii in 1:dim(minor)[2])
>       {
>       minot[loopii,minor[thousand[loopii],loopbii]] <- 1
>       }
>   }
>   super<-rbind(super,minot)
>   rm(minot)
>  }
> }
> super<-super[!rowSums(super)>n-1&!rowSums(super)<2,]
> return(super)
> }
>
> samplecommunityD(11,1000)
>
>
> So unless anyone knows of another function I could try my next step would be
> to modify the combn or expand.grid functions to generate subsamples, but
> their coding beyond me at this stage (I'm a 3.5 month newbie). Can anyone
> identify where in the code I would need to introduce a s

Re: [R] how to subsample all possible combinations of n species taken 1:n at a time?

2009-04-06 Thread Eik Vettorazzi

Hi Jasper,
maybe its not a very R'ish solution but the following could be a 
starting point:
First, notice that every combination you are looking for can be 
represented as an integer in binary notation where each bit stands for a 
specific community.
So looping through all combinations is the same as looping through 
0:(2^n-1) , eg. 7=2^0+2^2, so community 1 and 3 (natural numbering) are 
"set" in the corresponding subset.


#some auxillary functions are needed to extract the bits set in a given 
combination

#get bit returns presence/absence vector of species for given subset x
get.bit<-function(x,n)  x%/%(2^(0:(n-1)))%%2

#index of data columns included in subset x
get.index<-function(x,n)  x%/%(2^(0:(n-1)))%%2==1

n<-15 # number of communities
dta<-matrix(1:(12*n),ncol=n) # some sample data

#looping thru *all* possible combinations of n communities.
#will work, but it is in fact *very*! time consuming for n=25
for (i in 0:(2^n-1))  {
sub.index<-get.index(i,n)
# subsetting your dataset using this index and do subset analysis
# dta[,sub.index]
}

hth



jasper slingsby schrieb:

Hello

I apologise for the length of this entry but please bear with me.

In short:
I need a way of subsampling communities from all possible communities of n
taxa taken 1:n at a time without having to calculate all possible
combinations (because this gives me a memory error - using 
combn() or expand.grid() at least). Does anyone know of a function? Or can
you help me edit the 
combn
or 
expand.grid 
functions to generate subsamples?


In long:
I have been creating all possible communities of n taxa taken 1:n at a time
to get a presence/absence matrix of species occurrence in communities as
below...

Rows are samples, columns are species:

ABC   D . ...
101110001 1 1 1 0 0
0 0
011110001 1 1 1 0 0
0 0
111110001 1 1 1 0 0
0 0
000001001 1 1 1 0 0
0 0
100001001 1 1 1 0 0
0 0
010001001 1 1 1 0 0
0 0
110001001 1 1 1 0 0
0 0
001001001 1 1 1 0 0
0 0


...but the number of possible communities increases exponentially with each
added taxon. 


n<-11 #number of taxa
sum(for (i in 0:n) choose(i, k = 0:i)) #number of combos

So all possible combinations of 11 taxa taken 1:11 at a time is 2048, all
combos of 12 taken 1:12 is 4096, 13 taken 1:13 = 8192...etc etc such that
when I reach about 25 taken 1:25 the number of combos is 33554432 and I get
a memory error.

I have found that the number of combos of x taxa taken from a pool of n
creates a very kurtotic unimodal distribution,... 


x<-vector("integer",20)
for (i in 1:20) {x[i]<-choose(20,i)}
plot(x)

...but have found that limiting the number of samples for any community size
to 1000 is good enough for the further analyses I wish to do.
My problem lies in sampling all possible combos without having to calculate
all possible combos. I have tried two methods but both give memory errors at
about 25 taxa.

The expand.grid() method:

n <- 11 
toto <- vector("list",n)

titi <- lapply(toto,function(x) c(0,1))
tutu <- expand.grid(titi)

The combn() method (a slightly lengthlier function):

samplecommunityD<- function(n,numsamples)
{
super<-mat.or.vec(,n)
for (numspploop in 1:n)
{
  minor<-t(combn(n,numspploop))
  if (dim(minor)[1]n-1&!rowSums(super)<2,]
return(super)
}

samplecommunityD(11,1000)


So unless anyone knows of another function I could try my next step would be
to modify the combn or expand.grid functions to generate subsamples, but
their coding beyond me at this stage (I'm a 3.5 month newbie). Can anyone
identify where in the code I would need to introduce a sampling term or
skipping sequence?

Thanks for your time
Jasper




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

2009-04-06 Thread Dimitris Rizopoulos

try this:

dat <- data.frame(vals = rnorm(1000))
breaks <- quantile(dat$vals, seq(0, 1, .1))
dat$bucket <- cut(dat$vals, breaks, labels = FALSE, include.lowest = TRUE)


I hope it helps.

Best,
Dimitris


Dan Dube wrote:

is there a better way to bucket observations into more-or-less evenly
sized buckets than this?  it seems like this must be a common operation:

dt = data.frame(points=rnorm(1000),bucket=NA)

breaks = quantile(dt$points,seq(0:1,.1))
for (i in 2:length(breaks)) {
if (i == 2) {
ind = which(dt$points >= breaks[i-1] & dt$points <=
breaks[i])
} else {
ind = which(dt$points > breaks[i-1] & dt$points <=
breaks[i])
}
dt$bucket[ind] = i-1
}

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.



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

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

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

2009-04-06 Thread Dan Dube
great!  the "cut" function was exactly what i needed.

thank you both! 

> -Original Message-
> From: Dimitris Rizopoulos [mailto:d.rizopou...@erasmusmc.nl] 
> Sent: Monday, April 06, 2009 4:01 PM
> To: Dan Dube
> Cc: r-help@r-project.org
> Subject: Re: [R] "bucketing" observations
> 
> try this:
> 
> dat <- data.frame(vals = rnorm(1000))
> breaks <- quantile(dat$vals, seq(0, 1, .1)) dat$bucket <- 
> cut(dat$vals, breaks, labels = FALSE, include.lowest = TRUE)
> 
> 
> I hope it helps.
> 
> Best,
> Dimitris
> 
> 
> Dan Dube wrote:
> > is there a better way to bucket observations into 
> more-or-less evenly 
> > sized buckets than this?  it seems like this must be a 
> common operation:
> > 
> > dt = data.frame(points=rnorm(1000),bucket=NA)
> > 
> > breaks = quantile(dt$points,seq(0:1,.1)) for (i in 
> 2:length(breaks)) {
> > if (i == 2) {
> > ind = which(dt$points >= breaks[i-1] & dt$points <=
> > breaks[i])
> > } else {
> > ind = which(dt$points > breaks[i-1] & dt$points <=
> > breaks[i])
> > }
> > dt$bucket[ind] = i-1
> > }
> > 
> > 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.
> > 
> 
> --
> Dimitris Rizopoulos
> Assistant Professor
> Department of Biostatistics
> Erasmus University Medical Center
> 
> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
> Tel: +31/(0)10/7043478
> Fax: +31/(0)10/7043014
> 

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

2009-04-06 Thread carol white
Hi,
Having a set of values (non-time series data), what are the approximation 
functions that could determine the trend of the values?

Cheers,

Carol


  
[[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] approximation function

2009-04-06 Thread Luc Villandre

Hi,

This is a rather broad question.

The function lowess() might be a good place to start, I guess (although 
I'm not sure whether this fits in your definition of "approximation 
functions"...).


Best of luck,

Luc



carol white wrote:

Hi,
Having a set of values (non-time series data), what are the approximation 
functions that could determine the trend of the values?

Cheers,

Carol


  
	[[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] approximation function

2009-04-06 Thread Ravi Varadhan
Hi,

At the sampling points, do you know the function value "exactly" or you only 
observe it with "noise"?

If it is the former, you can use an interpolation scheme, such as, for example, 
interpSpline() in "splines" package.

If it is the latter, you can use a smoother, such as, for example, 
smooth.spline() or loess().

Ravi.


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

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


- Original Message -
From: carol white 
Date: Monday, April 6, 2009 4:16 pm
Subject: [R] approximation function
To: r-h...@stat.math.ethz.ch


> Hi,
>  Having a set of values (non-time series data), what are the 
> approximation functions that could determine the trend of the values?
>  
>  Cheers,
>  
>  Carol
>  
>  
>
>   [[alternative HTML version deleted]]
>  
>  __
>  R-help@r-project.org mailing list
>  
>  PLEASE do read the posting guide 
>  and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] SUM,COUNT,AVG

2009-04-06 Thread Dylan Beaudette
Nice example. Does anyone know if it is possible to use multiple aggregating 
functions with the melt/cast functions?

Cheers,

Dylan


On Monday 06 April 2009, Christian wrote:
> A good package for this sort of questions is doBy, too.
>
> library(doBy)
> summaryBy( tpdv + UM + qta ~ Materiale ,data=data,FUN=c(sum,length,mean))
>
> regards, Christian
>
> > Hi,
> > I ve been searching a lot in internet..but I can t find a solution
> > Attached, you find a file.
> > I need for each (Materiale, tpdv, UM) to find sum,avg and count
> > My idea was to aggregate for the 3 parameters ..but I don t know how to
> > get the numeric value (SUM,COUNT,AVG) I need.
> > Can you help me?
> > thank you
> >
> > http://www.nabble.com/file/p22905322/ordini2008_ex.txt ordini2008_ex.txt
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented, minimal,
> self-contained, reproducible code.



-- 
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] mtext problem - grainy and massive file size

2009-04-06 Thread gcam032

Hi Team,

I'm on a mac, 0SX 10.5.6, R 2.7.2.

I consistently make pairs plots and use mtext() to put labels on top of the
plot in the outer margin.  All of a sudden, this text has become really
grainy in the final product and is making huge files.  I have no idea why
this has just started happening.  The only thing I've done lately is install
the new version of GIMP and run the script to change the std dpi in x11. 
I'm using the quartz device though so this shouldn't be affected??  I can
use the outer=F argument and the text turns out crisp as before, but as soon
as I put it out of the margin it goes funny.  If I plot the pairs plot
without any mtext() it's a nice crisp image and a small file size.  Weird. 
Here is my code

quartz(file="plot.pdf", type="pdf", height=12, width=12)
par(bg="white", oma=c(6,6,6,6))
pairs(W$x,pch=sourcs, col=c(rep(1, nrow(A)), rep("darkcyan", nrow(T)),
rep(4, nrow(K)), rep(2, nrow(H))), cex=1.5, cex.labels=4)
mtext("Catchment",side=3, outer=T, line=4,cex=2,at=0)
mtext("Arahura",side=3,outer=T,line=4.5,col=1,cex=1.75,at=.2)
mtext("Hokitkia",side=3,outer=T,line=4.5,col=2,cex=1.75,at=.35)
mtext("Kokatahi",side=3,outer=T,line=4.5,col=4,cex=1.75,at=.5)
mtext("Toaroha",side=3,outer=T,line=4.5,col="darkcyan",cex=1.75,at=.65)
dev.off()

Any help would be appreciated.  Thanks!
-- 
View this message in context: 
http://www.nabble.com/mtext-problem---grainy-and-massive-file-size-tp22917033p22917033.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.


  1   2   >