Re: [R] Creating a loop with an indefinite end term

2012-04-10 Thread Charilaos Skiadas

On Apr 10, 2012, at 1:08 PM, Steve Lavrenz wrote:

I definitely need a loop - the example I gave was only a simple  
one. Say I
want to do more complex calculations in each step, such that the  
numeric

difference between consecutive terms is not constant.



I will try out some of the methods that have been shared so far.  
Thank you!




One thing to keep in mind is that, R is pretty darn well optimized  
for doing vector calculations. Depending on your problem, it might be  
worth it to just compute a lot more steps if you can do it in a  
vectorized form avoiding a loop, then do something like

x[x100]
to only pick out the values that are less than 100. So I think you  
should ask yourself if you really really need to stop the loop at  
that point. Not knowing more details about the actual problem you are  
trying to solve, I can't answer that, but in general in R if you can  
do something without loops and using vectorization instead, then that  
is the R way to do it. But it really depends on the particular  
problem whether that is doable or not.


If you do indeed need to use a loop, it would probably help indeed  
not have to constantly change the size of the vector, as Drew points  
out. If you know a reasonable upper bound for how many terms will be  
needed, reserve that many. If not, maybe you could reserve them in  
chunks of say 100; so start with a vector of size 100, and if you  
fill that up during the loop add another 100 etc.



-Steve


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College





From: Jean V Adams [mailto:jvad...@usgs.gov]
Sent: Tuesday, April 10, 2012 12:38 PM
To: Steve Lavrenz
Cc: r-help@r-project.org
Subject: Re: [R] Creating a loop with an indefinite end term




Do you need a loop at all?

Will this do the trick?

seq(from=0, to=100, by=5)

Jean


Steve Lavrenz wrote on 04/10/2012 09:48:34 AM:


Everyone,

I'm very new to R, especially when it comes to loops and  
functions, so
please bear with me if this is an elementary question. I cannot  
seem to
figure out how to construct a loop which runs a function until a  
certain

value is computed. For example, say I have the following:

num = numeric (10)
num [1] = 0
for (i in 2:10)   {
  num [i] = num [i-1] + 5
}

This adds 5 to the preceding spot of a vector of length 10 to get the

value
in the current spot. However, say I don't just want to run this  
for 10

spots; rather I want to run it until a certain value (say, 100) is

computed.

How I construct my loop to do this?

Thanks!




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


Re: [R] lattice panel question

2008-10-14 Thread Charilaos Skiadas

http://lmdvr.r-forge.r-project.org/figures/figures.html

Look at Figure 10.24 and the code therein. You will likely want to  
define your own strip function, and the code in strip.combined could  
be your guide. If you have Deepayan's book, you can find more details  
in the relevant section.



Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Oct 13, 2008, at 7:43 PM, Ferry wrote:


Dear R users,

How to change lattice panel label/text from the automatically  
generated

label (based on the conditioning) to our own set of label?

for example:

someStuff - data.frame(area = rep(c(SOUTH, NORTH, EAST,  
WEST), each

= 25),
group = rep(c(A,B,C,D), each = 5),
mytime = rep(1:4),
val1 = sample(1:100, size=100, replace=TRUE),
val2 = sample(1:100, size=100, replace=TRUE)
)

xyplot(val1+val2 ~ mytime | area * group, data = someStuff, type = c 
(a,

p, g))

I want to change each panel label/text from for example D/East or D/ 
North

... into Deriv/From East, Deriv/From North ...

I know I could change from the data, but is there a way to change  
it from

lattice ?

thanks beforehand.




__
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] Turn factors to numeric

2008-10-09 Thread Charilaos Skiadas

R-FAQ 7.10:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors- 
to-numeric_003f


On Oct 9, 2008, at 6:59 AM, joseph kambeitz wrote:


I am having some problems while trying to fit simple data.
I aggregated some data using:
data1 - aggregate(data1$T2, list=(SOA=data1$SOA), mean)

unfortunatly this coerces my variable SOA into a factor. Therefore  
when a afterwards try to fit a simple equation to my variable T2  
using a formula on SOA i get a error because SOA is a factor and  
that * is not meaningful for factors...


nls(T2 ~ a + b*SOA, start=list(a=1,b=1), data=data1, trace=TRUE)

In fact SOA is a numeric variable (in my experiments it is the time  
that passed!) so i would like to re-coerce it into a numeric  
variable to do the fit or to find a method to do the fit even  
though SOA is a factor. Thanks a lot for your help!


Best
Jokel
--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten

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


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Dot plot - equivalent of MINITAB

2008-09-25 Thread Charilaos Skiadas
I think the problem is that what you describe is not what some  
people, R folks included, refer to as dotplot, though I suppose  
wikipedia as well as some other top google links seem to agree with  
you and minitab. What you describe I think can be obtained with  
something like:


x- c(6,6,4,4,4,4,2,2,2,2,2,10)
cnt - table(x)
xs - rep(as.numeric(names(cnt)), cnt)
ys - do.call(c, sapply(cnt, function(x) 1:x))
plot(xs,ys, pch=19, ylim=c(0,10))

The R-dotplot you can think of, if you want, as a replacement of a  
barchart, which replaces the entire bar with a single dot where the  
bar would end. It can also be used when the scale you are using has  
nothing to do with counts, and doesn't even have to start from 0. But  
I am far from an expert, and I am sure/hope a bunch of people will  
jump in to correct me.


There are surely other descriptions of dotplots, but you could start  
with these:


http://www.processtrends.com/pg_charts_dot_plots.htm
http://www.b-eye-network.com/view/2468

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Sep 25, 2008, at 3:51 PM, kerfuffle wrote:



hi folks,

Bit of a newbie, but I've spent a fair bit of time looking for an  
answer on

this, with no joy.  Can anyone help me?

Dataset: A single column of values in a csv file (eg. 52, 53, 54,  
85, etc)


Goal: In Minitab, you have what they call a dot plot.  It's a  
histogram,
where a single dot represents a set of identical values (eg. 57,  
57, 57
would be one dot).   Multiple dots are stacked on top of each other  
(as if
gravity was affecting them). The advantage is that outliers are  
very visible
(since a single 155 still gets a single dot).  The net effect is a  
rug plot,

but in the main portion of the plot, not just on the axis.

Tried: I've played with dotchart and dotchart2 with no joy (eg.
dotchart(nc$bac) (where nc is the dataset and bac is the column  
header).
They do provide multiple dots (so that ten values of 57 are given 3  
dots)
but these overlap and aren't arranged in a logical way.  Sometimes  
a single

dot has a large y-value, sometimes it isn't.  As a result of this
non-gravitational effect, it doesn't look like a histogram at all.   
It's
also strange that the background of the plot is stripy.  This  
implies I'm
doing something very wrong, but don't know what.  I had a look at  
the plot

galleries, and didn't see anything else that looked like what I wanted
(except the rug plots).

thanks! (and apologies if I've missed something blatant)

Paul
--
View this message in context: http://www.nabble.com/Dot-plot--- 
equivalent-of-MINITAB-tp19677009p19677009.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] paste in xtable

2008-09-23 Thread Charilaos Skiadas
Actually the '\\textbf' specification would work just fine. If you  
examine test[,1] you'll see it contains the correct thing. The  
problem is when print.xtable is called. This is because it  
automatically contains a function that sanitizes the character  
entries to fix characters that have a special meaning in latex.  
Hence \\textbf becomes $\backslash$textbf. The following should work:


test= matrix(1:4, nrow=2,ncol=2)
test = xtable(test)
test[,1] = ifelse(test[,1]1,paste('\\textbf{',test[,1],'}'),test[,1])
print(test, sanitize.text.function=I)

The last command sets the sanitize function to do effectively do  
nothing and simply return the string. Hope this helps.


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Sep 23, 2008, at 8:13 PM, Ryan D. Enos wrote:


Dear R help:
I am trying to use paste(), within an ifelse() statement to insert  
latex commands into an object that has been created using xtable 
().  I cannot make the strings behave as I would like, the '\t' is  
creating a tab, the usual method of '\\t' is not working either -  
nor is any series of backslashes.  The xtable object, I think,  
automatically alters the strings.  How can I insert the literal  
'\textbf' into my xtable object?  Any help would be appreciated.   
Code examples below.

Ryan

example 1:

 test= matrix(1:4, nrow=2,ncol=2)
 test = xtable(test)
 test[,1] = ifelse(test[,1]1,paste('\textbf{',test[,1],'}'),test[, 
1])

 test
% latex table generated in R 2.5.1 by xtable 1.5-1 package
% Tue Sep 23 17:08:18 2008
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrr}
 \hline
 1  2 \\
 \hline
1  13 \\
 2extbf\{ 2 \}4 \\
  \hline
\end{tabular}
\end{center}
\end{table}

example 2:

 test= matrix(1:4, nrow=2,ncol=2)
 test = xtable(test)
 test[,1] = ifelse(test[,1]1,paste('\\textbf{',test[,1],'}'),test 
[,1])

 test
% latex table generated in R 2.5.1 by xtable 1.5-1 package
% Tue Sep 23 17:11:56 2008
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrr}
 \hline
 1  2 \\
 \hline
1  13 \\
 2  $\backslash$textbf\{ 2 \}4 \\
  \hline
\end{tabular}
\end{center}
\end{table}


--
Ryan D. Enos

Department of Political Science
UCLA

http://renos.bol.ucla.edu/

__
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] Compiling date

2008-09-10 Thread Charilaos Skiadas
So, am I correct that each datum is either of the form mm/dd/yy or  
of the form dd/mm/? If that is correct, then the following  
should work, and takes care of converting 99 to 1999 instead of 2099:


dates - c(06/15/07,04/09/99,20/03/2008)
short - grep(\\d\\d/\\d\\d/\\d\\d$, dates, perl=TRUE)
dates[short] - format(strptime(dates[short], format=%m/%d/%y),  
format=%d/%m/%Y)


Or Henrique's suggestion, slightly modified:

strptime(dates, ifelse(nchar(dates) == 8, '%m/%d/%y', '%d/%m/%Y'))

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Sep 10, 2008, at 7:40 AM, Megh Dal wrote:

It is a mixture of both. The data is so notorious excel cant format  
properly. Therefore I thought whether R can do something otherwise  
I have to do manually.



--- On Tue, 9/9/08, Dr Eberhard W Lisse [EMAIL PROTECTED] wrote:


From: Dr Eberhard W Lisse [EMAIL PROTECTED]
Subject: Re: [R] Compiling date
To: David Scott [EMAIL PROTECTED]
Cc: Dr Eberhard W Lisse [EMAIL PROTECTED], Megh Dal  
[EMAIL PROTECTED], [EMAIL PROTECTED]

Date: Tuesday, September 9, 2008, 11:37 PM
Is this Month-Day or Day-Month or a mixture of both?

I still think using the Format - Cell - Date will
work
much better...

el


On 09 Sep 2008, at 11:21 , David Scott wrote:


On Mon, 8 Sep 2008, Megh Dal wrote:


Hi,

I have following kind of dataset (all are dates)

in my Excel sheet.


09/08/08
09/05/08
09/04/08
09/02/08
09/01/08
29/08/2008
28/08/2008
27/08/2008
26/08/2008
25/08/2008
22/08/2008
21/08/2008
20/08/2008
18/08/2008
14/08/2008
13/08/2008
08/12/08
08/11/08
08/08/08
08/07/08

However I want to use R to compile those data to

make all dates in

same format. Can anyone please tell me any

automated way for doing

that?



Well you have to read them in as character first. Then

use sub to

make the two digit years into four digits. The

following could

probably be improved by a regular expression whiz, but

works:



strngs -

c(06/05/08,23/11/2008)



sub(([0-9][0-9]/[0-9][0-9]/)([0-9][0-9]$),\\120\\2,strngs)

[1] 06/05/2008 23/11/2008


David Scott




__
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] match problem by rownames

2008-09-09 Thread Charilaos Skiadas

As suggested in ?[.data.frame, try:

dat[match('a1', rownames(dat)),]


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Sep 9, 2008, at 2:41 AM, Xianming Wei wrote:


Hi all,

While dat['a1',] and dat['a10',] produce the same results in the
following example, I'd like dat['a1',] to return NAs.

dat - data.frame(x1 = paste(letters[1:5],10, sep=''), x2=rnorm(5))
rownames(dat) - dat$x1
dat['a1',]
dat['a10',]


sessionInfo()

R version 2.7.2 (2008-08-25)
i386-pc-mingw32

locale:
LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia. 
1252;LC_MON
ETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia. 
1252


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


other attached packages:
[1] lattice_0.17-13

loaded via a namespace (and not attached):
[1] grid_2.7.2




Regards,
Xianming



__
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] license for a university

2008-09-03 Thread Charilaos Skiadas

Try: license()

On Sep 3, 2008, at 6:59 PM, Erin Hodgess wrote:


Dear R People:

I am trying to install R in a classroom here, but have been told that
there must be a license.

Is there such a thing with R, please?  Since it is free, I assumed
that there would be no license.

Thanks for any help,
Sincerely,
Erin


--  
Erin Hodgess

Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: [EMAIL PROTECTED]

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


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Parenthesis recognition with grep

2008-08-31 Thread Charilaos Skiadas

Try:

myStr - YD\\(001\\)

In POSIX format, or in most such formats in fact, special characters  
like parentheses have a particular meaning, and need to be escaped if  
they are to have the parenthesis meaning. This is done typically by  
putting a backslash in front of them. Since however a backslash has a  
special meaning inside a ..., namely it is use to escape things,  
we need to escape it, hence the two backslashes you see back to back.  
You can use:


cat(myStr)

To see what hte string actually has in it.

A better way to solve your problem in your case is to use the  
original myStr you had, but change the grep call to be:


grep(myStr, headers, fixed=TRUE)


The fixed=TRUE part tells it to treat myStr as a string to be matched  
exactly. Of course ?grep should probably have led you to this.



Haris Skiadas
Department of Mathematics and Computer Science
Hanover College


On Aug 31, 2008, at 10:54 AM, Sébastien wrote:


Hi Jorge,

This is doing the work just fine. Thank you !
However, I would like to know what should be done with the grep  
call...

just for my personal education :)

Sebastien

Jorge Ivan Velez a écrit :


Dear Sébastien,

Is this what you want?

which(myStr==headers)
[1]  2

which(headers%in%myStr)
[1] 2


HTH,

Jorge



On Sun, Aug 31, 2008 at 10:28 AM, Sébastien [EMAIL PROTECTED]
mailto:[EMAIL PROTECTED] wrote:

Dear R-users,

I need to dynamically recognize the index of a given string myStr
in a vector of string. The problem is that myStr might contain
parenthesis, causing grep not to recognize it the way I want (see
below). The help mentions that the pattern used by grep should be
in the POSIX format... I guess the problem is here;  
unfortunately,

I am not familiar with the subtleties of the POSIX format

ex:
myStr - YD(001)
headers -c(TD, YD(001), YD(002), T, Y(001), Y(002))
grep(myStr, headers)

How should I modify my grep call to get the match right?

Thank you for your help,

Sebastien



__
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] Upgrading R means I lose my packages

2008-08-27 Thread Charilaos Skiadas

On Aug 27, 2008, at 10:40 PM, Rolf Turner wrote:



On 28/08/2008, at 2:02 PM, James Milks wrote:

The title says it all.  Does anyone know of a way to save your  
packages when you upgrade to a new version of R?  This may seem  
petty, but I'm accumulating enough packages that having to  
download and install each of them anew every time I install a new  
version of R is rather of a pain.  Ideally, I would like the new  
version of R to recognize the packages I've installed on the  
previous version without needing to reinstall the packages.  Is  
that possible?


My system: Mac OS 10.5.4.
Current R version: 2.7.1


Mac OS moves in mysterious ways, but apparently your installation  
moves in more mysterious

ways than most.

I also (by necessity, not by choice) run Mac OS.  But I certainly  
don't lose my
packages when I update R.  The new version of R certainly  
``recognizes'' the packages

that I have installed.  No action required.

There may be something funny about *where* you have your packages  
installed, and

what environment variables you have set.

To answer your question ``Is that possible?'' --- Yes.  Not just  
possible,
but universal.  Except, it would seem, in your case.  What have you  
done

to offend the gods? :-)



Actually have had the same problem as James. By default, unless I'm  
mistaken, R will save installed packages within the R.framework  
framework (system-wide installation). This framework gets completely  
replaced when a new version is installed. In my system, the location  
of these packages is:

/Library/Frameworks/R.framework/Resources/library

So unless I am mistaken you have to take some action to prevent  
packages from being installed there. I do hope I am wrong.



cheers,

Rolf Turner




Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] keywords

2008-07-29 Thread Charilaos Skiadas

On Jul 29, 2008, at 5:24 AM, Edna Bell wrote:


Hi R Gurus!

When you build a package, you need to put in keywords in the Rd files.

Where would you find the list of keywords, please?


Simplest way is to google for r keywords. First hit is:

http://www.stat.ucl.ac.be/ISdidactique/Rhelp/doc/keywords.html

Also, if you do help.start() and follow the link Search Engine   
Keywords, you will find the list.



TIA,
Edna Bell


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] include S4 class and methods in a package

2008-06-28 Thread Charilaos Skiadas

On Jun 27, 2008, at 1:44 PM, baptiste Auguié wrote:


DeaR list,


Pardon the stupidity of this question but I've been trying this for  
a while now without success.


I've followed the example given in the green book programming with  
data, and I now have a working example of a S4 class with a few  
methods (plot, summary, as.data.frame). It's all very nice in one  
file, but I cannot find the way to put this information in a  
package. I've created several simple packages (without S4 classes)  
in the past using package.skeleton and manual editing / adding of  
some files.
The question I have now is where do the setClass and setMethod live  
in the folder tree? I sort of believe they should be defined in a  
source file in the sub-directory R/, but is there a special name to  
give to these files, how do they get recognised during installation  
or build?


I've tried to find the answer in writing R extensions but I must  
have missed the relevant section.


I don't think there's any particular name needed for the file. I had  
a look at Matrix for an example when I was writing an S4 package, and  
kind of followed what they were doing. In my example, I had one file  
that had all the setGeneric calls, and another one named after my S4  
class containing setClass and setMethod. And then you need to work on  
the NAMESPACE file. I think to some extent this is described in  
1.6.6 Name spaces with formal classes and methods.


Hopefully someone more experienced than me can offer a more  
authoritative answer.



Many thanks,

Sincerely,

Baptiste


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

PS: I'm not sure a minimal example is relevant, I could provide one  
if requested.


OS is MacOS 10.4,
 sessionInfo()
R version 2.7.0 RC (2008-04-21 r45421)
powerpc-apple-darwin8.10.1

locale:
en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] datasets  utils stats graphics  grDevices splines
grid  methods   base



_

Baptiste Auguié

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

Phone: +44 1392 264187

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



__
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] Editor for Mac OSX

2008-06-18 Thread Charilaos Skiadas
One more advantage of TextMate is support for Sweave files. You can  
have a Sweave file open, and the LaTeX parts of it are syntax colored  
according to LaTeX and one can use all the facilities of the LaTeX  
extension (bundle) in LaTeX (which probably has some things similar  
to AucTeX, has a number of other features and perhaps misses some  
features, I'm not too familiar with AucTeX to do a definitive  
comparison), while on the other hand the R parts are colored  
according to the R syntax and one can use all the goodies of the R  
bundles that Hans-Jörg describes below.


It does have the disadvantage of not being free, but personally it's  
the best $60 I've ever spent. There's a 30-day fully functional free  
trial period.


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Jun 18, 2008, at 1:54 PM, Hans-Jörg Bibiko wrote:



On 18.06.2008, at 18:09, Graham Smith wrote:


Have a look at TextMate  http://macromates.com/


There are three extensions (bundles) available dealing with R for  
TextMate [up to now in the Review repository]:

[in very short terms]
1) R
- writing R scripts and executing it (plots are inside as pdfs  
available)

- one can execute more than one R script
- fast syntax highlighting, snippets (macros) for fast writing etc.
- command completion
- GUI for inserting function parameters
- displaying the command signature
- tidy function
- drag'n'drop facilities (drag a csv to the window it inserts  
read.csv('filename'))



2) R Console (R.app)
- to remote R.app via AppleScript but with all goodies of TextMate


3) R Console (Rdaemon) - an ESS-like extension
- R runs hidden inside of TextMate
- it combines a text editor and the R console in a sophisticated way
- easy to expandably
- many GUI-like elements (Graphics/Package Manager ...)
- only written in scripting languages
- crash safer - if R/TextMate/Mac crashes one has at least the  
entire last session as text file to reconstruct



and many many many more

If you want to know more let it me know.

--Hans



2008/6/18 Sebastian Leuzinger [EMAIL PROTECTED]:


Dear R-list
I am (forced) to change from Linux to Mac and am now looking for  
a new
editor for R. I would like one that features a split window  
(console +
editor) as well as syntax highlighting. Can anyone help?  
Especially the
split-window feature does not seem to be easily available in the  
editors
desribed on the R-help site, except Emacs, which I am reluctant  
to start

using.


__
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] Reshape or Stack? (To produce output as columns)

2008-06-17 Thread Charilaos Skiadas

On Jun 17, 2008, at 8:06 AM, Chuck Cleland wrote:


On 6/17/2008 6:59 AM, Steve Murray wrote:

Dear all,
I have used 'read.table' to create a data frame of 720 columns and  
360 rows (and assigned this to 'Jan'). The row and column names  
are numeric:
columnnames - sprintf(%.2f, seq(from = -179.75, to = 179.75,  
length = 720)). rnames - sprintf(%.2f, seq(from = -89.75, to =  
89.75, length = 360))

colnames(Jan) - columnnames
rownames(Jan) - rnames

A sample of the data looks like this:

head(Jan)
   -179.75 -179.25 -178.75 -178.25 -177.75 -177.25 -176.75  
-176.25 -175.75
-89.75   -56.9   -64.256.2   -90.056.9   -29.0   -91.0
34.0 -9.1
-89.2537.919.3 -0.4   -12.3   -11.8   -92.1 9.2
-23.5 -0.2
-88.7547.4  3.1   -47.446.434.2  6.1
-41.344.7   -10.3
-88.25   -20.334.5   -67.3   -99.937.9 -9.317.7
-17.263.4
-87.75   -46.447.412.4   -48.3  9.3   -33.838.1 
10.8   -34.1
-87.25   -48.410.3   -89.3   -33.0 -1.1   -33.181.2 
-8.3   -47.2
I'm hoping to get the whole dataset into the form of columns, so  
that, for example, the first row (as shown above) would look like  
this:

Latitude   Longitude   Value
-89.75  -179.75 -56.9
-89.75  -179.25 -64.2
-89.75  -178.75  56.2
-89.75  -178.25 -90.0
-89.75  -177.75  56.9
-89.75  -177.25 -29.0
-89.75  -176.75 -91.0
-89.75  -176.25  34.0
-89.75  -175.75  -9.1
As you can see, this would require the repeated printing of the  
the row and column names (in this case '-89.75') - so it's not  
just a case of rearranging the data, but creating 'more' data too.
I've tried to achieve this using 'reshape' and 'stack' (their help  
files and after looking through the mailing archives), but I'm  
obviously doing something wrong. For reshape, I'm getting errors  
relating to the commands I enter, and for stack, I can only  
produce two columns from my data (with the additional 3rd column  
being a row count). In any case, these two columns refer to the  
wrong values (it's producing output in the form of: row count  
number, Longitude, Value).
I'd be very grateful if anyone could help me out with the commands  
I need to enter in order to achieve the results I'm hoping for.


  Here is an approach with reshape() on a much smaller example:

columnnames - sprintf(%.2f, seq(from = -179.75, to = 179.75,  
length = 5))


rnames - sprintf(%.2f, seq(from = - 89.75, to =  89.75, length =  
3))


Jan - as.data.frame(matrix(runif(3*5), ncol=5))

colnames(Jan) - columnnames
rownames(Jan) - rnames

Jan$Latitude - rownames(Jan)

Jan.long - reshape(Jan, idvar=Latitude, direction=long,
varying = list(columnnames),
v.names=Value,
timevar=Longitude,
times=columnnames)

Jan.long[] - sapply(Jan.long, as.numeric)


Here's another approach, using Chuck's example. I have two methods,  
one produces a data frame, the other produces a matrix. It's up to  
you. In the data frame example the first two columns are actually  
factors, in the matrix they are numeric vectors. The other key  
difference is that I start from a matrix, and I simply use the fact  
that a matrix is just a vector with a dim attribute (and I use  
as.numeric to drop the dim argument).


Jan - matrix(runif(3*5), ncol=5)
Jan.long - data.frame(Latitude=rep(rownames(Jan), ncol(Jan)),  
Longitute=rep(colnames(Jan), each=nrow(Jan)), Value=as.numeric(Jan))


Jan.long - cbind(Latitude=rep(as.numeric(rownames(Jan)), ncol(Jan)),  
Longitute=rep(as.numeric(colnames(Jan)), each=nrow(Jan)),  
Value=as.numeric(Jan))


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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: Superpose bwplot on dotplot [Newbie Question]

2008-06-16 Thread Charilaos Skiadas

On Jun 16, 2008, at 12:13 PM, Lord Yo wrote:



Hello everyone

I have dataset containing a monetary value (ABS) and two factors (Fct,
Group).  I am able to create useful using:

bwplot(ABS~Group|Fct)
and
dotplot(ABS~Group|Fct)

Question: What do I have to do to overlay the dotplot with the  
bwplot (same

data set)?

I've found a couple of posts that hinted at the possibility of  
doing that,
and checked the panel.superpose() help, but the info was too  
complex for my

newbie brain.


Try this:

bwplot(ABS~Group|Fct, panel=function(...) {panel.bwplot(...);  
panel.dotplot(...)} )


There are probably others, perhaps better, ways.


Thanks for your help!
LY


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Subset by Factor by date

2008-06-14 Thread Charilaos Skiadas

On Jun 14, 2008, at 2:59 AM, T.D.Rudolph wrote:



I can't speak to the intricacies of the formula but when I run the
ByDataFrame() function provided on a subsample of my data (n=50) it  
returned
only the very first id value in the output; the rest came out as  
NA
This is not to say it has not properly selected the rows with min(x 
$diff),
but I have no way of verifying without the id membership in the  
output.


And equally we can't help you with that without a reproducible  
example. Doesn't it do the right thing in the little sample I posted?  
It moves the id and day columns to the end. Without that, the only  
thing I can think of that might cause trouble is that you have a  
matrix instead of a data.frame, or otherwise the columns have some  
class I have not anticipated. Perhaps you can send me a part of your  
data off-list, if you can't post it here?


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College


Charilaos Skiadas-3 wrote:



On Jun 14, 2008, at 1:25 AM, T.D.Rudolph wrote:



aggregate() is indeed a useful function in this case, but it only
returns the
columns by which it was grouped.  Is there a way I can use this  
while
simultaneously retaining all the other column values in the  
dataframe?


e.g. add superfluous (yet pertinent for later) column containing any
information at all and retain it in the final output


I had exactly this kind of need many times, and I have finally
created a function for it, which I hope to include soon in an
upcoming package. Here is a run of it (I added an extra A column
containing just the numbers 1:8):


DF

   id  day diff A
1  1 01-01-09  0.5 1
2  1 01-01-09  0.7 2
3  2 01-01-09  0.2 3
4  2 01-01-09  0.4 4
5  1 01-02-09  0.1 5
6  1 01-02-09  0.3 6
7  2 01-02-09  0.3 7
8  2 01-02-09  0.4 8

byDataFrame(DF, list(id, day), function(x) x[which.min(x$diff),])

   diff A id  day
1  0.5 1  1 01-01-09
2  0.2 3  2 01-01-09
3  0.1 5  1 01-02-09
4  0.3 7  2 01-02-09

Would that do what you want?

I've appended the function byDataFrame, and its prerequisite, a
function parseIndexList. I'm not quite set on the names yet, but
anyway. Hope this helps. I haven't really tested it on large sets, it
might perform poorly. Any suggestions on speeding the code /
corrections are welcome.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College



parseIndexList - function(indexList) {
   # browser()
   if (!is.list(indexList))
 indexList - as.list(indexList)
   nI - length(indexList)
   namelist - vector(list, nI)
   names(namelist) - names(indexList)
   extent - integer(nI)
   nx - length(indexList[[1]])
   one - as.integer(1)
   group - rep.int(one, nx)
   ngroup - one
   for (i in seq.int(indexList)) {
   index - as.factor(indexList[[i]])
   if (length(index) != nx)
   stop(arguments must have same length)
   namelist[[i]] - sort(unique(indexList[[i]]))
   extent[i] - length(namelist[[i]])
   group - group + ngroup * (as.integer(index) - one)
   ngroup - ngroup * nlevels(index)
   }
   nms - do.call(expand.grid, namelist)
   ind - unique(sort(group))
   res - data.frame(index=ind, nms[ind, , drop=FALSE])
   return(list(cases=group, groups=res))
}

byDataFrame - function (data, INDEX, FUN, newnames,
omit.index.cols=TRUE, ...) {
# # Part of the code shamelessly stolen from tapply
   IND - eval(substitute(INDEX), data)
   nms - as.character(as.list(substitute(INDEX)))
   if (!is.list(IND)) {
 IND - list(IND)
 names(IND) - nms
   } else {
 names(IND) - nms[-1]
   }
   funname - paste(as.character(substitute(FUN)), collapse=.)
   indexInfo - parseIndexList(IND)
   FUNx - if (omit.index.cols) {
 omit.cols - match(names(indexInfo$groups)[-1], names(data))
 function(x, ...) FUN(data[x, -omit.cols], ...)
   } else {
 function(x, ...) FUN(data[x, ], ...)
   }
   ans - lapply(split(1:nrow(data), indexInfo$cases), FUNx, ...)
   index - as.numeric(names(ans))
   if (!is.data.frame(ans[[1]])) {
 ans - lapply(ans, function(x) {
   dframe - as.data.frame(t(x))
   if (is.null(names(x)))
 names(dframe) - funname
   dframe
 })
   }
   lengths - sapply(ans, nrow)
   ans - do.call(rbind, ans)
   if (!missing(newnames))
 names(ans) - newnames
   nms - indexInfo$groups[rep(index, lengths),-1, drop=FALSE]
   res - cbind(ans, nms)
   res
}


__
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] Rest of a division

2008-06-13 Thread Charilaos Skiadas

?%%

On Jun 13, 2008, at 11:23 AM, Eric Ferreira wrote:


Dear useRs,

How do I ask for the rest of a division?

For instantce, in C is like:

4%2 = 0

Best regards,

--
Eric B Ferreira
Exact Sciences Department
Federal University of Lavras
Brasil



Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Subset by Factor by date

2008-06-13 Thread Charilaos Skiadas


On Jun 14, 2008, at 1:25 AM, T.D.Rudolph wrote:



aggregate() is indeed a useful function in this case, but it only  
returns the

columns by which it was grouped.  Is there a way I can use this while
simultaneously retaining all the other column values in the dataframe?

e.g. add superfluous (yet pertinent for later) column containing any
information at all and retain it in the final output


I had exactly this kind of need many times, and I have finally  
created a function for it, which I hope to include soon in an  
upcoming package. Here is a run of it (I added an extra A column  
containing just the numbers 1:8):


 DF
  id  day diff A
1  1 01-01-09  0.5 1
2  1 01-01-09  0.7 2
3  2 01-01-09  0.2 3
4  2 01-01-09  0.4 4
5  1 01-02-09  0.1 5
6  1 01-02-09  0.3 6
7  2 01-02-09  0.3 7
8  2 01-02-09  0.4 8
 byDataFrame(DF, list(id, day), function(x) x[which.min(x$diff),])
  diff A id  day
1  0.5 1  1 01-01-09
2  0.2 3  2 01-01-09
3  0.1 5  1 01-02-09
4  0.3 7  2 01-02-09

Would that do what you want?

I've appended the function byDataFrame, and its prerequisite, a  
function parseIndexList. I'm not quite set on the names yet, but  
anyway. Hope this helps. I haven't really tested it on large sets, it  
might perform poorly. Any suggestions on speeding the code /  
corrections are welcome.


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College



parseIndexList - function(indexList) {
  # browser()
  if (!is.list(indexList))
indexList - as.list(indexList)
  nI - length(indexList)
  namelist - vector(list, nI)
  names(namelist) - names(indexList)
  extent - integer(nI)
  nx - length(indexList[[1]])
  one - as.integer(1)
  group - rep.int(one, nx)
  ngroup - one
  for (i in seq.int(indexList)) {
  index - as.factor(indexList[[i]])
  if (length(index) != nx)
  stop(arguments must have same length)
  namelist[[i]] - sort(unique(indexList[[i]]))
  extent[i] - length(namelist[[i]])
  group - group + ngroup * (as.integer(index) - one)
  ngroup - ngroup * nlevels(index)
  }
  nms - do.call(expand.grid, namelist)
  ind - unique(sort(group))
  res - data.frame(index=ind, nms[ind, , drop=FALSE])
  return(list(cases=group, groups=res))
}

byDataFrame - function (data, INDEX, FUN, newnames,  
omit.index.cols=TRUE, ...) {

# # Part of the code shamelessly stolen from tapply
  IND - eval(substitute(INDEX), data)
  nms - as.character(as.list(substitute(INDEX)))
  if (!is.list(IND)) {
IND - list(IND)
names(IND) - nms
  } else {
names(IND) - nms[-1]
  }
  funname - paste(as.character(substitute(FUN)), collapse=.)
  indexInfo - parseIndexList(IND)
  FUNx - if (omit.index.cols) {
omit.cols - match(names(indexInfo$groups)[-1], names(data))
function(x, ...) FUN(data[x, -omit.cols], ...)
  } else {
function(x, ...) FUN(data[x, ], ...)
  }
  ans - lapply(split(1:nrow(data), indexInfo$cases), FUNx, ...)
  index - as.numeric(names(ans))
  if (!is.data.frame(ans[[1]])) {
ans - lapply(ans, function(x) {
  dframe - as.data.frame(t(x))
  if (is.null(names(x)))
names(dframe) - funname
  dframe
})
  }
  lengths - sapply(ans, nrow)
  ans - do.call(rbind, ans)
  if (!missing(newnames))
names(ans) - newnames
  nms - indexInfo$groups[rep(index, lengths),-1, drop=FALSE]
  res - cbind(ans, nms)
  res
}

__
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 change the class of data?

2008-06-12 Thread Charilaos Skiadas

On Jun 12, 2008, at 2:24 AM, Qman Fin wrote:


Hi all,

I have some data x, which are actualy consisted of numerical  
enties. But the

class of this matrix is set to be factor by someone else. I used
class(x), it turns out to be factor. So I can not calculate them.


The typical approach is to do:

as.numeric(as.character(x))

How can I turn them into numerical data so that I can apply math  
operations

on them? Thanks a lot for your help.

Selina


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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 change the class of data?

2008-06-12 Thread Charilaos Skiadas
Seeing how there have been three wrong answers so far, I should point  
out that:


1) This is an FAQ:  http://cran.r-project.org/doc/FAQ/R-FAQ.html#How- 
do-I-convert-factors-to-numeric_003f
2) Most of the other methods suggested so far fail if the example x  
used is not of the form 1:n. The only reason they happen to work, is  
that in that case the levels coincide with their labels.


 x-factor(8:5)
 as.numeric(levels(x))
[1] 5 6 7 8

 as.numeric(x)
[1] 4 3 2 1
 class(x) - numeric
 x+1
[1] 5 4 3 2
attr(,levels)
[1] 5 6 7 8



Haris Skiadas
Department of Mathematics and Computer Science
Hanover College


On Jun 12, 2008, at 3:07 AM, anna freni sterrantino wrote:


Hi Selina,
try ?as.numeric,

 small example
 a=c(1,2,3,4,5)
 b=as.factor(a)
class(b)

c=as.numeric(b)
class(c)

in the case of a matrix of factor,try
apply(matrix,1, as.numeric)

Cheers

A.


- Messaggio originale -
Da: Qman Fin [EMAIL PROTECTED]
A: r-help@r-project.org
Inviato: Giovedì 12 giugno 2008, 8:24:08
Oggetto: [R] How to change the class of data?

Hi all,

I have some data x, which are actualy consisted of numerical  
enties. But the

class of this matrix is set to be factor by someone else. I used
class(x), it turns out to be factor. So I can not calculate them.

How can I turn them into numerical data so that I can apply math  
operations

on them? Thanks a lot for your help.

Selina



__
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] numbers as part of long character

2008-06-12 Thread Charilaos Skiadas

On Jun 12, 2008, at 5:06 PM, Marc Schwartz wrote:


on 06/12/2008 03:46 PM Hua Li wrote:

Hi,
I'm looking for some way to pick up the numbers which are  
contained and buried in a long character. For example,
outtree.new=(((B:1204.25,E:1204.25):7581.11,F:8785.36):8353.85,C: 
17139.21);
num.char = unlist(strsplit(unlist(strsplit(unlist(strsplit(unlist 
(strsplit(unlist(strsplit 
(outtree.new,),fixed=TRUE)),(,fixed=TRUE)),:,fixed=TRUE)),,,f 
ixed=TRUE)),;,fixed=TRUE))

num.vec=as.numeric(num.char[1:(length(num.char)-1)])
num.char
#  B1204.25  E1204.25  7581.11   
F8785.36  8353.85  C17139.21  num.vec
# NA  1204.25   NA  1204.25  7581.11   NA  8785.36   
8353.85   NA 17139.21
would help me get the numbers such as 1204.25, 7581.11, etc, but  
with a warning message which reads:

Warning message:
NAs introduced by coercion 
Is there a way to get around this? Thanks!
Hua


Your code above is overly and needlessly complicated, which makes  
it difficult to debug.


I would take an approach whereby you use gsub() to strip non- 
numeric characters from the input character vector and then use scan 
() to read the remaining numbers:


 Vec - scan(textConnection(gsub([^0-9\\.]+,  , outtree.new)))
Read 6 items

 Vec
[1]  1204.25  1204.25  7581.11  8785.36  8353.85 17139.21

 str(Vec)
 num [1:6] 1204 1204 7581 8785 8354 ...


The result of using gsub() above is:

 gsub([^0-9\\.]+,  , outtree.new)
[1]  1204.25 1204.25 7581.11 8785.36 8353.85 17139.21 


That gives you a character vector which can then be passed to scan 
() as a textConnection().


Another approach would be to split on sequences of non-integers:

as.numeric( strsplit(outtree.new, [^\\d.]+, perl=TRUE)[[1]] )


Use [^+-\\d.]+ if your numbers might be signed. This does assume  
that dots, +/- occur only as decimal points.


Hua, did you want to keep the information of which number is B, which  
is C etc?



See ?gsub, ?regex, ?textConnection and ?scan for more information.

HTH,

Marc Schwartz



Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] numbers as part of long character

2008-06-12 Thread Charilaos Skiadas

On Jun 12, 2008, at 6:34 PM, Hua Li wrote:


Thanks, Marc and Haris!

I didn't know the values of the numbers beforehand, so the scan  
method won't work, but [^+-\\d.]+ will do!


And Haris, I didn't intend to keep the information of which number  
is B, which is C etc when asking the question, as I had a tedious  
way to do it (use strspilt and unlist over and over again, after I  
get the number). But if you have a easier way to do it, I'd like to  
know!


Depending on how your real use case looks like, the following might  
work:


vec1 - strsplit(outtree.new, [^+-\\d.:\\w]+, perl=TRUE)[[1]]
nums - as.numeric(gsub(\\w?:,, vec1, perl=TRUE))
names(nums) - gsub(:[+-\\d.]+,, vec1, perl=TRUE)

If it doesn't, then provide us with the example that fails it.


Hua


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Increase Number of Decimals

2008-06-11 Thread Charilaos Skiadas

On Jun 11, 2008, at 12:17 PM, Neil Gupta wrote:


R Users,

I'm new to R and was wondering how I can show more decimal places  
when I run
commands. If I'm simply running a correlation(ES,YM) how would I  
increase
the number of decimal places R shows? When I run this it shows me . 
9734044.

How can I extend this further?


I am not sure what you can gain by looking at more decimal points in  
a correlation, but there are two ways, as far as I can tell:


1) Wrap the command in print, and use the digits optional argument  
in print. Have a look at ?print for details
2) Change the default more permanently for the session, by something  
like

options(digits=10)
Look at ?options for details


In addition I was running histograms on high frequency data to check a
Spread. The spread moves at an extremely granular level. It may  
move .01
frequently but again at a low level. How  can I increase the  
graularity of

the histogram plots to detect smaller moves?


We would need a reproducible example for this, I think.


I appreciate any and all help.

Neil


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] fitting periodic 'sine wave' model

2008-06-10 Thread Charilaos Skiadas

In addition to Gabor's suggestion, note the following warning from ?nls

Warning

Do not use nls on artificial zero-residual data.

The nls function uses a relative-offset convergence criterion that  
compares the numerical imprecision at the current parameter estimates  
to the residual sum-of-squares. This performs well on data of the form


y = f(x, theta) + eps

(with var(eps)  0). It fails to indicate convergence on data of the  
form


y = f(x, theta)

because the criterion amounts to comparing two components of the  
round-off error. If you wish to test nls on artificial data please  
add a noise component, as shown in the example below.





So for instance if you try with:

r-nls(y ~ A*sin(2*pi*F*x), start=list(A = 1, F = .5), trace=T)

You will get convergence.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College


On Jun 10, 2008, at 10:25 AM, Jon Loehrke wrote:

I have been attempting to estimate the periodic contribution of an  
effect to some data but have not been able to fit a sine wave  
within R.
It would be nice to start by being able to fit a sine wave with an  
amplitude and frequency.


x-seq(0,20,by=0.5)
y-2*sin(2*pi*.5*x) #amplitude =2, frequency=0.5

# This failed to converge
r-nls(y ~ A*sin(2*pi*F*x), start=list(A = 1, F = 1), trace=T)


# even this gave a max iteration error
r-nls(y ~ A*sin(2*pi*F*x), start=list(A = 1, F = .5), trace=T)

I have a feeling I am approaching this incorrectly.  Thank you all  
very much for the guidance.


Jon
R 2.7.0
mac os 10.5


Jon Loehrke
Graduate Research Assistant
Department of Fisheries Oceanography
School for Marine Science and Technology
University of Massachusetts
200 Mill Road, Suite 325
Fairhaven, MA 02719
[EMAIL PROTECTED]
T 508-910-6393
F 509-910-6396



__
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 lm with a matrix?

2008-06-07 Thread Charilaos Skiadas


On Jun 7, 2008, at 8:13 AM, jonboym wrote:



I'm trying to do a linear regression between the columns of  
matrices.  In
example below I want to regress column 1 of matrix xdat with  
column1 of ydat
and do a separate regression between the column 2s of each matrix.   
But the

output I get seems to give correct slopes but incorrect intercepts and
another set of slopes with value NA.  How do I do this correctly?   
I'm after

the slope and intercept of each columns regression


xdat - matrix(1:6,3,2)
xdat

 [,1] [,2]
[1,]14
[2,]25
[3,]36

ydat - xdat
ydat[,1] - xdat[,1]*3 +2
ydat

 [,1] [,2]
[1,]54
[2,]85
[3,]   116

ydat[,2] - xdat[,2]*4 - 3
yadt

Error: object yadt not found

ydat

 [,1] [,2]
[1,]5   13
[2,]8   17
[3,]   11   21

lrg - lm(y~x)

Error in eval(expr, envir, enclos) : object y not found

lrg - lm(ydat~xdat)
lrg


Call:
lm(formula = ydat ~ xdat)

Coefficients:
 [,1]  [,2]
(Intercept)   2 9
xdat1 3 4
xdat2NANA


Try this:

lapply( 1:2, function(i) lm( y~x, data=list(x=xdat[,i], y=ydat[,i]) ) )

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Existence of formal arguments.

2008-06-05 Thread Charilaos Skiadas


On Jun 5, 2008, at 9:13 PM, Duncan Murdoch wrote:


On 05/06/2008 8:23 PM, Rolf Turner wrote:

I just discovered what seems to me to be a slight funny in respect
of formal argument names.  If I define a function
foo - function(a,b){ ... whatever ...}
then ``inside'' foo() the exists() function will return TRUE
from ``exists(a) whether an object named ``a'' exists or not.
But get(a) will yield an error ``object a not found''
in these circumstances.
I presume there is a reason for specifying that an object named
by a formal argument always exists --- but it is mysterious by my
standards.  Can anyone explain the reason for this behaviour?


Oops, I didn't explain why this is the way it should be.

Say your whatever above makes use of a, but you didn't pass an a  
in. Then you'd like an error, or you'd like missing(a) to  
evaluate to TRUE, or something along those lines.  But if a was  
completely undefined and nonexistent, R would just go looking for a  
global, and make use of that.  So it has to be marked as missing.


I am now baffled by this:

 foo - function(a,b){class(get(a))}
 foo()
[1] name

 foo - function(a,b){x-get(a);class(x)}
 foo()
Error in foo() : argument x is missing, with no default

And similarly with str:

 foo - function(a,b){str(get(a))}
 foo()
symbol
 foo - function(a,b){x-get(a);str(x)}
 foo()
Error in str(x) : argument x is missing, with no default


Well OK, maybe not baffled exactly, it short of fits with your  
description above. I guess I am wondering, how is this technically  
achieved?
I suppose then that missing(a) the only call we should expect to work  
in the absence of a, even though calls like class(get(a)) and str 
(get(a)), is.numeric(get(a)) etc seem to return something  
reasonable?



Duncan Murdoch


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] write.table() error

2008-06-05 Thread Charilaos Skiadas
I just managed to write things just fine, and then I recalled that I  
had a similar problem when teaching our students SPSS (Yes, I know,  
don't ask...), but the problem was effectively this: If a given file  
was open in Excel, then that file was locked and no other program  
could use it until you close the file in Excel. So is perhaps a file  
called data1.csv already in existence and open in Excel when you try  
this?


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Jun 5, 2008, at 11:57 PM, Megh Dal wrote:


Hi,

I got following error in write.table() :

write.table(dataa, file=c:/data1.csv, row.names=F, col.names=T,  
sep=,)

Error in file(file, ifelse(append, a, w)) :
  cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, a, w)) :
  cannot open file 'c:/data1.csv': Permission denied


where dataa is a zoo object

head(dataa)

 data11 data22
Nov 1980 988.25 194841
Dec 1980 942.38 205732
Jan 1981 935.90 226501
Feb 1981 968.79 227402
Mar 1981 932.77 233490
Apr 1981 906.18 233447


Can please tell me why this error is coming? I am using Windows vista



__
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] apply in apply

2008-05-30 Thread Charilaos Skiadas


On May 30, 2008, at 5:37 AM, baptiste Auguié wrote:

Thank you for the suggestions (off-list as well). I think the best  
option may eventually be an explicit for loop to make things  
clearer. To clarify a bit, I've used the plot function in the  
example where in fact it is a numerical integration (which is why I  
need to pass an additional variable in the second apply call),



intg - function (y, x)
{
n - length(x)
index - order(x)
dx - diff(sort(x))
z - y[index]
ys - (z[1:(n - 1)] + z[2:n])/2
sum(ys * dx)
}
environment: namespace:PROcess



Thanks again for the suggestions,


I think this is where the beauty of ... comes in, the following  
should be doing just what you want:


sapply(my.data, apply, 2, intg, x)

More clear? Not sure I can judge that, certainly more  concise.  
sapply just passes the extra arguments to apply, which then just  
passes them to intg.



baptiste


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College


On 30 May 2008, at 10:02, [EMAIL PROTECTED] wrote:

I need to apply a function on each column of each matrix  
contained in

a list. Consider the following code,


x - 1:3
my.data - list(matrix(c(1,2,3,4,5,6),ncol=2),
  matrix(c(4,5,6,7,8,9),ncol=2))

par(mfrow=c(2,2))
results - sapply(1:length(my.data),
 function(ii) apply(my.data[[ii]], 2, function(y) plot 
(x,y) ))

#

plot is for demonstration purposes



It works, but I think this is quite dirty code. Is there a simpler
way of achieving this?


The last line can be simplified
results - sapply(my.data, function(x) apply(x,2,sum))

(It is perhaps a little clearer what is going on when you use sum  
rather

than plot as the example function.)

Regards,
Richie.

Mathematical Sciences Unit
HSL



__
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] A question about *read.table()*

2008-05-30 Thread Charilaos Skiadas

On May 30, 2008, at 7:56 PM, ss wrote:


and I got an error message:


exprSet - read.table('process_all4_GSA2.txt', row.names = 1,header

=FALSE)
Error in read.table(process_all4_GSA2.txt, row.names = 1, header  
= FALSE)

:
  duplicate 'row.names' are not allowed


I would say that's pretty explanatory. You've asked it to use the  
first column for row names, but apparently there are two rows with  
the same name, and we can't have that.
Perhaps you might want to try to load it without the row.names=1  
part, and then use:


duplicated(exprSet[,1])

to see which rows are the ones with the same name.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

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


Re: [R] Problem with scatter plotting

2008-05-29 Thread Charilaos Skiadas

On May 29, 2008, at 9:56 PM, lek2k wrote:

PLEASE do read the posting guide http://www.R-project.org/posting- 
guide.html

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


I (and certainly many others) have been using multiple points calls  
for a while now with no problems at all, so I suggest you send us  
what the posting guide asks, i.e. a minimal reproducible example that  
we can all run.


Btw, I find using lattice easier for these kinds of things.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Including a tilde in a plotmath-type call

2008-05-29 Thread Charilaos Skiadas


On May 29, 2008, at 11:02 PM, [EMAIL PROTECTED] wrote:


Suppose I have a plot
plot(1:10, pch = )

And I want some text to indicate a Normal distrubition.  I could do
this:

text(5, 6, substitute(XN(mu, sigma^2)), adj = 0)
text(5.35, 6, ~, adj = 0)

But that's clumsy, and depending on your plotting device, might not  
even look

sensible.  I'd prefer to be able to do it more directly and
simply the way these do:

text(5, 1, expression(X %~~% N(mu, sigma^2)), adj = 0)
text(5, 2, expression(X %prop% N(mu, sigma^2)), adj = 0)
text(5, 3, expression(X %=~% N(mu, sigma^2)), adj = 0)

They're easy, but they don't give a single tilde.  I know how to put a
tilde(X) or even a wide tilde, but there're not it either.

What did I miss?



Does this do it?

text(2, 3, expression(X *~* N(mu, sigma^2)), adj = 0)

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] nlm and missing argument

2008-05-29 Thread Charilaos Skiadas

On May 29, 2008, at 11:54 PM, Redding, Matthew wrote:


Dear R Gurus,

I am having a little difficulty with nlm. I've searched the  
archives and

found nothing that tells me why this is occuring -- though there are
some slightly similar issues.

A simple example:

lev2-function(aaa,bbb,ccc,ddd,eee){
res-aaa+bbb+ccc+ddd+eee
res

}

nlm(lev2,p=c(32,4,5),ddd=45,eee=23)

Error in f(x, ...) : argument bbb is missing, with no default

Why is this occurring?  I am running 2.6.1.

Is there something simple here that I am overlooking?  I am trying to
take advantage of the ... method of inputing
parameters that I do not want optimised.

Kind regards,


Read the documentation for nlm more closely. The Arguments part says  
about f:


	This should be a function of a vector of the length of p followed by  
any other arguments specified by the ... argument.


All the examples in fact do exactly that, using only the first  
variable, x, of f for all the unknowns. So perhaps you want to do a  
simple wrapping like this:


lev3 - function(x,ddd,eee) {
lev2(x[1],x[2],x[3],ddd,eee)
}
nlm(lev3,p=c(32,4,5),ddd=45,eee=23)


Matt Redding


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] can I do this with R?

2008-05-28 Thread Charilaos Skiadas
A google search for logistic regression with stepwise forward in r  
returns the following post:


https://stat.ethz.ch/pipermail/r-help/2003-December/043645.html

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On May 28, 2008, at 7:01 AM, Maria wrote:


Hello,
I am just about to install R and was wondering about a few things.

I have only worked in Matlab because I wanted to do a logistic  
regression. However Matlab does not do logistic regression with  
stepwiseforward method. Therefore I thought about testing R. So my  
question is

can I do logistic regression with stepwise forward in R?

Thanks /M


__
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] Rotated text on a regression line

2008-05-27 Thread Charilaos Skiadas

I think this comment for ?par, meant for both crt and srt, applies:

crt
A numerical value specifying (in degrees) how single characters  
should be rotated. It is unwise to expect values other than multiples  
of 90 to work. Compare with srt which does string rotation.



So I would say that even getting close to the right angle is not bad.  
I would think that perhaps the graphics devices can only write in  
particular directions, and that's the one closest to your graph.


Actually, further playing with it, I think all you are missing is  
that this angle is not dependent on the aspect ratio, it's an  
absolute angle. Try to resize the window, and see how the direction  
of the string does not change at all, even though the line slope does  
change.


Hence the advice about only relying on 0 and 90 degrees.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College


On May 27, 2008, at 5:25 PM, Dr. Christoph Scherber wrote:


Dear all,

I stumbled over a problem recently when trying to use srt with text 
() on a

windows device.

What I intended to do was to plot a simple regression line, and to  
rotate
a piece of text such that the text has the same angle as the  
regression

line.

However, the text is always plotted in a slightly wrong angle:



x=1:10  #create arbitrary x and y values
y=x*2-rnorm(1:10)

plot(x,y,pch=16,xlim=c(0,10))  #create the graph
abline(lm(y~x))

#calculate the y coordinate of the text:
yval=predict(lm(y~x),list(x=rep(2,length(x[1]

#calculate the slope:
slope=as.numeric(lm(y~x)[[1]][2])

text(2,yval,Regression,srt=180/pi*atan(slope),adj=0)



What am I doing wrong here?

Many thanks in advance for any help!

Best wishes
Christoph

(using R 2.6.1 on Windows XP)



__
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 bind lists recursively

2008-05-27 Thread Charilaos Skiadas

On May 27, 2008, at 10:43 PM, Daniel Yang wrote:


Dear all,

I want to create a list that contains 0,1,2,3, ..., 1 as its  
elements. I used the following code, which apparently doesn't work  
very well.


a - 0
for(i in 1:1) {
   a - list(a, i)
}

The result is not what I wanted. So how to create the bind lists  
recursively so that the last element would be the newly added one  
while the previous elements all remain the same?


Hm, for the particular problem you are asking, I think that:

as.list(0:1)

should do the trick. I m guessing it might not work for the real  
application you had in mind.


If you insist on the for loop, then you can do the following:

a - list(0)
for(i in 1:1) {
   a - c(a, i)
}

Though it's much smaller. In general, it is better to assign the  
correct size to the list to begin with, I believe.



Thanks!
Daniel


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Some problems with Sweave

2008-05-23 Thread Charilaos Skiadas

Try results=verbatim instead of results=tex.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College


On May 23, 2008, at 4:16 AM, [EMAIL PROTECTED] wrote:


Dear R users,
I'm working in a brief R-tutorial to a group of students. To make  
that I'm

using Sweave but I've got two problems:

First, I want show how R operates with the matrix type but, I write  
in the

.rnw document the code

echo=T,results=tex=
 matriz - matrix(vector,nrow=3,ncol=6)
 matriz
@

and after compilating the LaTex document I obtain in the pdf the  
next text



matriz - matrix(vector, nrow = 3, ncol = 6)
matriz
[,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 4 1 4 1 4 [2,] 2 5 2 5 2 5  
[3,] 3 6 3

6 3 6

My question is, How must I do To obtain in the pdf somethin near to


matriz - matrix(vector, nrow = 3, ncol = 6)
matriz

 [,1] [,2] [,3] [,4] [,5] [,6]
[1,]141414
[2,]252525
[3,]363636

I`ve tought in xtable but the aspect is not as the R console.

On the other hand I want show the list type R-treatment, the  
problem here

is in the LaTex compilation
I write in the .rnwd document

echo=T,results=tex=
 lista - list(cadena='String',vector=c(1,1,1),logica=TRUE)
 lista$cadena
@

the Sweave call is ok, but when I compile the .tex document, It  
produces

errors caused by the $ simbols. Anybody knows how save this problem?

Thanks in advance,
Martín Gastón



__
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 pass variable of for loop on read table text

2008-05-23 Thread Charilaos Skiadas

?paste

paste('text',y,'.txt', sep=)

and you likely need data[[y]] instead of data$y.

On May 23, 2008, at 9:05 PM, Jason Lee wrote:


Hi,

I have a couple of text and would like to automate of reading these  
multiple

files using
(namely; text1.txt, text2.txt)

for(y in 3:10){
data$y-read.table('text$y.txt')}

But it seems not allow. Any idea?


Thanks.

[[alternative HTML version deleted]]



Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] disaggregate frequency table into flat file

2008-05-22 Thread Charilaos Skiadas

On May 22, 2008, at 8:56 AM, maiya wrote:



sorry, my mistake!
the data frame should read:
orig-as.data.frame.table(orig)
orig
 Var1 Var2 Freq
1AA   40
2BA5
3AB   30
4BB   25

but basicaly i would simply like a sample of the original matrix  
( which is

a frequency table/contingency table/crosstabulation)

hope this is clearer now!


This should get you started:

with(list(x=sample(1:4, 10, prob=orig$Freq, replace=TRUE)), sapply 
(1:4, function(k) sum(x==k)))


Or you can break it up in two steps (at the cost of creating a new  
variable):


x - sample(1:4, 10, prob=orig$Freq, replace=TRUE)
sapply(1:4, function(k) sum(x==k))


maja


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College



jholtman wrote:


Not exactly clear what you are asking for.  Your data.frame.table  
does not
seem related to the original 'orig'.  What exactly are you  
expecting as

output?

On Wed, May 21, 2008 at 10:16 PM, maiya [EMAIL PROTECTED]  
wrote:




i appologise for the trivialness of this post - but i've been  
searching

the
forum wothout luck - probably simply because it's late and my  
brain is

starting to go..

i have a frequency table as a matrix:

orig-matrix(c(40,5,30,25), c(2,2))
orig
[,1] [,2]
[1,]   40   30
[2,]5   25

i basically need a random sample say 10 from 100:

[,1] [,2]
[1,]   5   2
[2,]0   3

i got as far as

orig-as.data.frame.table(orig)
orig
 Var1 Var2 Freq
1AA   10
2BA5
3AB   30
4BB   25

and then perhaps

individ-rep(1:4, times=orig$Freq)

which gives a vector of the 100 individuals in each of the 4  
groups -

cells,
but I'm
(a) stuck here and
(b) afraid this is a very round-about way at getting to what I  
want i.e.

I
can now sample(individ, 10), but then I'll have a heck of a time  
getting

the
result back into the original matrix form

sorry again, just please tell me the simple solution that I've  
missed?


thanks!

maja

--
View this message in context:
http://www.nabble.com/disaggregate-frequency-table-into-flat-file- 
tp17396040p17396040.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.htmlhttp://www.r- 
project.org/posting-guide.html

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





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

What is the problem you are trying to solve?

[[alternative HTML version deleted]]



__
R-help@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] 3D Area Diagram

2008-05-22 Thread Charilaos Skiadas

On May 22, 2008, at 3:04 PM, AlGates wrote:


Hello,

maybe someone can help me. I am looking for a possibility to plot a  
3D area

diagram like in Excel:
http://www.microsoft.com/germany/mac/excel/images/chartbefore.jpg  
Watch

this!

Would be nice if someone had any idea about that.


I don't know why you would want to subject your viewers/readers to a  
graph like that (Do we really need three dimensions and a ton of  
color to represent two groups of 4 numbers? And how can you possibly  
do comparisons when they are each behind each other? The area shading  
would prompt the viewer to compare areas, and only the blue areas are  
visible. Actually, can one even tell from the graph which of the two  
lines is higher in the fourth quarter, let alone by how much?), but  
would using RExcel to actually ask Excel from R to draw the graph be  
an acceptable solution? Otherwise I think that perhaps looking at  
wireframe in the lattice package might get you started. Perhaps  
others have some better suggestions.


But I would reiterate my suggestion for considering other ways of  
showing your data.



Thank you
Alex


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] About Passing Arguments to Function

2008-05-22 Thread Charilaos Skiadas

On May 22, 2008, at 9:14 PM, Edward Wijaya wrote:


Hi,

Below I have a function mlogl_k,
later it's called with nlm .

__BEGIN__
vsamples- c(14.7, 18.8, 14, 15.9, 9.7, 12.8)

mlogl_k - function( k_func, x_func, theta_func, samp) {
 tot_mll - 0
 for (comp in 1:k_func) {
   curr_mll - (- sum(dgamma(samp, shape = x_func,
scale=theta_func, log = TRUE)))
   tot_mll - tot_mll + curr_mll
 }

 tot_mll
}

# Calling the function above
mlogl_out - nlm(mlogl_k, mean(vsamples), k_func =2, x_func = 1,
theta_func = 1, samp=vsamples)

__END__

I thought under NLM, I already assign
the parameter correctly.
However it gives me the following error.

Error in f(x, ...) : unused argument(s) (14.31667)
Calls: nlm - Anonymous - f
Execution halted


What's wrong with my code above?


nlm passes the following values over to mlogl_k: mean(vsamples),  
k_func =2, x_func = 1, theta_func = 1, samp=vsamples


Now, f is called with these arguments, and all its arguments are  
matched by the named arguments. Then it does not know what to do with  
the mean(vsamples) argument. Hence the error: f is called with one  
more argument than it can handle.


It is not clear with respect to what variables you want the  
minimization. Right now all the named variables are treated as  
constants, and there is no variable left with respect to which  
mlogl_k is supposed to be maximized. Read the documentation for nlm  
carefully: Your function should have one more argument (like the  
alpha in the question you asked yesterday).



- Edward


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Computing Maximum Loglikelihood With nlm Problem

2008-05-21 Thread Charilaos Skiadas

Try:

mlogl_out - nlm(mlogl, mean(vsamples), vsamples)

or

mlogl_out - nlm(mlogl, mean(vsamples), x=vsamples)

The argument vsamples=vsamples is passed to mlogl, since nlm does not  
recognize it. But mlogl doesn't have a vsamples argument, only alpha  
and x arguments. So you have to either leave mean(vsamples) and  
vsamples unnamed, or else name them alpha and x respectively, as you  
told mlogl. Or change the argument names in mlogl.


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On May 21, 2008, at 10:05 PM, Edward Wijaya wrote:


Hi,

I tried to compute maximum likelihood under gamma distribution,
using nlm function. The code is this:

__BEGIN__

vsamples- c(103.9, 88.5, 242.9, 206.6, 175.7, 164.4)

mlogl - function(alpha, x) {
if (length(alpha)  1) stop(alpha must be scalar)
if (alpha = 0) stop(alpha must be positive)
return(- sum(dgamma(x, shape = alpha, log = TRUE)))
 }

mlogl_out - nlm(mlogl, mean(vsamples),vsamples=vsamples)
print(mlogl_out)

__END__

However, it gives the following error:

Error in f(x, ...) :
  unused argument(s) (vsamples = c(103.9, 88.5, 242.9, 206.6,  
175.7, 164.4))

Calls: nlm - Anonymous - f
Execution halted


What's wrong in my way of calling 'nlm function?
Please advice.

- Edward



__
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 banking to 45 degrees.

2008-05-20 Thread Charilaos Skiadas

On May 20, 2008, at 2:34 PM, Deepayan Sarkar wrote:


On 5/20/08, Joshua Hertlein [EMAIL PROTECTED] wrote:


 Hello,

  I am very interested in banking to 45 degrees as defined by  
William S. Cleveland
in Visualizing Data.  I like to do it in R as well as Excel,  
etc.  With R I have come

across the following method:

 xyplot(x, y, aspect=xy)   (part of lattice package)

 which will bank my graph to 45 degrees.  My question is how do I  
obtain the
aspect ratio that banks this graph to 45 degrees?  I understand  
that R does it
for me, but I would like to explicitly know the aspect ratio so  
that I can configure

other graphs in Excel or other software.




foo - xyplot(sunspot.year ~ 1700:1988, type = l, aspect = xy)
foo$aspect.ratio

[1] 0.04554598


 aspect ratio = v / h(v is vertical distance of plot, h is  
horizontal distance of plot.

NOT in the data units, but true, actual distance).

 I've also come across banking (), but I don't understand it,  
nor the significance
of the value it returns.  Regardless, it doesn't seem to be the  
aspect ratio that

I am looking for.


banking(dx, dy) basically gives you the median of abs(dy/dx). The idea
is that dx and dy define the slopes of the segments you want to bank
(so typically, dx = diff(x) and dy = diff(y) if x and y are the data
you want to plot). banking() gives you a single (summary) slope; you
then choose the aspect ratio of your plot so that this slope (in the
data coordinates) has a physical slope of 1. To do this, you solve an
equation involving the data range in the x- and y-axes of your plot.


Here is how I see it. Let me define a visual y-unit as the height  
of a unit of data in the y-direction, and similarly for a visual x-unit.
Then the aspect ratio is the quotient of the visual y-unit over the  
visual x-unit. So the aspect ratio is the number of visual x-units  
that have the same length as one visual y-unit.
If a line has real (data) slope r, and the aspect ratio is b, then  
the line appears with slope rb.


Now, there are two things one can compute (for simplicity I assume  
all slopes are positive, insert absolute values as necessary):
1. The value of the aspect ratio, that makes the median of the visual  
slopes be 1. This would be obtained by requiring the median of all  
the rb to be 1, which means that the aspect ratio would be 1/median 
(slopes).
2. The median of the aspect ratios, that make each individual line  
have slope 1. So for each line with slope r, we consider the aspect  
ratio 1/r, and then take the median of that. So this would be median 
(1/slopes).


Now, unless I am missing something, the banking function computes the  
second one of these, while I think the documentation (and my  
intuition) say that we want the first of these. In the case where  
there is an odd number of data, they would agree, but otherwise one  
is related to the arithmetic mean of the two middle observations,  
while the other is referring to the harmonic mean of the two  
observations. Those will likely be close to each other in most cases,  
so perhaps this is a moot point in practice, but am I wrong in  
thinking that 1/median(abs(dy[id]/dx[id])) would be the right thing  
to have in the code to the banking function?



-Deepayan


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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 banking to 45 degrees.

2008-05-20 Thread Charilaos Skiadas

On May 20, 2008, at 5:59 PM, Deepayan Sarkar wrote:


On 5/20/08, Charilaos Skiadas [EMAIL PROTECTED] wrote:

 Here is how I see it. Let me define a visual y-unit as the  
height of a

unit of data in the y-direction, and similarly for a visual x-unit.
 Then the aspect ratio is the quotient of the visual y-unit over  
the visual
x-unit. So the aspect ratio is the number of visual x-units that  
have the

same length as one visual y-unit.


[Not that it matters, but it is not clear what you mean here. Let's
say we have a 100cm x 100cm plot, with data ranges xlim=c(0, 100) and
ylim=c(0, 200). Then, the aspect ratio is 1, your visual y-unit is
0.5cm, and visual x-unit is 1cm (so their ratio is 0.5).]


So in this case, the slope of the line y=x, which is 1, appears as  
0.5. I effectively wanted to combine the two effects, of the sizes of  
the two scales and of the sizes of the window. They both have an  
effect on how a line of slope 1 is seen. But perhaps I am missing  
something here?


 If a line has real (data) slope r, and the aspect ratio is b,  
then the line

appears with slope rb.


Agreed.

 Now, there are two things one can compute (for simplicity I  
assume all

slopes are positive, insert absolute values as necessary):
 1. The value of the aspect ratio, that makes the median of the  
visual
slopes be 1. This would be obtained by requiring the median of all  
the rb to

be 1, which means that the aspect ratio would be 1/median(slopes).
 2. The median of the aspect ratios, that make each individual  
line have
slope 1. So for each line with slope r, we consider the aspect  
ratio 1/r,

and then take the median of that. So this would be median(1/slopes).


I agree with your analysis, but would claim that both calculations are
right, since the median of 2 numbers is formally any number in
between.


That's a very good point, I never thought of it that way (though I  
have to say, I haven't seen anything but the arithmetic average used  
in getting THE median before).



I think it is unlikely that the difference in calculations
leads to any difference in the perceptual benefits.


Agreed.


Of course, the current calculation has the advantage of doing one less
division! :-)


For me, that's reason enough to keep it as is ;)


-Deepayan


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Histograms without bars

2008-05-19 Thread Charilaos Skiadas

Hi Andre,

On May 19, 2008, at 4:28 PM, Andre Nathan wrote:


Hello

I'd like to plot a histogram of some data composed of real numbers.  
The

bin width I'm using is ~ 0.01, which results in high values in the y
axis, so that the area under each bar corresponds to the  
probability of

the data in that range.

Is is possible to plot points whose y coordinate correspond to that
probability, instead of plotting the histogram bars? In other words,
instead of having a bar of width 0.01 and height, say, 80, I'd like to
have a single point at y = 0.8.

I know I could use the values returned from hist() and calculate that
manually, but maybe there's a better way to do that. I've been using
prop.table() to plot these histograms for integer numbers, but now I
need binning and I'm not sure what is the best way to proceed.


I would use ?cut to create a factor, followed with the usual  
prop.table (+ table) you have been using.

Unless you didn't want to have control over the precise binning?


Thanks in advance,
Andre


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Figure environment and includegraphics options from Sweave

2008-05-18 Thread Charilaos Skiadas


On May 18, 2008, at 10:41 AM, BXC (Bendix Carstensen) wrote:


Tha handy thinb about the fig=TRUE option in Sweave is that you do not
have to bother about filenames and starting and stpping the device.

I want the the resulting LaTeX to look as:

\begin{Schunk}
\begin{Sinput}

x - seq(-2 * pi, 2 * pi, 0.1)
plot(x, cos(x), type = l, lwd = 4)

\end{Sinput}
\end{Schunk}




\begin{figure}
\includegraphics[width=0.6\textwidth]{xx-001}
\end{figure}




i.e. with options to the \includegraphics and all embedded in a figure
environment.

1)
Is there a way to do this without writing the figure environment
manually?


The Sweave manual (section 4.1.2 in my version) suggests using  
something like this before the figure call:


\setkeys{Gin}{width=0.6\textwidth}

This sets the size globally. Not perfect, but it's what I've been doing.
I would myself like the ability to add optional arguments to the  
produced \includegraphics call, but perhaps there is a good reason  
why this hasn't been implemented (other than that the developer might  
not have thought it useful/necessary, which is in itself a perfectly  
good reason why this feature is not there).



2)
If not, is there a way to get the generated filename of the plot,  
or to

explicitly give it
in the .rnw file? The point of course being to avoid to start and stop
the graphics driver explicitly?


I haven't tried it, but perhaps if you have a named figure code  
chunk, this name is used for the file name?



Best,
Bendix Carstensen
__

Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Niels Steensens Vej 2-4
DK-2820 Gentofte
Denmark
+45 44 43 87 38 (direct)
+45 30 75 87 38 (mobile)
[EMAIL PROTECTED]   http://www.biostat.ku.dk/~bxc


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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: left-aligned text in strips?

2008-05-15 Thread Charilaos Skiadas

On May 15, 2008, at 3:18 AM, RINNER Heinrich wrote:


Thanks for your help!
I guess I could have thought for ages about this, and never would  
such a solution have come to my mind ;-)
It works as far as the text in the strips is left-aligned; a  
remaining drawback is that printing of longer texts will be  
continued outside the right border of their strip.


Yes, the only way to fix that I think will likely be to tell it to  
clip the string off, and to do that you would likely want to copy  
some of what strip.default does with viewports. Effectively, you need  
to create a new viewport occupying the strip space, and tell it to  
use clipping there. See the code for strip.default, and the  
pushViewport and upViewport calls. For example, using that code, this  
might work:


require(grid)
strip.left.aligned - function(which.given, which.panel,  
factor.levels, ...) {

  pushViewport(viewport(y = (which.given - 0.5)/length(which.panel),
height = 1/length(which.panel), clip = trellis.par.get 
(clip)$strip,

name = paste(strip.default, which.given, sep = .)))
   panel.rect(0, 0, 1, 1, col = trellis.par.get(strip.background) 
$col[which.given], border = 1)
   panel.text(x = 0, y = 0.5, pos = 4, lab = factor.levels 
[which.panel[which.given]])

   upViewport()
}
xyplot(y ~ x | a, data = test, strip = strip.left.aligned)

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College



For example, using your suggestion:

###
library(lattice)
test - data.frame(x=rnorm(100), y=rnorm(100), a=rep(c(A, B,  
C, D: left-aligned text (possibly  
long string),25))


strip.left.aligned - function(which.given, which.panel,  
factor.levels, ...) {
   panel.rect(0, 0, 1, 1, col = trellis.par.get(strip.background) 
$col[which.given], border = 1)
   panel.text(x = 0, y = 0.5, pos = 4, lab = factor.levels 
[which.panel[which.given]])

}

xyplot(y ~ x | a, data = test, strip = strip.left.aligned)
###

Anywag, thanks again for having taken the time thinking about my  
question;

Heinrich.


-Ursprüngliche Nachricht-
Von: Charilaos Skiadas [mailto:[EMAIL PROTECTED]
Gesendet: Mittwoch, 14. Mai 2008 13:30
An: RINNER Heinrich
Cc: [EMAIL PROTECTED]
Betreff: Re: [R] lattice: left-aligned text in strips?



On May 14, 2008, at 3:47 AM, RINNER Heinrich wrote:


[adapted repost of question
http://tolstoy.newcastle.edu.au/R/e4/help/08/03/6260.html]

Dear R community,

by default, text in the strips of a trellis plot is centered in the
strip.
Is there a way to have the text left-aligned?

For example:

library(lattice)
test - data.frame(x=rnorm(100), y=rnorm(100), a=rep(c(A: centered
text,B: centered text),50))
xyplot(y ~ x | a, data = test)  # ok, strip text is centered
test - data.frame(x=rnorm(100), y=rnorm(100), a=rep(c(A: left-
aligned
text,B: left-aligned text (possibly

lng

string),50))
xyplot(y ~ x | a, data = test)  # how???


Here's a way to do it, shamelessly stealing the main idea from:
http://dsarkar.fhcrc.org/lattice/book/figures.html?
chapter=10;figure=10_24

Mainly you just have to write your own strip function.

xyplot(Petal.Length~Petal.Width|Species, iris, strip=function
(which.given,which.panel, factor.levels,...) {
   panel.rect(0, 0, 1, 1, col = trellis.par.get(strip.background)
$col[which.given], border = 1)
   panel.text(x = 0, y = 0.5, pos = 4, lab =
factor.levels[which.panel
[which.given]])
} )

Better yet, you should probably write a more generic strip function
that does what you want.

I would however consider using ?abbreviate for what you want to do
instead.


I am using R 2.6.2 on Windows XP, package lattice Version 0.17-6.

[The reason I would like to do this is because in real life my
conditioning variable 'a' can have quite long strings as

its value.

I am
automatically creating a series of trellis plots, and in each one a
different number of panels will be produced (maybe 4, maybe
20,...). So
in some cases (few panels, short labels) text in the strips will be
perfectly readable, while in some cases (many panels, long labels)
only
the middle of the text will.
I know I could abbreviate the strip text by using something like:
xyplot(y ~ x | substr(a,1,35), data = test)
But there is no natural choice of string length here when

I want to

cut off as few text as possible, so just left aligning the

strip texts

would seem like a natural and easy(?) solution to me - if I was
able to
do it...]

-Heinrich.


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College







__
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] off topic

2008-05-15 Thread Charilaos Skiadas

On May 15, 2008, at 2:07 PM, lamack lamack wrote:



Dear all, someone could explain why the following example is not a  
valid

randomization scheme?

 Consider an experiment in which the
six experimental units to be used are permanently fixed in a row and  
two treat-
ments are to be randomly assigned to the units. (One can think of  
fruit trees
or a sequence of runs on a piece of laboratory equipment as the  
experimental
units.) A scientist proposes using an unbiased coin to assign the  
treatments. He
comes to the first unit, tosses the coin, and if it shows a head,  
assigns treatment
a and otherwise, treatment b. This is repeated at the second unit,  
and so on, until
three units have been assigned to one of the treatments. Then the  
remaining units
are assigned to the other treatment. Show that this is not a valid  
randomization

scheme.


Hm, this sounds very much like a homework. So I am going to leave you  
with what I would perceive to be a hint. Presumably a valid  
randomization scheme is one where each of the possible resulting  
arrangements is equally likely. So all you got to do is find out why  
some of them are more likely than others in your case.



best regards.


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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 histogram problem with integers values and nint

2008-05-15 Thread Charilaos Skiadas
Two comments. First of all, I don't see how you can be sure that if  
you specify 365 bins, then each bin will contain exactly one day. In  
order to do that, you need to know that each bin has width exactly 1,  
and you don't tell lattice to use such a width, so it is likely  
choosing something else. In fact, if you save your histogram in a  
temporary variable, say pl, then the following will show you where  
lattice puts the breaks:


pl$panel.args.common$breaks

In the example I tried, the difference in any two consecutive breaks  
was 1.077041


The second point, is that this would probably be better done with an  
xyplot, using type=h. So assuming that x has those 17 values,  
and that all days occur, the following might be more satisfactory:


xyplot(table(x)~1:365, type=h)

I don't see the benefit in having bars instead of single vertical  
lines personally.


Hope this helps,
Haris Skiadas
Department of Mathematics and Computer Science
Hanover College


On May 15, 2008, at 3:27 PM, Richard and Barbara Males wrote:


been puzzling over this for a day.

Summary
integer variable to use with histogram, 170,000 rows.  Value is day of
year.  Hist works, lattice histogram with nint does not work (spurious
spikes in display), lattice histogram using breaks=c(0:365) works
fine.  Spike values appear to be sum of two adjacent bins.  Want to
know if this is a familiar problem, and what the recommended
work-around is.  Also want to know how to get the bin count from the
lattice histogram object, as I would with hist$count.

Thanks in advance.


Detail

I have a dataset of approximately 170,000 rows, with a DayOfYear
field.  I want a histogram of the number of rows in each day of the
year.  I set up breaks from 0:365, and use this with hist, and the
lattice histogram, e.g.

histogram(dfTemp$DayOfYear,breaks=breaklist,type=count)

If I use hist to display this, all values are under 600, everything  
is fine..


If I use lattice histogram on the full 365 days, either with nint=365,
or breaks set from (0:366), I get 26 equally-spaced spurious peaks
above 800 (that is, 26 days reported with bad values).  A table
command on this field shows me that the highest count of rows in a day
is 553.  When I do hist (not histogram), the plot looks fine.  When I
do plot(table(dataframe$DayOfYear), the plot looks fine.  If I do a
subset of the data to look only at days below 340, the plot looks
fine.  At days below 341, I get one of these spikes, at about 170
days, going up to about 900.  At a subset of days below 342, I get two
spikes, both over 900.

If I set breaks to 0:366, and add a small increment to my integer  
values, e.g.


histogram(df2006NonRecVessels$DayOfYear+. 
001,breaks=breaklist,type=count)


All is well.under this approach.


I have attempted to search to see if this is a known problem, but
don't find anything.

Also, I can get the count in each bin for hist as

xx=hist(df2006NonRecVessels$DayOfYear,breaks=breaklist)
xx$count  # this gives me the counts


I am unclear how to get equivalent information on bin contents from
the lattice-generated histogram object. It appears to be in
panel.args, but I am unclear on the exact syntax.


Richard M. Males
Cincinnati, Ohio, USA


__
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] proto naming clash?

2008-05-15 Thread Charilaos Skiadas


On May 15, 2008, at 1:24 PM, David Katz wrote:



Trying to learn Proto. This threw me:

#startup r...

library(proto)

a - proto(x=10)
a$x

[1] 10

x - proto(x=100)
x$x

Error in get(x, env = x, inherits = TRUE) : invalid 'envir' argument




Do I simply need to be careful to name proto objects and proto  
components

uniquely? Is this the desired behavior for proto objects?


The problem was just with naming a proto object x, it has nothing  
to do with the names of its components. It has been fixed in the  
newer version:


http://tolstoy.newcastle.edu.au/R/e4/help/08/01/0205.html

So you should just need to update the proto package.


Thanks.


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Inconsistent linear model calculations

2008-05-15 Thread Charilaos Skiadas

On May 15, 2008, at 5:37 PM, e-letter wrote:


Below is direct copy from command terminals of both pcs (mandrake 92
with r 171; mandriva 2008 with r 251, respectively).

R : Copyright 2003, The R Development Core Team
Version 1.7.1  (2003-06-16)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type `license()' or `licence()' for distribution details.

R is a collaborative project with many contributors.
Type `contributors()' for more information.

Type `demo()' for some demos, `help()' for on-line help, or
`help.start()' for a HTML browser interface to help.
Type `q()' to quit R.


dubious-read.table('/path/to/file/dodgy.csv')
dubious


  V1  V2V3V4V5   V6 V7
1  1 300 39.87 39.85 39.90 39.87333  9
2  2 400 45.16 45.23 45.17 45.18667 16
3  3 500 50.72 51.03 50.90 50.88333 25
4  4 600 56.85 56.80 57.02 56.89000 36
5  5 700 63.01 63.09 63.14 63.08000 49
6  6 800 69.52 69.82 69.63 69.65667 64


This is exactly why we asked you for a reproducible example and full  
code. That last entry in the V6 column is 69.65667 in this case, but  
66.27667 in the other cases. So you clearly are working with two  
slightly different dodgy files, and consequently two slightly  
different dubious data sets, and lm rightfully produces two slightly  
different accurate coefficients.


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College


lm(V6~V2+V7,data=dubious)


Call:
lm(formula = V6 ~ V2 + V7, data = dubious)

Coefficients:
(Intercept)   V2   V7
  2.553e+014.332e-021.480e-05





R version 2.5.1 (2007-06-27)
Copyright (C) 2007 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.


dubious-read.table('/path/to/file/dodgy.csv')
dubious

  V1  V2V3V4V5   V6 V7
1  1 300 39.87 39.85 39.90 39.87333  9
2  2 400 45.16 45.23 45.17 45.18667 16
3  3 500 50.72 51.03 50.90 50.88333 25
4  4 600 56.85 56.80 57.02 56.89000 36
5  5 700 63.01 63.09 63.14 63.08000 49
6  6 800 69.52 59.68 69.63 66.27667 64

lm(V6~V2+V7,data=dubious)


Call:
lm(formula = V6 ~ V2 + V7, data = dubious)

Coefficients:
(Intercept)   V2   V7
  1.937e+017.168e-02   -1.537e-05





Below is the csv file itself:

1 300 39.87 39.85 39.90 39.87333  9
2 400 45.16 45.23 45.17 45.18667 16
3 500 50.72 51.03 50.90 50.88333 25
4 600 56.85 56.80 57.02 56.89000 36
5 700 63.01 63.09 63.14 63.08000 49
6 800 69.52 59.68 69.63 66.27667 64

Enjoy! :)



__
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: left-aligned text in strips?

2008-05-14 Thread Charilaos Skiadas

On May 14, 2008, at 3:47 AM, RINNER Heinrich wrote:


[adapted repost of question
http://tolstoy.newcastle.edu.au/R/e4/help/08/03/6260.html]

Dear R community,

by default, text in the strips of a trellis plot is centered in the
strip.
Is there a way to have the text left-aligned?

For example:

library(lattice)
test - data.frame(x=rnorm(100), y=rnorm(100), a=rep(c(A: centered
text,B: centered text),50))
xyplot(y ~ x | a, data = test)  # ok, strip text is centered
test - data.frame(x=rnorm(100), y=rnorm(100), a=rep(c(A: left- 
aligned

text,B: left-aligned text (possibly lng
string),50))
xyplot(y ~ x | a, data = test)  # how???


Here's a way to do it, shamelessly stealing the main idea from:  
http://dsarkar.fhcrc.org/lattice/book/figures.html? 
chapter=10;figure=10_24


Mainly you just have to write your own strip function.

xyplot(Petal.Length~Petal.Width|Species, iris, strip=function 
(which.given,which.panel, factor.levels,...) {
  panel.rect(0, 0, 1, 1, col = trellis.par.get(strip.background) 
$col[which.given], border = 1)
  panel.text(x = 0, y = 0.5, pos = 4, lab = factor.levels[which.panel 
[which.given]])

} )

Better yet, you should probably write a more generic strip function  
that does what you want.


I would however consider using ?abbreviate for what you want to do  
instead.



I am using R 2.6.2 on Windows XP, package lattice Version 0.17-6.

[The reason I would like to do this is because in real life my
conditioning variable 'a' can have quite long strings as its value.  
I am

automatically creating a series of trellis plots, and in each one a
different number of panels will be produced (maybe 4, maybe  
20,...). So

in some cases (few panels, short labels) text in the strips will be
perfectly readable, while in some cases (many panels, long labels)  
only

the middle of the text will.
I know I could abbreviate the strip text by using something like:
xyplot(y ~ x | substr(a,1,35), data = test)
But there is no natural choice of string length here when I want to
cut off as few text as possible, so just left aligning the strip texts
would seem like a natural and easy(?) solution to me - if I was  
able to

do it...]

-Heinrich.


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] win.graph() with more than one Lattice plot

2008-05-14 Thread Charilaos Skiadas

Deepayan's new book to the rescue again:

http://lmdvr.r-forge.r-project.org/figures/figures.html? 
chapter=01;figure=01_04


Look at the code for this figure, especially the last two lines. Not  
sure that the fact that it's a win.graph device has much to do with  
this.


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On May 14, 2008, at 6:21 PM, Duncan Mackay wrote:


Paulo

you can use the layout command if you use the plot command or using  
lattice viewports and grid.layout.


I have not use layout or lattice equivalents for a while so am not  
upto date with correct syntax


Regards

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
ARMIDALE NSW 2351


At 06:53 15/05/2008, you wrote:
Is is possible to accomodate more than a single independent (not  
resulting

from arranjment of layout=c()) lattice graphs in a single win.graph()
device?
Thanks in advance,

PS Maybe duplicated

Paulo



De: [EMAIL PROTECTED] em nome de Roland Rau
Enviada: qua 14-05-2008 17:06
Para: '[EMAIL PROTECTED]'
Assunto: [R] strip white in character strings



Dear all,

I have several datasets and I want to generate pdf plots from them.
I also want to generate automatically the names of the files. They  
are

country-specific and the element mycurrentdata[1,1] contains this
information.

So what I do is something like this:
pdf(file=paste(mycurrentdata[1,1], .pdf, sep=), width=...etc)

The only problem I have is that some of the country names contain  
white

space (e.g., United Kingdom). This is no problem for generating the
pdf plots but it may become problematic during further processing  
(e.g.

incl. the plots in LaTeX documents).

Is there an easy function to strip white space out of character  
strings

(similar to the strip.white=TRUE option in read.table/scan)?

I'd appreciate any kind of help and I hope I did not miss anything
completely obvious.

Thanks,
Roland

__
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] fancy text in pairs()

2008-05-14 Thread Charilaos Skiadas


On May 14, 2008, at 9:28 PM, [EMAIL PROTECTED] wrote:


Dear List,

I'm currently trying to produce a number of pairs() plots with special
text labels in the diagonal panels giving the units for the various
quantities.
These labels stretch across multiple lines, with the names of the
quantities
and the symbols for the units on separate lines. This seems to be  
leading

to
problems with the justification of the text that I can't seem to  
work out.



The code below gives an example of what I have in mind with some
fake data and units to illustrate. Has anyone got some ideas on how
to modify my code so that I can have both the name of the quantity and
the symbol for the unit nicely centred within the diagonal panel, one
above the
other?

I'm running R 2.7.0 under windows XP.


#generate some fake data:
x1-rnorm(100, 10, 1)
x2-rnorm(100, 5, 1)
x3-rnorm(100, 100, 2)
X-cbind(x1, x2, x3)


#character vector of labels..
labs-c(
expression(paste(Pressure \n, (kg , m^-2,))),
expression(paste(Acceleration \n, (, m , s^-1, s^-1,))),
expression(paste(Concentration \n,(, mu, g, , L^-1,)))
   )

#make a pairs() plot of the data.
pairs(X, labels=labs, las=1, label.pos=0.5)



Try this:

labs - expression(atop(Pressure,(kg * m^-2)), atop(Acceleration, 
(m*s^-1*s^-1)),atop(Concentration,(mu*g*L^-1)))

pairs(X, labels=units, las=1, label.pos=0.5)


Thanks for any solutions or suggestions,

Michael Scroggie.



Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] test

2008-05-13 Thread Charilaos Skiadas

On May 13, 2008, at 5:52 AM, Esmail Bonakdarian wrote:


Tony Plate wrote:
You probably should check this section in your R-help subscription  
options (via https://stat.ethz.ch/mailman/options/r-help/, I think):

Receive your own posts to the list?




Tony,

Like jt I too have it set to receive my own messages, but I too
don't see them. I wonder if it has to do with the fact that both
of us use gmail to post to the list?


Bingo! Well, I don't know if this happens with the web interface to  
gmail, but if you use POP to access your gmail account, then any  
emails you send to any kind of list will not get back to you (Problem  
being, sort of, that gmail groups things in Conversations, and in  
this case will remember the email you sent out and use that copy in  
the conversation, instead of the one sent through the list. Not a  
very good excuse in my opinion, and a particularly irritating  
feature.). I wouldn't really expect them to fix it any time soon.


In the rare occasions  where my waiting powers get exhausted before  
someone on this very helpful list replies to my email, I just use the  
online archives to check whether my email was sent or not.



In any case, regardless if we see them, they are getting posted,
which is what matters :)

Cheers,
Esmail


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Format integer

2008-05-12 Thread Charilaos Skiadas

On May 12, 2008, at 5:22 PM, Anh Tran wrote:


Hi,
What's one way to convert an integer to a string with preceding 0's?
such that
'13' becomes '013'
to be put into a string

I've tried formatC, but they removes all the zeros and replace it with
blanks


formatC(13, width=10, format=d, flag=0)


Thanks

--
Regards,
Anh Tran


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Hashes as S4 Classes, or: How to separate environments

2008-05-10 Thread Charilaos Skiadas

On May 10, 2008, at 7:30 AM, Hans W Borchers wrote:

For learning purposes mainly I attempted to implement hashes/maps/ 
dictionaries
(Python lingua) as S4 classes, see the coding below. I came across  
some rough S4

edges, but in the end it worked (for one dictionary).

When testing ones sees that the dictionaries D1 and D2 share their  
environments
[EMAIL PROTECTED] and [EMAIL PROTECTED], though I thought a new and empty environment  
would be

generated each time 'new(Dict)' is called.

QUESTION: How can I separate the environments [EMAIL PROTECTED] and [EMAIL 
PROTECTED] ?


The problem you are encountering is that the prototype is only  
created once. Because environments are passed by reference, [EMAIL PROTECTED]  
and [EMAIL PROTECTED] are the exact same environment:


 D1 - new(Dict)
 D1
 [EMAIL PROTECTED]
environment: 0x182ac870
 D2 - new(Dict)
 [EMAIL PROTECTED]
environment: 0x182ac870

You have assumed that setClass will be executed for each new  
dictionary, or at least that the prototype(...) part of it would run  
each time. Not wanting right now to dig into the internals of  
setClass, my guess is that it only creates a prototype once, and then  
just reuses it each time, with something like an assignment operator.  
One solution, very similar to what Martin just suggested, is below. I  
believe another solution might be to have the hash be a list  
containing an environment, though I haven't tried that.


The solution is to create a constructor function, the function  
newDict below:


setClass(Dict,
representation (hash = environment))
)
newDict - function() {
obj - new(Dict)
[EMAIL PROTECTED] - new.env(hash=T, parent = emptyenv())
obj
}

In practice, you would probably want newDict to accept an arguments,  
which may be a list or another Dict object, and then use that as a  
starting point for the new hash.


Here's a sample run:

 #  Some tests 
 D1 - newHash()
 D2 - newHash()
 [EMAIL PROTECTED]
environment: 0x1e80c98
 [EMAIL PROTECTED]# Notice the different address
environment: 0x1e868fc
 hput(D1, a, 1)
 hget(D1, a)
[1] 1
 show(D1)
[1] a
 hput(D2, c, 3)
 hget(D2, a)  # Does the correct thing this time
NULL
 hget(D2, c)
[1] 3
 show(D2)
[1] c
 hclear(D2)
 show(D1)# Works properly now
[1] a
 #-

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

Reading the articles mentioned in Tipps and Tricks didn't help me  
really.

Of course, I will welcome other corrections and improvements as well.
Working in R 2.7.0 under Windows.

Hans Werner





#-- Class and method definition for dictionaries  
---


setClass(Dict,
representation (hash = environment),
prototype (hash = new.env(hash=T, parent = emptyenv()))
)

setMethod(show, signature(object=Dict),
definition = function(object) ls([EMAIL PROTECTED])
)

setGeneric(hclear, function(object) standardGeneric(hclear))
setMethod(hclear, signature(object=Dict),
function(object) rm(list=ls([EMAIL PROTECTED]), [EMAIL PROTECTED])
)

setGeneric(hput, function(object, key, value) standardGeneric 
(hput))
setMethod(hput, signature(object=Dict, key=character,  
value=ANY),

function(object, key, value) assign(key, value, [EMAIL PROTECTED])
)

setGeneric(hget, function(object, key, ...) standardGeneric(hget))
setMethod(hget, signature(object=Dict, key=character),
function(object, key) {
if (exists(key, [EMAIL PROTECTED], inherits = FALSE)) {
get(key, [EMAIL PROTECTED])
} else {
return(NULL)
}
}
)

#  Some tests 
D1 - new(Dict)
hput(D1, a, 1)   # Same as: [EMAIL PROTECTED] - 1
hput(D1, b, 2)
hget(D1, a)
hget(D1, b)
show(D1)

D2 - new(Dict)
hput(D2, c, 3)
hput(D2, d, 4)
hget(D2, a)  # Wrong: was defined only for D1
hget(D2, b)
show(D2)

hclear(D2) # Wrong: clears D1 too
show(D1)
#-


__
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] Is there in R a function equivalent to the mround, as found in most spreadsheets?

2008-05-09 Thread Charilaos Skiadas

On May 9, 2008, at 5:39 AM, Dieter Menne wrote:

Dr. Ottorino-Luca Pantani ottorino-luca.pantani at unifi.it  
writes:


Imagine that for a particular cuvette (I have 112 different  
cuvettes !!)
you have to mix the following volumes of solution A, B, and C  
respectively.


c(1803.02, 193.51, 3.47)

Each solution is to be taken with 3 different pipettes (5000, 250  
and 10
µL Volume max) and each of those delivers volumes in steps of 50  
µL,  5

µL  or 1µL, respectively



Since the above values  would eventually become

c(1800, 195, 3)

it is then necessary to recalculate all the final concentrations
of A, B and C, because the volumes are changed.


A first guess would be

a = c(1803.02, 193.51, 3.47)
round(a / 5)*5

which gives

1805  1955



If I understand the OP's question properly, the first value is to be  
a multiple of 50, the second a multiple of 5, and the third a  
multiple of 1. This can be done with this slight variation on the  
above theme:


a - c(1803.02, 193.51, 3.47)
b - c(50,5,1)
round(a/b) *b

This is not exactly what you want, but it shows that the problem is  
a bit
ill-defined. In the example you gave, why do you want 1800, and not  
1805, which
is possible with the pipettes? I assume that you laboratory  
experience is
working in the background, telling you to stop pipetmanning when  
you are close

to the result in some percentage feeling.

Dieter


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] LaTeX in system()

2008-05-08 Thread Charilaos Skiadas
This is exactly the problem: apps launched through the Finder do not  
go through the usual shell initialization process, where the PATH is  
typically set up. The two solutions would be to either use the full  
path to the command, or else start R.app from the Terminal, via the  
command:


open -a R

If you start R.app this way, it will get the same path as your shell.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On May 8, 2008, at 11:25 AM, Erik Iverson wrote:


Are you running R from the shell, or R.app?

I don't own or use a Mac, but I've seen something like this happen  
to people running R through ESS on some Emacs on a Mac.


Apologies for lack of precision here in terminology, but it had  
something to do with the PATH getting set through a shell  
initialization file (e.g., .cshrc, .bashrc).  Thus, starting in a  
shell, the path was set properly.  But the path was not set in the  
'Mac GUI environment', so things started 'from there' (i.e., by  
clicking something), did not know about the path.


If it is a situation like the above, it really has nothing to do  
with R directly.  If that is the problem, there is probably some  
way to set environment variables so that the Mac GUI shell knows  
about them.


HTH,
Erik Iverson

Christoph Heibl wrote:

Dear list,
I want to run latex from an R script:
system(latex mysource.tex)
or:
texi2dvi(mysource.tex, pdf = TRUE, clean = FALSE, quiet  
= TRUE, texi2dvi = latex)

but latex does not seem to be on the search path:
/bin/sh: line 1: latex: command not found.
Although 'printenv PATH' tells me that the usr/texbin is looked  
for executables:
/Library/Frameworks/Python.framework/Versions/Current/bin:/sw/bin:/ 
sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/texbin:/ 
usr/X11R6/bin Or am I wrong here?
In any case this is strange because if I call latex from the  
Terminal shell it runs without problems.  On the other hand  
texi2dvi from the tools package also does not work (for the same  
reason?)

I use R version 2.6.2 on Intel Mac OS X 10.4.11
Why is there a difference between the way the call to latex  
behaves directly in the shell or via the R system () command?

Thanks in advance for any advice!
Christoph

Christoph Heibl
Systematic Botany
Ludwig-Maximilians-Universität München
Menzinger Str. 67
D-80638 München
GERMANY
phone: +49-(0)89-17861-251
e-mail:[EMAIL PROTECTED]
http://www.botanik.biologie.uni-muenchen.de/botsyst/heibl/ch- 
home.html

SAVE PAPER - THINK BEFORE YOU PRINT


__
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] Is it possible to do fancy area plots?

2008-05-08 Thread Charilaos Skiadas

On May 8, 2008, at 9:11 PM, Sean Carmody wrote:

Does anyone have any ideas about how you could use R to produce a  
fancy area

plot like this one in the NY Times? http://tinyurl.com/6rr22g


I certainly hope not, I wouldn't want my favorite statistics program  
to produce an area graph where the sizes of the areas are not  
proportional to the percentages represented, and where the shapes of  
the areas are so irregular as to make effective area comparisons near  
impossible...


Unless my eyes are seriously deceiving me, which is quite possible.

It would be interesting however, to find out how such a graph is  
constructed. I wonder if hyperbolic geometry enters the picture.



Regards,
Sean,


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] building a formula string bit by bit ..

2008-05-06 Thread Charilaos Skiadas

I would actually go with this:

bits=c(1, 0, 1, 1, 0)
paste(X, which(bits==1), sep=.,collapse=+)

No need for the vars variable. Though admittedly it breaks down if  
bits is identically 0.


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On May 6, 2008, at 3:11 PM, Jorge Ivan Velez wrote:


Hi Esmail,

Try this:

vars=c('X.1', 'X.2', 'X.3', 'X.4', 'X.5')
bits=c(1, 0, 1, 1, 0)
paste(vars[which(bits==1)],collapse=+)

HTH,

Jorge



On Tue, May 6, 2008 at 3:06 PM, Esmail Bonakdarian  
[EMAIL PROTECTED]

wrote:


Hello,

Still a newbie with R, though I have learned a lot from reading
this list. I'm hoping someone can help with this question:

I have two vectors, one for variables, and one for bits.

I want to build a string (really a formula) based on the values in my
vector of 1s and 0s in bits. If I have a one, I want to include the
corresponding entry in the vars vector, otherwise ignore it. Of  
course

the bits vector will not stay the same.

So for example:

 vars=c('X.1', 'X.2', 'X.3', 'X.4', 'X.5')

 bits=c(1, 0, 1, 1, 0)
 ones=which(bits==1)

should yield:

 X.1 + X.3 + X.4

where as

 bits=c(1, 1, 0, 0, 0)

would yield

 X.1 + X.2

the which operator gives me the index values, is there an easy and
*efficient* way to build this string so that I can pass it on to glm?
I can probably hack some ugly code together to do this, but it won't
be efficient, and it won't be elegant :-)

Can anyone help?

Thanks!


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


Re: [R] figure margins too large for a barplot in png, pdf ok

2008-05-06 Thread Charilaos Skiadas

On May 6, 2008, at 10:43 PM, Alexy Khrabrov wrote:

I've used to have a script with a barplot command it in, preceded  
by a png:


png(graph.file,height=H,width=W)
barplot(t,names.arg=breaks[2:(length(t)+1)],tck=gridlines)

-- worked before R 2.6.2.  When I tried it in R 2.6.2, which I have  
for a while but didn't run with that script, it complained, the  
margins too large, and I've googled the messages from our list  
where neither height nor width had been specified.  Yet here they  
are specified here.


Calling same from R GUI draws the nice barplot in Quartz, and  
replacing png with pdf or postscript does fine.  Other graphs work  
fine with png.  Jpeg also complains; when I try various values for  
H or W, still the same -- how can I subdue the png?


What values do H,W have? Keep in mind, the numbers count pixels in  
png. And you have not given us a reproducible example.



Cheers,
Alexy


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Formating numbers

2008-05-05 Thread Charilaos Skiadas

On May 5, 2008, at 7:03 AM, pecardoso wrote:

Maybe a very, very basic question but how can I get a vector of  
values with the specific format:

001,002,010,100

instead of:
1,2,10,100


Not perfect, but might get you started:

sprintf(%03d,c(8:10,101))

or

formatC(c(8:10,101), width=3, flag=0)

For a better solution, so as not to hard-code the width:

paddedZeros - function(x) {
formatC(x, width=max(nchar(x)), flag=0)
}
paddedZeros(c(8:10,101))


Paulo


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

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

2008-04-30 Thread Charilaos Skiadas
Actually it's been out for a couple of weeks now at least. I just  
finished my first reading of it, and I must say it was spectacular.  
Congratulations Deepayan, the book gave me exactly the kind of  
lattice knowledge I needed, and then some. The graphics are really  
impressive and good illustrations of what lattice can do, and I found  
the writing very clear, with the complexity increasing at just the  
right speed. I definitely recommend it to anyone who wants to learn  
how to use lattice, at any level they desire.


Ok, I guess I better stop now. Happy reading Mark!

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Apr 30, 2008, at 4:51 PM, Mark Wardle wrote:


Dear all,

I haven't seen this mentioned and presumably Dr. Deepayan Sarkar is
too polite to advertise!

I just received a flyer from Springer: A new book on Lattice  
released today!!


http://www.springer.com/statistics/computational/book/ 
978-0-387-75968-5?cm_mmc=NBA-_-Apr-08_UK_1753460-_-product- 
_-978-0-387-75968-5


http://www.amazon.co.uk/exec/obidos/ASIN/0387759689/ 
ref=ord_cart_shr?%5Fencoding=UTF8m=A3P5ROKL5A1OLE


Well done and many congratulations. My order is being processed as  
we speak!


Best wishes,

Mark
--
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, 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.


Re: [R] Making a data frame into a factor ?

2008-04-15 Thread Charilaos Skiadas
I think you want to look into ?stack. For example:

x-data.frame(a=1:5,b=6:10)
y- stack(x)

Then x$values are the values, and x$ind is the factor.

On Apr 15, 2008, at 9:36 PM, Paul Lynch wrote:

 Hi,
I'm trying to do a linear regression style one-way ANOVA using some
 data in a data frame, and (perhaps because I am still relatively
 unfamiliar with both R and statistics) what I thought I should do was
 to make the data frame into a factor.  By that I mean that I have a
 data frame whose column labels are the levels of the factor, and the
 values in the frame are numeric values for the dependent variable.
I can construct the relevant vectors by hand, if I have to (and I
 guess I will start in that direction) but I am sure there must be 1-3
 line bit of R that could elegantly create the factor and the vector of
 values.
Thanks in advance,

 -- 
 Paul Lynch
 Aquilent, Inc.
 National Library of Medicine (Contractor)

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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 test if t[[cat]] exists ?

2008-04-15 Thread Charilaos Skiadas
On Apr 15, 2008, at 9:53 PM, Ng Stanley wrote:

 Hi,

 t - list(cat=1)
 exists(t)
 [1] TRUE
 exists(t[[cat]])
 Error: unexpected symbol in exists(t[[cat
 exists(t[[\cat\]])
 [1] FALSE

Perhaps what you want is:

cat %in% names(t)

 Thanks
 Stanley

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

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


Re: [R] Number of words in a string

2008-04-09 Thread Charilaos Skiadas

On Apr 9, 2008, at 1:27 PM, Hans-Jörg Bibiko wrote:


 On 09.04.2008, at 17:46, Shubha Vishwanath Karanth wrote:
 To put it simple,

 C=c(My Dog, Its really good, Beautiful)

 Now,
 SOMEFUNCTION(C) should give: c(My, Its really, )

 SOMEFUNCTION - function(x) gsub( *\\w+$, , x)

 But be aware that this won't work for instance for combining  
 diacritics.
 If you have this:

 C - c(My Dog, Its really good, Beautiful, Tuli faŝda)

 in fasda above the s is a combining circumfix ^

 would give

 [1] My Its reallyTuli faŝ

 Then one should use the strsplit approach.

How about:

SOMEFUNCTION - function(x) gsub( *\\S+$, , x)

 Cheers,

 --Hans

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] What to use for assignment, = or - ?

2008-04-06 Thread Charilaos Skiadas
On Apr 6, 2008, at 10:35 AM, Ben Bolker wrote:

  Bill.Venables at csiro.au writes:


 I've noticed an increasing tendency for people to use '=' rather than
 the older '-' symbol.  When '=' became available as an assignment
 operator in S-PLUS in the late '90s my first reaction was to  
 switch to
 it as well.  Brian Ripley warned me that it was not a good idea.  As
 usual he was right, but it took a couple of pretty serious
 finger-burning episodes before I came fully around to his view.

   [snip]
 I suspect the push towards using '=' instead of '-' has two main
 drivers:

 1. the world is full of lazy typists

 2. right now there seems to be a big influx of Matlab people into  
 R, and
 it makes them feel more at home.

 Neither of these is much of a reason, I reckon.


It may not be a good reason, but the reason I usually
 teach = rather than - to my students is that they are
 usually learning scripting/programming for the very first
 time, and the = syntax for assignment (which as I recall
 was called gozzinta, for goes into, in the FORTRAN coloring
 book) seems natural to most people (even though it's
 logically quite different).  They are so overwhelmed by
 learning new things that I don't want to add one more.
 (This is admittedly a judgment call.)

I actually teach my students to use -, for a number of reasons, but  
in some sense for the same reason you choose to teach = instead: I  
feel that - expresses better the act of assigning.

The problem really is that in mathematics we use = to denote both  
assignment and equality, and are forced to use words like let and  
define to indicate when an assignment is meant, which I suppose is  
not the norm. In other words, which one is meant is based on  
context. Context is perhaps a reasonable way to define things in  
mathematics, or most other non-programming settings really, but it is  
definitely not a very good way in programming settings, in my  
opinion. This is the problem with = in this case: It has different  
meanings depending on its context. This can lead to subtle errors,  
not easy to track down.

On another level, - brings up the severity of the act of assignment  
more clearly. You are about to overwrite whatever meaning that symbol  
had in the past, and replace it with a brand new meaning, and this  
can have a number of quite unpredictable side-effects. So it is not  
something that should be done lightly. In my opinion assignments  
should be used sparingly.

Now, you might argue that when students are first learning  
programming, we should make it as simple as possible for them. Though  
I do respect that view, I think it is also important to not teach  
them bad practices, and overdoing it on the assignments is such a  
bad practice, IMO. It's hard to change what one has learned early on  
and gotten used to. I've spent a lot of my teaching time trying to  
correct such bad habits on the part of my students, especially on the  
importance of making it clear, when writing down an equation, whether  
that equation is something we know, something we are trying to prove,  
or used as a definition for the LHS of it.

That's my story anyway, and I'm sticking to it.

Sorry if I strayed a bit off topic there

   Ben Bolker

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Definition of wrapper?

2008-03-30 Thread Charilaos Skiadas
On Mar 30, 2008, at 2:51 PM, Bryan Hanson wrote:

 I think I more or less understand what a “wrapper” is, but I’d like  
 to hear
 how more experienced R users define it, and especially I'd like to  
 know if
 there is a formal definition.  In my reading, it seems like there  
 are a
 fairly wide range of meanings, but they are all conceptually similar.

 I've looked in a couple of the classic R texts, the extensions and
 developers' manuals, and R help archives, and didn't find a  
 definition.  Of
 course, I may have missed it.

 Thanks in advance.  Bryan

This is a general programming question, likely. This might offer a  
starting point:
http://en.wikipedia.org/wiki/Wrapper_pattern

Greetings from Hanover, IN

 **
 Bryan Hanson
 Professor of Chemistry  Biochemistry
 DePauw University

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Sweave - print \n ?

2008-03-29 Thread Charilaos Skiadas
Try adding strip.white=false on the code chunks:

echo=false,results=tex, strip.white=false=
hline()
hline()
@

Read ?RweaveLatex for more settings.

or if you want this to happen in all code chunks add this early on in  
the rnw file:

\SweaveOpts{strip.white=false}

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Mar 29, 2008, at 4:54 AM, Werner Wernersen wrote:

 Thanks for your comments!
 I think using just one backslash for \n is correct
 because otherwise I get a \n literally printed out
 in the generated .tex code. But what I'm trying to get
 is just a line break, thus that the .tex code
 continues on a new line from the point where I put the
 \n.

 All the best,
   Werner



 --- Abhijit Dasgupta [EMAIL PROTECTED]
 schrieb:

 you haven't escaped the \ for the \n, I think. Your
 line should be
 cat(\\hline \\n). You did escape the \ for hline,
 though.

 Abhijit Dasgupta, Ph.D
 Assistant Professor | Division of Biostatistics
 Dept of Pharmacology and Experimental Therapeutics |
 Thomas Jefferson
 University
 1015 Chestnut St | Suite M100 | Philadelphia PA
 19107
 Ph: (215) 503-9201 | Fax: (215) 503-3804
 adasgupt (at) mail (dot) jci (dot) tju (dot) edu

 -- 
 --
 The documents accompanying this transmission may
 contain confidential
 health or business information. This information is
 intended for the use
 of the individual or entity named above. If you have
 received this
 information in error, please notify the sender
 immediately and arrange
 for the return or destruction of these documents.

 -- 
 --


 Werner Wernersen wrote:
 Hi,

 this is probably quite stupid but I have no clue
 what's wrong. Let's say I write the function
 hline - function() {
   cat(\\hline \n)
 }
 and call hline() from within a Sweave chunk. Why
 is
 there no carriage return after the \hline in the
 resulting tex file?

 if I call hline() hline() in the chunk, then I get
 \hline \hline
 in the tex code without a linebreak in between.

 Thanks for any hints,
   Werner


__
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 as Trellis graphic

2008-03-28 Thread Charilaos Skiadas
On Mar 28, 2008, at 2:42 AM, Agustin Lobo wrote:

 Thanks for your detailed explanation.
 You are right, a set of boxplots done with bwplot
 is a much better graphic for this type of data:

 bwplot(V1~VAR|f,data=datos2)

 This was not a good example. The barplot would be suited
 for counts, ie. species composition:
 datos4 - data.frame(V1=round(runif(200,1,5)),SITE=factor(round 
 (runif(200,1,3

 where I would like a barplot of table(V1) for each site:
 par(mfrow=c(3,1))
 barplot(table(datos4$V1[datos4$SITE==1]))
 barplot(table(datos4$V1[datos4$SITE==2]))
 barplot(table(datos4$V1[datos4$SITE==3]))

 I'll try with barchart!

Perhaps this:

datos5 - with(datos4,aggregate(rep(1,nrow(datos4)), list 
(V1=V1,SITE=SITE),sum))
barchart(x~ordered(V1)|SITE, data=datos5)

 Is there an R guide to Trellis graphics?

I found Paul Murrell's book useful.

 Agus

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

 Charilaos Skiadas escribió:
 On Mar 27, 2008, at 1:47 PM, Agustin Lobo wrote:
 Thanks, it was a matter of reshaping the data matrix as I usually  
 have
 it, ie:
 datos -
 data.frame(x=abs(round(rnorm(100,10,5))),y=abs(round(rnorm 
 (100,2,1))),f=factor(round(runif(100,1,3

 to become:

 datos2 -
 data.frame(V1=c(datos[,1],datos[,2]),VAR=c(rep(x,100),rep(y, 
 100)),f=factor(c(datos[,3],datos[,3])))

 and then
 require(lattice)
 barchart(V1~VAR|f,data=datos2)

 I get horizontal lines in the bars that I do not understand, though.
 In order to understand the lines , you should ask: What does the  
 height of each bar correspond to? As you have set things up, the  
 x bar in panel 1 should somehow correspond to the all values:
 datos2$V1[datos2$VAR==x  datos2$f==1]
 [1] 15 13 14  1 18 14  8 12  7 19 10  1  5 14  7  9 14  7  5 10  6  
 12 10 11 11  7 15
 [28]  9  4 12 17 10  4  5
 So you should ask yourself, how you expect R to produce a single  
 column, which in some sense corresponds to just one single number,  
 its height, from these different values. My guess is that you want  
 R to show you just the mean on each group. For me this is not a  
 barplot, but anyway. What happens in the barplot you have now, I  
 think, is this that R will start by constructing a bar with height  
 15, then put on it a bar of height 13, then on it a bar of height  
 14 and so on. So the lines you see account for the boxes that  
 survive:
   x-datos2$V1[datos2$VAR==x  datos2$f==1]
   unique(cummax(rev(x)))
 [1]  5 10 17 19
 I would recommend using boxplots instead of barplots only showing  
 the means. If you really want barplots of the means, I think you  
 can do the following:
 datos3 - with(datos2, aggregate(x=V1, by=list(VAR=VAR,f=f), mean))
 barchart(x~VAR|f, datos3)
 Another option would be ggplot2 I think, but I'll let someone  
 knowledgeable with that package speak up.
 Agus

 Haris Skiadas
 Department of Mathematics and Computer Science
 Hanover College

 -- 
 Dr. Agustin Lobo
 Institut de Ciencies de la Terra Jaume Almera (CSIC)
 LLuis Sole Sabaris s/n
 08028 Barcelona
 Spain
 Tel. 34 934095410
 Fax. 34 934110012
 email: [EMAIL PROTECTED]
 http://www.ija.csic.es/gt/obster

__
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 as Trellis graphic

2008-03-27 Thread Charilaos Skiadas

On Mar 27, 2008, at 1:47 PM, Agustin Lobo wrote:

 Thanks, it was a matter of reshaping the data matrix as I usually have
 it, ie:
 datos -
 data.frame(x=abs(round(rnorm(100,10,5))),y=abs(round(rnorm 
 (100,2,1))),f=factor(round(runif(100,1,3

 to become:

 datos2 -
 data.frame(V1=c(datos[,1],datos[,2]),VAR=c(rep(x,100),rep(y, 
 100)),f=factor(c(datos[,3],datos[,3])))

 and then
 require(lattice)
 barchart(V1~VAR|f,data=datos2)

 I get horizontal lines in the bars that I do not understand, though.

In order to understand the lines , you should ask: What does the  
height of each bar correspond to? As you have set things up, the x  
bar in panel 1 should somehow correspond to the all values:

datos2$V1[datos2$VAR==x  datos2$f==1]
[1] 15 13 14  1 18 14  8 12  7 19 10  1  5 14  7  9 14  7  5 10  6 12  
10 11 11  7 15
[28]  9  4 12 17 10  4  5


So you should ask yourself, how you expect R to produce a single  
column, which in some sense corresponds to just one single number,  
its height, from these different values. My guess is that you want R  
to show you just the mean on each group. For me this is not a  
barplot, but anyway. What happens in the barplot you have now, I  
think, is this that R will start by constructing a bar with height  
15, then put on it a bar of height 13, then on it a bar of height 14  
and so on. So the lines you see account for the boxes that survive:

  x-datos2$V1[datos2$VAR==x  datos2$f==1]
  unique(cummax(rev(x)))
[1]  5 10 17 19


I would recommend using boxplots instead of barplots only showing  
the means. If you really want barplots of the means, I think you can  
do the following:

datos3 - with(datos2, aggregate(x=V1, by=list(VAR=VAR,f=f), mean))
barchart(x~VAR|f, datos3)

Another option would be ggplot2 I think, but I'll let someone  
knowledgeable with that package speak up.

 Agus


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Mean in bwplot

2008-03-23 Thread Charilaos Skiadas

On Mar 23, 2008, at 1:37 PM, Charilaos Skiadas wrote:

   panel.points(mean(x), y, col=red, ...)

Correction, this should have probably been:

   panel.points(tapply(x, y, mean), y, col=red, ...)

All this assuming you want horizontal boxplots.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] (no subject)

2008-03-23 Thread Charilaos Skiadas
As you have not given us a reproducible example (namely we don't  
really know what test is), there are likely better ways to do this  
than what I am about to suggest, and you can find examples in the  
relevant plot functions likely, but I think what you want can be  
achieved using ifelse:

  plot(test, col = ifelse(test[,1]8 , steelblue2 ,wheat2) )

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Mar 23, 2008, at 7:06 PM, Donna Tucker wrote:


 Is there any way to use more than one color or shape in the same  
 plot.  I would like to make the points different colors for various  
 levels of a variable.  I have tried a simple 'if' statement in the  
 plot command, but I get an error message.  Here is what I have  
 tried and the error message I get:  plot(test, if(test[,1]8)  
 col=steelblue2 else col=wheat2)Error in xy.coords(x, y, xlabel,  
 ylabel, log) :   'x' and 'y' lengths differIn addition: Warning  
 message:In if (test[, 1]  8) col = steelblue2 else col =  
 wheat2 :  the condition has length  1 and only the first element  
 will be usedI know 'x' and 'y' lenghths do NOT differ.  If I just  
 do plot(test), it works perfectly.  Is there any way to this? 
 Thanks,Donna

__
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] setAs vs setIs

2008-03-16 Thread Charilaos Skiadas

On Mar 16, 2008, at 8:12 PM, Christophe Genolini wrote:

 Hi the list

 I am fighting with the twins setAs and setIs...

 Here are some questions and comments (comments to myself but that  
 migth
 be wrong, it is why I am posting them)
 1. Very surprising : using setIs define 'is', 'as-' but not 'as' ???
 2. Using setAs define 'as', 'as-' but not 'is'...
 What surprise me is that as- can be define by both. I would have  
 thing
 that setis is for 'is', setAs is for 'as' and 'as-'...
 Since it is not the case, is there a possibility to set with only one
 function 'as', 'is' and 'as-'

 Last point, I get a warning using setAs. I did not manage to find the
 name of the variable it want me to use...

 ### Data
 setClass(B,representation(b=numeric))
 setClass(C,representation(c=numeric))
 setClass(D,representation(d=numeric))
 b - new(B,b=3)
 c - new(C,c=4)
 d - new(D,d=5)

 ### using setIs
 setIs(C,B,
 test=function(object){return([EMAIL PROTECTED]0)},
 replace=function(from,values){
 [EMAIL PROTECTED] - [EMAIL PROTECTED]
 return(from)
 }
 )
 is(c,B) #Ok
 as(c,B) #not ok

It seems to me your problem here is simply that you did not define a  
coerce cal in setIs, so it does not know how to turn a C object into  
a B object, which is what you ask it to do here. It knows how to test  
if C object is also a B object, because of the test function you  
provided, and it can do the replacement you ask it in as(c,B) -b  
because of the replace command you provided, but the third part is  
missing. Perhaps something like this:
setIs(C,B,
test=function(object){return([EMAIL PROTECTED]0)},
replace=function(from,values){
[EMAIL PROTECTED] - [EMAIL PROTECTED]
return(from)
},
coerce=function(from) {
new(B,[EMAIL PROTECTED](1/3))
}
)


 as(c,B) - b#ok (!)

 ### using setAs
 setAs(D,B,
 function(from,to){to-new(B,[EMAIL PROTECTED]);return(to)},
 replace=function(from,values){
 [EMAIL PROTECTED][EMAIL PROTECTED];
 return(from)
 }
 )
 is(d,B) # not ok
 as(d,B) # ok
 as(d,B)-b  # ok


 Thanks

 Christophe

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Sealed for setGeneric

2008-03-13 Thread Charilaos Skiadas
On Mar 13, 2008, at 5:04 AM, Christophe Genolini wrote:

 Hi the list

 When two setGeneric occurs on the same function, the second erage the
 first and erase all the function previously define.
 Is it possible to prevent that ? Is it possible to declare a  
 setGeneric
 that can not be erased later ?
 Something like the |sealed for setMethod...|
 ||
 |Thanks|
 ||
 Christophe

Does this answer your questions?
http://www1.maths.lth.se/help/R/setGenericS3/

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Odp: comparing two columns of a dataset on a graph

2008-03-10 Thread Charilaos Skiadas
On Mar 10, 2008, at 5:15 AM, Petr PIKAL wrote:

 Hi
 [EMAIL PROTECTED] napsal dne 10.03.2008 08:12:28:

 hello

 I want to compare the values of two columns of a dataset on a graph.
 Which graphic do you recommend ?

 It depends on what values you have and what you want to compare.

 plot(x,y)

 boxplot(x, y)

 There are plenty other options in R.

When it comes to these, I prefer plot(y~x, data=dataset), since it  
picks up the correct graph depending on what types the variables have.

 Regards
 Petr

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Calling plot with a formula, from within a function, using ..., and xlim

2008-03-09 Thread Charilaos Skiadas
I ran into a weird, to me at least, problem, and hoping someone can  
shed some light into it. In a nutshell, there seems to be some  
problem when one calls plot with a formula, from within another  
function, using ... to pass arguments, and one of those arguments  
being xlim (and only xlim shows this problem). Here is an example:

  plotw - function(obj,...) {
+   plot(k~j, data=obj,...)
+ }
  plotw2 - function(obj,...) {
+   plot(obj$j,obj$k, ...)
+ }
  df - data.frame(j=1:3,k=1:3)
  plotw(df, las=1, xaxs=i)
  plotw(df, xlim=c(0,4))
Error in eval(expr, envir, enclos) :
   ..1 used in an incorrect context, no ... to look in
  plotw2(df, las=1, xaxs=i)
  plotw2(df, xlim=c(0,4))


I was guessing this might be related to some sort of argument  
matching, but I don't see why xaxs doesn't cause a problem in that  
case. So I am somewhat puzzled.

Thanks in advance.
Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

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


Re: [R] R error: Not able to launch R 2.6.2

2008-03-09 Thread Charilaos Skiadas
On Mar 9, 2008, at 12:12 PM, Keizer_71 wrote:


 Hi Everyone,

 I am having trouble using R. I am not sure what happen but when i  
 start R, i
 am getting error message

 Fatal Error: Unable to restore saved data in .RData.

Just google for unable to restore saved data in .RData. , and you  
are likely to find many posts discussing this.

 -I restarted my pc but still same error
 -I reinstall R but still same error
 -deleted the R folder and have a fresh re-install but still same  
 issue.

 I am not sure what else i can do.

 any advice?
 -- 
 View this message in context: http://www.nabble.com/R-error%3A-Not- 
 able-to-launch-R-2.6.2-tp15942837p15942837.html
 Sent from the R help mailing list archive at Nabble.com.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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 navigate in layout() created graph?

2008-03-07 Thread Charilaos Skiadas
On Mar 7, 2008, at 7:18 AM, Rainer M Krug wrote:

 Hi

 I created a complex layout with using layout() and it looks exactly as
 I need it. But I don't want to print in the order in which the
 subfigure are numbered, but in a different order.

 How can I navigate in the layout so that I can specify the subfigure
 in which to plot?

 At the moment I am using a function which is converting the number to
 mfg parameter for par, but it does not seem to work as expected.

 Thanks,

 Rainer


Look at documentation of ?layout. The mat argument determines the  
order in which the figures appear. The example code that talks about  
scatterplot with marginal histograms should show you how that works.

In other words, to the best of my knowledge, you specify in the call  
to layout in which order the new figures you create will be filling  
the layout.


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

 Plant Conservation Unit Department of Botany
 University of Cape Town
 Rondebosch 7701
 South Africa

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] training svm

2008-03-07 Thread Charilaos Skiadas
On Mar 7, 2008, at 2:17 AM, Oldrich Kruza wrote:

 Hello Soumyadeep,

 if you store the data in a tabular file, then I suggest using standard
 text-editing tools like cut (say your file is called data.csv, fields
 are separated with commas and you want to get rid of the third and
 sixth column):

 $ cut --complement --delimiter=, --fields=3,6  data.csv   
 data_cut.csv

 If you're not in an Unix environment but have perl, then you may use a
 script like:

  open SRC, data.csv or die(couldn't open source);
  open DST, data_cut.csv or die(couldn't open destination);
  while (SRC) {
  chomp;
  @fields = split /,/;#substitute the comma for the  
 delimiter you use
  splice @fields, 2, 1;#get rid of third column (they're
 zero-based, thus 2 instead of 3)
  splice @fields, 5, 1;#get rid of sixth column
  print DST join(,, @fields), \n;
  }

 If you need to do the selection within R, then you can do it by
 indexing the data structure. Suppose you have the data in a data.frame
 called data. Then:

 data - data[,-6]
 data - data[,-3]

 might do the trick (but since I'm not much of an R hacker, this is
 without guarantee). I think it might be better however to do the
 preprocessing before the data get into R because then you avoid
 loading the columns to discard into memory.

I am guessing that the data is already in R, so it should be easier  
to do it in R, especially if he doesn't know which columns are the  
ones with all identical values. For instance, suppose the data set is  
called x. Then the following would return TRUE for the columns that  
have all values the same:

allsame - sapply(x,function(y) length(table(y))==1)

and then the following will take them out

newdata - x[,!allsame]

 Hope this helps
 ~ Oldrich

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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 navigate in layout() created graph?

2008-03-07 Thread Charilaos Skiadas
On Mar 7, 2008, at 8:02 AM, Rainer M Krug wrote:

 On 07/03/2008, Charilaos Skiadas [EMAIL PROTECTED] wrote:
 On Mar 7, 2008, at 7:18 AM, Rainer M Krug wrote:

 Hi

 I created a complex layout with using layout() and it looks  
 exactly as
 I need it. But I don't want to print in the order in which the
 subfigure are numbered, but in a different order.

 How can I navigate in the layout so that I can specify the subfigure
 in which to plot?

 At the moment I am using a function which is converting the  
 number to
 mfg parameter for par, but it does not seem to work as expected.

 Thanks,

 Rainer



 Look at documentation of ?layout. The mat argument determines the
  order in which the figures appear. The example code that talks about
  scatterplot with marginal histograms should show you how that works.

  In other words, to the best of my knowledge, you specify in the call
  to layout in which order the new figures you create will be filling
  the layout.

 Yes - I know that I can define the order when I call layout(mat=...,
 ...), but is there any way that I can skip one when plotting and
 return to plot that one later? (e.g. plot subfigure 1, then 3 and
 finally 2)

Only if you number them in the right order. You might have better  
luck using split.screen, and the associated screen command, for  
what you are trying to do.

I'm not sure I understand it, why don't you want to just number the  
subfigures in the order in which you will draw them?




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

 Plant Conservation Unit Department of Botany
 University of Cape Town
 Rondebosch 7701
 South Africa


 Haris Skiadas
  Department of Mathematics and Computer Science
  Hanover College


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

 Plant Conservation Unit Department of Botany
 University of Cape Town
 Rondebosch 7701
 South Africa

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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 navigate in layout() created graph?

2008-03-07 Thread Charilaos Skiadas
On Mar 7, 2008, at 8:41 AM, Rainer M Krug wrote:


  I'm not sure I understand it, why don't you want to just number the
  subfigures in the order in which you will draw them?

 Because i thought it would be easier the other way round? Thanks  
 anyway

Yes, I agree it should not be as hard as it is ;). I am guessing  
there might be some technical reasons why layout doesn't make it easy  
to do this.
split.screen is good for that.

 Rainer

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] locate the rows in a dataframe with some criteria

2008-03-07 Thread Charilaos Skiadas
On Mar 7, 2008, at 10:50 AM, zhihuali wrote:


 Hi, netters,

 This is probably a rookie question but I couldn't find the answer  
 after hours of searching and trying.

 Suppose there'a a dataframe M:

 x y
 10   A
 13   B
 8 A
  11   A

 I want to locate the rows where x =10 and y=A. I know how to do  
 it to vectors by using
 which, but how to do it with the dataframe?


Does ?subset do what you want?

 Thank you very much!


 Zhihua Li


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

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


Re: [R] R-Logo in \LaTeX

2008-03-06 Thread Charilaos Skiadas
On Mar 6, 2008, at 1:49 PM, Mag. Ferri Leberl wrote:

 Dear everybody!
 Is there a command in \LaTeX to display the R-Logo or has anybody  
 made it up?
 Thank you in advance.

Isn't it just an image? Hence you would include it like one usually  
includes images. Or do you mean something else?

 Yours, sincerely
 Mag. Ferri Leberl

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] read stata data file

2008-03-06 Thread Charilaos Skiadas

On Mar 6, 2008, at 9:05 PM, John Taffe wrote:

 Dear R-help list,

 I'm new to R.  I tried to get R to read a Stata data file using the
 read.dta function in the package foreign, which I downloaded and
 extracted to C:\Program Files\R\R-2.6.2\library on my pc.

 I tried

 nora - read.dta(nora.dta)

 and got

 Error: could not find function read.dta

 I guess foreign needs to be installed.  How do you do this?

library(foreign)

or

require(foreign)


 John Taffe

 Biostatistician
 Centre for Developmental Psychiatry and Psychology
 Faculty of Medicine Nursing and Health Science
 Monash University, Australia

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

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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 inversion using solve() and matrices containing large/small values

2008-03-05 Thread Charilaos Skiadas
Sorry, I meant to send this to the whole list.

On Mar 5, 2008, at 8:46 AM, Charilaos Skiadas wrote:

 The problem doesn't necessarily have to do with the range of data.  
 At first level, it has to do with the simple fact that dfdb has  
 rank 6 at most, (7 at most in general, though in your case since  
 290=10*29, it is at most 6). Since matrix rank only goes down when  
 multiplying, your infomatrix is an 8x8 matrix, with rank at most 6  
 (7 if you were more lucky with that 290, still not good enough), so  
 it is certainly not invertible, even forgetting the computational  
 issues of computing the inverse.

 You would need either power smaller than 7, or a longer dosis  
 vector, I think.

 If you manage to make your problem in a case where dfdb is square,  
 then you just have to invert that, which might be easier, seeing  
 how it's a Vandermonde matrix.

 Haris Skiadas
 Department of Mathematics and Computer Science
 Hanover College

 On Mar 5, 2008, at 8:21 AM, gerardus vanneste wrote:

 Hello

 I've stumbled upon a problem for inversion of a matrix with large  
 values,
 and I haven't found a solution yet... I wondered if someone could  
 give a
 hand. (It is about automatic optimisation of a calibration  
 process, which
 involves the inverse of the information matrix)

 code:

 *
 macht=0.8698965
 coeff=1.106836*10^(-8)

 echtecoeff=c 
 (481.46,19919.23,-93.41188,0.5939589,-0.002846272,8.030726e-6
 ,-1.155094e-8,6.357603e-12)/1000
 dosis=c(0,29,70,128,201,290,396)


 dfdb -
 array(c 
 (1,1,1,1,1,1,1,dosis,dosis^2,dosis^3,dosis^4,dosis^5,dosis^6,dosis^7) 
 ,dim=c(7,8))

 dfdbtrans = aperm(dfdb)
 sigerr=sqrt(coeff*dosis^macht)
 sigmadosis = c(1:7)
 for(i in 1:7){
 sigmadosis[i]=ifelse(sigerr[i]2.257786084*10^(-4),2.257786084*10^ 
 (-4),sigerr[i])

 }
 omega = diag(sigmadosis)
 infomatrix = dfdbtrans%*%omega%*%dfdb
 **

 I need the inverse of this information matrix, and

 infomatrix_inv = solve(infomatrix, tol = 10^(-43))

 does not deliver adequate results (matrixproduct of infomatrix_inv  
 and
 infomatrix is not 1). Regular use of solve() delivers the error  
 'system is
 computationally singular: reciprocal condition number: 2.949.10^ 
 (-41)'


 So I went over to an eigendecomposition using eigen(): (so that  
 infomatrix =
 V D V^(-1) == infomatrix^(-1)= V D^(-1) V^(-1) )
 in the hope this would deliver better results.)

 ***
 infomatrix_eigen = eigen(infomatrix)
 infomatrix_eigen_D = diag(infomatrix_eigen$values)
 infomatrix_eigen_V = infomatrix_eigen$vectors
 infomatrix_eigen_V_inv = solve(infomatrix_eigen_V)
 ***

 however, the matrix product of these are not the same as the  
 infomatrix
 itself, only in certain parts:

 infomatrix_eigen_V %*% infomatrix_eigen_D %*% infomatrix_eigen_V_inv
 infomatrix


 Therefore, I reckon the inverse of eigendecomposition won't be  
 correct
 either.

 As far as I understand, the problem is due to the very large range  
 of data,
 and therefore results in numerical problems, but I can't come up  
 with a way
 to do it otherwise.


 Would anyone know how I could solve this problem?



 (PS, i'm running under linux suse 10.0, latest R version with MASS  
 libraries
 (RV package))

 F. Crop
 UGent -- Medical Physics

  [[alternative HTML version deleted]]






Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] types of vectors / lists

2008-03-05 Thread Charilaos Skiadas
On Mar 5, 2008, at 2:56 PM, [EMAIL PROTECTED] wrote:

 Hello,

 I am an advanced user of R. Recently I found out that apparently I do
 not fully understand vectors and lists fully
 Take this code snippet:


 T = c(02.03.2008 12:23, 03.03.2008 05:54)
 Times = strptime(T, %d.%m.%Y %H:%M)
 Times # OK

Far from OK, which is where your misunderstanding starts. Times is a  
POSIXlt object, and behaves as such, not as a vector and not as a  
list. Rather, a bit of both.
The output you see is the result of print(Times), which calls  
print.POSIXlt(Times), which is:

function (x, ...)
{
 print(format(x, usetz = TRUE), ...)
 invisible(x)
}
environment: namespace:base


This in turn calls format.POSIXlt(Times), which is pretty complicated  
and I'll omit here, but point is what you see when you type Times is  
not the object TImes itself, but only what the writer of  
print.POSIXlt wants you to see. Similar to the output of lm, which is  
much less than what lm really contains.

Have a look at ?POSIXlt, which says:

Class POSIXlt is a named list of vectors representing  9  
vectors following.

Try:

names(Times)
Times$sec
Times$min


Now perhaps this helps understand the answers?

 class(Times)  # OK
 is.list(Times)# sort of understand and not understand that
 length(Times) # 9 ??? why is it length(Times[1]) ??

 Times[1] # OK

Not OK at all. This calls [.POSIXlt, look at:

`[.POSIXlt`

In particular, try Times[2], Times[3] etc

Times[[1]] is the same as Times$sec
Times[[2]] is the same as Times$min
and so on.


 Times[[1]] # Wrong


 so Times is a vector-style thing of a non-atomic type.
 What puzzles me is first that is.list returns true, and more  
 importantly
 that the length-query returns the length of the first object of that
 apparent list and not how many elements are contained (i.e., I would
 have expected 2 as result - and I do not know what syntax to use in
 order to get the 2).

 Moreover, if the whole thing is part of a data.frame:

 DFTimes = as.data.frame(Times)
 dim(DFTimes)
 length(DFTimes$Times)  # OK, 2

 then everything is as expected.

 Could anyone please clearify why is.list returns true and why  
 length in
 the first example returns 9 ? Is it that c() makes a list if the  
 objects
 to be concatenated are not representable directly by atomic types ?

 thanks,
 Thomas


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] connectivity measure for graph nodes

2008-03-04 Thread Charilaos Skiadas
Mark,

if I understand what you are asking, then you likely want either the  
Floyd-Warshall algorithm:

http://en.wikipedia.org/wiki/Floyd-Warshall_algorithm

or Djikstra's algorithm

http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

The package igraph seems to have some useful methods, (The  
shortest.paths method is probably what you want, I think).

How large a graph are we talking about here?

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Mar 4, 2008, at 9:03 PM, Mark W Kimpel wrote:

 I am doing some work the Rgraphviz, a Bioconductor package, but  
 since my
 question is of a more general nature, thought I would send to this  
 list
 in hopes that a graph theory expert could answer my question.

 I wish to do some statistics on node-node relationships. In  
 particular,
 I want to see if two connected nodes share a common property. I  
 believe
 that the more connected the two nodes are the more likely it  
 would be
 that they share the property. The graph is highly connected, with a
 large majority of nodes connected in some fashion.

 My first question is: can anyone make this real easy and tell me if  
 this
 has been done and how?

 If not, I need to start with developing a measure of connectedness  
 that
 includes degrees of separation and number of edges at each degree. The
 highest level of connectivity, with weighting 1, would be a first  
 order
 connection (the graph is undirected). Beyond that, of course, it gets
 more complicated. To begin, I need to identify the best path  
 between two
 nodes then characterize that path.

 Rgraphviz seems to have a fair amount of rendering capabilities, but I
 don't see many functions to statistically analyze the graph.

 Thanks,
 Mark
 -- 

 Mark W. Kimpel MD  ** Neuroinformatics ** Dept. of Psychiatry
 Indiana University School of Medicine

 15032 Hunter Court, Westfield, IN  46074

 (317) 490-5129 Work,  Mobile  VoiceMail
 (317) 204-4202 Home (no voice mail please)

 mwkimpelatgmaildotcom


__
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] simulating the anova

2008-03-04 Thread Charilaos Skiadas

On Mar 5, 2008, at 12:03 AM, Will Holcomb wrote:

 I have been trying to figure out how to run a simple simulation of  
 the ANOVA
 and I'm coming up just a bit short. The code I've got is:

 cohen.f = .25
 groups = 4
 between.var = 19
 within.var =  between.var / cohen.f ^ 2
 n = 500
 sim.means = rnorm(n = groups, mean = 0, sd = sqrt(between.var))
 sim.data = lapply(sim.means, function(mean) rnorm(n = n, mean =  
 mean, sd =
 sqrt(within.var)))
 sim.anova = ?

 I'm pretty sure I've got data with the between group and within group
 variances that I want. I don't really know how to run an ANOVA on  
 it though.
 All the examples I've been able to find (with aov and anova)  
 require an
 explicit model. The ANOVA just tests the equivalence of means for a  
 set of
 groups, right? Can I not just tell it to give me the likelihood the  
 means
 are equal for all the columns without writing an explicit model.

I don't know if you can without writing an explicit model or not, but  
writing the model isn't that hard:

simdata2 - do.call(data.frame, sim.data)
names(simdata2) - LETTERS[1:4]
simdata3 - stack(simdata2)
fit - lm(values~ind, data=simdata3)
summary(fit)
anova(fit)

Unless I misunderstood what you wanted to do.

 Any help would be appreciated,
 Will

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] vertex labels in igraph from adjacency matrix

2008-03-04 Thread Charilaos Skiadas
On Mar 5, 2008, at 1:39 AM, Mark W Kimpel wrote:

 I am getting some unexpected results from some functions of igraph and
 it is possible that I am misinterpreting the vertex numbers. Eg., the
 max betweenness measure seems to be from a vertex that is not  
 connected
 to a single other vertex. Below if my code snippet:

 require(igraph)
 my.graph - graph.adjacency(adjmatrix = my.adj.matrix, mode=c 
 (undirected))

 most.between.vert - colnames(my.adj.matrix)[which(betweenness(graph =
 my.graph, v=V(my.graph), directed = FALSE) == max(betweenness(graph =
 my.graph, v=V(my.graph), directed = FALSE))) + 1]

What is the +1 for? Seems to me that this would give you the wrong  
vertex, since you find the vertex which is the max, and then you ask  
it to give you the next vertex in the list.

Btw, you will likely want to take the betweenness call out, and call  
it once and store the result, instead of calling it twice (well,  
assuming the graph is largish). Or even better, use which.max:

which.max(betweenness(graph = my.graph, v=V(my.graph), directed =  
FALSE))

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

 sum(my.adj.matrix[most.between.vertext,])
 0


 Is there a way to automatically set the vertex name attributes from  
 the
 row and colnames of the inputted adjacency matrix to graph.adjacency?
 This would seem like an intuitive feature, but I can't find it
 documented. In the absence of this feature, how can I make sure that I
 am setting the vertex name attributes correctly?
 -- 

 Mark W. Kimpel MD  ** Neuroinformatics ** Dept. of Psychiatry
 Indiana University School of Medicine

 15032 Hunter Court, Westfield, IN  46074

 (317) 490-5129 Work,  Mobile  VoiceMail
 (317) 204-4202 Home (no voice mail please)

 mwkimpelatgmaildotcom


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


Re: [R] Problem with lme4 use and installation

2008-03-03 Thread Charilaos Skiadas
Nothing's wrong. It just means that the package or one of its  
dependencies, has its own xtabs function, which hides the default  
xtabs function, since it comes first in the search path. So when you  
next write xtabs(...), it is this new xtabs that is being loaded. If  
you want to call the original xtabs, you can still do it I think with  
stats::xtabs(...).

This is a warning, not an error. It warns you that something you  
perhaps did not expect has just happened.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Mar 3, 2008, at 10:33 AM, Andreas Nord wrote:


 Dear all,

 I've been trying to install the lme4 package from
 http://r-forge.r-project.org/projects/lme4/. However, when wanting  
 to load
 the package, I get an message saying that x-tabs are masked (see  
 pasted
 code). Can anyone point to what has gone wrong?

 Kind regards,
 Andreas Nord
 Sweden

 utils:::menuInstallLocal()
 package 'lme4' successfully unpacked and MD5 sums checked
 updating HTML package descriptions
 library(lme4)
 Loading required package: Matrix
 Loading required package: lattice

 Attaching package: 'Matrix'


 The following object(s) are masked from package:stats :

  xtabs


 -- 
 View this message in context: http://www.nabble.com/Problem-with- 
 lme4-use-and-installation-tp15806404p15806404.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] read.zoo problem reading in date time

2008-03-03 Thread Charilaos Skiadas
On Mar 3, 2008, at 11:12 AM, stephen sefick wrote:

 x-read.zoo(SC2.csv, sep=, , format=%m%m/%d%d/%y%y%y%y %h%h:%m% 
 m)

 #Error in read.zoo(SC2.csv, sep = ,, format =
 %m%m/%d%d/%y%y%y%y %h%h:%m%m) :
 index contains NAs  Error message

You need header=TRUE in there, since your dataset has a header.

 what am I doing wrong SC2.csv is a comma seperated file.  The above
 data is right out out of the csv file, which is more like 30,000 rows.
  There are some NA for all of the variables except DateTime for a week
 here and a week there, but I can not find any missing dates.
 thanks

 stephen

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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:Export Data into Excel from R

2008-03-02 Thread Charilaos Skiadas
You will likely need to escape that backslash, i.e. c:\\foo.csv.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Mar 2, 2008, at 10:12 AM, Keizer_71 wrote:


 Hi,

 All i want is to export my list into c: drive and save it as csv  
 file and
 manually import into Excel.

 I have the read the article but i am having issues
 http://pbil.univ-lyon1.fr/library/base/html/write.table.html


 excel-write.table(probe_gene, file = c:\foo.csv, sep = ,,  
 col.names =
 NA)
 Error in file(file, ifelse(append, a, w)) :

 unable to open connection
 In addition: Warning message:
 cannot open file 'c:\foo.csv', reason 'Invalid argument'

 any suggestions?

 thanks,
 chris


 -- 
 View this message in context: http://www.nabble.com/Newbie%3AExport- 
 Data-into-Excel-from-R-tp15788950p15788950.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] listing components of an object

2008-03-02 Thread Charilaos Skiadas
On Mar 2, 2008, at 4:12 PM, Nair, Murlidharan T wrote:

 Is there a method to list the components of an object, instead of  
 looking at the help for that method?  Let me be more clear with an  
 example

 data(iris)
   ## tune `svm' for classification with RBF-kernel (default in svm),
   ## using one split for training/validation set

   obj - tune(svm, Species~., data = iris,
   ranges = list(gamma = 2^(-1:1), cost = 2^(2:4)),
   tunecontrol = tune.control(sampling = fix)
  )

   ## alternatively:
   ## obj - tune.svm(Species~., data = iris, gamma = 2^(-1:1), cost  
 = 2^(2:4))

   summary(obj)
   plot(obj)
 -
 For tune, an object of class tune, including the components:

 best.parameters a 1 x k data frame, k number of parameters.
 best.performance best achieved performance.
 performances if requested, a data frame of all parameter  
 combinations along with the corresponding performance results.
 train.ind list of index vectors used for splits into training and  
 validation sets.
 best.model if requested, the model trained on the complete training  
 data using the best parameter combination.

 I got the above by doing ?tune.

 Is there a function that helps be do this?

Usually str(obj), or possibly as.list(obj) for many objects, will  
give you the sort of information that I think you want, but what's  
wrong with ?tune ? In other words, why do you want this list?  
Typically, it is advisable that one uses methods to access the  
components of an object, like for instance coef(obj) for the  
coefficients in a model object. This is so that the internal  
representation of an object can change without breaking your code,  
and a host of other reasons.

 Thanks ../Murli

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] write.csv +RMySQL request

2008-02-29 Thread Charilaos Skiadas
The following worked for me (put together after reading ? 
textConnection). Put simply, all read/write command work with  
connections, which are if you like devices that know how to read  
or write things. textConnection creates such a device that writes  
(or reads if we used open=r) to/from an already existing vector.
If the file argument to write.csv is not a connection, then it is  
interpreted as a file name, and a connection to read/write on that  
file is automatically made for you. The description in ?write.csv  
explains this part.

x - character()
y-textConnection(x, open=w)
write.csv(iris,file=y)
close(y)

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Feb 29, 2008, at 4:37 AM, Tristan Casey wrote:

 Well that is certainly good news if write.csv output can be stored  
 directly to a character vector!

 I have tried to specify a vector within the file= argument for  
 example;

 write.csv(a,file=b) where b is a preexisting character vector

 This does not work. Do I need to define b as something else, like a  
 textConnection?


 Date: Fri, 29 Feb 2008 09:16:11 +
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 CC: [EMAIL PROTECTED]; r-help@r-project.org
 Subject: RE: [R] write.csv +RMySQL request

 On Fri, 29 Feb 2008, Tristan Casey wrote:

 Ahh, my apologies I must admit that I don't fully understand
 textConnections fully. I have been reading up on th RODBC package  
 as an
 alternative to RMySQL.

 With the file argument in write.csv, are you saying it is  
 possible to
 write the csv formated data directly to a cell in a MySQL  
 database? I am
 unsure what the variable 'con' must consist of.

 No, that it is possible to write it to an R character vector.

 Would this need to be a character string that initially connects  
 to the
 database (dbConnect) then pastes the MySQL query? I am unsure how to
 specify where the data is going with the file/connection argument.

 Thanks


 Date: Fri, 29 Feb 2008 08:44:58 +
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 CC: [EMAIL PROTECTED]; r-help@r-project.org
 Subject: RE: [R] write.csv +RMySQL request

 On Fri, 29 Feb 2008, Tristan Casey wrote:

 Thanks again for your help.

 I am wanting my variable to store a character string exactly as  
 the write.csv function would store as a csv text file;

 IE: My goal is to store a data frame of this construction;

 x1 x2
 1  2
 3 4

 as X1,X2,1,2,3,4 (the same format as CSV).

 I am aware of the file argument, however that is the problem,  
 storing to
 a physical text file and then importing into the SQL database  
 is a very
 inefficient way of doing things, especially when I can use  
 RMySQL to
 send commands directly to the database.

 You seem however unaware of text connections.  Neither of us  
 said anything
 about using a 'physical text file', and the documentation for
 write.csv says

  file: either a character string naming a file or a  
 connection open
for writing.  '' indicates output to the console.

 A 'text connection; is not a file (physical or otherwise).



 Kind Regards,

 Tristan Casey BPsySci (UQ)
 + 4 Festa Court, Capalaba, QLD 4157
 H 8/33 Lilly St, Greenslopes, QLD 4120
 0450 033 948



 Date: Fri, 29 Feb 2008 05:12:04 +
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 CC: [EMAIL PROTECTED]; r-help@r-project.org
 Subject: Re: [R] write.csv +RMySQL request

 On Thu, 28 Feb 2008, jim holtman wrote:

 ?capture.output

 myoutput - capture.output(write.csv(...))

 It would be better to write directly to a text connection: see  
 the 'file'
 argument to write.csv.

 On Thu, Feb 28, 2008 at 7:34 PM, Tristan Casey  
 [EMAIL PROTECTED] wrote:
 Hello,

 I am relatively new to R and learning its ins and outs. As  
 part of a website I am building, I need to read and write  
 csv files directly from an SQL database. Basically I want to  
 convert R variables (dataframes) into CSV format, store them  
 as another R variable (as a properly formatted text string  
 suitable for csv reading) and then send this to one row in a  
 database.

 The SQL part is fine, the problem arises because I cannot  
 capture the output of write.csv! It posts to the terminal  
 when file= is used, however I also want to store it. Does  
 anyone have any ideas?

 Thanks in advance!

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

 _
 Your Future Starts Here. Dream it? Then be it! Find it at  
 www.seek.com.au
 http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fninemsn%2Eseek% 
 2Ecom%2Eau%2F%3Ftracking%3Dsk%3Ahet%3Ask%3Anine%3A0%3Ahot% 
 3Atext_t=764565661_r=OCT07_endtext_Future_m=EXT

 --
 Brian D. Ripley,  

Re: [R] help

2008-02-29 Thread Charilaos Skiadas
Have a look at the documentation of ?.libPaths, it seems to me that  
setting the variable R_LIBS_USER is what you would want to do.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Feb 29, 2008, at 10:14 AM, Daoping Mo wrote:

 Dear Sir/Madam,

 I got some problem about using R.
 I am a student, and need to use R a lot. But sometimes when I am  
 working in
 computer lab, we can not install some particular pacakges by  
 ourselves because
 of the previliges.

 Can the folder of Librabry of R, move to, for instance the personal  
 folder, my
 documents... then we can install any specified package?

 Best regards,


 =

 Daoping Mo
 Via Real Collegio 30, CORPIE 10024, Moncalieri, Italy.
 Tel: +39 - 329-1865124 (Better after GMT 15:00, thanks!)
 Email: [EMAIL PROTECTED]


__
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] Running LaTeX dvi previewer on MacOS X

2008-02-29 Thread Charilaos Skiadas
On Feb 29, 2008, at 12:38 PM, Michael wrote:

 On 29 Feb 2008, Frank E. Harrell, Jr. wrote:

 Several people have given great advice on how to successfully use  
 X11 on
 Mac to so we can use the dvi previewer to view latex() output from
 Hmisc.  Now after a version upgrade of X11 and X11sdk we are getting
 lots of crashes.  I noticed a Mac dvi previewer with an executable
 stored as /Applications/TeX/TeXShop.app/Contents/MacOS/TeXShop

 Can we bypass X11 problems and point Hmisc to this executable for dvi
 viewing?

 I think TeXshop converts dvi to pdf (something like dvips -  
 ps2pdf) for
 viewing. Why not just use pdf for Mac?  Preview.app on Leopard does  
 do live
 updating.

And Skim.app does updating on Tiger, and is IMHO much better to  
Preview.app in other ways (works with pdfsync for instance, allows  
syncing back and forth between the pdf file and the corresponding tex  
source)

 From Preview, those pdf file can also be dragged to Pages ducument.

 Michael

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Running LaTeX dvi previewer on MacOS X

2008-02-29 Thread Charilaos Skiadas

On Feb 29, 2008, at 5:39 PM, Michael wrote:

 On 29 Feb 2008, Charilaos Skiadas wrote:

 On Feb 29, 2008, at 12:38 PM, Michael wrote:

 On 29 Feb 2008, Frank E. Harrell, Jr. wrote:

 Several people have given great advice on how to successfully use
 X11 on
 Mac to so we can use the dvi previewer to view latex() output from
 Hmisc.  Now after a version upgrade of X11 and X11sdk we are  
 getting
 lots of crashes.  I noticed a Mac dvi previewer with an executable
 stored as /Applications/TeX/TeXShop.app/Contents/MacOS/TeXShop

 Can we bypass X11 problems and point Hmisc to this executable  
 for dvi
 viewing?

 I think TeXshop converts dvi to pdf (something like dvips -  
 ps2pdf) for
 viewing. Why not just use pdf for Mac?  Preview.app on Leopard  
 does do
 live updating.

 And Skim.app does updating on Tiger, and is IMHO much better to
 Preview.app in other ways (works with pdfsync for instance, allows
 syncing back and forth between the pdf file and the corresponding tex
 source)

 We were not talking about using TeXshop to edit LaTeX files.   
 Rather the
 latex() function Hmisc generates a dvi file and the question is how  
 to view
 it since Mac does not have native dvi viewer (other than xdvi).   
 The pdfsync
 function of Skim or TeXshop is irrelevant.

Why is it important that the output file be a dvi file? Would it be a  
problem to have the latex() function produce a pdf file on mac systems?
I thought the latex() command was just producing tex code.

 Michael

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] Raw histogram plots

2008-02-27 Thread Charilaos Skiadas
On Feb 27, 2008, at 8:16 AM, Andre Nathan wrote:

 On Wed, 2008-02-27 at 14:15 +1300, Peter Alspach wrote:
 If I understand you correctly, you could try a barplot() on the  
 result
 of table().

 Hmm, table() does the counting exactly the way I want, i.e., just
 counting individual values. Is there a way to extract the counts  
 vs. the
 values from a table, so that I can pass them as the x and y  
 arguments to
 plot()?


x - table(rbinom(20,2,0.5))
plot(names(x),x)

should do it. You can also try just plot(x). Use prop.table on table  
if you want the relative frequencies instead.

 Thanks,
 Andre

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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] multi-level hierarchical logistic regression with sampling weight

2008-02-27 Thread Charilaos Skiadas
On Feb 27, 2008, at 11:04 PM, David Winsemius wrote:

 Rolf Turner [EMAIL PROTECTED] wrote in
 news:[EMAIL PROTECTED]:


 On 28/02/2008, at 11:28 AM, GUO, Qian wrote:

 Hi

 I would like to run a multi-level hierarchical logistic regression
 model with sampling weight? Is this possible with R?

  Yes.  In R, all things are *possible*. :-)

 Is this the right place for fortune() nominations?

Seconded, though this is very close:

  fortune(no if)

Evelyn Hall: I would like to know how (if) I can extract some of the  
information from the summary
of my nlme.
Simon Blomberg: This is R. There is no if. Only how.
-- Evelyn Hall and Simon 'Yoda' Blomberg
   R-help (April 2005)

I just love that one.

 -- 
 David Winsemius

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

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


  1   2   >