[R] Looping through a series of (csv) files

2007-07-15 Thread Yuchen Luo
Dear Colleagues.

This should be a very common operation and I believe there should be a nice
way in R to handle it.  I couldn't find it in the manual or by searching
online. I am wondering if I could ask for some help in this community.

I have 48 csv files; each stores the data for a specific month. The 48
corresponding months are consecutively from January, 2001 to December, 2004.
I name the files A200101, A200102,….., A200112, A200201, ……,etc.

I want to process file A2000101 and store the result to a new file named
B200101, process file A200102 and store the result to a new file named
B200102… …etc.

I do not want to manually change a little bit of the code to read a
different file and write to a different file every time. I want the program
to be able to loop through all the files.

My question is, how to loop through the 48 files?

Your help will be highly appreciated!


Best Wishes

Yuchen Luo

[[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] Send SMS out of R?

2007-07-15 Thread Hans-Peter
 Now I want to send an SMS out of R! Any idea how it could work? Could I send
 an eMail to a mobile phone number?

There are Email to SMS services you can use. Google gives plenty of
them (also free ones (which I wouldn't use myself...)).

-- 
Regards,
Hans-Peter

__
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] Send SMS out of R?

2007-07-15 Thread hadley wickham
On 7/14/07, Thomas Schwander [EMAIL PROTECTED] wrote:
 Hi everyone,



 Now I read the posting guidelines again; COMPLETELY! ;-)



 I use Windows XP Professional, R 2.5.1 and I have Blat to send eMails out of
 R. Works perfect! Thank you for your help!



 Now I want to send an SMS out of R! Any idea how it could work? Could I send
 an eMail to a mobile phone number?

This might be a good place to start:
http://en.wikipedia.org/wiki/SMS_gateways

Hadley

__
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] Mailing List

2007-07-15 Thread Alfred Inselberg

Please add me to your mailing list. Thank you

Alfred Inselberg

-- 
Alfred Inselberg, Professor 
School of Mathematical Sciences
Tel Aviv University
Tel Aviv 61390, Israel
Tel +972-3-640 5372
http://www.math.tau.ac.il/~aiisreal/

__
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] Looping through a series of (csv) files

2007-07-15 Thread Chuck Cleland
Yuchen Luo wrote:
 Dear Colleagues.
 
 This should be a very common operation and I believe there should be a nice
 way in R to handle it.  I couldn't find it in the manual or by searching
 online. I am wondering if I could ask for some help in this community.
 
 I have 48 csv files; each stores the data for a specific month. The 48
 corresponding months are consecutively from January, 2001 to December, 2004.
 I name the files A200101, A200102,….., A200112, A200201, ……,etc.
 
 I want to process file A2000101 and store the result to a new file named
 B200101, process file A200102 and store the result to a new file named
 B200102… …etc.
 
 I do not want to manually change a little bit of the code to read a
 different file and write to a different file every time. I want the program
 to be able to loop through all the files.
 
 My question is, how to loop through the 48 files?
 
 Your help will be highly appreciated!
 
 
 Best Wishes
 
 Yuchen Luo

  This will read each of the 48 csv files, add 50 to the values in each
file, and then write each resulting data frame to its own new file:

for(i in 1:48){
 tempdf - read.csv(paste(c:/myfolder/raw, i, .csv, sep=))
 tempdf.new - tempdf + 50
 write.table(tempdf.new,
 file=paste(c:/myfolder/plus50-, i, .csv, sep=),
 sep=,, row.names=FALSE)
}

rm(list=c(tempdf, tempdf.new, i))

  Of course, you can do something more useful than adding 50.

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

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

__
R-help@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] unixtime conversion

2007-07-15 Thread Patrick Drechsler
Prof Brian Ripley [EMAIL PROTECTED] writes:

 On Sat, 14 Jul 2007, Patrick Drechsler wrote:

 is there an R function to convert unixtime to one of the R time
 formats (using chron or POSIXct)?

 Example data:

 unixtime   year  month  day hour
 1183377301 2007  7  2   13

 I would like to only use the first column.

 See ?as.POSIXct, especially its examples.  (Isn't that the very obvious 
 place to look?)

 It seems you want ISOdatetime(1970,1,1,0,0,0) + unixtime

 although depending on the 'unix' in 'unixtime' you might have to wrorry 
 about leap seconds (which POSIX-compliant systems ignore).

Thank you very much for your reply! Indeed, ISOdatetime was the
command I was looking for.

Regards

Patrick

__
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] Please Please Help me!!!

2007-07-15 Thread TIMMMAY

I posted the message below a few days ago but I have not had any responses. I
keep thinking that there must be some easy way to answer the problem I am
just not familiar enough with regression to answer the problem myself. If
anyone can help me I would be very grateful. I need to fit a gamma curve to
a set of data. ie a scatterplot of the data indicates that the curve looks
like a truncated gamma density function and I would like to estimate the
paramaters so that I can fit a curve to the data points. Its not MLE
paramater estimation just a curve fitting exercise. The problem again is 

I have a set transition intensities and when plotted the curve looks like a
gamma density. I want to fit a gamma density curve to these intensities. It
is just a curve fitting problem but whats causing the trouble is that I need
to use least squares minimization to calculate the parameters for the gamma
curve. How do I do this??? 

The curve will be a truncated gamma function so it will have 3 paramaters a,
b, c. I tried to do the following 

nls(lograte ~ log(c) + a*log(b) + (a-1)*log(age)+b*(age)-lgamma(a),
start=list(a=1,b=1,c=1)), where lograte, and age are my data. a,b the gamma
parameters and c the parameter we need because we are fitting a truncated
distribution. 

I also tried defining 
fn = function(p) sum((log(y)-log(dgamma(x,p[1],p[2])*p[3]))^2) 
a residual sum of squares and using nlm to minimise this and find paramaters
but this doesnt work either. Can anyone help me ?? Please :) 

Original message follows :(
Fitting a Gamma Curve   
by TIMMMAY Jul 12, 2007; 03:38pm :: Rate this Message:(use ratings to
moderate[?])

Reply | Reply to Author | Show Only this Message 

Hi there, I hope someone can help me before I tear all my hair out. I have a
set transition intensities and when plotted the curve looks like a gamma
density. I want to fit a gamma density curve to these intensities. It is
just a curve fitting problem but whats causing the trouble is that I need to
use least squares minimization to calculate the parameters for the gamma
curve. How do I do this??? 

The curve will be a truncated gamma function so it will have 3 paramaters a,
b, c. I tried to do the following 

nls(lograte ~ log(c) + a*log(b) + (a-1)*log(age)+b*(age)-lgamma(a),
start=list(a=1,b=1,c=1)), where lograte, and age are my data. a,b the gamma
parameters and c the parameter we need because we are fitting a truncated
distribution. 

I also tried defining 
fn = function(p) sum((log(y)-log(dgamma(x,p[1],p[2])*p[3]))^2) 
a residual sum of squares and using nlm to minimise this and find paramaters
but this doesnt work either. Can anyone help me ?? Please :) 




« Return to forum

Start a free forum or mailing list archive on Nabble  Help - Powered by -
Terms of Use - Jobs at Nabble - Nabble Support  

-- 
View this message in context: 
http://www.nabble.com/Please-Please-Help-me%21%21%21-tf4081887.html#a11601686
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] Complex surveys, properly computed SEs and non-parametric analyses

2007-07-15 Thread John Sorkin
Can someone direct me to an R function that properly computes standard errors 
of data obtained from a complex survery design, i.e. perform alnalyses similiar 
to those that can be performed with SUDAAN, particularly for a non-parametric 
one-way ANOVA, e.g. signed rank test?
Thanks,
John

John Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
Baltimore VA Medical Center GRECC,
University of Maryland School of Medicine Claude D. Pepper OAIC,
University of Maryland Clinical Nutrition Research Unit, and
Baltimore VA Center Stroke of Excellence

University of Maryland School of Medicine
Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524

(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
[EMAIL PROTECTED]
Confidentiality Statement:
This email message, including any attachments, is for the so...{{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.


[R] Area selection agorithms

2007-07-15 Thread Des Callaghan
Hi,
 
Various algorithms have been developed for selecting efficient sets of areas
for biodiversity conservation, given a list of the areas and the different
species they contain (e.g. the algorithms used within the WorldMap software
that is distributed by the Natural History Museum in London). Does anyone
know if these algorithms are available through an R package please? Thanks
very much in advance for any help.
 
Best wishes,
Des
 

[[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] Complex surveys, properly computed SEs and non-parametric analyses

2007-07-15 Thread Tobias Verbeke
Dear John,

 Can someone direct me to an R function that properly computes standard errors 
 of data obtained from 
  a complex survery design i.e. perform alnalyses similiar to those 
that can be performed with SUDAAN,
  articularly for a non-parametric one-way ANOVA, e.g. signed rank test?

The survey package of Thomas Lumley has very broad functionality for the 
analysis of data from complex sampling designs. Please find below the 
homepage of the package (which is available on CRAN):

http://faculty.washington.edu/tlumley/survey/

I don't think non-parametric one-way ANOVA is implemented, but
quoting

http://faculty.washington.edu/tlumley/survey/survey-wss.pdf

slide 101:

Many features of the survey package result from requests from
unsatisfied users.

For new methods the most important information is a reference
that gives sufficient detail for implementation. A data set is nice
but not critical.

HTH,
Tobias

-- 

Tobias Verbeke - Consultant
Business  Decision Benelux
Rue de la révolution 8
1000 Brussels - BELGIUM

+32 499 36 33 15
[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] Please Please Help me!!!

2007-07-15 Thread Gabor Grothendieck
The reason no one answered may be that you did not follow the last
line to every r-help message or read and follow the posting guide.  Its
time consuming to develop a test environment and data needed to clarify
and test the answer to a question.  By providing data and reproducible
code you reduce the amount of time it takes responders to answer thereby
making it more likely someone will.

On 7/15/07, TIMMMAY [EMAIL PROTECTED] wrote:

 I posted the message below a few days ago but I have not had any responses. I
 keep thinking that there must be some easy way to answer the problem I am
 just not familiar enough with regression to answer the problem myself. If
 anyone can help me I would be very grateful. I need to fit a gamma curve to
 a set of data. ie a scatterplot of the data indicates that the curve looks
 like a truncated gamma density function and I would like to estimate the
 paramaters so that I can fit a curve to the data points. Its not MLE
 paramater estimation just a curve fitting exercise. The problem again is

 I have a set transition intensities and when plotted the curve looks like a
 gamma density. I want to fit a gamma density curve to these intensities. It
 is just a curve fitting problem but whats causing the trouble is that I need
 to use least squares minimization to calculate the parameters for the gamma
 curve. How do I do this???

 The curve will be a truncated gamma function so it will have 3 paramaters a,
 b, c. I tried to do the following

 nls(lograte ~ log(c) + a*log(b) + (a-1)*log(age)+b*(age)-lgamma(a),
 start=list(a=1,b=1,c=1)), where lograte, and age are my data. a,b the gamma
 parameters and c the parameter we need because we are fitting a truncated
 distribution.

 I also tried defining
 fn = function(p) sum((log(y)-log(dgamma(x,p[1],p[2])*p[3]))^2)
 a residual sum of squares and using nlm to minimise this and find paramaters
 but this doesnt work either. Can anyone help me ?? Please :)

 Original message follows :(
 Fitting a Gamma Curve
 by TIMMMAY Jul 12, 2007; 03:38pm :: Rate this Message:(use ratings to
 moderate[?])

 Reply | Reply to Author | Show Only this Message

 Hi there, I hope someone can help me before I tear all my hair out. I have a
 set transition intensities and when plotted the curve looks like a gamma
 density. I want to fit a gamma density curve to these intensities. It is
 just a curve fitting problem but whats causing the trouble is that I need to
 use least squares minimization to calculate the parameters for the gamma
 curve. How do I do this???

 The curve will be a truncated gamma function so it will have 3 paramaters a,
 b, c. I tried to do the following

 nls(lograte ~ log(c) + a*log(b) + (a-1)*log(age)+b*(age)-lgamma(a),
 start=list(a=1,b=1,c=1)), where lograte, and age are my data. a,b the gamma
 parameters and c the parameter we need because we are fitting a truncated
 distribution.

 I also tried defining
 fn = function(p) sum((log(y)-log(dgamma(x,p[1],p[2])*p[3]))^2)
 a residual sum of squares and using nlm to minimise this and find paramaters
 but this doesnt work either. Can anyone help me ?? Please :)




 « Return to forum

 Start a free forum or mailing list archive on Nabble  Help - Powered by -
 Terms of Use - Jobs at Nabble - Nabble Support

 --
 View this message in context: 
 http://www.nabble.com/Please-Please-Help-me%21%21%21-tf4081887.html#a11601686
 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-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] Pairlist of pairlsit assembly howto

2007-07-15 Thread Johannes Graumann
Hy guys,

I'm trying something like this

minbins - list()
for (minute in sequence(3)) {
minbins[minute] - list(data=a,variable=b)
}

And it doesn't work ...
Warning messages:
1: number of items to replace is not a multiple of replacement length in:
minbins[minute] - list(data = a, variable = b) 
2: number of items to replace is not a multiple of replacement length in:
minbins[minute] - list(data = a, variable = b) 
3: number of items to replace is not a multiple of replacement length in:
minbins[minute] - list(data = a, variable = b)

What am I doing wrong and how to do this properly?

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


[R] Break during the recursion?

2007-07-15 Thread Atte Tenkanen
Hi,

Is it possible to break using if-condition during the recursive function?

Here is a function which almost works. It is for inorder-tree-walk. 

iotw-function(v,i,Stack,Indexes) # input: a vector and the first index (1), 
Stack=c(), Indexes=c().
{
print(Indexes)
# if (sum(i)==0) break # Doesn't work...

if (is.na(v[i])==FALSE  is.null(unlist(v[i]))==FALSE)
{Stack=c(i,Stack); i=2*i; iotw(v,i,Stack,Indexes)}
Indexes=c(Indexes,Stack[1])
Stack=pop.stack(Stack)$vector
Indexes=c(Indexes,Stack[1])
i=2*Stack[1]+1
Stack=pop.stack(Stack)$vector
iotw(v,i,Stack,Indexes)
}


 v=c(`-`,`+`,1,`^`,`^`,NA,NA,X,3,X,2)
 Stack=c()
 Indexes=c()

 iotw(v,1,Stack,Indexes)
NULL
NULL
NULL
NULL
NULL
[1] 8 4
[1] 8 4
[1] 8 4 9 2
[1] 8 4 9 2
[1] 8 4 9 2
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
Error in if (is.na(v[i]) == FALSE  is.null(unlist(v[i])) == FALSE) { : 
argument is of length zero

Regards,

Atte Tenkanen
University of Turku, Finland

__
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] Pairlist of pairlsit assembly howto

2007-07-15 Thread Duncan Murdoch

(This isn't important to your question, but those aren't pairlists. 
Pairlists are rarely used in R code, except implicitly in the way R 
stores parsed code.)

On 15/07/2007 10:00 AM, Johannes Graumann wrote:
 Hy guys,
 
 I'm trying something like this
 
 minbins - list()
 for (minute in sequence(3)) {
 minbins[minute] - list(data=a,variable=b)
 }

You want to use

minbins[[minute]] - list(data=a,variable=b)

The difference between [[ ]] and [ ] is that the former works on the 
element, the latter works on a subset.  So your version tried to change 
a subset of length 1 into a subset of length 2, which generates the 
warnings.  You want to assign a list of length 2 as an element of minbins.

Duncan Murdoch
 
 And it doesn't work ...
 Warning messages:
 1: number of items to replace is not a multiple of replacement length in:
 minbins[minute] - list(data = a, variable = b) 
 2: number of items to replace is not a multiple of replacement length in:
 minbins[minute] - list(data = a, variable = b) 
 3: number of items to replace is not a multiple of replacement length in:
 minbins[minute] - list(data = a, variable = b)
 
 What am I doing wrong and how to do this properly?
 
 Thanks, 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.

__
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] Break during the recursion?

2007-07-15 Thread Atte Tenkanen
Oh. I forgot one extra-function:

pop.stack-function(v){
if(length(v)==0){x=NA}
if(length(v)==1){x=v[1]; v=c()}
if(length(v)1){x=v[1]; v=v[2:length(v)]}
return(list(vector=v,x=x))
}

Atte

 Hi,
 
 Is it possible to break using if-condition during the recursive 
 function?
 Here is a function which almost works. It is for inorder-tree-walk. 
 
 iotw-function(v,i,Stack,Indexes) # input: a vector and the first 
 index (1), Stack=c(), Indexes=c().
 {
   print(Indexes)
   # if (sum(i)==0) break # Doesn't work...
   
   if (is.na(v[i])==FALSE  is.null(unlist(v[i]))==FALSE)
   {Stack=c(i,Stack); i=2*i; iotw(v,i,Stack,Indexes)}
   Indexes=c(Indexes,Stack[1])
   Stack=pop.stack(Stack)$vector
   Indexes=c(Indexes,Stack[1])
   i=2*Stack[1]+1
   Stack=pop.stack(Stack)$vector
   iotw(v,i,Stack,Indexes)
 }
 
 
  v=c(`-`,`+`,1,`^`,`^`,NA,NA,X,3,X,2)
  Stack=c()
  Indexes=c()
 
  iotw(v,1,Stack,Indexes)
 NULL
 NULL
 NULL
 NULL
 NULL
 [1] 8 4
 [1] 8 4
 [1] 8 4 9 2
 [1] 8 4 9 2
 [1] 8 4 9 2
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 Error in if (is.na(v[i]) == FALSE  is.null(unlist(v[i])) == FALSE) 
 { : 
   argument is of length zero
 
 Regards,
 
 Atte Tenkanen
 University of Turku, Finland


__
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] Break during the recursion?

2007-07-15 Thread Duncan Murdoch
On 15/07/2007 10:06 AM, Atte Tenkanen wrote:
 Hi,
 
 Is it possible to break using if-condition during the recursive function?

You can do

  if (condition) return(value)

 
 Here is a function which almost works. It is for inorder-tree-walk. 
 
 iotw-function(v,i,Stack,Indexes) # input: a vector and the first index (1), 
 Stack=c(), Indexes=c().
 {
   print(Indexes)
   # if (sum(i)==0) break # Doesn't work...

if (sum(i)==0) return(NULL)

should work.

Duncan Murdoch

   
   if (is.na(v[i])==FALSE  is.null(unlist(v[i]))==FALSE)
   {Stack=c(i,Stack); i=2*i; iotw(v,i,Stack,Indexes)}
   Indexes=c(Indexes,Stack[1])
   Stack=pop.stack(Stack)$vector
   Indexes=c(Indexes,Stack[1])
   i=2*Stack[1]+1
   Stack=pop.stack(Stack)$vector
   iotw(v,i,Stack,Indexes)
 }
 
 
 v=c(`-`,`+`,1,`^`,`^`,NA,NA,X,3,X,2)
 Stack=c()
 Indexes=c()
 
 iotw(v,1,Stack,Indexes)
 NULL
 NULL
 NULL
 NULL
 NULL
 [1] 8 4
 [1] 8 4
 [1] 8 4 9 2
 [1] 8 4 9 2
 [1] 8 4 9 2
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 Error in if (is.na(v[i]) == FALSE  is.null(unlist(v[i])) == FALSE) { : 
   argument is of length zero
 
 Regards,
 
 Atte Tenkanen
 University of Turku, Finland
 
 __
 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] Break during the recursion?

2007-07-15 Thread Atte Tenkanen
 On 15/07/2007 10:06 AM, Atte Tenkanen wrote:
  Hi,
  
  Is it possible to break using if-condition during the recursive 
 function?
 You can do
 
  if (condition) return(value)
 
  
  Here is a function which almost works. It is for inorder-tree-
 walk. 
  
  iotw-function(v,i,Stack,Indexes) # input: a vector and the first 
 index (1), Stack=c(), Indexes=c().
  {
  print(Indexes)
  # if (sum(i)==0) break # Doesn't work...
 
   if (sum(i)==0) return(NULL)
 
 should work.
 
 Duncan Murdoch

Hmm - - - I'd like to save the Indexes-vector (in the example 
c(8,4,9,2,10,5,11,1,3)) and stop, when it is ready. 

The results are enclosed to the end.

Atte

 
  
  if (is.na(v[i])==FALSE  is.null(unlist(v[i]))==FALSE)
  {Stack=c(i,Stack); i=2*i; iotw(v,i,Stack,Indexes)}
  Indexes=c(Indexes,Stack[1])
  Stack=pop.stack(Stack)$vector
  Indexes=c(Indexes,Stack[1])
  i=2*Stack[1]+1
  Stack=pop.stack(Stack)$vector
  iotw(v,i,Stack,Indexes)
  }
  
  
  v=c(`-`,`+`,1,`^`,`^`,NA,NA,X,3,X,2)
  Stack=c()
  Indexes=c()
  
  iotw(v,1,Stack,Indexes)
  NULL
  NULL
  NULL
  NULL
  NULL
  [1] 8 4
  [1] 8 4
  [1] 8 4 9 2
  [1] 8 4 9 2
  [1] 8 4 9 2
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  Error in if (is.na(v[i]) == FALSE  is.null(unlist(v[i])) == 
 FALSE) { : 
  argument is of length zero
  
  Regards,
  
  Atte Tenkanen
  University of Turku, Finland
  


 iotw(v,1,Stack,Indexes)
NULL
NULL
NULL
NULL
NULL
[1] 8 4
[1] 8 4
[1] 8 4 9 2
[1] 8 4 9 2
[1] 8 4 9 2
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1] 8 4 9 2 5 1
[1] 8 4 9 2 5 1
[1] 8 4 9 2 5 1 3
[1] 8 4 9 2 5 1 3
[1] 8 4 9 2
[1] 8 4 9 2
[1] 8 4 9 2
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1] 8 4 9 2 5 1
[1] 8 4 9 2 5 1
[1] 8 4 9 2 5 1 3
[1] 8 4 9 2 5 1 3
[1] 8 4
[1] 8 4
[1] 8 4 9 2
[1] 8 4 9 2
[1] 8 4 9 2
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1] 8 4 9 2 5 1
[1] 8 4 9 2 5 1
[1] 8 4 9 2 5 1 3
[1] 8 4 9 2 5 1 3
[1] 8 4 9 2
[1] 8 4 9 2
[1] 8 4 9 2
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1
[1]  8  4  9  2 10  5 11  1  3
[1]  8  4  9  2 10  5 11  1  3
[1] 8 4 9 2 5 1
[1] 8 4 9 2 5 1
[1] 8 4 9 2 5 1 3
[1] 8 4 9 2 5 1 3
[1] 4 2
[1] 4 2
[1] 4 2
[1]  4  2 10  5
[1]  4  2 10  5
[1]  4  2 10  5 11  1
[1]  4  2 10  5 11  1
[1]  4  2 10  5 11  1  3
[1]  4  2 10  5 11  1  3
[1]  4  2 10  5 11  1
[1]  4  2 10  5 11  1
[1]  4  2 10  5 11  1  3
[1]  4  2 10  5 11  1  3
[1]  4  2 10  5
[1]  4  2 10  5
[1]  4  2 10  5 11  1
[1]  4  2 10  5 11  1
[1]  4  2 10  5 11  1  3
[1]  4  2 10  5 11  1  3
[1]  4  2 10  5 11  1
[1]  4  2 10  5 11  1
[1]  4  2 10  5 11  1  3
[1]  4  2 10  5 11  1  3
[1] 4 2 5 1
[1] 4 2 5 1
[1] 4 2 5 1 3
[1] 4 2 5 1 3
[1] 2 1
[1] 2 1
[1] 2 1 3
[1] 2 1 3
[1] 1
[1] 1

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

Re: [R] Break during the recursion?

2007-07-15 Thread Duncan Murdoch
On 15/07/2007 10:33 AM, Atte Tenkanen wrote:
 On 15/07/2007 10:06 AM, Atte Tenkanen wrote:
 Hi,

 Is it possible to break using if-condition during the recursive 
 function?
 You can do

  if (condition) return(value)

 Here is a function which almost works. It is for inorder-tree-
 walk. 
 iotw-function(v,i,Stack,Indexes) # input: a vector and the first 
 index (1), Stack=c(), Indexes=c().
 {
 print(Indexes)
 # if (sum(i)==0) break # Doesn't work...
  if (sum(i)==0) return(NULL)

 should work.

 Duncan Murdoch
 
 Hmm - - - I'd like to save the Indexes-vector (in the example 
 c(8,4,9,2,10,5,11,1,3)) and stop, when it is ready. 

This seems more like a problem with the design of your function than a 
question about R.  I can't really help you with that, because your 
description of the problem doesn't make sense to me.  What does it mean 
to do an inorder tree walk on something that isn't a tree?

Duncan Murdoch


 
 The results are enclosed to the end.
 
 Atte
 
 
 if (is.na(v[i])==FALSE  is.null(unlist(v[i]))==FALSE)
 {Stack=c(i,Stack); i=2*i; iotw(v,i,Stack,Indexes)}
 Indexes=c(Indexes,Stack[1])
 Stack=pop.stack(Stack)$vector
 Indexes=c(Indexes,Stack[1])
 i=2*Stack[1]+1
 Stack=pop.stack(Stack)$vector
 iotw(v,i,Stack,Indexes)
 }


 v=c(`-`,`+`,1,`^`,`^`,NA,NA,X,3,X,2)
 Stack=c()
 Indexes=c()
 iotw(v,1,Stack,Indexes)
 NULL
 NULL
 NULL
 NULL
 NULL
 [1] 8 4
 [1] 8 4
 [1] 8 4 9 2
 [1] 8 4 9 2
 [1] 8 4 9 2
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 Error in if (is.na(v[i]) == FALSE  is.null(unlist(v[i])) == 
 FALSE) { : 
 argument is of length zero

 Regards,

 Atte Tenkanen
 University of Turku, Finland

 
 
 iotw(v,1,Stack,Indexes)
 NULL
 NULL
 NULL
 NULL
 NULL
 [1] 8 4
 [1] 8 4
 [1] 8 4 9 2
 [1] 8 4 9 2
 [1] 8 4 9 2
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1] 8 4 9 2 5 1
 [1] 8 4 9 2 5 1
 [1] 8 4 9 2 5 1 3
 [1] 8 4 9 2 5 1 3
 [1] 8 4 9 2
 [1] 8 4 9 2
 [1] 8 4 9 2
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1] 8 4 9 2 5 1
 [1] 8 4 9 2 5 1
 [1] 8 4 9 2 5 1 3
 [1] 8 4 9 2 5 1 3
 [1] 8 4
 [1] 8 4
 [1] 8 4 9 2
 [1] 8 4 9 2
 [1] 8 4 9 2
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1] 8 4 9 2 5 1
 [1] 8 4 9 2 5 1
 [1] 8 4 9 2 5 1 3
 [1] 8 4 9 2 5 1 3
 [1] 8 4 9 2
 [1] 8 4 9 2
 [1] 8 4 9 2
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1
 [1]  8  4  9  2 10  5 11  1  3
 [1]  8  4  9  2 10  5 11  1  3
 [1] 8 4 9 2 5 1
 [1] 8 4 9 2 5 1
 [1] 8 4 9 2 5 1 3
 [1] 8 4 9 2 5 1 3
 [1] 4 2
 [1] 4 2
 [1] 4 2
 [1]  4  2 10  5
 [1]  4  2 10  5
 [1]  4  2 10  5 11  1
 [1]  4  2 10  5 11  1
 [1]  4  2 10  5 11  1  3
 [1]  4  2 10  5 11  1  3
 [1]  4  2 10  5 11  1
 [1]  4  2 10  5 11  1
 [1]  4  2 10  5 11  1  3
 [1]  4  2 10  5 11  1  3
 [1]  4  2 10  5
 [1]  4  2 10  5
 [1]  4  2 10  5 11  1
 [1]  4  2 10  5 11  1
 [1]  4  2 10  5 

Re: [R] Break during the recursion?

2007-07-15 Thread Atte Tenkanen
 On 15/07/2007 10:33 AM, Atte Tenkanen wrote:
  On 15/07/2007 10:06 AM, Atte Tenkanen wrote:
  Hi,
 
  Is it possible to break using if-condition during the recursive 
  function?
  You can do
 
   if (condition) return(value)
 
  Here is a function which almost works. It is for inorder-tree-
  walk. 
  iotw-function(v,i,Stack,Indexes) # input: a vector and the 
 first 
  index (1), Stack=c(), Indexes=c().
  {
print(Indexes)
# if (sum(i)==0) break # Doesn't work...
 if (sum(i)==0) return(NULL)
 
  should work.
 
  Duncan Murdoch
  
  Hmm - - - I'd like to save the Indexes-vector (in the example 
 c(8,4,9,2,10,5,11,1,3)) and stop, when it is ready. 
 
 This seems more like a problem with the design of your function 
 than a 
 question about R.  I can't really help you with that, because your 
 description of the problem doesn't make sense to me.  What does it 
 mean 
 to do an inorder tree walk on something that isn't a tree?
 
 Duncan Murdoch

The symbols in vector v have been originally derived from tree. See

http://users.utu.fi/attenka/Tree.jpg

But perhaps there's another way to do this, for instance by using loops and 
if-conditions? 

Atte



 
 
  
  The results are enclosed to the end.
  
  Atte
  

if (is.na(v[i])==FALSE  is.null(unlist(v[i]))==FALSE)
{Stack=c(i,Stack); i=2*i; iotw(v,i,Stack,Indexes)}
Indexes=c(Indexes,Stack[1])
Stack=pop.stack(Stack)$vector
Indexes=c(Indexes,Stack[1])
i=2*Stack[1]+1
Stack=pop.stack(Stack)$vector
iotw(v,i,Stack,Indexes)
  }
 
 
  v=c(`-`,`+`,1,`^`,`^`,NA,NA,X,3,X,2)
  Stack=c()
  Indexes=c()
  iotw(v,1,Stack,Indexes)
  NULL
  NULL
  NULL
  NULL
  NULL
  [1] 8 4
  [1] 8 4
  [1] 8 4 9 2
  [1] 8 4 9 2
  [1] 8 4 9 2
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  Error in if (is.na(v[i]) == FALSE  is.null(unlist(v[i])) == 
  FALSE) { : 
argument is of length zero
 
  Regards,
 
  Atte Tenkanen
  University of Turku, Finland
 
  
  
  iotw(v,1,Stack,Indexes)
  NULL
  NULL
  NULL
  NULL
  NULL
  [1] 8 4
  [1] 8 4
  [1] 8 4 9 2
  [1] 8 4 9 2
  [1] 8 4 9 2
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1] 8 4 9 2 5 1
  [1] 8 4 9 2 5 1
  [1] 8 4 9 2 5 1 3
  [1] 8 4 9 2 5 1 3
  [1] 8 4 9 2
  [1] 8 4 9 2
  [1] 8 4 9 2
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1] 8 4 9 2 5 1
  [1] 8 4 9 2 5 1
  [1] 8 4 9 2 5 1 3
  [1] 8 4 9 2 5 1 3
  [1] 8 4
  [1] 8 4
  [1] 8 4 9 2
  [1] 8 4 9 2
  [1] 8 4 9 2
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1] 8 4 9 2 5 1
  [1] 8 4 9 2 5 1
  [1] 8 4 9 2 5 1 3
  [1] 8 4 9 2 5 1 3
  [1] 8 4 9 2
  [1] 8 4 9 2
  [1] 8 4 9 2
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1
  [1]  8  4  9  2 10  5 11  1  3
  [1]  8  4  9  2 10  5 11  1  3
  [1] 8 4 9 2 5 1
  [1] 8 4 9 2 5 1
  [1] 8 

Re: [R] Break during the recursion?

2007-07-15 Thread Duncan Murdoch
On 15/07/2007 11:36 AM, Atte Tenkanen wrote:
 On 15/07/2007 10:33 AM, Atte Tenkanen wrote:
 On 15/07/2007 10:06 AM, Atte Tenkanen wrote:
 Hi,

 Is it possible to break using if-condition during the recursive 
 function?
 You can do

  if (condition) return(value)

 Here is a function which almost works. It is for inorder-tree-
 walk. 
 iotw-function(v,i,Stack,Indexes) # input: a vector and the 
 first 
 index (1), Stack=c(), Indexes=c().
 {
   print(Indexes)
   # if (sum(i)==0) break # Doesn't work...
if (sum(i)==0) return(NULL)

 should work.

 Duncan Murdoch
 Hmm - - - I'd like to save the Indexes-vector (in the example 
 c(8,4,9,2,10,5,11,1,3)) and stop, when it is ready. 

 This seems more like a problem with the design of your function 
 than a 
 question about R.  I can't really help you with that, because your 
 description of the problem doesn't make sense to me.  What does it 
 mean 
 to do an inorder tree walk on something that isn't a tree?

 Duncan Murdoch
 
 The symbols in vector v have been originally derived from tree. See
 
 http://users.utu.fi/attenka/Tree.jpg
 
 But perhaps there's another way to do this, for instance by using loops and 
 if-conditions? 

Or perhaps by doing the tree walk on the tree, before you collapse it 
into a vector.

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.


[R] Text with differents colors in a plot / Detecting if text exists

2007-07-15 Thread Maja Schröter
Hi everybody,

I want to write some text in a plot.

That's simple I know. But I want to make use of different colors.

Eg. text(x,y,paste(Sunderland,high)).

Then Sunderland should be black and high red.

Has anyone an idea?

By the way. I'm looking for a function or something similar, that can check 
whether there is text in some regions on the plot. 
Because I don't want to overwrite an existing text with a new one.

Thank you so much for your help. I appologize in advance if my question is very 
stupid but I have really no idea.

Yours,

Maja
--

__
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] Break during the recursion?

2007-07-15 Thread hadley wickham
On 7/15/07, Duncan Murdoch [EMAIL PROTECTED] wrote:
 On 15/07/2007 11:36 AM, Atte Tenkanen wrote:
  On 15/07/2007 10:33 AM, Atte Tenkanen wrote:
  On 15/07/2007 10:06 AM, Atte Tenkanen wrote:
  Hi,
 
  Is it possible to break using if-condition during the recursive
  function?
  You can do
 
   if (condition) return(value)
 
  Here is a function which almost works. It is for inorder-tree-
  walk.
  iotw-function(v,i,Stack,Indexes) # input: a vector and the
  first
  index (1), Stack=c(), Indexes=c().
  {
print(Indexes)
# if (sum(i)==0) break # Doesn't work...
 if (sum(i)==0) return(NULL)
 
  should work.
 
  Duncan Murdoch
  Hmm - - - I'd like to save the Indexes-vector (in the example
  c(8,4,9,2,10,5,11,1,3)) and stop, when it is ready.
 
  This seems more like a problem with the design of your function
  than a
  question about R.  I can't really help you with that, because your
  description of the problem doesn't make sense to me.  What does it
  mean
  to do an inorder tree walk on something that isn't a tree?
 
  Duncan Murdoch
 
  The symbols in vector v have been originally derived from tree. See
 
  http://users.utu.fi/attenka/Tree.jpg
 
  But perhaps there's another way to do this, for instance by using loops and 
  if-conditions?

 Or perhaps by doing the tree walk on the tree, before you collapse it
 into a vector.

If it's a binary tree with n levels, I think you should be able to
generate the positions more directly, depending on how the tree has
been flattened.  Binary heaps work this way, so that might be a good
place to start.  See http://en.wikipedia.org/wiki/Binary_heap,
particularly heap implementation.

Hadley

__
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] Complex surveys, properly computed SEs and non-parametric analyses

2007-07-15 Thread Thomas Lumley
On Sun, 15 Jul 2007, Tobias Verbeke wrote:
 The survey package of Thomas Lumley has very broad functionality for the
 analysis of data from complex sampling designs. Please find below the
 homepage of the package (which is available on CRAN):

 http://faculty.washington.edu/tlumley/survey/

 I don't think non-parametric one-way ANOVA is implemented

No.

 but quoting
 http://faculty.washington.edu/tlumley/survey/survey-wss.pdf
 Many features of the survey package result from requests from
 unsatisfied users.

 For new methods the most important information is a reference
 that gives sufficient detail for implementation. A data set is nice
 but not critical.


Yes, and the details are especially non-obvious here.  The test won't be 
small-sample exact, AFAICS, and it isn't clear whether the idea is to add 
weights to the influence function for the signed-rank test or to replace 
it with a design-based estimate of a population quantity. Often these 
approaches are equivalent, but they won't be in this case. It wouldn't 
have occured to me that people would want this. `Non-parametric' isn't 
really a relevant idea since design-based inference assumes a completely 
known model for the sampling indicators and doesn't even treat the data as 
random variables.

All this goes to say that if there is a standard quantity that John wants, 
it will have resulted in part from a set of arbitrary decisions, and it 
won't be possible to reverse-engineer the estimator in the absence of a 
precise description.  This is in contrast to apparently more complicated 
analyses such as calibration estimators for Cox models in case-cohort
designs, which follow just by putting standard pieces together in an 
obvious way.


-thomas

__
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] Choosing the number of colour breaks in ggplot2

2007-07-15 Thread Karl Ove Hufthammer
Fredag 13. juli 2007 skreiv hadley wickham:

 There's no official way to do it, but you can hack the colour
 gradient scale to do what you want:

 # Create a modified scale
 gr - scale_fill_gradient2()$clone()
 gr$breaks - function(.) seq(-100, 100, by=10)

Thank you so much. It works perfectly.

-- 
Karl Ove Hufthammer

__
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] How to sort a data.frame

2007-07-15 Thread Andrew Prendergast
I noticed a decent guide on how to sort data.frames is somewhat lacking.

To fill the gap I have written a quick post on the subject, which is here:

http://www.andrewprendergast.com/2007/07/sorting_a_dataframe_in_r.html

Regards,

ap.

__
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] How to load a dataset

2007-07-15 Thread Felipe Carrillo
Hi:
  Since I didn't get any answers, I'll refresh my question.
  I have a dataset called Chinook Run saved in Excel and I want it to be 
loaded everytime R starts, so I can call it with a statement like the one below:
  qplot(color, Year/Forklength, data = Chinook Run)
  I wonder how can I do that.
  I went to the rprofile.site and copied the path to my dataset there and it 
seems to work
  but I am wondering if that's how's done.
  Felipe
  



 Felipe D. Carrillo
  Fishery Biologist
  US Fish  Wildlife Service
  Red Bluff, California 96080

   
-

[[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] Break during the recursion?

2007-07-15 Thread Atte Tenkanen
Here is now more elegant function for inorder tree walk, but I still can't save 
the indexes!? This version now prints them ok, but if I use return, I get only 
the first v[i]. 

leftchild-function(i){return(2*i)}

rightchild-function(i){return(2*i+1)}

iotw-function(v,i)
{
if (is.na(v[i])==FALSE  is.null(unlist(v[i]))==FALSE)
{
iotw(v,leftchild(i))
print(v[i]) # return doesn't work here
iotw(v,rightchild(i))
}
}

 iotw(1:11,1)
[1] 8
[1] 4
[1] 9
[1] 2
[1] 10
[1] 5
[1] 11
[1] 1
[1] 6
[1] 3
[1] 7


Yours faithfully ;-)

Atte





- Original Message -
From: hadley wickham [EMAIL PROTECTED]
Date: Sunday, July 15, 2007 6:58 pm
Subject: Re: [R] Break during the recursion?

 On 7/15/07, Duncan Murdoch [EMAIL PROTECTED] wrote:
  On 15/07/2007 11:36 AM, Atte Tenkanen wrote:
   On 15/07/2007 10:33 AM, Atte Tenkanen wrote:
   On 15/07/2007 10:06 AM, Atte Tenkanen wrote:
   Hi,
  
   Is it possible to break using if-condition during the 
 recursive  function?
   You can do
  
if (condition) return(value)
  
   Here is a function which almost works. It is for inorder-
 tree-
   walk.
   iotw-function(v,i,Stack,Indexes) # input: a vector and the
   first
   index (1), Stack=c(), Indexes=c().
   {
 print(Indexes)
 # if (sum(i)==0) break # Doesn't work...
  if (sum(i)==0) return(NULL)
  
   should work.
  
   Duncan Murdoch
   Hmm - - - I'd like to save the Indexes-vector (in the example
   c(8,4,9,2,10,5,11,1,3)) and stop, when it is ready.
  
   This seems more like a problem with the design of your function
   than a
   question about R.  I can't really help you with that, because 
 your  description of the problem doesn't make sense to me.  What 
 does it
   mean
   to do an inorder tree walk on something that isn't a tree?
  
   Duncan Murdoch
  
   The symbols in vector v have been originally derived from 
 tree. See
  
   http://users.utu.fi/attenka/Tree.jpg
  
   But perhaps there's another way to do this, for instance by 
 using loops and if-conditions?
 
  Or perhaps by doing the tree walk on the tree, before you 
 collapse it
  into a vector.
 
 If it's a binary tree with n levels, I think you should be able to
 generate the positions more directly, depending on how the tree has
 been flattened.  Binary heaps work this way, so that might be a good
 place to start.  See http://en.wikipedia.org/wiki/Binary_heap,
 particularly heap implementation.
 
 Hadley


__
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] Break during the recursion?

2007-07-15 Thread hadley wickham
On 7/15/07, Atte Tenkanen [EMAIL PROTECTED] wrote:
 Here is now more elegant function for inorder tree walk, but I still can't 
 save the indexes!? This version now prints them ok, but if I use return, I 
 get only the first v[i].

 leftchild-function(i){return(2*i)}

 rightchild-function(i){return(2*i+1)}

 iotw-function(v,i)

 {
 if (is.na(v[i])==FALSE  is.null(unlist(v[i]))==FALSE)
 {
 iotw(v,leftchild(i))
 print(v[i]) # return doesn't work here
 iotw(v,rightchild(i))
 }
 }

Shouldn't you return:

c(iotw(v, leftchild(i)), v[i], iotw(v, rightchild(i)))

(and rewrite the conditition to return null if the node doesn't exist,
I think it reads clearer that way)

Hadley

__
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] Break during the recursion?

2007-07-15 Thread Atte Tenkanen
TNX Hadley!

Atte

- Original Message -
From: hadley wickham [EMAIL PROTECTED]
Date: Sunday, July 15, 2007 11:04 pm
Subject: Re: [R] Break during the recursion?

 On 7/15/07, Atte Tenkanen [EMAIL PROTECTED] wrote:
  Here is now more elegant function for inorder tree walk, but I 
 still can't save the indexes!? This version now prints them ok, but 
 if I use return, I get only the first v[i].
 
  leftchild-function(i){return(2*i)}
 
  rightchild-function(i){return(2*i+1)}
 
  iotw-function(v,i)
 
  {
  if (is.na(v[i])==FALSE  is.null(unlist(v[i]))==FALSE)
  {
  iotw(v,leftchild(i))
  print(v[i]) # return doesn't work here
  iotw(v,rightchild(i))
  }
  }
 
 Shouldn't you return:
 
 c(iotw(v, leftchild(i)), v[i], iotw(v, rightchild(i)))
 
 (and rewrite the conditition to return null if the node doesn't exist,
 I think it reads clearer that way)
 
 Hadley


__
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] HELP FOR BUGS

2007-07-15 Thread Mike Meredith


You might find the 'arm' package useful. For a good introduction to
heirarchical modeling, using 'arm' and also WinBUGS and R2WinBUGS, read
Gelman, A; J Hill 2007. Data analysis using regression and
multilevel/hierarchical models. Cambridge University Press.

Cheers,  Mike.


Ali raza-4 wrote:
 
 Hi Sir

   I am very new user of R for the research project on multilevel logistic
 regression.
   There is confusion about bugs() function in R and BUGS software. Is
 there any relation between these two? Is there any comprehensive package
 for  Multilevel Logistic modelling in R?

   Please guide in this regard.

   Thank You

   RAZA
 

 -
 Boardwalk for $500? In 2007? Ha! 
 
   [[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/HELP-FOR-BUGS-tf4078749.html#a11605645
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] NNET re-building the model

2007-07-15 Thread dos Reis, Marlon
Hello,
I've been working with nnet and  now I'd like to use the weigths, from
the fitted model, to iterpret some of variables impornatce.
I used the following command:
mts - nnet(y=Y,x=X,size =4, rang = 0.1,
 decay = 5e-4, maxit = 5000,linout=TRUE)
X is (m x n) Y is (m x 1)
And then I get the coeficients by:
Wts-coef(mts)

b-h1i1-h1i2-h1i3-h1i4-h1
i5-h1i6-h1i7-h1 ...
b-o h1-o h2-o h3-o h4-o  ...

I understood that I should get the predicted Y (hat(Y)) by:

hat(Y)=
(b-o)+((b-h1)sum(X[,1:m]*Wts[i1:m-h1]+X[,1:m]*Wts[i1:m-h2]+...+X[,1:m]
*Wts[i1:m-h4]))*(h1-o)+
((b-h2)sum(X[,1:m]*Wts[i1:m-h2]+X[,1:m]*Wts[i1:m-h2]+...+X[,1:m]*Wts[i1
:m-h4]))*(h2-o)+...)
Am I missed some point on this definition of NNET.
Thanks in advance,
Best Regards,
Marlon !!!


===
Attention: The information contained in this message and/or ...{{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] spatstat - Fitting a Strauss model with trend determined by kernel density smoother

2007-07-15 Thread Rolf Turner

On 14/07/2007, at 2:51 AM, Alejandro Veen wrote:

 Dear r-help,

 I would like to use the 'ppm' function of the 'spatstat' package to
 fit a Strauss inhibition model.  I understand that I can specify a
 parametric model for the background trend, but how would I specify a
 trend which is estimated using a Kernel density smoother?

 In particular, I would like to use the 'kde' function of the 'ks'
 package to estimate the background intensity and then use this as
 the trend for a Strauss inhibition process.


Questions about a specific contributed package should usually be  
directed to the maintainers of
that package rather than to r-help.

To attempt to answer your question:

You need to convert your estimate of the background trend to an  
***image***; see the
function im() in the spatstat package.

Or instead of using kde, you could use the ppp method for density()  
which is provided in
spatstat; this methop returns an image.  See the help for density.ppp 
().

Now suppose that your point pattern is ``X'' and your estimate of  
the trend is ``bgim''.

You can then fit the model you want via

fit - ppm(X,~bgim,inter=Strauss(42),covariates=list(bgim=bgim))

Note that you have to specify the interaction radius for the Strauss  
model (I have specified this
radius to be 42 in the forgoing example); this radius is an  
``irregular'' parameter --- i.e. it does
not appear in exponential family form --- and hence is not estimated  
by ppm(), at least not
directly.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confidenti...{{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] Please Please Help me!!!

2007-07-15 Thread TIMMMAY

Followings someones advice on a previous post I am reposting my question
again. Here is is and I would appreciate any help with my problem. This
question is basically a mathematical question, but I am sure there must be
an easy way to achieve the answer to my problem using R as, my problem seems
to me to be quite straight forward and something that people must use quite
a lot. So if there is an easy way to do this I would appreciate the help.

I have a transition intensities at different ages in a markov model. I want
to estimate this intensity by fitting a curve to the known intensities. The
data is as follows

Age Intensity
22 0.0002
27 0.0011
32 0.0074
37 0.0159
42 0.0292
47 0.0428
52 0.0265
57 0.0301
62 0.0270
67 0.0296

When plotted as intensity vs age, the data looks like a gamma curve. I want
to fit a gamma density curve to this data, so I need to estimate the
paramaters for the gamma curve,It is just a curve fitting problem but whats
causing the trouble is that I need to use least squares minimization to
calculate the parameters for the gamma curve. How do I do this??? 

The curve will be a truncated gamma function so it will have 3 paramaters a,
b, c. I tried to do the following 

nls(lograte ~ log(c) + a*log(b) + (a-1)*log(age)+b*(age)-lgamma(a),
start=list(a=1,b=1,c=1)), where lograte, and age are my data. a,b the gamma
parameters and c the parameter we need because we are fitting a truncated
distribution. 

I also tried defining 
fn = function(p) sum((log(y)-log(dgamma(x,p[1],p[2])*p[3]))^2) 
a residual sum of squares and using nlm to minimise this and find paramaters
but I cant get this to work either. Can anyone help me ?? Please :) 

Thanks


TIMMMAY wrote:
 
 I posted the message below a few days ago but I have not had any
 responses. I keep thinking that there must be some easy way to answer the
 problem I am just not familiar enough with regression to answer the
 problem myself. If anyone can help me I would be very grateful. I need to
 fit a gamma curve to a set of data. ie a scatterplot of the data indicates
 that the curve looks like a truncated gamma density function and I would
 like to estimate the paramaters so that I can fit a curve to the data
 points. Its not MLE paramater estimation just a curve fitting exercise.
 The problem again is 
 
 I have a set transition intensities and when plotted the curve looks like
 a gamma density. I want to fit a gamma density curve to these intensities.
 It is just a curve fitting problem but whats causing the trouble is that I
 need to use least squares minimization to calculate the parameters for the
 gamma curve. How do I do this??? 
 
 The curve will be a truncated gamma function so it will have 3 paramaters
 a, b, c. I tried to do the following 
 
 nls(lograte ~ log(c) + a*log(b) + (a-1)*log(age)+b*(age)-lgamma(a),
 start=list(a=1,b=1,c=1)), where lograte, and age are my data. a,b the
 gamma parameters and c the parameter we need because we are fitting a
 truncated distribution. 
 
 I also tried defining 
 fn = function(p) sum((log(y)-log(dgamma(x,p[1],p[2])*p[3]))^2) 
 a residual sum of squares and using nlm to minimise this and find
 paramaters but this doesnt work either. Can anyone help me ?? Please :) 
 
 Original message follows :(
 Fitting a Gamma Curve   
 by TIMMMAY Jul 12, 2007; 03:38pm :: Rate this Message:(use ratings to
 moderate[?])
 
 Reply | Reply to Author | Show Only this Message 
 
 Hi there, I hope someone can help me before I tear all my hair out. I have
 a set transition intensities and when plotted the curve looks like a gamma
 density. I want to fit a gamma density curve to these intensities. It is
 just a curve fitting problem but whats causing the trouble is that I need
 to use least squares minimization to calculate the parameters for the
 gamma curve. How do I do this??? 
 
 The curve will be a truncated gamma function so it will have 3 paramaters
 a, b, c. I tried to do the following 
 
 nls(lograte ~ log(c) + a*log(b) + (a-1)*log(age)+b*(age)-lgamma(a),
 start=list(a=1,b=1,c=1)), where lograte, and age are my data. a,b the
 gamma parameters and c the parameter we need because we are fitting a
 truncated distribution. 
 
 I also tried defining 
 fn = function(p) sum((log(y)-log(dgamma(x,p[1],p[2])*p[3]))^2) 
 a residual sum of squares and using nlm to minimise this and find
 paramaters but this doesnt work either. Can anyone help me ?? Please :) 
 
 
 
 
 « Return to forum
 
 Start a free forum or mailing list archive on Nabble  Help - Powered by -
 Terms of Use - Jobs at Nabble - Nabble Support  
 
 

-- 
View this message in context: 
http://www.nabble.com/Please-Please-Help-me%21%21%21-tf4081887.html#a11606008
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, 

Re: [R] NNET re-building the model

2007-07-15 Thread Prof Brian Ripley
This is almost unreadable (is your space bar broken?) but you seem to be 
missing the non-linearity of the hidden units.

The definition is in the book nnet (sic) supports, in a layout I cannot 
reproduce in plain text.

On Mon, 16 Jul 2007, dos Reis, Marlon wrote:

 Hello,
 I've been working with nnet and  now I'd like to use the weigths, from
 the fitted model, to iterpret some of variables impornatce.
 I used the following command:
 mts - nnet(y=Y,x=X,size =4, rang = 0.1,
 decay = 5e-4, maxit = 5000,linout=TRUE)
 X is (m x n) Y is (m x 1)
 And then I get the coeficients by:
 Wts-coef(mts)

 b-h1i1-h1i2-h1i3-h1i4-h1
 i5-h1i6-h1i7-h1 ...
 b-o h1-o h2-o h3-o h4-o  ...

 I understood that I should get the predicted Y (hat(Y)) by:

 hat(Y)=
 (b-o)+((b-h1)sum(X[,1:m]*Wts[i1:m-h1]+X[,1:m]*Wts[i1:m-h2]+...+X[,1:m]
 *Wts[i1:m-h4]))*(h1-o)+
 ((b-h2)sum(X[,1:m]*Wts[i1:m-h2]+X[,1:m]*Wts[i1:m-h2]+...+X[,1:m]*Wts[i1
 :m-h4]))*(h2-o)+...)
 Am I missed some point on this definition of NNET.
 Thanks in advance,
 Best Regards,
 Marlon !!!


 ===
 Attention: The information contained in this message and/or ...{{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.


-- 
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] Restructuring data

2007-07-15 Thread Daniel Malter
Hi folks,

I am new to the list and relatively new to R. I am trying to unstack data
arraywise and could not find a convenient solution yet. I tried to find a
solution for the problem on help archives. I also tried to use the reshape
command in R and the reshape package but could not get result. I will
illustrate the case below, but the real dataset is quite large so that I
would appreciate an easy solution if there is any.

The current data structure (variable names): 

ID, TIME, BUY-A, BUY-B, SELL-A, SELL-B

Achieved structure (with the reshape command or the reshape package)

ID, TIME, BUY-A
ID, TIME, BUY-B
ID, TIME, SELL-A
ID, TIME, SELL-B 

This is regular unstacking with two identifier variables. Nothing special
though. What I am looking for and did not manage is the following structure:

ID, TIME, BUY-A, SELL-A
ID, TIME, BUY-B, SELL-B

I am quite sure it's pretty easy, but I could not find how to do this. 

Thanks a bunch,
Daniel

__
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] Partial Proportional Odds model using vglm

2007-07-15 Thread Rizwan Younis
Hi:
I am trying to fit a PPO model using vglm from VGAM, and get an error while
executing the code. 

Here is the data, code, and error:

Data  = rc13, first row is the column names. a = age, and 1,2,3, 4 and 5 are
condition grades.

  a  1 2 3  4 5
  1  1 0 0  0 0
  2 84 2 7 10 2
  3 16 0 6  6 2
  4 13 0 3  4 0
  5  0 0 0  1 0

rc13-read.table(icg_rcPivot_group2.txt,header=F)
names(rc13)-c(a,1,2,3,4,5)

ppo-vglm(cbind(rc13[,2],rc13[,3],rc13[,4],rc13[,5],rc13[,6])~a,family =
cumulative(link = logit, parallel = F , reverse = F),na.action=na.pass,
data=rc13)
summary(ppo)

I get the following error:

Error in [-(`*tmp*`, , index, value = c(1.13512932539841,
0.533057528200189,  : 
number of items to replace is not a multiple of replacement length
In addition: Warning messages:
1: NaNs produced in: log(x) 
2: fitted values close to 0 or 1 in: tfun(mu = mu, y = y, w = w, res =
FALSE, eta = eta, extra) 
3: 19 elements replaced by 1.819e-12 in: checkwz(wz, M = M, trace = trace,
wzeps = control$wzepsilon)

I will appreciate any help to fix this problem.
Thanks

Reez You
Grad Student
University of Waterloo
Waterloo, ON Canada

__
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] neural networks function in R

2007-07-15 Thread adschai
Hi all gurus,

I have a few general questions about using neural networks function, i.e. the 
nnet function. I'm new to this function and still exploring it. So please 
kindly bear with me.

Here are my questions.

1. Is there anyway that I can specify my own objective or loss function for my 
neural networks? I see that by arguments that we can pass into the networks, we 
have either square loss or entropy. I'm trying to create an NN that fits 
ordinal regression data. So my objective function is the likelihood function 
but is not exactly the entropy function due to the fact that order of the 
labels matters in my application. Or I'm better of to write my own function?

2. If I need to write my own function, I could see that I can use constOptim to 
help me maximize my likelihood. Another question here is how can I pass 
analytical gradient function of each of my network weight into the function? 
Specifically, my question is that does my gradient function has to be flat 
representation of each parameter like the following arbitrary example:

2*w_i1_h1+3*w_h1_o1+4 (where w_i1_h1 is weight of input node 1 to hidden layer 
node 1, and vice versa)

Or I can do a nest expression like:

sigmoid(node_eval(input_x, j)) 

here my node_eval is a function that takes in input_x feature value vector and 
produces output to node j in the next layer. 

If expression base evaluation like in case 2 is possible, it will significantly 
simplify the definition of my gradient function output. 

Any help would be really appreciated on these issues. Thank you.

- adschai

__
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] Restructuring data

2007-07-15 Thread deepayan . sarkar
On 7/15/07, Daniel Malter [EMAIL PROTECTED] wrote:
 Hi folks,

 I am new to the list and relatively new to R. I am trying to unstack data
 arraywise and could not find a convenient solution yet. I tried to find a
 solution for the problem on help archives. I also tried to use the reshape
 command in R and the reshape package but could not get result. I will
 illustrate the case below, but the real dataset is quite large so that I
 would appreciate an easy solution if there is any.

 The current data structure (variable names):

 ID, TIME, BUY-A, BUY-B, SELL-A, SELL-B

 Achieved structure (with the reshape command or the reshape package)

 ID, TIME, BUY-A
 ID, TIME, BUY-B
 ID, TIME, SELL-A
 ID, TIME, SELL-B

 This is regular unstacking with two identifier variables. Nothing special
 though. What I am looking for and did not manage is the following structure:

 ID, TIME, BUY-A, SELL-A
 ID, TIME, BUY-B, SELL-B

 I am quite sure it's pretty easy, but I could not find how to do this.

This seems to work:

 foo - data.frame(ID = 1:4, TIME=1:4,
+   BUY-A = rnorm(4),
+   BUY-B = rnorm(4),
+   SELL-A = rnorm(4),
+   SELL-B = rnorm(4), check.names = FALSE)


 foo
  ID TIME   BUY-A  BUY-B SELL-A  SELL-B
1  11  0.47022807 1.09573107  0.1977035 -0.08333043
2  22 -0.20672870 0.07397772  1.4959044 -0.98555020
3  33  0.05533779 0.25821758  1.3531913  0.16808307
4  44 -0.11471772 1.27798740 -0.1101390 -0.36937994

 reshape(foo, direction=long,
+ varying = list(c(BUY-A, BUY-B), c(SELL-A, SELL-B)),
+ v.names=c(BUY, SELL), idvar=ID,
+ times = c(A, B), timevar=which)
ID TIME which BUYSELL
1.A  11 A  0.47022807  0.19770349
2.A  22 A -0.20672870  1.49590443
3.A  33 A  0.05533779  1.35319133
4.A  44 A -0.11471772 -0.11013896
1.B  11 B  1.09573107 -0.08333043
2.B  22 B  0.07397772 -0.98555020
3.B  33 B  0.25821758  0.16808307
4.B  44 B  1.27798740 -0.36937994

-Deepayan

__
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 sort a data.frame

2007-07-15 Thread Gabor Grothendieck
The example could be simplified like this:

T - productSalesByStore
T - merge(T, rowsum(T$sales, T$store), by.x = 2, by.y = 0)
T[order(T$V1, T$sales, decreasing = TRUE), 1:3]

If you transfer your data to a data base then this SQL statement would
also do it:

select store, product, sales
   from productSalesByStore
   natural join (select store, sum(sales) storesales from
 productSalesByStore group by store)
   order by storesales desc, sales desc

On 7/15/07, Andrew Prendergast [EMAIL PROTECTED] wrote:
 I noticed a decent guide on how to sort data.frames is somewhat lacking.

 To fill the gap I have written a quick post on the subject, which is here:

 http://www.andrewprendergast.com/2007/07/sorting_a_dataframe_in_r.html

 Regards,

 ap.

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


[R] Dates in 'persp' plots

2007-07-15 Thread Josh Quigley
Hello,

I would like to have the y axis show dates in a 3D 'persp' plot.

The following example works...

x - spot
y - as.numeric(dates)# class(dates) produces output [1] Date
z - t(price)

persp(x, y, z, ticktype=detailed)


...however the y axes contains 'meaningless' integers (days since 1970-01-01
is not very intuitive!)

Changing the commented line above to 

y - dates

is no good because 'persp' automatically coerces input to numeric types.

I would really like the axis to be labeled with dates. A string, eg
13-Jul-2007 would be best, but ISO date integer, eg 20070713, would also
be acceptable.

I've checked help for 'persp' and 'par' with no luck - any ideas
appreciated!

Cheers,

Josh.

__
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 sort a data.frame

2007-07-15 Thread Gabor Grothendieck
In thinking about this a bit more an even simpler solution based on ave is:

storesales - ave(T$sales, T$store, FUN = sum)
T[order(storesales, T$sales, decreasing = TRUE), ]


On 7/15/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
 The example could be simplified like this:

 T - productSalesByStore
 T - merge(T, rowsum(T$sales, T$store), by.x = 2, by.y = 0)
 T[order(T$V1, T$sales, decreasing = TRUE), 1:3]

 If you transfer your data to a data base then this SQL statement would
 also do it:

 select store, product, sales
   from productSalesByStore
   natural join (select store, sum(sales) storesales from
 productSalesByStore group by store)
   order by storesales desc, sales desc

 On 7/15/07, Andrew Prendergast [EMAIL PROTECTED] wrote:
  I noticed a decent guide on how to sort data.frames is somewhat lacking.
 
  To fill the gap I have written a quick post on the subject, which is here:
 
  http://www.andrewprendergast.com/2007/07/sorting_a_dataframe_in_r.html
 
  Regards,
 
  ap.
 
  __
  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] Restructuring data

2007-07-15 Thread hadley wickham
On 7/16/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 On 7/15/07, Daniel Malter [EMAIL PROTECTED] wrote:
  Hi folks,
 
  I am new to the list and relatively new to R. I am trying to unstack data
  arraywise and could not find a convenient solution yet. I tried to find a
  solution for the problem on help archives. I also tried to use the reshape
  command in R and the reshape package but could not get result. I will
  illustrate the case below, but the real dataset is quite large so that I
  would appreciate an easy solution if there is any.
 
  The current data structure (variable names):
 
  ID, TIME, BUY-A, BUY-B, SELL-A, SELL-B
 
  Achieved structure (with the reshape command or the reshape package)
 
  ID, TIME, BUY-A
  ID, TIME, BUY-B
  ID, TIME, SELL-A
  ID, TIME, SELL-B
 
  This is regular unstacking with two identifier variables. Nothing special
  though. What I am looking for and did not manage is the following structure:
 
  ID, TIME, BUY-A, SELL-A
  ID, TIME, BUY-B, SELL-B
 
  I am quite sure it's pretty easy, but I could not find how to do this.

 This seems to work:

  foo - data.frame(ID = 1:4, TIME=1:4,
 +   BUY-A = rnorm(4),
 +   BUY-B = rnorm(4),
 +   SELL-A = rnorm(4),
 +   SELL-B = rnorm(4), check.names = FALSE)
 
 
  foo
   ID TIME   BUY-A  BUY-B SELL-A  SELL-B
 1  11  0.47022807 1.09573107  0.1977035 -0.08333043
 2  22 -0.20672870 0.07397772  1.4959044 -0.98555020
 3  33  0.05533779 0.25821758  1.3531913  0.16808307
 4  44 -0.11471772 1.27798740 -0.1101390 -0.36937994
 
  reshape(foo, direction=long,
 + varying = list(c(BUY-A, BUY-B), c(SELL-A, SELL-B)),
 + v.names=c(BUY, SELL), idvar=ID,
 + times = c(A, B), timevar=which)
 ID TIME which BUYSELL
 1.A  11 A  0.47022807  0.19770349
 2.A  22 A -0.20672870  1.49590443
 3.A  33 A  0.05533779  1.35319133
 4.A  44 A -0.11471772 -0.11013896
 1.B  11 B  1.09573107 -0.08333043
 2.B  22 B  0.07397772 -0.98555020
 3.B  33 B  0.25821758  0.16808307
 4.B  44 B  1.27798740 -0.36937994

It's a little more verbose with the reshape package, but I find it
easier to understand what's going on.

fm - melt(foo, id=c(ID,TIME))
fm - cbind(fm, colsplit(fm$variable, -, c(direction,type)))
fm$variable - NULL

cast(fm, ... ~ direction)

There's an example like this in the introduction to reshape manual.

Hadley

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