Re: [R] Q

2007-04-03 Thread Prof Brian Ripley
The problem is that relatively few DBMSes come even close to conformance 
with SQL (and Laurent Valdes did not tell us his DBMS even in his reply).

ANSI SQL says single quotes are used for literals, and double quotes for 
identifiers (e.g. table and column names).

Literals are only relevant to RODBC in sqlSave(fast=FALSE) and 
sqlUpdate(fast=FALSE), neither being the defaults.  In theory ODBC can 
tell you the quoting characters for each data type, and it seems now all 
the drivers I have access to are ODBC3, this works (it used not to).  Not 
all drivers use single quote for all types, but in all cases I tried where 
they use single quote for character strings, doubling it works.  So that 
will be incorporated in RODBC 1.1-9.

There is less conformance for quoting identifiers.  MySQL uses backtick by 
default (it can be run in ANSI_QUOTE mode), and some Microsoft drivers use 
[...] for table names.  RODBC 1.1.9 makes these settable options, and 
tries to select suitable defaults based on the DBMS name reported.

I will send RODBC_1.1-9 to CRAN shortly.  People testing R-2.5.0 alpha 
under Windows will be able to get it now from CRANextras (a default 
repository).

On Sun, 1 Apr 2007, Duncan Murdoch wrote:

> On 4/1/2007 3:39 AM, Prof Brian Ripley wrote:
>> I think this is about RODBC, uncredited.
>>
>> There is currently no way to do escapes here, and I am pretty sure that
>> ODBC drivers do not support 'slash' as an escape (or did you mean
>> backslash? I am still not sure that would work).
>>
>> sqlSave() has fast=TRUE and fast=FALSE options, and it is worth trying
>> both.  Since the default fast=TRUE passes character data as binary fields,
>> I don't understand why there is a problem (there might be for fast=FALSE
>> with single quotes in character fields).
>
> SQL doubles quotes to escape them, doesn't it?  I.e. if I wanted
>
> this 'value'
>
> as an SQL literal, I would use
>
> 'this ''value'''
>
> I think this is described in the SQL 92 standard (it defines
>  ::= ), but I don't know if it is
> universally implemented.  So if this syntax is supported in Laurent's
> driver/DBMS combination, he could simply double the quotes himself
> before trying to save them, i.e.
>
> values <- gsub("'", "''", values)
>
> Duncan Murdoch
>
>>
>> Without any relevant details (OS, R version, packages used, package
>> version, ODBC driver, DBMS) and any sort of example it is really hard to
>> offer help: please DO study the R posting guide (and note also the comment
>> about using a signature block).
>>
>> On Sat, 31 Mar 2007, Laurent Valdes wrote:
>>
>>> Hi everybody,
>>>
>>> I'm doing a sqlSave() in R, to insert a big data frame of 1 rows.
>>> However, there is problems, since several rows contains quotations marks,
>>> that can leave inserts buggy.
>>> I would like to find a way to add slashes in front of these quotation marks.
>>>
>>> Best regards,
>>>
>>> Laurent
>>>
>>>
>>>
>>
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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

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


Re: [R] RODBC, sqlQuery with NA:s

2007-04-03 Thread Prof Brian Ripley

In my attempts to reproduce this both approaches worked.

There seems to be something going on we cannot see (and I don't believe 
NULL in the database is being mapped to " ").  For example, might there be 
non-breaking spaces (character A0 in Windows 1252, your most likely 
character set) in the database?


On Mon, 2 Apr 2007, Lauri Nikkinen wrote:


Hi R-users,

I'm trying to retrieve data from MS SQL database with RODBC's
sqlQuery-function:

temp <- sqlQuery(channel,"select *, (select text from table1 where
koodi='paa' and koodi2=paa) as tempor from table2")

str(temp)

…
$ var0: num  NA NA 1.6 NA NA 1.4 NA 1 NA NA ...
$ var1  : Factor w/ 45 levels " ","01","01;07",..: 1 1 1 4 38 1 38 7
1 1 ...
$ var2: Factor w/ 95 levels " ","01","01;02;09",..: 1 1 1 9 72 1 78
13 1 1 ...
$ var3  : Factor w/ 104 levels " ","01","01;02;09",..: 1 1 1 44 82 1 87
14 1 1 ...
…

Data types of these variables in the MS SQL database are:

var0: float, NULL
var1: varchar, NULL
var2: varchar, NULL
var3: varchar, NULL

As you can see from above, I get variable var0 with NA:s because of the data
type (there is NULL in the database if there is no observation in the
specific cell). How can I get NA:s to these Factor variables also? I have
tried the following with no positive results:

temp <- sqlQuery(channel,"select *, (select text from table1 where
koodi='paa' and koodi2=paa) as tempor from table2", na.strings=" ")

and also afterwards

temp$var1[temp$var1 == " "] <- "NA"

Regards,
Lauri

[[alternative HTML version deleted]]




--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Compiling C codes in Windows

2007-04-03 Thread Tong Wang
Thank you all for the help . It seems I only need to change the back slash to 
forward slash to get things work .

As to using Cygwin as the shell, I couldn't find an instruction dedicated to 
Cygwin, should I just follow the " Installing 
R under Unix-alikes " ?  Is there an easier way, like making use of the 
installed binaries.

I will post future questions to R-devel.  

Thanks again.

tong 

- Original Message -
From: Duncan Murdoch <[EMAIL PROTECTED]>
Date: Monday, April 2, 2007 9:21 am
Subject: Re: [R] Compiling C codes in Windows
To: Martin Morgan <[EMAIL PROTECTED]>
Cc: Tong Wang <[EMAIL PROTECTED]>, R help 

> On 4/2/2007 4:53 AM, Martin Morgan wrote:
> > Tong Wang <[EMAIL PROTECTED]> writes:
> > 
> >> Hi All,
> > [...]
> >> After I followed all the instructions in " Building R for 
> Windows" 
> > [...]
> >>  Anyway, I assumed that I need to run this command in Cygwin
> > 
> > No, do this from a DOS shell. 
> 
> Cygwin is fine as a shell (it's what I use), but the rest of your 
> advice 
> is correct:
> 
> > The usual problems are either missing
> > components from the installation steps outlined in Building R for
> > Windows, or an incorrect PATH variable so that windows or cygwin
> > versions of programs are used rather than MinGW / Rtools.
> 
> Duncan Murdoch
> 
> > 
> > Also, this question belongs on the R-devel list, where those doing
> > development work are more likely to see and respond to your
> > questions.
> > 
> > Hope that helps,
> > 
> > Martin Morgan
> >>
> >> $ make all recommended
> >> make: ./Rpwd.exe: Command not found
> >> make[1]: ./Rpwd.exe: Command not found
> >> make --no-print-directory -C front-ends Rpwd
> >> make -C ../../include -f Makefile.win version
> >> make Rpwd.exe
> >> gcc  -O3 -Wall -pedantic -I../../include  -c rpwd.c -o rpwd.o
> >> rpwd.c:22:20: direct.h: No such file or directory
> >> rpwd.c: In function `main':
> >> rpwd.c:42: warning: implicit declaration of function `chdir'
> >> rpwd.c:45: warning: implicit declaration of function `getcwd'
> >> make[3]: *** [rpwd.o] Error 1
> >> make[2]: *** [Rpwd] Error 2
> >> make[1]: *** [front-ends/Rpwd.exe] Error 2
> >> make: *** [all] Error 2 
> >>
> >>
> >> Can I get some help with my quesitons , and some suggestions 
> concerning the best way to solve the whole problem ?
> >>
> >> THanks a lot  for your help..
> >>
> >> tong
> >>
> >> __
> >> R-help@stat.math.ethz.ch mailing list
> >> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] RODBC, sqlQuery with NA:s

2007-04-03 Thread Lauri Nikkinen
Thanks Prof Ripley for your answer. In fact, there is no NULL's in these
varchar variables, that is because one of the software's we use do not
accept NULL's (that is strange, isn't it?). So, for instance, when I type

select * from table1
where var1=''

I get all those rows where the cells of var1 are empty. So, is there any
possibility to tell R that it should convert these empty cells to NA:s (when
importing)?

Thanks for your help
Lauri


2007/4/3, Prof Brian Ripley <[EMAIL PROTECTED]>:
>
> In my attempts to reproduce this both approaches worked.
>
> There seems to be something going on we cannot see (and I don't believe
> NULL in the database is being mapped to " ").  For example, might there be
> non-breaking spaces (character A0 in Windows 1252, your most likely
> character set) in the database?
>
> On Mon, 2 Apr 2007, Lauri Nikkinen wrote:
>
> > Hi R-users,
> >
> > I'm trying to retrieve data from MS SQL database with RODBC's
> > sqlQuery-function:
> >
> > temp <- sqlQuery(channel,"select *, (select text from table1 where
> > koodi='paa' and koodi2=paa) as tempor from table2")
> >
> > str(temp)
> >
> > …
> > $ var0: num  NA NA 1.6 NA NA 1.4 NA 1 NA NA ...
> > $ var1  : Factor w/ 45 levels " ","01","01;07",..: 1 1 1 4 38 1
> 38 7
> > 1 1 ...
> > $ var2: Factor w/ 95 levels " ","01","01;02;09",..: 1 1 1 9 72 1
> 78
> > 13 1 1 ...
> > $ var3  : Factor w/ 104 levels " ","01","01;02;09",..: 1 1 1 44 82 1
> 87
> > 14 1 1 ...
> > …
> >
> > Data types of these variables in the MS SQL database are:
> >
> > var0: float, NULL
> > var1: varchar, NULL
> > var2: varchar, NULL
> > var3: varchar, NULL
> >
> > As you can see from above, I get variable var0 with NA:s because of the
> data
> > type (there is NULL in the database if there is no observation in the
> > specific cell). How can I get NA:s to these Factor variables also? I
> have
> > tried the following with no positive results:
> >
> > temp <- sqlQuery(channel,"select *, (select text from table1 where
> > koodi='paa' and koodi2=paa) as tempor from table2", na.strings=" ")
> >
> > and also afterwards
> >
> > temp$var1[temp$var1 == " "] <- "NA"
> >
> > Regards,
> > Lauri
> >
> >   [[alternative HTML version deleted]]
> >
> >
>
> --
> Brian D. Ripley,  [EMAIL PROTECTED]
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel:  +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UKFax:  +44 1865 272595

[[alternative HTML version deleted]]

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


Re: [R] substitute values

2007-04-03 Thread Mark Wardle
Sergio Della Franca wrote:
> Dear R-Helpers,
> 
> I have the following data set(y):
> 
> Years   Products
> 1  10
> 2  25
> 3  40
> 4  NA
> 5  35
>23
> 6 NA
> 7 67
> 8 NA
> 
> I want to create a new column into my dataset(y) under the following
> conditions:
> if years =NA and products >20 then new column=1 else new column=0;
> to obtain the following results:
> 
> Years   Products New Column
> 1  10  0
> 2  25  0
> 3  40  0
> 4  NA 0
> 5  35  0
>23  1
> 6 NA  0
> 7 67   0
> 8 NA  0
> 

How about using ifelse():
year = c(1,2,3,4,5,NA,6,7,8)
products = c(10,25,40,NA,35,23,NA,67,NA)
ifelse(is.na(year) & products>20,1,0)


=>

[1] 0 0 0 0 0 1 0 0 0


Mark

-- 
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK

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


Re: [R] RODBC, sqlQuery with NA:s

2007-04-03 Thread Lauri Nikkinen
Thanks again,

There is still going on something strange, because na.strings="" in sqlQuery
clause didn't help. I'm helpless but thanks anyway...

-Lauri


2007/4/3, Prof Brian Ripley <[EMAIL PROTECTED]>:
>
> On Tue, 3 Apr 2007, Lauri Nikkinen wrote:
>
> > Thanks Prof Ripley for your answer. In fact, there is no NULL's in these
> > varchar variables, that is because one of the software's we use do not
> > accept NULL's (that is strange, isn't it?).
>
> It's not uncommon.  (Be grateful you are not on MacOS, where it seems
> quite common to accept NULLs but not treat them as different from "".)
>
> > So, for instance, when I type
> >
> > select * from table1
> > where var1=''
> >
> > I get all those rows where the cells of var1 are empty. So, is there any
> > possibility to tell R that it should convert these empty cells to NA:s
> (when
> > importing)?
>
> Yes, via na.strings="".
>
> >
> > Thanks for your help
> > Lauri
> >
> >
> > 2007/4/3, Prof Brian Ripley <[EMAIL PROTECTED]>:
> >>
> >> In my attempts to reproduce this both approaches worked.
> >>
> >> There seems to be something going on we cannot see (and I don't believe
> >> NULL in the database is being mapped to " ").  For example, might there
> be
> >> non-breaking spaces (character A0 in Windows 1252, your most likely
> >> character set) in the database?
> >>
> >> On Mon, 2 Apr 2007, Lauri Nikkinen wrote:
> >>
> >> > Hi R-users,
> >> >
> >> > I'm trying to retrieve data from MS SQL database with RODBC's
> >> > sqlQuery-function:
> >> >
> >> > temp <- sqlQuery(channel,"select *, (select text from table1 where
> >> > koodi='paa' and koodi2=paa) as tempor from table2")
> >> >
> >> > str(temp)
> >> >
> >> > ?
> >> > $ var0: num  NA NA 1.6 NA NA 1.4 NA 1 NA NA ...
> >> > $ var1  : Factor w/ 45 levels " ","01","01;07",..: 1 1 1 4 38
> 1
> >> 38 7
> >> > 1 1 ...
> >> > $ var2: Factor w/ 95 levels " ","01","01;02;09",..: 1 1 1 9
> 72 1
> >> 78
> >> > 13 1 1 ...
> >> > $ var3  : Factor w/ 104 levels " ","01","01;02;09",..: 1 1 1 44
> 82 1
> >> 87
> >> > 14 1 1 ...
> >> > ?
> >> >
> >> > Data types of these variables in the MS SQL database are:
> >> >
> >> > var0: float, NULL
> >> > var1: varchar, NULL
> >> > var2: varchar, NULL
> >> > var3: varchar, NULL
> >> >
> >> > As you can see from above, I get variable var0 with NA:s because of
> the
> >> data
> >> > type (there is NULL in the database if there is no observation in the
> >> > specific cell). How can I get NA:s to these Factor variables also? I
> >> have
> >> > tried the following with no positive results:
> >> >
> >> > temp <- sqlQuery(channel,"select *, (select text from table1 where
> >> > koodi='paa' and koodi2=paa) as tempor from table2", na.strings=" ")
> >> >
> >> > and also afterwards
> >> >
> >> > temp$var1[temp$var1 == " "] <- "NA"
> >> >
> >> > Regards,
> >> > Lauri
> >> >
> >> >   [[alternative HTML version deleted]]
> >> >
> >> >
> >>
> >> --
> >> Brian D. Ripley,  [EMAIL PROTECTED]
> >> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> >> University of Oxford, Tel:  +44 1865 272861 (self)
> >> 1 South Parks Road, +44 1865 272866 (PA)
> >> Oxford OX1 3TG, UKFax:  +44 1865 272595
> >
>
> --
> Brian D. Ripley,  [EMAIL PROTECTED]
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel:  +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UKFax:  +44 1865 272595
>

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Referencing function name from within function

2007-04-03 Thread Johannes Graumann
Hello,

For verbose coding I'd like to do something like:
> myfunction <- function(x){
>   if (a){
>   stop(paste(myfunction_name_here,"requires xyz!")
>   }   
Is that possible?

Thanks for any hints, Joh

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 choose the df when using GAM function?

2007-04-03 Thread Simon Wood
>   When using GAM function in R, we need to specify the degree of freedom
> for the smooth function (i.e. s=(x, df=#)). I am wondering how to choose an
> appropriate df.
--- you could use the gam function in package mgcv. It will select the 
effective degrees of freedom for you automatically using GCV or (generalized) 
AIC.

Simon

-- 
> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK
> +44 1225 386603  www.maths.bath.ac.uk/~sw283

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


Re: [R] (Newbie)Basic Basic global vs. local variables

2007-04-03 Thread Mark Wardle
projection83 wrote:
> My R code has got too complex to have a non-modular approach. Ive done some
> coding in other languages before, but I somehow cant figure out R's general
> rules for global and local variables. I have put a simple code below, if
> anyone can show me what i need to add to make this work, i would greatly
> appreciate it!
> 
> #
> g_Means<-numeric()
>   
> defineSamples<- function()
>   {
>   g_Means<-5
>   }
> 
> runit<-function()
>   {
>   defineSamples()
>   g_Means #<   }
> 
> runit()
> #
> Basically I can not get the parameter I set from a global scale...

I don't think you quite understand variable scope.

The "Introduction to R" says:

(http://cran.r-project.org/doc/manuals/R-intro.html#Assignment-within-functions)

> 10.5 Assignments within functions
> 
> Note that any ordinary assignments done within the function are local and 
> temporary and are lost after exit from the function. Thus the assignment X <- 
> qr(X) does not affect the value of the argument in the calling program.
> 
> To understand completely the rules governing the scope of R assignments the 
> reader needs to be familiar with the notion of an evaluation frame. This is a 
> somewhat advanced, though hardly difficult, topic and is not covered further 
> here.
> 
> If global and permanent assignments are intended within a function, then 
> either the “superassignment” operator, <<- or the function assign() can be 
> used. See the help document for details. S-Plus users should be aware that 
> <<- has different semantics in R. These are discussed further in Scope.


I've struggled with keeping my global namespace relatively clutter-free.
 You should think of functions as separate pieces of work, independent
from most other things, and try to design them to be as generic as
possible.

Presumably defineSamples() does some complex calculations, although it
is impossible to tell as it appears to not take any parameters, and
returns the value of g_Means (functions return their last evaluated
expression).

Therefore your runIt() function isn't actually getting the result.

I would suggest defining functions with well-defined inputs and outputs,
and NOT using global variables. It is difficult to give examples as you
haven't said what your functions are doing, but for example:

defineSamples <- function(a,b,c=TRUE) {
# do some complex things with our input variables
# and return the results  - let's make it explicit with a return() call
return(a*b)

}

This is an isolated piece of logic, and if you go and change things
elsewhere, its functionality won't have to be changed.

# note that this doesn't take any parameters.
runIt <- function() {
my.result = defineSamples(3,4)
return(my.results)  # superfluous, but nice to make it 
explicit for
this example
}


Then you can call

runIt()
=> gives 12

And if you want to save the result, use

g_Means = runIt()


You can pass arbitrarily complex data structures from and to functions
if you have the need -  see list().

Hope this helps,

Mark
-- 
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK

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


Re: [R] RODBC, sqlQuery with NA:s

2007-04-03 Thread Prof Brian Ripley
On Tue, 3 Apr 2007, Lauri Nikkinen wrote:

> Thanks Prof Ripley for your answer. In fact, there is no NULL's in these
> varchar variables, that is because one of the software's we use do not
> accept NULL's (that is strange, isn't it?).

It's not uncommon.  (Be grateful you are not on MacOS, where it seems 
quite common to accept NULLs but not treat them as different from "".)

> So, for instance, when I type
>
> select * from table1
> where var1=''
>
> I get all those rows where the cells of var1 are empty. So, is there any
> possibility to tell R that it should convert these empty cells to NA:s (when
> importing)?

Yes, via na.strings="".

>
> Thanks for your help
> Lauri
>
>
> 2007/4/3, Prof Brian Ripley <[EMAIL PROTECTED]>:
>> 
>> In my attempts to reproduce this both approaches worked.
>> 
>> There seems to be something going on we cannot see (and I don't believe
>> NULL in the database is being mapped to " ").  For example, might there be
>> non-breaking spaces (character A0 in Windows 1252, your most likely
>> character set) in the database?
>> 
>> On Mon, 2 Apr 2007, Lauri Nikkinen wrote:
>> 
>> > Hi R-users,
>> >
>> > I'm trying to retrieve data from MS SQL database with RODBC's
>> > sqlQuery-function:
>> >
>> > temp <- sqlQuery(channel,"select *, (select text from table1 where
>> > koodi='paa' and koodi2=paa) as tempor from table2")
>> >
>> > str(temp)
>> >
>> > ?
>> > $ var0: num  NA NA 1.6 NA NA 1.4 NA 1 NA NA ...
>> > $ var1  : Factor w/ 45 levels " ","01","01;07",..: 1 1 1 4 38 1
>> 38 7
>> > 1 1 ...
>> > $ var2: Factor w/ 95 levels " ","01","01;02;09",..: 1 1 1 9 72 1
>> 78
>> > 13 1 1 ...
>> > $ var3  : Factor w/ 104 levels " ","01","01;02;09",..: 1 1 1 44 82 1
>> 87
>> > 14 1 1 ...
>> > ?
>> >
>> > Data types of these variables in the MS SQL database are:
>> >
>> > var0: float, NULL
>> > var1: varchar, NULL
>> > var2: varchar, NULL
>> > var3: varchar, NULL
>> >
>> > As you can see from above, I get variable var0 with NA:s because of the
>> data
>> > type (there is NULL in the database if there is no observation in the
>> > specific cell). How can I get NA:s to these Factor variables also? I
>> have
>> > tried the following with no positive results:
>> >
>> > temp <- sqlQuery(channel,"select *, (select text from table1 where
>> > koodi='paa' and koodi2=paa) as tempor from table2", na.strings=" ")
>> >
>> > and also afterwards
>> >
>> > temp$var1[temp$var1 == " "] <- "NA"
>> >
>> > Regards,
>> > Lauri
>> >
>> >   [[alternative HTML version deleted]]
>> >
>> >
>> 
>> --
>> Brian D. Ripley,  [EMAIL PROTECTED]
>> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
>> University of Oxford, Tel:  +44 1865 272861 (self)
>> 1 South Parks Road, +44 1865 272866 (PA)
>> Oxford OX1 3TG, UKFax:  +44 1865 272595
>

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

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


Re: [R] substitute values

2007-04-03 Thread Sergio Della Franca
I have much more problem in the following case:

 Years   Products  New Column
 1  10   0
 2  25   0
 3  40   0
 4  NA  0
 5  35   0
23   1
 6 NA   0
 7 670
 8 NA   0
NA   NA   *NA*
NA   NA   *NA*

When i hane NA in both columns the results of the procedure give me NA.
I'd like to obtain 0.



2007/4/3, Mark Wardle <[EMAIL PROTECTED]>:
>
> Sergio Della Franca wrote:
> > Dear R-Helpers,
> >
> > I have the following data set(y):
> >
> > Years   Products
> > 1  10
> > 2  25
> > 3  40
> > 4  NA
> > 5  35
> >23
> > 6 NA
> > 7 67
> > 8 NA
> >
> > I want to create a new column into my dataset(y) under the following
> > conditions:
> > if years =NA and products >20 then new column=1 else new column=0;
> > to obtain the following results:
> >
> > Years   Products New Column
> > 1  10  0
> > 2  25  0
> > 3  40  0
> > 4  NA 0
> > 5  35  0
> >23  1
> > 6 NA  0
> > 7 67   0
> > 8 NA  0
> >
>
> How about using ifelse():
> year = c(1,2,3,4,5,NA,6,7,8)
> products = c(10,25,40,NA,35,23,NA,67,NA)
> ifelse(is.na(year) & products>20,1,0)
>
>
> =>
>
> [1] 0 0 0 0 0 1 0 0 0
>
>
> Mark
>
> --
> Dr. Mark Wardle
> Specialist registrar, Neurology
> Cardiff, UK
>

[[alternative HTML version deleted]]

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


Re: [R] RODBC, sqlQuery with NA:s

2007-04-03 Thread Mark Wardle
Lauri Nikkinen wrote:
> Thanks Prof Ripley for your answer. In fact, there is no NULL's in these
> varchar variables, that is because one of the software's we use do not
> accept NULL's (that is strange, isn't it?). So, for instance, when I type
> 
> select * from table1
> where var1=''
> 
> I get all those rows where the cells of var1 are empty. So, is there any
> possibility to tell R that it should convert these empty cells to NA:s (when
> importing)?
> 

You could use a SQL case statement to do some pre-processing so that
RODBC can do the right thing.

Best wishes,

Mark

-- 
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Testing additive nonparametric model

2007-04-03 Thread Donal O'Neill
I have estimated a multiple nonparametric regression using the loess 
command in R. I have also estimated an additive version of the model using 
the gam function. Is there a way of using the output of these two models to 
test the restrictions imposed by the additive model?

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] converting a list to a data.frame

2007-04-03 Thread Biscarini, Filippo
Hello,
 
I have a list with n numerical components of different length (3, 4 or 5
values in each component of the list); I need to export this as a text
file where each component of the list will be a row and where missing
values should fill in the blanks due to the different lengths of the
components of the list.
I think that as a first step I should convert my list to a data frame,
but this is not such a simple task to accomplish: I was thinking of the
following "for" loop:
 
X<-data.frame(1,1,1,1,1);
 
for (i in 1:length(list)) {
 
X[i,]<-unlist(list[[i]]);
 
}
 
Unfortunately, when the number of elements in the components of the list
are lower than 5 (maximum), I get errors or undesired results. I also
tried with rbind(), but again I couldn't manage to make it accept rows
of different length.
 
Does anybody have any suggestions? Working with lists is very nice, but
I still have to learn how to transfer them to text files for external
use.
 
Thnak you,
 
Filippo Biscarini
Wageningen University

[[alternative HTML version deleted]]

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


Re: [R] Testing additive nonparametric model

2007-04-03 Thread vito muggeo
You can use the LRT (although I think that it assumes the df to be 
fixed). For instance the package mgcv by Simon Wood has an anova method 
to compare models fitted by the relevant gam() function, and the 
print.summary() itself returns such information..

best,
vito

set.seed(123)
n<-100
sig<-2
x0 <- runif(n, 0, 1)
x1 <- runif(n, 0, 1)
y <- sin(2*pi*x0) + .5*x1 +sig*rnorm(n)
library(mgcv)
obj<-gam(y~s(x0)+s(x1))
obj1<-gam(y~s(x0)+x1)
anova(obj1,obj,test="F")
#also see the "Approximate significance of smooth terms"
summary(obj)




Donal O'Neill wrote:
> I have estimated a multiple nonparametric regression using the loess 
> command in R. I have also estimated an additive version of the model using 
> the gam function. Is there a way of using the output of these two models to 
> test the restrictions imposed by the additive model?
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 

Vito M.R. Muggeo
Dip.to Sc Statist e Matem `Vianelli'
Università di Palermo
viale delle Scienze, edificio 13
90128 Palermo - ITALY
tel: 091 6626240
fax: 091 485726/485612

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


Re: [R] bivariate interpolation

2007-04-03 Thread Adelchi Azzalini
On Mon, 2 Apr 2007 22:26:06 -0400, eric lee wrote:

EL> Hi.  I'm trying to take a data set with two independent and one dependent
EL> variable and enter a x,y value to predict the dependent with a
EL> nonparametric technique.  I've been using interpp in the akima package,
EL> (windows xp, R 2.4.1), but get values that are orders of magnitude off
EL> when the predictors are slightly out of the range of the data set.  Can
EL> you recommend a function for me?  I've read that predict.loess has the
EL> same problem or just lists NA.  Smooth.spline looks good, but can only do
EL> one predictor instead of bivariate.  I've tried help.search("predict"),
EL> but couldn't find what I needed.  Thanks.
EL> 

one option is to use sm.regression of package sm, along these lines

 x <- cbind(runif(100,-2, 2), runif(100,-2, 2))
 y <- x[,1]^2 + x[,2]^2 + 0.7*x[,1]*x[,2] + rnorm(100)/3
 sm.regression(x,y)
 ev.pt <- rbind(c(-2,-2),c(2,2), c(2,-2),c(-2,2))
 a <- sm.regression(x,y, eval.points=ev.pt,  eval.grid=FALSE)
-- 
Adelchi Azzalini  <[EMAIL PROTECTED]>
Dipart.Scienze Statistiche, Università di Padova, Italia
tel. +39 049 8274147,  http://azzalini.stat.unipd.it/

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


Re: [R] bivariate interpolation

2007-04-03 Thread Adelchi Azzalini
On Tue, 3 Apr 2007 11:43:55 +0200, Adelchi Azzalini wrote:

AA> On Mon, 2 Apr 2007 22:26:06 -0400, eric lee wrote:
AA> 
AA> EL> Hi.  I'm trying to take a data set with two independent and one
AA> EL> dependent variable and enter a x,y value to predict the dependent
AA> EL> with a nonparametric technique.  I've been using interpp in the akima
AA> EL> package, (windows xp, R 2.4.1), but get values that are orders of
AA> EL> magnitude off when the predictors are slightly out of the range of
AA> EL> the data set.  Can you recommend a function for me?  I've read that
AA> EL> predict.loess has the same problem or just lists NA.  Smooth.spline
AA> EL> looks good, but can only do one predictor instead of bivariate.  I've
AA> EL> tried help.search("predict"), but couldn't find what I needed.
AA> EL> Thanks.
AA> EL> 
AA> 
AA> one option is to use sm.regression of package sm, along these lines
AA> 
AA>  x <- cbind(runif(100,-2, 2), runif(100,-2, 2))
AA>  y <- x[,1]^2 + x[,2]^2 + 0.7*x[,1]*x[,2] + rnorm(100)/3
AA>  sm.regression(x,y)
AA>  ev.pt <- rbind(c(-2,-2),c(2,2), c(2,-2),c(-2,2))
AA>  a <- sm.regression(x,y, eval.points=ev.pt,  eval.grid=FALSE)

I forgot the last bit

   print(a$estimate)
-- 
Adelchi Azzalini  <[EMAIL PROTECTED]>
Dipart.Scienze Statistiche, Università di Padova, Italia
tel. +39 049 8274147,  http://azzalini.stat.unipd.it/

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Coding for contrasts in unbalanced designs

2007-04-03 Thread Guillaume Brutel
Dear list members,

I want to use a GLM with an unbalanced factor and continuous variables.
My factor F has 12 unbalanced levels:
F=as.factor(c('A','B','C','C','C','C','D','D','D','D','D','D','E','E','E','E','E','E','F','G','G','H','I','I','J','J','J','K','L','L','L'))
> summary(F)
A B C D E F G H I J K L 
1 1 4 6 6 1 2 1 2 3 1 3

I thus want to code contrasts appropriatly.
I have looked in R documentations and R-help archives without finding the 
information for unbalanced designs.
Any help will be very useful.
Thanks you very much.
Guillaume Brutel.


-

[[alternative HTML version deleted]]

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


Re: [R] substitute values

2007-04-03 Thread Mark Wardle
Sergio Della Franca wrote:
> I have much more problem in the following case:
>  
>  Years   Products  New Column
>  1  10   0
>  2  25   0
>  3  40   0
>  4  NA  0
>  5  35   0
> 23   1
>  6 NA   0
>  7 670
>  8 NA   0
> NA   NA   *NA*
> NA   NA   *NA*
>  
> When i hane NA in both columns the results of the procedure give me NA.
> I'd like to obtain 0.
>  
> 
>  
> 2007/4/3, Mark Wardle <[EMAIL PROTECTED] >:
> 
> Sergio Della Franca wrote:
> > Dear R-Helpers,
> >
> > I have the following data set(y):
> >
> > Years   Products
> > 1  10
> > 2  25
> > 3  40
> > 4  NA
> > 5  35
> >23
> > 6 NA
> > 7 67
> > 8 NA
> >
> > I want to create a new column into my dataset(y) under the following
> > conditions:
> > if years =NA and products >20 then new column=1 else new column=0;
> > to obtain the following results:
> >
> > Years   Products New Column
> > 1  10  0
> > 2  25  0
> > 3  40  0
> > 4  NA 0
> > 5  35  0
> >23  1
> > 6 NA  0
> > 7 67   0
> > 8 NA  0
> >
> 
> How about using ifelse():
> year = c(1,2,3,4,5,NA,6,7,8)
> products = c(10,25,40,NA,35,23,NA,67,NA)
> ifelse( is.na(year) & products>20,1,0)
>

Did you try to investigate why that happened? It's because the term
(products>20) is evaluated to NA if products == NA. Try typing that by
itself and experiment - it is the best way of learning!

For example:

> year = c(1,2,3,4,5,NA,6,7,8,NA)
> products = c(10,25,40,NA,35,23,NA,67,NA,NA)

Experiment and see what happens with

> year > 4

> products > 25

> is.na(year)

> is.na(year) & year>4


And finally, try the ifelse command, and read the help!

> ifelse(T, 1, 0)
> ifelse(NA, 1, 0)


And so:

> ifelse( is.na(year) & !is.na(products) & products>20,1,0)


Did you look at ?ifelse, and ?is.na Really do try experiment with
things - it is all quite logical (no pun intended). Suddenly, you'll
understand what is actually going on, and won't have to keep asking for
help with minor variations on the same theme.

Best wishes,

Mark
-- 
Specialist registrar, Neurology,
Cardiff, UK

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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: converting a list to a data.frame

2007-04-03 Thread Petr PIKAL
Hi

do.call("cbind", your.list) # or rbind

gives you rectangular matrix, however shorter items in list are recycled 
as necessary. Problem is that you need to specify how shall be shorter 
items  handeled as it is not obvious. One possibility could be add NAs to 
positions where you want them, what is not so simple. But maybe somebody 
can give more elegant solution.

Regards

Petr
[EMAIL PROTECTED]

[EMAIL PROTECTED] napsal dne 03.04.2007 11:28:27:

> Hello,
> 
> I have a list with n numerical components of different length (3, 4 or 5
> values in each component of the list); I need to export this as a text
> file where each component of the list will be a row and where missing
> values should fill in the blanks due to the different lengths of the
> components of the list.
> I think that as a first step I should convert my list to a data frame,
> but this is not such a simple task to accomplish: I was thinking of the
> following "for" loop:
> 
> X<-data.frame(1,1,1,1,1);
> 
> for (i in 1:length(list)) {
> 
> X[i,]<-unlist(list[[i]]);
> 
> }
> 
> Unfortunately, when the number of elements in the components of the list
> are lower than 5 (maximum), I get errors or undesired results. I also
> tried with rbind(), but again I couldn't manage to make it accept rows
> of different length.
> 
> Does anybody have any suggestions? Working with lists is very nice, but
> I still have to learn how to transfer them to text files for external
> use.
> 
> Thnak you,
> 
> Filippo Biscarini
> Wageningen University 
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] substitute values

2007-04-03 Thread Sergio Della Franca
Ok,
this procedure, ifelse( is.na(year) & !is.na(products) & products>20,1,0)
, run correctly.

Thank you very much.


Best.


2007/4/3, Mark Wardle <[EMAIL PROTECTED]>:
>
> Sergio Della Franca wrote:
> > I have much more problem in the following case:
> >
> >  Years   Products  New Column
> >  1  10   0
> >  2  25   0
> >  3  40   0
> >  4  NA  0
> >  5  35   0
> > 23   1
> >  6 NA   0
> >  7 670
> >  8 NA   0
> > NA   NA   *NA*
> > NA   NA   *NA*
> >
> > When i hane NA in both columns the results of the procedure give me NA.
> > I'd like to obtain 0.
> >
> >
> >
> > 2007/4/3, Mark Wardle <[EMAIL PROTECTED] >:
> >
> > Sergio Della Franca wrote:
> > > Dear R-Helpers,
> > >
> > > I have the following data set(y):
> > >
> > > Years   Products
> > > 1  10
> > > 2  25
> > > 3  40
> > > 4  NA
> > > 5  35
> > >23
> > > 6 NA
> > > 7 67
> > > 8 NA
> > >
> > > I want to create a new column into my dataset(y) under the
> following
> > > conditions:
> > > if years =NA and products >20 then new column=1 else new column=0;
> > > to obtain the following results:
> > >
> > > Years   Products New Column
> > > 1  10  0
> > > 2  25  0
> > > 3  40  0
> > > 4  NA 0
> > > 5  35  0
> > >23  1
> > > 6 NA  0
> > > 7 67   0
> > > 8 NA  0
> > >
> >
> > How about using ifelse():
> > year = c(1,2,3,4,5,NA,6,7,8)
> > products = c(10,25,40,NA,35,23,NA,67,NA)
> > ifelse( is.na(year) & products>20,1,0)
> >
>
> Did you try to investigate why that happened? It's because the term
> (products>20) is evaluated to NA if products == NA. Try typing that by
> itself and experiment - it is the best way of learning!
>
> For example:
>
> > year = c(1,2,3,4,5,NA,6,7,8,NA)
> > products = c(10,25,40,NA,35,23,NA,67,NA,NA)
>
> Experiment and see what happens with
>
> > year > 4
>
> > products > 25
>
> > is.na(year)
>
> > is.na(year) & year>4
>
>
> And finally, try the ifelse command, and read the help!
>
> > ifelse(T, 1, 0)
> > ifelse(NA, 1, 0)
>
>
> And so:
>
> > ifelse( is.na(year) & !is.na(products) & products>20,1,0)
>
>
> Did you look at ?ifelse, and ?is.na Really do try experiment with
> things - it is all quite logical (no pun intended). Suddenly, you'll
> understand what is actually going on, and won't have to keep asking for
> help with minor variations on the same theme.
>
> Best wishes,
>
> Mark
> --
> Specialist registrar, Neurology,
> Cardiff, UK
>
>
>
>
>

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] the numimum number of fixed factors lme package can deal with

2007-04-03 Thread Fang, Yongxiang

Hello,

In my study, mixed effects model is required and the number of fixed
effects is very large. When lme package is employed, a model error is
displayed once the number of fixed  factors in the formula reaches 200. Is
this the maximum number of fixed factors can be handled by lme package?
If not, what is possible reason of the error message?

Thanks

Yongxiang

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


Re: [R] converting a list to a data.frame

2007-04-03 Thread Mark Wardle
Biscarini, Filippo wrote:
> Dear Mark,
> 
> If you have time you can try directly into R this excerpt from my list.
> 


This is horrible code, and I should be shot! I would appreciate any
better ways of doing this, but I think this works!

l = list(c(1,2,4),c(4,5,2,1),c(3,4,6,3),c(3,1,76,4,2))


fix.it <- function(list) {
max.length = 0
x = NULL
for(i in list) max.length = max(max.length, length(i))
for(i in list) {
d = c(i, rep(NA, max.length - length(i)))
if(is.null(x)) x = rbind(unlist(d))
else x = rbind(x, unlist(d))
}
return(x)
}

fix.it(l)

It works on the data you sent me:

> fix.it(A)

Have fun,

Mark

-- 
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK

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


Re: [R] Referencing function name from within function

2007-04-03 Thread rolf
I dunno much about such things, but a wee experiment seems to
indicate that the following structure does what you want:

myfunction <- function(x){
nm <- as.character(match.call())[1]
a  <- TRUE
if (a){
stop(paste(nm,"requires xyz!"))
}   
}

cheers,

Rolf Turner
[EMAIL PROTECTED]

===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===
Original message:

> For verbose coding I'd like to do something like:
> > myfunction <- function(x){
> >   if (a){
> >   stop(paste(myfunction_name_here,"requires xyz!")
> >   }   
> Is that possible?

(Note:  In R *all* things are possible!)

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


Re: [R] Referencing function name from within function

2007-04-03 Thread jim holtman
Try this:

> myfunction <- function(){
+ # some calculations
+ # now get my name
+ .caller <- sys.call()
+ cat(paste(as.character(.caller[[length(.caller)]]),"needs 'xyz'\n"))
+ }
> myfunction()
myfunction needs 'xyz'
>
>



On 4/3/07, Johannes Graumann <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> For verbose coding I'd like to do something like:
> > myfunction <- function(x){
> >   if (a){
> >   stop(paste(myfunction_name_here,"requires xyz!")
> >   }
> Is that possible?
>
> Thanks for any hints, Joh
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

What is the problem you are trying to solve?

[[alternative HTML version deleted]]

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


Re: [R] converting a list to a data.frame

2007-04-03 Thread Dimitris Rizopoulos
try something like this:

lis <- list(c(1,2,4), c(4,5,2,1), c(3,4,6,3), c(3,1,76,4,2))
##
n.max <- max(sapply(lis, length))
val <- NA # what to fill in
fill <- function(x) c(x, rep(val, n.max - length(x)))
as.data.frame(do.call(rbind, lapply(lis, fill)))


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Biscarini, Filippo" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, April 03, 2007 11:28 AM
Subject: [R] converting a list to a data.frame


> Hello,
>
> I have a list with n numerical components of different length (3, 4 
> or 5
> values in each component of the list); I need to export this as a 
> text
> file where each component of the list will be a row and where 
> missing
> values should fill in the blanks due to the different lengths of the
> components of the list.
> I think that as a first step I should convert my list to a data 
> frame,
> but this is not such a simple task to accomplish: I was thinking of 
> the
> following "for" loop:
>
> X<-data.frame(1,1,1,1,1);
>
> for (i in 1:length(list)) {
>
>X[i,]<-unlist(list[[i]]);
>
> }
>
> Unfortunately, when the number of elements in the components of the 
> list
> are lower than 5 (maximum), I get errors or undesired results. I 
> also
> tried with rbind(), but again I couldn't manage to make it accept 
> rows
> of different length.
>
> Does anybody have any suggestions? Working with lists is very nice, 
> but
> I still have to learn how to transfer them to text files for 
> external
> use.
>
> Thnak you,
>
> Filippo Biscarini
> Wageningen University
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] controling omitted category in factor()

2007-04-03 Thread toby909
Hi All

How can I specify which category R should omit when running a linear model with 
categorical predictors? I saw it omits the first category by default, but I 
like 
to have the 3rd category omitted.

Thanks for your hints.

Toby

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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: protein class prediction in bioinformatics

2007-04-03 Thread Bing Xiong
Dear R members:
Sorry, this question is not tightly related to R software, but I 
usually use R to do this type thing. So please if you can help me out!
I want to predict a protein function, by through sequence alignment, I 
get several low identity sequences(say 100) in several classes(say 5 different 
classes), I have the Z-score for every sequence alignment, how to calculate the 
class prediction reliability? Thanks so much!!
 

regards,

Bing

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


Re: [R] converting a list to a data.frame

2007-04-03 Thread Stephen Tucker
You can concatenate a series of NA's to match the length of your longest
element.

(1) exampDat is example data
(2) max(rapply(exampDat,length)) is length of longest element
(3) function(x,m) will do the concatenation
(4) sapply() will return each list element as a column of a data frame
(5) t() will transpose it so you get it in row format (and convert it to a
matrix.

then you can use write() or write.table() to export your file to a text file.

exampDat <- list(x=1:2,y=1:3,z=1:4)
mat <- t(sapply(exampDat,
function(x,m) c(x,rep(NA,m-length(x))),
max(rapply(exampDat,length

## use write.table()

Hope this helps.

--- "Biscarini, Filippo" <[EMAIL PROTECTED]> wrote:

> Hello,
>  
> I have a list with n numerical components of different length (3, 4 or 5
> values in each component of the list); I need to export this as a text
> file where each component of the list will be a row and where missing
> values should fill in the blanks due to the different lengths of the
> components of the list.
> I think that as a first step I should convert my list to a data frame,
> but this is not such a simple task to accomplish: I was thinking of the
> following "for" loop:
>  
> X<-data.frame(1,1,1,1,1);
>  
> for (i in 1:length(list)) {
>  
> X[i,]<-unlist(list[[i]]);
>  
> }
>  
> Unfortunately, when the number of elements in the components of the list
> are lower than 5 (maximum), I get errors or undesired results. I also
> tried with rbind(), but again I couldn't manage to make it accept rows
> of different length.
>  
> Does anybody have any suggestions? Working with lists is very nice, but
> I still have to learn how to transfer them to text files for external
> use.
>  
> Thnak you,
>  
> Filippo Biscarini
> Wageningen University
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 



 

Don't pick lemons.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] approx with ties = 'ordered'

2007-04-03 Thread Vadim Ogranovich
Hi,

I am a bit surprised how approx resolves ties when ties = 'ordered'. In the
following two examples I'd expect the first expression to return 1 (not 2).

The documentation reads that "that 'f=0' is right-continuous and 'f=1' is
left-continuous" so one would expect  the argument to matter when resolving 
ties.

Thanks,
Vadim

->  approx(c(1,1), seq(2), 1, method = "const", rule = 2, f = 1, yleft = NA, 
ties
= "ordered")$y
[1] 2
->  approx(c(1,1), seq(2), 1, method = "const", rule = 2, f = 0, yleft = NA, 
ties
= "ordered")$y
[1] 2


-> version
   _   
platform   i486-pc-linux-gnu   
arch   i486
os linux-gnu   
system i486, linux-gnu 
status 
major  2   
minor  4.1 
year   2006
month  12  
day18  
svn rev40228   
language   R   
version.string R version 2.4.1 (2006-12-18)

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


Re: [R] Referencing function name from within function

2007-04-03 Thread Prof Brian Ripley
This presumes a function is always called by name.  Try

> lapply(1:10, myfunction)
Error in FUN(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)[[1]], ...) :
 FUN requires xyz!

to see a (simple case of) the problem.

On Tue, 3 Apr 2007, [EMAIL PROTECTED] wrote:

> I dunno much about such things, but a wee experiment seems to
> indicate that the following structure does what you want:
>
>myfunction <- function(x){
>nm <- as.character(match.call())[1]
>a  <- TRUE
>if (a){
>stop(paste(nm,"requires xyz!"))
>}
>}
>
>cheers,
>
>Rolf Turner
>[EMAIL PROTECTED]
>
> ===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===
> Original message:
>
>> For verbose coding I'd like to do something like:
>>> myfunction <- function(x){
>>>   if (a){
>>>   stop(paste(myfunction_name_here,"requires xyz!")
>>>   }
>> Is that possible?
>
>(Note:  In R *all* things are possible!)

I don't believe so.

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

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] confine a dataframe with a polygon

2007-04-03 Thread temiz
hello

how can I confine a dataframe with a known polygon that is part of whole 
data ?

regards

-- 
Ahmet Temiz


-- 
This message has been scanned for viruses and\ dangerous con...{{dropped}}

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


Re: [R] controling omitted category in factor()

2007-04-03 Thread Prof Brian Ripley
model.matrix() does this following the instructions you give it 
(ultimately via options("contrasts") about how to encode a factor variable 
(and this is also nothing to do with 'factor()', and factors have 'levels' 
not 'categories', a completely different concept in S but not used 
nowadays in R).

Without an example (see below) we cannot be sure, but probably you are 
using the default options setting of 'contr.treatment' and not specifying 
'contrasts' in your call to lm() (if indeed you are using lm()).  See its 
help page and that of 'relevel' for how to change the base level.

On Mon, 2 Apr 2007, [EMAIL PROTECTED] wrote:

> Hi All
>
> How can I specify which category R should omit when running a linear 
> model with categorical predictors? I saw it omits the first category by 
> default, but I like to have the 3rd category omitted.
>
> Thanks for your hints.

You seem to have the wrong ends of several ideas.  Please study 'An 
Introduction to R' and then a good book (and Chapter 6 of MASS4 is Dr 
Venables' definitive treatment of this area).

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


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

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Coding for contrasts in unbalanced designs

2007-04-03 Thread Guillaume Brutel
Sorry for possible cross posting but it seems that my previous message was send 
as HTML and then scrubbed.

Dear list members,

I want to use a GLM with an unbalanced factor and continuous variables.
My factor F has 12 unbalanced levels:
F=as.factor(c('A','B','C','C','C','C','D','D','D','D','D','D','E','E','E','E','E','E','F','G','G','H','I','I','J','J','J','K','L','L','L'))
> summary(F)
A B C D E F G H I J K L 
1 1 4 6 6 1 2 1 2 3 1 3

I thus want to code contrasts appropriatly.
I have looked in R documentations and R-help archives without finding the 
information for unbalanced designs.
Any help will be very useful.
Thanks you very much.
Guillaume Brutel.

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


Re: [R] Calculating DIC from MCMC output

2007-04-03 Thread Duncan Murdoch
On 4/2/2007 10:07 PM, Kyle Edwards wrote:
> Greetings all,
> 
> I'm a newcomer to Bayesian stats, and I'm trying to calculate the  
> Deviance Information Criterion "by hand" from some MCMC output.  
> However, having consulted several sources, I am left confused as to  
> the exact terms to use. The most common formula can be written as
> 
> DIC = 2*Mean(Deviance over the whole sampled posterior distribution)  
> - Deviance(Mean posterior parameter values)
> 
> However, I have also seen this as
> 
> DIC = 2*Mean(Deviance over the whole sampled posterior distribution)  
> - Min(Deviance over the whole sampled posterior)
> 
> Now, my understanding is that for some distributions, the deviance at  
> the parameter means will be equal to the minimum deviance (i.e. these  
> are the maximum likelihood parameter values). But, in other cases  
> this will not be true. I have also read that the choice of exactly  
> which point estimate of the parameters to use is somewhat arbitrary  
> (i.e. one could use the mean, the mode, the median). It would be much  
> easier for me to analyze this data if I can just use the formula with  
> Min(Deviance). Could anyone comment on the difference between these  
> and recommend the best course?

The Spiegelhalter et al (2002) gives both of those as possibilities, as 
well as the posterior median.  I don't have any experience with DIC to 
offer direct advice, but if you don't get any here, I can offer the 
indirect advice to ask on the BUGS mailing list, where David 
Spiegelhalter and Nicky Best are active.  There's also some advice here: 
.

Duncan Murdoch

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


Re: [R] Coding for contrasts in unbalanced designs

2007-04-03 Thread Peter Dalgaard
Guillaume Brutel wrote:
> Sorry for possible cross posting but it seems that my previous message was 
> send as HTML and then scrubbed.
>
> Dear list members,
>
> I want to use a GLM with an unbalanced factor and continuous variables.
> My factor F has 12 unbalanced levels:
> F=as.factor(c('A','B','C','C','C','C','D','D','D','D','D','D','E','E','E','E','E','E','F','G','G','H','I','I','J','J','J','K','L','L','L'))
>   
>> summary(F)
>> 
> A B C D E F G H I J K L 
> 1 1 4 6 6 1 2 1 2 3 1 3
>
> I thus want to code contrasts appropriatly.
> I have looked in R documentations and R-help archives without finding the 
> information for unbalanced designs.
> Any help will be very useful.
> Thanks you very much.
> Guillaume Brutel.
>
>   
Er, in which sense do you mean "code contrasts"? There are some
ambiguities relating to the use of the term "contrasts", so it isn't
possible to tell what it is that you need. Please give an example of
what you want to  do and explain why you think that it night come out
wrong when data are unbalanced.

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


-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] two-way anova nested fix effects issues

2007-04-03 Thread Hufkens Koen
Hi list,
 
I have some anova issues...
I have a dataset comprised of two factor values and a dependent value.
The factors are patchiness and within patchiness I have 4 treatments. 
So factor treatment is nested within factor patchiness. The dependent variable 
is a lenght.
 
If I'm not mistaken my model would be:
 
model <- aov(length ~ patchiness + patchiness/treatments)
 
However there are a few issues:
 
First, the design is unbalanced because of missing values
Second, the variances across the different treatments and patchiness levels is 
not equal (probably due to the patchiness level changes)
Third, the second parameter and the fact that the values are in a way discrete 
produce a non normal distribution and heteroscedacity in my residuals if is 
ignore everything and run the above model.
 
So is there still a way to tell if there is a difference in length for the 
different patchiness levels and treatments?
 
Kind regards,
Koen

-- 

Checked by AVG Free Edition.

5:32
 

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Coding for contrasts in unbalanced designs

2007-04-03 Thread Guillaume Brutel
In fact I want to test for the effects of multiple continuous and 
categorical variables (with GLMs) which are nested in the factor levels 
on a single continuous variable. Since the design is unbalanced, I 
though I had to specify it in the glm formula.



Guillaume Brutel wrote:
 > Sorry for possible cross posting but it seems that my previous 
message was send as HTML and then scrubbed.
 >
 > Dear list members,
 >
 > I want to use a GLM with an unbalanced factor and continuous variables.
 > My factor F has 12 unbalanced levels:
 > 
F=as.factor(c('A','B','C','C','C','C','D','D','D','D','D','D','E','E','E','E','E','E','F','G','G','H','I','I','J','J','J','K','L','L','L'))
 >
 >> summary(F)
 >>
 > A B C D E F G H I J K L
 > 1 1 4 6 6 1 2 1 2 3 1 3
 >
 > I thus want to code contrasts appropriatly.
 > I have looked in R documentations and R-help archives without finding 
the information for unbalanced designs.
 > Any help will be very useful.
 > Thanks you very much.
 > Guillaume Brutel.
 >
 >
Er, in which sense do you mean "code contrasts"? There are some
ambiguities relating to the use of the term "contrasts", so it isn't
possible to tell what it is that you need. Please give an example of
what you want to  do and explain why you think that it night come out
wrong when data are unbalanced.

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


-- 
O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 
35327918
~~ - (p.dalgaard at biostat.ku.dk)  FAX: (+45) 
35327907

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


Re: [R] Referencing function name from within function

2007-04-03 Thread Alberto Monteiro

Jim Holtman wrote:
> 
> > myfunction <- function(){
> + # some calculations
> + # now get my name
> + .caller <- sys.call()
> + cat(paste(as.character(.caller[[length(.caller)]]),"needs 
> 'xyz'\n")) + }
> > myfunction()
> myfunction needs 'xyz'
> >

I like this! It's even possible to know _which_ function
called myfunction and caused the 'disaster' (for bug tracking):

myfunction <- function() {
  # some calculations
  # oops, something wrong here
  call.stack <- sys.calls()
  n <- length(call.stack)
  cat(as.character(call.stack[[n]]), 
" crashed, called from ", 
as.character(call.stack[[n-1]]), "\n")
}

evil.function <- function() myfunction()

evil.function()

How can I get the _arguments_ to the calls? as.character strips
them :-/

Alberto Monteiro

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Strange labels on plot with dates

2007-04-03 Thread Henrik Andersson
Hello fellow R people,

I don't understand the default behavior of the axis labeling when 
plotting dates.

I would expect something like 2001, 2002 or possibly Jan 01, Jan 
02...Jan 06, but instead I only see Jan 01, Jan 01, Jan 01


See the following example

startdate <- strptime("2001-01-01",format="%Y-%m-%d")
enddate <- strptime("2006-12-31",format="%Y-%m-%d")
dates <- seq(startdate,enddate,by="month")

daynr <- as.numeric(julian(dates,origin=dates[1]))

yvar <- sin(daynr*2*pi/365)

plot(yvar~dates,type='l')

Cheers, Henrik

-- 
Henrik Andersson

Danish Meteorological Institute
Lyngbyvej 100
2100 Copenhagen Ø
Denmark
Tel: +45 39157215 
Email: [EMAIL PROTECTED]

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


Re: [R] Referencing function name from within function

2007-04-03 Thread Mark Wardle
Alberto Monteiro wrote:
> Jim Holtman wrote:
>>> myfunction <- function(){
>> + # some calculations
>> + # now get my name
>> + .caller <- sys.call()
>> + cat(paste(as.character(.caller[[length(.caller)]]),"needs 
>> 'xyz'\n")) + }
>>> myfunction()
>> myfunction needs 'xyz'
> 
> I like this! It's even possible to know _which_ function
> called myfunction and caused the 'disaster' (for bug tracking):
> 
> myfunction <- function() {
>   # some calculations
>   # oops, something wrong here
>   call.stack <- sys.calls()
>   n <- length(call.stack)
>   cat(as.character(call.stack[[n]]), 
> " crashed, called from ", 
> as.character(call.stack[[n-1]]), "\n")
> }
> 
> evil.function <- function() myfunction()
> 
> evil.function()
> 
> How can I get the _arguments_ to the calls? as.character strips
> them :-/
> 


?traceback


Or aren't you better off creating a custom error handler if you are
going to go this far?

Best wishes,

Mark

-- 
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK

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


Re: [R] Strange labels on plot with dates

2007-04-03 Thread Gabor Grothendieck
What version of R are you using?  When I copy and paste that into
R 2.4.1 on Windows XP I get 2001, 2002, ..., 2007

On 4/3/07, Henrik Andersson <[EMAIL PROTECTED]> wrote:
> Hello fellow R people,
>
> I don't understand the default behavior of the axis labeling when
> plotting dates.
>
> I would expect something like 2001, 2002 or possibly Jan 01, Jan
> 02...Jan 06, but instead I only see Jan 01, Jan 01, Jan 01
>
>
> See the following example
>
> startdate <- strptime("2001-01-01",format="%Y-%m-%d")
> enddate <- strptime("2006-12-31",format="%Y-%m-%d")
> dates <- seq(startdate,enddate,by="month")
>
> daynr <- as.numeric(julian(dates,origin=dates[1]))
>
> yvar <- sin(daynr*2*pi/365)
>
> plot(yvar~dates,type='l')
>
> Cheers, Henrik
>
> --
> Henrik Andersson
>
> Danish Meteorological Institute
> Lyngbyvej 100
> 2100 Copenhagen Ø
> Denmark
> Tel: +45 39157215
> Email: [EMAIL PROTECTED]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Strange labels on plot with dates

2007-04-03 Thread Henrik Andersson

Hmm,
I'm running 2.4.0 under linux


> sessionInfo()
R version 2.4.0 (2006-10-03)
i686-pc-linux-gnu

locale:
C

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


++
pdf("strange.pdf")
startdate <- strptime("2002-01-01",format="%Y-%m-%d")
enddate <- strptime("2006-12-31",format="%Y-%m-%d")
##enddate <- strptime("2002-12-31",format="%Y-%m-%d")
dates <- seq(startdate,enddate,by="week")

daynr <- as.numeric(julian(dates,origin=dates[1]))

yvar <- sin(daynr*2*pi/365)

plot(yvar~dates,type='l')
dev.off()

- Henrik

Gabor Grothendieck wrote:

What version of R are you using?  When I copy and paste that into
R 2.4.1 on Windows XP I get 2001, 2002, ..., 2007

On 4/3/07, Henrik Andersson <[EMAIL PROTECTED]> wrote:

Hello fellow R people,

I don't understand the default behavior of the axis labeling when
plotting dates.

I would expect something like 2001, 2002 or possibly Jan 01, Jan
02...Jan 06, but instead I only see Jan 01, Jan 01, Jan 01


See the following example

startdate <- strptime("2001-01-01",format="%Y-%m-%d")
enddate <- strptime("2006-12-31",format="%Y-%m-%d")
dates <- seq(startdate,enddate,by="month")

daynr <- as.numeric(julian(dates,origin=dates[1]))

yvar <- sin(daynr*2*pi/365)

plot(yvar~dates,type='l')

Cheers, Henrik

--
Henrik Andersson

Danish Meteorological Institute
Lyngbyvej 100
2100 Copenhagen Ø
Denmark
Tel: +45 39157215
Email: [EMAIL PROTECTED]

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

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




--
Henrik Andersson

Danish Meteorological Institute
Lyngbyvej 100
2100 Copenhagen Ø
Denmark
Tel: +45 39157215 
Email: [EMAIL PROTECTED]




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


Re: [R] Strange labels on plot with dates

2007-04-03 Thread Prof Brian Ripley
PLEASE do read the posting guide and give us the ouput it asks for.
Current R (2.5.0 alpha) does give 2001, 2002, ..., so you did not follow 
the request to update your R, I suspect.

On Tue, 3 Apr 2007, Henrik Andersson wrote:

> Hello fellow R people,
>
> I don't understand the default behavior of the axis labeling when
> plotting dates.
>
> I would expect something like 2001, 2002 or possibly Jan 01, Jan
> 02...Jan 06, but instead I only see Jan 01, Jan 01, Jan 01
>
>
> See the following example
>
> startdate <- strptime("2001-01-01",format="%Y-%m-%d")
> enddate <- strptime("2006-12-31",format="%Y-%m-%d")
> dates <- seq(startdate,enddate,by="month")
>
> daynr <- as.numeric(julian(dates,origin=dates[1]))
>
> yvar <- sin(daynr*2*pi/365)
>
> plot(yvar~dates,type='l')
>
> Cheers, Henrik
>
>

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

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


Re: [R] strange fisher.test result

2007-04-03 Thread Thomas Lumley
On Mon, 2 Apr 2007, [EMAIL PROTECTED] wrote:
>
>> From the above, the marginal totals for his 2x2 table
>
>  a   b   =   168
>
>  c   d   15   24
>
> are (rows then columns) 24,39,31,32
>
> These fixed marginals mean that the whole table is determined
> by the value of a. The following function P.FX() computes the
> probabilities of all possible tables, conditional on the
> marginal totals (it is much more transparent than the code
> for the same purpose in fisher.test()):

As this example has shown, 2x2 tables are a nice opportunity for 
illustrating how the ordering of the sample space affects inference 
(because you can actually see the whole sample space).

I used something like this as a term project in an introductory R class, 
where we wrote code to compute the probabilities for all outcomes 
conditional on one margin, and used this to get (conservative) exact 
versions of all the popular tests in 2x2 tables.  It's interesting to do 
things like compare the rejection regions and power under various 
alternatives for the exact versions of the likelihood ratio test and 
Fisher's test.  We didn't get as far as confidence intervals, but the code 
is at
http://faculty.washington.edu/tlumley/b514/exacttest.R
with .Rd files at
http://faculty.washington.edu/tlumley/b514/man/

[credits: this is all based on ideas from Scott Emerson]


-thomas

Thomas Lumley   Assoc. Professor, Biostatistics
[EMAIL PROTECTED]   University of Washington, Seattle

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] which points within an ellipsoid? Sorting data in 3d

2007-04-03 Thread Kim Milferstedt
Hello,

in a three dimensional coordinate system, I'd like to find all my 
experimental data points that fall within an ellipsoid around a fixed 
coordinate. The fixed point is defined by (x.coord.point, 
y.coord.point, z.coord.point). The coordinates of the ellipsoid are 
given by the three vectors x,y,z.

In a previous version of my code, I simply used a box instead of an 
ellipsoid to sort my data, which was really easy as I only had to 
compare each data point to three coordinates. I used something like this...

XYZ.within <- which( x.data  < x.coord.point + multipl &
  x.data  > x.coord.point - multipl &
  y.data  < y.coord.point + multipl &
  y.data  > y.coord.point - multipl &
z.data  < z.coord.point + multipl &
  z.data  > z.coord.point - multipl
 )

But now I have many more coordinate sets to compare my data to. How 
can I find out in an efficient way which of the data points lie 
within the ellipsoid?

Thanks!

Kim

#mock-data for the display with rgl
data.1 <- xyz.coords(5,-2,17)
data.2 <- xyz.coords(15, -10,18)
data.3 <- xyz.coords(-19, 13,9)

#code I use to construct the ellipsoid
x.coord.point <- 4
y.coord.point <- -7
z.coord.point <- -3

radius <- 8
x.radius.multiplier <- 1
y.radius.multiplier <- 2
z.radius.multiplier <- 3

endpoint <- 350
interval <- 2
alpha <- rep(seq(0,endpoint, by 
=interval),rep((endpoint+interval)/interval,(endpoint+interval)/interval))
beta <- c(rep(seq(0,endpoint, by =interval),(endpoint+interval)/interval))

x <- 
x.coord.point+(x.radius.multiplier*radius)*cos(alpha*pi/180)*sin(beta*pi/180)
y <- y.coord.point+(y.radius.multiplier*radius)*sin(alpha*pi/180)
z <- 
z.coord.point+(z.radius.multiplier*radius)*cos(alpha*pi/180)*cos(beta*pi/180)

# using rlg to visualize the mock-data and the ellipsoid
plot.lim <- c(-20,20)
plot3d(x, y, z,
 xlim = plot.lim,
 ylim = plot.lim,
 zlim = plot.lim
 )
points3d(data.1, col ="green", size = 6)
points3d(data.2, col ="red", size = 6)
points3d(data.3, col ="blue", size = 6)

__

Kim Milferstedt
University of Illinois at Urbana-Champaign
Department of Civil and Environmental Engineering
4125 Newmark Civil Engineering Laboratory
205 North Mathews Avenue MC-250
Urbana, IL 61801
USA
phone: (001) 217 333-9663
fax: (001) 217 333-6968
email: [EMAIL PROTECTED]
http://cee.uiuc.edu/research/morgenroth

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


Re: [R] confine a dataframe with a polygon

2007-04-03 Thread Roger Bivand
On Tue, 3 Apr 2007, temiz wrote:

> hello
> 
> how can I confine a dataframe with a known polygon that is part of whole 
> data ?

Could I suggest following up this question on the R-sig-geo list? It is 
not clear what you want to do - are the rows in the data frame points 
which may lie inside or outside a polygon? If so, the overlay() methods in 
the sp package may be suitable.

> 
> regards
> 
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [EMAIL PROTECTED]

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


Re: [R] Generate a serie of new vars that correlate with existing var

2007-04-03 Thread Greg Snow
Here is one way to do it:

# create the initial x variable
x1 <- rnorm(100, 15, 5)

# x2, x3, and x4 in a matrix, these will be modified to meet the
criteria
x234 <- scale(matrix( rnorm(300), ncol=3 ))

# put all into 1 matrix for simplicity
x1234 <- cbind(scale(x1),x234)

# find the current correlation matrix
c1 <- var(x1234)

# cholesky decomposition to get independence
chol1 <- solve(chol(c1))

newx <-  x1234 %*% chol1 

# check that we have independence and x1 unchanged
zapsmall(cor(newx))
all.equal( x1234[,1], newx[,1] )

# create new correlation structure (zeros can be replaced with other r
vals)
newc <- matrix( 
c(1  , 0.4, 0.5, 0.6, 
  0.4, 1  , 0  , 0  ,
  0.5, 0  , 1  , 0  ,
  0.6, 0  , 0  , 1  ), ncol=4 )

# check that it is positive definite
eigen(newc)

chol2 <- chol(newc)

finalx <- newx %*% chol2 * sd(x1) + mean(x1)

# verify success
mean(x1)
colMeans(finalx)

sd(x1)
apply(finalx, 2, sd)

zapsmall(cor(finalx))
pairs(finalx)

all.equal(x1, finalx[,1])


Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Nguyen 
> Dinh Nguyen
> Sent: Sunday, April 01, 2007 7:47 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Generate a serie of new vars that correlate with 
> existing var
> 
> Dear R helpers,
> I have a var (let call X1) with approximately Normal 
> distribution (say, mean=15, SD=5).
> I want to generate a series of additional vars X2, X3, 
> X4...such that the correlation between X2 and X1 is o.4, X3 and 
> X1 is 0.5, X4 and X1 is 0.6 and so on with the condition all 
> variables X2, X3, X4have the same mean and SD with X1.
> Any help should be appreciated
> Regards
> Nguyen
> 
>

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


Re: [R] which points within an ellipsoid? Sorting data in 3d

2007-04-03 Thread Greg Snow
I don't understand how the x,y,z vectors define the ellipsoid, but one
approach would be:

Find a 3x3 matrix that represents the ellipsoid as a variance matrix
(some of the code in the ellipse package may be informative for this).

Subtract x.coord.point, y.coord.point, and z.coord.point from your data.

Post multiply the data (in an nx3 matrix) with the inverse of the
cholesky decomposition of the above variance matrix (this should convert
your data on the scale of the ellipsoid to be now based on the unit
sphere).

Find x^2+y^2+z^2 (where x,y,z are the transformed coordinates of your
points) which will be the distance of each point from 0, any values < 1
correspond to points originally within the ellipsoid, >1 outside the
ellipsoid.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Kim Milferstedt
> Sent: Tuesday, April 03, 2007 9:16 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] which points within an ellipsoid? Sorting data in 3d
> 
> Hello,
> 
> in a three dimensional coordinate system, I'd like to find 
> all my experimental data points that fall within an ellipsoid 
> around a fixed coordinate. The fixed point is defined by 
> (x.coord.point, y.coord.point, z.coord.point). The 
> coordinates of the ellipsoid are given by the three vectors x,y,z.
> 
> In a previous version of my code, I simply used a box instead 
> of an ellipsoid to sort my data, which was really easy as I 
> only had to compare each data point to three coordinates. I 
> used something like this...
> 
> XYZ.within <- which( x.data  < x.coord.point + multipl &
>   x.data  > x.coord.point - multipl &
>   y.data  < y.coord.point + multipl &
>   y.data  > y.coord.point - multipl &
> z.data  < z.coord.point + multipl &
>   z.data  > z.coord.point - multipl
>  )
> 
> But now I have many more coordinate sets to compare my data 
> to. How can I find out in an efficient way which of the data 
> points lie within the ellipsoid?
> 
> Thanks!
> 
> Kim
> 
> #mock-data for the display with rgl
> data.1 <- xyz.coords(5,-2,17)
> data.2 <- xyz.coords(15, -10,18)
> data.3 <- xyz.coords(-19, 13,9)
> 
> #code I use to construct the ellipsoid
> x.coord.point <- 4
> y.coord.point <- -7
> z.coord.point <- -3
> 
> radius <- 8
> x.radius.multiplier <- 1
> y.radius.multiplier <- 2
> z.radius.multiplier <- 3
> 
> endpoint <- 350
> interval <- 2
> alpha <- rep(seq(0,endpoint, by
> =interval),rep((endpoint+interval)/interval,(endpoint+interval
> )/interval))
> beta <- c(rep(seq(0,endpoint, by 
> =interval),(endpoint+interval)/interval))
> 
> x <-
> x.coord.point+(x.radius.multiplier*radius)*cos(alpha*pi/180)*s
> in(beta*pi/180)
> y <- y.coord.point+(y.radius.multiplier*radius)*sin(alpha*pi/180)
> z <-
> z.coord.point+(z.radius.multiplier*radius)*cos(alpha*pi/180)*c
> os(beta*pi/180)
> 
> # using rlg to visualize the mock-data and the ellipsoid 
> plot.lim <- c(-20,20) plot3d(x, y, z,
>  xlim = plot.lim,
>  ylim = plot.lim,
>  zlim = plot.lim
>  )
> points3d(data.1, col ="green", size = 6) points3d(data.2, col 
> ="red", size = 6) points3d(data.3, col ="blue", size = 6)
> 
> __
> 
> Kim Milferstedt
> University of Illinois at Urbana-Champaign Department of 
> Civil and Environmental Engineering
> 4125 Newmark Civil Engineering Laboratory
> 205 North Mathews Avenue MC-250
> Urbana, IL 61801
> USA
> phone: (001) 217 333-9663
> fax: (001) 217 333-6968
> email: [EMAIL PROTECTED]
> http://cee.uiuc.edu/research/morgenroth
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] strange fisher.test result

2007-04-03 Thread Peter Dalgaard
Thomas Lumley wrote:
> On Mon, 2 Apr 2007, [EMAIL PROTECTED] wrote:
>   
>>> From the above, the marginal totals for his 2x2 table
>>>   
>>  a   b   =   168
>>
>>  c   d   15   24
>>
>> are (rows then columns) 24,39,31,32
>>
>> These fixed marginals mean that the whole table is determined
>> by the value of a. The following function P.FX() computes the
>> probabilities of all possible tables, conditional on the
>> marginal totals (it is much more transparent than the code
>> for the same purpose in fisher.test()):
>> 
>
> As this example has shown, 2x2 tables are a nice opportunity for 
> illustrating how the ordering of the sample space affects inference 
> (because you can actually see the whole sample space).
>
> I used something like this as a term project in an introductory R class, 
> where we wrote code to compute the probabilities for all outcomes 
> conditional on one margin, and used this to get (conservative) exact 
> versions of all the popular tests in 2x2 tables.  It's interesting to do 
> things like compare the rejection regions and power under various 
> alternatives for the exact versions of the likelihood ratio test and 
> Fisher's test.  We didn't get as far as confidence intervals, but the code 
> is at
> http://faculty.washington.edu/tlumley/b514/exacttest.R
> with .Rd files at 
> http://faculty.washington.edu/tlumley/b514/man/
>   
The effect is already visible with binomial tests. In fact the last 
exercise in the section on categorical data in Introductory Statistics 
with R currently reads (the \Answer section is not in the actual book -- 
yet):

 Make a plot of the two-sided $p$ value for
  testing that the probability parameter is $x$ when the observations
  are 3 successes in 15 trials, for $x$ varying from 0 to 1 in steps of
  0.001. Explain what makes the definition of a two-sided confidence
  interval difficult.
 
  \Answer The curve shows substantial discontinuities where
  probability mass is shifted from one tail to the other, and also a
  number of local minima. A confidence region could be defined as
  those $p$ that there is no significant evidence against at level
  $\alpha$, but for some $\alpha$, that is not an interval.

   p <- seq(0,1,0.001)
   pval <- sapply(p,function(p)binom.test(3,15,p=p)$p.value)
   plot(p,pval,type="l")

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


Re: [R] Referencing function name from within function

2007-04-03 Thread rolf
Wott about this then?

myfunction <- function(x){
temp <- sys.calls()[[1]]
nm <- temp[length(temp)]
a  <- TRUE
if (a){
stop(paste(nm,"requires xyz!"))
}
}

> myfunction()
Error in myfunction() : myfunction requires xyz!

> lapply(1:10,myfunction)
Error in FUN(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)[[1]], ...) : 
myfunction requires xyz!

cheers,

Rolf Turner
[EMAIL PROTECTED]

===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===
Prof Brian Ripley wrote:

> This presumes a function is always called by name.  Try
> 
> > lapply(1:10, myfunction)
> Error in FUN(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)[[1]], ...) :
>  FUN requires xyz!
> 
> to see a (simple case of) the problem.
> 
> On Tue, 3 Apr 2007, [EMAIL PROTECTED] wrote:
> 
> > I dunno much about such things, but a wee experiment seems to
> > indicate that the following structure does what you want:
> >
> >myfunction <- function(x){
> >nm <- as.character(match.call())[1]
> >a  <- TRUE
> >if (a){
> >stop(paste(nm,"requires xyz!"))
> >}
> >}
> >
> >cheers,
> >
> >Rolf Turner
> >[EMAIL PROTECTED]
> >
> > ===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===
> > Original message:
> >
> >> For verbose coding I'd like to do something like:
> >>> myfunction <- function(x){
> >>>   if (a){
> >>>   stop(paste(myfunction_name_here,"requires xyz!")
> >>>   }
> >> Is that possible?
> >
> >(Note:  In R *all* things are possible!)
> 
> I don't believe so.

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

2007-04-03 Thread HelponR
Hi, Anybody used treenet here? I downloaded a demo but don't know how to
start with. Does R has something like treenet? Thanks,

[[alternative HTML version deleted]]

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


Re: [R] Testing additive nonparametric model

2007-04-03 Thread Donal O'Neill

   Dear Vito,
   Thank you for your prompt reply. Perhaps I am missing something but as
   I  understand  it the procedure you suggest would allow me to test for
   nonlinearities  in  one of the control variables. However my objective
   is to nonparametrically test whether the nature of the nonlinearity in
   one  variable  is  constant across all values of a second conditioning
   variable.  That is I want to test y=f(x1,x2)+e against y=f1(x1)+f2(x2)
   + u
   I tried
   library(mgcv)
   mod.1<-gam(y~s(x1)+s(x2))
   mod.2<-loess(y~x1+x2, f=**, iter=**), lwd=**)
   anova(mod.1, mod.2)
   but got the following error message
   Error in s^2 : non-numeric argument to binary operator
   Any suggestions would be welcome.
   Donal.
   At 11:43 03/04/2007 +0200, vito muggeo wrote:

 You  can use the LRT (although I think that it assumes the df to be
 fixed).  For  instance  the package mgcv by Simon Wood has an anova
 method to compare models fitted by the relevant gam() function, and
 the print.summary() itself returns such information..
 best,
 vito
 set.seed(123)
 n<-100
 sig<-2
 x0 <- runif(n, 0, 1)
 x1 <- runif(n, 0, 1)
 y <- sin(2*pi*x0) + .5*x1 +sig*rnorm(n)
 library(mgcv)
 obj<-gam(y~s(x0)+s(x1))
 obj1<-gam(y~s(x0)+x1)
 anova(obj1,obj,test="F")
 #also see the "Approximate significance of smooth terms"
 summary(obj)
 Donal O'Neill wrote:

 I  have  estimated  a  multiple  nonparametric regression using the
 loess  command  in  R. I have also estimated an additive version of
 the  model  using  the  gam  function.  Is there a way of using the
 output  of these two models to test the restrictions imposed by the
 additive model?
 __
 R-help@stat.math.ethz.ch mailing list
 [1]https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 [2]http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

 --
 
 Vito M.R. Muggeo
 Dip.to Sc Statist e Matem `Vianelli'
 Università di Palermo
 viale delle Scienze, edificio 13
 90128 Palermo - ITALY
 tel: 091 6626240
 fax: 091 485726/485612
 

References

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


Re: [R] the numimum number of fixed factors lme package can deal with

2007-04-03 Thread Douglas Bates
On 4/3/07, Fang, Yongxiang <[EMAIL PROTECTED]> wrote:

> In my study, mixed effects model is required and the number of fixed
> effects is very large. When lme package is employed, a model error is
> displayed once the number of fixed  factors in the formula reaches 200. Is
> this the maximum number of fixed factors can be handled by lme package?
> If not, what is possible reason of the error message?

What error message?  You didn't tell use what you did and what
happened.  Please read and follow the instructions in the posting
guide - otherwise we will only be able to guess at what the problem
may be.

There is no specific limit of 200 fixed factors (perhaps you mean 200
columns in the model matrix for the fixed effects?) in lme.  However
there will be limits on the amount of memory available to store the
model matrices and associated structures needed to fit the model.

The first thing I would suggest is determining why you want to fit a
model with 200 (or possibly more if you really meant 200 fixed
factors) fixed effects.  It is rare to want to examine such a large
number of coefficients.  Frequently the number of coefficients gets to
this order because you have a factor with a large number of levels, in
which case why not model such a factor with random effects?

You could also try using the lmer function from the lme4 package
instead of lme to fit a linear mixed model.  It is generally more
efficient than lme in both time and storage.

However, before we can help you much you will need to be much more
specific in your question and provide us with the recommended
background information.

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


Re: [R] lmer, CHOLMOD warning: matrix not positive definite

2007-04-03 Thread Douglas Bates
On 4/2/07, Seyed Reza Jafarzadeh <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am getting a warning message when I am fitting a generalized linear
> mixed model (m1.2 below).
>
>
> CHOLMOD warning: matrix not positive definite
>  Error in objective(.par, ...) : Cholmod error `matrix not positive
> definite' at file:../Supernodal/t_cholmod_super_numeric.c, line 614
>
>
> Any idea?
>
> Thanks for your help,
> Reza
>
>
>
>  > sessionInfo()
> R version 2.4.1 (2006-12-18)
>  i386-pc-mingw32
>
> locale:
>  LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
> States.1252;LC_MONETARY=English_United
> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>
> attached base packages:
>  [1] "stats" "graphics"  "grDevices" "utils" "datasets"
> "methods"   "base"
>
>  other attached packages:
>lme4  Matrix lattice
> "0.9975-13" "0.9975-11"   "0.14-17"
>
>
>  > m1.1 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (1 |
> prov) + (1 | pm), data = mydata[1:1392,], family = quasipoisson)
>  > m1.1
> Generalized linear mixed model fit using Laplace
>  Formula: o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (1 | prov) + (1 | pm)
>Data: mydata[1:1392, ]
>  Family: quasipoisson(log link)
>   AIC  BIC logLik deviance
>  2622 2675  -1301 2602
> Random effects:
>  Groups   NameVariance Std.Dev.
>  prov (Intercept) 0.495021 0.70358
>  pm   (Intercept) 0.047755 0.21853
>  Residual 1.935867 1.39135
> number of obs: 1392, groups: prov, 24; pm, 12
>
> Fixed effects:
>  Estimate Std. Error t value
> (Intercept) -0.207562   0.202715  -1.024
>  pv1o 0.056575   0.006861   8.246
> pv2o 0.023042   0.007216   3.193
>  pv1toa   0.026497   0.003309   8.008
> pv2toa  -0.001075   0.003467   -0.310
> sesblf2  0.307805   0.195291   1.576
>  sesblf3  0.067867   0.194097   0.350
> sesblf4  0.232652   0.194075   1.199
>
> Correlation of Fixed Effects:
>  (Intr) pv1o   pv2o   pv1toa pv2toa ssblf2 ssblf3
> pv1o 0.035
> pv2o-0.014 -0.568
>  pv1toa   0.017 -0.239  0.050
> pv2toa  -0.104  0.035 -0.267 -0.772
> sesblf2 -0.498 -0.038  0.037 -0.067  0.102
>  sesblf3 -0.483 -0.042  0.021 -0.096  0.085  0.508
> sesblf4 -0.483 -0.052  0.029 -0.099  0.083  0.508  0.518
>
>
> > m1.2 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (pv1o | prov) + 
> > (1 | pm), data = mydata[1:1392,], family = quasipoisson)
> CHOLMOD warning: matrix not positive definite
>  Error in objective(.par, ...) : Cholmod error `matrix not positive
> definite' at file:../Supernodal/t_cholmod_super_numeric.c, line 614
>
>
> > m1.3 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (pv1toa | prov) + 
> > (1 | pm), data = mydata[1:1392,], family = quasipoisson)
> > m1.3
> Generalized linear mixed model fit using Laplace
> Formula: o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (pv1toa | prov)
> +  (1 | pm)
>Data: mydata[1:1392, ]
>  Family: quasipoisson(log link)
>   AIC  BIC logLik deviance
>  2459 2522  -1218 2435
> Random effects:
>  Groups   NameVariance   Std.Dev. Corr
>  prov (Intercept) 0.88071235 0.938463
>   pv1toa  0.00065327 0.025559 -0.712
>  pm   (Intercept) 0.04588791 0.214215
>  Residual 1.76873748 1.329939
> number of obs: 1392, groups: prov, 24; pm, 12
>
> Fixed effects:
>   Estimate Std. Error t value
> (Intercept) -0.3854583  0.2384690  -1.616
> pv1o 0.0545945  0.0069507   7.855
> pv2o 0.0266912  0.0072733   3.670
> pv1toa   0.0369315  0.0063083   5.854
> pv2toa  -0.0008906  0.0034099  -0.261
> sesblf2  0.3326815  0.1908401   1.743
> sesblf3  0.1012759  0.1896883   0.534
> sesblf4  0.1968002  0.1899092   1.036
>
> Correlation of Fixed Effects:
> (Intr) pv1o   pv2o   pv1toa pv2toa ssblf2 ssblf3
> pv1o 0.016
> pv2o-0.023 -0.306
> pv1toa  -0.485 -0.143 -0.014
> pv2toa  -0.080 -0.055 -0.306 -0.367
> sesblf2 -0.414 -0.037  0.033 -0.028  0.099
> sesblf3 -0.402 -0.034  0.027 -0.046  0.080  0.509
> sesblf4 -0.399 -0.039  0.031 -0.056  0.079  0.507  0.517

Thanks for including the information that you did.  Would you be kind
enough to rerun the model that failed with the additional argument
control = list(msVerbose = 1).  That will help to show exactly what is
happening to the parameter estimates in the model during the course of
the iterations.

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


Re: [R] Coding for contrasts in unbalanced designs

2007-04-03 Thread Peter Dalgaard
Guillaume Brutel wrote:
> In fact I want to test for the effects of multiple continuous and 
> categorical variables (with GLMs) which are nested in the factor levels 
> on a single continuous variable. Since the design is unbalanced, I 
> though I had to specify it in the glm formula.
>
>   
That didn't make me any wiser... What is the model and which hypotheses 
do you wish to test?
>
> Guillaume Brutel wrote:
>  > Sorry for possible cross posting but it seems that my previous 
> message was send as HTML and then scrubbed.
>  >
>  > Dear list members,
>  >
>  > I want to use a GLM with an unbalanced factor and continuous variables.
>  > My factor F has 12 unbalanced levels:
>  > 
> F=as.factor(c('A','B','C','C','C','C','D','D','D','D','D','D','E','E','E','E','E','E','F','G','G','H','I','I','J','J','J','K','L','L','L'))
>  >
>  >> summary(F)
>  >>
>  > A B C D E F G H I J K L
>  > 1 1 4 6 6 1 2 1 2 3 1 3
>  >
>  > I thus want to code contrasts appropriatly.
>  > I have looked in R documentations and R-help archives without finding 
> the information for unbalanced designs.
>  > Any help will be very useful.
>  > Thanks you very much.
>  > Guillaume Brutel.
>  >
>  >
> Er, in which sense do you mean "code contrasts"? There are some
> ambiguities relating to the use of the term "contrasts", so it isn't
> possible to tell what it is that you need. Please give an example of
> what you want to  do and explain why you think that it night come out
> wrong when data are unbalanced.
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Testing random effect in logistic mixed model

2007-04-03 Thread Julien
Hi
When using linear mixed model, I could test for the effect of the random
part of the model using a likelihood ratio test comparing two model with and
without the random part.

model.lmer=lmer(y~x+(1|r))
model.lm = lm(y~x)
anova(model.lmer,model.lm)

However, this does not work with a mixed model with binomial or poisson
distribution

> model.lmer = lmer(z~x+(1|r),family=binomial)
> model.glm =  glm(z~x,family=binomial)
> anova(model.lmer,model.glm)
 Erreur dans FUN(X[[1]], ...) : aucun slot de nom "call" pour cet objet de
la classe "glm"
De plus : Warning message:
arguments supplémentaires ignorés in: logLik.glm(X[[2]], ...)

My question is how cold I test for a random effect in logistic mixed model
because the anova function does not work here?

Thanks

Julien Martin

-- 



12:48

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


Re: [R] treenet

2007-04-03 Thread Weiwei Shi
gbm package if I am right.

On 4/3/07, HelponR <[EMAIL PROTECTED]> wrote:
> Hi, Anybody used treenet here? I downloaded a demo but don't know how to
> start with. Does R has something like treenet? Thanks,
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Weiwei Shi, Ph.D
Research Scientist
GeneGO, Inc.

"Did you always know?"
"No, I did not. But I believed..."
---Matrix III

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] problems with residuals of an arima model

2007-04-03 Thread Katharina Vedovelli
Hi all!

I want to fit a time series with 17376 values by using the arima() function.

If I extract the residuals from the fitted model there are values for the
residuals 1 to 710 but the residuals 711 to 17376 have the value NA.
Does anybody know what the problem could be? Is the function arima()
restricted to a maximum length of the underlying time series?

Besides, is there a better possibility to get the fitted values from an
arima model than using the residuals?

It would be great if somebody could help me!

Thanks a lot in advance...
Cheers,
Katharina

[[alternative HTML version deleted]]

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


Re: [R] lmer, CHOLMOD warning: matrix not positive definite

2007-04-03 Thread Seyed Reza Jafarzadeh
Dear Douglas Bates,

Thanks for your attention. Please see the warnings with additional
control argument for the models that failed.


> m1.2 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (pv1o | prov) + (1 
> | pm), data = mydata[1:1392,], family = quasipoisson, control = 
> list(msVerbose = 1))
relative tolerance set to 3.97418414349626e-06
  0  2516.24: -0.0343767 0.0799244 0.0463578 0.0173111 -0.00385332
0.330649 0.0896930 0.185739 0.0459770 0.00241710  0.0 0.0229885
CHOLMOD warning: matrix not positive definite
Error in objective(.par, ...) : Cholmod error `matrix not positive
definite' at file:../Supernodal/t_cholmod_super_numeric.c, line 614


> m1.4 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (1 | prov) + (pv1o 
> | pm), data = mydata[1:1392,], family = quasipoisson, control = 
> list(msVerbose = 1))
relative tolerance set to 3.82209043930558e-06
  0  2616.37: -0.0343767 0.0799244 0.0463578 0.0173111 -0.00385332
0.330649 0.0896930 0.185739 0.0459770 0.0229885 0.00120855  0.0
CHOLMOD warning: matrix not positive definite
Error in objective(.par, ...) : Cholmod error `matrix not positive
definite' at file:../Supernodal/t_cholmod_super_numeric.c, line 614


> m1.6 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (pv1o | prov) + 
> (pv1o | pm), data = mydata[1:1392,], family = quasipoisson, control = 
> list(msVerbose = 1))
relative tolerance set to 4.08445979897786e-06
  0  2448.30: -0.0343767 0.0799244 0.0463578 0.0173111 -0.00385332
0.330649 0.0896930 0.185739 0.0459770 0.00241710  0.0 0.0229885
0.00120855  0.0
CHOLMOD warning: matrix not positive definite
Error in objective(.par, ...) : Cholmod error `matrix not positive
definite' at file:../Supernodal/t_cholmod_super_numeric.c, line 614


> m1.23 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (pv1toa | pm), 
> data =  mydata[1:1392, ], family = quasipoisson, control = list(msVerbose = 
> 1))
relative tolerance set to 3.35608419754339e-06
  0  2979.66: -0.0343767 0.0799244 0.0463578 0.0173111 -0.00385332
0.330649 0.0896930 0.185739 0.0229885 7.10587e-05  0.0
CHOLMOD warning: matrix not positive definite
Error in objective(.par, ...) : Cholmod error `matrix not positive
definite' at file:../Supernodal/t_cholmod_super_numeric.c, line 614


Thanks,
Reza



On 4/3/07, Douglas Bates <[EMAIL PROTECTED]> wrote:
> On 4/2/07, Seyed Reza Jafarzadeh <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I am getting a warning message when I am fitting a generalized linear
> > mixed model (m1.2 below).
> >
> >
> > CHOLMOD warning: matrix not positive definite
> >  Error in objective(.par, ...) : Cholmod error `matrix not positive
> > definite' at file:../Supernodal/t_cholmod_super_numeric.c, line 614
> >
> >
> > Any idea?
> >
> > Thanks for your help,
> > Reza
> >
> >
> >
> >  > sessionInfo()
> > R version 2.4.1 (2006-12-18)
> >  i386-pc-mingw32
> >
> > locale:
> >  LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
> > States.1252;LC_MONETARY=English_United
> > States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
> >
> > attached base packages:
> >  [1] "stats" "graphics"  "grDevices" "utils" "datasets"
> > "methods"   "base"
> >
> >  other attached packages:
> >lme4  Matrix lattice
> > "0.9975-13" "0.9975-11"   "0.14-17"
> >
> >
> >  > m1.1 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (1 |
> > prov) + (1 | pm), data = mydata[1:1392,], family = quasipoisson)
> >  > m1.1
> > Generalized linear mixed model fit using Laplace
> >  Formula: o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (1 | prov) + (1 | pm)
> >Data: mydata[1:1392, ]
> >  Family: quasipoisson(log link)
> >   AIC  BIC logLik deviance
> >  2622 2675  -1301 2602
> > Random effects:
> >  Groups   NameVariance Std.Dev.
> >  prov (Intercept) 0.495021 0.70358
> >  pm   (Intercept) 0.047755 0.21853
> >  Residual 1.935867 1.39135
> > number of obs: 1392, groups: prov, 24; pm, 12
> >
> > Fixed effects:
> >  Estimate Std. Error t value
> > (Intercept) -0.207562   0.202715  -1.024
> >  pv1o 0.056575   0.006861   8.246
> > pv2o 0.023042   0.007216   3.193
> >  pv1toa   0.026497   0.003309   8.008
> > pv2toa  -0.001075   0.003467   -0.310
> > sesblf2  0.307805   0.195291   1.576
> >  sesblf3  0.067867   0.194097   0.350
> > sesblf4  0.232652   0.194075   1.199
> >
> > Correlation of Fixed Effects:
> >  (Intr) pv1o   pv2o   pv1toa pv2toa ssblf2 ssblf3
> > pv1o 0.035
> > pv2o-0.014 -0.568
> >  pv1toa   0.017 -0.239  0.050
> > pv2toa  -0.104  0.035 -0.267 -0.772
> > sesblf2 -0.498 -0.038  0.037 -0.067  0.102
> >  sesblf3 -0.483 -0.042  0.021 -0.096  0.085  0.508
> > sesblf4 -0.483 -0.052  0.029 -0.099  0.083  0.508  0.518
> >
> >
> > > m1.2 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (pv1o | prov) + 
> > > (1 | pm), data = mydata[1:1392,], family = quasipoisson)
> > CHOLMOD warning: matrix not positive definite

Re: [R] Generate a serie of new vars that correlate with existing var

2007-04-03 Thread Nguyen Dinh Nguyen
Dear Greg,
Thanks million!
"As good as it gets" :)
All the best
Nguyen

-Original Message-
From: Greg Snow [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 04, 2007 1:46 AM
To: Nguyen Dinh Nguyen; r-help@stat.math.ethz.ch
Subject: RE: [R] Generate a serie of new vars that correlate with existing
var

Here is one way to do it:

# create the initial x variable
x1 <- rnorm(100, 15, 5)

# x2, x3, and x4 in a matrix, these will be modified to meet the
criteria
x234 <- scale(matrix( rnorm(300), ncol=3 ))

# put all into 1 matrix for simplicity
x1234 <- cbind(scale(x1),x234)

# find the current correlation matrix
c1 <- var(x1234)

# cholesky decomposition to get independence
chol1 <- solve(chol(c1))

newx <-  x1234 %*% chol1 

# check that we have independence and x1 unchanged
zapsmall(cor(newx))
all.equal( x1234[,1], newx[,1] )

# create new correlation structure (zeros can be replaced with other r
vals)
newc <- matrix( 
c(1  , 0.4, 0.5, 0.6, 
  0.4, 1  , 0  , 0  ,
  0.5, 0  , 1  , 0  ,
  0.6, 0  , 0  , 1  ), ncol=4 )

# check that it is positive definite
eigen(newc)

chol2 <- chol(newc)

finalx <- newx %*% chol2 * sd(x1) + mean(x1)

# verify success
mean(x1)
colMeans(finalx)

sd(x1)
apply(finalx, 2, sd)

zapsmall(cor(finalx))
pairs(finalx)

all.equal(x1, finalx[,1])


Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Nguyen 
> Dinh Nguyen
> Sent: Sunday, April 01, 2007 7:47 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Generate a serie of new vars that correlate with 
> existing var
> 
> Dear R helpers,
> I have a var (let call X1) with approximately Normal 
> distribution (say, mean=15, SD=5).
> I want to generate a series of additional vars X2, X3, 
> X4...such that the correlation between X2 and X1 is o.4, X3 and 
> X1 is 0.5, X4 and X1 is 0.6 and so on with the condition all 
> variables X2, X3, X4have the same mean and SD with X1.
> Any help should be appreciated
> Regards
> Nguyen
> 
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Optimization and simulation

2007-04-03 Thread Jin Huang
Dear all,
   
  I would need to maximize a self-defined 'target' function(see below) with 
respect to theta, where v follows a log-normal distribution with mean 'mu(x)' 
and a constant variance. For each v drawn from its distribution, one maximized 
value and optimal theta are produced. I'd like to do this repeatedly and store 
the maximized value and corresponding theta. I wrote the following code that 
can produce a result. But the problem is that the result doesn't seem to be the 
optimized one because if I arbitrarily choose theta=c(4,27), I will get much 
bigger value than those simulated ones. I am not sure where is wrong. Could 
anyone help me with this?  Thank you in advance! Here is the code:
   
  rdt<-matrix(0,10,3)
  for (i in 1:10){
  #Define the target function
  target<-function(theta){
d0=theta[1]
T0=theta[2] 
  mu<-function(x,d=d0,ta=23.86,ti=11.067,ppt=1.321,a=-12.31, S=5.62, L=3.83,
b=c(0.338,-0.0055,0.113,-0.00466,-0.008,-0.205,-0.044,0.266,1.719,-0.169)){
return(a+sum(b*c(x,x^2,d,d^2,S,L,ta,ti,ppt,ti*ppt)))} 
  v<-function(x,d=d0){
return(rlnorm(1,mean=mu(x),sd=0.835^0.5))}
  p<-function(x,d=d0){
if(8.179+0.00023*(5.29+0.16*x-0.21*d)^5>45){return(45)}
return(8.179+0.00023*(5.29+0.16*x-0.21*d)^5)
}
  Y3<-function(x,d=d0){
return(p(x,d)*v(x,d))
}
  r<-Y3(T0)
return(r)
  }
  result<-optim(c(2,10),target,lower=c(0.1,0.5),upper=c(66,50),
method="L-BFGS-B",control=list(maxit=10,fnscale=-1))
rdt[i,1]<-result$value
rdt[i,2:3]<-result$par }
  
 

 
-


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] REPLACE and REMOVE fns

2007-04-03 Thread Tina Robles

I want to use the replace function on "R_Jeter_04_post" (see attached)
so that S=1, D=1, T=1, HR=1, O=0, K=0, E=0, FC=0, and W,IW,and HP are
removed, so that i have a simple list of 1's and 0's.

I understand that I need to use the command "replace(x,list,values)"
and "rm()" but I'm having trouble using them. (syntax errors and
whatnot)

Any help would be appreciated.

--
Tina Robles
Graduate Assistant
Dept. Of Management Science
University of Miami
Post
0
1
1
0
1
0
0
0
0
0
1
0
1
1
0
1
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
1
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
1
0
0
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] (Newbie)Basic Basic global vs. local variables

2007-04-03 Thread projection83

Thank you, 
I will give this a good think


Mark Wardle wrote:
> 
> projection83 wrote:
>> My R code has got too complex to have a non-modular approach. Ive done
>> some
>> coding in other languages before, but I somehow cant figure out R's
>> general
>> rules for global and local variables. I have put a simple code below, if
>> anyone can show me what i need to add to make this work, i would greatly
>> appreciate it!
>> 
>> #
>> g_Means<-numeric()
>>   
>> defineSamples<- function()
>>  {
>>  g_Means<-5
>>  }
>> 
>> runit<-function()
>>  {
>>  defineSamples()
>>  g_Means #<>  }
>> 
>> runit()
>> #
>> Basically I can not get the parameter I set from a global scale...
> 
> I don't think you quite understand variable scope.
> 
> The "Introduction to R" says:
> 
> (http://cran.r-project.org/doc/manuals/R-intro.html#Assignment-within-functions)
> 
>> 10.5 Assignments within functions
>> 
>> Note that any ordinary assignments done within the function are local and
>> temporary and are lost after exit from the function. Thus the assignment
>> X <- qr(X) does not affect the value of the argument in the calling
>> program.
>> 
>> To understand completely the rules governing the scope of R assignments
>> the reader needs to be familiar with the notion of an evaluation frame.
>> This is a somewhat advanced, though hardly difficult, topic and is not
>> covered further here.
>> 
>> If global and permanent assignments are intended within a function, then
>> either the “superassignment” operator, <<- or the function assign() can
>> be used. See the help document for details. S-Plus users should be aware
>> that <<- has different semantics in R. These are discussed further in
>> Scope.
> 
> 
> I've struggled with keeping my global namespace relatively clutter-free.
>  You should think of functions as separate pieces of work, independent
> from most other things, and try to design them to be as generic as
> possible.
> 
> Presumably defineSamples() does some complex calculations, although it
> is impossible to tell as it appears to not take any parameters, and
> returns the value of g_Means (functions return their last evaluated
> expression).
> 
> Therefore your runIt() function isn't actually getting the result.
> 
> I would suggest defining functions with well-defined inputs and outputs,
> and NOT using global variables. It is difficult to give examples as you
> haven't said what your functions are doing, but for example:
> 
> defineSamples <- function(a,b,c=TRUE) {
>   # do some complex things with our input variables
>   # and return the results  - let's make it explicit with a return() call
>   return(a*b)
> 
> }
> 
> This is an isolated piece of logic, and if you go and change things
> elsewhere, its functionality won't have to be changed.
> 
> # note that this doesn't take any parameters.
> runIt <- function() {
>   my.result = defineSamples(3,4)
>   return(my.results)  # superfluous, but nice to make it 
> explicit for
> this example
> }
> 
> 
> Then you can call
> 
> runIt()
> => gives 12
> 
> And if you want to save the result, use
> 
> g_Means = runIt()
> 
> 
> You can pass arbitrarily complex data structures from and to functions
> if you have the need -  see list().
> 
> Hope this helps,
> 
> Mark
> -- 
> Dr. Mark Wardle
> Specialist registrar, Neurology
> Cardiff, UK
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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/%28Newbie%29Basic-Basic-global-vs.-local-variables-tf3503101.html#a9830501
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Reading user input

2007-04-03 Thread projection83

I dont know if thats what i want (its not working like i want).  I would like
to have R pause, wait for a user input of a number, then store that number
as a variable to use in the next calculation it does... 
Or should the below do that?


jim holtman wrote:
> 
> what you want is:
> 
> defineSamples<- function()
>{
>  readline("enter the number of groups: ")
>}
> 
> ANSWER <- defineSamples()
> 
> 
> 
> On 4/1/07, projection83 <[EMAIL PROTECTED]> wrote:
>>
>>
>> Hi there, this is a very easy question, i just cant seem to find a
>> straight
>> answer- i need this one thing, then i can finish my project for this
>> term.
>>
>> I am making an interactive application with R where I get the user to
>> input
>> numbers that the program then uses in the analysis.  I have figured out a
>> lot of stuff, yet this is somehow hard to find the answer to:
>> #--
>> defineSamples<- function()
>>{
>>  ANSWER<-numeric()
>>  ANSWER<-readline("enter the number of groups: ")
>>}
>>
>> runit()
>>
>> ANSWER # this does not hold the value the user inputs
>> #-
>>
>> If I then see what ANSWER is storing it says "numeric(0)", how do I get
>> this
>> to store whatever number the user inputs (and am i going to have to
>> convert
>> from a string to a number???
>>
>> THANKs for any help!
>> --
>> View this message in context:
>> http://www.nabble.com/Reading-user-input-tf3503016.html#a9783275
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> 
> 
> -- 
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
> 
> What is the problem you are trying to solve?
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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/Reading-user-input-tf3503016.html#a9830512
Sent from the R help mailing list archive at Nabble.com.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Newbie: Simple loops: complex troubles

2007-04-03 Thread projection83

I am used to java (well, i dont remember it really well, but anyway)

I have having a really difficult time making simple loops to work. I got the
following to work:

 ##
##Creates objects Ux1, Ux2, Ux2 etc. that  all contain n numbers in a
random distribution
##
m<-c(m1,m2,m3,m4,m5,m6,m7,m8,m9,m10)#these are defined as numbers 
(means)
v<-c(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10)#these are defined as numbers
(variances)  
n<-50
for(k in 1:g)
{
assign( paste("Ux", k, sep=""), rnorm( n  , 
assign(paste("m",1,sep=""),m[k])   ,   assign(paste("m",1,sep=""),v[k])  )  
)
}


The above seems like a lot of work for such a simple feat, no?

Also, I CANNot get the following to work in a loop manor:

Ux1i<-as.integer(Ux1)
Ux2i<-as.integer(Ux2)
Ux3i<-as.integer(Ux3)

or

Sx1<-sort(Ux1i)
Sx2<-sort(Ux2i)
Sx3<-sort(Ux3i)

Maybe I am just not using matrixes enough? but even that seems quite a lot
more complex than calling x<-matrix() then grabbing values by
x[j][k]...(java style if i remember correctly). the matrix help in R dosnt
make much sense to me. And also i am not sure why numeric() dosnt make you
define length before you use it, yet matrix() does.  Is there some other
funciton that i should be using to make length not an issue?


All in all, I dont know if i am going about this loop stuff a rely round
about way - Any help would make me much less loopy:Pthanks 



-- 
View this message in context: 
http://www.nabble.com/Newbie%3A-Simple-loops%3A-complex-troubles-tf3523751.html#a9830574
Sent from the R help mailing list archive at Nabble.com.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] gnomeGUI under KDE

2007-04-03 Thread Luis Lopez Oliveros
Dear all,

Recently, I installed the KDE desktop under my Linux system, but Included
also the Gnome desktop (actually, I installed everything that comes in the
openSUSE cd).

My question about R is the following. I would like to run some kind of
console under Linux. I was reading and first I found out that there is a
GUI under gnome, just by typing the command line R -g gnome; however, to
do this I need first to install the package gnomeGUI. Will this package
still work under KDE. So far I have been able to run all GNOME
applications under KDE, but I don't know about this one.

Kindly regards,

Luis LO

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


Re: [R] HPDinterval problem

2007-04-03 Thread Seyed Reza Jafarzadeh
Hi,

I am providing more examples where HPDinterval failed. It seems to be
working OK for (generalized linear mixed) models without crossed
random-effects (m1.17, m1.18, m1.19, m1.20, m1.21, m1.22, and m1.24
below).

Thank you,
Reza


> m1.1 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (1 | prov) + (1 | 
> pm), data = mydata[1:1392, ], family = quasipoisson)
> HPDinterval(mcmcsamp(m1.1, n = 1))
  lowerupper
(Intercept)-0.207561922 -0.207561922
pv1o0.056574609  0.056574609
pv2o0.023042057  0.023042057
pv1toa  0.026497315  0.026497315
pv2toa -0.001074887 -0.001074887
sesblf2 0.307805373  0.307805373
sesblf3 0.067866694  0.067866694
sesblf4 0.232652035  0.232652035
log(prov.(In)) -1.948540913 -0.815550437
log(pm.(In))   -4.609549269 -3.008113214
attr(,"Probability")
[1] 0.95


> m1.3 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (pv1toa | prov) + 
> (1 | pm), data = mydata[1:1392, ], family = quasipoisson)
> HPDinterval(mcmcsamp(m1.3, n = 1))
   lower upper
(Intercept)-0.3854582560 -0.3854582560
pv1o0.0545945359  0.0545945359
pv2o0.0266911717  0.0266911717
pv1toa  0.0369314516  0.0369314516
pv2toa -0.0008906397 -0.0008906397
sesblf2 0.3326814534  0.3326814534
sesblf3 0.1012759194  0.1012759194
sesblf4 0.1968001587  0.1968001587
log(prov.(In)) -1.2423994216 -0.0463231047
log(prov.pv1t) -8.5013756480 -7.3008649434
atanh(prv.(I).pv1) -1.3266358579 -0.4613822430
log(pm.(In))   -4.5813293741 -2.9416249086
attr(,"Probability")
[1] 0.95


> m1.5 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (1 | prov) + 
> (pv1toa | pm), data = mydata[1:1392, ], family = quasipoisson)
> HPDinterval(mcmcsamp(m1.5, n = 1))
 lowerupper
(Intercept)   -0.298634101 -0.298634101
pv1o   0.056017516  0.056017516
pv2o   0.021658991  0.021658991
pv1toa 0.028086682  0.028086682
pv2toa 0.003447681  0.003447681
sesblf20.413727463  0.413727463
sesblf30.046766676  0.046766676
sesblf40.255977008  0.255977008
log(prov.(In))-1.875689638 -0.751072995
log(pm.(In))  -3.556592560 -1.722182602
log(pm.pv1t)  -9.709527247 -7.885488338
atanh(pm.(I).pv1) -1.901663364 -0.616765080
attr(,"Probability")
[1] 0.95


> m1.7 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (pv1toa | prov) + 
> (pv1o | pm), data = mydata[1:1392, ], family = quasipoisson)
> HPDinterval(mcmcsamp(m1.7, n = 1))
  lowerupper
(Intercept)-0.389923132 -0.389923132
pv1o0.063098026  0.063098026
pv2o0.034944761  0.034944761
pv1toa  0.032622126  0.032622126
pv2toa  0.003154919  0.003154919
sesblf2 0.300371141  0.300371141
sesblf3 0.020146759  0.020146759
sesblf4 0.187532056  0.187532056
log(prov.(In)) -1.322210629 -0.131769983
log(prov.pv1t) -8.411977395 -7.219326685
atanh(prv.(I).pv1) -1.257375358 -0.396660253
log(pm.(In))   -3.671581481 -1.835388518
log(pm.pv1o)   -7.107693068 -5.275740794
atanh(pm.(I).pv1)  -1.679642476 -0.382000422
attr(,"Probability")
[1] 0.95


> m1.8 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (pv1o | prov) + 
> (pv1toa | pm), data = mydata[1:1392, ], family = quasipoisson)
> HPDinterval(mcmcsamp(m1.8, n = 1))
  lowerupper
(Intercept)-0.457054707 -0.457054707
pv1o0.156145534  0.156145534
pv2o0.024773645  0.024773645
pv1toa  0.024579764  0.024579764
pv2toa  0.001907060  0.001907060
sesblf2 0.394565315  0.394565315
sesblf3 0.061645816  0.061645816
sesblf4 0.259691274  0.259691274
log(prov.(In)) -1.301168272 -0.105499439
log(prov.pv1o) -5.255142692 -4.057937301
atanh(prv.(I).pv1) -1.851880731 -0.999139040
log(pm.(In))   -3.798743689 -1.968443546
log(pm.pv1t)   -9.788997900 -7.962938034
atanh(pm.(I).pv1)  -1.761670102 -0.480121774
attr(,"Probability")
[1] 0.95


> m1.9 <- lmer(o ~ pv1o + pv2o + pv1toa + pv2toa + sesblf + (pv1toa | prov) + 
> (pv1toa | pm), data = mydata[1:1392, ], family = quasipoisson)
> HPDinterval(mcmcsamp(m1.9, n = 1))
  lowerupper
(Intercept)-0.485035838 -0.485035838
pv1o0.053927806  0.053927806
pv2o0.027072754  0.027072754
pv1toa  0.036558311  0.036558311
pv2toa  0.004437478  0.004437478
sesblf2 0.470407622  0.470407622
sesblf3 0.094079640  0.094079640
sesblf4 0.240104293  0.240104293
log(prov.(In)) -1.195701809  0.010070569
log(prov.pv1t) -8.449706678 -7.242412741
atanh(prv.(I).pv1) -1.288497599 -0.4360

Re: [R] converting a list to a data.frame

2007-04-03 Thread Patrick Connolly
On Tue, 03-Apr-2007 at 01:55PM +0200, Dimitris Rizopoulos wrote:

|> try something like this:
|> 
|> lis <- list(c(1,2,4), c(4,5,2,1), c(3,4,6,3), c(3,1,76,4,2))
|> ##
|> n.max <- max(sapply(lis, length))
|> val <- NA # what to fill in
|> fill <- function(x) c(x, rep(val, n.max - length(x)))
|> as.data.frame(do.call(rbind, lapply(lis, fill)))

I think that should be cbind, not rbind.



-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~} Great minds discuss ideas
 _( Y )_Middle minds discuss events 
(:_~*~_:)Small minds discuss people  
 (_)-(_)   . Anon
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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 zone problems

2007-04-03 Thread Marc Fischer
Folks,

I'm having  trouble with how datetime objects with time zones are set 
and plotted.   This may be the result of my running R (2.4.0) on a 
Windoze XP box.  Perhaps not.  Here are two example problems I need 
advise on if you have time:

1)  I collect data with dates (often as a fractional day of year) in 
UTC.  Using strptime to create date time objects appears to force the 
data into the local time zone (including daylight time) of my 
machine.  Setting the tz="UTC" or "GMT" inside strptime seems to be 
ignored.  I made the following cumbersome work around:

foo$date=strptime((paste(yr,DOY), 0, 0), format="%Y %j %H %M",tz="") + 0
tzone.err=as.numeric(as.POSIXct(format(Sys.time(),tz="GMT"))-as.POSIXct(format(Sys.time(),tz="")))*3600
foo$date=foo$date-tzone.err
attributes(foo$date)$tzone="GMT"

Am I missing something obvious or is this a problem with Windoze?

2) Once I have the data in GMT, I try to plot it using the standard 
plot command but it converts the data back to local time before 
making the plot.  Now the work around is:

plot(foo$date+tzone.err,foo$var, xlab="Date(GMT)")

  Very frustrating... I've read the help pages but can't find answers 
to these issues.  Any help?

Best regards,

Marc

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


Re: [R] Reading user input

2007-04-03 Thread Petr Klasterecky
???
The code below is correct and does exactly what you described - just 
check the value of ANSWER. R is paused and the user-specified valued is 
assigned to ANSWER when you call your function, not inside. In your 
former code ANSWER was a local variable which 'died' when your function 
finished.

Petr

projection83 napsal(a):
> I dont know if thats what i want (its not working like i want).  I would like
> to have R pause, wait for a user input of a number, then store that number
> as a variable to use in the next calculation it does... 
> Or should the below do that?
> 
> 
> jim holtman wrote:
>> what you want is:
>>
>> defineSamples<- function()
>>{
>>  readline("enter the number of groups: ")
>>}
>>
>> ANSWER <- defineSamples()
>>
>>
>>
>> On 4/1/07, projection83 <[EMAIL PROTECTED]> wrote:
>>>
>>> Hi there, this is a very easy question, i just cant seem to find a
>>> straight
>>> answer- i need this one thing, then i can finish my project for this
>>> term.
>>>
>>> I am making an interactive application with R where I get the user to
>>> input
>>> numbers that the program then uses in the analysis.  I have figured out a
>>> lot of stuff, yet this is somehow hard to find the answer to:
>>> #--
>>> defineSamples<- function()
>>>{
>>>  ANSWER<-numeric()
>>>  ANSWER<-readline("enter the number of groups: ")
>>>}
>>>
>>> runit()
>>>
>>> ANSWER # this does not hold the value the user inputs
>>> #-
>>>
>>> If I then see what ANSWER is storing it says "numeric(0)", how do I get
>>> this
>>> to store whatever number the user inputs (and am i going to have to
>>> convert
>>> from a string to a number???
>>>
>>> THANKs for any help!
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Reading-user-input-tf3503016.html#a9783275
>>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> __
>>> R-help@stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>> -- 
>> Jim Holtman
>> Cincinnati, OH
>> +1 513 646 9390
>>
>> What is the problem you are trying to solve?
>>
>>  [[alternative HTML version deleted]]
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
> 

-- 
Petr Klasterecky
Dept. of Probability and Statistics
Charles University in Prague
Czech Republic

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


Re: [R] Newbie: Simple loops: complex troubles

2007-04-03 Thread Petr Klasterecky
Not sure whether this is exactly and everything you want, but at least 
it may give you some ideas how to proceed. You do not need loops at all:

Let's try a simplified example with 3 samples, each of length 10 (just 
for printing purposes):

m <- c(1,2,3)
v <- c(1,4,9)
n <- 10
means <- rep(m,each=n)
vars <- rep(v,each=n)
means
  [1] 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3
vars
  [1] 1 1 1 1 1 1 1 1 1 1 4 4 4 4 4 4 4 4 4 4 9 9 9 9 9 9 9 9 9 9

numbers <- matrix(rnorm(length(means), mean=means, sd=sqrt(vars)), 
nrow=n, byrow=F)
numbers
 [,1]   [,2]  [,3]
  [1,]  0.9721407  0.4510903 -2.880967
  [2,] -0.4834124 -2.7958993 -1.368037
  [3,]  1.6871736 -0.6717009 -3.268698
  [4,]  0.9738312  3.1919293  3.982135
  [5,]  0.8032162  1.0397078  7.227974
  [6,] -0.1606657  2.6339503  5.873210
  [7,]  0.5786295 -0.3589869  4.194425
  [8,]  0.9909184  2.0622899  6.432129
  [9,]  3.1687842  1.9765014  3.788201
[10,]  1.4814704  3.3024049  4.194628

colnames(numbers) <- paste('Ux',1:length(m),sep='')
numbers
  Ux1Ux2   Ux3
  [1,]  0.9721407  0.4510903 -2.880967
  [2,] -0.4834124 -2.7958993 -1.368037
  [3,]  1.6871736 -0.6717009 -3.268698
  [4,]  0.9738312  3.1919293  3.982135
  [5,]  0.8032162  1.0397078  7.227974
  [6,] -0.1606657  2.6339503  5.873210
  [7,]  0.5786295 -0.3589869  4.194425
  [8,]  0.9909184  2.0622899  6.432129
  [9,]  3.1687842  1.9765014  3.788201
[10,]  1.4814704  3.3024049  4.194628

Now your random vectors are in columns of 'numbers' and you can work 
with them using indexing.

Petr

projection83 napsal(a):
> I am used to java (well, i dont remember it really well, but anyway)
> 
> I have having a really difficult time making simple loops to work. I got the
> following to work:
> 
>  ##
>   ##Creates objects Ux1, Ux2, Ux2 etc. that  all contain n numbers in a
> random distribution
>   ##
>   m<-c(m1,m2,m3,m4,m5,m6,m7,m8,m9,m10)#these are defined as numbers 
> (means)
>   v<-c(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10)#these are defined as numbers
> (variances)  
> n<-50
>   for(k in 1:g)
>   {
>   assign( paste("Ux", k, sep=""), rnorm( n  , 
> assign(paste("m",1,sep=""),m[k])   ,   assign(paste("m",1,sep=""),v[k])  )  
> )
>   }
> 
> 
> The above seems like a lot of work for such a simple feat, no?
> 
> Also, I CANNot get the following to work in a loop manor:
> 
> Ux1i<-as.integer(Ux1)
>   Ux2i<-as.integer(Ux2)
>   Ux3i<-as.integer(Ux3)
> 
> or
> 
>   Sx1<-sort(Ux1i)
>   Sx2<-sort(Ux2i)
>   Sx3<-sort(Ux3i)
> 
> Maybe I am just not using matrixes enough? but even that seems quite a lot
> more complex than calling x<-matrix() then grabbing values by
> x[j][k]...(java style if i remember correctly). the matrix help in R dosnt
> make much sense to me. And also i am not sure why numeric() dosnt make you
> define length before you use it, yet matrix() does.  Is there some other
> funciton that i should be using to make length not an issue?
> 
> 
> All in all, I dont know if i am going about this loop stuff a rely round
> about way - Any help would make me much less loopy:Pthanks 
> 
> 
> 

-- 
Petr Klasterecky
Dept. of Probability and Statistics
Charles University in Prague
Czech Republic

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


Re: [R] gnomeGUI under KDE

2007-04-03 Thread Prof Brian Ripley
On Wed, 4 Apr 2007, Luis Lopez Oliveros wrote:

> Dear all,
>
> Recently, I installed the KDE desktop under my Linux system, but Included
> also the Gnome desktop (actually, I installed everything that comes in the
> openSUSE cd).
>
> My question about R is the following. I would like to run some kind of
> console under Linux. I was reading and first I found out that there is a
> GUI under gnome, just by typing the command line R -g gnome; however, to
> do this I need first to install the package gnomeGUI. Will this package
> still work under KDE. So far I have been able to run all GNOME
> applications under KDE, but I don't know about this one.

Yes, it will work.

However, it is minimal console and uses old GNOME libraries (GTk not 
GTk2) so what you have on a modern OS might not be enough to install it.

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

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


Re: [R] confine a dataframe with a polygon

2007-04-03 Thread temiz
Roger Bivand wrote:
> On Tue, 3 Apr 2007, temiz wrote:
>
>   
>> hello
>>
>> how can I confine a dataframe with a known polygon that is part of whole 
>> data ?
>> 
>
> Could I suggest following up this question on the R-sig-geo list? It is 
> not clear what you want to do - are the rows in the data frame points 
> which may lie inside or outside a polygon? If so, the overlay() methods in 
> the sp package may be suitable.
>
>   
>> regards
>>
>>
>> 
>
>   
thank you for your reply

I have not been aware of  that list (R-sig-geo list)
My data is elevation point data in a text file.
I want to create DEMs with different interpolation
methods for comparision.
Actually I created DEM in GRASS using spline tension.
Then I want to create DEM in R with different techniques to compare.
But my data seems so huge for GSTAT-kriging and FIELDS-krig.
So I decided to select smaller interpolation area within whole data.

How can I define a subregion in which I do interpolation ?

I found locator and chull function that may serve this.

I will regard your recommendations.

PS : Thinking facing a memory problem, I refrained from GRASS-R interface.



-- 
Ahmet Temiz


-- 
This message has been scanned for viruses and\ dangerous con...{{dropped}}

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