[R] How use a matrix method?

2009-04-19 Thread Grześ

Why when I want to find my value from matrix I get: 2,3,4,1,2? I think that I
should get: 1,2,3,4,7,8.

> macierz=matrix(1:4,7,8)
> macierz[[2]]
[1] 2
> macierz[[3]]
[1] 3
> macierz[[4]]
[1] 4
> macierz[[5]]
[1] 1
> macierz[[6]]
[1] 2


This is a similar situation:
> macierz=matrix(9,8,7,6)
> macierz[[1]]
[1] 9
> macierz[[2]]
[1] 9
> macierz[[3]]
[1] 9

Why not: 9,8,7
-- 
View this message in context: 
http://www.nabble.com/How-use-a-matrix-method--tp23116974p23116974.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] Binomial simulation

2009-04-19 Thread beetle2

Thank you for your help!
Yes you are right the probabilities are for the values 0 through 12.
I been asked to compare the simulated values to that of dbinom()
once again thanks!





Ranjan Maitra wrote:
> 
> This sounds like a potential homework problem. You don't quite need to
> simulate anything if your question is all you have been asked to do.
> 
> dbinom(x = 1:10, size = 10, prob = 0.25)
> 
> Perhaps you have been asked to simulate 1000 realizations and compare
> the relative frequencies with these probabilities: use 
> 
> rbinom(n = 1000, size = 10, prob = 0.25)
> 
> in that case and compare the relative frequencies.
> 
> Btw, there is a small chance of getting a 0. Are you sure the
> instructor (or whoever has issued the orders) wants only from 1:10?
> 
> HTH!
> Ranjan
> 
> On Fri, 17 Apr 2009 22:23:11 -0700 (PDT) beetle2
>  wrote:
> 
>> 
>> 
>> Not being entirely sure what you mean, I think 
>> 
>> rbinom(1000, 10, .25) 
>> 
>> may be what you want. 
>> 
>> Hi,
>> Thanks for your reply.
>> It is close to that but I need to know the probabilty of how many judges
>> pick a certain brand.
>> Just say x= 6 judges pick brand A which has P=0.25.
>> 
>> Using R it would be:
>> > dbinom(6,10,.25)
>> [1] 0.016222
>> 
>> Probability of six judges choosing  brand A. Hence not very likely.
>> 
>> I have been asked to do this for all values of x = 1 to 10.
>> But the question says to simulate 1000 trials for each x value.
>> I'm not sure how to construct the simulation.
>> regards
>> Brendan
>> 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/Binomial-simulation-tp23106347p23109522.html
>> Sent from the R help mailing list archive at Nabble.com.
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Binomial-simulation-tp23106347p23117793.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] Binomial simulation

2009-04-19 Thread beetle2

Sorry guys one quick question
I've graphed the histogram with
hist(rbinom(n = 1000, size = 10, prob = 0.25)) 
How to I sum the individual values 0 to 12?
regards
Brendan

beetle2 wrote:
> 
> Hi Guy's
> I was wondering if someone could point me in the right direction.
> 
> dbinom(10,1,0.25)
> 
> I am using dbinom(10,1,0.25) to calculate the probabilty of 10 judges
> choosing a certain brand x times. 
> 
> I was wondering how I would go about simulating 1000 trials of each x
> value ?
> 
> regards
> Brendan
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Binomial-simulation-tp23106347p23117871.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] Can't read table encoded in Unicode (R-2.8.1)

2009-04-19 Thread Hilmar Berger

Hi Duncan,
Thanks, this solves my problem.
Regards, Hilmar

Duncan Murdoch schrieb:

On 18/04/2009 1:18 PM, Hilmar Berger wrote:

Hi all,

I have problems reading Unicode (UTF-16) coded tables in R 2.8.1 
under Windows Vista.


Imagine the following table:

abcd
X1,21,31,4
Y2,22,32,4
Z3,23,33,4

Usually I would use the following code to read the table:

t = read.table("test.txt", header=T, sep="\t",dec=",")

This works well if I create the table using Notepad (the text will be 
in UTF-8 or ASCII, then).


I haven't tried 2.8.1 (which is obsolete, since yesterday :-), but in 
2.9.0 it works fine if I use the fileEncoding argument to read.table.


Duncan Murdoch


However, If I use e.g. OpenOffice scalc to create a spreadsheet 
holding the same data and save this data as text (using tabs as 
separators, no quotes and using Unicode encoding)  the command above 
gives this:


 > t = read.table("test.csv", header=T, sep="\t",dec=",")
 > t
  ÿþa
1  NA
2  NA
3  NA

I tried to play with the "encoding" parameter but that would not 
change anything.


The file from OpenOffice is in UTF-16, as shown by hexdump:
$ hexdump test.csv
000 feff 0061 0009 0062 0009 0063 0009 0064
010 000d 000a 0058 0009 0031 002c 0032 0009
020 0031 002c 0033 0009 0031 002c 0034 000d
030 000a 0059 0009 0032 002c 0032 0009 0032
040 002c 0033 0009 0032 002c 0034 000d 000a
050 005a 0009 0033 002c 0032 0009 0033 002c
060 0033 0009 0033 002c 0034 000d 000a
06e

I tried to read the file using file/readLines, which seemed to work 
after specifying the encoding:


 > a = file("test.csv",open="r", encoding="UTF-16")
 > b = readLines(a)
 > b
[1] "a\tb\tc\td"   "X\t1,2\t1,3\t1,4" "Y\t2,2\t2,3\t2,4" 
"Z\t3,2\t3,3\t3,4"


Looking at the code of readtable.R in R-2.8.1. and R-2.9.0 it seems 
that the encoding does not get passed through in the second call to 
scan() appearing in the code.


I'm not sure if this is a bug or if I'm doing something wrong here.

Regards,
Hilmar

--
My system  and R settings are:

 > sessionInfo()
R version 2.8.1 (2008-12-22)
i386-pc-mingw32

locale:
LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252 



attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base   
loaded via a namespace (and not attached):

[1] tools_2.8.1

 > Sys.info()
 sysname  
release  version nodename
   "Windows"  "Vista" "build 
6001, Service Pack 1"  "PC"
 machine
login user
   "x86" 
 > options("encoding")

$encoding
[1] "native.enc"

__
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] Binomial simulation

2009-04-19 Thread beetle2

I'm thinking I will just  use:
results <- rbinom(1000, 10, .25)
d = sum(results == 0 )
df = (d/1000)
df

And do each individually




beetle2 wrote:
> 
> Hi Guy's
> I was wondering if someone could point me in the right direction.
> 
> dbinom(10,1,0.25)
> 
> I am using dbinom(10,1,0.25) to calculate the probabilty of 10 judges
> choosing a certain brand x times. 
> 
> I was wondering how I would go about simulating 1000 trials of each x
> value ?
> 
> regards
> Brendan
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Binomial-simulation-tp23106347p23118747.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Question about rpart(sth~.,database)

2009-04-19 Thread Grześ

I have a standard database - HouseVotes84 
For example:
   Class   V1 V2 V3   V4 V5 V6 V7 V8 V9 V10  V11 V12 V13 V14 V15  V16
1 republicann  y  ny  y  y  n  n  n   yy   y   y   ny
2 republicann  y  ny  y  y  n  n  n   nn   y   y   y   n 
3 democrat   y  y   y  y  n  n  n   ny   n   y   y   nn
 .
 .
 .
end I build a tree like this: 
> hv.tree1=rpart(Class~.,HouseVotes84)
everything is ok! My question is:
What exactly mean "Class~.,"? 

Why when I use "Class~.," - then I get the best solution but when I use as a
parameter like this:
> hv.tree2=rpart(V2~.,HouseVotes84)
I also get solution but not such good like before.  
-- 
View this message in context: 
http://www.nabble.com/Question-about-rpart%28sth%7E.%2Cdatabase%29-tp23117162p23117162.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] Binomial simulation

2009-04-19 Thread beetle2

I've done some study.

And made a couple of loops to compare the dbinom() and rbinom()
 Here are the results:
The instructor only asked for 1000 trials so its not that accurate. but its
close to it.

> for(x in c(1:10))
+ {print(dbinom(x,10,.25)) }
[1] 0.1877117
[1] 0.2815676
[1] 0.2502823
[1] 0.145998
[1] 0.0583992
[1] 0.016222
[1] 0.003089905
[1] 0.0003862381
[1] 2.861023e-05
[1] 9.536743e-07
> 
> results <- rbinom(1000, 10, .25)
>  for (x in c(1:10) )
+ {d=sum(results == x)
+ df = (d/1000)
+ print(df)
+ }
[1] 0.173
[1] 0.279
[1] 0.274
[1] 0.15
[1] 0.059
[1] 0.013
[1] 0.004
[1] 0
[1] 0
[1] 0
> 


Thanks for pointing me to the rbinom() function
regards
Brendan















beetle2 wrote:
> 
> Hi Guy's
> I was wondering if someone could point me in the right direction.
> 
> dbinom(10,1,0.25)
> 
> I am using dbinom(10,1,0.25) to calculate the probabilty of 10 judges
> choosing a certain brand x times. 
> 
> I was wondering how I would go about simulating 1000 trials of each x
> value ?
> 
> regards
> Brendan
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Binomial-simulation-tp23106347p23118881.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How use a matrix method?

2009-04-19 Thread Peter Dalgaard

Grześ wrote:

Why when I want to find my value from matrix I get: 2,3,4,1,2? I think that I
should get: 1,2,3,4,7,8.


macierz=matrix(1:4,7,8)


That's

matrix(data=1:4, nrow=7, ncol=8)

a 7x8 matrix with the numbers 1 to 4 repeated columnwise.

You probably want something like matrix(c(1:4, 7, 8))

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

__
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] explicit documentation (was: get() versus getAnywhere())

2009-04-19 Thread Patrick Burns

Rolf Turner wrote:


On 17/04/2009, at 10:21 PM, Duncan Murdoch wrote:


Benjamin Tyner wrote:

Many thanks Duncan. Perhaps this merits a more explicit note in the
documentation?



The quote I gave is from the documentation.  How could it be more 
explicit?


This is unfortunately typical of the attitude of R-core people toward the
documentation.  ``It's clear.'' they say.  ``It's explicit.''  Clear and
explicit once you *know* what it's saying.  Not before, but.


I think this unfairly blames R-core for being human.
It takes dedication and a certain skill to be able to
write so that technical issues really are explicit to
those who are not tuned in. 


To demand that talent on top of all of the other talent
present in R-core seems a step too far to me.

I'm of the opinion that help files are among the most
difficult of literary forms.  They need to clearly
state the information, they need to be short enough that
some people might actually read them, they need to
cater to non-native speakers, and they need
to serve their purpose when the reader is frustrated.
(Who reads help files unless they are frustrated?)

It seems to me that help files are a bit like the old
saw about the weather: everyone complains but no one
does anything about it.

"Real" software companies have a documentation
department.  Perhaps there should be a documentation
department for R as well.


Patrick Burns
patr...@burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of "The R Inferno" and "A Guide for the Unwilling S User")


In this case the documentation is quite opaque to me, and I would suspect
to a good many like me.  Now that you have made it *genuinely* explicit,
I can understand what the documentation is saying.  Prior to that I 
wouldn't

have had a prayer of guessing that get() would sometimes find things that
getAnywhere() would not find.

Moreover, if getAnywhere() does not really mean ``get *anywhere*'' 
then its
name is misleading.  Surely it wouldn't be too tough to modify 
getAnywhere()

so that it really got anywhere.  E.g. get it to call get() when it can't
find an object with a given name?

cheers,

Rolf

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
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] get() versus getAnywhere()

2009-04-19 Thread Duncan Murdoch

On 18/04/2009 8:47 PM, Rolf Turner wrote:

On 17/04/2009, at 10:21 PM, Duncan Murdoch wrote:


Benjamin Tyner wrote:

Many thanks Duncan. Perhaps this merits a more explicit note in the
documentation?

The quote I gave is from the documentation.  How could it be more  
explicit?


This is unfortunately typical of the attitude of R-core people toward  
the

documentation.  ``It's clear.'' they say.  ``It's explicit.''  Clear and
explicit once you *know* what it's saying.  Not before, but.


But I didn't say that.  I asked how to make it more explicit.



In this case the documentation is quite opaque to me, and I would  
suspect
to a good many like me. 


What change would make it less opaque?

Duncan Murdoch

Now that you have made it *genuinely* explicit,
I can understand what the documentation is saying.  Prior to that I  
wouldn't
have had a prayer of guessing that get() would sometimes find things  
that

getAnywhere() would not find.

Moreover, if getAnywhere() does not really mean ``get *anywhere*''  
then its
name is misleading.  Surely it wouldn't be too tough to modify  
getAnywhere()

so that it really got anywhere.  E.g. get it to call get() when it can't
find an object with a given name?

cheers,

Rolf

##
Attention: 
This e-mail message is privileged and confidential. If you are not the 
intended recipient please delete the message and notify the sender. 
Any views or opinions presented are solely those of the author.


This e-mail has been scanned and cleared by MailMarshal 
www.marshalsoftware.com

##


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


Re: [R] How use a matrix method?

2009-04-19 Thread Grześ


Peter Dalgaard wrote:
> 
> Grześ wrote:
>> Why when I want to find my value from matrix I get: 2,3,4,1,2? I think
>> that I
>> should get: 1,2,3,4,7,8.
>> 
>>> macierz=matrix(1:4,7,8)
> 
> That's
> 
> matrix(data=1:4, nrow=7, ncol=8)
> 
> a 7x8 matrix with the numbers 1 to 4 repeated columnwise.
> 
> You probably want something like matrix(c(1:4, 7, 8))
> 
> -- 
> O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
>c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
>   (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
> ~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907
> 
> 
> I understand. Thank you very much!
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 


-- 
View this message in context: 
http://www.nabble.com/How-use-a-matrix-method--tp23116974p23121213.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Sweave: Changing the background color, adding a border

2009-04-19 Thread Christophe Genolini

Hi all,

I am using Sweave to produce a document. Unfortunately, I have to print 
several copies and I can't print them in color. So I would like to 
change the way of printing the code. I would like to print the code in a 
box with a black borderline and a grey background (quite classic). Is it 
possible to do it by changing some Schunk options?


Christophe

__
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: Changing the background color, adding a border

2009-04-19 Thread Duncan Murdoch

On 19/04/2009 6:03 AM, Christophe Genolini wrote:

Hi all,

I am using Sweave to produce a document. Unfortunately, I have to print 
several copies and I can't print them in color. So I would like to 
change the way of printing the code. I would like to print the code in a 
box with a black borderline and a grey background (quite classic). Is it 
possible to do it by changing some Schunk options?


It should be, if you know how to print things like that, but I don't 
Here's some code I wrote a while ago to modify the Sweave formats in a 
much simpler way:


% This removes the extra spacing after code and output chunks in Sweave,
% but keeps the spacing around the whole block.

\fvset{listparameters={\setlength{\topsep}{0pt}}}
\renewenvironment{Schunk}{\vspace{\topsep}}{\vspace{\topsep}}
% We want to avoid having examples switch us to an italic font shape.
\DefineVerbatimEnvironment{Soutput}{Verbatim}{fontshape=n}

Presumably some combination of \renewenvironment, \fvset (which sets 
fancyvrb parameters), or \DefineVerbatimEnvironment (a fancyvrb command) 
should do what you want.


Duncan Murdoch

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


[R] tcltk2 treectrl

2009-04-19 Thread _

Hi all,
I loaded the treectrl widget, but i can not add any elements oder styles.
Has anybody a little code snippet, please.

Thank you !

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


Re: [R] Sweave: Changing the background color, adding a border

2009-04-19 Thread Romain Francois

Christophe Genolini wrote:

Hi all,

I am using Sweave to produce a document. Unfortunately, I have to 
print several copies and I can't print them in color. So I would like 
to change the way of printing the code. I would like to print the code 
in a box with a black borderline and a grey background (quite 
classic). Is it possible to do it by changing some Schunk options?


Christophe


Hi Christophe,

This is not a trivial task, \Sinput and \Soutput environments are 
basically verbatim environments. You might want to have a look at the 
highlight package (not on CRAN yet) 
http://r-forge.r-project.org/R/?group_id=384 which ships a sweave driver 
that does some syntax highlighting of the code and does not rely on semi 
verbatim environments:


require( grid )
require( highlight, lib = "~/.R/library" )
v <- vignette( "grid", package = "grid" )
file.copy( v$file, "grid.Snw" )
Sweave( "grid.Snw", driver = HighlightWeaveLatex( ) )

See the result here: addictedtor.free.fr/misc/grid.pdf

The driver writes Hinput and Houtput environments instead of Sinput and 
Soutput, and they are defined as this in the preamble:


\newenvironment{Hinput}%
{}%
{}%
\newenvironment{Houtput}%
{}%
{}%

So you might imagine to redefine them using some combination of 
fcolorbox and minipage.


What happens with the box if the code spans more than one page ?

Romain

--
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr

__
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 rpart(sth~.,database)

2009-04-19 Thread Gavin Simpson

Grześ wrote:
I have a standard database - HouseVotes84 
For example:

   Class   V1 V2 V3   V4 V5 V6 V7 V8 V9 V10  V11 V12 V13 V14 V15  V16
1 republicann  y  ny  y  y  n  n  n   yy   y   y   ny
2 republicann  y  ny  y  y  n  n  n   nn   y   y   y   n 
3 democrat   y  y   y  y  n  n  n   ny   n   y   y   nn
 .
 .
 .
end I build a tree like this: 

hv.tree1=rpart(Class~.,HouseVotes84)

everything is ok! My question is:
What exactly mean "Class~.,"? 


It means include all remaining variables in HouseVotes84 on the rhs of 
the formula, i.e. as variables that should be used to predict the Class 
variable.




Why when I use "Class~.," - then I get the best solution but when I use as a
parameter like this:

hv.tree2=rpart(V2~.,HouseVotes84)


Why does this surprise you? You are now trying to predict the variable 
V2 (y/n) from Class and all remaining variables.


I also get solution but not such good like before.  


They are solutions to two different problems.

If you want to predict Class, then you need

Class ~ ., data = HouseVotes84

or, to specify exactly which variables to use as predictors of Class, 
state them explicitly:


Class ~ V1 + V3 + V4, data = HouseVotes84

I think you should look at the documentation that comes with R (An 
Introduction to R) or some of the contributed help documents on the R 
Website to read up on model formulae and how to represent models using 
this notation.


HTH

G

__
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] importing spreadsheet data - linera regression - panel data

2009-04-19 Thread Cecilia Carmo

Hi everyone and thank you for the help you could give me.

My data is in a spreadsheet. The 1st column identifies the 
firm (with the fiscal number), the columns 2 to 11 have 
the variable value for 11 years. I have many variables 
(files like this). Each file has about 40.000 firms 
(rows). I transformed all the files in txt files. The data 
is a panel data, like this:

firmrevenu2007  revenue2006 revenue2005 revenue2004 
revenue2003 revenue2002 revenue2001 revenue2000 revenue1999 
revenue1998 
500100144   

504394029   4282809 3769159 3520807 3548322 3458122 

503264032   

502011475   2595780 2417433 2299563 2060552 1804531 1821638 1789533 
1463371 947712
500400911   

504615947   22801   28656   27067   26182   26356   34060   39147   

502616695   1412354 1209619 1429755 1623496 1955123 2273486 2087406 
2076868 2036937
500829993   1383396 1095570 805830  793809  777591  791614  779924  
774560  702845
The objective of my work is to do linear regressions with 
the variables in the files or with other variables that I 
can obtain from those by doing some mathematical 
operations.  I’ve already tried to import this information 
to an array in R, but I’ve seen that the linear 
regressions functions need the data into a dataframe. So 
I’m asking: How to import this information to a dataframe 
in R, in a manner that I can easily do the mathematical 
operations between the variables and then use it to do the 
regressions?


Cecília Carmo

__
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] dynlm question: How to predefine formula for call to dynlm(formula) call

2009-04-19 Thread Achim Zeileis

On Sat, 18 Apr 2009, Ron Burns wrote:

I want to set up a model with a formula and then run dynlm(formula) because I 
ultimately want to loop over a set of formulas (see end of post)


R> form <- gas~price
R> dynlm(form)

Time series regression with "ts" data:
Start = 1959(1), End = 1990(4)


Works OK without a Lag term

R> dynlm(gas ~ L(gas,1))

Time series regression with "ts" data:
Start = 1959(2), End = 1990(4)


Works OK with a Lag with this type of call

R> form <- gas~L(gas,1)
R> dynlm(form)
Error in merge.zoo(gas, L(gas, 1), retclass = "list", all = FALSE) :
could not find function "L"

Does not work using a predefined formula with a Lag  (This type of call works 
using dyn$lm from library(dyn))


The problem with "dynlm" is that it defines it's lag/diff functionality 
locally (unlike "dyn" which re-uses the usual lag/diff functions) and in 
the setting above this conflicts with the non-standard evaluation, 
unfortunately. I don't know a good solution to this...



How do I make the call (or how do I setup form) so that this works in dynlm?


In your specific problem, I think it is worth to take the extra step and 
do the processing yourself because...



To be specific the following is an example of what I was attempting to do:
 m1 <- gas ~ L(gas,1)
m2 <- gas ~ L(gas,1) + price
m3 <- gas ~ L(gas,1) + price + d(gas)
m4 <- gas ~ L(gas,1) + price + d(gas) + L(d(gas),1)


...these models correspond to different samples. m4 will lose one more 
observation at the beginning by lag+diff. Of course, it is possible to 
address this in dynlm as well but I (personally) find it simpler to do 
the data processing first and then the modeling and model selection. I 
would do something like:


## data processing
dat <- ts.intersect(gas, price,
   gas1 = lag(gas, k = -1),
   dgas = diff(gas),
   dgas1 = lag(diff(gas), k = -1))

## models
form <- list(
   gas ~ gas1,
   gas ~ gas1 + price,
   gas ~ gas1 + price + dgas,
   gas ~ gas1 + price + dgas + dgas1)

## fitting
mod <- lapply(form, lm, data = dat)

## evaluation
sapply(mod, AIC)
sapply(mod, AIC, k = log(nrow(dat)))

hth,
Z


M <- c(m1,m2,m3,m4)
A <- array(0,c(4,2))

for(i in 1:4){
 g <- dynlm(M[[i]])   ## works if use dyn$lm from library(dyn) and use 
appropriate m's

 A[i,1] <- AIC(g,k=2)
 A[i,2] <- AIC(g,k=log(length(fitted(g
}
colnames(A) <- c("AIC","BIC")
rownames(A) <- c("m1","m2","m3","m4")
A

--

R. R. Burns
Retired in Oceanside, CA

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




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


[R] creating a package in R

2009-04-19 Thread Antonio.Gasparrini
Dear R users,
 
I created some functions I want to convert in a package under Windows (Vista or 
XP).
I carefully read both "Writing R extensions" by the R Development Core Team and 
"Creating R packages: a tutorial" by Friedrich Leisch.
I've also installed Rtools as suggested.
These tutorials are very useful, but I'm struggling with the last step of the 
installation process: after running package.skeleton, creating the directory 
and modifying the help files, I cannot understand where I should run the 
commands R CMD INSTALL, check and build.
 
Sorry for the stupid question, but I've been stuck for weeks with this problem.
Thanks for your help
 
Antonio Gasparrini
Public and Environmental Health Research Unit (PEHRU)
London School of Hygiene & Tropical Medicine
Keppel Street, London WC1E 7HT, UK
Office: 0044 (0)20 79272406 - Mobile: 0044 (0)79 64925523

__
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] creating a package in R

2009-04-19 Thread Duncan Murdoch

On 19/04/2009 9:02 AM, antonio.gasparr...@lshtm.ac.uk wrote:

Dear R users,
 
I created some functions I want to convert in a package under Windows (Vista or XP).

I carefully read both "Writing R extensions" by the R Development Core Team and 
"Creating R packages: a tutorial" by Friedrich Leisch.
I've also installed Rtools as suggested.
These tutorials are very useful, but I'm struggling with the last step of the 
installation process: after running package.skeleton, creating the directory 
and modifying the help files, I cannot understand where I should run the 
commands R CMD INSTALL, check and build.
 
Sorry for the stupid question, but I've been stuck for weeks with this problem.


Those commands are meant to be run at the console.  I normally use a 
Cygwin console, but the commands are designed to work fine in the 
Windows CMD console too.


They should also work from within R, if you run them within the system() 
function, and have your system set up properly.  For example:


> setwd("d:/svn/MyR")
> system("R CMD build rgl")
* checking for file 'rgl/DESCRIPTION' ... OK
* preparing 'rgl':
* checking DESCRIPTION meta-information ... OK
* cleaning src
make: Nothing to be done for `clean'.
* removing junk files
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
WARNING: directory 'rgl/src/ext/GLsdk/GL/codegen' is empty
* building 'rgl_0.85.tar.gz'

(With the usual settings in Rgui, this will be buffered and will appear 
all at once:  you can uncheck the menu item "Misc | Buffered output" to 
have the lines show up reassuringly one at a time.)


The most likely reason for this not to work is that your system path is 
not set correctly.  The relevant path is the one shown by 
Sys.getenv("PATH") while running R.  Mine currently shows


> Sys.getenv("PATH")




PATH
"c:\\Rtools\\bin;c:\\Rtools\\perl\\bin;c:\\Rtools\\minGW\\bin;f:\\cygwin\\usr\\local\\bin;f:\\cygwin\\bin;f:\\cygwin\\bin;f:\\cygwin\\usr\\X11R6\\bin;c:\\util\\misc;c:\\windows\\system32;f:\\R\\svn\\r-devel\\R\\bin;f:\\texmf\\miktex\\bin;c:\\progra~1\\htmlhe~1;f:\\program 
files\\subversion\\bin"


(If you read it closely, you'll notice some duplication.  It's hard to 
keep a Windows path clean.)


Duncan Murdoch


Duncan Murdoch



Thanks for your help
 
Antonio Gasparrini

Public and Environmental Health Research Unit (PEHRU)
London School of Hygiene & Tropical Medicine
Keppel Street, London WC1E 7HT, UK
Office: 0044 (0)20 79272406 - Mobile: 0044 (0)79 64925523

__
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] importing spreadsheet data - linera regression - panel data

2009-04-19 Thread Stefan Grosse
Cecilia Carmo schrieb:
> The objective of my work is to do linear regressions with the
> variables in the files or with other variables that I can obtain from
> those by doing some mathematical operations.  I’ve already tried to
> import this information to an array in R, but I’ve seen that the
> linear regressions functions need the data into a dataframe. So I’m
> asking: How to import this information to a dataframe in R, in a
> manner that I can easily do the mathematical operations between the
> variables and then use it to do the regressions?
>

Your question is probably misspecified. Or the pure import is not your
only problem. For the import of the txt you should easily find read.csv
your candidate. (please use search on the r-project.org page which leads
easily to this solution.)
firms<-read.csv("myfilename.txt",header=T,sep="\t")

see
?read.csv for help.

Then your data are maybe in the wrong order. Instead of
Firm Year1 Year2
A100   101

it is sometimes better to

Firm Year Rev
A1100
A1101

the transformation is called reshape. See
?reshape
and
example(reshape)

Then you can do your "mathematical operations".

See eg.
?lm
example(lm)

hth
Stefan

__
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] AICs from lmer different with summary and anova

2009-04-19 Thread Michael Dewey

At 16:22 15/04/2009, Jonathan Williams wrote:

Dear R Helpers,

I have noticed that when I use lmer to analyse data, the summary function
gives different values for the AIC, BIC and log-likelihood compared with the
anova function.


I do not think I have seen a reply to this.

What happens if you fit the models originally using ML rather than REML?



Here is a sample program

#make some data
set.seed(1);
datx=data.frame(array(runif(720),c(240,3),dimnames=list(NULL,c('x1','x2','y'

id=rep(1:120,2); datx=cbind(id,datx)

#give x1 a slight relation with y (only necessary to make the random effects
non-zero in this artificial example)
datx$x1=(datx$y*0.1)+datx$x1

library(lme4)

#fit the data
fit0=lmer(y~x1+x2+(1|id), data=datx); print(summary(fit0),corr=F)
fit1=lmer(y~x1+x2+(1+x1|id), data=datx); print(summary(fit1),corr=F)

#compare the models
anova(fit0,fit1)


Now, look at the output, below. You can see that the AIC from
"print(summary(fit0))" is 87.34, but the AIC for fit0 in "anova(fit0,fit1)"
is 73.965. There are similar changes for the values of BIC and logLik.

Am I doing something wrong, here? If not, which are the real AIC and logLik
values for the different models?

Thanks for your help,

Jonathan Williams


Output:-

> fit0=lmer(y~x1+x2+(1|id), data=datx); print(summary(fit0),corr=F)
Linear mixed model fit by REML
Formula: y ~ x1 + x2 + (1 | id)
   Data: datx
   AIC   BIC logLik deviance REMLdev
 87.34 104.7 -38.6763.96   77.34
Random effects:
 Groups   NameVariance Std.Dev.
 id   (Intercept) 0.016314 0.12773
 Residual 0.062786 0.25057
Number of obs: 240, groups: id, 120

Fixed effects:
Estimate Std. Error t value
(Intercept)  0.503760.05219   9.652
x1   0.089790.06614   1.358
x2  -0.066500.06056  -1.098
> fit1=lmer(y~x1+x2+(1+x1|id), data=datx); print(summary(fit1),corr=F)
Linear mixed model fit by REML
Formula: y ~ x1 + x2 + (1 + x1 | id)
   Data: datx
   AIC   BIC logLik deviance REMLdev
 90.56 114.9 -38.2863.18   76.56
Random effects:
 Groups   NameVariance  Std.Dev. Corr
 id   (Intercept) 0.0076708 0.087583
  x1  0.0056777 0.075351 1.000
 Residual 0.0618464 0.248689
Number of obs: 240, groups: id, 120

Fixed effects:
Estimate Std. Error t value
(Intercept)  0.500780.05092   9.835
x1   0.092360.06612   1.397
x2  -0.065150.06044  -1.078
> anova(fit0,fit1)
Data: datx
Models:
fit0: y ~ x1 + x2 + (1 | id)
fit1: y ~ x1 + x2 + (1 + x1 | id)
 Df AIC BIC  logLik  Chisq Chi Df Pr(>Chisq)
fit0  5  73.965  91.368 -31.982
fit1  7  77.181 101.545 -31.590 0.7839  2 0.6757


Michael Dewey
http://www.aghmed.fsnet.co.uk

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


[R] (senza oggetto)

2009-04-19 Thread giuseppef...@libero.it
Dear all, excuse me for my simple questions: i had imported with read table a 
database with x, y,value and i must do variogram with gstat.
can someone tell me how to do it? I read the help but I could not
to obtain variogram,

__
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] Binomial simulation

2009-04-19 Thread Ranjan Maitra
With due respect, and in all fairness, you should inform your instructor
that you took help from R's mailing list for doing homework. 

This mailing list (or any other general mailing list for that matter) is
not for doing your (or anyone else's) homework. If the instructor
allowed that, that is a different story but you should state that in
your post to the mailing list.

Ranjan

On Sat, 18 Apr 2009 15:06:15 -0700 (PDT) beetle2
 wrote:

> 
> Thank you for your help!
> Yes you are right the probabilities are for the values 0 through 12.
> I been asked to compare the simulated values to that of dbinom()
> once again thanks!
> 
> 
> 
> 
> 
> Ranjan Maitra wrote:
> > 
> > This sounds like a potential homework problem. You don't quite need to
> > simulate anything if your question is all you have been asked to do.
> > 
> > dbinom(x = 1:10, size = 10, prob = 0.25)
> > 
> > Perhaps you have been asked to simulate 1000 realizations and compare
> > the relative frequencies with these probabilities: use 
> > 
> > rbinom(n = 1000, size = 10, prob = 0.25)
> > 
> > in that case and compare the relative frequencies.
> > 
> > Btw, there is a small chance of getting a 0. Are you sure the
> > instructor (or whoever has issued the orders) wants only from 1:10?
> > 
> > HTH!
> > Ranjan
> > 
> > On Fri, 17 Apr 2009 22:23:11 -0700 (PDT) beetle2
> >  wrote:
> > 
> >> 
> >> 
> >> Not being entirely sure what you mean, I think 
> >> 
> >> rbinom(1000, 10, .25) 
> >> 
> >> may be what you want. 
> >> 
> >> Hi,
> >> Thanks for your reply.
> >> It is close to that but I need to know the probabilty of how many judges
> >> pick a certain brand.
> >> Just say x= 6 judges pick brand A which has P=0.25.
> >> 
> >> Using R it would be:
> >> > dbinom(6,10,.25)
> >> [1] 0.016222
> >> 
> >> Probability of six judges choosing  brand A. Hence not very likely.
> >> 
> >> I have been asked to do this for all values of x = 1 to 10.
> >> But the question says to simulate 1000 trials for each x value.
> >> I'm not sure how to construct the simulation.
> >> regards
> >> Brendan
> >> 
> >> 
> >> -- 
> >> View this message in context:
> >> http://www.nabble.com/Binomial-simulation-tp23106347p23109522.html
> >> Sent from the R help mailing list archive at Nabble.com.
> >> 
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> > 
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> > 
> > 
> 
> -- 
> View this message in context: 
> http://www.nabble.com/Binomial-simulation-tp23106347p23117793.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] AICs from lmer different with summary and anova

2009-04-19 Thread hadley wickham
> Am I doing something wrong, here? If not, which are the real AIC and logLik
> values for the different models?

I don't think it's reasonable to expect that the log-likelihood
computed by different functions be should comparable.  Are the
constant terms included or dropped?

Hadley

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

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


[R] drawing data structures

2009-04-19 Thread rajesh j
Hi,
I need to represent data structures in a figure.stuff like trees with nodes
and pointers etc.can someone guide me to a package that does this?

-- 
Rajesh.J

[[alternative HTML version deleted]]

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


[R] help with this code

2009-04-19 Thread li li
Hi, can anyone help me with the following code?  Thanks!

library(mvtnorm)
f2 <- function(n, rho) {
var <- matrix(c(1,rho,rho,1), nrow=2, ncol=2, byrow=T)
beta <-  seq(0, 1, length.out=n+1)
alpha <- sort (sapply(1-beta, qnorm))
x <- array(0, dim=c(n, n))
for (s in 1:n) {
 for (t in 1:n){
if (s>=t)
   x[s,t] <- pmvnorm(lower=c(alpha[s], alpha[t]),upper=c(alpha[s+1],
alpha[t+1]),  mean=c(0,0), corr=var)/(s*(s+1))
else
   x[s,t] <- pmvnorm(lower=c(alpha[s], alpha[t]),upper=c(alpha[s+1],
alpha[t+1]), mean-c(0,0), corr=var)/(t*(t+1))
 } }

n*beta[2]-(n-1)*pmvnorm(lower=c(alpha[n-1],alpha[n-1]), upper=rep(Inf,2),
corr=var, mean=c(0,0))+n*(n-1)*sum(x) }

I got the error informatio as below if I want to calculate the value the
function for some specific parameters.

> f2(5, 0.1)
Error in checkmvArgs(lower = lower, upper = upper, mean = mean, corr =
corr,  :
  ‘diag(corr)’ and ‘lower’ are of different length

[[alternative HTML version deleted]]

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


[R] covariance

2009-04-19 Thread Benny Chain
Does anyone know a way to calculate the covariances between two
arrays/matrices x and y, row by row. i.e. var(x[n,],y[n,]) for all n ?

Benjamin Chain
Division of Infection and Immunity
Windeyer Building
UCL, 46 Cleveland St.
London W1T 4JF
Fax 00 44 20 7679 9301

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

2009-04-19 Thread Gábor Csárdi
sapply(seq_len(nrow(x)), function(i) var(x[i,], y[i,]))

Gabor

On Sun, Apr 19, 2009 at 7:12 PM, Benny Chain  wrote:
> Does anyone know a way to calculate the covariances between two
> arrays/matrices x and y, row by row. i.e. var(x[n,],y[n,]) for all n ?
>
> Benjamin Chain
> Division of Infection and Immunity
> Windeyer Building
> UCL, 46 Cleveland St.
> London W1T 4JF
> Fax 00 44 20 7679 9301
>
> __
> 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.
>



-- 
Gabor Csardi  UNIL DGM

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

2009-04-19 Thread Jorge Ivan Velez
Dear Benny,
Here is something that could get you a hint:

# Some data
set.seed(123)
X <- matrix(rnorm(100),ncol=10)
Y <- matrix(rnorm(100,2,4),ncol=10)

# Number of rows
n<-nrow(X)

# Covariances
sapply(1:n,function(i) cov(X[i,],Y[i,]))
# [1]  0.23396819  0.51455839  1.13851842 -4.30551345 -2.60720372
-0.06834326  0.78344182 -0.02085422
# [9]  1.05896045  1.37631451

See ?cov and ?sapply for more details.

HTH,

Jorge


On Sun, Apr 19, 2009 at 1:12 PM, Benny Chain  wrote:

> Does anyone know a way to calculate the covariances between two
> arrays/matrices x and y, row by row. i.e. var(x[n,],y[n,]) for all n ?
>
> Benjamin Chain
> Division of Infection and Immunity
> Windeyer Building
> UCL, 46 Cleveland St.
> London W1T 4JF
> Fax 00 44 20 7679 9301
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] covariance

2009-04-19 Thread Marc Schwartz

Depending upon the size of the matrix, using:

  diag(cov(t(x), t(y)))

might be notably faster. On smaller matrices the time savings is  
negligible.


Using Jorge's example below:

> diag(cov(t(X), t(Y)))
 [1]  0.23396819  0.51455839  1.13851842 -4.30551345 -2.60720372
 [6] -0.06834326  0.78344182 -0.02085422  1.05896045  1.37631451

HTH,

Marc Schwartz

On Apr 19, 2009, at 12:22 PM, Jorge Ivan Velez wrote:


Dear Benny,
Here is something that could get you a hint:

# Some data
set.seed(123)
X <- matrix(rnorm(100),ncol=10)
Y <- matrix(rnorm(100,2,4),ncol=10)

# Number of rows
n<-nrow(X)

# Covariances
sapply(1:n,function(i) cov(X[i,],Y[i,]))
# [1]  0.23396819  0.51455839  1.13851842 -4.30551345 -2.60720372
-0.06834326  0.78344182 -0.02085422
# [9]  1.05896045  1.37631451

See ?cov and ?sapply for more details.

HTH,

Jorge


On Sun, Apr 19, 2009 at 1:12 PM, Benny Chain   
wrote:



Does anyone know a way to calculate the covariances between two
arrays/matrices x and y, row by row. i.e. var(x[n,],y[n,]) for all  
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] AICs from lmer different with summary and anova

2009-04-19 Thread Ben Bolker



hadley wrote:
> 
>> Am I doing something wrong, here? If not, which are the real AIC and
>> logLik
>> values for the different models?
> 
> 

  The difference here is that summary() is using REML=TRUE and anova()
is using REML=FALSE.  It makes sense that anova (which is typically being
used to compare fixed effects) should make this assumption, but I'm not
sure whether it's documented anywhere.

  Ben Bolker

-- 
View this message in context: 
http://www.nabble.com/AICs-from-lmer-different-with-summary-and-anova-tp23061269p23125352.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] Sweave: Changing the background color, adding a border

2009-04-19 Thread Christophe Genolini

Duncan Murdoch a écrit :

On 19/04/2009 6:03 AM, Christophe Genolini wrote:

Hi all,

I am using Sweave to produce a document. Unfortunately, I have to 
print several copies and I can't print them in color. So I would like 
to change the way of printing the code. I would like to print the 
code in a box with a black borderline and a grey background (quite 
classic). Is it possible to do it by changing some Schunk options?


It should be, if you know how to print things like that, but I don't 
Here's some code I wrote a while ago to modify the Sweave formats in a 
much simpler way:


% This removes the extra spacing after code and output chunks in Sweave,
% but keeps the spacing around the whole block.

\fvset{listparameters={\setlength{\topsep}{0pt}}}
\renewenvironment{Schunk}{\vspace{\topsep}}{\vspace{\topsep}}
% We want to avoid having examples switch us to an italic font shape.
\DefineVerbatimEnvironment{Soutput}{Verbatim}{fontshape=n}


Hi Duncan, hi Romain

Thanks for your answer. I finally succeed.
I used the listings package to define an environment that put code in a 
grey box. The command is \lstnewenvironment{Sinput}[1][]{


Then I change the Schunk, Sinput and Soutput environment.
- For the Schunk, I use \renewenvironment as Duncan suggest.
- For Sinput, I would like to use something like \lstREnewenvironment 
but it does not exist.
So I comment the line \usepackage{Sweave}, I copy the contain of file of 
Sweave.sty in the .Rwn file and I remove the definition of Sinput and 
Soutput.
Note: The line %\usepackage{Sweave} is necessary, otherwise the R 
command 'Sweave()' add the line \package{Sweave}in the LaTeX file.


--- 8< --
The final file is :
%\usepackage{Sweave}
\RequirePackage[T1]{fontenc}
\RequirePackage{graphicx,ae,fancyvrb}
\IfFileExists{upquote.sty}{\RequirePackage{upquote}}{}
\setkeys{Gin}{width=0.8\textwidth}

%\DefineVerbatimEnvironment{Sinput}{}{}
%\DefineVerbatimEnvironment{Soutput}{}{}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl}

\newenvironment{Schunk}{}{}

\usepackage{listings}

\definecolor{gris90}{gray}{0.90}

\lstloadlanguages{R}

\lstnewenvironment{Sinput}[1][]{
 \lstset{%
   language={R},
   basicstyle=\small,% print whole listing small
   keywordstyle=\color{black}\bfseries,  % style for keyword
   emph={in},% define a list of word to 
emphasis

   emphstyle=\color{black}\bfseries, % define the way to emphase
   % emph={[2]out},% define a second list 
of word to emphasis
   % emphstyle=[2]\color{red}\bfseries,% define the way to 
emphase the list 2

   frame=single, % box arround the code
   backgroundcolor=\color{gris90},   % background color
   % commentstyle=\color{gris10},  % define the style of 
the comments
   showspaces=false, % show the space in code, 
or not
   stringstyle=\ttfamily,% style of the string 
(like "hello word")
   showstringspaces=false,   % show the space in 
string, on not

   #1
 }
}{}
\lstnewenvironment{Soutput}[1][]{
 \lstset{%
   language={R},
   basicstyle=\small,% print whole listing small
   keywordstyle=\color{black}\bfseries,  % style for keyword
   emph={in},% define a list of word to 
emphasis

   emphstyle=\color{black}\bfseries, % define the way to emphase
   % emph={[2]out},% define a second list 
of word to emphasis
   % emphstyle=[2]\color{red}\bfseries,% define the way to 
emphase the list 2

   frame=single, % box arround the code
   backgroundcolor=\color{gris90},   % background color
   % commentstyle=\color{gris10},  % define the style of 
the comments
   showspaces=false, % show the space in code, 
or not
   stringstyle=\ttfamily,% style of the string 
(like "hello word")
   showstringspaces=false,   % show the space in 
string, on not

   #1
 }
}{}

--- 8< --


Christophe

__
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] flip certain bits in vector

2009-04-19 Thread Esmail

I have a string of binary values, and I would like to flip certain
bits in a set of positions.

Let's say the

vector p contains position [1, 3, 5, 7]
vector b contains bits   [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]
result r should be   [0, 1, 0, 0, 0, 0, 0, 0, 1, 0]

in pseudo code this would be something like

---

r = c()

for (i in 1:10)
  if (i in p)
 r = c(r, flip[i])

r


doesn't work :-)  R doesn't like the if statement.

Is there a nice, concise way to do this? The vector contents and
size will vary, but length of p <= b.

Thanks,
Esmail

__
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] flip certain bits in vector

2009-04-19 Thread David Winsemius
I do not think your wetware processed the inputs correctly. The second  
bit should not have been flipped:


Try this loop free index based solution:

 b <- c( 1, 0, 1, 0, 1, 0, 1, 0, 1, 0)
 r <- b
 r[p] <- 0 + !r[p]  # adding 0 converts logical TRUE/FALSE  to 0/1
 r
 [1] 0 0 0 0 0 0 0 0 1 0

The "if" statement is for control but you might have succeeded with an  
ifelse function which is generally more useful for conditional  
modification of vectors. It could have been used if the transformation  
were not binary.


--
David Winsemius

On Apr 19, 2009, at 3:24 PM, Esmail wrote:


I have a string of binary values, and I would like to flip certain
bits in a set of positions.

Let's say the

vector p contains position [1, 3, 5, 7]
vector b contains bits   [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]
result r should be   [0, 1, 0, 0, 0, 0, 0, 0, 1, 0]

in pseudo code this would be something like

---

r = c()

for (i in 1:10)
 if (i in p)
r = c(r, flip[i])

r


doesn't work :-)  R doesn't like the if statement.

Is there a nice, concise way to do this? The vector contents and
size will vary, but length of p <= b.

Thanks,
Esmail


__
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] flip certain bits in vector

2009-04-19 Thread jim holtman
try this:

> b <- c(1, 0, 1, 0, 1, 0, 1, 0, 1, 0)
> p <- c(1, 3, 5, 7)
> b[p] <- ifelse(b[p] == 0, 1, 0)
> b
 [1] 0 0 0 0 0 0 0 0 1 0


On Sun, Apr 19, 2009 at 3:24 PM, Esmail  wrote:
> I have a string of binary values, and I would like to flip certain
> bits in a set of positions.
>
> Let's say the
>
> vector p contains position [1, 3, 5, 7]
> vector b contains bits   [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]
> result r should be       [0, 1, 0, 0, 0, 0, 0, 0, 1, 0]
>
> in pseudo code this would be something like
>
> ---
>
> r = c()
>
> for (i in 1:10)
>  if (i in p)
>     r = c(r, flip[i])
>
> r
> 
>
> doesn't work :-)  R doesn't like the if statement.
>
> Is there a nice, concise way to do this? The vector contents and
> size will vary, but length of p <= b.
>
> Thanks,
> Esmail
>
> __
> 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.
>



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

What is the problem that you are trying to solve?

__
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] Binomial simulation

2009-04-19 Thread Johannes Huesing
beetle2  [Sun, Apr 19, 2009 at 03:01:43AM CEST]:
> 
> I'm thinking I will just  use:
> results <- rbinom(1000, 10, .25)
> d = sum(results == 0 )
> df = (d/1000)
> df
> 
> And do each individually

ok, at least you are trying some things out for yourself. In fact, along
with reading the doc, this is the fastest and most efficient way to 
learn the language. If you keep going, you will soon realize that the
language is much more powerful than the vocabulary you are applying
currently. For the time being, try

table(result)

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

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


Re: [R] flip certain bits in vector

2009-04-19 Thread Esmail

David Winsemius wrote:
I do not think your wetware processed the inputs correctly. The second 
bit should not have been flipped:


Ooops .. yes you are right!



Try this loop free index based solution:

 b <- c( 1, 0, 1, 0, 1, 0, 1, 0, 1, 0)
 r <- b
 r[p] <- 0 + !r[p]  # adding 0 converts logical TRUE/FALSE  to 0/1
 r
 [1] 0 0 0 0 0 0 0 0 1 0


Great! .. thanks ... I appreciate the hlep,


Esmail

__
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] flip certain bits in vector

2009-04-19 Thread Esmail

jim holtman wrote:

try this:


b <- c(1, 0, 1, 0, 1, 0, 1, 0, 1, 0)
p <- c(1, 3, 5, 7)
b[p] <- ifelse(b[p] == 0, 1, 0)


I'll have to look up the ifelse operator, looks like
the ternary operator used in C

b[p] = b[p]==0?1:0

Cool - thanks!

Esmail

__
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] get() versus getAnywhere()

2009-04-19 Thread Rolf Turner


On 19/04/2009, at 9:45 PM, Duncan Murdoch wrote:


On 18/04/2009 8:47 PM, Rolf Turner wrote:

On 17/04/2009, at 10:21 PM, Duncan Murdoch wrote:


Benjamin Tyner wrote:

Many thanks Duncan. Perhaps this merits a more explicit note in the
documentation?


The quote I gave is from the documentation.  How could it be more
explicit?


This is unfortunately typical of the attitude of R-core people toward
the
documentation.  ``It's clear.'' they say.  ``It's explicit.''   
Clear and

explicit once you *know* what it's saying.  Not before, but.


But I didn't say that.  I asked how to make it more explicit.


Oh come on Duncan!  You did *not*.  You asked (rhetorical
question) ``How could it be more explicit?''  (Implied:  How
could it ***possibly*** be more explicit?)




In this case the documentation is quite opaque to me, and I would
suspect
to a good many like me.


What change would make it less opaque?


For one thing, point out ***explicitly***, as you did in your post, that
getAnywhere() doesn't actually get ***anywhere***.  Only some wheres.

(How's that for Canuck English, Berwin?)

cheers,

Rolf

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
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] explicit documentation (was: get() versus getAnywhere())

2009-04-19 Thread Rolf Turner


On 19/04/2009, at 8:59 PM, Patrick Burns wrote:


Rolf Turner wrote:


On 17/04/2009, at 10:21 PM, Duncan Murdoch wrote:


Benjamin Tyner wrote:

Many thanks Duncan. Perhaps this merits a more explicit note in the
documentation?



The quote I gave is from the documentation.  How could it be more
explicit?


This is unfortunately typical of the attitude of R-core people  
toward the
documentation.  ``It's clear.'' they say.  ``It's explicit.''   
Clear and

explicit once you *know* what it's saying.  Not before, but.


I think this unfairly blames R-core for being human.


Why is this unfair?  R-core is supposed to be superhuman! :-)

cheers,

Rolf

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
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] explicit documentation

2009-04-19 Thread Peter Dalgaard

Rolf Turner wrote:


On 19/04/2009, at 8:59 PM, Patrick Burns wrote:



I think this unfairly blames R-core for being human.


Why is this unfair?  R-core is supposed to be superhuman! :-)


Aiming for the fortune file again, eh?


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

__
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] get() versus getAnywhere()

2009-04-19 Thread Johannes Huesing
Rolf Turner  [Sun, Apr 19, 2009 at 10:01:34PM CEST]:
>
> On 19/04/2009, at 9:45 PM, Duncan Murdoch wrote:
>
>> On 18/04/2009 8:47 PM, Rolf Turner wrote:
>>> On 17/04/2009, at 10:21 PM, Duncan Murdoch wrote:
>>>
 Benjamin Tyner wrote:
> Many thanks Duncan. Perhaps this merits a more explicit note in the
> documentation?
>
 The quote I gave is from the documentation.  How could it be more
 explicit?
>>>
>>> This is unfortunately typical of the attitude of R-core people toward
>>> the
>>> documentation.  ``It's clear.'' they say.  ``It's explicit.''  Clear 
>>> and
>>> explicit once you *know* what it's saying.  Not before, but.
>>
>> But I didn't say that.  I asked how to make it more explicit.
>
>   Oh come on Duncan!  You did *not*.  You asked (rhetorical
>   question) ``How could it be more explicit?''  (Implied:  How
>   could it ***possibly*** be more explicit?)

E-mail doesn't convey tone, facial expression or gesture. I would give
Duncan the benefit of the doubt here.

>>
>>>
>>> In this case the documentation is quite opaque to me, and I would
>>> suspect
>>> to a good many like me.
>>
>> What change would make it less opaque?
>
> For one thing, point out ***explicitly***, as you did in your post, that
> getAnywhere() doesn't actually get ***anywhere***.  Only some wheres.

Ask explicitly, get an explicit answer. A documentation comprising explicit
answers would be an FAQ, which in itself is not concise in most cases.
-- 
Johannes Hüsing   There is something fascinating about science. 
  One gets such wholesale returns of conjecture 
mailto:johan...@huesing.name  from such a trifling investment of fact.  
  
http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi")

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


[R] Sweave: Howto write real TeX formula in plot

2009-04-19 Thread Jonas Stein
Hi,

i use Sweave to put plots in my .tex Documents. (pdflatex)
Is there a nice solution for this:

a) get a real LaTeX formula in the plot area. 
I have only found very complicate solutions. Is there sth. like 
\formula{x^2 = \oint f} 

b) how can i format axis and legend to get exact the same font that is
used in the TeX-document? 

Thank you for any help. 

-- 
Jonas Stein 

__
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: Howto write real TeX formula in plot

2009-04-19 Thread baptiste auguie

Perhaps try the pgfSweave package on r-forge?

http://r-forge.r-project.org/projects/pgfsweave/

HTH,

baptiste

On 19 Apr 2009, at 22:15, Jonas Stein wrote:


Hi,

i use Sweave to put plots in my .tex Documents. (pdflatex)
Is there a nice solution for this:

a) get a real LaTeX formula in the plot area.
I have only found very complicate solutions. Is there sth. like
\formula{x^2 = \oint f}

b) how can i format axis and legend to get exact the same font that is
used in the TeX-document?

Thank you for any help.

--
Jonas Stein 

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


_

Baptiste Auguié

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

Phone: +44 1392 264187

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

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


Re: [R] get() versus getAnywhere()

2009-04-19 Thread Duncan Murdoch

On 19/04/2009 4:01 PM, Rolf Turner wrote:

On 19/04/2009, at 9:45 PM, Duncan Murdoch wrote:


On 18/04/2009 8:47 PM, Rolf Turner wrote:

On 17/04/2009, at 10:21 PM, Duncan Murdoch wrote:


Benjamin Tyner wrote:

Many thanks Duncan. Perhaps this merits a more explicit note in the
documentation?


The quote I gave is from the documentation.  How could it be more
explicit?

This is unfortunately typical of the attitude of R-core people toward
the
documentation.  ``It's clear.'' they say.  ``It's explicit.''   
Clear and

explicit once you *know* what it's saying.  Not before, but.

But I didn't say that.  I asked how to make it more explicit.


Oh come on Duncan!  You did *not*.  You asked (rhetorical
question) ``How could it be more explicit?''  (Implied:  How
could it ***possibly*** be more explicit?)


Well, I have to admit that I was thinking "***possibly***", but I didn't 
write it, because I wanted a suggested revision.  I didn't get one, and 
still haven't, even after asking again.  I won't ask a third time; I 
already put something in, and if that doesn't satisfy you, then I think 
you'll likely go to your grave unsatisfied.


You have to understand the process here:

 - You (or Benjamin, in this case) find something unclear, but don't 
suggest a clarification.
 - I read it, find it clear, assume you didn't because you didn't read 
the man page (or are mentally deficient), but I'm polite enough to point 
out where I found the explicit explanation.
 - You (this time really you) complain that it isn't clear, but *still* 
don't write a revision.


Now, at either the 1st or 3rd step, it would have been much easier for 
you (or Benjamin) to suggest a change that would have been clear to you, 
than it was for me to try to imagine what it is like to live in your 
head, and figure out what would be clear to you.



In this case the documentation is quite opaque to me, and I would
suspect
to a good many like me.

What change would make it less opaque?


For one thing, point out ***explicitly***, as you did in your post, that
getAnywhere() doesn't actually get ***anywhere***.  Only some wheres.


We said where it looks.  That still seems explicit to me.  There are a 
lot of places where it doesn't look, and now it lists two of them, but I 
expect to hear complaints from you that I didn't mention the fact that 
it doesn't look in your back garden.



(How's that for Canuck English, Berwin?)

cheers,

Rolf

##
Attention: 
This e-mail message is privileged and confidential. If you are not the 
intended recipient please delete the message and notify the sender. 
Any views or opinions presented are solely those of the author.


This e-mail has been scanned and cleared by MailMarshal 
www.marshalsoftware.com

##



My message is neither privileged nor confidential, and hasn't been 
cleared by anybody.


Duncan Murdoch

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


[R] Including a vector element in an if statement

2009-04-19 Thread Enda Hargaden
Hi all,

I've searched high and low on this and found nothing of help. I'm using
v2.6.2 and trying to write a function that will count how many people from a
dataset fall under a poverty line of 50% of the mean income.

a9 is my 100-element vector of incomes. I want pa9 to be my vector that
counts how many of these are classed as in poverty.

My problem is that my command if(a9[i] < mean(a9)/2 ) returns an "argument
is of length zero" error. But a9[i] is not really of length zero; if I
remove the if() command and simply set pa9[i] = a9[i] in the loop it comes
out fine.

I don't think it's a problem with the type of variable either, because if I
multiply the vector by 2 I get the "correct" output, so I think it's a
problem with R interpreting my vector as a list of strings or anything.

povertyline = function()
{
pa9 = c()
i=0
 while(i<=length(a9))
 {
if(a9[i] < mean(a9)/2)
{
pa9[i] = a9[i]
}
 i = i+1
 }
return(length(pa9))
}

Has anyone any ideas what's going wrong? (Just for clarification: yes, this
is for my homework. However I've already done the assignment in Excel and
I'm repeating it to improve my R'ing.)

Thanks a lot,
Enda

[[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] Binomial simulation

2009-04-19 Thread beetle2

Hi All,
Thank you for all your help.
In future I will state if it's homework related.
regards
Brendan








beetle2 wrote:
> 
> Hi Guy's
> I was wondering if someone could point me in the right direction.
> 
> dbinom(10,1,0.25)
> 
> I am using dbinom(10,1,0.25) to calculate the probabilty of 10 judges
> choosing a certain brand x times. 
> 
> I was wondering how I would go about simulating 1000 trials of each x
> value ?
> 
> regards
> Brendan
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Binomial-simulation-tp23106347p23128391.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] Question about rpart(sth~.,database)

2009-04-19 Thread Grześ


Gavin Simpson wrote:
> 
> Grześ wrote:
>> I have a standard database - HouseVotes84 
>> For example:
>>Class   V1 V2 V3   V4 V5 V6 V7 V8 V9 V10  V11 V12 V13 V14 V15  V16
>> 1 republicann  y  ny  y  y  n  n  n   yy   y   y   ny
>> 2 republicann  y  ny  y  y  n  n  n   nn   y   y   y   n 
>> 3 democrat   y  y   y  y  n  n  n   ny   n   y   y   nn
>>  .
>>  .
>>  .
>> end I build a tree like this: 
>>> hv.tree1=rpart(Class~.,HouseVotes84)
>> everything is ok! My question is:
>> What exactly mean "Class~.,"? 
> 
> It means include all remaining variables in HouseVotes84 on the rhs of 
> the formula, i.e. as variables that should be used to predict the Class 
> variable.
> 
>> 
>> Why when I use "Class~.," - then I get the best solution but when I use
>> as a
>> parameter like this:
>>> hv.tree2=rpart(V2~.,HouseVotes84)
> 
> Why does this surprise you? You are now trying to predict the variable 
> V2 (y/n) from Class and all remaining variables.
> 
>> I also get solution but not such good like before.  
> 
> They are solutions to two different problems.
> 
> If you want to predict Class, then you need
> 
> Class ~ ., data = HouseVotes84
> 
> or, to specify exactly which variables to use as predictors of Class, 
> state them explicitly:
> 
> Class ~ V1 + V3 + V4, data = HouseVotes84
> 
> I think you should look at the documentation that comes with R (An 
> Introduction to R) or some of the contributed help documents on the R 
> Website to read up on model formulae and how to represent models using 
> this notation.
> 
> HTH
> 
> G
> 
> __
> 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.
> 
> 

Thank you very much!

-- 
View this message in context: 
http://www.nabble.com/Question-about-rpart%28sth%7E.%2Cdatabase%29-tp23117162p23128038.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] data$ID -> I always get a NULL

2009-04-19 Thread Grześ

I have database write as .csv file.
When I want to get sth from my database I get NULL, but I know that there is
sth! 
For example:

> data$ID
NULL
> data$kod
NULL

but command like below is always recognize by R
> data[2,3]
[1] '082'

In my opinion this problem is also connect with my attempt to create a tree.
I always get errors.

> t.tree0=rpart(ID~.,t.train)
Error in eval(expr, envir, enclos) : object "ID" not found

> t.tree0=rpart(kod~.,t.train)
Error in eval(expr, envir, enclos) : object "kod" not found

What I should do to create my simple trees?
-- 
View this message in context: 
http://www.nabble.com/data%24ID--%3E-I-always-get-a-NULL-tp23128214p23128214.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] package installation error

2009-04-19 Thread Joseph P Gray
After installing 2.9.0 I tried loading packages, but keep getting the following 
error.

package 'robustbase' successfully unpacked and MD5 sums checked
Error in normalizePath(path) : 
  path[1]="C:\Program Files\R\R-2.9.0\library/robustbase": The system cannot 
find the file specified

I've tried loading various packages with the same result.
Thanks for any help.

Pat Gray
Department of Anthropology
University of Wisconsin-Milwaukee
PO Box 413
Milwaukee, WI 53201-0413
414-229-4822
jpg...@uwm.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.


Re: [R] Including a vector element in an if statement

2009-04-19 Thread jim holtman
If all you want is a count, then you can construct a logical vector
and count the TRUEs:

sum(a9 < (mean(a9) / 2))

On Sun, Apr 19, 2009 at 5:58 PM, Enda Hargaden  wrote:
> Hi all,
>
> I've searched high and low on this and found nothing of help. I'm using
> v2.6.2 and trying to write a function that will count how many people from a
> dataset fall under a poverty line of 50% of the mean income.
>
> a9 is my 100-element vector of incomes. I want pa9 to be my vector that
> counts how many of these are classed as in poverty.
>
> My problem is that my command if(a9[i] < mean(a9)/2 ) returns an "argument
> is of length zero" error. But a9[i] is not really of length zero; if I
> remove the if() command and simply set pa9[i] = a9[i] in the loop it comes
> out fine.
>
> I don't think it's a problem with the type of variable either, because if I
> multiply the vector by 2 I get the "correct" output, so I think it's a
> problem with R interpreting my vector as a list of strings or anything.
>
> povertyline = function()
> {
> pa9 = c()
> i=0
>  while(i<=length(a9))
>  {
>    if(a9[i] < mean(a9)/2)
>    {
>    pa9[i] = a9[i]
>    }
>  i = i+1
>  }
> return(length(pa9))
> }
>
> Has anyone any ideas what's going wrong? (Just for clarification: yes, this
> is for my homework. However I've already done the assignment in Excel and
> I'm repeating it to improve my R'ing.)
>
> Thanks a lot,
> Enda
>
>        [[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.
>



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

What is the problem that you are trying to solve?

__
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] package installation error

2009-04-19 Thread Joseph P Gray
No, this is on Windows-Xp.

From: Erin Hodgess 
To: Joseph P. Gray 
Sent: Sun, 19 Apr 2009 19:17:34 -0500 (CDT)
Subject: Re: [R] package installation error

Hi Pat!

Are you using Windows Vista by any chance, please?

If so, try running as administrator.

It might help.

Sincerely,
Erin


On Sun, Apr 19, 2009 at 6:38 PM, Joseph P Gray  wrote:
> After installing 2.9.0 I tried loading packages, but keep getting the 
> following error.
>
> package 'robustbase' successfully unpacked and MD5 sums checked
> Error in normalizePath(path) :
>  path[1]="C:\Program Files\R\R-2.9.0\library/robustbase": The system cannot 
> find the file specified
>
> I've tried loading various packages with the same result.
> Thanks for any help.
>
> Pat Gray
> Department of Anthropology
> University of Wisconsin-Milwaukee
> PO Box 413
> Milwaukee, WI 53201-0413
> 414-229-4822
> jpg...@uwm.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.
>



-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.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] Presenting R Results in Webpages

2009-04-19 Thread robert denham
On Fri, Apr 17, 2009 at 3:36 AM, Jason Rupert wrote:

>
> I apologize in advance that this question is not specific to R, but I
> thought some R users may be using this in their work process flow.
>
> I would like to be able to have a tool (prefer "scriptable") that will take
> two images and some pre-written text and put it on an simple webpage.
>
>
If you were doing more elaborate things, or doing this often, you could
consider non-R approaches such as the Cheetah - python template engine.

[[alternative HTML version deleted]]

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


[R] plotCI (plotrix) problem

2009-04-19 Thread Derek Ogle
I am attempting to create a plot with intervals "stretched" in the
x-direction using plotCI() in the plotrix package.  The same data
provides an appropriate set of intervals when "stretched" in the
y-direction but I only get a lower interval when "stretched" in the
x-direction.

 

The data are as follows

 

mns <-
c(-0.00584,-0.00458,-0.00934,-0.00969,-0.01007,0.01146,-0.00261,-0.00287
,0.00035,-0.00248,0.00084,0.01183,-0.00617,-0.00789,-0.00405,-0.01076,0.
00285,0.01464,0.01665,0.00179,-0.00038,-0.00046,0.00388,0.00501,0.00237,
-0.00488,-0.00081,-0.00432,-0.00172,0.00574,0.00853,0.00869,-0.00551,-0.
00069,0.00047)

ses <-
c(0.001552,0.001341,0.001442,0.001511,0.001794,0.001735,0.001288,0.00136
4,0.001826,0.00196,0.001037,0.9,0.00153,0.00147,0.002195,0.001189,0.
002442,0.001293,0.000803,0.001359,0.001936,0.001431,0.001962,0.002132,0.
001879,0.002846,0.003047,0.003176,0.003178,0.00328,0.001725,0.003523,0.0
03681,0.002316,0.002367)

 

This plot works as expected ...

 

require(plotrix)

plotCI(1:length(mns),mns,ses)

 

... but this one does not ...

 

plotCI(mns,1:length(mns),ses,err="x")

 

If I multiply the ses values by successively larger values then more of
the points are plotted with the upper portion of the interval, e.g., ...

 

plotCI(mns,1:length(mns),10*ses,err="x")

 

which implies that this is a scaling issue.  >From this, I suspect (am
guessing) that the issue arises somewhere in this part of the plotCI()
code ...

 

nz <- abs(li - pmax(x - gap, li)) * x.to.in > 0.001

...

nz <- abs(ui - pmin(x + gap, ui)) * y.to.in > 0.001

 

but I don't quite understand what is going on here (and elsewhere in
plotCI()) and my "guesses" at corrections did not work.  My searches on
R-help were not fruitful.

 

So, does anyone have any suggestions?  Thanks in advance for any help.

 

 

Note my session information below ...

 

> sessionInfo()

R version 2.8.0 (2008-10-20) 

i386-pc-mingw32 

 

locale:

LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

 

attached base packages:

[1] stats graphics  grDevices datasets  tcltk utils methods
base 

 

other attached packages:

[1] plotrix_2.5-4  svSocket_0.9-5 TinnR_1.0.2R2HTML_1.59
Hmisc_3.5-2   

 

loaded via a namespace (and not attached):

[1] cluster_1.11.12 grid_2.8.0  lattice_0.17-20 svMisc_0.9-5
tools_2.8.0

 

 

 


[[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] Including a vector element in an if statement

2009-04-19 Thread David Winsemius


On Apr 19, 2009, at 5:58 PM, Enda Hargaden wrote:


Hi all,

I've searched high and low on this and found nothing of help. I'm  
using
v2.6.2 and trying to write a function that will count how many  
people from a

dataset fall under a poverty line of 50% of the mean income.

a9 is my 100-element vector of incomes. I want pa9 to be my vector  
that

counts how many of these are classed as in poverty.

My problem is that my command if(a9[i] < mean(a9)/2 ) returns an  
"argument

is of length zero" error. But a9[i] is not really of length zero; if I
remove the if() command and simply set pa9[i] = a9[i] in the loop it  
comes

out fine.

I don't think it's a problem with the type of variable either,  
because if I

multiply the vector by 2 I get the "correct" output, so I think it's a
problem with R interpreting my vector as a list of strings or  
anything.


See below. the 'if' control construct is not set up to accept vectors.
From the help page ?"if"
if(cond) expr
Arguments
condA length-one logical vector that is not NA.



povertyline = function()
{
pa9 = c()
i=0
while(i<=length(a9))
{
   if(a9[i] < mean(a9)/2)
   {
   pa9[i] = a9[i]
   }
i = i+1
}
return(length(pa9))
}

Has anyone any ideas what's going wrong? (Just for clarification:  
yes, this
is for my homework. However I've already done the assignment in  
Excel and

I'm repeating it to improve my R'ing.)


Jim gave you a perfectly workable solution, but you might find it  
instructive to review the difference between "if" and the function  
"ifelse". Generally "if" will not be useful in situations where you  
are doing comparisons on indexed objects whereas that is precisely  
what "ifelse" is designed to do. (Tthis was also pointed out in a  
response to a question earlier today.)



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] data$ID -> I always get a NULL

2009-04-19 Thread David Winsemius


On Apr 19, 2009, at 6:45 PM, Grześ wrote:



I have database write as .csv file.


The external sorage format is not likely to be relevant. What might be  
informative would be to produce the code that reads this file.


When I want to get sth from my database I get NULL, but I know that  
there is

sth!
For example:


data$ID

NULL

data$kod

NULL

but command like below is always recognize by R

data[2,3]

[1] '082'


Tell is what happens when you enter:

str(data)
class(data)

Perhaps the third column is not named "ID" or "kod" or the object is  
not a data.frame, but is rather a matrix.


--
David Winsemius



In my opinion this problem is also connect with my attempt to create  
a tree.

I always get errors.


t.tree0=rpart(ID~.,t.train)

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


t.tree0=rpart(kod~.,t.train)

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

What I should do to create my simple trees?
--
View this message in context: 
http://www.nabble.com/data%24ID--%3E-I-always-get-a-NULL-tp23128214p23128214.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.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] explicit documentation (was: get() versus getAnywhere())

2009-04-19 Thread ronggui
It is always unfair to complain about volunteer work, and what you
should do is to make contributions.

2009/4/20 Rolf Turner :
>
> On 19/04/2009, at 8:59 PM, Patrick Burns wrote:
>
>> Rolf Turner wrote:
>>>
>>> On 17/04/2009, at 10:21 PM, Duncan Murdoch wrote:
>>>
 Benjamin Tyner wrote:
>
> Many thanks Duncan. Perhaps this merits a more explicit note in the
> documentation?
>

 The quote I gave is from the documentation.  How could it be more
 explicit?
>>>
>>> This is unfortunately typical of the attitude of R-core people toward the
>>> documentation.  ``It's clear.'' they say.  ``It's explicit.''  Clear and
>>> explicit once you *know* what it's saying.  Not before, but.
>>
>> I think this unfairly blames R-core for being human.
>
>        Why is this unfair?  R-core is supposed to be superhuman! :-)
>
>                cheers,
>
>                        Rolf
>
> ##
> Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
>
> __
> 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.
>



-- 
HUANG Ronggui, Wincent
PhD Candidate
Dept of Public and Social Administration
City University of Hong Kong
Home page: http://asrr.r-forge.r-project.org/rghuang.html

__
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] PCA and automatic determination of the number of components

2009-04-19 Thread nikolay12

Hi all, 

I have relatively small dataset on which I would like to perform a PCA. I am
interested about a package that would also combine a method for determining
the number of components (I know there are plenty of approaches to this
problem). Any suggestions about a package/function?

thanks,

Nick
-- 
View this message in context: 
http://www.nabble.com/PCA-and-automatic-determination-of-the-number-of-components-tp23129941p23129941.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] Sweave: Howto write real TeX formula in plot

2009-04-19 Thread cls59


Bugzilla from n...@jonasstein.de wrote:
> 
> Hi,
> 
> i use Sweave to put plots in my .tex Documents. (pdflatex)
> Is there a nice solution for this:
> 
> a) get a real LaTeX formula in the plot area. 
> I have only found very complicate solutions. Is there sth. like 
> \formula{x^2 = \oint f} 
> 
> b) how can i format axis and legend to get exact the same font that is
> used in the TeX-document? 
> 
> Thank you for any help. 
> 
> 


baptiste auguie-2 wrote:
> 
> Perhaps try the pgfSweave package on r-forge?
> 
> http://r-forge.r-project.org/projects/pgfsweave/
> 
> HTH,
> 
> baptiste
> 
> 

Aye- the aim of the pgfSweave package is to make the integration of R and
TeX more seamless. Right now it does a great job with respect to fonts by
passing the actual typesetting and printing of figures off to LaTeX. This is
accomplished using the java utility eps2pgf and requires the PGF/TiKZ
package for LaTeX:

http://sourceforge.net/projects/pgf/

The default behavior is to pass text directly to LaTeX unfiltered- this
means that things like percent signs and dollar signs will need to be
escaped by backslashes.

-Charlie



-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Sweave%3A-Howto-write-real-TeX-formula-in-plot-tp23127536p23130478.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] Modelling an "incomplete Poisson" distribution ?

2009-04-19 Thread Emmanuel Charpentier
Dear Ben,

Le samedi 18 avril 2009 à 23:37 +, Ben Bolker a écrit :
> Emmanuel Charpentier  bacbuc.dyndns.org> writes:
> 
> > 
> > I forgot to add that yes, I've done my homework, and that it seems to me
> > that answers pointing to zero-inflated Poisson (and negative binomial)
> > are irrelevant ; I do not have a mixture of distributions but only part
> > of one distribution, or, if you'll have it, a "zero-deflated Poisson".
> > 
> > An answer by Brian Ripley
> > (http://finzi.psych.upenn.edu/R/Rhelp02/archive/11029.html) to a similar
> > question leaves me a bit dismayed : if it is easy to compute the
> > probability function of this zero-deflated RV (off the top of my head,
> > Pr(X=x)=e^-lambda.lambda^x/(x!.(1-e^-lambda))), and if I think that I'm
> > (still) able to use optim to ML-estimate lambda, using this to
> > (correctly) model my problem set and test it amounts to re-writing some
> > (large) part of glm. Furthermore, I'd be a bit embarrassed to test it
> > cleanly (i. e. justifiably) : out of the top of my head, only the
> > likelihood ration test seems readily applicable to my problem. Testing
> > contrasts in my covariates ... hum !
> > 
> > So if someone has written something to that effect, I'd be awfully glad
> > to use it. A not-so-cursory look at the existing packages did not ring
> > any bells to my (admittedly untrained) ears...
> > 
> > Of course, I could also bootstrap the damn thing and study the
> > distribution of my contrasts. I'd still been hard pressed to formally
> > test hypotheses on factors...
> > 
> 
>   I would call this a truncated Poisson distribution, related
> to hurdle models.  You could probably use the hurdle function
> in the pscl package to do this, by ignoring the fitting to
> the zero part of the model.  On the other hand, it might break
> if there are no zeros at all (adding some zeros would be a
> pretty awful hack/workaround).

Indeed ... 

>   If you defined a dtpoisson() for the distribution of the
> truncated Poisson model, you could probably also use bbmle
> with the formula interface and the "parameters" argument.

This I was not aware of... Thank you for the tip !

By the way, I never delved into stats4, relying (erroneously) on its
one-liner description in CRAN, which is (more or less) an implementation
of stats with S4 classes. Therefore mle escaped me also... May I suggest
a better one-liner ? (This goes also for bbmle...)

>   The likelihood ratio test seems absolutely appropriate for
> this case.  Why not?

Few data, therefore a bit far from the asymptotic condition...

Anyway, a better look at my data after discovering a bag'o bugs in the
original files led me to reconsider my model : I wanted to assess, among
other things, the effect of a boolean (really a two-class variable).
After the *right* graph, I now tend to think that my distribution is
indeed zero-deflated Poisson in one group and ... zero-deflated negative
binomial in the other (still might be zero-deflated Poisson with very
small mean, hard to say graphically...). Which gives me some insights on
the mechanisms at work (yippeee !!) but will require some nonparametric
beast for assessing central value differences (yes, this still has a
meaning...), such as bootstrap.

__
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] plotCI (plotrix) problem

2009-04-19 Thread Dieter Menne
Derek Ogle  northland.edu> writes:

> 
> I am attempting to create a plot with intervals "stretched" in the
> x-direction using plotCI() in the plotrix package.  The same data
> provides an appropriate set of intervals when "stretched" in the
> y-direction but I only get a lower interval when "stretched" in the
> x-direction.
> 
> nz <- abs(ui - pmin(x + gap, ui)) * y.to.in > 0.001

It's a copy-paste typo. The above line should be 
nz <- (abs(ui - pmin(x + gap, ui)) * x.to.in) > 0.001

Dieter

__
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] plotCI (plotrix) problem

2009-04-19 Thread Dieter Menne
Derek Ogle  northland.edu> writes:

> 
> I am attempting to create a plot with intervals "stretched" in the
> x-direction using plotCI() in the plotrix package.  The same data
> provides an appropriate set of intervals when "stretched" in the
> y-direction but I only get a lower interval when "stretched" in the
> x-direction.
> 
> The data are as follows
..

This looks  like a bug to me, and you should contact the author.
As a temporary workaround, use plotCI from package gplots which is
one father (the grandfather is Bill Venables).

Dieter

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