[R] Gamma

2009-05-16 Thread Kon Knafelman

Hey,

I am having trouble graphing the following function

√2Γ(n/2)/[√n − 1Γ((n − 1)/2 for the values of n between 2 and 50.

i know that Γ(n) = (n-1)!, which in R is factorial(n-1)

When i type that into R, using y - function(n).
and
then plot(y,2,50), it doesnt give me anything meaningful, in fact, it
comes up with a message saying something like in gamma(n+1) ploted or
something along those lines.

Can anyone please help?

thank you

_
Looking to move somewhere new this winter? Let ninemsn property help
http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fninemsn%2Edomain%2Ecom%2Eau%2F%3Fs%5Fcid%3DFDMedia%3ANineMSN%5FHotmail%5FTagline_t=774152450_r=Domain_tagline_m=EXT
[[alternative HTML version deleted]]

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


[R] How to turn the xyplot graphics upside-down?

2009-05-16 Thread lau kue
Hi everyone,

I'm learning to use R. The below script works well, but i want to turn the
y-axis and the graphics upside-down, how should i do? Appreciate if any
tips!


 library(lattice)


xyplot(P3+PZ+P4+C3+CZ+C4+F3+FZ+F4~Time,groups=Cond,data=data,type=l,auto.key=list(space=top,points=FALSE,lines=TRUE),layout=c(3,3))

Liam

[[alternative HTML version deleted]]

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


[R] Gamma function

2009-05-16 Thread Kon Knafelman

Hi Guy,

I am having trouble graphing the following function

√2Γ(n/2)/[√n − 1Γ((n − 1)/2 for the values of n between 2 and 50.

i know that Γ(n) = (n-1)!, which in R is factorial(n-1)

When i type that into R, using y - function(n).
and then plot(y,2,50), it doesnt give me anything meaningful, in fact, it comes 
up with a message saying something like in gamma(n+1) ploted or something 
along those lines.

Can anyone please help?

thanks you

_
Looking to change your car this year? Find car news, reviews and more
http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fsecure%2Dau%2Eimrworldwide%2Ecom%2Fcgi%2Dbin%2Fa%2Fci%5F450304%2Fet%5F2%2Fcg%5F801459%2Fpi%5F1004813%2Fai%5F859641_t=762955845_r=tig_OCT07_m=EXT
[[alternative HTML version deleted]]

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


[R] Fwd: Cannot allocate a new database connection error

2009-05-16 Thread Moumita Das
-- Forwarded message --
From: Moumita Das das.moumita.onl...@gmail.com
Date: Sat, May 16, 2009 at 2:26 PM
Subject: Cannot allocate a new database connection error
To: r-help-requ...@r-project.org


Hi friends,
why do i keep getting this error?The program runs, twice and every third
time i get this error.I have to quit.Again get teh R-prompt and then run the
script.

*Error in mysqlNewConnection(drv, ...) :
  RS-DBI driver: (�...@`qe@°
°
cannot allocate a new connection -- maximum of 16 connections already
opened)
Error in is(object, Cl) :
  error in evaluating the argument 'conn' in selecting a method for function
'dbSendQuery'
Error in is(object, Cl) :
  error in evaluating the argument 'res' in selecting a method for function
'fetch'*


*this is my DB connection function*
*myDbConnect - function (dbName, hostName) {
  drv-MySQL()
  con - dbConnect(drv, user=xyz, password=xyz,dbname = dbName, host
= hostName)
return(con)
}*


everytime i need ,Db connection , i used in this way:



This is the structure of my code:--
main - function ()
 {
  #Looping through subgroups
   for(sub_group_num_loopcounter in 1:sub_group_num_data_size[1])
   {
 #Fetching the where clause for the particular subgroup
*sub_group_where_condition -
fetch(dbSendQuery(myDbConnect(dbName,hostName), paste(c(SELECT where_clause
FROM sub_grp where

num=,sub_group_num_data[sub_group_num_loopcounter,1]),collapse=)), n =
-1)  *
}
dbDisconnect(con)
dbListConnections(MySQL())
l-list()

}

Where should i close the DB connection  or use one single connection
throughout the prograam.

-- 
Thanks
Moumita



-- 
Thanks
Moumita

[[alternative HTML version deleted]]

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


Re: [R] Gamma

2009-05-16 Thread Johannes Huesing
Kon Knafelman konk2...@hotmail.com [Sat, May 16, 2009 at 08:49:44AM CEST]:
 
 Hey,
 
 I am having trouble graphing the following function
 
 ???2??(n/2)/[???n ??? 1??((n ??? 1)/2 for the values of n between 2 and 50.
 
 i know that ??(n) = (n-1)!, which in R is factorial(n-1)
 
 When i type that into R, using y - function(n).
 and
 then plot(y,2,50), it doesnt give me anything meaningful, in fact, it
 comes up with a message saying something like in gamma(n+1) ploted or
 something along those lines.

Please send us the actual code, and the actual lines, not something along them.

For me, both

plot(gamma, 1, 4)

and

plot(factorial, 0, 3)

give meaningful results without warnings or errors.

I am using the following:

 R.Version()
$platform
[1] i486-pc-linux-gnu

$arch
[1] i486

$os
[1] linux-gnu

$system
[1] i486, linux-gnu

$status
[1] 

$major
[1] 2

$minor
[1] 7.2

$year
[1] 2008

$month
[1] 08

$day
[1] 25

$`svn rev`
[1] 46428

$language
[1] R

$version.string
[1] R version 2.7.2 (2008-08-25)



-- 
Johannes Hüsing   There is something fascinating about science. 
  One gets such wholesale returns of conjecture 
mailto:johan...@huesing.name  from such a trifling investment of fact.  
  
http://derwisch.wikidot.com (Mark Twain, Life on the Mississippi)

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

2009-05-16 Thread Maria I. Tchalakova
Hi,

I am trying to install R on Ubuntu 8.10. I have added this line:

deb http://cran.at.r-project.org/bin/linux/ubuntu intrepid/

in my /etc/apt/sources.list file. However when I Reload, I get the
following error message:
W: GPG error: http://cran.at.r-project.org intrepid/ Release: The
following signatures couldn't be verified because the public key is
not available: NO_PUBKEY D67FC6EAE2A11821

I have tried different mirror sites, but the result is the same. There
is nothing written about public keys on the download page:
http://cran.at.r-project.org/

Then, I have tried (after I added the line to the
/etc/apt/sources/list file) not pressing Reload, but Close, and I
have written in the console:
sudo apt-get update

but I received similar message again:

Reading package lists... Done
W: GPG error: http://cran.rakanu.com intrepid/ Release: The following
signatures couldn't be verified because the public key is not
available: NO_PUBKEY D67FC6EAE2A11821
W: You may want to run apt-get update to correct these problems

Do you know what the problem is, and what should I do? Thanks in advance.

Maria

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

2009-05-16 Thread Nordlund, Dan (DSHS/RDA)
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
 Behalf Of Maria I. Tchalakova
 Sent: Saturday, May 16, 2009 2:37 AM
 To: R-help Forum
 Subject: [R] Installing R on Ubuntu 8.10
 
 Hi,
 
 I am trying to install R on Ubuntu 8.10. I have added this line:
 
 deb http://cran.at.r-project.org/bin/linux/ubuntu intrepid/
 
 in my /etc/apt/sources.list file. However when I Reload, I get the
 following error message:
 W: GPG error: http://cran.at.r-project.org intrepid/ Release: The
 following signatures couldn't be verified because the public key is
 not available: NO_PUBKEY D67FC6EAE2A11821
 
 I have tried different mirror sites, but the result is the same. There
 is nothing written about public keys on the download page:
 http://cran.at.r-project.org/
 
 Then, I have tried (after I added the line to the
 /etc/apt/sources/list file) not pressing Reload, but Close, and I
 have written in the console:
 sudo apt-get update
 
 but I received similar message again:
 
 Reading package lists... Done
 W: GPG error: http://cran.rakanu.com intrepid/ Release: The following
 signatures couldn't be verified because the public key is not
 available: NO_PUBKEY D67FC6EAE2A11821
 W: You may want to run apt-get update to correct these problems
 
 Do you know what the problem is, and what should I do? Thanks in advance.
 
 Maria
 

Maria,

Go to the CRAN website (or your preferred mirror), select Linux under the 
download and install section, then select Ubuntu, and read what it says about 
installation.

http://cran.r-project.org/

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA  98504-5204

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

2009-05-16 Thread Jim Lemon

christophe dutang wrote:

Hi,

I would like to draw arrows in a classic 2D plot. Which package should I
use? is there R base functions that do job?

On google, I could not find any useful discussion about this topic, except a
link to the function 'grid.arrows' of the grid package.

My problem is I would like to draw arrows at the edge of circles drawn by
the 'symbols' function. Maybe there is already a dedicated function for
this?

Any help is appreciated.

Christophe



  

Hi Christophe,
If you are trying to do what I think you are trying to do, consider 
drawing the arrow first, with the starting point at the center of the 
circle, then draw the circle with a fill color the same as the 
background. This should give you a circle with a nice radial arrow 
emerging from the edge.


Jim

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


Re: [R] Installing R on Ubuntu 8.10

2009-05-16 Thread Maria I. Tchalakova
Hi Dan,

thanks for the reply. Yes, I have read everything there, but it didn't
help. I've written to the Ubuntu forums as well, from where I was told
to type first:

 gpg --keyserver keyserver.ubuntu.com --recv D67FC6EAE2A11821
 gpg --export --armor D67FC6EAE2A11821 | sudo apt-key add -

before
 sudo apt-get update
 sudo apt-get install r-base

and it worked.

Best,
Maria



On Sat, May 16, 2009 at 11:52 AM, Nordlund, Dan (DSHS/RDA)
nord...@dshs.wa.gov wrote:
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
 Behalf Of Maria I. Tchalakova
 Sent: Saturday, May 16, 2009 2:37 AM
 To: R-help Forum
 Subject: [R] Installing R on Ubuntu 8.10

 Hi,

 I am trying to install R on Ubuntu 8.10. I have added this line:

 deb http://cran.at.r-project.org/bin/linux/ubuntu intrepid/

 in my /etc/apt/sources.list file. However when I Reload, I get the
 following error message:
 W: GPG error: http://cran.at.r-project.org intrepid/ Release: The
 following signatures couldn't be verified because the public key is
 not available: NO_PUBKEY D67FC6EAE2A11821

 I have tried different mirror sites, but the result is the same. There
 is nothing written about public keys on the download page:
 http://cran.at.r-project.org/

 Then, I have tried (after I added the line to the
 /etc/apt/sources/list file) not pressing Reload, but Close, and I
 have written in the console:
 sudo apt-get update

 but I received similar message again:
 
 Reading package lists... Done
 W: GPG error: http://cran.rakanu.com intrepid/ Release: The following
 signatures couldn't be verified because the public key is not
 available: NO_PUBKEY D67FC6EAE2A11821
 W: You may want to run apt-get update to correct these problems

 Do you know what the problem is, and what should I do? Thanks in advance.

 Maria


 Maria,

 Go to the CRAN website (or your preferred mirror), select Linux under the 
 download and install section, then select Ubuntu, and read what it says about 
 installation.

 http://cran.r-project.org/

 Hope this is helpful,

 Dan

 Daniel J. Nordlund
 Washington State Department of Social and Health Services
 Planning, Performance, and Accountability
 Research and Data Analysis Division
 Olympia, WA  98504-5204




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


[R] newbie: closing unused connection + readline

2009-05-16 Thread Aval Sarri
Hello;
I am new to R and trying to read a line from socket connection at a
time but at the end of script I am getting closing unused connection
warning. I am not able to understand how to solve this. I want to read
a line from socket and then use read.table/scan on that line but it
looks like I am opening multiple connections instead of just one.  I
think I am doing something wrong or not able to understand correct
method of doing this.

---code
# Create a socket from which to read lines - one at a time (record)
reader.socket -   socketConnection( host = 'localhost', 5000,
 server = TRUE, blocking = TRUE,
 open = r, encoding =
getOption(encoding) );
# now read each record and split/validate it using read.table
repeat {
  # here for each line I am opening new connection! how to avoid it?
  line.raw - textConnection(readLines( reader.socket, n = 1, ok = TRUE));
  line.raw - read.table(line.raw, sep=,);

  if ( length(line.raw)   1)
break;

  print (showConnections());
  print(warnings());
}

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

2009-05-16 Thread Gabor Grothendieck
Try explicitly closing it:

close(reader.socket)

or

closeAllConnections()

On Sat, May 16, 2009 at 8:34 AM, Aval Sarri aval.sa...@gmail.com wrote:
 Hello;
 I am new to R and trying to read a line from socket connection at a
 time but at the end of script I am getting closing unused connection
 warning. I am not able to understand how to solve this. I want to read
 a line from socket and then use read.table/scan on that line but it
 looks like I am opening multiple connections instead of just one.  I
 think I am doing something wrong or not able to understand correct
 method of doing this.

 ---code
 # Create a socket from which to read lines - one at a time (record)
 reader.socket -   socketConnection( host = 'localhost', 5000,
                                     server = TRUE, blocking = TRUE,
                                     open = r, encoding =
 getOption(encoding) );
 # now read each record and split/validate it using read.table
 repeat {
  # here for each line I am opening new connection! how to avoid it?
  line.raw - textConnection(readLines( reader.socket, n = 1, ok = TRUE));
  line.raw - read.table(line.raw, sep=,);

  if ( length(line.raw)   1)
    break;

  print (showConnections());
  print(warnings());
 }

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


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


[R] barplot in a loop not printing out to directory

2009-05-16 Thread Dimitri Liakhovitski
Hello!
I am experiencing a problem with section 3 of the code below. I want
to generate barplots (based on data generated in Sections 1 and 2) in
a loop - for each variable in data - and save them as .emf files in
my current directory. But it's not working - it's printing values to
be plotted to the screen but does not print the plots themselves
anywhere (and not in the directory).
Thank you very much for your help!
Dimitri

### Section 1. This section generates my data set data - no problems there:

N-100
myset1-c(1,2,3,4,5)
probs1-c(.05,.10,.15,.40,.30)
myset2-c(0,1)
probs2-c(.65,.30)
myset3-c(1,2,3,4,5,6,7)
probs3-c(.02,.03,.10,.15,.20,.30,.20)

group-as.factor(sapply(1:4,function(x){
out-rep(x,25)
out
}))
set.seed(1)
a-sample(myset1, N, replace = TRUE,probs1)
a[which(rbinom(100,2,.01)==1)]-NA
set.seed(12)
b-sample(myset1, N, replace = TRUE,probs1)
b[which(rbinom(100,2,.01)==1)]-NA
set.seed(123)
c-sample(myset2, N, replace = TRUE,probs2)
set.seed(1234)
d-sample(myset2, N, replace = TRUE,probs2)
set.seed(12345)
e-sample(myset3, N, replace = TRUE,probs3)
e[which(rbinom(100,2,.01)==1)]-NA
set.seed(123456)
f-sample(myset3, N, replace = TRUE,probs3)
f[which(rbinom(100,2,.01)==1)]-NA
data-data.frame(group,a=a,b=b,c=c,d=d,e=e,f=f)

### Section 2. Generating tables with percentages for barplot:
tables-lapply(data,function(x){
out-table(x)
out-prop.table(out)
out-round(out,3)*100
out.df-data.frame(matrix(nrow=length(out),ncol=2))
names(out.df)-c(Value,Percentages)
out.df[1]-dimnames(out)[1]
out.df[2]-out
return(out.df)
})
(tables)

### Section 3. I want to generate a barplot based on each and every
table I produced above and put it in my current directory. But it's
not working.

for(i in 1:length(tables)) {
chart.name-names(data)[i]
filename=paste(i,chart.name,emf,sep=.)
win.metafile(file=filename)
chart-barplot(tables[[i]][[2]],xlab = Values, ylab =
Percentages,ylim=c(0,100))
print(chart)
dev.off()
}

Thank you very much!
-- 
Dimitri Liakhovitski
MarketTools, Inc.
dimitri.liakhovit...@markettools.com

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


Re: [R] fitdistr for t distribution

2009-05-16 Thread Martin Maechler
 l == lagreene  lagreene...@gmail.com
 on Fri, 15 May 2009 04:22:59 -0700 (PDT) writes:

l Thanks Jorge,

l but I still don't understand where they come from.  when I use: 
l fitdistr(mydata, t, df = 9) and get values for m and s, and the 
variance
l of my data should be the df/s?

definitely *not*;  How did you get to this completely wrong formula?
 
l I jsut want to be able to confirm how m and s are calculated
 
by maximum likelihood.
And, of course, only for the normal (aka Gaussian) are the ML
estimates of mu the artithmetic mean and of sigma  (n-1)/n * sd(x)
{i.e. even *there* the ML estimate of s is *not* the SD}

As you can read on  ?dt,
the variance of a (0,1)-t-distribution is  df / (df - 2)
and hence only defined for df  2.
Consequently, the variance of a  (mu,sigma)-t-distribution is

   sigma^2 * df / (df - 2)

l mydt - function(x, m, s, df) dt((x-m)/s, df)/s
l fitdistr(x2, mydt, list(m = 0, s = 1), df = 9, lower = c(-Inf, 0))

{this is copy-pasted from example(dt);
 the examples have nice comments there}


l Jorge Ivan Velez wrote:
 
 Dear lagreene,
 See the second example in
 
 require(MASS)
 ?fitdistr
 
 HTH,
 
 Jorge
 
 
 On Thu, May 14, 2009 at 7:15 PM, lagreene lagreene...@gmail.com wrote:
 
 
 Hi,
 I was wondering if anyone could tell me how m and s are calculated for a
 t
 distribution?
 
 I thought m was the sample mean and s the standard deviation- but
 obviously
 I'm wrong as this doesn'y give the same answer.
 
 Thank you

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


Re: [R] ggplot2: annotating plot with mathematical formulae

2009-05-16 Thread Paul Emberson
Hi Stephen,

The problem is that the label on the graph doesn't get rendered with a
superscript.  I want the label on the graph to be rendered the same way
as the label you have put on the axis.

I am plotting a piecewise function and I wanted to label each section of it.

Paul

stephen sefick wrote:
 how about this

 a - 1:10
 b - 1:10
 d - paste(x,^,{n-1})
 qplot(a,b, xlab=expression(x^{n-1}))+geom_text(aes(4,8, label=d))

 On Fri, May 15, 2009 at 10:02 PM, Paul Emberson em...@calidasoft.co.uk 
 wrote:
   
 Hi,

 Is there a way of annotating a ggplot plot with mathematical formulae?

 I can do

 geom_text(aes(label=some text, ...

 but I can't do

 geom_text(aes(label=expression(x^{n-1}), ...

 It gives the error

 Error: geom_text requires the following missing aesthetics: label

 Is there a convenient equivalent?

 Cheers,

 Paul

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

 





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


Re: [R] barplot in a loop not printing out to directory

2009-05-16 Thread Jim Lemon

Dimitri Liakhovitski wrote:

Hello!
I am experiencing a problem with section 3 of the code below. I want
to generate barplots (based on data generated in Sections 1 and 2) in
a loop - for each variable in data - and save them as .emf files in
my current directory. But it's not working - it's printing values to
be plotted to the screen but does not print the plots themselves
anywhere (and not in the directory).
Thank you very much for your help!
Dimitri
...

I would insert a line just after filename=...
cat(filename,\n)
and see what the filenames are.

Jim

### Section 3. I want to generate a barplot based on each and every
table I produced above and put it in my current directory. But it's
not working.

for(i in 1:length(tables)) {
chart.name-names(data)[i]
filename=paste(i,chart.name,emf,sep=.)
win.metafile(file=filename)
chart-barplot(tables[[i]][[2]],xlab = Values, ylab =
Percentages,ylim=c(0,100))
print(chart)
dev.off()
}

Thank you very much!



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

2009-05-16 Thread Aval Sarri
On Sat, May 16, 2009 at 6:12 PM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 Try explicitly closing it:

 close(reader.socket)

 or

 closeAllConnections()

Thank you Sir but is there a way that it does not get open each time?
I mean following line creates a new text connection each time so how
to avoid it or reuse an open connection?

line.raw - textConnection(readLines( reader.socket, n = 1, ok = TRUE));

I tried something line this also:

mydataframe - read.table (socket, sep=,);

but does not work says no input lines.

this also.

mydataframe - read.table (readLine(socket), sep=,);

what is the best method of doing something like this? I am getting
totally lost between textConnection, socket and getConnection.  Now I
am trying to get the connection that was opened and reuse it but then
how do I get connection that was previously opened when running code -
since getConnection() requires a number and for that I need to know
the number of my previously opened connection. So how do I get the
number of textConnection that I open?

Sir any pointers would greatly help.

Thanks and regards
-Aval



 On Sat, May 16, 2009 at 8:34 AM, Aval Sarri aval.sa...@gmail.com wrote:
 Hello;
 I am new to R and trying to read a line from socket connection at a
 time but at the end of script I am getting closing unused connection
 warning. I am not able to understand how to solve this. I want to read
 a line from socket and then use read.table/scan on that line but it
 looks like I am opening multiple connections instead of just one.  I
 think I am doing something wrong or not able to understand correct
 method of doing this.

 ---code
 # Create a socket from which to read lines - one at a time (record)
 reader.socket -   socketConnection( host = 'localhost', 5000,
                                     server = TRUE, blocking = TRUE,
                                     open = r, encoding =
 getOption(encoding) );
 # now read each record and split/validate it using read.table
 repeat {
  # here for each line I am opening new connection! how to avoid it?
  line.raw - textConnection(readLines( reader.socket, n = 1, ok = TRUE));
  line.raw - read.table(line.raw, sep=,);

  if ( length(line.raw)   1)
    break;

  print (showConnections());
  print(warnings());
 }

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



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


Re: [R] anova(cph(..) output

2009-05-16 Thread Frank E Harrell Jr

pompon wrote:

Hello,

I am a beginner in R and statistics, so my question may be trivial. Sorry in
advance.
I performed a Cox proportion hazard regression with 2 categorical variables
with cph{design}. Then an anova on the results.
the output is 


anova(cph(surv(survival, censor) ~ plant + leaf.age + plant*leaf.age,
Mpnymph)


Wald Statistics  Response: Surv(survival, censored) 

 FactorChi-Square d.f. P 
 plant  (Factor+Higher Order Factors) 96.96 12   .0001
  All Interactions   10.58 
6   0.1022

 leaf.age  (Factor+Higher Order Factors)  29.11  7   0.0001
  All Interactions 10.58 
6   0.1022

 plant * leaf.age  (Factor+Higher Order Factors)  10.58  6   0.1022
 TOTAL   106.63 13   .0001

What do All interaction stand for?
The real df of for plant is 6 and 1 for leaf.age. Then, which chi square is
one for my main factors anf their interaction.

thank you,
Julien.


Julien,

I know what you mean when you say 'real df' but that's not the whole 
story as plant has 6 more df by interacting with a single df variable. 
There is no such thing as 'the' main effect test for plant.  The 12 df 
test is unique and tests whether plant is associated with Y for any 
level of leaf.age.


You can see exactly what is being tested by using various print options 
for anova.Design, as described in the help file.  The dots option is 
easy on the eyes.


Frank
--
Frank E Harrell Jr   Professor and Chair   School of Medicine
 Department of Biostatistics   Vanderbilt University

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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: Cannot allocate a new database connection error

2009-05-16 Thread Uwe Ligges

Open a connection as in

con - myDbConnect(dbName,hostName)

before the loop starts and afterwards just work on con.

Uwe Ligges






Moumita Das wrote:

-- Forwarded message --
From: Moumita Das das.moumita.onl...@gmail.com
Date: Sat, May 16, 2009 at 2:26 PM
Subject: Cannot allocate a new database connection error
To: r-help-requ...@r-project.org


Hi friends,
why do i keep getting this error?The program runs, twice and every third
time i get this error.I have to quit.Again get teh R-prompt and then run the
script.

*Error in mysqlNewConnection(drv, ...) :
  RS-DBI driver: (�...@`qe@°
°
cannot allocate a new connection -- maximum of 16 connections already
opened)
Error in is(object, Cl) :
  error in evaluating the argument 'conn' in selecting a method for function
'dbSendQuery'
Error in is(object, Cl) :
  error in evaluating the argument 'res' in selecting a method for function
'fetch'*


*this is my DB connection function*
*myDbConnect - function (dbName, hostName) {
  drv-MySQL()
  con - dbConnect(drv, user=xyz, password=xyz,dbname = dbName, host
= hostName)
return(con)
}*


everytime i need ,Db connection , i used in this way:



This is the structure of my code:--
main - function ()
 {
  #Looping through subgroups
   for(sub_group_num_loopcounter in 1:sub_group_num_data_size[1])
   {
 #Fetching the where clause for the particular subgroup
*sub_group_where_condition -
fetch(dbSendQuery(myDbConnect(dbName,hostName), paste(c(SELECT where_clause
FROM sub_grp where

num=,sub_group_num_data[sub_group_num_loopcounter,1]),collapse=)), n =
-1)  *
}
dbDisconnect(con)
dbListConnections(MySQL())
l-list()

}

Where should i close the DB connection  or use one single connection
throughout the prograam.





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


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


Re: [R] Matrix package,solve() errors and crashes Please help

2009-05-16 Thread Martin Maechler
 SS == Surendar Swaminathan surendar.swaminat...@gmail.com
 on Fri, 15 May 2009 15:55:23 -0700 writes:

 Hello All,
 
SS Please help me with this problem.I have been having this problem for 
over a
SS month now and I could not find any information.I later realised that 
error
SS is with MATRIX package.

[...]


SS This is my graph object.
SS The file 'Bonacich Power.RData' (1.5 MB) is available for download at
SS 
SS 
http://dropbox.unl.edu/uploads/20090522/7a0d0313f21fd6a8/Bonacich%20Power.RData

[...]

and you have asked almost the idetnical question 4 weeks ago,
and got a first answer, but then not a *real* answer.
I'm sorry for that, since I had started answering you, 
and even more as I *did* solve the problem back then.. (April 22).

more below ...

SS computer Configuration

SS *WIndows XP service Pack 3 .0 GB RAM*

SS I am using SPARSE matrix to solve the problem
SS This is the code I use to obtain bonpower using Sparse Matrix 
SS alternatively the code is in the following website

SS http://igraph.wikidot.com/r-recipes#toc6

I'm really appaled that R-recipes on such a website give 
such an unprofessional advice


{the following is so grabled because of your (implicit)
 insistence on using HTML-ified e-mail .. }

SS *bonpow.sparse - function(graph, nodes=V(graph), loops=FALSE,
SS exponent=1, rescale=TRUE, tol=1e-07) {*
SS *  ## remove loops if requested
SS *
SS *  ## sparse adjacency matrix
SS d - get.adjacency(graph, sparse=TRUE)*
SS *  ## sparse identity matrix
SS id - spMatrix(vcount(graph), vcount(graph),
SS i=1:vcount(graph), j=1:vcount(graph),
SS x=rep(1, vcount(graph)))
SS id - as(id, dgCMatrix)*
SS *  ## solve it
  SS ev - solve(id - exponent * d, tol=tol) %*% degree(graph, mode=all)*
SS *  if (rescale) {
SS ev - ev/sum(ev)
SS } else {
SS ev - ev * sqrt(vcount(graph)/sum((ev)^2))
SS }*
SS *  ev[as.numeric(nodes) + 1]
SS }*
SS **
SS I realised that the error is in Matrix Package
SS *Error: cannot allocate vector of size 3.3 Gb
SS In addition: Warning messages:
SS 1: In solve(id - exponent * d, tol = tol) :
SS Reached total allocation of 1535Mb: see help(memory.size)
SS 2: In solve(id - exponent * d, tol = tol) :
SS Reached total allocation of 1535Mb: see help(memory.size)
SS 3: In solve(id - exponent * d, tol = tol) :
SS Reached total allocation of 1535Mb: see help(memory.size)
SS 4: In solve(id - exponent * d, tol = tol) :
SS Reached total allocation of 1535Mb: see help(memory.size)*
SS **
SS sessionInfo()
SS R version 2.9.0 (2009-04-17)

 [ . ] {irrelevant here}


SS Please help Matrix Experts

Well, I've marked the one line above

 ev - solve(id - exponent * d, tol=tol) %*% degree(graph, mode=all)*

begin abusive language; excuse in advance .. 
which really contains stupid advice.
Yes, this is strongly put, but I think people who tell you to
solve

A x = b  (A [n x n] matrix)

in R by  x - solve(A) %*% b
should not give advice on programming at all.
end abusive language

One of the proper advices would use
 x - solve(A, b)

and indeed that's even more crucial in the case where  A  is
sparse matrix:  solve(A) is never sparse for sparse A (*),
but   solve(A, b)  can happen with a fast (and memory-efficient)
algorithm, and that's what happens also when you use the Matrix package.
I append a version of your function that is also slightly
improved in other places.

(*) and that's why your memory blows up when A is large and sparse !

SS Thanks in advance
SS Nathan

SS [[alternative HTML version deleted]]

(still   It would *really* help if you used a more sensible e-mail
 configuration  }

Regards,
Martin Maechler

---

Here's the corrected bonpow.sparse() function , actually with
extra code for diagnostic output, etc.
You should probably simplify it again :

## I got help from IGRAPH community to use sparse Matrix
##
## http://igraph.wikidot.com/r-recipes#toc6
##
### Enhanced by Martin Maechler:
bonpow.sparse - function(graph, nodes = V(graph), loops = FALSE,
  exponent = 1, adj.type = both,
  trace = TRUE,
  rescale=FALSE, tol=1e-07)
{
stopifnot(require(igraph),
  require(Matrix))

if(trace) {
c.width - 30
C1 - function(s) cat(sprintf(%-*s .. , c.width, s))
C2 - function() cat([Ok]\n)
} else { C1 - C2 - function(...) {} }

## remove loops if requested
if (!loops) {
C1(simplify()ing graph)
graph - simplify(graph, remove.multiple=FALSE, remove.loops=TRUE)
C2()
}

## sparse adjacency matrix
C1(d - get.adjacency(., sparse))
d - get.adjacency(graph, type = adj.type, sparse=TRUE); C2()

if(trace = 2)
cat(class(d): , class(d),\n)

Re: [R] Memory size problems in R

2009-05-16 Thread Uwe Ligges



Fernando José Nascimento Sebastião wrote:

Dear all,

I have some problems how to increase memory in R.
I tried to start R by calling e.g. :(in the Properties, Shortcut tab, Target
field)

Rgui.exe --max-mem-size=2Gb  (Is this correct?)

But the error message still continue:


X-princomp(MAT2D.AltGeop61.90)

Error: cannot allocate vector of size 445.4 Mb


Note, this just means that the next chunk to be allocated is 445.4 Mb, 
it does not mean the amount will be sufficient for your problem .




memory.size()

[1] 456.01

memory.limit()

[1] 4095


That's strange, because you have not asked for 4Gb.
Do you have some other setting (perhaps in your startup code) that 
increases memory size to 4Gb after you started R?




dim(MAT2D.AltGeop61.90)

[1] 10957  5328

I use R 2.9.0 in Windows XP, with 40 GB on the disk and 7 GB of RAM.



64-bit version of Windows XP, I guess?




What can I do?



Use a 64-bit version of R [i.e. something on a LInux machine or perhaps 
the recently available commercial 64-bit version for Windows] or 
rephrase/-code your problem.


Uwe Ligges





I would appreciate somebody to help with any ideia.

[[alternative HTML version deleted]]

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


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


Re: [R] Plotting question re. cuminc

2009-05-16 Thread Uwe Ligges



K F Pearce wrote:

Hello everyone,

(This is my second question posted today on the R list).


and you have still not read the posting guide?

It asks you to provide commented, minimal, self-contained, reproducible 
code which also means that you need to tell which packages you are using.


I get, e.g.:

 cuminc(ftime,fstatus,group)
Error: could not find function cuminc
 ftime
Error: object 'ftime' not found
 fstatus
Error: object 'fstatus' not found
 group
Error: object 'group' not found

Best,
Uwe Ligges




I am carrying out a competing risks analysis using the cuminc function...this 
takes the form:

cuminc(ftime,fstatus,group)

In my study, fstatus has 3 different causes of failure (1,2,3) there are also censored 
cases (0).  group has two levels (0 and 1).

I therefore have 6 different cumulative incidence curves:

cause 1, group=0; cause 1 group=1
cause 2, group=0; cause 2 group=1
cause 3, group=0; cause 3 group=1

If I type the following commands:


xx-cuminc(ftime,fstatus,group)
plot(xx,lty=1,color=1:6)


I end up with the 6 curves plotted on the same graph.

Is there a way that I can plot a selection of these curves? (say only curves 
for cause 1, group=0 and cause 1 group=1).

Thank you so much,
Kind Regards,
Kim


Dr Kim Pearce CStat
Industrial Statistics Research Unit (ISRU)
School of Mathematics and Statistics
Herschel Building
University of Newcastle
Newcastle upon Tyne
United Kingdom
NE1 7RU

Tel.   0044 (0)191 222 6244 (direct)
Fax.   0044 (0)191 222 8020
Email: k.f.pea...@ncl.ac.uk
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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


Re: [R] data summary and some automated t.tests.

2009-05-16 Thread Uwe Ligges



stephen sefick wrote:

I would like to preform a t.test to each of the measured variables
(sand.silt etc.)


I am a big fan of applying t.test()s, but in this case: Are you really 
sure? The integers and particularly boxplot(x) do not indicate very well 
that the variables are somehow close to Gaussian ...



with a mean and sd for each of the treatments 


And what is the treatment???

Best,
Uwe Ligges



(up or
down), and out put this as a table  I am having a hard time
starting- maybe it is to close to lunch.  Any suggestions would be
greatly appreciated.

Stephen Sefick

x - (structure(list(sample. = structure(c(1L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 2L, 3L, 4L, 5L, 6L, 1L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 2L, 3L, 4L, 5L, 6L, 25L, 28L, 29L, 30L, 31L, 32L,
33L, 34L, 35L, 26L, 25L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L,
26L, 27L, 25L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 26L, 15L,
17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 16L, 15L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 24L, 16L, 36L, 39L, 40L, 41L, 42L, 43L, 44L,
45L, 46L, 37L, 36L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 37L,
38L), .Label = c(0805-r1, 0805-r10, 0805-r11, 0805-r12,
0805-r13, 0805-r14, 0805-r2, 0805-r3, 0805-r4, 0805-r5,
0805-r6, 0805-r7, 0805-r8, 0805-r9, 0805-u1, 0805-u10,
0805-u2, 0805-u3, 0805-u4, 0805-u5, 0805-u6, 0805-u7,
0805-u8, 0805-u9, 1005-r1, 1005-r10, 1005-r11, 1005-r2,
1005-r3, 1005-r4, 1005-r5, 1005-r6, 1005-r7, 1005-r8,
1005-r9, 1005-u1, 1005-u10, 1005-u11, 1005-u2, 1005-u3,
1005-u4, 1005-u5, 1005-u6, 1005-u7, 1005-u8, 1005-u9
), class = factor), date = structure(c(2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label =
c(10/1/05,
8/29/05), class = factor), Replicate = c(1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
), site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(dn, up
), class = factor), sand.silt = c(20L, 45L, 90L, 21L, 80L,
77L, 30L, 80L, 36L, 9L, 62L, 71L, 20L, 65L, 10L, 70L, 50L, 80L,
90L, 97L, 94L, 82L, 30L, 10L, 65L, 80L, 90L, 70L, 10L, 50L, 60L,
40L, 10L, 45L, 10L, 10L, 15L, 10L, 8L, 35L, 10L, 40L, 10L, 10L,
28L, 5L, 45L, 35L, 2L, 10L, 40L, 2L, 70L, 40L, 20L, 30L, 50L,
60L, 10L, 100L, 98L, 98L, 90L, 87L, 87L, 40L, 97L, 92L, 70L,
50L, 81L, 35L, 70L, 89L, 28L, 28L, 82L, 81L, 33L, 80L, 40L, 40L,
60L, 30L, 5L, 50L, 70L, 75L, 85L, 95L, 93L, 80L, 80L, 60L, 82L,
60L, 5L, 70L, 80L, 40L), gravel = c(8L, 45L, 7L, 5L, 10L, 5L,
35L, 7L, 45L, 60L, 0L, 0L, 5L, 8L, 25L, 0L, 45L, 15L, 0L, 1L,
2L, 5L, 6L, 15L, 10L, 5L, 3L, 10L, 20L, 0L, 20L, 31L, 20L, 35L,
70L, 30L, 60L, 60L, 70L, 50L, 70L, 40L, 50L, 30L, 48L, 85L, 20L,
30L, 20L, 60L, 30L, 8L, 10L, 30L, 30L, 10L, 0L, 0L, 10L, 0L,
0L, 0L, 2L, 8L, 8L, 30L, 0L, 3L, 15L, 29L, 11L, 60L, 15L, 8L,
60L, 25L, 8L, 9L, 42L, 1L, 50L, 40L, 10L, 60L, 60L, 30L, 10L,
10L, 0L, 0L, 0L, 2L, 2L, 0L, 1L, 25L, 10L, 10L, 10L, 50L), cobble = c(5L,
2L, 1L, 5L, 0L, 3L, 10L, 2L, 4L, 3L, 1L, 0L, 3L, 14L, 50L, 0L,
1L, 1L, 0L, 0L, 0L, 2L, 0L, 5L, 0L, 0L, 2L, 5L, 3L, 0L, 0L, 0L,
0L, 0L, 0L, 30L, 5L, 2L, 1L, 0L, 0L, 0L, 5L, 35L, 3L, 0L, 0L,
0L, 40L, 0L, 0L, 5L, 0L, 0L, 10L, 5L, 0L, 0L, 10L, 0L, 0L, 0L,
0L, 1L, 1L, 30L, 0L, 0L, 0L, 10L, 4L, 3L, 2L, 0L, 2L, 0L, 0L,
0L, 20L, 0L, 0L, 0L, 0L, 0L, 20L, 0L, 10L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 10L, 0L, 0L, 0L), boulder.bedrock = c(60L, 0L,
0L, 45L, 0L, 0L, 0L, 0L, 0L, 8L, 10L, 0L, 35L, 5L, 8L, 0L, 0L,
0L, 0L, 0L, 0L, 10L, 60L, 70L, 0L, 0L, 0L, 5L, 55L, 0L, 0L, 0L,
40L, 0L, 0L, 0L, 0L, 15L, 0L, 0L, 10L, 0L, 20L, 10L, 0L, 0L,
0L, 0L, 20L, 0L, 0L, 60L, 0L, 0L, 20L, 0L, 10L, 0L, 50L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 10L, 0L, 0L, 0L, 0L, 0L, 4L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 5L, 0L, 0L, 5L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 75L, 10L, 0L, 0L), fine.root = c(5L, 7L,
0L, 10L, 2L, 6L, 5L, 4L, 3L, 7L, 0L, 0L, 7L, 4L, 6L, 1L, 4L,
2L, 2L, 2L, 3L, 1L, 0L, 1L, 20L, 5L, 3L, 5L, 10L, 2L, 0L, 6L,
10L, 10L, 15L, 0L, 0L, 5L, 15L, 0L, 10L, 10L, 0L, 5L, 8L, 5L,
0L, 20L, 0L, 8L, 0L, 0L, 7L, 0L, 

Re: [R] (no subject)

2009-05-16 Thread Linlin Yan
On Sat, May 16, 2009 at 12:05 PM, Debbie Zhang debbie0...@hotmail.com wrote:

 Dear R users,

 Does anyone know how to write a function involving derivative?

 i.e. I want to implementing Newton's method in R, so my function is something 
 like

 x- x-y/y'

 I am not sure how to write y' in my function. Can anyone help?



 In addition, if I want to implementing newton's method several times, what 
 code should I use?

 Currently, I use the following code.



 -1
Is this line x - 1?

 for (i in 1:20){
 + x-x-(x^3-2*x^2+3*x-5)/(3*x^2-4*x+3)}
 x
 [1] 1.843734

 However, when I typed in the following code, I would yield the same answer.
 -1
And is this line x - 1, too?

 for (i in 1:1){
 + x-x-(x^3-2*x^2+3*x-5)/(3*x^2-4*x+3)}
 x
 [1] 1.843734

Are you sure about this result?
What I got is like this:

 x - 1; for (i in 1:20) { x - x-(x^3-2*x^2+3*x-5)/(3*x^2-4*x+3); }; x
[1] 1.843734
 x - 1; for (i in 1:1) { x - x-(x^3-2*x^2+3*x-5)/(3*x^2-4*x+3); }; x
[1] 2.5

There are different!


 Can anyone suggest me what the problem is?

 Please help.
 Thanks so much.

 Debbie
 _
 View photos of singles in your area Click Here

 au%2Fsearch%2Fsearch%2Easpx%3Fexec%3Dgo%26tp%3Dq%26gc%3D2%26tr%3D1%26lage%3D18%26uage%3D55%26cl%3D14%26sl%3D0%26dist%3D50%26po%3D1%26do%3D2%26trackingid%3D1046138%26r2s%3D1_t=773166090_r=Hotmail_Endtext_m=EXT
        [[alternative HTML version deleted]]

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


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


Re: [R] Fw: Help with loops(corrected question)

2009-05-16 Thread Uwe Ligges



Amit Patel wrote:



--- On Fri, 15/5/09, Amit Patel amitrh...@yahoo.co.uk wrote:


From: Amit Patel amitrh...@yahoo.co.uk
Subject: Help with loops
To: r-help@r-project.org
Date: Friday, 15 May, 2009, 12:17 PM
Hi
I am trying to create a loop which averages replicates in
my data.
The original data has many rows. and consists of 40 column
zz[,2:41] plus row headings in zz[,1]
I am trying to average each set of values (i.e. zz[1,2:3]
averaged and placed in average_value[1,2] and so on.
below is my script but it seems to be stuck in an endless
loop
Any suggestions??



If you want row-wise means, rowMeans does it without any loop, but 
instead you could loop over the column indices or go without any 
explicit loop as in:


averaged_value - zz[,1:21]
temp - as.matrix(zz[,2:41])
dim(temp) - c(nrow(temp),2,20)
# and then either:
temp - aperm(temp, c(1,3,2))
averaged_value[,2:21] - rowMeans(temp, dim=2)
#
averaged_value[,2:21] - apply(temp, c(1,3), mean)


Uwe Ligges



for (i in 1:length(zz[,1])) {



#calculates Meanss
#Sample A
average_value[i,2] - rowMeans(zz[i,2:3])
average_value[i,3] - rowMeans(zz[i,4:5])
average_value[i,4] - rowMeans(zz[i,6:7])
average_value[i,5] - rowMeans(zz[i,8:9])
average_value[i,6] - rowMeans(zz[i,10:11])

#Sample B
average_value[i,7] - rowMeans(zz[i,12:13])
average_value[i,8] - rowMeans(zz[i,14:15])
average_value[i,9] - rowMeans(zz[i,16:17])
average_value[i,10] - rowMeans(zz[i,18:19])
average_value[i,11] - rowMeans(zz[i,20:21])

#Sample C
average_value[i,12] - rowMeans(zz[i,22:23])
average_value[i,13] - rowMeans(zz[i,24:25])
average_value[i,14] - rowMeans(zz[i,26:27])
average_value[i,15] - rowMeans(zz[i,28:29])
average_value[i,16] - rowMeans(zz[i,30:31])

#Sample D
average_value[i,17] - rowMeans(zz[i,32:33])
average_value[i,18] - rowMeans(zz[i,34:35])
average_value[i,19] - rowMeans(zz[i,36:37])
average_value[i,20] - rowMeans(zz[i,38:39])
average_value[i,21] - rowMeans(zz[i,40:41])
  }


thanks









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


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


[R] maxLik pakage

2009-05-16 Thread amene kheradmandi
Hi all;
I recently have been used 'maxLik' function for maximizing G2StNV178 function 
with gradient function gradlik; for receiving this goal, I write the following 
program; but I have been seen an error  in calling gradient  function;
The maxLik function can't enter gradlik function (definition of gradient 
function); I guess my mistake is in line  ,that the vector  ‘h’ is 
defined.
 
I need your advices for resolve the error;
Sincerely yours
A. Kheradmandi
##data vector
x=c(0,0,14,7,0,22,2,18,10,29,
16,11,59,6,33,5,1,0,28,17,
28,19,10,43,9,17,42,2,22,6,
14,0,59,9,11,5,11,37,15,26,
57,8,16,22,5,13,19,12,34,8,28,35,13,11,59,
8,7,20,36,39,14,31,18,32,30,
29,9,2,5,3,19,27,76,4,32,
24,13,3,13,24,41,20,0,13,26,
0,23,19,10,14,14,13,15,18,29,
29,0,20,0,22,13,17,12,29,0,
0,16,55,11,19,9,2,9,32,16,
55,10,59,8,65,39,1,8,2,7,
37,8,0,5,8,0,7,0,20,10,
11,3,0,7,31,14,18,3,4,34,
32,4,9,9,8,36,44,0,9,27,28,55,72,12,1,
9,0,32,0,0,2,15,5,6,17,
63,61,9,15,15,0,2)
#goal is  found unique maximum for  5-parameter function with using  
maxLik function
#the function in latex commands is as following:
 \begin{eqnarray*}
\ell(\xi,\omega,\nu,\lambda_1,\lambda_2)=n\log2-n\log\omega+n\log\Gamma(\frac{\nu+1}{2})-\frac{n}{2}\log(\nu\pi)\\
-n\log\Gamma(\frac{\nu}{2})-\frac{\nu+1}{2}\sum_{i=1}^{n}\log(1+\frac{(x_i-\xi)^2}{\omega^2\nu})+\sum_{i=1}^{n}\log\Phi(\lambda_1\frac{(x_i-\xi)}{\sqrt{\omega^2+\lambda_2(x_i-\xi)^2}})
\end{eqnarray*}
##
G2StNV178-function(a){
require(maxLik)
II=0
nu-(a[1])
lambda1-a[2]
lambda2-a[3]
ksi-a[4]
omega-a[5]
II-log(prod((2*dt((x-ksi)/omega,nu)*pnorm((lambda1*(x-ksi)/omega)/sqrt(1+lambda2*((x-ksi)/omega)^2)))/omega))
II
}
definition of gradient  function
gradlik- function(a){
nu-a[1]
lambda1-a[2]
lambda2-a[3]
ksi-a[4]
omega-a[5]  
#***#
h-c(f1=n*digamma((nu+1)/2)-n/(2*nu)-n*digamma(nu/2)-1/2*sum(log(1+(x-ksi)^2/(omega^2nu)))+(nu+1)/2*sum((x-ksi)^2/(omege^2*nu^2+nu*(x-ksi)^2)),
f2=sum((x-ksi)*dnorm(lambda1*(x-ksi)/sqrt(omega^2+lambda2*(x-ksi)^2))/(sqrt(omega^2+lambda2*(x-ksi)^2)*pnorm(lambda1*(x-ksi)/sqrt(omega^2+lambda2*(x-ksi),
 
f3=sum((lambda1*(x-ksi)^3*dnorm(lambda1*(x-ksi)/sqrt(omega^2+lambda2*(x-ksi)^2)))/(
 2*omega^3*pnorm(lambda1*(x-ksi)/sqrt(omega^2+lambda2*(x-ksi)^2))
*sqrt((1+lambda2*(x-ksi)^2/omega^2 )^3))),
f4=(nu+1)*sum((x-ksi)/(omega^2*nu+(x-ksi)^2))-sum((lambda1*dnorm((lambda1*(x-ksi))/(omega^2+lambda2*(x-ksi)^2)))/(omega*sqrt(1+lambda2*(x-ksi)^2/(omega^2))
*pnorm(lambda1*(x-ksi)/(sqrt(omega^2+lambda2*(x-ksi)^2), 
f5=-n/omega+(nu+1)*n*sum((x-ksi)^2/(nu*omega^3+omega*(x-ksi)^2))-sum((lambda1*(x-ksi)*omega*dnorm(lambda1*(x-ksi)/(sqrt(omega^2+lambda2*(x-ksi)^2))
/(pnorm(lambda1*(x-ksi)/(sqrt(omega^2+lambda2*(x-ksi)^2))*sqrt((omega^2+lambda2*(x-ksi)^2)^3)))
}
n- length(x) # the final command is :
res- maxLik(G2StNV178,grad=gradlik,start=c(4.666484 ,4603.399055 , 
4603.399055   ,-0.016674 ,19.055865),tol=1e-16,iterlim =3000)
summary(res)


  
[[alternative HTML version deleted]]

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


[R] MANOVA

2009-05-16 Thread Davide Floriello

Dear Sir,
I am Davide Floriello and I am a student in mathematics. I have got a problem 
with the MANOVA commands. I write here what I have done:

 

PV - read.table('PV.txt')
PV - data.frame(PV)

g - 12
p - 2
REL - factor(PV$REL)
HPV - factor(PV$HPV)
fit - manova(as.matrix(PV) ~ REL + HPV + REL:HPV)

 

After this last line, an error message is shown:

 

Errore in `[[-.data.frame`(`*tmp*`, i, value = c(17L, 19L, 16L, 14L, 15L,  : 
  replacement has 48 rows, data has 12
Inoltre: Warning message:
In storage.mode(v) - double : si è prodotto un NA per coercizione

 

I don't know how to solve this problem.

Thank you.

Davide Floriello



_


[[alternative HTML version deleted]]

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


[R] vector fragment

2009-05-16 Thread jonas garcia
Dear R users:



I have got a simple question that has been bothering me for a while.

Given a certain character vector, I would like to get in a separate vector a
fragment of text, in this case the 3rd and 4th letters of each element.



So, if:



v- c(“stratosphere”, “mesosphere”, “troposphere”)



I want to obtain a different vector like this:



c(“ra”, “so”, “op”)



Thanks in advance for your help



Jonas

[[alternative HTML version deleted]]

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


Re: [R] vector fragment

2009-05-16 Thread Jorge Ivan Velez
Dear Jonas,
Try this:

 v- c('stratosphere', 'mesosphere', 'troposphere')
 substr(v,3,4)
[1] ra so op

See ?substr for more information.

HTH,

Jorge


On Sat, May 16, 2009 at 9:52 AM, jonas garcia garcia.jona...@googlemail.com
 wrote:

 Dear R users:



 I have got a simple question that has been bothering me for a while.

 Given a certain character vector, I would like to get in a separate vector
 a
 fragment of text, in this case the 3rd and 4th letters of each element.



 So, if:



 v- c(“stratosphere”, “mesosphere”, “troposphere”)



 I want to obtain a different vector like this:



 c(“ra”, “so”, “op”)



 Thanks in advance for your help



 Jonas

[[alternative HTML version deleted]]


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



[[alternative HTML version deleted]]

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


Re: [R] maxLik pakage

2009-05-16 Thread spencerg
 1. Have you worked through the examples in the maxLik help page? Your 
example is sufficiently complicated that I hesitate to try it myself, 
especially since I see characters in your email that are not simple 
ASCII. If you can get the examples in the maxLik help page to work, 
identify the differences between your example and those on the help 
page, then generate intermediate examples to test your understanding 
until you either solve your problem or you find a simpler example that 
you don't understand and then post that to this list.



2. Have you checked your gradient with the compareDerivatives function 
in the maxLik package? If your gradient function is not correct, this 
should help you understand and hopefully fix the problem.



Hope this helps.
Spencer

amene kheradmandi wrote:

Hi all;
I recently have been used 'maxLik' function for maximizing G2StNV178 function 
with gradient function gradlik; for receiving this goal, I write the following 
program; but I have been seen an error  in calling gradient  function;
The maxLik function can't enter gradlik function (definition of gradient 
function); I guess my mistake is in line  ,that the vector  ‘h’ is 
defined.
 
I need your advices for resolve the error;

Sincerely yours
A. Kheradmandi
##data vector
x=c(0,0,14,7,0,22,2,18,10,29,
16,11,59,6,33,5,1,0,28,17,
28,19,10,43,9,17,42,2,22,6,
14,0,59,9,11,5,11,37,15,26,
57,8,16,22,5,13,19,12,34,8,28,35,13,11,59,
8,7,20,36,39,14,31,18,32,30,
29,9,2,5,3,19,27,76,4,32,
24,13,3,13,24,41,20,0,13,26,
0,23,19,10,14,14,13,15,18,29,
29,0,20,0,22,13,17,12,29,0,
0,16,55,11,19,9,2,9,32,16,
55,10,59,8,65,39,1,8,2,7,
37,8,0,5,8,0,7,0,20,10,
11,3,0,7,31,14,18,3,4,34,
32,4,9,9,8,36,44,0,9,27,28,55,72,12,1,
9,0,32,0,0,2,15,5,6,17,
63,61,9,15,15,0,2)
#goal is  found unique maximum for  5-parameter function with using  
maxLik function
#the function in latex commands is as following:
 \begin{eqnarray*}
\ell(\xi,\omega,\nu,\lambda_1,\lambda_2)=n\log2-n\log\omega+n\log\Gamma(\frac{\nu+1}{2})-\frac{n}{2}\log(\nu\pi)\\
-n\log\Gamma(\frac{\nu}{2})-\frac{\nu+1}{2}\sum_{i=1}^{n}\log(1+\frac{(x_i-\xi)^2}{\omega^2\nu})+\sum_{i=1}^{n}\log\Phi(\lambda_1\frac{(x_i-\xi)}{\sqrt{\omega^2+\lambda_2(x_i-\xi)^2}})
\end{eqnarray*}
##
G2StNV178-function(a){
require(maxLik)
II=0
nu-(a[1])
lambda1-a[2]
lambda2-a[3]
ksi-a[4]
omega-a[5]
II-log(prod((2*dt((x-ksi)/omega,nu)*pnorm((lambda1*(x-ksi)/omega)/sqrt(1+lambda2*((x-ksi)/omega)^2)))/omega))
II
}
definition of gradient  function
gradlik- function(a){
nu-a[1]
lambda1-a[2]
lambda2-a[3]
ksi-a[4]
omega-a[5]Â  
#***#

h-c(f1=n*digamma((nu+1)/2)-n/(2*nu)-n*digamma(nu/2)-1/2*sum(log(1+(x-ksi)^2/(omega^2nu)))+(nu+1)/2*sum((x-ksi)^2/(omege^2*nu^2+nu*(x-ksi)^2)),
f2=sum((x-ksi)*dnorm(lambda1*(x-ksi)/sqrt(omega^2+lambda2*(x-ksi)^2))/(sqrt(omega^2+lambda2*(x-ksi)^2)*pnorm(lambda1*(x-ksi)/sqrt(omega^2+lambda2*(x-ksi), 
f3=sum((lambda1*(x-ksi)^3*dnorm(lambda1*(x-ksi)/sqrt(omega^2+lambda2*(x-ksi)^2)))/( 2*omega^3*pnorm(lambda1*(x-ksi)/sqrt(omega^2+lambda2*(x-ksi)^2))

*sqrt((1+lambda2*(x-ksi)^2/omega^2 )^3))),
f4=(nu+1)*sum((x-ksi)/(omega^2*nu+(x-ksi)^2))-sum((lambda1*dnorm((lambda1*(x-ksi))/(omega^2+lambda2*(x-ksi)^2)))/(omega*sqrt(1+lambda2*(x-ksi)^2/(omega^2))
*pnorm(lambda1*(x-ksi)/(sqrt(omega^2+lambda2*(x-ksi)^2), 
f5=-n/omega+(nu+1)*n*sum((x-ksi)^2/(nu*omega^3+omega*(x-ksi)^2))-sum((lambda1*(x-ksi)*omega*dnorm(lambda1*(x-ksi)/(sqrt(omega^2+lambda2*(x-ksi)^2))

/(pnorm(lambda1*(x-ksi)/(sqrt(omega^2+lambda2*(x-ksi)^2))*sqrt((omega^2+lambda2*(x-ksi)^2)^3)))
}
n- length(x) # the final command is :
res- maxLik(G2StNV178,grad=gradlik,start=c(4.666484 ,4603.399055 , 
4603.399055Â Â  ,-0.016674 ,19.055865),tol=1e-16,iterlim =3000)
summary(res)


  
	[[alternative HTML version deleted]]


  



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



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


[R] bagged importance estimates in earth problem

2009-05-16 Thread Joseph Retzer
I was trying to produced bagged importance estimates of attributes in earth 
using the caret package with the following commands:

  fit2 - bagEarth(loyalty ~ ., data=model1, B = 10)
  bagImpGCV - varImp(fit2,value=gcv)

My bootstrap estimates are produced however the second command varImp 
produces the following error:

   Error in UseMethod(varImp) : no applicable method for varImp

Not sure what is going on, any advice would be appreciated,
Thanks,
Joe Retzer




  
[[alternative HTML version deleted]]

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


Re: [R] barplot in a loop not printing out to directory

2009-05-16 Thread Dimitri Liakhovitski
Thanks a lot.
The problem was that I was naming my files illegally. I was starting
them with a number. As soon as I changed that, everything worked.
Dimitri

On Sat, May 16, 2009 at 9:12 AM, Jim Lemon j...@bitwrit.com.au wrote:
 Dimitri Liakhovitski wrote:

 Hello!
 I am experiencing a problem with section 3 of the code below. I want
 to generate barplots (based on data generated in Sections 1 and 2) in
 a loop - for each variable in data - and save them as .emf files in
 my current directory. But it's not working - it's printing values to
 be plotted to the screen but does not print the plots themselves
 anywhere (and not in the directory).
 Thank you very much for your help!
 Dimitri
 ...

 I would insert a line just after filename=...
 cat(filename,\n)
 and see what the filenames are.

 Jim

 ### Section 3. I want to generate a barplot based on each and every
 table I produced above and put it in my current directory. But it's
 not working.

 for(i in 1:length(tables)) {
        chart.name-names(data)[i]
        filename=paste(i,chart.name,emf,sep=.)
        win.metafile(file=filename)
        chart-barplot(tables[[i]][[2]],xlab = Values, ylab =
 Percentages,ylim=c(0,100))
        print(chart)
        dev.off()
 }

 Thank you very much!






-- 
Dimitri Liakhovitski
MarketTools, Inc.
dimitri.liakhovit...@markettools.com

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


Re: [R] ggplot2: annotating plot with mathematical formulae

2009-05-16 Thread hadley wickham
Hi Paul,

Unfortunately that's not something that's currently possible with
ggplot2, but I am thinking about how to make it possible.

Hadley

On Sat, May 16, 2009 at 7:48 AM, Paul Emberson em...@calidasoft.co.uk wrote:
 Hi Stephen,

 The problem is that the label on the graph doesn't get rendered with a
 superscript.  I want the label on the graph to be rendered the same way
 as the label you have put on the axis.

 I am plotting a piecewise function and I wanted to label each section of it.

 Paul

 stephen sefick wrote:
 how about this

 a - 1:10
 b - 1:10
 d - paste(x,^,{n-1})
 qplot(a,b, xlab=expression(x^{n-1}))+geom_text(aes(4,8, label=d))

 On Fri, May 15, 2009 at 10:02 PM, Paul Emberson em...@calidasoft.co.uk 
 wrote:

 Hi,

 Is there a way of annotating a ggplot plot with mathematical formulae?

 I can do

 geom_text(aes(label=some text, ...

 but I can't do

 geom_text(aes(label=expression(x^{n-1}), ...

 It gives the error

 Error: geom_text requires the following missing aesthetics: label

 Is there a convenient equivalent?

 Cheers,

 Paul

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







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




-- 
http://had.co.nz/

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


Re: [R] Checking a (new) package - examples require other package functions

2009-05-16 Thread Rebecca Sela
After adding the right functions to the NAMESPACE file, I am now getting a 
different error:

Error: package/namespace load failed for 'REEMtree'
Call sequence:
2: stop(gettextf(package/namespace load failed for '%s', 
libraryPkgName(package)), 
   call. = FALSE, domain = NA)
1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE)
Execution halted

I have attached the NAMESPACE file in case that is where the problem is.  

Thanks again for your help!

Rebecca


- Original Message -
From: Duncan Murdoch murd...@stats.uwo.ca
To: Rebecca Sela rs...@stern.nyu.edu
Cc: r-help r-help@r-project.org
Sent: Thursday, May 14, 2009 6:57:21 AM GMT -05:00 US/Canada Eastern
Subject: Re: [R] Checking a (new) package - examples require other package 
functions

On 13/05/2009 2:38 PM, Rebecca Sela wrote:
 I am creating an R package.  I ran R CMD check on the package, and everything 
 passed until it tried to run the examples.  Then, the result was:
 
 * checking examples ... ERROR
 Running examples in REEMtree-Ex.R failed.
 The error most likely occurred in:
 
 ### * AutoCorrelationLRtest

 flush(stderr()); flush(stdout())

 ### Name: AutoCorrelationLRtest
 ### Title: Test for autocorrelation in the residuals of a RE-EM tree
 ### Aliases: AutoCorrelationLRtest
 ### Keywords: htest tree models

 ### ** Examples

 # Estimation without autocorrelation
 simpleEMresult-RandomEffectsTree(Y~D+t+X, data=simpleREEMdata, 
 random=~1|ID, simpleREEMdata$ID)
 Error: couldn't find function RandomEffectsTree
 Execution halted
 
 
 The function RandomEffectsTree is defined in the R code for the package.  
 How can I refer to other functions from the package in examples?  (I have the 
 Writing R-extensions PDF, so it would be enough to point me to the right 
 page, if the answer is in there and I just missed it.)

You should not need to do anything special to make package functions 
visible, as long as they would be visible to a normal user.  (Functions 
not exported in the NAMESPACE file won't be visible in the examples.)

Are you sure you have a function with that exact name?  It could be a 
typo somewhere, e.g. RandomEffectTree or RandomeffectsTree.

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


[R] MEXVAL

2009-05-16 Thread Mihai Nica
Greetings:

I would like to kindly ask help with obtaining mexval statistics (marginal 
explanatory value - percentage increase in SEE if the variable were left out of 
the regression model) for a logit (glm) model with several continuous 
independent variables. I believe I can do it manually for each variable, but I 
really hope there might be somebody who has a function already written. Writing 
one is still a little over my skills (I am working on it though).

Thanks,

 mike



  
[[alternative HTML version deleted]]

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


Re: [R] ggplot2: annotating plot with mathematical formulae

2009-05-16 Thread baptiste auguie
If you're desperate for a workaround, you might want to try this  
example using pgfSweave,


http://ggplot2.wik.is/Mathematical_annotations

On a similar vein, you could try psfrag replacements with a postscript  
device (there is some code for this on the list archives).


Feel free to comment / edit on the wiki page.

HTH,

baptiste

On 16 May 2009, at 14:48, Paul Emberson wrote:


Hi Stephen,

The problem is that the label on the graph doesn't get rendered with a
superscript.  I want the label on the graph to be rendered the same  
way

as the label you have put on the axis.

I am plotting a piecewise function and I wanted to label each  
section of it.


Paul

stephen sefick wrote:

how about this

a - 1:10
b - 1:10
d - paste(x,^,{n-1})
qplot(a,b, xlab=expression(x^{n-1}))+geom_text(aes(4,8, label=d))

On Fri, May 15, 2009 at 10:02 PM, Paul Emberson em...@calidasoft.co.uk 
 wrote:



Hi,

Is there a way of annotating a ggplot plot with mathematical  
formulae?


I can do

geom_text(aes(label=some text, ...

but I can't do

geom_text(aes(label=expression(x^{n-1}), ...

It gives the error

Error: geom_text requires the following missing aesthetics: label

Is there a convenient equivalent?

Cheers,

Paul

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









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


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

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

2009-05-16 Thread Paul Johnson
On Fri, May 15, 2009 at 6:22 AM, lagreene lagreene...@gmail.com wrote:

 Thanks Jorge,

 but I still don't understand where they come from.  when I use:
 fitdistr(mydata, t, df = 9) and get values for m and s, and the variance
 of my data should be the df/s?

 I jsut want to be able to confirm how m and s are calculated

I've wondered the same kind of thing and I've learned the answer is
easy!  It is not so easy for all R functions, but did you try this
with fitdistr?

 library (MASS)
 fitdistr

the output that follows is the ACTUAL FORMULA that is used to make the
calculations!

I've not yet mastered the art of getting code for some functions.

 predict
function (object, ...)
UseMethod(predict)
environment: namespace:stats

But I know there is a way to get that code if you know the correct way
to run getS3method().  But I usually just go read the R source code
rather than puzzle over that.




 mydt - function(x, m, s, df) dt((x-m)/s, df)/s
 fitdistr(x2, mydt, list(m = 0, s = 1), df = 9, lower = c(-Inf, 0))

 Thanks anyway for the help!

-- 
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas

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

2009-05-16 Thread John Fox
Dear Davide,

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On
 Behalf Of Davide Floriello
 Sent: May-16-09 8:51 AM
 To: r-help@r-project.org
 Subject: [R] MANOVA
 
 
 Dear Sir,
 I am Davide Floriello and I am a student in mathematics. I have got a
problem
 with the MANOVA commands. I write here what I have done:
 
 
 
 PV - read.table('PV.txt')
 PV - data.frame(PV)

The second command is redundant, since read.table() produces a data frame.

 
 g - 12
 p - 2

These commands are unnecessary, since you're not referencing g or p.

 REL - factor(PV$REL)
 HPV - factor(PV$HPV)

Whether these commands are necessary depends upon whether REL and HPV are
already factors; if they are character data in the file PV.txt, then by
default read.table() will make factors.

 fit - manova(as.matrix(PV) ~ REL + HPV + REL:HPV)

This really doesn't make sense: Since REL and HPV are among the variables in
PV (although not necessarily factors), these variables are both on the
left-hand and right-hand side of the model.

 
 
 
 After this last line, an error message is shown:
 
 
 
 Errore in `[[-.data.frame`(`*tmp*`, i, value = c(17L, 19L, 16L, 14L, 15L,
:
   replacement has 48 rows, data has 12
 Inoltre: Warning message:
 In storage.mode(v) - double : si h prodotto un NA per coercizione

My guess is that REL and HPV are non-numeric. I wouldn't have to guess if
you had provided the data.

I hope this helps,
 John

 
 
 
 I don't know how to solve this problem.
 
 Thank you.
 
 Davide Floriello
 
 
 
 _
 
 
   [[alternative HTML version deleted]]

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


[R] converting numeric to integer

2009-05-16 Thread Thomas Mang

Hello,

Suppose I have x, which is a variable of class numeric. The calculations 
performed to yield x imply that mathematically it should be an integer , 
but due to round-off errors, it might not be (and so in either 
direction). The error is however small, so round(x) will yield the 
appropriate integer value. Moreover, this integer values is guaranteed 
to be representable by an 'integer' class, that is -2^31  x  2^31, and 
logically it is an integer anyway. So I want to convert x from class 
'numeric' to 'integer'. What is the most elegant, but always correct 
way, to achieve this conversion ?


What comes to mind is of course something along:

x = as.integer(round(x))

I am, however, not sure if this always works, because I do not know if 
the round-function is guaranteed to return a numeric value which, in 
finite binary representation, is always = the underlying mathematical 
integer. If that is however guaranteed, that would of course be a simple 
+ elegant one.


An alternative I came up with is:

x = as.integer(round(x) + ifelse(x = 0, 0.5, -0.5))
Where I explicitly add a bit to ensure the finite binary representation 
must be = the underlying integer, and then truncate the decimal digits.
IMO, this one is always guaranteed to work, at least within the 
numerical range of what integers are limited to anyway.



What's your opinion on the issue ?
Any other solution ?

Thanks a lot in advance and cheers,
Thomas

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


[R] Question about barplot: gridlines value labels

2009-05-16 Thread Dimitri Liakhovitski
Hello!
I promise I looked into help files before asking. Still cannot figure
it out. I think it's because I am totally confused what packages use
lettice, which use trellis, etc.
Sections 1 and 2 below produce the data and the data to plot. My
question is about barplot in Section 3. I am trying to:
1. add only horizontal gridlines and manipulate the type and color of
that line. tck = 1 is not flexible enough to do it.
2. make the legend come on top of gridlines and not under them
3. add plotted Y values above the bars

Thank you very much for any pointers!
Dimitri

### Section 1: generates my data set data:

N-100
myset1-c(1,2,3,4,5)
probs1-c(.05,.10,.15,.40,.30)

group-unlist(lapply(1:4,function(x){
out-rep(x,25)
return(out)
}))
set.seed(1)
a-sample(myset1, N, replace = TRUE,probs1)
a[which(rbinom(100,2,.01)==1)]-NA
set.seed(12)
b-sample(myset1, N, replace = TRUE,probs1)
b[which(rbinom(100,2,.01)==1)]-NA
set.seed(123)
data-data.frame(group,a=a,b=b)
data[group]-lapply(data[group],function(x) {
x[x %in% 1]-Group 1
x[x %in% 2]-Group 2
x[x %in% 3]-Group 3
x[x %in% 4]-Group 4
return(x)
})
data$group-as.factor(data$group)
lapply(data,table,exclude=NULL)

### Section 2. Creating data to plot:
table.a-with(data,table(group,a))
table.a.percents-apply(table.a,2,function(x){
out-round(x*100/sum(x),1)
return(out)
})

### Section 3. Creating a plot:
barplot(table.a.percents,xlab = Values, ylab =
Percentages,ylim=c(0,100),axis.lty=1,legend=T,beside=T,tck = 1)

-- 
Dimitri Liakhovitski
MarketTools, Inc.
dimitri.liakhovit...@markettools.com

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


[R] How to draw a R plot in Java frame ?

2009-05-16 Thread Obi Wan
Hi guys,

I am new to R and would like to display a R plot inside my Java app.

Is there a possibility to do that? If so, what library do I need?

May the force be with you



  
[[alternative HTML version deleted]]

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


Re: [R] data summary and some automated t.tests.

2009-05-16 Thread stephen sefick
Up and down are the treatments.  These are replicates within date for
percent cover of habiat.  This is habitat data for a stream
restoration - up is the unrestored and dn is the restored.  I have
looked at the density plots and they do not look gaussian - you are
absolutely right.  Even log(n+1) transformed they do not look
Gaussian.  Is there some other way that I would test for a difference
that you can think of?  My thoughts were to run a Permutation t.test,
but I am very new to permutations, and don't know if this applies.
The other thing that I was thinking was to use a npmanova (adonis in
vegan) to test if the centroids of the habitat classifications were
different.  I am in the process of working up my thesis data for
publication in a journal (there are other very interesting pieces to
the data set that I am working with, and this is one of the last
things that I need to wrap up before I can start editing/rewriting my
masters work).  Any thoughts would be greatly appreciated.
thanks,

Stephen Sefick

2009/5/16 Uwe Ligges lig...@statistik.tu-dortmund.de:


 stephen sefick wrote:

 I would like to preform a t.test to each of the measured variables
 (sand.silt etc.)

 I am a big fan of applying t.test()s, but in this case: Are you really sure?
 The integers and particularly boxplot(x) do not indicate very well that the
 variables are somehow close to Gaussian ...


 with a mean and sd for each of the treatments

 And what is the treatment???

 Best,
 Uwe Ligges


 (up or
 down), and out put this as a table  I am having a hard time
 starting- maybe it is to close to lunch.  Any suggestions would be
 greatly appreciated.

 Stephen Sefick

 x - (structure(list(sample. = structure(c(1L, 7L, 8L, 9L, 10L, 11L,
 12L, 13L, 14L, 2L, 3L, 4L, 5L, 6L, 1L, 7L, 8L, 9L, 10L, 11L,
 12L, 13L, 14L, 2L, 3L, 4L, 5L, 6L, 25L, 28L, 29L, 30L, 31L, 32L,
 33L, 34L, 35L, 26L, 25L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L,
 26L, 27L, 25L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 26L, 15L,
 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 16L, 15L, 17L, 18L, 19L,
 20L, 21L, 22L, 23L, 24L, 16L, 36L, 39L, 40L, 41L, 42L, 43L, 44L,
 45L, 46L, 37L, 36L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 37L,
 38L), .Label = c(0805-r1, 0805-r10, 0805-r11, 0805-r12,
 0805-r13, 0805-r14, 0805-r2, 0805-r3, 0805-r4, 0805-r5,
 0805-r6, 0805-r7, 0805-r8, 0805-r9, 0805-u1, 0805-u10,
 0805-u2, 0805-u3, 0805-u4, 0805-u5, 0805-u6, 0805-u7,
 0805-u8, 0805-u9, 1005-r1, 1005-r10, 1005-r11, 1005-r2,
 1005-r3, 1005-r4, 1005-r5, 1005-r6, 1005-r7, 1005-r8,
 1005-r9, 1005-u1, 1005-u10, 1005-u11, 1005-u2, 1005-u3,
 1005-u4, 1005-u5, 1005-u6, 1005-u7, 1005-u8, 1005-u9
 ), class = factor), date = structure(c(2L, 2L, 2L, 2L, 2L,
 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label =
 c(10/1/05,
 8/29/05), class = factor), Replicate = c(1L, 1L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
 ), site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(dn, up
 ), class = factor), sand.silt = c(20L, 45L, 90L, 21L, 80L,
 77L, 30L, 80L, 36L, 9L, 62L, 71L, 20L, 65L, 10L, 70L, 50L, 80L,
 90L, 97L, 94L, 82L, 30L, 10L, 65L, 80L, 90L, 70L, 10L, 50L, 60L,
 40L, 10L, 45L, 10L, 10L, 15L, 10L, 8L, 35L, 10L, 40L, 10L, 10L,
 28L, 5L, 45L, 35L, 2L, 10L, 40L, 2L, 70L, 40L, 20L, 30L, 50L,
 60L, 10L, 100L, 98L, 98L, 90L, 87L, 87L, 40L, 97L, 92L, 70L,
 50L, 81L, 35L, 70L, 89L, 28L, 28L, 82L, 81L, 33L, 80L, 40L, 40L,
 60L, 30L, 5L, 50L, 70L, 75L, 85L, 95L, 93L, 80L, 80L, 60L, 82L,
 60L, 5L, 70L, 80L, 40L), gravel = c(8L, 45L, 7L, 5L, 10L, 5L,
 35L, 7L, 45L, 60L, 0L, 0L, 5L, 8L, 25L, 0L, 45L, 15L, 0L, 1L,
 2L, 5L, 6L, 15L, 10L, 5L, 3L, 10L, 20L, 0L, 20L, 31L, 20L, 35L,
 70L, 30L, 60L, 60L, 70L, 50L, 70L, 40L, 50L, 30L, 48L, 85L, 20L,
 30L, 20L, 60L, 30L, 8L, 10L, 30L, 30L, 10L, 0L, 0L, 10L, 0L,
 0L, 0L, 2L, 8L, 8L, 30L, 0L, 3L, 15L, 29L, 11L, 60L, 15L, 8L,
 60L, 25L, 8L, 9L, 42L, 1L, 50L, 40L, 10L, 60L, 60L, 30L, 10L,
 10L, 0L, 0L, 0L, 2L, 2L, 0L, 

Re: [R] newbie: closing unused connection + readline

2009-05-16 Thread Stavros Macrakis
On Sat, May 16, 2009 at 8:34 AM, Aval Sarri aval.sa...@gmail.com wrote:
 # Create a socket from which to read lines - one at a time (record)
 reader.socket -   socketConnection( host = 'localhost', 5000,
                                     server = TRUE, blocking = TRUE,
                                     open = r, encoding = 
 getOption(encoding) );
 # now read each record and split/validate it using read.table
 repeat {
  # here for each line I am opening new connection! how to avoid it?
  line.raw - textConnection(readLines( reader.socket, n = 1, ok = TRUE));

What is the function of textConnection here?  Is read.table
incompatible with socketConnection for some reason?

  line.raw - read.table(line.raw, sep=,);

 ...at the end of script I am getting closing unused connection warning

This is not a problem in itself.  For some reason, R gives a warning
when connections are garbage collected.  Of course, that can be a
symptom of poor connection management, but not necessarily.

In the present case, you are creating many unnecessary
textConnections, and R correctly garbage collects them.

-s

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


Re: [R] newbie: closing unused connection + readline

2009-05-16 Thread Stavros Macrakis
On Sat, May 16, 2009 at 9:11 AM, Aval Sarri aval.sa...@gmail.com wrote:
 ...I tried something line this also:

 mydataframe - read.table (socket, sep=,);

 but does not work says no input lines.

 this also.

 mydataframe - read.table (readLine(socket), sep=,);

Sorry, I didn't see this before my last email.  This seems to be the
real problem

I don't understand why read.table would have a problem reading
directly from a socket instead of a textConnection.  Is this a bug?
Some subtlety in the semantics of socketConnection as opposed to
textConnection?  Incorrect parameters when opening the
socketConnection?

-s

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


Re: [R] Gamma function

2009-05-16 Thread Stavros Macrakis
What exactly is the R code you wrote for your function f?  Without
that, it will be hard to help you.

 -s

On Sat, May 16, 2009 at 2:48 AM, Kon Knafelman konk2...@hotmail.com wrote:

 Hi Guy,

 I am having trouble graphing the following function

 √2Γ(n/2)/[√n - 1Γ((n - 1)/2 for the values of n between 2 and 50.

 i know that Γ(n) = (n-1)!, which in R is factorial(n-1)

 When i type that into R, using y - function(n).
 and then plot(y,2,50), it doesnt give me anything meaningful, in fact, it 
 comes up with a message saying something like in gamma(n+1) ploted or 
 something along those lines.

 Can anyone please help?

 thanks you

 _
 Looking to change your car this year? Find car news, reviews and more
 http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fsecure%2Dau%2Eimrworldwide%2Ecom%2Fcgi%2Dbin%2Fa%2Fci%5F450304%2Fet%5F2%2Fcg%5F801459%2Fpi%5F1004813%2Fai%5F859641_t=762955845_r=tig_OCT07_m=EXT
[[alternative HTML version deleted]]


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



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


[R] Lattice scales question: using at when log = TRUE

2009-05-16 Thread Afshartous, David

All,

I have a simple lattice plot where I have set log = TRUE for the y scale.

When I attempt to change the tick locations via the at argument within
scales, the supplied numeric vector is not followed. Any suggestions much
appreciated for the example below:

y = c(10^1.5, 10^2, 10^3, 10^2)
t = c(1,2,3,4)
xyplot(y ~ t, type = b, scales = list(y = list(log = TRUE)))

## tick marks not followed for supplied marks below:
xyplot(y ~ t, type = b, scales = list(y = list(log = TRUE), at = c(10^1,
10^2, 10^2.5, 10^3)))

Cheers,
David

PS - 
Another thing is that the scale is no longer in scientific notations, but
that is okay since this can be fixed via the labels argument within scales:
e.g., labels = c(expression(10^1), expression(10^2), ...)
An example of fancy labels for log axes is on p.147 of Deepayan's Lattice
book.

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

2009-05-16 Thread Gilson Sanchez
To whom it concenrt
I am trying to update the R program 2.9
This is the message that the program give is:

 update.packages(ask='graphics')
Warning in install.packages(update[instlib == l, Package], l, contriburl =
contriburl,  :
  'lib = C:/PROGRA~1/R/R-29~1.0/library' is not writable
Erro em install.packages(update[instlib == l, Package], l, contriburl =
contriburl,  :
  unable to install packages

I will wait for answer about this.

Sicerelly

-- 
MSc. Gilson Sánchez Chia
Doutorando do curso Agronomia Tropical - AT
Universidade Federal do Amazonas, UFAM
Av. General Rodrigo Otávio Jordão Ramos 3000
Campus Universitário - Setor Sul, Bloco X. CEP 69077-000
Manaus, Amazonas, Brasil
E-mails:
gilson...@gmail.com
gilson.c...@cpaa.embrapa.br
+92-9170-1825

[[alternative HTML version deleted]]

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


[R] How to save R clean sessions in BATCH mode?

2009-05-16 Thread mcnda839
Thanks a lot for all of you that have reply me about opening and  
ending R workspaces in BATCH mode. However replies were a king general  
and I’m afraid I could not take the entire message from them.  
Therefore I chose to expose here a representative fraction of my work.


I have 50 Rdata files (F1,F2,F3,F4,…,F50) with objects inside.
I need to:

open F1:
   - perform some simple operations with the objects
   - export the solution with write.table
   - end F1 session
open F2
   repeat procedures as F1
…
open F50
   repeat procedures as F1
…

My difficulty here is to end a workspace and open one from the scratch  
to avoid mixing files from consecutive worksessions, and thus using R  
memory unnecessarily. I could use rm() to delete objects from the  
previous sessions but it seems not an efficient task.
Any suggestions on how to perform this in Batch Mode? An examplified  
help would be nice!


Diogo André Alagador
http://www.biochange-lab.eu/people/diogo-alagador
Biodiversity and Global Change Lab, Museo Nacional de Ciencias  
Naturales, CSIC, Madrid, España

Forest Research Centre, Instituto Superior de Agronomia, UTL, Lisboa, Portugal

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

2009-05-16 Thread Gilson Sanchez

  To whom it concenrt
 I am trying to update the R program 2.9
 This is the message that the program give is:

  update.packages(ask='graphics')
 Warning in install.packages(update[instlib == l, Package], l, contriburl
 = contriburl,  :
   'lib = C:/PROGRA~1/R/R-29~1.0/library' is not writable
 Erro em install.packages(update[instlib == l, Package], l, contriburl =
 contriburl,  :
   unable to install packages

 I will wait for answer about this.

 Sicerelly
 --
 MSc. Gilson Sánchez Chia
 Doutorando do curso Agronomia Tropical - AT
 Universidade Federal do Amazonas, UFAM
 Av. General Rodrigo Otávio Jordão Ramos 3000
 Campus Universitário - Setor Sul, Bloco X. CEP 69077-000
 Manaus, Amazonas, Brasil
 E-mails:
 gilson...@gmail.com
 gilson.c...@cpaa.embrapa.br
 +92-9170-1825


[[alternative HTML version deleted]]

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


Re: [R] How to save R clean sessions in BATCH mode?

2009-05-16 Thread Sarah Goslee
Would
rm(list=ls())
not be an easier solution, if I understand your question correctly?

Sarah

On Sat, May 16, 2009 at 11:21 AM,  mcnda...@mncn.csic.es wrote:
 Thanks a lot for all of you that have reply me about opening and ending R
 workspaces in BATCH mode. However replies were a king general and I’m afraid
 I could not take the entire message from them. Therefore I chose to expose
 here a representative fraction of my work.

 I have 50 Rdata files (F1,F2,F3,F4,…,F50) with objects inside.
 I need to:

 open F1:
   - perform some simple operations with the objects
   - export the solution with write.table
   - end F1 session
 open F2
   repeat procedures as F1
 …
 open F50
   repeat procedures as F1
 …

 My difficulty here is to end a workspace and open one from the scratch to
 avoid mixing files from consecutive worksessions, and thus using R memory
 unnecessarily. I could use rm() to delete objects from the previous sessions
 but it seems not an efficient task.
 Any suggestions on how to perform this in Batch Mode? An examplified help
 would be nice!

 Diogo André Alagador
 http://www.biochange-lab.eu/people/diogo-alagador
 Biodiversity and Global Change Lab, Museo Nacional de Ciencias Naturales,
 CSIC, Madrid, España
 Forest Research Centre, Instituto Superior de Agronomia, UTL, Lisboa,
 Portugal

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

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


Re: [R] How to draw a R plot in Java frame ?

2009-05-16 Thread Liviu Andronic
On Sat, May 16, 2009 at 9:18 PM, Obi Wan wan_...@ymail.com wrote:
 I am new to R and would like to display a R plot inside my Java app.

 Is there a possibility to do that? If so, what library do I need?

Perhaps library(JavaGD) is an option. It is currently used in JGR.
Liviu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Lattice scales question: using at when log = TRUE

2009-05-16 Thread Gabor Grothendieck
Your parentheses are wrong.  It should be

y = list(log = TRUE, at = ...)


On Sat, May 16, 2009 at 5:11 PM, Afshartous, David
dafshart...@med.miami.edu wrote:

 All,

 I have a simple lattice plot where I have set log = TRUE for the y scale.

 When I attempt to change the tick locations via the at argument within
 scales, the supplied numeric vector is not followed. Any suggestions much
 appreciated for the example below:

 y = c(10^1.5, 10^2, 10^3, 10^2)
 t = c(1,2,3,4)
 xyplot(y ~ t, type = b, scales = list(y = list(log = TRUE)))

 ## tick marks not followed for supplied marks below:
 xyplot(y ~ t, type = b, scales = list(y = list(log = TRUE), at = c(10^1,
 10^2, 10^2.5, 10^3)))

 Cheers,
 David

 PS -
 Another thing is that the scale is no longer in scientific notations, but
 that is okay since this can be fixed via the labels argument within scales:
 e.g., labels = c(expression(10^1), expression(10^2), ...)
 An example of fancy labels for log axes is on p.147 of Deepayan's Lattice
 book.

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


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


Re: [R] bagged importance estimates in earth problem

2009-05-16 Thread Gavin Simpson
On Sat, 2009-05-16 at 08:57 -0700, Joseph Retzer wrote:
 I was trying to produced bagged importance estimates of attributes in earth 
 using the caret package with the following commands:
 
  fit2 - bagEarth(loyalty ~ ., data=model1, B = 10)
  bagImpGCV - varImp(fit2,value=gcv)
 
 My bootstrap estimates are produced however the second command varImp 
 produces the following error:
 
  Error in UseMethod(varImp) : no applicable method for varImp
 
 Not sure what is going on, any advice would be appreciated,

The example in ?bagEarth works for me with caret and earth loaded

 library(earth)
 data(trees)
 fit1 - earth(trees[,-3], trees[,3])
 fit2 - bagEarth(trees[,-3], trees[,3], B = 10)
 varImp(fit2)
  Overall
Girth  100.00
Height   2.387985

 packageDescription(earth)$Version
[1] 2.3-2
 packageDescription(caret)$Version
[1] 4.15

Have you loaded the relevant packages and are they up-to-date? Can you
run the example above?

If the example works, then you'll probably need to supply data and code
that fails for you or contact the package maintainer for expert help.

HTH

G
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Updating to 2.9 - ' no slot call in the result'

2009-05-16 Thread Raghu Naik
I updated R (to R-patched) and Zelig and the problem went away.

Raghu

[[alternative HTML version deleted]]

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


Re: [R] How to save R clean sessions in BATCH mode?

2009-05-16 Thread Douglas Bates
On Sat, May 16, 2009 at 10:21 AM,  mcnda...@mncn.csic.es wrote:
 Thanks a lot for all of you that have reply me about opening and ending R
 workspaces in BATCH mode. However replies were a king general and I’m afraid
 I could not take the entire message from them. Therefore I chose to expose
 here a representative fraction of my work.

 I have 50 Rdata files (F1,F2,F3,F4,…,F50) with objects inside.
 I need to:

 open F1:
   - perform some simple operations with the objects
   - export the solution with write.table
   - end F1 session
 open F2
   repeat procedures as F1
 …
 open F50
   repeat procedures as F1
 …

 My difficulty here is to end a workspace and open one from the scratch to
 avoid mixing files from consecutive worksessions, and thus using R memory
 unnecessarily. I could use rm() to delete objects from the previous sessions
 but it seems not an efficient task.
 Any suggestions on how to perform this in Batch Mode? An examplified help
 would be nice!
First try either

Rcmd BATCH --help # for Windows

or

R CMD BATCH --help # for Mac OS X or for Linux

and note that there are optional arguments --no-save and --no-restore.
 Use them.

 Diogo André Alagador
 http://www.biochange-lab.eu/people/diogo-alagador
 Biodiversity and Global Change Lab, Museo Nacional de Ciencias Naturales,
 CSIC, Madrid, España
 Forest Research Centre, Instituto Superior de Agronomia, UTL, Lisboa,
 Portugal

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


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


Re: [R] fitdistr for t distribution

2009-05-16 Thread spencerg
 In addition to seeing the code by typing the name of the function 
(and copying it from there into a file), you can also enter 
debug(fitdistr), for example.  Then the next time you use fitdistr, 
either directly  or indirectly, it puts you in the environment of that 
function, and you can walk through it line by line, examining objects, 
changing them, etc. 



 To get the code for an S3 generic function like predict, use the 
methods function, followed, e.g., by getAnywhere. 



 Hope this helps. 
 Spencer Graves


Paul Johnson wrote:

On Fri, May 15, 2009 at 6:22 AM, lagreene lagreene...@gmail.com wrote:
  

Thanks Jorge,

but I still don't understand where they come from.  when I use:
fitdistr(mydata, t, df = 9) and get values for m and s, and the variance
of my data should be the df/s?

I jsut want to be able to confirm how m and s are calculated



I've wondered the same kind of thing and I've learned the answer is
easy!  It is not so easy for all R functions, but did you try this
with fitdistr?

  

library (MASS)
fitdistr



the output that follows is the ACTUAL FORMULA that is used to make the
calculations!

I've not yet mastered the art of getting code for some functions.

  

predict


function (object, ...)
UseMethod(predict)
environment: namespace:stats

But I know there is a way to get that code if you know the correct way
to run getS3method().  But I usually just go read the R source code
rather than puzzle over that.



  

mydt - function(x, m, s, df) dt((x-m)/s, df)/s
fitdistr(x2, mydt, list(m = 0, s = 1), df = 9, lower = c(-Inf, 0))

Thanks anyway for the help!






__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Lattice scales question: using at when log = TRUE

2009-05-16 Thread Afshartous, David


Thanks, but even with typo corrected as below the supplied marks are not 
followed:
xyplot(y ~ t, type = b, scales = list(y = list(log = TRUE, at = c(10^1,10^2, 
10^2.5, 10^3




From: Gabor Grothendieck [ggrothendi...@gmail.com]
Sent: Saturday, May 16, 2009 6:11 PM
To: Afshartous, David
Cc: r-help@r-project.org
Subject: Re: [R] Lattice scales question: using at when log = TRUE

Your parentheses are wrong.  It should be

y = list(log = TRUE, at = ...)


On Sat, May 16, 2009 at 5:11 PM, Afshartous, David
dafshart...@med.miami.edu wrote:

 All,

 I have a simple lattice plot where I have set log = TRUE for the y scale.

 When I attempt to change the tick locations via the at argument within
 scales, the supplied numeric vector is not followed. Any suggestions much
 appreciated for the example below:

 y = c(10^1.5, 10^2, 10^3, 10^2)
 t = c(1,2,3,4)
 xyplot(y ~ t, type = b, scales = list(y = list(log = TRUE)))

 ## tick marks not followed for supplied marks below:
 xyplot(y ~ t, type = b, scales = list(y = list(log = TRUE), at = c(10^1,
 10^2, 10^2.5, 10^3)))

 Cheers,
 David

 PS -
 Another thing is that the scale is no longer in scientific notations, but
 that is okay since this can be fixed via the labels argument within scales:
 e.g., labels = c(expression(10^1), expression(10^2), ...)
 An example of fancy labels for log axes is on p.147 of Deepayan's Lattice
 book.

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


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


Re: [R] Lattice scales question: using at when log = TRUE

2009-05-16 Thread Deepayan Sarkar
On 5/16/09, Afshartous, David dafshart...@med.miami.edu wrote:


  Thanks, but even with typo corrected as below the supplied marks are not 
 followed:
  xyplot(y ~ t, type = b, scales = list(y = list(log = TRUE, at = 
 c(10^1,10^2, 10^2.5, 10^3


How so? Looks OK to me.

-Deepayan




  
  From: Gabor Grothendieck [ggrothendi...@gmail.com]
  Sent: Saturday, May 16, 2009 6:11 PM
  To: Afshartous, David
  Cc: r-help@r-project.org
  Subject: Re: [R] Lattice scales question: using at when log = TRUE


  Your parentheses are wrong.  It should be

  y = list(log = TRUE, at = ...)


  On Sat, May 16, 2009 at 5:11 PM, Afshartous, David
  dafshart...@med.miami.edu wrote:
  
   All,
  
   I have a simple lattice plot where I have set log = TRUE for the y scale.
  
   When I attempt to change the tick locations via the at argument within
   scales, the supplied numeric vector is not followed. Any suggestions much
   appreciated for the example below:
  
   y = c(10^1.5, 10^2, 10^3, 10^2)
   t = c(1,2,3,4)
   xyplot(y ~ t, type = b, scales = list(y = list(log = TRUE)))
  
   ## tick marks not followed for supplied marks below:
   xyplot(y ~ t, type = b, scales = list(y = list(log = TRUE), at = c(10^1,
   10^2, 10^2.5, 10^3)))
  
   Cheers,
   David
  
   PS -
   Another thing is that the scale is no longer in scientific notations, but
   that is okay since this can be fixed via the labels argument within scales:
   e.g., labels = c(expression(10^1), expression(10^2), ...)
   An example of fancy labels for log axes is on p.147 of Deepayan's Lattice
   book.
  
   __
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
  

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


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


Re: [R] Lattice scales question: using at when log = TRUE

2009-05-16 Thread Gabor Grothendieck
It works for me on both of these (Windows Vista):

 R.version.string
[1] R version 2.8.1 Patched (2008-12-26 r47350)
 packageDescription(lattice)$Version
[1] 0.17-22

 R.version.string
[1] R version 2.9.0 Patched (2009-05-03 r48460)
 packageDescription(lattice)$Version
[1] 0.17-22




On Sat, May 16, 2009 at 8:46 PM, Afshartous, David
dafshart...@med.miami.edu wrote:


 Thanks, but even with typo corrected as below the supplied marks are not 
 followed:
 xyplot(y ~ t, type = b, scales = list(y = list(log = TRUE, at = 
 c(10^1,10^2, 10^2.5, 10^3



 
 From: Gabor Grothendieck [ggrothendi...@gmail.com]
 Sent: Saturday, May 16, 2009 6:11 PM
 To: Afshartous, David
 Cc: r-help@r-project.org
 Subject: Re: [R] Lattice scales question: using at when log = TRUE

 Your parentheses are wrong.  It should be

 y = list(log = TRUE, at = ...)


 On Sat, May 16, 2009 at 5:11 PM, Afshartous, David
 dafshart...@med.miami.edu wrote:

 All,

 I have a simple lattice plot where I have set log = TRUE for the y scale.

 When I attempt to change the tick locations via the at argument within
 scales, the supplied numeric vector is not followed. Any suggestions much
 appreciated for the example below:

 y = c(10^1.5, 10^2, 10^3, 10^2)
 t = c(1,2,3,4)
 xyplot(y ~ t, type = b, scales = list(y = list(log = TRUE)))

 ## tick marks not followed for supplied marks below:
 xyplot(y ~ t, type = b, scales = list(y = list(log = TRUE), at = c(10^1,
 10^2, 10^2.5, 10^3)))

 Cheers,
 David

 PS -
 Another thing is that the scale is no longer in scientific notations, but
 that is okay since this can be fixed via the labels argument within scales:
 e.g., labels = c(expression(10^1), expression(10^2), ...)
 An example of fancy labels for log axes is on p.147 of Deepayan's Lattice
 book.

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



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


[R] Newton's method for finding roots

2009-05-16 Thread Kon Knafelman

Hey guys, i have a relatively simple problem.

I need to use netwon's method to find the root of a polynomial, lets say 
x^3-2x-1

i start off with

p - function(x) x^3-2*x-1

My method, which im sure is very amateur, is to type another function, which is 
the derivative of p, and after picking an initial value to start off with, i 
follow the steps of newton's method manually, but i dont think that is what the 
question is asking.

I've done some research on wikipedia, but i cant seem to find any code that 
will help me.

Can someone help?

Thanks a lot

_



[[alternative HTML version deleted]]

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


Re: [R] Using column length in plot gives error

2009-05-16 Thread Stephanie Kovalchik
Is spectra.wavelength a factor? If so, plot will treat it as  
categorical and not draw a line. Try the following modification.


plot(as.numeric(spectra.wavelength), cormat, type = l, ylim=c(-1,1),  
xlab=Wavelength (nm), ylab=Correlation)


Quoting MikSmith m...@hsm.org.uk:



Hi

I'm trying to write a generic script for processing some data which finishes
off with some plots. Given Im never sure how many columns will be in my
dataframe I wanted to using the following

plot(spectra.wavelength, cormat, type = l, ylim=c(-1,1), xlab=Wavelength
(nm), ylab=Correlation)

however even if I specify as type=l it appears plot as points (right hand
plot). If I specify a range such as

plot(650:700, cormat, type = l, ylim=c(-1,1), xlab=Wavelength (nm),
ylab=Correlation)

it looks good (left hand plot). If I try something like:

plot(spectra.wavelength[1]:spectra.wavelength[length(spectra.wavelength)],
cormat, type = l, ylim=c(-1,1), xlab=Wavelength (nm),
ylab=Correlation)

it fails with variable lengths differ and when I look at
spectra.wavelength[1] it gives me the value but then states there are 53
levels.

What does this mean and how can I get the result I want??!

many thanks

mike http://www.nabble.com/file/p23562717/1.pdf 1.pdf
--
View this message in context:   
http://www.nabble.com/Using-column-length-in-plot-gives-error-tp23562717p23562717.html

Sent from the R help mailing list archive at Nabble.com.

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



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


Re: [R] converting numeric to integer

2009-05-16 Thread Linlin Yan
How about ceiling(x), which return the smallest integer not less than x?

On Sun, May 17, 2009 at 2:49 AM, Thomas Mang thomas.m...@fiwi.at wrote:
 Hello,

 Suppose I have x, which is a variable of class numeric. The calculations
 performed to yield x imply that mathematically it should be an integer , but
 due to round-off errors, it might not be (and so in either direction). The
 error is however small, so round(x) will yield the appropriate integer
 value. Moreover, this integer values is guaranteed to be representable by an
 'integer' class, that is -2^31  x  2^31, and logically it is an integer
 anyway. So I want to convert x from class 'numeric' to 'integer'. What is
 the most elegant, but always correct way, to achieve this conversion ?

 What comes to mind is of course something along:

 x = as.integer(round(x))

 I am, however, not sure if this always works, because I do not know if the
 round-function is guaranteed to return a numeric value which, in finite
 binary representation, is always = the underlying mathematical integer. If
 that is however guaranteed, that would of course be a simple + elegant one.

 An alternative I came up with is:

 x = as.integer(round(x) + ifelse(x = 0, 0.5, -0.5))
 Where I explicitly add a bit to ensure the finite binary representation must
 be = the underlying integer, and then truncate the decimal digits.
 IMO, this one is always guaranteed to work, at least within the numerical
 range of what integers are limited to anyway.


 What's your opinion on the issue ?
 Any other solution ?

 Thanks a lot in advance and cheers,
 Thomas

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


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

2009-05-16 Thread Duncan Mackay

Dimitri

You mentioned lattice so I presumed that you tried a barchart in lattice

if you found the class of table.a.percents will it comply with the lattice 
requirements of the data type ?

 class(table.a.percents)
[1] matrix

Using the lattice package and converting to a data.frame
x - data.frame(Group = rep(paste(Group, 1:4), 5), a = 
rep(1:5,each=4),percentage = as.vector(table.a.percents))
 barchart(percentage~a,x,groups = Group, horizontal = F, auto.key = T, 
ylim = c(0,60))


will get you started in lattice, and customize as required
see also ?make.groups

PS ?sweep may be of interest in your data manipulation

Regards

Duncan Mackay
Department of Agronomy and Soil Science
University of New


At 04:57 17/05/2009, you wrote:

Hello!
I promise I looked into help files before asking. Still cannot figure
it out. I think it's because I am totally confused what packages use
lettice, which use trellis, etc.
Sections 1 and 2 below produce the data and the data to plot. My
question is about barplot in Section 3. I am trying to:
1. add only horizontal gridlines and manipulate the type and color of
that line. tck = 1 is not flexible enough to do it.
2. make the legend come on top of gridlines and not under them
3. add plotted Y values above the bars

Thank you very much for any pointers!
Dimitri

### Section 1: generates my data set data:

N-100
myset1-c(1,2,3,4,5)
probs1-c(.05,.10,.15,.40,.30)

group-unlist(lapply(1:4,function(x){
out-rep(x,25)
return(out)
}))
set.seed(1)
a-sample(myset1, N, replace = TRUE,probs1)
a[which(rbinom(100,2,.01)==1)]-NA
set.seed(12)
b-sample(myset1, N, replace = TRUE,probs1)
b[which(rbinom(100,2,.01)==1)]-NA
set.seed(123)
data-data.frame(group,a=a,b=b)
data[group]-lapply(data[group],function(x) {
x[x %in% 1]-Group 1
x[x %in% 2]-Group 2
x[x %in% 3]-Group 3
x[x %in% 4]-Group 4
return(x)
})
data$group-as.factor(data$group)
lapply(data,table,exclude=NULL)

### Section 2. Creating data to plot:
table.a-with(data,table(group,a))
table.a.percents-apply(table.a,2,function(x){
out-round(x*100/sum(x),1)
return(out)
})

### Section 3. Creating a plot:
barplot(table.a.percents,xlab = Values, ylab =
Percentages,ylim=c(0,100),axis.lty=1,legend=T,beside=T,tck = 1)

--
Dimitri Liakhovitski
MarketTools, Inc.
dimitri.liakhovit...@markettools.com

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


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


Re: [R] ggplot2: annotating plot with mathematical formulae

2009-05-16 Thread Paul Emberson
Hi Baptiste,

I think on this occasion I'll edit manually in inkscape with the textext
plugin which is a somewhat clumsy but simple option.  Thanks for the
link to the wiki which I wasn't aware of until now.

Paul

baptiste auguie wrote:
 If you're desperate for a workaround, you might want to try this
 example using pgfSweave,

 http://ggplot2.wik.is/Mathematical_annotations

 On a similar vein, you could try psfrag replacements with a postscript
 device (there is some code for this on the list archives).

 Feel free to comment / edit on the wiki page.

 HTH,

 baptiste

 On 16 May 2009, at 14:48, Paul Emberson wrote:

 Hi Stephen,

 The problem is that the label on the graph doesn't get rendered with a
 superscript.  I want the label on the graph to be rendered the same way
 as the label you have put on the axis.

 I am plotting a piecewise function and I wanted to label each section
 of it.

 Paul

 stephen sefick wrote:
 how about this

 a - 1:10
 b - 1:10
 d - paste(x,^,{n-1})
 qplot(a,b, xlab=expression(x^{n-1}))+geom_text(aes(4,8, label=d))

 On Fri, May 15, 2009 at 10:02 PM, Paul Emberson
 em...@calidasoft.co.uk wrote:

 Hi,

 Is there a way of annotating a ggplot plot with mathematical formulae?

 I can do

 geom_text(aes(label=some text, ...

 but I can't do

 geom_text(aes(label=expression(x^{n-1}), ...

 It gives the error

 Error: geom_text requires the following missing aesthetics: label

 Is there a convenient equivalent?

 Cheers,

 Paul

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







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

 _

 Baptiste Auguié

 School of Physics
 University of Exeter
 Stocker Road,
 Exeter, Devon,
 EX4 4QL, UK

 Phone: +44 1392 264187

 http://newton.ex.ac.uk/research/emag
 __


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] projecting onto 2d *integer* grid?

2009-05-16 Thread haettulegur

I have a bunch of data points in R^2 (Euclidean plane). But I want to project
these onto a 2d integer grid -- that is, there's at most one data point for
each integer (x, y) coordinate, and points near each other in the integer
grid should also be near each other in the original R^2 space.
Is there some method to do this? I'm not necessarily looking for an R
function (though that would be nice).

For example, I tried a kind of simulated annealing approach (basically, I
threw all the data points onto a rectangular integer grid, and tried to
minimize the distances between points), but is there any other method?
I'm not too familiar with self-organizing maps, but would using an SOM with
# of clusters = # of original data points give me what I want?
Any pointers are appreciated!
-- 
View this message in context: 
http://www.nabble.com/projecting-onto-2d-*integer*-grid--tp23579946p23579946.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to turn the xyplot graphics upside-down?

2009-05-16 Thread Ben Bolker



lau kue wrote:
 
 Hi everyone,
 
 I'm learning to use R. The below script works well, but i want to turn the
 y-axis and the graphics upside-down, how should i do? Appreciate if any
 tips!
 
 

Your example isn't reproducible (i.e. we don't have the data), so can't be
sure,
but try giving an explicit ylim argument with low and high limits
reversed.
For example:

 d - data.frame(x=runif(100),y=runif(100))
 xyplot(y~x,data=d)
 xyplot(y~x,data=d,ylim=c(1,0))

or perhaps

 xyplot(y~x,data=d,ylim=rev(range(d$y)))
-- 
View this message in context: 
http://www.nabble.com/How-to-turn-the-xyplot-graphics-upside-down--tp23571346p23579970.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Row number of minimum value?

2009-05-16 Thread Ben Bolker



MikSmith wrote:
 
 This *must* be an insanely easy thing to work out, but I'm not too
 familiar with R syntax. So how do I work out the row number (if I pass a
 column) of the minimum value?? I can get the value itself from min(), but
 where can I get the row??
 

?which
?which.min

 Ben Bolker

-- 
View this message in context: 
http://www.nabble.com/Row-number-of-minimum-value--tp23578215p23579979.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] wireframe 3-D problems

2009-05-16 Thread Xu Jun
Dear All R Users,

I am trying to graph a 3-D graph of simulated data for logit models using
the powerful wireframe command, but I got stuck. Here are the codes:

x - seq(-4, 4, by=0.01)
 y - seq(-4, 4, by=0.01)
 p - 1/(1+exp(-0.12*x + 0.35*y))
 mydata - cbind(x, y, p)
 require(lattice)
 wireframe(p~x*y, data=mydata)

 and I received the following message:

Error in eval(substitute(groups), data, environment(formula)) :
  numeric 'envir' arg not of length one

Can anyone here point me to the right direction? Thanks!

Jun Xu, PhD
Assistant Professor
Department of Sociology
Ball State University

[[alternative HTML version deleted]]

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