[R] symbol.C is now deprecated?

2006-12-02 Thread Wee-Jin Goh
Hello list,

I have a function that I wrote in C to be called in R. I've done that  
using symbol.C, which is the method I came across on the internet.

Now that it's supposed to be deprecated and can be removed in the  
next version of R (!!), what up-to-date method that replaces symbol.C?

cheers,
Wee-Jin

__
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] Quadratic Optimization

2006-12-02 Thread Martin Maechler
 SpG == Spencer Graves [EMAIL PROTECTED]
 on Fri, 01 Dec 2006 17:29:56 -0800 writes:

SpG   Unless I'm missing something, optimizing a linear
SpG function with quadratic constraints is almost trivial
SpG with Langrange multipliers.

yes. Good point, let's hope we're not solving someone's homework
here :-)

SpG   Maximize a'x subject to x'Ax=c.

SpG   S = Lagrange objective = a'x+lam*(x'Ax-c).
SpG dS/dx = a + 2*lam*Ax.

SpG   Given lam, x1 = solve(A, a)/(2*lam)

  [you forgot a - , but it's irrelevant, since 'lam' arbitrarily varies;
   and we can use  x1 = solve(A,a) in the following ]

SpG   Then x = c*x1/(x'Ax)

but the last equation above is not useful (x on the RHS).
Rather, we know that  x = s * x1 (for some scalar 's') and from
the constraint x'Ax = c (or equivalently, from dS/d{lam} = 0),
we find that

   s = +/- sqrt(c / (x1' A x1))

and can even see that  x1' A x1 = x1' A A^{-1} a =  x1' a

Note the +/- : we get the minimizing and the maximizing values

SpG   In R, you need to know that t = transpose of a
SpG matrix.

In other words, as an algorithm in R



solveLinQuad - function(a,A,c)
{
## Purpose: maximize a'x  under constraint  x'Ax = c
##   we return x = arg.max{...}, but note that  arg.min{..} = -x
## ---
## Author: Martin Maechler, Date:  2 Dec 2006

## argument checking ...
stopifnot(is.matrix(A), nrow(A) == ncol(A), length(a) == nrow(A),
  is.numeric(A), is.numeric(a), is.numeric(c))
x1 - solve(A,a)
## note that  x1' A x1 = x1' A A^{-1} a = x1' a { == sum(x1 * a) }
x - sqrt(c / sum(x1 * a)) * x1
## we return the arg.max :
if(sum(x * a) = 0) x else -x
}

## Test:
set.seed(1)
A - crossprod(matrix(round(rnorm(24),2), 6,4))
a - c(-1, 1, -2, 6)
c - 3
(x - solveLinQuad(a,A,c))
##-
sum(a * x) # 4.677
## constraint
sum(x * (A %*% x)) ## - 3

SpG   I thought I had seen mention of a contributed
SpG package for optimization with nonlinear constraints.
SpG However, you don't need that here.

SpG   In case this does not solve your problem, my
SpG crude engineer's approach to constrained optimization
SpG includes the following:

SpG   (1) Find transformation to send the constraints
SpG to +/-Inf.

SpG   (2) If that fails, add the constraints as a
SpG penalty.  Start with a low penalty and gradually
SpG increase it if necessary until you solve the problem.
SpG Of course, to do this, you have to make sure your
SpG objective function returns valid numbers outside the
SpG constrained region.

SpG   How's this?  Spencer Graves

SpG amit soni wrote:
 Hi,

 I need to solve an optimization problem in R having
 linear objective function and quadratic
 constraints(number of variables is around 80).  What are
 the possible choices to do this in R.  optim() function
 only allows box constrained problems. Is it possible in
 nlm()? Or please tell me if there is any other routine.

 Thanks

 Amit

__
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] error using environment(f) - NULL

2006-12-02 Thread Carmen Meier
Hi To all,
I found in the tread
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/46740.html

the reply for

/ y - 3 /
/ f - function(x) y /
/ environment(f) - NULL /
/ f(1)

/but this example (R 2.4.0) will cause an error:

The use of the NULL environment is not longer possible (translated)
The ?environment reports the NULL as possible.
is there any other way now ,to get the same result

Regards Carmen

__
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] error using environment(f) - NULL

2006-12-02 Thread Gabor Grothendieck
Try :

environment(f) - baseenv()

There is also emptyenv() depending on what you want.

See ?baseenv



On 12/2/06, Carmen Meier [EMAIL PROTECTED] wrote:
 Hi To all,
 I found in the tread
 http://finzi.psych.upenn.edu/R/Rhelp02a/archive/46740.html

 the reply for

 / y - 3 /
 / f - function(x) y /
 / environment(f) - NULL /
 / f(1)

 /but this example (R 2.4.0) will cause an error:

 The use of the NULL environment is not longer possible (translated)
 The ?environment reports the NULL as possible.
 is there any other way now ,to get the same result

 Regards Carmen

 __
 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] Fwd: Urgent Help in Paste Command

2006-12-02 Thread Shubha Karanth
Hi Experts,

I want to see my object as below:
 'C:\Program Files\R\R-2.4.0\bin\Rgui.exe'
So I use the paste command. None of the below is working. Could anyone help
me on this?

 paste('C:\Program Files\R\R-2.4.0\bin\Rgui.exe')
[1] 'C:Program FilesRR-2.4.0\binRgui.exe'

 paste('C:,\,Program Files,\,R,\,R-2.4.0,\,bin,\,
Rgui.exe',sep=)
Error: syntax error in paste('C:,\,Program

paste('C:,Program Files,R,R-2.4.0,bin,Rgui.exe',sep=\)
+

I need to only use the \ symbol and not / or \\. Please help me…

Thank you,
Shubha.

[[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] Is there a better way for inputing data manually?

2006-12-02 Thread Michael Dewey
At 04:40 02/12/2006, Duncan Murdoch wrote:
On 12/1/2006 11:00 PM, Wei-Wei Guo wrote:
Dear All,
I have worked with R for some time. It's a great tool for data 
analysis. But it's too hard to inputing raw data manually with R (I 
don't mean importing data. R is good at importing data). Maybe it's 
not a focused topic in this list, but I don't know other place 
where I can ask the question. How do you do when inputing data from 
a paper material, such as questionnaire, or what do you use ?

I would not use R for this.  Depending on how many questionnaires I 
had, from small number to large, I would use:

1.  A text file.
2.  A spreadsheet, like Excel, or the OpenOffice one, or the R data editor.
3.  A custom program written specifically to handle the particular 
questionnaire.

You can do 1 and 2 in R, but you can't do them as well as programs 
dedicated to those tasks, and you can't do 3 at all well.  It 
depends a lot on the specific conventions of the platform you're 
working on.  R is aimed at writing cross-platform programs, and 
isn't particularly good at writing GUI programs, which is what you 
want here.  I would personally use Delphi for this, but there are 
lots of alternatives.

I usually use Epidata, available from http://www.epidata.dk/, which 
is free and enables you to write your own questionnaire file and then 
input your data. It also enables you to implement checks during data 
entry which in my view is an important feature. It enables export in 
a number of formats but its native output format, the .rec file, can 
be read into R using the foreign package.

Duncan Murdoch



Michael Dewey
http://www.aghmed.fsnet.co.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] Fwd: Urgent Help in Paste Command

2006-12-02 Thread Gabor Grothendieck
Try this:

 x - readline()
C:\Program Files\R\R-2.4.0\bin\Rgui.exe
 x
[1] C:\\Program Files\\R\\R-2.4.0\\bin\\Rgui.exe



You can also use

   readLines(clipboard)

if you are trying to read in something from the clipboard.


On 12/2/06, Shubha Karanth [EMAIL PROTECTED] wrote:
 Hi Experts,

 I want to see my object as below:
 'C:\Program Files\R\R-2.4.0\bin\Rgui.exe'
 So I use the paste command. None of the below is working. Could anyone help
 me on this?

  paste('C:\Program Files\R\R-2.4.0\bin\Rgui.exe')
 [1] 'C:Program FilesRR-2.4.0\binRgui.exe'

  paste('C:,\,Program Files,\,R,\,R-2.4.0,\,bin,\,
 Rgui.exe',sep=)
 Error: syntax error in paste('C:,\,Program

 paste('C:,Program Files,R,R-2.4.0,bin,Rgui.exe',sep=\)
 +

 I need to only use the \ symbol and not / or \\. Please help me…

 Thank you,
 Shubha.

[[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] Fwd: Urgent Help in Paste Command

2006-12-02 Thread Shubha Vishwanath Karanth
But when I do this I need x value to be  C:\Program
Files\R\R-2.4.0\bin\Rgui.exe and not C:\\Program
Files\\R\\R-2.4.0\\bin\\Rgui.exe

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Gabor
Grothendieck
Sent: Saturday, December 02, 2006 5:21 PM
To: Shubha Karanth
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Fwd: Urgent Help in Paste Command

Try this:

 x - readline()
C:\Program Files\R\R-2.4.0\bin\Rgui.exe
 x
[1] C:\\Program Files\\R\\R-2.4.0\\bin\\Rgui.exe



You can also use

   readLines(clipboard)

if you are trying to read in something from the clipboard.


On 12/2/06, Shubha Karanth [EMAIL PROTECTED] wrote:
 Hi Experts,

 I want to see my object as below:
 'C:\Program Files\R\R-2.4.0\bin\Rgui.exe'
 So I use the paste command. None of the below is working. Could anyone
help
 me on this?

  paste('C:\Program Files\R\R-2.4.0\bin\Rgui.exe')
 [1] 'C:Program FilesRR-2.4.0\binRgui.exe'

  paste('C:,\,Program
Files,\,R,\,R-2.4.0,\,bin,\,
 Rgui.exe',sep=)
 Error: syntax error in paste('C:,\,Program

 paste('C:,Program Files,R,R-2.4.0,bin,Rgui.exe',sep=\)
 +

 I need to only use the \ symbol and not / or \\. Please help me...

 Thank you,
 Shubha.

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

__
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] Fwd: Urgent Help in Paste Command

2006-12-02 Thread Gabor Grothendieck
x is the value you asked for.  I think you are confusing its printed
representation
with its value.  Try cat(x) and strsplit(x, )

On 12/2/06, Shubha Vishwanath Karanth [EMAIL PROTECTED] wrote:
 But when I do this I need x value to be  C:\Program
 Files\R\R-2.4.0\bin\Rgui.exe and not C:\\Program
 Files\\R\\R-2.4.0\\bin\\Rgui.exe

 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Gabor
 Grothendieck
 Sent: Saturday, December 02, 2006 5:21 PM
 To: Shubha Karanth
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] Fwd: Urgent Help in Paste Command

 Try this:

  x - readline()
 C:\Program Files\R\R-2.4.0\bin\Rgui.exe
  x
 [1] C:\\Program Files\\R\\R-2.4.0\\bin\\Rgui.exe



 You can also use

   readLines(clipboard)

 if you are trying to read in something from the clipboard.


 On 12/2/06, Shubha Karanth [EMAIL PROTECTED] wrote:
  Hi Experts,
 
  I want to see my object as below:
  'C:\Program Files\R\R-2.4.0\bin\Rgui.exe'
  So I use the paste command. None of the below is working. Could anyone
 help
  me on this?
 
   paste('C:\Program Files\R\R-2.4.0\bin\Rgui.exe')
  [1] 'C:Program FilesRR-2.4.0\binRgui.exe'
 
   paste('C:,\,Program
 Files,\,R,\,R-2.4.0,\,bin,\,
  Rgui.exe',sep=)
  Error: syntax error in paste('C:,\,Program
 
  paste('C:,Program Files,R,R-2.4.0,bin,Rgui.exe',sep=\)
  +
 
  I need to only use the \ symbol and not / or \\. Please help me...
 
  Thank you,
  Shubha.
 
 [[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.


__
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] Fwd: Urgent Help in Paste Command

2006-12-02 Thread Shubha Vishwanath Karanth
O yaa... Thank you so much...

 



From: jim holtman [mailto:[EMAIL PROTECTED] 
Sent: Saturday, December 02, 2006 5:58 PM
To: Shubha Vishwanath Karanth
Subject: Re: [R] Fwd: Urgent Help in Paste Command

 

It is fine since '\' is used to escape characters (like ' and ), it
prints as '\\' escaping itself.
 

 x - '\\'  # need to escape 'escape'
 x
[1] \\
 cat(x)
\ 
 

 

For use in path names, use '/'; usable on Windows and other systems:

 

fileName - 'C:/Program Files/R/R-2.4.0/bin/Rgui.exe'
 

On 12/2/06, Shubha Vishwanath Karanth [EMAIL PROTECTED] wrote: 

But when I do this I need x value to be  C:\Program
Files\R\R-2.4.0\bin\Rgui.exe and not C:\\Program 
Files\\R\\R-2.4.0\\bin\\Rgui.exe

-Original Message-
From: [EMAIL PROTECTED]
[mailto: [EMAIL PROTECTED]
mailto:[EMAIL PROTECTED] ] On Behalf Of Gabor
Grothendieck
Sent: Saturday, December 02, 2006 5:21 PM
To: Shubha Karanth
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Fwd: Urgent Help in Paste Command

Try this:

 x - readline()
C:\Program Files\R\R-2.4.0\bin\Rgui.exe
 x
[1] C:\\Program Files\\R\\R-2.4.0\\bin\\Rgui.exe



You can also use

  readLines(clipboard)

if you are trying to read in something from the clipboard.


On 12/2/06, Shubha Karanth [EMAIL PROTECTED]  wrote:
 Hi Experts,

 I want to see my object as below:
 'C:\Program Files\R\R-2.4.0\bin\Rgui.exe'
 So I use the paste command. None of the below is working. Could anyone
help
 me on this?

  paste('C:\Program Files\R\R-2.4.0\bin\Rgui.exe')
 [1] 'C:Program FilesRR-2.4.0\binRgui.exe'

  paste('C:,\,Program 
Files,\,R,\,R-2.4.0,\,bin,\,
 Rgui.exe',sep=)
 Error: syntax error in paste('C:,\,Program 

 paste('C:,Program Files,R,R-2.4.0,bin,Rgui.exe',sep=\)
 +

 I need to only use the \ symbol and not / or \\. Please help me... 

 Thank you,
 Shubha.

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

__
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] Fwd: Urgent Help in Paste Command

2006-12-02 Thread Shubha Vishwanath Karanth

O yaa... Thank you so much...
-Original Message-
From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] 
Sent: Saturday, December 02, 2006 5:56 PM
To: Shubha Vishwanath Karanth
Cc: Shubha Karanth; r-help@stat.math.ethz.ch
Subject: Re: [R] Fwd: Urgent Help in Paste Command

x is the value you asked for.  I think you are confusing its printed
representation
with its value.  Try cat(x) and strsplit(x, )

On 12/2/06, Shubha Vishwanath Karanth [EMAIL PROTECTED] wrote:
 But when I do this I need x value to be  C:\Program
 Files\R\R-2.4.0\bin\Rgui.exe and not C:\\Program
 Files\\R\\R-2.4.0\\bin\\Rgui.exe

 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Gabor
 Grothendieck
 Sent: Saturday, December 02, 2006 5:21 PM
 To: Shubha Karanth
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] Fwd: Urgent Help in Paste Command

 Try this:

  x - readline()
 C:\Program Files\R\R-2.4.0\bin\Rgui.exe
  x
 [1] C:\\Program Files\\R\\R-2.4.0\\bin\\Rgui.exe



 You can also use

   readLines(clipboard)

 if you are trying to read in something from the clipboard.


 On 12/2/06, Shubha Karanth [EMAIL PROTECTED] wrote:
  Hi Experts,
 
  I want to see my object as below:
  'C:\Program Files\R\R-2.4.0\bin\Rgui.exe'
  So I use the paste command. None of the below is working. Could
anyone
 help
  me on this?
 
   paste('C:\Program Files\R\R-2.4.0\bin\Rgui.exe')
  [1] 'C:Program FilesRR-2.4.0\binRgui.exe'
 
   paste('C:,\,Program
 Files,\,R,\,R-2.4.0,\,bin,\,
  Rgui.exe',sep=)
  Error: syntax error in paste('C:,\,Program
 
  paste('C:,Program
Files,R,R-2.4.0,bin,Rgui.exe',sep=\)
  +
 
  I need to only use the \ symbol and not / or \\. Please help me...
 
  Thank you,
  Shubha.
 
 [[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.


__
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] Quadratic Optimization

2006-12-02 Thread Prof Brian Ripley
On Sat, 2 Dec 2006, Martin Maechler wrote:

 SpG == Spencer Graves [EMAIL PROTECTED]
 on Fri, 01 Dec 2006 17:29:56 -0800 writes:

SpG   Unless I'm missing something, optimizing a linear
SpG function with quadratic constraints is almost trivial
SpG with Langrange multipliers.

 yes. Good point, let's hope we're not solving someone's homework
 here :-)

But that is a single equality quadratic constraint, and I believe 
'quadratic constraints' (note, plural) conventionally means multiple 
inequality constraints.  That meaning is a hard problem that needs 
specialized software (most likely using interior-point methods).

SpG   Maximize a'x subject to x'Ax=c.

Not I believe the usual meaning (nor what Googling 'quadratic constraints' 
came up with for me).

-- 
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] symbol.C is now deprecated?

2006-12-02 Thread Duncan Murdoch
On 12/2/2006 4:04 AM, Wee-Jin Goh wrote:
 Hello list,
 
 I have a function that I wrote in C to be called in R. I've done that  
 using symbol.C, which is the method I came across on the internet.
 
 Now that it's supposed to be deprecated and can be removed in the  
 next version of R (!!), what up-to-date method that replaces symbol.C?

You don't need it at all.  Just give the entry point name directly in 
you .C() calls.  This is documented in the Writing R Extensions manual, 
with examples.

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] newbie: new_data_frame - selected set of rows

2006-12-02 Thread Philipp Pagel

Hi!

 distances - order(distancevector(scaled_DB, scaled_DB['query',],
 d=euclid))

Just compute the distances WITHOUT ordering, here. And then

 1) create a small top_five frame

top = scaled_DB[rank(distances)=5, ]

rank() is better for this than order() in case there are ties.

 2) after I got top_five I woul like to get the index
 of my query entry, something along Pythons 
 top_five.index('query_string')

You mean by row name?

which(row.names(scaled_DB)=='query_string')

But why would you need the index? If you want to get the respective row
use logical indexing:

my_dataframe['query_string', ]

 3) possibly combine values in distances with row names
 from my_dataframe:
 row_1 distance_from_query1
 row_2 distance_from_query2

The easiest way to store the distances along with the original names and
data would be to simply make distances a column in your data frame,
which is what I would have done to begin with. The entire procedure
would then look like this:

my_dataframe = read.table( ... )
scaled_DB - scale(my_dataframe, center=FALSE)
scaled_DB$dist1 = distancevector(scaled_DB, scaled_DB['query1',], ...)
scaled_DB$dist2 = distancevector(scaled_DB, scaled_DB['query2',], ...)
scaled_DB$dist3 = distancevector(scaled_DB, scaled_DB['query3',], ...)
...
top1 = scaled_DB[rank(scaled_DB$dist1)=5, ]
...

cu
Philipp

-- 
Dr. Philipp PagelTel.  +49-8161-71 2131
Dept. of Genome Oriented Bioinformatics  Fax.  +49-8161-71 2186
Technical University of Munich
Science Center Weihenstephan
85350 Freising, Germany

 and

Institute for Bioinformatics / MIPS  Tel.  +49-89-3187 3675
GSF - National Research Center   Fax.  +49-89-3187 3585
  for Environment and Health
Ingolstädter Landstrasse 1
85764 Neuherberg, Germany
http://mips.gsf.de/staff/pagel

__
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] Trouble passing arrays to C code

2006-12-02 Thread Wee-Jin Goh
Hello,

I'm having more trouble with interfacing with C code. I have a  
function in C that will return the result of its computation as 3  
arrays. The signature of the function is as follows:

void lorenz_run(double x0, double y0, double z0, double h, int steps,
double *res_x, double *res_y, double 
*res_z)

The function works, as I've tested it from within C itself and the  
results it gives are accurate. In order to integrate it with R, I've  
written the following C wrapper function:

void lorenz_run_R_wrapper(double *x0, double *y0, double *z0, double  
*h, double *steps,
double *res_x, double *res_y, double *res_z) {
lorenz_run(*x0, *y0, *z0, *h, *steps, res_x, res_y, res_z); 
}

The corresponding R wrapper function is:

lorenz_run - function(x0,y0,z0,h,steps) {
returned_data = .C(lorenz_run_R_wrapper,
x0=as.double(x0),
y0=as.double(y0),
z0=as.double(z0),
h=as.double(h),
steps=as.integer(steps),
res_x=double(steps),
res_y=double(steps),
res_z=double(steps))
  # Return the value of the result parameter
  return( rbind(returned_data$res_x, returned_data$res_y,  
returned_data$res_z))

}

My problem is, that the first elements of res_x, res_y, and res_z are  
correctly set. But the rest of the cells in those 3 arrays remain 0.  
This leads me to think that I am passing these arrays to the C code  
wrongly. Can anyone help me out?

Thanks in advance,
Wee-Jin

__
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] Trouble passing arrays to C code

2006-12-02 Thread Antonio, Fabio Di Narzo
2006/12/2, Wee-Jin Goh [EMAIL PROTECTED]:
 Hello,

 I'm having more trouble with interfacing with C code. I have a
 function in C that will return the result of its computation as 3
 arrays. The signature of the function is as follows:

 void lorenz_run(double x0, double y0, double z0, double h, int steps,
 double *res_x, double *res_y, double 
 *res_z)

 The function works, as I've tested it from within C itself and the
 results it gives are accurate. In order to integrate it with R, I've
 written the following C wrapper function:

 void lorenz_run_R_wrapper(double *x0, double *y0, double *z0, double
 *h, double *steps,

here 'steps' is double, was integer in 'lorenz_run'.

 double *res_x, double *res_y, double *res_z) {
 lorenz_run(*x0, *y0, *z0, *h, *steps, res_x, res_y, res_z);
 }

 The corresponding R wrapper function is:

 lorenz_run - function(x0,y0,z0,h,steps) {
 returned_data = .C(lorenz_run_R_wrapper,
 x0=as.double(x0),
 y0=as.double(y0),
 z0=as.double(z0),
 h=as.double(h),
 steps=as.integer(steps),
 res_x=double(steps),
 res_y=double(steps),
 res_z=double(steps))
   # Return the value of the result parameter
   return( rbind(returned_data$res_x, returned_data$res_y,
 returned_data$res_z))

 }

 My problem is, that the first elements of res_x, res_y, and res_z are
 correctly set. But the rest of the cells in those 3 arrays remain 0.
 This leads me to think that I am passing these arrays to the C code
 wrongly.  Can anyone help me out?

 Thanks in advance,
 Wee-Jin

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



--
Antonio, Fabio Di Narzo
Ph.D. student at
Department of Statistical Sciences
University of Bologna, Italy

__
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] Chi-squared approximation may be incorrect in: chisq.test(x)

2006-12-02 Thread Ethan Johnsons
I am getting Chi-squared approximation may be incorrect in:
chisq.test(x)  with the data bleow.

Frequency distribution of number of male offspring in families of size 5.
Number of Male OffspringN
0 518
12245
2 4621
3 4753
4 2476
5   549
Total 15,162


 x=matrix(c(0,1,2,3,4,5,518,2245,4621,4753,2476,549), ncol=2)
 x
 [,1] [,2]
[1,]0  518
[2,]1 2245
[3,]2 4621
[4,]3 4753
[5,]4 2476
[6,]5  549
 chisq.test(x)

Pearson's Chi-squared test

data:  x
X-squared = 40.4672, df = 5, p-value = 1.202e-07

Warning message:
Chi-squared approximation may be incorrect in: chisq.test(x)

Does the warning mean that chisq.test(x) can't be used for this data.

If chisq.test(x) can't be used for this data, which test is to be used?

Pls advise.

thx

ej

__
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] specify point shape for ggplot (equivalent to pch)?

2006-12-02 Thread John Kane

--- Rainer M Krug [EMAIL PROTECTED] wrote:

 Hi
 
 is it possible to specify the shape of the point to
 be used in ggplot 
 (as with pch in plot)? I couldn't find anything in
 the help.
 
 Thanks
 
 Rainer

I was looking for that the other day while just poking
around with ggplot and did not see it but I a very new
to R and to ggplot. 

However have a look at the function map_shape.  It
looks to me like this decides what points are used but
this is just a guess.

__
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] specify point shape for ggplot (equivalent to pch)?

2006-12-02 Thread Gabor Grothendieck
See the last example in ?qplot

On 12/1/06, Rainer M Krug [EMAIL PROTECTED] wrote:
 Hi

 is it possible to specify the shape of the point to be used in ggplot
 (as with pch in plot)? I couldn't find anything in the help.

 Thanks

 Rainer

 --
 Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation
 Biology (UCT)

 Department of Conservation Ecology and Entomology
 University of Stellenbosch
 Matieland 7602
 South Africa

 Tel:+27 - (0)72 808 2975 (w)
 Fax:+27 - (0)86 516 2782
 Fax:+27 - (0)21 808 3304 (w)
 Cell:   +27 - (0)83 9479 042

 email:  [EMAIL PROTECTED]
[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] memory problem [cluster]

2006-12-02 Thread Dylan Beaudette
Hi Stephano,

Looks like you used my example verbatim 
(http://casoilresource.lawr.ucdavis.edu/drupal/node/221)

:)

While my approach has not *yet* been published, the original source [4] by 
Roger Bivand certainly has. Just a reminder.

That said, I would highly recommend reading up on the background literature 
assocated with both the cluster package [1] and terrain classificartion i.e.
[2] and [3]. Note that although the clara() function was created to work on 
massive datasets, it is still possible to overwhelm the available memory with 
multiple gridded objects- recall that all R objects are held in memory.

I have asked the maintainer of the cluster package, Martin Maechler, about 
integrating a known medoid option into the clara() function- which would be 
extremely useful in adding some 'supervision' to landscape classification 
with clara(). Hopefully there will be enough requests for the feature, that 
Martin will kindly add it :) .

1. Kaufman, L.  Rousseeuw, P.J. Finding Groups in Data An Introduction to 
Cluster Analysis Wiley-Interscience, 2005

2. Blaszczynski, J. Landform characterization with geographical information 
systems Photogrammetric Engineering and Remote Sensing, 1997, 63, 183-191

3. Wood, W.F.  Snell, J.B. A Quatitative system for classifying landforms 
U.S. Quatermaster Research  Engineering Center, 1960

4. Bivand, R. Integrating GRASS 5.0 and R: GIS and modern statistics Computers 
 Geosciences, 2000, 26, 1043–1052


On Friday 01 December 2006 14:04, Massimo Di Stefano wrote:
 hi to all,
 frustated for this error, to day i buy a 1 GB memory
 slot for my laptop
 now it have 1,28GB instead the old 512, but i've the
 same error :-(
 damn!damn!how can i do?
 repeat for a little area (about 20X20 km and res=20m)
 it work fine!
 have you any suggestion?
 is ther a method for look if this error depend from my
 ram or other?
 thanks foe any suggestion!
 i need your help.
 thanks.
 Massimo


 Il giorno 01/dic/06, alle ore 16:05, massimodisasha ha
 scritto:
 hi,
 i'm trying to perform a clustering on a big dataframe
 the code is this:


 print(load required R packages)

 require(spgrass6)

 require(cluster)

 gmeta6 - gmeta6()

 print(read in our 7 raster files from GRASS)

 x -
 readFLOAT6sp(c(er,crosc,longc,slope,profc,minic,maxic))

 print(assemble a matrix of our terrain variables)

 morph - data.frame(cbind(x$er, x$crosc, x$longc,
 x$slope, x$profc, x$minic, x$maxic))

 print(normailize slope by dividing my max(slope))

 morph - data.frame(cbind(x$er, x$crosc, x$longc,
 x$slope/max(x$slope), x$profc, x$minic, x$maxic))

 names(morph) -
 c(er,crosc,longc,slope_n,profc,minic,maxic)

 print(perform the clustering)

 morph.clara - clara(morph, k=5, stand=F)

 x$morph_class - morph.clara$clustering

 print(send result back to GRASS)

 rast.put6(x,morph, zcol=morph_class)



 during the step : perform the clustering
 after a lot of time,
 i've this error:




 Errore in sprintf(fmt, ...) : La lunghezza della
 stringa eccede la dimensione del buffer di 8192
 Inoltre: Warning messages:
 1: perl = TRUE è implementato solo nei locale UTF-8
 2: perl = TRUE è implementato solo nei locale UTF-8
 3: perl = TRUE è implementato solo nei locale UTF-8
 4: perl = TRUE è implementato solo nei locale UTF-8
 5: perl = TRUE è implementato solo nei locale UTF-8
 6: perl = TRUE è implementato solo nei locale UTF-8
 7: perl = TRUE è implementato solo nei locale UTF-8
 8: La stringa di caratteri verrà probabilmente
 troncata
 Esecuzione interrotta



 if i try the same code on a subregion of my data, it
 works very fine!
 but for a large region i've this error :-(

 obviously i think that is a memory problem, right ?
 (i'm working with a notebook PPC-1.33-512ram)
 my data are  : 7 raster-map on a region of about 50X40
 km at a resolution of 20m.
 is there some wolkaround about the memory problems?

 an other question is:
 what is this :
 Warning messages:
 1: perl = TRUE è implementato solo nei locale UTF-8
 2: perl = TRUE è implementato solo nei locale UTF-8
 3: perl = TRUE è implementato solo nei locale UTF-8
 4: perl = TRUE è implementato solo nei locale UTF-8
 5: perl = TRUE è implementato solo nei locale UTF-8
 6: perl = TRUE è implementato solo nei locale UTF-8
 7: perl = TRUE è implementato solo nei locale UTF-8

 is it about this line of the code :

 morph.clara - clara(morph, k=5, stand=F)
 i have an F  false


 thanks for any suggestion about,

 Massimo

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

-- 
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help

Re: [R] Chi-squared approximation may be incorrect in: chisq.tes

2006-12-02 Thread Ted Harding
On 02-Dec-06 Ethan Johnsons wrote:
 I am getting Chi-squared approximation may be incorrect in:
 chisq.test(x)  with the data bleow.
 
 Frequency distribution of number of male offspring in families of size
 5.
 Number of Male Offspring  N
 0   518
 1  2245
 2  4621
 3  4753
 4  2476
 5   549
 Total 15162
 
 
 x=matrix(c(0,1,2,3,4,5,518,2245,4621,4753,2476,549), ncol=2)
 x
  [,1] [,2]
 [1,]0  518
 [2,]1 2245
 [3,]2 4621
 [4,]3 4753
 [5,]4 2476
 [6,]5  549
 chisq.test(x)
 
 Pearson's Chi-squared test
 
 data:  x
 X-squared = 40.4672, df = 5, p-value = 1.202e-07
 
 Warning message:
 Chi-squared approximation may be incorrect in: chisq.test(x)
 
 Does the warning mean that chisq.test(x) can't be used for this data.
 
 If chisq.test(x) can't be used for this data, which test is to be used?

You are feeding a matrix with 6 rows and *2 columns* to chisq.test()

See ?chisq.test:

  If 'x' is a matrix with at least two rows and columns, it is taken
  as a two-dimensional contingency table, and hence its entries
  should be nonnegative integers.

In other words, the first column -- giving the numbers (0-5)
of male offspring -- is also being used as count data, so what
you're getting is a test of association between the two sets
of counts {0,1,2,3,4,5} and {518,2245,4621,4753,2476,549}!

So, if (which seems likely) you want to test the counts in
the second column against (say) a binomial distribution,
you could use the following code (assuming P[boy]=0.5)

  chisq.test(x[,2],p=dbinom(x[,1],5,0.5))
  ##Chi-squared test for given probabilities
  ##data:  x[, 2] 
  ##X-squared = 30.3181, df = 5, p-value = 1.277e-05

so it seems a binomial with P=0.5 won't do. Hence next try
the best estimate of P assuming binomial:

  P-sum((0:5)*x[,2])/(5*sum(x[,2]))
  P
  ##  [1] 0.5064635

So does this improve things?:

  chisq.test(x[,2],p=dbinom(x[,1],5,P))
  ##Chi-squared test for given probabilities
  ##data:  x[, 2] 
  ##X-squared = 17.744, df = 5, p-value = 0.003285

well, quite a bit -- but of course chisq.test() uses the wrong
degrees of freedom (should be 4, since we've estimated P this
time), so actually it's worse than that:

  ## 1-pchisq(17.744,4)
  ## [1] 0.001384664

though at 1.4e-3 it's still better than 1.3e-5!

Nevertheless, now that we've got the best-fitting binomial model,
the hypothesis that the numbers of male children in families of
size 5 is binomially distributed is clearly implausible.

Sufficient conditions for binomial distribution are
a) The genders of different births in the same family are
   independent of each other
b) The probability of boy is the same for all families.
Hence either (a) or (b) [or both] fails for these data.

I don't know of any way to force chisq.test() itself to take
account of degrees of freedom used up in estimation. chisq.test()
is a test for contingency tables (including a 1-row table tested
against a fixed given probability distribution).

Anyway, an indication of how the data fail to follow the best fitting
binomial distribution can be obtained by looking at

  X2T-chisq.test(x[,2],p=dbinom(x[,1],5,P))
  cbind((0:5),X2T$expected,X2T$observed)
  ##   [,1]  [,2] [,3]
  ##  [1,]0  443.9691  518
  ##  [2,]1 2277.9893 2245
  ##  [3,]2 4675.3120 4621
  ##  [4,]3 4797.7711 4753
  ##  [5,]4 2461.7188 2476
  ##  [6,]5  505.2396  549


showing (at least) that there seem to be excess counts in
the 0 and 5 classes. This can be further clarified with

  n.E-X2T$expected; n.O-X2T$observed; Dev-(n.O-n.E)/sqrt(n.E)
  cbind((0:5),X2T$expected,X2T$observed,Dev)
  ##   Dev
  ##  [1,] 0  443.9691  518  3.5134726
  ##  [2,] 1 2277.9893 2245 -0.6911901
  ##  [3,] 2 4675.3120 4621 -0.7943114
  ##  [4,] 3 4797.7711 4753 -0.6463652
  ##  [5,] 4 2461.7188 2476  0.2878353
  ##  [6,] 5  505.2396  549  1.9468512

  sum(Dev^2)
  ##  [1] 17.74403
[agreeing with the 17.744 from chisq.test()]

Hence there seems to be a clear excess of all-girl families,
and some excess of all-boy families, but nothing obviously
remarkable about the others (which does not of course exclude
that there is a dependency between the genders of successive
births in these too).

Quite how you proceed further depends on how you wish to model
this dependency. See VGAM package for betabin.ab(), which fits
a beta-binomial (binomial where the probability P varies from
case [family] to case according to a beta-distribution), for
instance.

Hoping this helps,
Ted.


E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 02-Dec-06   Time: 17:42:16

Re: [R] Trouble passing arrays to C code

2006-12-02 Thread Wee-Jin Goh
Thank you!!! That was the problem and now it's solved. Thanks for  
providing a fresh pair of eyes.

Regards,
Wee-Jin


On 2 Dec 2006, at 15:17, Antonio, Fabio Di Narzo wrote:



 here 'steps' is double, was integer in 'lorenz_run'.

 --
 Antonio, Fabio Di Narzo
 Ph.D. student at
 Department of Statistical Sciences
 University of Bologna, Italy

 __
 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] Quadratic Optimization

2006-12-02 Thread Spencer Graves
Hi, Prof. Ripley: 

snip


 But that is a single equality quadratic constraint, and I believe 
 'quadratic constraints' (note, plural) conventionally means multiple 
 inequality constraints.  That meaning is a hard problem that needs 
 specialized software (most likely using interior-point methods).

SpG   Maximize a'x subject to x'Ax=c.

 Not I believe the usual meaning (nor what Googling 'quadratic 
 constraints' came up with for me).

Thanks for the clarification.  Spencer Graves

__
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] package installation fails only for sp

2006-12-02 Thread Don McKenzie
Thanks to Brian Ripley and Roger Bivand for their quick replies to my  
question (original post
below).  Both politely pointed out that I had failed to check if I  
was running the latest version of
R (2.4).  I was attempting to download the current version of the  
sp package, which is not compatible with
v 2.3.




 On Fri, 1 Dec 2006, Don McKenzie wrote:

 I have escaped Splus for Windows (mostly) and have started using
 R (v 2.3.1 on i686 redhat).  Installing packages has been routine  
 except
 for sp (classes and methods for spatial data).  I get the  
 following error
 message
  install.packages(sp)
 Warning in download.packages(unique 
 (pkgs),destdir=tmpd,available=available,:
no package 'sp'  at the repositories
 Clearly I am missing something (probably obvious), but can someone
 enlighten me
 as to why the behavior of this package installation is different  
 from
 others?  sp is
 listed under Contributed packages at the R-project URL.  Thank you
 for your time.





Don McKenzie, Research Ecologist
Pacific WIldland Fire Sciences Lab
US Forest Service

Affiliate Assistant Professor
College of Forest Resources
CSES Climate Impacts Group
University of Washington

206.732.7824
[EMAIL PROTECTED]
[EMAIL PROTECTED]




[[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] nonlinear quantile regression

2006-12-02 Thread Ricardo Bessa
Hello, I’m with a problem in using nonlinear quantile regression, the 
function nlrq.
I want to do a quantile regression o nonlinear function in the form 
a*log(x)-b, the coefficients “a” and “b” is my objective. I try to use the 
command:

funx - function(x,a,b){
res - a*log(x)-b
res
}

Dat.nlrq - nlrq(y ~ funx(x, a, b), data=Dat, tau=0.25, trace=TRUE)

But a can’t solve de problem, How I put the formula “y ~ funx(x,a,b)”?

_
MSN Busca: fácil, rápido, direto ao ponto.  http://search.msn.com.br

__
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] nonlinear quantile regression

2006-12-02 Thread roger koenker
This isn't a nonlinear QR problem.  You can write:

f - rq(y ~ log(x),  data=Dat, tau=0.25)

which corresponds to the model

Q_y (.25|x)  =  a log(x) + b

note the sign convention on b.

url:www.econ.uiuc.edu/~rogerRoger Koenker
email   [EMAIL PROTECTED]   Department of Economics
vox:217-333-4558University of Illinois
fax:217-244-6678Champaign, IL 61820


On Dec 2, 2006, at 1:47 PM, Ricardo Bessa wrote:

 Hello, I’m with a problem in using nonlinear quantile regression, the
 function nlrq.
 I want to do a quantile regression o nonlinear function in the form
 a*log(x)-b, the coefficients “a” and “b” is my objective. I try to  
 use the
 command:

 funx - function(x,a,b){
 res - a*log(x)-b
 res
 }

 Dat.nlrq - nlrq(y ~ funx(x, a, b), data=Dat, tau=0.25, trace=TRUE)

 But a can’t solve de problem, How I put the formula “y ~ funx(x,a,b)”?

 _
 MSN Busca: fácil, rápido, direto ao ponto.  http://search.msn.com.br

 __
 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] Problem with CH.test in uroot package

2006-12-02 Thread hassen62
Dear friends, I installed the package “uroot” then I wrote library (uroot) 
and I entered a series entitled extp, in spite of that the problem persite. In 
short,here are what I wrote and the message that I obtained: 
 library(uroot)
 extp=c(1,3,10,14,12,5,8,12,13,15,9,8,7,10,9,7,3,10,3,11,12,7,4,9,8,10,20,17)
 CH.test (wts=extp, frec=c(1,1), f0=1, DetTr=FALSE, ltrunc=NULL)
Erreur dans seq.default(2, qq * 2, 2) : signe incorrect de l'argument 'by'

The last line wants to say that there is incorrect sign of the argument “by”
Which will be your suggestions, thank you.
[[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] memeory problem?!

2006-12-02 Thread massimodisasha
hi to all,
frustated for this error, to day i buy a 1 GB memory slot for my laptop
now it have 1,28GB instead the old 512, but i've the same error :-(
damn!damn!how can i do?
repeat for a little area (about 20X20 km and res=20m) it work fine!
have you any suggestion?
is ther a method for look if this error depend from my ram or other?
thanks foe any suggestion!
i need your help.
thanks.
Massimo


Il giorno 01/dic/06, alle ore 16:05, massimodisasha ha scritto:

 hi,
 i'm trying to perform a clustering on a big dataframe the code is  
 this:


 print(load required R packages)

 require(spgrass6)

 require(cluster)

 gmeta6 - gmeta6()

 print(read in our 7 raster files from GRASS)

 x - readFLOAT6sp(c 
 (er,crosc,longc,slope,profc,minic,maxic))

 print(assemble a matrix of our terrain variables)

 morph - data.frame(cbind(x$er, x$crosc, x$longc, x$slope, x$profc,  
 x$minic, x$maxic))

 print(normailize slope by dividing my max(slope))

 morph - data.frame(cbind(x$er, x$crosc, x$longc, x$slope/max(x 
 $slope), x$profc, x$minic, x$maxic))

 names(morph) - c 
 (er,crosc,longc,slope_n,profc,minic,maxic)

 print(perform the clustering)

 morph.clara - clara(morph, k=5, stand=F)

 x$morph_class - morph.clara$clustering

 print(send result back to GRASS)

 rast.put6(x,morph, zcol=morph_class)



 during the step : perform the clustering
 after a lot of time,
 i've this error:




 Errore in sprintf(fmt, ...) : La lunghezza della stringa eccede la  
 dimensione del buffer di 8192
 Inoltre: Warning messages:
 1: perl = TRUE è implementato solo nei locale UTF-8
 2: perl = TRUE è implementato solo nei locale UTF-8
 3: perl = TRUE è implementato solo nei locale UTF-8
 4: perl = TRUE è implementato solo nei locale UTF-8
 5: perl = TRUE è implementato solo nei locale UTF-8
 6: perl = TRUE è implementato solo nei locale UTF-8
 7: perl = TRUE è implementato solo nei locale UTF-8
 8: La stringa di caratteri verrà probabilmente troncata
 Esecuzione interrotta



 if i try the same code on a subregion of my data, it works very fine!
 but for a large region i've this error :-(

 obviously i think that is a memory problem, right ?
 (i'm working with a notebook PPC-1.33-512ram)
 my data are  : 7 raster-map on a region of about 50X40 km at a  
 resolution of 20m.
 is there some wolkaround about the memory problems?

 an other question is:
 what is this :
 Warning messages:
 1: perl = TRUE è implementato solo nei locale UTF-8
 2: perl = TRUE è implementato solo nei locale UTF-8
 3: perl = TRUE è implementato solo nei locale UTF-8
 4: perl = TRUE è implementato solo nei locale UTF-8
 5: perl = TRUE è implementato solo nei locale UTF-8
 6: perl = TRUE è implementato solo nei locale UTF-8
 7: perl = TRUE è implementato solo nei locale UTF-8

 is it about this line of the code :

 morph.clara - clara(morph, k=5, stand=F)
 i have an F  false


 thanks for any suggestion about,

 Massimo


[[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] Quadratic Optimization

2006-12-02 Thread amit soni
Thanks for the suggestions. I have started using R just a few days back. So i 
thought I might be missing something and its better to clarify. I was actually 
looking for a direct command(like fmincon in Matlab or NMinimize in 
Mathematica) which can solve non linear problems straightaway (quadratically 
constrained problem in my case).
I tried searching more but coudn't find any such direct command.

Thanks
Amit

- Original Message 
From: Spencer Graves [EMAIL PROTECTED]
To: Prof Brian Ripley [EMAIL PROTECTED]
Cc: r-help@stat.math.ethz.ch; Martin Maechler [EMAIL PROTECTED]
Sent: Saturday, December 2, 2006 1:19:06 PM
Subject: Re: [R] Quadratic Optimization

Hi, Prof. Ripley: 

snip


 But that is a single equality quadratic constraint, and I believe 
 'quadratic constraints' (note, plural) conventionally means multiple 
 inequality constraints.  That meaning is a hard problem that needs 
 specialized software (most likely using interior-point methods).

SpG   Maximize a'x subject to x'Ax=c.

 Not I believe the usual meaning (nor what Googling 'quadratic 
 constraints' came up with for me).

Thanks for the clarification.  Spencer Graves

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







 

Cheap talk?


[[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] memory problem [cluster]

2006-12-02 Thread Roger Bivand
On Sat, 2 Dec 2006, Dylan Beaudette wrote:

 Hi Stephano,

Looks like you used my example verbatim 
(http://casoilresource.lawr.ucdavis.edu/drupal/node/221)

:)

From exchanges on R-sig-geo, I believe the original questioner is feeding
NAs to clara, and the error message in clara() is overrunning the buffer
in sprintf(), so the memory problem isn't correctly identified. Using
scripts out of context without checking whether the input data frame 
satifies the conditions of the functions being used is asking for trouble. 
The error message:

  traceback()
2: stop(ngettext(length(i), sprintf(Observation %d has, i[1]),
sprintf(Observations %s have, paste(i, collapse = ,))),
 *only* NAs -- omit for clustering)
1: clara(morph, k = 5, stand = F)

is coming from lines:

i[1]), sprintf(Observations %s have, paste(i, 
collapse = ,))),  *only* NAs -- omit for clustering)

in clara(). I have suggested dropping those rows from the data frame in a 
reply on R-sig-geo, but maybe clara() could be patched to count the # of 
completely missing rows, and if # is more than a modest number, not print 
the obs. numbers, just the total?

Roger


While my approach has not *yet* been published, the original source [4] by 
Roger Bivand certainly has. Just a reminder.

That said, I would highly recommend reading up on the background literature 
assocated with both the cluster package [1] and terrain classificartion i.e.
[2] and [3]. Note that although the clara() function was created to work on 
massive datasets, it is still possible to overwhelm the available memory with 
multiple gridded objects- recall that all R objects are held in memory.

I have asked the maintainer of the cluster package, Martin Maechler, about 
integrating a known medoid option into the clara() function- which would be 
extremely useful in adding some 'supervision' to landscape classification 
with clara(). Hopefully there will be enough requests for the feature, that 
Martin will kindly add it :) .

1. Kaufman, L.  Rousseeuw, P.J. Finding Groups in Data An Introduction to 
Cluster Analysis Wiley-Interscience, 2005

2. Blaszczynski, J. Landform characterization with geographical information 
systems Photogrammetric Engineering and Remote Sensing, 1997, 63, 183-191

3. Wood, W.F.  Snell, J.B. A Quatitative system for classifying landforms 
U.S. Quatermaster Research  Engineering Center, 1960

4. Bivand, R. Integrating GRASS 5.0 and R: GIS and modern statistics Computers 
 Geosciences, 2000, 26, 1043–1052


On Friday 01 December 2006 14:04, Massimo Di Stefano wrote:
 hi to all,
 frustated for this error, to day i buy a 1 GB memory
 slot for my laptop
 now it have 1,28GB instead the old 512, but i've the
 same error :-(
 damn!damn!how can i do?
 repeat for a little area (about 20X20 km and res=20m)
 it work fine!
 have you any suggestion?
 is ther a method for look if this error depend from my
 ram or other?
 thanks foe any suggestion!
 i need your help.
 thanks.
 Massimo


 Il giorno 01/dic/06, alle ore 16:05, massimodisasha ha
 scritto:
 hi,
 i'm trying to perform a clustering on a big dataframe
 the code is this:


 print(load required R packages)

 require(spgrass6)

 require(cluster)

 gmeta6 - gmeta6()

 print(read in our 7 raster files from GRASS)

 x -
 readFLOAT6sp(c(er,crosc,longc,slope,profc,minic,maxic))

 print(assemble a matrix of our terrain variables)

 morph - data.frame(cbind(x$er, x$crosc, x$longc,
 x$slope, x$profc, x$minic, x$maxic))

 print(normailize slope by dividing my max(slope))

 morph - data.frame(cbind(x$er, x$crosc, x$longc,
 x$slope/max(x$slope), x$profc, x$minic, x$maxic))

 names(morph) -
 c(er,crosc,longc,slope_n,profc,minic,maxic)

 print(perform the clustering)

 morph.clara - clara(morph, k=5, stand=F)

 x$morph_class - morph.clara$clustering

 print(send result back to GRASS)

 rast.put6(x,morph, zcol=morph_class)



 during the step : perform the clustering
 after a lot of time,
 i've this error:




 Errore in sprintf(fmt, ...) : La lunghezza della
 stringa eccede la dimensione del buffer di 8192
 Inoltre: Warning messages:
 1: perl = TRUE è implementato solo nei locale UTF-8
 2: perl = TRUE è implementato solo nei locale UTF-8
 3: perl = TRUE è implementato solo nei locale UTF-8
 4: perl = TRUE è implementato solo nei locale UTF-8
 5: perl = TRUE è implementato solo nei locale UTF-8
 6: perl = TRUE è implementato solo nei locale UTF-8
 7: perl = TRUE è implementato solo nei locale UTF-8
 8: La stringa di caratteri verrà probabilmente
 troncata
 Esecuzione interrotta



 if i try the same code on a subregion of my data, it
 works very fine!
 but for a large region i've this error :-(

 obviously i think that is a memory problem, right ?
 (i'm working with a notebook PPC-1.33-512ram)
 my data are  : 7 raster-map on a region of about 50X40
 km at a resolution of 20m.
 is there some wolkaround about the memory problems?

 an other question 

[R] Force square crosstabulation

2006-12-02 Thread Manuel Morales
Hello list members,

I'm looking for a way to force the results of a crosstabulation to be
square - that is, to include 0 values.

For example:

table(letters[1:4],letters[c(1:3,3)])

yields:
a b c
  a 1 0 0
  b 0 1 0
  c 0 0 1
  d 0 0 1

I would like to return:
a b c d
  a 1 0 0 0
  b 0 1 0 0
  c 0 0 1 0
  d 0 0 1 0

Any suggestions?

Thanks!
-- 
Manuel A. Morales
http://mutualism.williams.edu


signature.asc
Description: This is a digitally signed message part
__
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] Force square crosstabulation

2006-12-02 Thread Duncan Murdoch
On 12/2/2006 8:26 PM, Manuel Morales wrote:
 Hello list members,
 
 I'm looking for a way to force the results of a crosstabulation to be
 square - that is, to include 0 values.
 
 For example:
 
 table(letters[1:4],letters[c(1:3,3)])
 
 yields:
 a b c
   a 1 0 0
   b 0 1 0
   c 0 0 1
   d 0 0 1
 
 I would like to return:
 a b c d
   a 1 0 0 0
   b 0 1 0 0
   c 0 0 1 0
   d 0 0 1 0
 
 Any suggestions?

Force the categories to be factors.

  fletters - factor(letters[1:4])
  table(fletters[1:4],fletters[c(1:3,3)])

 a b c d
   a 1 0 0 0
   b 0 1 0 0
   c 0 0 1 0
   d 0 0 1 0

The idea is that when you take subsets of factors, the levels stay the 
same, and table uses those levels for its categories.

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] Force square crosstabulation

2006-12-02 Thread Bill.Venables
Use factors with specified levels.

 lev - letters[1:4]
 table(factor(letters[1:4], levels = lev),
   factor(letters[c(1:3,3)], levels = lev)) 
   
a b c d
  a 1 0 0 0
  b 0 1 0 0
  c 0 0 1 0
  d 0 0 1 0

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Manuel Morales
Sent: Sunday, 3 December 2006 11:27 AM
To: r-help@stat.math.ethz.ch
Subject: [R] Force square crosstabulation

Hello list members,

I'm looking for a way to force the results of a crosstabulation to be
square - that is, to include 0 values.

For example:

table(letters[1:4],letters[c(1:3,3)])

yields:
a b c
  a 1 0 0
  b 0 1 0
  c 0 0 1
  d 0 0 1

I would like to return:
a b c d
  a 1 0 0 0
  b 0 1 0 0
  c 0 0 1 0
  d 0 0 1 0

Any suggestions?

Thanks!
-- 
Manuel A. Morales
http://mutualism.williams.edu

__
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] prop.trend.test issue

2006-12-02 Thread Ethan Johnsons
I have the clinical study data.

   Year 0   Year 3
Retinol (nmol/L)N   Mean +-sd   Mean +-sd
Vitamin A group 73  1.89+-0.36  2.06+-0.53
Trace group57  1.83+-0.31 1.78+-0.30

where N is the number of male for the clinical study.

I want to test if the mean serum retinol has increased over 3 years
among subjects in the vitamin A group.

  1.89+0.36
[1] 2.25
 1.89-0.36
[1] 1.53
 2.06+0.53
[1] 2.59
 2.06-0.53
[1] 1.53


 prop.trend.test(c(2.25, 1.53),c( 2.59, 1.53))

Chi-squared Test for Trend in Proportions

data:  c(2.25, 1.53) out of c(2.59, 1.53) ,
 using scores: 1 2
X-squared = 0.2189, df = 1, p-value = 0.6399

The issue I am seeing that N of Vitamin A group = 73 seems not reflected.
This leads me to think that I can't implement the test based on the
data just presented.
Nor a two-tailed test is possible.

2-sample test for equality of proportions with continuity correction

data:  c(2.25, 1.53) out of c(2.59, 1.53)
X-squared = 0, df = 1, p-value = 1
alternative hypothesis: two.sided
95 percent confidence interval:
 -0.6738203  0.4112720
sample estimates:
   prop 1prop 2
0.8687259 1.000

Warning message:
Chi-squared approximation may be incorrect in: prop.test(c(2.25,
1.53), c(2.59, 1.53))

Any ideas, please?

thx

ej

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