Re: [R] Table and ftable

2007-09-04 Thread David Barron
There might be simpler ways, but you can certainly do this with the
reshape package, like this:

library(reshape)
dta - read.table(clipboard,header=TRUE)

  sic level area
1   a   211  2.4
2   b   311  2.3
3   b   322  0.2
4   b   322  0.5
5   c   100  3.0
6   c   100  1.5
7   c   242  1.5
8   d   222  0.2


mlt.dta - melt(dta)
cst.dta - cast(mlt.dta,sic~level,sum)

  sic 100 211 222 242 311 322
1   a  NA 2.4  NA  NA  NA  NA
2   b  NA  NA  NA  NA 2.3 0.7
3   c 4.5  NA  NA 1.5  NA  NA
4   d  NA  NA 0.2  NA  NA  NA

Then just replace the NAs with 0s.

HTH.

David Barron
On 9/4/07, Giulia Bennati [EMAIL PROTECTED] wrote:
 Dear listmembers,
 I have a little question: I have my data organized as follow

 sic  level  area
 a2112.4
 b3112.3
 b3220.2
 b3220.5
 c1003.0
 c1001.5
 c2421.5
 d2220.2

 where levels and sics are factors. I'm trying to obtain a matrix like this:

 level
  211311322   100242 222
 sic
 a2.4  0   0   0   00
 b 0   2.30.7 0   00
 c 00  0   4.5 1.5 0
 d 00  00   0   0.2

 I tryed with table function as
 table(sic,level) but i obteined only a contingency table.
 Have you any suggestions?
 Thank you very much,
 Giulia

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] How to fit an linear model withou intercept

2007-08-23 Thread David Barron
A number of alternatives, such as:

lm(y ~ 0 + x)
lm(y ~ x -1)

See ?formula

On 8/23/07, Michal Kneifl [EMAIL PROTECTED] wrote:
 Please could anyone help me?
 How can I fit a linear model where an intercept has no sense?
  Thanks in advance..

 Michael

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Regression with Missing values. na.action?

2007-07-26 Thread David Barron
na.exclude should give the same results as na.omit, which is the
default na.action.  Is the number of complete cases the same in these
two regressions?

On 26/07/07, Vaibhav Gathibandhe [EMAIL PROTECTED] wrote:
 Hi all,

 Can you please tell me what is the problem here.

 My regression eq is  y = B0 + B1X1 +B2X2 +e
 And i am interested in coefficient B1

 I am doing regression with two cases:

 1) reg-lm(y ~ X1 + X2, sam) where sam is the data

 2) reg-lm(y ~ X1 + X2, sam, na.action= na.exclude) . I have missing values
 in X1


 but the values of coefficient is not consistent in two cases.

 Actually B1 in case one sould be smaller than B1 in case 2. But sometimes it
 comes greater.

 I can't figure it out. Is there some problem with *na.action ? *My sample
 size is 100


 *Regards,*
 *Vaibhav*

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] standardization

2007-07-13 Thread David Barron
Try having a look at the scale and sweep functions.

David

On 13/07/07, Amir_17 [EMAIL PROTECTED] wrote:
 Hi
   I have dataframe which contain 5 columns and 1000 records. I want standard 
 each cell.
   I want range each column  between 0 and 1 . I think i must use loop?
   could you help me?


 -
 Moody friends. Drama queens. Your life? Nope! - their life, your story.

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Standard Probability Distributions.

2007-06-30 Thread David Barron
Have a look in the stats package for the distributions that come with
base R.  There is a package called SuppDists that has some others, and
no doubt there are others.  Try RSiteSearch to look for specific
distributions.

On 30/06/07, Marcus Vinicius [EMAIL PROTECTED] wrote:
 Dear all,
 What are the standard probability distributions available in R?
 I need some as Normal-Truncated, Half-Normal, Gamma, Chi-squared, Wishard,
 etc.
 Thanks.
 Marcus Vinicius

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] transposing data.frames

2007-06-25 Thread David Barron
t(KK) will transpose your data frame

On 25/06/07, Christoph Heibl [EMAIL PROTECTED] wrote:
 Hello,
 This must be simple...
 Thanks a lot
 - Christoph

 # Imagine you have a list, e.g:

 K - list(1:10, 2:11, 9:18)
 K

 # Transforming to dataframe...

 KK - as.data.frame(K)

 # ... one obtaines the list elements as column.

 KK

 # But I need the list elements as rows
 # How can I achieve this? Is there a simple way to transpose
 data.frames?

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Highliting a text in a plot

2007-06-24 Thread David Barron
How about this:

hilight - function(x,y,s, bg=yellow) {
text.width - strwidth(s)
text.height - strheight(s)
rect(x,y,x+text.width,y+text.height,col=bg,border=NA)
text(x,y,s,adj=c(0,0))
}

plot(1:10,1:10,type=b)
hilight(4,4,Point)


On 23/06/07, Maja Schröter [EMAIL PROTECTED] wrote:
 Hi everyone,

 I want to highlight something in a plot.
 So I want to write a text with a yellow background.


 I tried to make use of text(x,y,hallo,bg=yellow)
 but that does not work.

 I know I am a handful. Sorry!

 Maja!
 --

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Could not find lmer function in {Matrix} package

2007-06-19 Thread David Barron
It's now in the lme4 package.

On 19/06/07, Steve Brady [EMAIL PROTECTED] wrote:
 I am having trouble calling the lmer function in the {Matrix}
 package.  I first installed and loaded {Matrix} as follows:

   install.packages(Matrix)
   library(Matrix)

 The package loaded successfully, however when I attempted to call
 lmer, I received the following message:

 Error: could not find function lmer

 I also tried:

  ?lmer

 which produced no search results.

 I have attempted these actions in both MacOSx R Versions 2.4.1 and
 2.5.0.  I have also tried this in Version 2.5.1. beta on a Windows
 machine.

 Thanks in advance for any suggestions.

 Steve
 
 Steven P. Brady, M.E.Sc (2007)
 School of Forestry  Environmental Studies
 Yale University
 http://www.cbc.yale.edu/people/skelly/steveb.html




 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Histogram

2007-06-19 Thread David Barron
I expect there's a more elegant way of doing this, but this should work:

set.seed(101)
x - rnorm(500,sd=.03)
hist (x, seq(-0.1,0.1,0.01),freq = FALSE)
d - density(x,bw=SJ)
lowt - d$x  -.05
upt - d$x  .05
lines (d$x[lowt],d$y[lowt], col = red)
lines(d$x[upt],d$y[upt], col = red)


On 19/06/07, livia [EMAIL PROTECTED] wrote:

 Hello, I am using the following codes to plot a histogram and density line
 for x. For the density line, I just want it to show the two tails, eg, for x
 larger than 0.05 ans smaller than -0.05

 hist (x, seq(-0.1,0.1,0.01),freq = FALSE)
 lines (density(x,bw=SJ), x 0.05  x (-0.05), col = red)

 But is does not work, can anyone give me some advice?



 --
 View this message in context: 
 http://www.nabble.com/Histogram-tf3947281.html#a11197644
 Sent from the R help mailing list archive at Nabble.com.

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Storing output vector form a loop as a matrix

2007-06-17 Thread David Barron
I'm not sure I've completely understood this, but would this do what you want:


for (i in 1:N){

aa - sample(a, replace=TRUE)

c -data.frame(b,aa)

output - by(c, aa, function(x) sum(x$b))

output.matrix[,i] - as.vector(output)
}



On 17/06/07, Economics Guy [EMAIL PROTECTED] wrote:
 Based on help files and searching the archives and help from the listserv I
 have managed to build my monte carlo program.

 However I cannot get the proper syntax for running the loop and storing the
 output of each loop (which is a vector) into a matrix.

 I took out some of the crazy code I was writing, but here is what I have:

 

 rm(list = ls(all = TRUE))
 # removes everything

 a -c(A,C,B,A,B,C)

 b -c(10,20,30,40,50,60)

 c -data.frame(a,b)

 N=10 #Number of Loops

 output.matrix - matrix(0.0,3,N)

 #I need to START LOOP HERE

 a - sample(a, replace=TRUE)

 c -data.frame(b,a)

 output.vector - by(c, a, function(x) sum(x$b))

 output.vector - as.vector(output)

 output.vector - data.frame(output)

 #END LOOP here


 --

 What I would like to have at the end is the output.matrix contain as a
 column the  output.vector from  each iteration. The actual data frame I
 will be running has 60,000 observations and I am going to run 2
 iterations so speed is important too.

 Thanks so much

 EG

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Recoding

2007-06-11 Thread David Barron
I've used the one in car with no problems.  For grouping a continuous
variable you might also consider cut.

On 11/06/07, David Scott [EMAIL PROTECTED] wrote:

 I want to do some recoding of variables: code Age into groups and recode a
 factor into a smaller number of levels.

 There are a couple of options for recode functions, in the car package and
 in memisc, and I think in gmisc.

 Does anyone have any opinions on the the easiest, most reliable approach
 for these problems?

 David Scott

 _
 David Scott Department of Statistics, Tamaki Campus
 The University of Auckland, PB 92019
 Auckland 1142,NEW ZEALAND
 Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000
 Email:  [EMAIL PROTECTED]

 Graduate Officer, Department of Statistics
 Director of Consulting, Department of Statistics

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] How to plot vertical line

2007-06-09 Thread David Barron
abline(v=c(intercept1,intercept2,intercept3))

On 09/06/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi,I have a result from polr which I fit a univariate variable (of ordinal 
 data) with probit function. What I would like to do is to overlay the plot of 
 my fitted values with the different intercept for each level in my ordinal 
 data. I can do something like:lines(rep(intercept1, 1000), 
 seq(from=0,to=max(fit),by=max(fit)/1000))where my intercept1 is, for example, 
 the intercept that breaks between y=1 and y=2 labels and the max(fit) is the 
 maximum of overall fitted values or maximum of all ordinal y labels. I'm 
 wondering if there is better way to do this? If you could let me know, I 
 would really appreciated. Thank you.- adschai

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] comparison of two logistic regression models

2007-06-07 Thread David Barron
You could use lmer in the lme4 package to fit the logistic regression
with random effect as it does report the AIC.

On 07/06/07, Anna-Maria Tyriseva [EMAIL PROTECTED] wrote:
 Dear list members!

 Could you help me?
 I would like to compare two models: a) logistic regression model, 3
 factors as independents b) logistic regression model, 3 factors and one
 random effect as independents (function glmmPQL). AIC are not available
 with PQL and model comparison using ANOVA is not possible. What should I do?

 Thanks in advance.
 Anna-Maria

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] list

2007-06-06 Thread David Barron
There's no special method, just create a list in the usual way.  For example:

 l1-list(a=letters[1:5],b=letters[6:10])
 l1
$a
[1] a b c d e

$b
[1] f g h i j

 l2-list(c=LETTERS[1:5],d=LETTERS[6:10])
 l2
$c
[1] A B C D E

$d
[1] F G H I J

 l3-list(l1,l2)
 l3
[[1]]
[[1]]$a
[1] a b c d e

[[1]]$b
[1] f g h i j


[[2]]
[[2]]$c
[1] A B C D E

[[2]]$d
[1] F G H I J



On 06/06/07, elyakhlifi mustapha [EMAIL PROTECTED] wrote:
 hello,
 I wanna know how to create a list of list if it's possible and if it isn't 
 possible how to do without.
 thanks.


   
 _

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] using cut

2007-05-26 Thread David Barron
You can split a vector into groups with equal numbers using the
quantcut function in the gtools package.  For example, to split into
two groups, use:

c - quantcut(y,c(0,.5,1))

On 26/05/07, J. Scott Olsson [EMAIL PROTECTED] wrote:
 Suppose I have some data

 x - rnorm(1000);
 y - x*x;

 then try to cut it into 2 chunks,

 c - cut(y, breaks=2);

 summary(y)
  Min.   1st Qu.Median  Mean   3rd Qu.  Max.
 6.879e-06 9.911e-02 3.823e-01 9.499e-01 1.297e+00 8.342e+00

 summary(c)
 (-0.00833,4.17] (4.17,8.35]
 958  42

 Is that the correct behavior? Why is the left hand side of the interval
 negative?

 How would I split a data vector into groups/intervals such that each
 interval contained the same number of points?


 Thanks much!
 Scott

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] impossible to open SPSS file

2007-04-29 Thread David Barron
Have a look at FAQ 2.16 in the R for Windows FAQ.

On 29/04/07, Frank Thomas [EMAIL PROTECTED] wrote:
 Hi,
 I try to import a SPSS file with foreign but don't succeed. I looked
 into the help pages but find no answer. The file has been produced with
 SPSS 15 but I got the same error with a file in SPSS portable format.

 mydata-read.spss(C:\Rdata\ESS1_ICT.SAV)
 Erreur dans read.spss(C:RdataESS1_ICT.SAV) :
 impossible d'ouvrir le fichier

 I guess the error is evident for everyone else, but I don't see it.
 Thanks
 Frank Thomas

 --
 ..
 Dr. Frank Thomas
 FTR Internet Research
 93110 Rosny-sous-Bois
 France

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] No fit statistics for some models using sem

2007-03-07 Thread David Barron
It's not the correlation as such that is the problem; it's because you
only have 10 degrees of freedom available with four observed
variables, and you are estimating 10 parameters, which is why you get
a chi square of zero.  When you remove any one free parameter (such as
the correlation), the model becomes identified.

On 07/03/07, Ista Zahn [EMAIL PROTECTED] wrote:
 Hi,

 New to both R and SEM, so this may be a very simple question. I am
 trying to run a very simple path analysis using the sem package.
 There are 2 exogenous (FARSCH, LOCUS10) and 2 endogenous (T_ATTENT,
 RMTEST) observed variables in the model.  The idea is that T_ATTENT
 mediates the effect of FARSCH and LOCUS10 on RMTEST. The RAM
 specification I used is

 FARSCH - T_ATTENT, y1x1, NA
 LOCUS10 - T_ATTENT, y1x2, NA
 FARSCH - RMTEST10, y2x1, NA
 LOCUS10 - RMTEST10, y2x2, NA
 T_ATTENT - RMTEST10, y2y1, NA
 FARSCH - FARSCH, x1x1, NA
 LOCUS10 - LOCUS10, x2x2, NA
 T_ATTENT - T_ATTENT, y1y1, NA
 RMTEST10 - RMTEST10, y2y2, NA
 LOCUS10 - FARSCH, x2x1, NA

 This model runs, but using the summary function does not return the
 usual model fit statistics, only the following:

 Model Chisquare =  0   Df =  0 Pr(Chisq) = NA
   Chisquare (null model) =  8526.8   Df =  6
   Goodness-of-fit index =  1
   BIC =  0

 If I omit the last line from the RAM specification(i.e., delete
 LOCUS10 - FARSCH, x2x1, NA), I DO get all the usual statistics:

   Model Chisquare =  1303.7   Df =  1 Pr(Chisq) = 0
   Chisquare (null model) =  8526.8   Df =  6
   Goodness-of-fit index =  0.95864
   Adjusted goodness-of-fit index =  0.58639
   RMSEA index =  0.30029   90% CI: (NA, NA)
   Bentler-Bonnett NFI =  0.84711
   Tucker-Lewis NNFI =  0.082726
   Bentler CFI =  0.84712
   BIC =  1294.1

 My understanding is the you should always put in the correlation
 between exogenous predictors, but when I do this I don't get fit
 statistics. Can anyone help me understand what is happening here?

 Thank you,

 Ista

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] dispersion_parameter_GLMM's

2007-03-06 Thread David Barron
That amount of overdispersion would make the use of a poisson model
very questionable, and will very likely result in estimated standard
errors that are too low, hence the change in statistical significance
when you switch to quasipoisson.

On 06/03/07, Cristina Gomes [EMAIL PROTECTED] wrote:
 Hi all,
 I was wondering if somebody could give me advice regarding the
 dispersion parameter in GLMM's. I'm a beginner in R and basically in
 GLMM's. I've ran a GLMM with a poisson family and got really nice
 results that conform with theory, as well with results that I've
 obtained previously with other analysis and that others have obtained in
 similar studies. But the dispersion parameter is too large (25 compared
 to 1). So I ran a quasipoisson that allows for overdispersion and all of
 the significant results fell out. My question is, how much does
 overdispersion invalidate ones results when using a poisson family? What
 could the reason be for having non significant results with a
 quasipoisson distribution?
 If anybody could give me some help with this or/and recommend me
 literature that is somewhat comprehensible to lay people (i.e. non
 statisticians) that would be great.
 Thanks in advance,
 Cristina.

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Identifying points in a plot that have duplicate values

2007-03-05 Thread David Barron
Have a look at ?sunflowerplot, which not only produces a scatterplot
showing multiple points with the same coordinates using special
symbols, but will also produce a list showing the number of points at
each coordinate as well.

On 05/03/07, David Lloyd [EMAIL PROTECTED] wrote:
 I have code like this: -

 #---
 --

 x=scan()
 0 0 0 0 0 1 2 3 4

 y=scan()
 1 1 1 2 2 1 3 4 5

 plot(x,y)

 identify(0,1,3) #Allows me to select manually to identify co-ordinate
 (0,1) as being duplicated 3 times
 identify(0,2,2) #Allows me to select manually to identify co-ordinate
 (0,2) as being duplicated 2 times
 #---
 --

 Is there not a way I can automatically display if points are duplicated
 and by how many times?

 I thought if I 'jittered' the points ever so slightly I could get an
 idea of how many duplicates there are but with 100 points the graph
 looks very messy.

 Regards
 DaveL








 Click for free info on getting an MBA and make $200K/ year




 Need cash? Click to get a payday loan
 http://tagline.bidsystem.com/fc/CAaCDCZ60nyjrrOboFeUJgRjigwgNftK/



 span id=m2wTlpfont face=Arial, Helvetica, sans-serif size=2 
 style=font-size:13.5px___BRGet
  the Free email that has everyone talking at a 
 href=http://www.mail2world.com target=newhttp://www.mail2world.com/abr  
 font color=#99Unlimited Email Storage #150; POP3 #150; Calendar 
 #150; SMS #150; Translator #150; Much More!/font/font/span
 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Rbind with data frames -- column names question

2007-03-05 Thread David Barron
I don't know if this is the right way, but I think this would work
(I'm assuming you want the result to be a data frame):

data.frame(rbind(as.matrix(A),B))

You might get a warning about row names, but I think it works OK.

On 05/03/07, Gregg Lind [EMAIL PROTECTED] wrote:

 As part of my work, I am trying to append matrices onto data frames.
 Naively I assumed that when rbinding a data.frame and matrix, the matrix
 would be coerced and appended, keeping the names from the data frame.
 Clearly, I am not fully understanding the process by which rbind works.

 Example code:

   A-data.frame(1,1,1); names(A)=letters[1:3] ; B-matrix(0,2,3)
   rbind(A,B)
 Error in match.names(clabs, names(xi)) : names do not match previous names:
 V1, V2, V3
   rbind(A,as.data.frame(B))
 Error in match.names(clabs, names(xi)) : names do not match previous names:
 V1, V2, V3



 Is there a right way to combine the two such that the both end up
 having the same column names?

 I have tried to understand the deparse.level argument of rbind, but it
 doesn't seem to do what I'm asking.

 Thank you for any help you can give.


 Gregg
 --
 Gregg Lind, M.S.

 Division of Epidemiology and Community Health
 School of Public Health
 University of Minnesota, United States

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Chi Square with two tab-delimited text files

2007-02-26 Thread David Barron
It's a bit difficult to advise without knowing what the rows and
columns represent, but why not just calculate the statistic yourself,
given that you already have observed and expected values?  For
example:

chi2 - sum((y-x)^2/x)



On 26/02/07, Carina Brehony [EMAIL PROTECTED] wrote:
 Yes, I would like to do a goodness-of-fit test.

 -Original Message-
 From: Petr Klasterecky [mailto:[EMAIL PROTECTED]
 Sent: 26 February 2007 11:50
 To: Carina Brehony
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] Chi Square with two tab-delimited text files

 Carina Brehony napsal(a):
  Hi,
  I want to do a chi square test and I have two tab delimited text files
 with
  Expected and Observed values to compare.  Each file contains only the
 values
 snip

 There are a lot of chi^2 tests, most of them compare OE quantities and
 it is not clear which one you want to use. I'd guess a goodness of fit
 test, but who knows? See ?chisq.test and the examples given there. It
 also tells you that the y-argument is ignored if x is a matrix (that's
 probably the reason why you get different results using read.table and
 scan).
 Petr
 --
 Petr Klasterecky
 Dept. of Probability and Statistics
 Charles University in Prague
 Czech Republic

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Chi Square with two tab-delimited text files

2007-02-26 Thread David Barron
In that case, you can just ignore the expected values and use the
observed values in the chisq.test.  The reason you got a p value of 1
before is because the second argument was ignored, and so you did a
chi square test on the expected values alone.

If you have loaded the obseved values into a matrix y using read.table
as in your first example, then just use chisq.test(y).  But you should
notice that you have a lot of zero cells and so probably lots of small
expected values, which is a problem for the chi square test.



On 26/02/07, Carina Brehony [EMAIL PROTECTED] wrote:
 Hi,
 The files look like below and the rows and columns are numbers of genetic
 types e.g. row1 is type 4; column1 is type A. So for, row1:column1 cell
 there are 78 type 4/type A combinations.  I hope this makes sense!



 78  500 18  6   0   4   0   1   6
 1   1   0   0   0   1   0   0   0   0
 0   1   0   0   0   0   0   2   1   0
 0   0   1   0   0   0   0   23  0   0
 0   7   0   0   7   0   0   0   6   0
 8   0   0   0   0   0   0   14  0   0
 0   0   0   0   0   0   0   5   0   0
 0   0   0   0   45  0   0   0   0   0
 0   0   0   0   0   0   0   3   0   40
 0   0   0   0   0   0   0   0   0   0
 0   0   0   12  0   0   0   0   8   4
 0   0   0   0   0   0   etc...





 -Original Message-
 From: David Barron [mailto:[EMAIL PROTECTED]
 Sent: 26 February 2007 12:12
 To: Carina Brehony; r-help
 Subject: Re: [R] Chi Square with two tab-delimited text files

 It's a bit difficult to advise without knowing what the rows and
 columns represent, but why not just calculate the statistic yourself,
 given that you already have observed and expected values?  For
 example:

 chi2 - sum((y-x)^2/x)



 On 26/02/07, Carina Brehony [EMAIL PROTECTED] wrote:
  Yes, I would like to do a goodness-of-fit test.
 
  -Original Message-
  From: Petr Klasterecky [mailto:[EMAIL PROTECTED]
  Sent: 26 February 2007 11:50
  To: Carina Brehony
  Cc: r-help@stat.math.ethz.ch
  Subject: Re: [R] Chi Square with two tab-delimited text files
 
  Carina Brehony napsal(a):
   Hi,
   I want to do a chi square test and I have two tab delimited text files
  with
   Expected and Observed values to compare.  Each file contains only the
  values
  snip
 
  There are a lot of chi^2 tests, most of them compare OE quantities and
  it is not clear which one you want to use. I'd guess a goodness of fit
  test, but who knows? See ?chisq.test and the examples given there. It
  also tells you that the y-argument is ignored if x is a matrix (that's
  probably the reason why you get different results using read.table and
  scan).
  Petr
  --
  Petr Klasterecky
  Dept. of Probability and Statistics
  Charles University in Prague
  Czech Republic
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 


 --
 =
 David Barron
 Said Business School
 University of Oxford
 Park End Street
 Oxford OX1 1HP




-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Sorting rows of a binary matrix

2007-02-22 Thread David Barron
I'm sure there are more elegant ways, but this should work:

 ix-order(mat[,1],mat[,2],mat[,3])
 ix
[1] 1 5 3 7 2 6 4 8
 mat[ix,]
  Var1 Var2 Var3
1000
5001
3010
7011
2100
6101
4110
8111


On 22/02/07, Serguei Kaniovski [EMAIL PROTECTED] wrote:

 Hallo,

 The command:

 x - 3
 mat - as.matrix(expand.grid(rep(list(0:1), x)))

 generates a matrix with 2^x columns containing the binary representations
 of the decimals from 0 to (2^x-1), here from 0 to 7. But the rows are not
 sorted in this order.

 How can sort the rows the ascending order of the decimals they represent,
 preferably without a function which converts binaries to decimals (which I
 have)? Alternatively, generate a matrix that has the rows sorted that way?

 Thanks,
 Serguei
 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] residuals and glm

2007-02-22 Thread David Barron
You really need to look at ?glm and ?residuals.glm.

resfit$residuals are the *working* residuals, which are not typically
very useful in themselves.  Far better to use the extractor function.
This enables you to obtain a number of different types of residuals,
but the default (and therefore the type you have obtained) are
deviance residuals.  You can also specify other types, such as pearson
residuals.

Hope this helps.
David

On 22/02/07, Martin Olivier [EMAIL PROTECTED] wrote:
 Hi all,

 I have some problems to compute the residuals from a glm model with
 binomial distribution.

 Suppose I have the following result :
 resfit-glm(y~x1+x2,weights=we,family=binomial(link=logit))

 Now I would like to obtain the residuals .
 the command residuals(resfit) and the vector resfit$residuals give
 different
 results, and they do not correspond to residuals E(yi)-yi (that is
 resfit$fitted-resfit$y)

 so, I would like to know what formula  is applied to compute these
 residuals.
 And moreover,  if I want to compute the standardized residuals, what is the
 right command from the glmfit result.
 Is it
 (resfit$fitted-resfit$y)/sqrt(1/resfit$prior*resfit$fitt*(1-resfit$fitt)) ??


 Thanks for your help,
 Olivier.

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Data frame: how to create list of row max?

2007-02-19 Thread David Barron
Try do.call(pmax,c(dataframe[,intensityindices],na.rm=TRUE))

This is like the second example in the help page for do.call

On 19/02/07, Johannes Graumann [EMAIL PROTECTED] wrote:
 On Monday 19 February 2007 11:53, Prof Brian Ripley wrote:
  do.call(pmax, dataframe[,intensityindeces])
 Thank you very much for your help!

 Any idea why do.call(pmax,list(na.rm=TRUE),dataframe[,intensityindeces])
 would give me

 Error in if (quote) { : argument is not interpretable as logical
 In addition: Warning message:
 the condition has length  1 and only the first element will be used in: if
 (quote) {

 ?

 Thanks, Joh

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





-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Advice on visual graph packages

2007-02-13 Thread David Barron
You might also want to look at the network package, which includes a
plot method for network objects that is pretty flexible.  It also
enables you to convert a network object into various different matrix
reprentations.

On 13/02/07, Jarrett Byrnes [EMAIL PROTECTED] wrote:
 Hey, all.  I'm looking for packages that are good at two things

 1) Drawing directed graphs (i.e nodes and edges), both with single
 and double headed arrows, as well as allowing for differences in line
 width and solid versus dashed.  Note: I've tried Rgraphviz here, but
 have run into some problems (which seem fixable and I may go with it
 in the end), and it doesn't satisfy need # 2 (which would be ideal if
 there is a package that does both).

 2) Allowing a user to create a directed graph, and have some text
 object created that can be reprocessed easily reprocessed into a
 matrix representation, or other representation of my choosing.   I've
 tried dynamicGraph, but it seems buggy, and continually either
 crashes, behaves very erratically (nodes disappearing when I modify
 edges), nor is it clear from the UI how one outputs a new graph, nor
 how one even accesses many graph attributes.  This may be my own
 ignorance on the latter.

 Do you have any suggestions?

 Thanks!

 -Jarrett




 --
 A Quick and (Very) Dirty Guide to Stats in R
 http://didemnid.ucdavis.edu/rtutorial.html


 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] extract submatrix with unique names

2007-02-09 Thread David Barron
This should do it, assuming you data is in a data frame called dat:

sel - unique(dat$V1)
ix - match(sel,dat$V1)
dat[ix,]


On 09/02/07, Glazko, Galina [EMAIL PROTECTED] wrote:
 Dear list,



 I have a table where first 3 columns are identical if the name in the
 first column is the same, and

 the number in N4 is slightly different for all identical names, like
 this:

 ---

 29Mm.1_at   3  +  93649936

 30Mm.1_at   3  +  93649990

 31Mm.1_at   3  +  93649993

 32Mm.1_at   3  +  93650001

 33Mm.1_at   3  +  93650010

 34   Mm.10_at   4  + 147438101

 35   Mm.10_at   4  + 147438192

 36   Mm.10_at   4  + 147438214

 37   Mm.100043_at   5  +  31602952

 38   Mm.100043_at   5  +  31602982

 39   Mm.100043_at   5  +  31603000

  ---



 I need to select unique identifiers in column N 1, without paying
 attention to what is in column N4, taking the first number in N4
 corresponding to first unique ID in N1, like this:

 29Mm.1_at   3  +  93649936

 34   Mm.10_at   4  + 147438101

 37   Mm.100043_at   5  +  31602952



 Could someone tell me how to do it without FOR cycle over all IDs in N1?



 Thank you!



 Best regards

 Galina






 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Zeta and Zipf distribution

2007-02-08 Thread David Barron
Does the zipf function in the VGAM package do what you want?

On 08/02/07, Mauro Rossi [EMAIL PROTECTED] wrote:

 Dear R user,
 I want to estimate the parameter of ZETA or/and ZIPF distributions
 using R, given a series of integer values. Do you know a package
 (similar to MASS) or a function (similar to fitdistr) I can use to
 estimate the parameter of these distributions using MLE method?
 Otherwise do you know a function (which use MLE method to estimate
 distribution parameters) that allow me to specify a PDF or PMF?
 Thanks,
 Regards
 Mauro Rossi

 --
 Mauro Rossi
 Istituto di Ricerca per la Protezione Idrogeologica
 Consiglio Nazionale delle Ricerche
 Via della Madonna Alta, 126
 06128 Perugia
 Italia
 Tel. +39 075 5014421
 Fax +39 075 5014420

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




-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

[[alternative HTML version deleted]]

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


Re: [R] Zeta and Zipf distribution

2007-02-08 Thread David Barron
I don't claim to be a huge expert on this, but I think you are mistaken
about what you are getting when you use the zipf family with the vglm
function.  From what I can tell from the documentation, this does indeed
give you an estimate of the parameter of the zipf distribution.  I've tried
to test this using some random numbers (probably not strictly correct
procedure, but I think it's a reasonable approximation):

set.seed(1234)
 N - 5
  y - (1:N)
  alpha - 2.5  # this is the parameter of the zipf distribution
  p - 1/(y^alpha) ; p - p/sum(p)
  n - 10
  x - sample (y, n, replace=TRUE, prob=p)
w - as.vector(table(x))
fit = vglm  (y ~ 1, zipf(link=identity, init=2), tra=TRUE, weight=w)
 Coef(fit)

   s
2.501086

Is this not what you need?

On 08/02/07, Mauro Rossi [EMAIL PROTECTED] wrote:

 Dear David,
 thank you for your reply.
 I tried to use the package VGAM, the function zipf and also the
 function zetaff, but these functions don't allow me to estimate
 parameters directly, I have to use a Gerneralized Linear Model or a
 Generalized Additive Model (vgam or vglm functions) and I don't want to
 use those. Don't you know a way to apply these tools to my data?
 At the end my PMF has to be Y=f(X) where f(X) is a zeta or a zipf
 distribution, while using VGAM the PMF is Y = b0 + b1*f(X1)+ ...
 +bn*f(Xn). Do you know how I can write the script using the VGAM
 function for the PMF I need?

 Thank you in advance,

 Mauro Rossi


 David Barron ha scritto:
  Does the zipf function in the VGAM package do what you want?
 
  On 08/02/07, *Mauro Rossi* [EMAIL PROTECTED]
  mailto:[EMAIL PROTECTED] wrote:
 
  Dear R user,
  I want to estimate the parameter of ZETA or/and ZIPF distributions
  using R, given a series of integer values. Do you know a package
  (similar to MASS) or a function (similar to fitdistr) I can use to
  estimate the parameter of these distributions using MLE method?
  Otherwise do you know a function (which use MLE method to estimate
  distribution parameters) that allow me to specify a PDF or PMF?
  Thanks,
  Regards
  Mauro Rossi
 
  --
  Mauro Rossi
  Istituto di Ricerca per la Protezione Idrogeologica
  Consiglio Nazionale delle Ricerche
  Via della Madonna Alta, 126
  06128 Perugia
  Italia
  Tel. +39 075 5014421
  Fax +39 075 5014420
 
  __
  R-help@stat.math.ethz.ch mailto:R-help@stat.math.ethz.ch mailing
 list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 
  --
  =
  David Barron
  Said Business School
  University of Oxford
  Park End Street
  Oxford OX1 1HP

 --
 Mauro Rossi

 Istituto di Ricerca per la Protezione Idrogeologica

 Consiglio Nazionale delle Ricerche

 Via della Madonna Alta, 126

 06128 Perugia

 Italia

 Tel. +39 075 5014421

 Fax +39 075 5014420





-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

[[alternative HTML version deleted]]

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


Re: [R] remove component from list or data frame

2007-02-08 Thread David Barron
 The first example you provide is a vector, not a list.  You can
remove the third element with:

  lst[-3]
 [1] 5 6 8 9

 The same thing works for rows of data frames:
  frame[-3,]
   lst1 lst2
 116
 227
 449
 55   10




 On 08/02/07, Jason Horn [EMAIL PROTECTED] wrote:
   Sorry to ask such a simple question, but I can't find the answer after
  extensive searching the docs and the web.
 
  How do you remove a component from a list?  For example say you have:
 
  lst-c(5,6,7,8,9)
 
  How do you remove, for example, the third component in the list?
 
  lst[[3]]]-NULL generates an error:  Error: more elements supplied
  than there are to replace
 
 
 
  Also, how do you remove a row from a data frame?  For example, say you
  have:
 
  lst1-c(1,2,3,4,5)
  lst2-c(6,7,8,9,10)
  frame-data.frame(lst1,lst2)
 
  How do you remove, for example, the second row of frame?
 
  Thanks,
 
  - Jason
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide  
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 



 --
 =
 David Barron
 Said Business School
 University of Oxford
 Park End Street
 Oxford OX1 1HP



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Beginner Question on Persp()

2007-02-05 Thread David Barron
read.delim creates a data frame (which is a type of list), whereas
persp requires that the z argument be a matrix.  These are different
classes of object in R -- you might want to read the Introduction to R
that ships with the programme.  Try

persp(x,y,as.matrix(z))

On 05/02/07, Tom H. [EMAIL PROTECTED] wrote:

 I recently downloaded R for Windows, running on Win XP.  I'm trying to create
 a perspective plot but not having any luck after reading the R manual and
 several examples found on the Internet.

 I have a 100 x 100 matrix of Z data as a tab-delimited text file exported
 from Minitab.  I read this in to R using read.delim; this seemed to go ok.
 I created  X and Y using seq() to get 100 divisions for the X and Y axes.
 Again, everything looked good, when I typed X or Y I got a string of 100
 numbers.

 However, when I try to do persp(x,y,z) I get an error something like: (list)
 cannot be coerced to double.  I know the basic data (matrix of z values) is
 ok (no hidden non-numeric values) because Minitab will graph it just fine.
 Any suggestions on how to proceed?  Thanks in advanced for your help.
 --
 View this message in context: 
 http://www.nabble.com/Beginner-Question-on-Persp%28%29-tf3174399.html#a8806483
 Sent from the R help mailing list archive at Nabble.com.

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] indexing without looping

2007-02-01 Thread David Barron
One way would be to use merge, like this:

merge(assignation,data.frame(class=x),all.y=TRUE)

There might well be better ways...

On 01/02/07, javier garcia-pintado [EMAIL PROTECTED] wrote:
 Hello,
 I've got a data.frame like this:

   assignation - data.frame(value=c(6.5,7.5,8.5,12.0),class=c(1,3,5,2))
   assignation
 
   value class
 1   6.5 1
 2   7.5 3
 3   8.5 5
 4  12.0 2

  
 

 and a long vector of classes like this:


   x - c(1,1,2,7,6,5,4,3,2,2,2...)
 

 And would like to obtain  a vector of length = length(x), with the
 corresponding values extracted from assignation table. Like this:

   x.value
 
  [1]  6.5  6.5 12.0   NA   NA  8.5   NA  7.5 12.0 12.0 12.0

 Could you help me with an elegant way to do this ?
 (I just can do it with looping for each class in the assignation table,
 what a think is not perfect in R's sense)

 Wishes,
 Javier

 --
 Javier García-Pintado
 Institute of Earth Sciences Jaume Almera (CSIC)
 Lluis Sole Sabaris s/n, 08028 Barcelona
 Phone: +34 934095410
 Fax:   +34 934110012
 e-mail:[EMAIL PROTECTED]


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




-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] solving a structural equation model using sem or other package

2007-01-24 Thread David Barron
This is an extract from the sem help page, which deals with your situation:

S covariance matrix among observed variables; may be input as a
symmetric matrix, or as a lower- or upper-triangular matrix. S may
also be a raw (i.e., ``uncorrected'') moment matrix — that is, a
sum-of-squares-and-products matrix divided by N. This form of input is
useful for fitting models with intercepts, in which case the moment
matrix should include the mean square and cross-products for a unit
variable all of whose entries are 1; of course, the raw mean square
for the unit variable is 1. Raw-moment matrices may be computed by
raw.moments.

On 24/01/07, Daniel Nordlund [EMAIL PROTECTED] wrote:
 I am trying to work my way through the book Singer, JD and Willett, JB, 
 Applied Longitudinal Data Analysis. Oxford University Press, 2003  using R.  
 I have the SAS code and S-Plus code from the UCLA site (doesn't include 
 chapter 8 or later problems).  In chapter 8, there is a structural 
 equation/path model which can be specified for the sem package as follows

 S - cov(al2) #al2 contains the variables alc1, alc2, alc3, and cons
 N - 1122

 modelA.ram - specify.model()
   f1- alc1,  NA,  1
   f1- alc2,  NA,  1
   f1- alc3,  NA,  1
   f2- alc1,  NA,  0
   f2- alc2,  NA,  .75
   f2- alc3,  NA,  1.75
   cons  - f1,p0,  1
   cons  - f2,p1,  1
   alc1 - alc1,  u1,  1
   alc2 - alc2,  u2,  1
   alc3 - alc3,  u3,  1
   cons - cons,  u4,  1
   f1   - f1,s1,  1
   f2   - f2,s2,  1
   f1   - f2,s3,  1

 modelA - sem(modelA.ram, S, N, analytic.gradient=FALSE)

 An equivalent specification in SAS produces the solution presented in the 
 book.  The variable cons is a constant vector of 1's.  The problem with the 
 sem package is that the covariance matrix which includes the variable cons is 
 singular and sem says so and will not continue.  Is there an alternative way 
 to specify this problem for sem to obtain a solution?  If not, is there 
 another package that would produce a solution?

 Thanks,

 Dan Nordlund
 Bothell, WA

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Scatterplot help

2007-01-22 Thread David Barron
The following three lines will do what you want.  You will probably
want to change some of the default behaviour; just look at the
relevant help pages.

plot(x,y)
text(x,y,ID)
grid(2)

On 21/01/07, gnv shqp [EMAIL PROTECTED] wrote:
 Hi my friends,

 I'm trying to make a scatterplot like this.

 1) I have a 3-variable dataset.  They are ID, x, and y.

 2) x is for the X-axis, y for the Y-axis, and ID is used to label all
 the cases in the scatterplot.

 3) After creating the scatterplot, I need to add both a X-axis  reference
 line and a Y-axis reference line.  The X-axis reference line is a vertical
 line starting from the center of the X-axis.  The Y-axis reference line is a
 horizontal line starting from the center of the Y-axis.  In other words, by
 creating the two reference lines, the scatterplot is divided into 4
 quadrants.

 Please help me figure out how to do that in R.

 Many thanks in advance!

 Feng

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Combination of variables

2007-01-22 Thread David Barron
You don't say what model you want to do.  It isn't necessary to store
each combination of predictors in a separate matrix unless you really
need to do this for some other reason, in which case I imagine you
could adopt this idea. I dare say there are better ways, but this
should work (assuming you want a linear model):

x-matrix(runif(30*6),ncol=6)
y - rnorm(30)
cmbs - list()
for (i in 1:6) cmbs - c(cmbs,combn(6,i,simplify=FALSE))
for (i in 1:length(cmbs))  print(summary(lm(y ~ x[,cmbs[[i]]])))


On 22 Jan 2007 08:51:22 -, anil kumar rohilla
[EMAIL PROTECTED] wrote:

 Hi,
  List , i have 6 predictor variables and i want to make possible combinations 
 of these 6 predictors ,all the data is in matrix form ,
 if i am having 6 predictors than possible combination of sets are 64 2 power 
 6, or 63 ,whatever it may be i want to store the result in another variable 
 to each combination and that i want to put in some model ,

 i want to put every combination in some model ,please help me how to find 
 suitable combinations of these variables 

 i was not able to do this .
 Any package is there in R which can help me in this regards
 any help .
 thanks in Advance


 ANIL KUMAR( METEOROLOGIST)
 LRF SECTION
 NATIONAL CLIMATE CENTER
 ADGM(RESEARCH)
 INDIA METEOROLOGICAL DEPARTMENT
 SHIVIJI NAGAR
 PUNE-411005 INDIA
 MOBILE +919422023277
 [EMAIL PROTECTED]

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Insert R logo

2007-01-20 Thread David Barron
I expect you could do something with the addlogo function in the pixmap package.

On 20/01/07, Arun Kumar Saha [EMAIL PROTECTED] wrote:
 Dear all R users,

 I want to insert the R logo in every graphic that I made in my Statistical
 analysis using R. Can anyone tell me whether is it possible or not and if
 possible how to do this? your help will be highly appreciated.

 Thanks and Regards,
 Arun

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Insert R logo

2007-01-20 Thread David Barron
Something like this:

library(pixmap)
# From the addlogo example
x - read.pnm(system.file(pictures/logo.ppm, package=pixmap)[1])
fg - matrix(c(0,1,0,1,0,.05,0,.05), ncol=4, byrow=TRUE)
split.screen(fg)
screen(1)
plot(rnorm(100))
screen(2)
addlogo(x,c(0,1),c(0,1))


On 20/01/07, Arun Kumar Saha [EMAIL PROTECTED] wrote:
 Dear all R users,

 I want to insert the R logo in every graphic that I made in my Statistical
 analysis using R. Can anyone tell me whether is it possible or not and if
 possible how to do this? your help will be highly appreciated.

 Thanks and Regards,
 Arun

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] selecting rows for inclusion in lm

2007-01-18 Thread David Barron
Why not use the subset option?  Something like:

lm(diff ~ Age + Race, data=data, subset=data$Meno==PRE)

should do the trick, and be much easier to read!

On 18/01/07, John Sorkin [EMAIL PROTECTED] wrote:
 I am having trouble selecting rows of a dataframe that will be included
 in a regression. I am trying to select those rows for which the variable
 Meno equals PRE. I have used the code below:

 difffitPre-lm(data[,diff]~data[,Age]+data[,Race],data=data[data[,Meno]==PRE,])
 summary(difffitPre)

 The output from the summary indicates that more than 76 rows are
 included in the regression:

 Residual standard error: 2.828 on 76 degrees of freedom

 where in fact only 22 rows should be included as can be seen from the
 following:

 print(data[length(data[,Meno]==PRE,Meno]))
 [1] 22

 I would appreciate any help in modifying the data= parameter of the lm
 so that I include only those subjects for which Meno=PRE.

 R 2.3.1
 Windows XP

 Thanks,
 John

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

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

 (Phone) 410-605-7119
 (Fax) 410-605-7913 (Please call phone number above prior to faxing)
 [EMAIL PROTECTED]

 Confidentiality Statement:
 This email message, including any attachments, is for the so...{{dropped}}

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] logistic regression packages

2007-01-10 Thread David Barron
1. multinom is is the nnet package

2. There is a polyclass function in package polspline

On 10/01/07, Feng Qiu [EMAIL PROTECTED] wrote:
 Hi All:
I'm testing a set of data classification algorithms in this paper
 (www.stat.wisc.edu/~loh/treeprogs/quest1.7/mach1317.pdf )
 I couldn't find such algorithms in R packages:
1. LOG: polytomous logistic regression (there was one in MASS
 library: multinom. But after I update MASS library, multinom was lost.)
2. POL: POLYCLASS algorithm. There is a S-Plus package(polyclass
 library) for this algorithm, so there should be a corresponding package in
 R, but I haven't found it so far.
Any advice is appreciated.

 Best,

 Feng

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



--
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP


-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] loop is going to take 26 hours - needs to be quicker!

2006-12-14 Thread David Barron
What about

gpcc.array - array(gpcc.data2[,5], dim=c(144,72,46))

On 14/12/06, Rainer M Krug [EMAIL PROTECTED] wrote:
 Jenny Barnes wrote:
  Dear R-help,
 
  I have a loop, which is set to take about 26 hours to run at the rate it's 
  going
  - this is ridiculous and I really need your help to find a more efficient 
  way of
  loading up my array gpcc.array:
 
  #My data is stored in a table format with all the data in one long column
  #running though every longitute, for every latitude, for every year. The
  #original data is sotred as gpcc.data2 where dim(gpcc.data2) = [476928,5] 
  where
  #the 5th column is the data:
 
  #make the array in the format I need [longitude,latitude,years]
 
  gpcc.array - array(NA, c(144,72,46))
 
  n=0
  for(k in 1:46){
  for(j in 1:72){
  for(i in 1:144){
  n - n+1
  gpcc.array[i,j,k] - gpcc.data2[n,5]
  print(j)
  }
  }
  }

 I don't know if it is faster - but adding three columns to qpcc.data,
 one for longitude, one for lattitude and one for year (using rep() as
 they are in sequence) and the using reshape() might be faster?


 
  So it runs through all the longs for every lat for every year - which is the
  order the data is running down the column in gpcc.data2 so n increses by 1 
  each
  time and each data point is pulled off
 
  It needs to be a lot quicker, I'd appreciate any ideas!
 
  Many thanks for taking time to read this,
 
  Jenny Barnes
 
  ~~
  Jennifer Barnes
  PhD student - long range drought prediction
  Climate Extremes
  Department of Space and Climate Physics
  University College London
  Holmbury St Mary, Dorking
  Surrey
  RH5 6NT
  01483 204149
  07916 139187
  Web: http://climate.mssl.ucl.ac.uk
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.


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

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

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

 email:  [EMAIL PROTECTED]
 [EMAIL PROTECTED]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Switch and integer

2006-12-11 Thread David Barron
From the help entry for switch:

If the value of EXPR is an integer between 1 and nargs()-1 then the
corresponding element of ... is evaluated and the result returned.

So, for integers you don't give names to the elements in ...  This should work:

test=c(3,9,3,9,3,9,8,9,8,9,8,9,3,9,3,9,5,9,3,9,1,2,7,9,3,9,1,1,2,2,3,9,2,1,2,5,9,8,9,1,2)
count1 - 0
for (i in 1:length(test))
 switch(EXPR=test[i],
 NULL,
 NULL,
 NULL,
 count1 - count1 +1,
 count1 - count1 +1,
 count1 - count1 +1,
 count1 - count1 +1,
 count1 - count1 +1,
 NULL
 )
 count1


On 11/12/06, Knut Krueger [EMAIL PROTECTED] wrote:
 I searched the help list and the manual, but I do not find my mistake.
 Switch is working with character , with integer, but not in the third
 example

 Regards Knut


 count1 - 0
 test
 =c(3,9,3,9,3,9,8,9,8,9,8,9,3,9,3,9,5,9,3,9,1,2,7,9,3,9,1,1,2,2,3,9,2,1,2,5,9,8,9,1,2)
 count1 - 0
 for (i in 1:length(test))
   switch (EXPR=test[i],
   5 = print(test[i]),
   6 = print(test[i]),
   7 = print(test[i]),
   8 = print(test[i]),
   9 = print(test[i])
   )
   count1
 # example from helpfile
 for(i in c(-1:3,9))  print(switch(i, 1,2,3,4))

 #  not working
 test
 =c(3,9,3,9,3,9,8,9,8,9,8,9,3,9,3,9,5,9,3,9,1,2,7,9,3,9,1,1,2,2,3,9,2,1,2,5,9,8,9,1,2)
 count1 - 0
 for (i in 1:length(test))
   switch (EXPR=test[i],
   4 = count1 - count1 +1,
   5 = count1 - count1 +1,
   6 = count1 - count1 +1,
   7 = count1 - count1 +1,
   8 = count1 - count1 +1
   )
   count1

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] A smal fitting problem...

2006-12-08 Thread David Barron
b = mean(y)

On 08/12/06, KÃ¥re Edvardsen [EMAIL PROTECTED] wrote:
 Dear R-helpers,

 I'm for sure not familiar with R, but it seem like a nice sofware tool,
 so I've decided to try using it.

 Here is my problem I just can't figure out:

 I'd like to do least square fit of a straight horizontal (a = 0) line y
 = ax + b through some data points

 x = (3,4,5,6,7,8)

 y = (0.62, 0.99, 0.83, 0.69, 0.76, 0.82)

 How would i find b?

 All the best,
 Ked

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] incidence and adjacency matrix conversion

2006-12-05 Thread David Barron
I think you can do this using the network package.  Look at the
as.network.matrix and as.matrix.network functions, for example.

On 05/12/06, Philip Leifeld [EMAIL PROTECTED] wrote:
 Dear all,

 how can I convert an m x n incidence matrix into an m x m adjacency
 matrix or an n x n adjacency matrix? The current matrix contains binary
 data, hence the new matrix would contain counts of common occurrences.

 Thank you for your help.

 Phil

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Dummies multiplied with other variable

2006-11-30 Thread David Barron
I'm not sure if this will help, but it's worth a try.  Do the
regression as I suggested before, extract the model matrix and remove
the offending column.  I'm assuming you don't know in advance how
many levels there are in the factor.  Then use this to perform the
regression.  Something like this:

m1 - lm(x ~ fd:y + fd)
mm - model.matrix(m1)
nl - length(levels(fd))
newdat - mm[,-c(1,nl)]
lm(x ~ newdat)


On 30/11/06, Andreas Goesele [EMAIL PROTECTED] wrote:
 David Barron [EMAIL PROTECTED] writes:

  I'm not sure that's possible, given that you would effectively be
  fitting a different model to those cases with fd==1, wouldn't you?

 This was what I was afraid of. But your argument I don't understand
 completely.

 Do you want to say, that the *model* x = a + b1*fd2 + b2*fd3 +
 c1*fd2*y + c1*fd3*y doesn't make sense as fd2 together with fd3
 doesn't cover all cases? And that because the model doesn't make sense
 it is not easily implemented in R?

 My problem is that I have to estimate a model of this kind whether it
 makes sense or not. So I still would be happy to find an easy and
 elegant way...

  On 29/11/06, Andreas Goesele [EMAIL PROTECTED] wrote:
  David Barron [EMAIL PROTECTED] writes:
 
   Is this what you want?
  
   lm(y ~ fd + fd:y)
 
  Thanks for you fast reply. But it's not what I wanted.
 
  To make it clearer I have to correct the first part of what I wrote:
 
   On 29/11/06, Andreas Goesele [EMAIL PROTECTED] wrote:
 
   I would like to estimate something like y = a + b*d2*y + c*d3*y
   where the dummies are created from some vector d with three
   (actually many more) levels using factor(). But either there is
   included the variable y or d1*y. How could I get rid of these?
 
  This should have been something like:
 
  x = a + b1*d2 + b2*d3 + c1*d2*y + c1*d3*y
 
  When I change your suggestion to lm(x ~ fd + fd:y) I get the same as
  for lm(x ~ fd*y - y), namely:
 
  Coefficients:
  (Intercept) fd2 fd3   fd1:y   fd2:y   fd3:y
2.4231  9.5769  6.1822 -0.1154 -1. -0.4474
 
  What I want is:
 
  Coefficients:
  (Intercept) fd2 fd3   fd2:y   fd3:y
 
  Thanks a lot again!
 
  Andreas Goesele
 
  --
  Andreas Gösele   Omnis enim res, quae dando non deficit,
  Inst. f. Gesellschaftspolitikdum habetur et non datur,
  Kaulbachstr. 31a, 80539 München  nondum habetur, quomodo habenda est.
  E-mail: [EMAIL PROTECTED]  (Augustinus)
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
  --
  =
  David Barron
  Said Business School
  University of Oxford
  Park End Street
  Oxford OX1 1HP
 
 

 --
 Andreas Gösele   Omnis enim res, quae dando non deficit,
 Inst. f. Gesellschaftspolitikdum habetur et non datur,
 Kaulbachstr. 31a, 80539 München  nondum habetur, quomodo habenda est.
 E-mail: [EMAIL PROTECTED]  (Augustinus)



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] need help with barplot

2006-11-29 Thread David Barron
You need the transpose of the matrix (or create it differently in the
first place!).  Changing the last line to

 barplot(t(b),beside=T,col=(c(red,orange,yellow)))

should do the trick.

On 29/11/06, Robertas Kavaliūnas [EMAIL PROTECTED] wrote:
 Hello,
 I do this
 a=c(10.2,0.4,0.2,5.2,8.6,1.6,0.0,1.0,6.3,1.4,0.4,0.2)
 b=matrix(a,nrow=4)
 rownames(b)=c(20/04/2002,21/04/2002,22/04/2002,23/04/2002)
 colnames(b)=c(p1,p2,p3)
 barplot(b,beside=T,col=(c(red,orange,yellow)))

 then I have 
 http://www.mif.vu.lt/~roka5178/barplot1.JPGhttp://www.mif.vu.lt/%7Eroka5178/barplot1.JPG
 but I need to have
 http://www.mif.vu.lt/~roka5178/barplot.JPGhttp://www.mif.vu.lt/%7Eroka5178/barplot.JPG
 how can i do this?
 i need to  to change axis x whit y

 --
 Robertas

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Dummies multiplied with other variable

2006-11-29 Thread David Barron
Is this what you want?

lm(y ~ fd + fd:y)

On 29/11/06, Andreas Goesele [EMAIL PROTECTED] wrote:
 Hi,

 I would like to estimate something like y = a + b*d2*y + c*d3*y where
 the dummies are created from some vector d with three (actually many
 more) levels using factor(). But either there is included the variable
 y or d1*y. How could I get rid of these?

 Example:

 x = c(1,2,3,4,5,6,7,8)
 y = c(3,6,2,8,7,6,2,4)
 d = c(1,1,1,2,3,2,3,3)
 fd = factor(d)

 lm(x ~ fd*y)
 gives:

 Coefficients:
 (Intercept) fd2 fd3   y   fd2:y   fd3:y
  2.4231  9.5769  6.1822 -0.1154 -0.8846 -0.3320

 lm(x ~ fd*y - y)
 gives:

 Coefficients:
 (Intercept) fd2 fd3   fd1:y   fd2:y   fd3:y
  2.4231  9.5769  6.1822 -0.1154 -1. -0.4474

 What I would like to get is:

 Coefficients:
 (Intercept) fd2 fd3   fd2:y   fd3:y

 Is there an easy way to achieve this?

 Maybe it's obvious how to do it, but I'm new to R did quite some
 searching without finding the solution.

 Thanks a lot in advance!

 Andreas Goesele

 --
 Andreas Gösele

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Predicted values in lmer modeling

2006-11-28 Thread David Barron
The fitted values for m5 must be logits.

On 28/11/06, Aimin Yan [EMAIL PROTECTED] wrote:
 m3 is a logistic regression model without random effect fitted by glm
 m5 is a logistic regression model with random effect fitted by lmer
 why the range for the fitted value for m5 is not between 0 and 1.
 thanks,
 Aimin
   range(fitted(m3))
 [1] 0.1630141 0.9903415
   range(fitted(m5))
 [1] -1.515915  4.576576

 At 07:53 AM 11/28/2006, Douglas Bates wrote:
   fitted(model)

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] plot p(Y=1) vs as

2006-11-26 Thread David Barron
I'd recommend having a look at the lrm function in the Design package.
 Looking at the examples should show you how you can product this type
of plot using some of the other components of this package.

On 26/11/06, Aimin Yan [EMAIL PROTECTED] wrote:
 I am trying to fit a logistic regression model for this data set.
 Firstly, I want to plot  P(Y=1) vs As and P(Y=1) vs Aa.
 Does any body know how to do these in R.
 Thanks,
 Aimin

   p5 - read.csv(http://www.public.iastate.edu/~aiminy/data/p_5_2.csv;)
   str(p5)
 'data.frame':   1030 obs. of  6 variables:
   $ P  : Factor w/ 5 levels 821p,8ABP,..: 1 1 1 1 1 1 1 1 1 1 ...
   $ Aa : Factor w/ 19 levels ALA,ARG,ASN,..: 12 16 7 18 11 10 19 19
 19 1 ...
   $ As : num  126.9  64.1  82.7   7.6  42.0 ...
   $ Ms : num  92.4 50.7 75.3 17.2 57.7 ...
   $ Cur: num  -0.1320 -0.0977 -0.0182  0.2368  0.1306 ...
   $ Y  : int  0 0 1 1 0 0 1 0 1 1 ...

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Questions about generating samples in R

2006-11-26 Thread David Barron
?sample should tell you what you need to know.

On 26/11/06, Alexander Geisler [EMAIL PROTECTED] wrote:
 Hello!

 I have a data set with 8 columns and in about 5000 rows. What I want to
 do is to generate samples of this data set.

 Samples of a special size, as example 200.

 What is the easiest way to do this? No special things are needed, only
 the random selection of 200 rows of the data set.

 Thanks
 Alex

 --
 Alexander Geisler * Kaltenbach 151 * A-6272 Kaltenbach
 email: [EMAIL PROTECTED] | [EMAIL PROTECTED]
 phone: +43 650 / 811 61 90 | skpye: al1405ex

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Plot with two seperate y axis

2006-11-24 Thread David Barron
Assuming the data are in a data frame called dt, this should work:

 plot(dt$Wk,dt$Para1,type=h)
 par(new=TRUE)
 plot(dt$Wk,dt$Para2,yaxt=n)
 axis(4,at=97:100)


On 24/11/06, Thorsten Muehge [EMAIL PROTECTED] wrote:

 Hello,
 I would like to plot the following matrix:
 Wk=x achsis.
 Para 1 = left y-axis as a barplot
 para 2 right y-axis as a normal scatter plat.

 I could not find such a solution in any of my documentation.

 Can someone help me?

 Thanks a lot
 Thorsten

 WkPara 1  Para 2
 312000  99.8
 322005  99.0
 332002  98.0
 341090  98.5
 352001  99.1
 362010  97.0
 372010  98.8

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Using roman and italic fonts in an xlab expression for a plot

2006-11-23 Thread David Barron
Something like:

xlab=expression(paste(The excess level is,italic( M)))

in your plot command should do the trick.  See ?plotmath.

On 23/11/06, Philip Boland [EMAIL PROTECTED] wrote:
 Just wondering if it is possible to put something like

 The excess level is M

 in the xlab position of a plot but where the M is in italic font and
 the rest in ordinary (or Roman) font.

 Thanks - Phil Boland

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] (no subject)

2006-11-18 Thread David Barron
I'm not sure what the last line is trying to achieve, but this might
be what you want:

i - ifelse(m==0, l/ky, l/ky + 1)
j - ifelse(m==0,ky, l %% ky)


On 18/11/06, Céline Henzelin [EMAIL PROTECTED] wrote:
 Hello,

 I need help to understand my error in this code... I would like to make a
 direct sampler...

 thanks

 Celine


 p-matrix(c(1,2,3,2,1,4),3,2,byrow=T)
 p-p/sum(p)
 ky-ncol(p)
 kx-nrow(p)
 p.vec-as.vector(t(p))
 l-rmultinom(1,1,p)
 l-(t(l))
 m-(l%%ky)
 ifelse (m==0, i-l/ky  (j-ky), i-((l/ky)+1)   (j-(l %% ky)

 _
 Faites de MSN Search votre page d'accueil: Toutes les réponses en un clic!

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Creating a table

2006-11-14 Thread David Barron
addmargins(table(df))

On 14/11/06, Michael Graber [EMAIL PROTECTED] wrote:
 Dear R List,

 I am a new to R,  so my question may be easy to answer for you:

 I have a dataframe, for example:

 df-data.frame(loc=c(A,B,A,A,A),
 year=as.numeric(c(1970,1970,1970,1976,1980)))

 and I want to create the following table without using loops:

   1970-74 ; 1975-79 ; 1980-85; rowsum
 A 2   1   1  4
 B 1   00  1
 colsum   31   15

 so that the frequencies of df$loc are shown in the table for different
 time intervals.

 Thanks in advance for any hint,

 Michael Graber

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] R Help

2006-11-11 Thread David Barron
d - read.table(lahore.txt, header=TRUE)

On 11/11/06, amna khan [EMAIL PROTECTED] wrote:
 Respected Sir
 I request you to please fill the following read.table function and
 read.csvfor my understanding by assuming my data attached with this
 maiL, because I
 am fail to run these functions using manual guidlines.

 read.table(file, header = FALSE, sep = , quote = \',
dec = ., row.names, col.names,
as.is = !stringsAsFactors,
na.strings = NA, colClasses = NA, nrows = -1,
skip = 0, check.names = TRUE, fill = !blank.lines.skip,
strip.white = FALSE, blank.lines.skip = TRUE,
comment.char = #, allowEscapes = FALSE, flush = FALSE,
stringsAsFactors = default.stringsAsFactors())

 read.csv(file, header = TRUE, sep = ,, quote=\, dec=.,
  fill = TRUE, comment.char=, ...)

 read.delim(file, header = TRUE, sep = \t, quote=\, dec=.,
fill = TRUE, comment.char=, ...)

 I shall be really thankful to  you.
 REGARDS

 --
 AMINA SHAHZADI
 Department of Statistics
 GC University Lahore, Pakistan.
 Email:
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]


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






-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] neg-bin clustered analysis in R?

2006-11-06 Thread David Barron
I'm not certain, but I think you should be able to use the robcov
function in the Design package in conjunction with glm.nb, perhaps
with a bit of tweaking.  Another alternative might be to use the quasi
family in lmer.

On 06/11/06, Lutz Ph. Breitling [EMAIL PROTECTED] wrote:
 Dear All,

 I'm analysing a negative binomial dataset from a population-based
 study. Many covariates were determined on household level, so all
 members of a household have the same value for those covariates.

 In STATA, there seems to be an option for 'clustered analysis' for
 neg-bin regression. Does an equivalent exist for R(MASS)'s glm.nb or a
 comparable function?

 Many thanks for all help!
 Lutz
 --
 Lutz Ph. Breitling, Marie Curie EST Research Fellow
 Integrative  Comparative Biology (Irene Manton 8.93e)
 University of Leeds, LS2 9JT Leeds/UK

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] grep searching for sequence of 3 consecutive upper case letters

2006-11-06 Thread David Barron
Try

str[grep('[[:upper:]]{3}',str)]


On 06/11/06, Lapointe, Pierre [EMAIL PROTECTED] wrote:
 Hello,

 I need to identify all elements which have a sequence of 3 consecutive upper
 case letters, anywhere in the string.

 I tested my grep expression on this site: http://regexlib.com/RETester.aspx

 But when I try it in R, it does not filter anything.

 str -c(AGH, this WOUld be good, Not Good at All)
 str[grep('[A-Z]{3}',str)] #looking for a sequence of 3 consecutive upper
 case letters

 [1] AGHthis WOUld be good Not Good at All

 Any idea?

 Pierre

 **
 AVIS DE NON-RESPONSABILITE: Ce document transmis par courrie...{{dropped}}

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] information about sna packages

2006-10-31 Thread David Barron
I don't think so, but you should email the package's author, Carter
Butts for help on this package.  His email is [EMAIL PROTECTED]

On 31/10/06, Bagatti Davide [EMAIL PROTECTED] wrote:
 Hello,

 I'm a student who want to use the R social network analysis package. I have
 a question: can this package analyse dynamical networks (network changing
 over time)? I didn't find this functionality in the package's user manual.

 Thank you

 Davide

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Put a normal curve on plot

2006-10-31 Thread David Barron
Something like this?

library(MASS)
mu - c(0,1)
Sigma - matrix(c(1,.8,.8,1), ncol=2)
set.seed(123)
x - mvrnorm(50,mu,Sigma)
dta - data.frame(x=x[,1],y=x[,2])
plot(x)

fit - lm(y~x, data=dta)
sfit - summary(fit)
se - sfit$sigma
abline(fit)

yhat - predict(fit,data.frame(x=c(-1,0,1)),se.fit=TRUE)

x1 - seq(-2,0,length=50)
x2 - x1 + 1
x3 - x2 + 1
lines(x1,yhat$fit[1]+dnorm(x1,-1,se))
lines(x2,yhat$fit[2]+dnorm(x2,0,se))
lines(x3,yhat$fit[3]+dnorm(x3,1,se))


On 31/10/06, Doran, Harold [EMAIL PROTECTED] wrote:
 I would like to be able to place a normal distribution surrounding the
 predicted values at various places on a plot. Below is some toy code
 that creates a scatterplot and plots a regression line through the data.

 library(MASS)
 mu - c(0,1)
 Sigma - matrix(c(1,.8,.8,1), ncol=2)
 set.seed(123)
 x - mvrnorm(50,mu,Sigma)
 plot(x)
 abline(lm(x[,2] ~ x[,1]))

 Say I want to add a normal distribution surrounding the predicted values
 at the x-values of -1, 0, and 1. That is, at the points

 \hat{y} = \mu + \beta_1(-1)
 \hat{y} = \mu + \beta_1(0)
 \hat{y} = \mu + \beta_1(1)

 How might I go about doing this?

 Harold

  version
_
 platform   i386-pc-mingw32
 arch   i386
 os mingw32
 system i386, mingw32
 status
 major  2
 minor  4.0
 year   2006
 month  10
 day03
 svn rev39566
 language   R
 version.string R version 2.4.0 (2006-10-03)

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] for importing data

2006-10-30 Thread David Barron
Most likely the file lahore.txt isn't in the current working
directory, which is where R will be looking for it as you don't
specify a path (I'm assuming that you are working in Windows).  If so,
you have three options.  1) Move lahore.txt to the current working
directory (you can find with directory that is using the function
getwd()).  2) Specify the full path in read.delim (e.g.,
read.delim(c:/my documents/data/lahore.txt).  3) Change the working
directory to the one in which lahore.txt is located using the function
setwd().

Hope this helps.
David

On 30/10/06, amna khan [EMAIL PROTECTED] wrote:
 *I am a very new user of R. I've spent several hours trying to import
 data, so I feel okay asking the list for help. *
 *I had an Excel file,  then I turned it into a tab-delimited file, as
 instructed by directions My
 filename is lahore.txt I amusing the following commands for read.delim but
 i am getting following mesages. Sir i am sending you my excel data file i
 request you to   please write the right read.delim function for  importing
 data file after transforming it into a tab-delimited form.*

 lahore-read.delim(lahore.txt)
 Error in file(file, r) : unable to open connection
 In addition: Warning message:
 cannot open file 'lahore.txt', reason 'No such file or directory'

 Regards

 AMINA SHAHZADI*.*
 Department of Statistics
 GC University Lahore, Pakistan.
 Email:
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] correlation structure in lme without random effect

2006-10-30 Thread David Barron
You haven't specified a random equation.  Try:

fit-lme(fixed=y~g,random=~1|g,correlation=corAR1(0,~1|g))


On 30/10/06, Benjamin Tyner [EMAIL PROTECTED] wrote:
 I was hoping to fit along the lines of

 g-gl(20,5)
 y-runif(100)
 fit-lme(fixed=y~g,correlation=corAR1(0,~1|g))

 But I get the error Incompatible formulas for groups in random and
 correlation

 Any help would be greatly appreciated.
 Ben

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] plot history

2006-10-30 Thread David Barron
Are you working in Windows?  If so, you can turn on recording either
in the History menu on the active graphics device window, or by using
windows(record=TRUE) to open a new device.

On 30/10/06, Rohini Mulford [EMAIL PROTECTED] wrote:

 ___




 Hi,

 When I create multiple graphs subsequent graphs overwrite previous
 graphs. How do I keep all my graphs in the current workspace (but not
 all on the same page) so I can scroll through them?


 thanks,

 Rohini



 Rohini Mulford

 Senior Research Analyst

 Technical Research

 Research  Development

 Insurance Australia Group(IAG)

 ph (02) 9292 1560

 fax (02) 9292 1509

 email: [EMAIL PROTECTED]






 ___

 The information transmitted in this message and its attachme...{{dropped}}

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


[R] legends in ggplot

2006-10-26 Thread David Barron
Is it possible to change the legend title in ggplot that is generated
by a colour (other than by changing the name of the variable)?  For
example, this produces a legend title, tip/total_bill.  How can that
title be changed?

ggpoint(ggplot(tips,aesthetics=list(y=tip,x=total_bill,colour=tip/total_bill)) )

Thanks.

-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] distance between legend title and legend box

2006-10-26 Thread David Barron
I don't know if there is a nice, easy way of doing this, but this
method will work:

with(iris,
  plot(Sepal.Length, Sepal.Width,
   pch=as.numeric(Species), cex=1.2))

lg-legend(6.5, 4.2, c(setosa, versicolor, virginica),
  cex=1, pch=1:3, title=expression(kg/km^2), bty=n)

x1 - lg$rect$left
y1 - lg$rect$top - lg$rect$h
x2 - x1 + lg$rect$w
y2 - lg$rect$top + .1  # change the .1 to get more or less space

rect(x1,y1,x2,y2)


On 26/10/06, Denis Chabot [EMAIL PROTECTED] wrote:
 Hi,

 I've looked at the parameters available for the legend function and
 cannot find a way to change the distance between the top of the box
 surrounding a legend and the legend's title. I have a math expression
 that raises the height of my title.

 If you don't mind the non-sensical title I give to the legend for
 this plot (Figure 3.20 in R Graphics):

 with(iris,
plot(Sepal.Length, Sepal.Width,
 pch=as.numeric(Species), cex=1.2))
 legend(6.5, 4.2, c(setosa, versicolor, virginica),
cex=1, pch=1:3, title=expression(kg/km^2))

 The result depends on the device, but I think any device will show
 the box needs to be raised a bit (in quartz, the top of the box
 passes in the middle of the 2, in pdf it is acceptable, but just
 (the top of the box lightly touches the top of the 2).

 Sincerely,

 Denis Chabot

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] To big characters in barplot

2006-10-24 Thread David Barron
Use the option cex.names.  For example:

 tN - table(Ni - rpois(100, lambda=5))
 barplot(tN, col=rainbow(20))
 barplot(tN, col=rainbow(20), cex.names=.6)




On 24/10/06, David Graf [EMAIL PROTECTED] wrote:
 Hi everybody!

 The characters under the bars in my barplot are to big, so I can't see them 
 all. How can I make them smaller?

 Thanks!
 David GRaf
 --

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] colinearity?

2006-10-24 Thread David Barron
There are functions to calculate variance inflation factors in various
packages, e.g. car and Design.  I believe these work with generalized
linear models.

On 24/10/06, Chris Linton [EMAIL PROTECTED] wrote:
 I'm sorry to all those who are tired of seeing my email appear in need of
 help.  But, I've never coded in any program before, so this has been a
 difficult process for me.

 Is there a simple function to test for colinearity in R?  I'm running a
 logistic regression and a linear regression.



 Thanks for the help!

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] colinearity?

2006-10-24 Thread David Barron
Also, have a look at the perturb package which has a couple of
functions for collinearity diagnosis.

On 24/10/06, Chris Linton [EMAIL PROTECTED] wrote:
 I'm sorry to all those who are tired of seeing my email appear in need of
 help.  But, I've never coded in any program before, so this has been a
 difficult process for me.

 Is there a simple function to test for colinearity in R?  I'm running a
 logistic regression and a linear regression.



 Thanks for the help!

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Help with understanding [[]] [] array, list, matrix referencing

2006-10-24 Thread David Barron
Have you tried help([), which gives a good explanation.


On 24/10/06, Joe W. Byers [EMAIL PROTECTED] wrote:
 Hi all,

 I would greatly appreciate some help understanding how R references
 arrays, matrices, lists, and objects using [[]] and [].  I have read the
 R guides and several tutorials but I am not the fastest kid on the block
 so I am still having difficulty understanding this.  For examples the
 following code produces a 5 element list of 2X5 random numbers that I
 then convert to a 2X5X5 matrix.
 cov-matrix(c(.4,-.1,-.1,.3),nrow=2,ncol=2)
 rnds-NULL;
 for (i in 1:5){
 t1-rnorm(5,cov)
 t2-rnorm(5,cov)
 t3-rbind(t1,t2)
 rnds[i]-list(t3)
 }

 rnds.matrix-array(unlist(rnds),dim=c(2,5,5));

 To access the matrix rnds.matrix I use rnds.matrix[x,y,z].  This I
 understand.

 To access the list I user [[z]][x,y].  This I do not understand.  I
 found by chance this reference notation in an old mailing list that
 helped me.

 I could use some help in knowing when to use [[]] referencing and when
 to use [] referencing.  If there is a really good book, webpage, or link
 with explanation and examples I would appreciate you forwarding the the
 citation.

 Thank you
 Joe

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Help with understanding [[]] [] array, list, matrix referencing

2006-10-24 Thread David Barron
Well, as I understand it, with a list [] doesn't return the actual
contents of that element of the list, whereas [[]] does.  Compare, for
example rnds[1] + 1 with rnds[[1]] + 1.  So, with a list you have to
use the double bracket notation to get to the actual contents of that
element of the list, as opposed to a pointer to the element.  With a
vector or a matrix, [[]] doesn't seem to have much use, though you can
use it with a single number, in which case you will get the same
result as [].

There is a separate method for data frames, in which [[]] will give
you a column.  So, I think that data[[1]] is the same as data[,1].

Anyway, these rules have always worked for me, though I'm sure others
can give a more sophisticated answer!

On 24/10/06, Joe Byers [EMAIL PROTECTED] wrote:
 David,

 Yes, I did.  I just still do not get it.  That is why I ask here.
 Hoping someone knew a step by step guide that I could look at.  My trial
 and error approach takes me hours some days.  I currently move most
 things in and out of data.frames where I can name the columns and
 reference with the $ and a subsetting function, but that is not always
 efficient.  If I could understand the [ referencing better, my code
 would be more efficient and I think faster.  Part of my problem is my
 SAS background where everything is a flat table and coding is really
 sloppy.  A data step with a bunch of if-then-else to perform the
 calculation where as in matrix format like in R you do things more
 compactly.  Not always easy to read but efficient and fast.

 I appreciate you help.

 Thank you
 Joe




 David Barron wrote:
  Have you tried help([), which gives a good explanation.
 
 
  On 24/10/06, Joe W. Byers [EMAIL PROTECTED] wrote:
  Hi all,
 
  I would greatly appreciate some help understanding how R references
  arrays, matrices, lists, and objects using [[]] and [].  I have read the
  R guides and several tutorials but I am not the fastest kid on the block
  so I am still having difficulty understanding this.  For examples the
  following code produces a 5 element list of 2X5 random numbers that I
  then convert to a 2X5X5 matrix.
  cov-matrix(c(.4,-.1,-.1,.3),nrow=2,ncol=2)
  rnds-NULL;
  for (i in 1:5){
  t1-rnorm(5,cov)
  t2-rnorm(5,cov)
  t3-rbind(t1,t2)
  rnds[i]-list(t3)
  }
 
  rnds.matrix-array(unlist(rnds),dim=c(2,5,5));
 
  To access the matrix rnds.matrix I use rnds.matrix[x,y,z].  This I
  understand.
 
  To access the list I user [[z]][x,y].  This I do not understand.  I
  found by chance this reference notation in an old mailing list that
  helped me.
 
  I could use some help in knowing when to use [[]] referencing and when
  to use [] referencing.  If there is a really good book, webpage, or link
  with explanation and examples I would appreciate you forwarding the the
  citation.
 
  Thank you
  Joe
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 





-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Plotting Text on a graph

2006-10-23 Thread David Barron
Have you thought of using split.screen instead?

Something like might work for you:

split.screen(c(1,1))
split.screen(c(3,4), 1)
for (i in 1:12) {
   screen(i+1)
   par(mar=c(2,2,4,2))
   plot(1:20,rnorm(20),xlab=,ylab=)
}
screen(1)
title(Overall title)


On 23/10/06, Dan Chan [EMAIL PROTECTED] wrote:
 Hi,



 I plotted 12 graphs on a page and output to a png file.  I wanted to
 have an overall title for all 12 graphs.  What command can I use to do
 this?  Below is the code that plotted the 12 graphs in one page.



 # FM10 by Month/ Export the plot to Wash2005FM10.png

 png(file=Wash2005FM10.png,bg=white)

 par(mfrow = c(3,4))

 # Plot 12 Month of OFM10, FFM10

 for(i in 1:12) {

 Temp - subset (Wash2005, MM == i)

 plot (Temp$FM10.1,
 Temp$FM10,main=month.name[i],xlim=c(5,25),ylim=c(5,25))

 }

 text(10,10, Overall Title)  'This will plot Overall Title at
 coordinate (10,10) on the last graph, and so it is not what I want.

 dev.off()



 Thank you.



 Daniel Chan

 Meteorologist

 Georgia Forestry Commission

 P O Box 819

 Macon, GA

 31202

 Tel: 478-751-3508

 Fax: 478-751-3465




 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] extract arguments from a list

2006-10-19 Thread David Barron
First, that isn't what is called a list in R, it is a character vector.

Second, to get what you want, try

 sort(unique(x))
[1] Atrazine  Atrazine desethyl Bentazone
[4] Epoxiconazol  Fenpropimorph Metolachlor
[7] Simazine

On 19/10/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi,

 I would like to know how to extract the arguments from a list :

 For example, I have a list of charchacter x
 x-
 c(Bentazone,Atrazine,Epoxiconazol,Metolachlor,Epoxiconazol,Atrazine
 desethyl,Fenpropimorph,Epoxiconazol,Metolachlor,Simazine,Atrazine
 desethyl,Epoxiconazol,Atrazine
 desethyl,Atrazine,Epoxiconazol,Metolachlor,Epoxiconazol,Atrazine
 desethyl,Fenpropimorph,Epoxiconazol,Metolachlor,Simazine)

 and I am searching for a (basic) function which would return arguments of
 the list x, aphabeticaly reordered like this :
  (Atrazine,Atrazine
 desethyl,Bentazone,Epoxiconazol,Fenpropimorph,Metolachlor,Simazine).


 Can anyone help me ?


 Thanks by advance

 Jessica




 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Labels for Points- 2 character labels?

2006-10-19 Thread David Barron
Is this what you want?

 plot(e,n)
 text(e,n,labels=e_order,pos=4)


On 18/10/06, ableape [EMAIL PROTECTED] wrote:
 I would like to be able to label each point in a scatter plot with
 the numeric order of that point. for example, I create the following plot:

 plot(e,n)
 #
 # now I go back and create my labels
 #
 for(i in 1:length(e)) {# lets say e 10
 pc - as.character(e_order[i])   # e_order has an
 integer array 1,4,3,2... which is the order of e
 points(e15[i], n15[i],pch=pc)# this will plot
 0-9 as data labels

   }
 #
 The above works for single characters.  Now if the length of e[] is
 greater than 9, the character string converted by as.character will
 yield more than one digit. At this point, my labeling trick fails:-(

 1) is there a way to create two character labels for a plot?
 2) Or even better, is there a way to do what I am trying to
 do.  Label each point by its numeric order?

 Thanks for your help.

 Renaldo

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] How to get multiple Correlation Coefficients

2006-10-19 Thread David Barron
Oh, and of course you need to use an explicit print inside a for loop.
 So, the line would be:

  print( polychor(sdi[,i], sdi[,j]))

On 19/10/06, David Barron [EMAIL PROTECTED] wrote:
 The problem is that in the expression  polychor(vars[i], vars[j]),
 vars[i] and vars[j] refer to the names of the variables, not the
 variables themselves.  So, use sdi[,i] and sdi[,j] instead.

 On 19/10/06, Kum-Hoe Hwang [EMAIL PROTECTED] wrote:
  Hi
 
  I have used a polycor package for categorical correlation coefficients.
  I run the following script. But there were no results.
 
  Could you tell me how to correct the script?
 
  Thanks in advance,
 
  vars - names(sdi)
  for (i in 1:length(vars)) {
  for (j in 1:length(vars)) {
paste(vars[i], and , vars[j])
polychor(vars[i], vars[j])
# corr
  }
  }
 
 
 
  --
  Kum-Hoe Hwang, Ph.D.Phone : 82-31-250-3516Email : [EMAIL PROTECTED]
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 


 --
 =
 David Barron
 Said Business School
 University of Oxford
 Park End Street
 Oxford OX1 1HP



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] How to get multiple Correlation Coefficients

2006-10-19 Thread David Barron
The problem is that in the expression  polychor(vars[i], vars[j]),
vars[i] and vars[j] refer to the names of the variables, not the
variables themselves.  So, use sdi[,i] and sdi[,j] instead.

On 19/10/06, Kum-Hoe Hwang [EMAIL PROTECTED] wrote:
 Hi

 I have used a polycor package for categorical correlation coefficients.
 I run the following script. But there were no results.

 Could you tell me how to correct the script?

 Thanks in advance,

 vars - names(sdi)
 for (i in 1:length(vars)) {
 for (j in 1:length(vars)) {
   paste(vars[i], and , vars[j])
   polychor(vars[i], vars[j])
   # corr
 }
 }



 --
 Kum-Hoe Hwang, Ph.D.Phone : 82-31-250-3516Email : [EMAIL PROTECTED]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Multiple histograms in one plot

2006-10-18 Thread David Barron
I suspect that mar doesn't work with split.screen.  You could try
using mfrow instead:

 par(mar=c(1,1,1,1),mfrow=c(5,4))
 for (i in 1:20) hist(rnorm(100),main=,cex.axis=.8)

With margins this small, though, you won't be able to see the axis
annotation for the left axes of the left column or the bottom axis of
the bottom row.

On 18/10/06, Johann Hibschman [EMAIL PROTECTED] wrote:
 Hi all,

 I'm trying to plot multiple histograms in one plot (cross-validation
 values of model parameters), but I cannot seem to reduce the margins
 enough to fit as many of them in as I would like.

 I'm using split.screen to divide the window into a 5x4 grid, then
 plotting with hist.  I've tried explicitly reducing the margins with
 par(mar=c(1,1,1,1)), but it doesn't seem to have any effect.
 Visually, there is a lot of whitespace and very little histogram in my
 results.

 Can anyone suggest either a better method to visualize these results,
 a better way to plot histograms, or a way to actually reduce the
 margins used?  The intent is to give a sense of how well-constrained
 the various model parameters are.

 Thanks,

 Johann

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Variance of fitted value in lm

2006-10-17 Thread David Barron
You can get these via the predict function.

On 17/10/06, Li Zhang [EMAIL PROTECTED] wrote:
 Hi,

 I am wondering if a linear model

 lm(y~ x1+x2) calculates the variance of a fitted
 value.

 Thank you

 Li

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Fill a matrix with vectors of different lengths

2006-10-16 Thread David Barron
 for (i in 1:length(v)) {
  bi - binc(v[1:i])
  mat[1:length(bi),i]=mat[1:length(bi),i]+bi
}

On 16/10/06, Serguei Kaniovski [EMAIL PROTECTED] wrote:
 Hello,

 how can I best fill a (fixed) matrix with vectors of varying lengths by
 column, setting the superfluous elements to zero? Here is my code:

 v-(1,1,2,3,4,6)

 binc-function(x){
 l-sum(x)+1
 y-c(1,rep(0,l-1))
 for (i in x) y-y+c(rep(0,i),y)[1:l]
 }

 mat-matrix(0, nrow=sum(v)+1, ncol=length(v))
 for (i in 1:length(v)) mat[,i]=mat[,i]+binc(v[1:i])

 the expression in the for-loop produces an error since mat[,i] and
 binc(v[1:i]) are of unequal lengths, except on the last iteration.

 Thanks in advance,
 Serguei
 --
 ___

 Austrian Institute of Economic Research (WIFO)

 Name: Serguei Kaniovski P.O.Box 91
 Tel.: +43-1-7982601-231 Arsenal Objekt 20
 Fax:  +43-1-7989386 1103 Vienna, Austria
 Mail: [EMAIL PROTECTED]

 http://www.wifo.ac.at/Serguei.Kaniovski

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] set linetype with plotCI

2006-10-16 Thread David Barron
You could look at the plotCI function in the plotrix package, which
has a separate parameter for setting the linetype of the error bars.

(An additional benefit is that it works with R 2.4.0 -- gplots seems
not to have been updated, or at least the windows binary hasn't, and
still includes a now defunct feature.)

On 16/10/06, JeeBee [EMAIL PROTECTED] wrote:
 Sorry, the plot_linetypes[1] is a debugging leftover.
 It's plot_linetypes[graph_idx] in my actual code ...
 And plot_linetypes is just the sequence 1,2,3,4... etc

  plotCI(
x = xvals.f[sorted],
y = yvals.f[sorted],
xlim = c(xmin, xmax), ylim = c(ymin, ymax),
pch = plot_symbols[graph_idx], type = b,
  lty = plot_linetypes[1],
col = plot_colors[graph_idx],
  barcol = plot_colors[graph_idx], uiw = NA,
xlab = , ylab = ,
add = (plot_cnt  0)
  )

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] set linetype with plotCI

2006-10-16 Thread David Barron
Looking at the source code for plotCI, I see that it calls plot with
type specified as n when  the error bars are not being added to an
existing plot, so you cannot use the type argument in a call to
plotCI.  If you want to add lines as well as points, I think you will
have to use lines(x,y,type=b,lty = plot_linetypes[graph_idx]) in
addition to plotCI, or amend the plotCI function to your own
specifications.

On 16/10/06, JeeBee [EMAIL PROTECTED] wrote:
 Thanks, I tried using plotCI in the plotrix library.
 This, however, gives me the below error.

 CODE::
   cat(x = ); print(xvals.f[sorted])
   cat(y = ); print(yvals.f[sorted])
   cat(pch = ); print(plot_symbols[graph_idx])
   cat(lty = ); print(plot_linetypes[graph_idx])
   cat(col = ); print(plot_colors[graph_idx])
   print(paste(graph_idx =, graph_idx, and plot_cnt =, plot_cnt))
   plotCI(
 x = xvals.f[sorted],
 y = yvals.f[sorted],
 xlim = c(xmin, xmax), ylim = c(ymin, ymax),
 pch = plot_symbols[graph_idx], type = b,
 lty = plot_linetypes[graph_idx],
 col = plot_colors[graph_idx],
 barcol = plot_colors[graph_idx], uiw = NA,
 xlab = , ylab = ,
 add = (plot_cnt  0)
   )
   print(plotCI succeeeded...)

 OUTPUT::

 x =  [1] 160 160 160 160 160 160 160 160 160 160 320 320 320 320 320 320 320 
 320 320
 [20] 480 480 480 480 480 480 480 480 480 640 640 640 640 640 640 640 640 800 
 800
 [39] 800 800 800 800 800 800 800 960 960 960 960 960 960 960 960 960
 y =  [1] 0.062263829 0.062263829 0.062263829 0.062263829 0.062263829 
 0.062263829
  [7] 0.062263829 0.062263829 0.062263829 0.062263829 0.029483948 0.029483948
 [13] 0.029483948 0.029483948 0.029483948 0.029483948 0.029483948 0.029483948
 [19] 0.029483948 0.018035707 0.018035707 0.018035707 0.018035707 0.018035707
 [25] 0.018035707 0.018035707 0.018035707 0.018035707 0.009895540 0.009895540
 [31] 0.009895540 0.009895540 0.009895540 0.009895540 0.009895540 0.009895540
 [37] 0.008534913 0.008534913 0.008534913 0.008534913 0.008534913 0.008534913
 [43] 0.008534913 0.008534913 0.008534913 0.007301515 0.007301515 0.007301515
 [49] 0.007301515 0.007301515 0.007301515 0.007301515 0.007301515 0.007301515
 pch = [1] 0
 lty = [1] 1
 col = [1] #FF
 [1] graph_idx = 1 and plot_cnt = 0
 Error in plot.default(c(160, 160, 160, 160, 160, 160, 160, 160, 160, 160,  :
 formal argument type matched by multiple actual arguments

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] help with plot()

2006-10-16 Thread David Barron
It's possible the problem is with your data; could you provide some
sample data with which we can reproduce the error?

On 16/10/06, tom soyer [EMAIL PROTECTED] wrote:
 Hi,

 I am new to R and I have been trying it out. I ran into a problem with the
 plot() function. Below is my code:

   d - read.table(c:/test/sp.txt,header=0)
  spval - d[,2]
  plot(spval,type=l)
 Warning messages:
 1: graphical parameter type is obsolete in: plot.window(xlim, ylim, log,
 asp, ...)
 2: graphical parameter type is obsolete in: axis(side, at, labels, tick,
 line, pos, outer, font, lty, lwd,
 3: graphical parameter type is obsolete in: title(main, sub, xlab, ylab,
 line, outer, ...)
 4: graphical parameter type is obsolete in: axis(side, at, labels, tick,
 line, pos, outer, font, lty, lwd,

 I tried to plot a line graph from a text file with two columns. Some how R
 won't plot the data as lines, and it kept giving me the same warning: type
 is obsolete. What does this mean? Am I doing something wrong, or is the
 parameter really obsolete, or do I need install some package?

 Thanks,

 Tom

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] BarPlot

2006-10-16 Thread David Barron
Specify margins using par(mar=c(5,1,4,2)) before the call to barplot.
You won't be able to see the vertical axis labels with those settings,
though.

On 16/10/06, Mohsen Jafarikia [EMAIL PROTECTED] wrote:
 Hello everyone:

 I am using the following code to draw my barplot but it has two problems.

 BL-c(1.97,8.04,2.54,10.53,4.85,1.73)
 LR-c(0.85,0.86,8.33,04.18,6.26,2.40)
  Q-c(0.00,0.00,1.92,01.92,4.48,0.00)
 cols - ifelse(Q!=0, orange, green)
 Graph- barplot(LR, main='LR Value',col=cols, border='black', space=0.05,
 width=(BL), xlab='Length', ylab='LR block',mar=c(5,1,4,2))  
 axis(1, at=Graph, sprintf('%0.2f',BL))
 mtext(1, at=Graph, text=ifelse(Q!=0, sprintf('%0.2f',Q), ), line=2)
 mtext(1, at=par('usr')[1], text='BL', line=1)
 mtext(1, at=par('usr')[1], text='Var', line=2)
 abline(h=3.84,col='blue')
 abline(h=6.64,col='red')
 text(31,3.84,expression(paste(alpha==5,%)),pos=3)
 text(31,6.64,expression(paste(alpha==1,%)),pos=3)

 1)  I don't know how to specify the margins. I have written it in the
 code but it is not working.
 2)  I want the value of alph=5% at the right end of the line but it is
 almost in the left side and sometimes in the right side when I use the same
 code for drawing another barplot.

 I appreciate any comments about these problems.

 Thanks,
 Mohsen

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] BarPlot

2006-10-15 Thread David Barron
Try adding

 text(31,3.8,expression(paste(alpha==5,%)),pos=3)


On 15/10/06, Mohsen Jafarikia [EMAIL PROTECTED] wrote:
 Hello again,

 Thanks for answering my questions.
 If my program is now:

  pdf('Test.pdf')
 BL-c(1.97,8.04,2.54,10.53,4.85,1.73)
 LR-c(0.85,0.86,8.33,04.18,6.26,2.40)
  Q-c(0.00,0.00,1.92,01.92,4.48,0.00)

  cols - ifelse(Q!=0, orange, green)
 Graph- barplot(LR, main='LR Value',col=cols, border='black', space=0.05,
 width=(BL), xlab='Length', ylab='LR block')

 axis(1, at=Graph, sprintf('%0.2f',BL))
 mtext(1, at=Graph, text=ifelse(Q!=0, sprintf('%0.2f',Q), ), line=2)
 mtext(1, at=par('usr')[1], text='BL', line=1)
 mtext(1, at=par('usr')[1], text='Var', line=2)
 abline(h=3.8, col='blue')I want to add alpha=5% at the end
 of this line

  And now I want to write alpha=5% at the end of the line that I have on my
 graph.

 Thanks,
 Mohsen



 On 10/15/06, Marc Schwartz [EMAIL PROTECTED] wrote:
 
  On Sat, 2006-10-14 at 23:52 -0400, Mohsen Jafarikia wrote:
   Hello everyone,
  
   I have the following program to draw a barplot.
  
  
  
   MP-read.table(file='AR.out')
  
   names(MP)-c('BN','BL','LR','Q')
  
   Graph- barplot(MP$LR, main='LR Value', col='orange', border='black',
  space=
   0.05, width=(MP$BL), xlab='Length', ylab='LR each')
  
   axis(1, at=Graph, sprintf('%0.2f',MP$BL))
  
   mtext(1, at=Graph, text=sprintf('%0.2f',MP$Q), line=2)
  
   mtext(1, at=par('usr')[1], text='BL', line=1)
  
   mtext(1, at=par('usr')[1], text='Var', line=2)
  
   abline(h= 3.841,col='blue')
  
   abline(h=6.635,col='red')
  
  
  
   I have two more questions about the graph that I have:
  
   1) I want to write the 'Q' only when it is not equal to zero.
  
   2) I would like to change the bars when 'Q' is not zero. For example,
  from
   orange to green.
  
  
  
   I would appreciate your input to this question.
   Thanks,
  
   Mohsen
 
  It would be helpful to have the data that you are working with so that
  we can provide each other a working example.
 
  However, here are some hints:
 
  1.
 
mtext(1, at = Graph,
  text = ifelse(MP$Q != 0, sprintf('%0.2f',MP$Q), ),
  line=2)
 
 
  2.
 
cols - ifelse(MP$Q != 0, orange, green)
barplot(..., col = cols, ...)
 
 
  See ?ifelse
 
  HTH,
 
  Marc Schwartz
 
 
 

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Need help with barplots

2006-10-13 Thread David Barron
First, produce two barplots for comparison:

 par(mfrow=c(2,1) )
 barplot(VADeaths,beside=TRUE)
 barplot(VADeaths)

The same information is in both plots; in the top, it is displayed as
5 separate bars for each group, and in the stacked plot it is shown as
5 separate regions in each of the four bars.  The hight of each of
these regions is the same as the hight of the corresponding bar in the
side-by-side plot.  The stacked plot enables you to see overall
differences more easily (easier to see that the death rate is highest
for Urban Males), but it is harder to compare the sizes of the
categories.

On 13/10/06, laba diena [EMAIL PROTECTED] wrote:
 I`ve read all the manuals and still couln`t find what is the difference
 between the stacked and side-by-side barplots ? Could you explain me ?

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Need help with tables

2006-10-13 Thread David Barron
I'm not quite sure what you mean, but if you are wanting to select
columns of a data frame, have a look at

 help([)

David

On 13/10/06, laba diena [EMAIL PROTECTED] wrote:
 I have a data file with 3 columns and I need to take only 2, how to do that
 ?

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] for loop not working in function

2006-10-11 Thread David Barron
I'd suggest looking at the boxcox function in the MASS package, which might
show you how to change your code.

It would be easier to diagnose the problem if you included a small example
showing the errors.  Some possibilities are that if x is a vector, nrow(x)
will return NULL,  that you are using lambda as the index variable in the
for loop, so the sequence generated in the second line is getting
overwritten, and the for loop isn't enclosed in braces, so only the first
line will be counted as being in the loop.

HTH,

David

On 11/10/06, Dale Steele [EMAIL PROTECTED] wrote:

 I'm trying to write a small function (below) to compute Box  Cox
 transformations of x for arbitrary values of lambda.  I'd like to
 specify a range of values for lamba (min,max,step) and am having trouble
 getting the for loop to work.  Suggestions?

 Any pointers to resources for learning to write functions in R for
 neophyte programmers?  Thanks.  --Dale


 boxcox - function(x,min,max,step) {
 lambda - seq(min,max,step)
 s - length(lambda)
 for (lambda in 1:s)
 n - nrow(x)
 if(lambda ==0) xL - log(x) else
 xL - ((x^lambda) - 1)/lambda
 xLbar - mean(xL)
 t1 - (-n/2)* log((1/n)*sum((xL -  xLbar)^2))
 t2 - (lambda - 1)*sum(log(x))
 l= t1 + t2
 l
 }

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




-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

[[alternative HTML version deleted]]

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


Re: [R] samples to dataframes

2006-10-11 Thread David Barron
I'm not familiar with seewave package, but I imagine what you have to do is
extract the sound component of the sample object and convert that to a data
frame.

 waveLeft - 2*((seq(0,80,length=88200)%%1^2)-.5)
 s - as.Sample(waveLeft,44100,16)
 ds  - data.frame(s$sound)
 is.data.frame(ds)
[1] TRUE


On 11/10/06, randy zelick [EMAIL PROTECTED] wrote:

 Hello all,

 I'll bet this is not complicated, but I really did hunt for information
 on it, and tried some ideas without success.

 Running Windows XP and R 2.3.1

 I am using the Sound package to read in .wav files, and this works fine.
 The R object produced is of class sample. I want to use some of the
 functions in the package Seewave to do further analysis, but this
 package wants data objects to be dataframes. So I tried various ways to
 coerce samples to dataframes, but was not successful.

 Does anyone have a hint/solution?

 Thanks much,

 =Randy=

 --
 Randy Zelickemail: [EMAIL PROTECTED]
 Department of Biology   voice: 503-725-3086
 Portland State University   fax:   503-725-3888

 mailing:
 P.O. Box 751
 Portland, OR 97207

 shipping:
 1719 SW 10th Ave, Room 246
 Portland, OR 97201

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




-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

[[alternative HTML version deleted]]

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


Re: [R] Rank Function

2006-10-10 Thread David Barron
 y-round(c(0.68,0.95,b,c,d),2)
 rank(y)
[1] 3.5 5.0 1.0 2.0 3.5


On 10/10/06, Li Zhang [EMAIL PROTECTED] wrote:

 Does anyone know why the two rank functions gives
 different results? I need to use the rank function in
 a for loop, so the sequence to be ranked is given
 values in the form of part (1). How can I use
 assignment like in part (1) to get correct ranks as in
 part (2)?

 Thank You



 Part (1)
 i-1.94
 b-0.95-i
 c-1.73-i
 d-2.62-i

 y-c(0.68,0.95,b,c,d)

 y
 0.68  0.95 -0.99 -0.21  0.68

 rank(y)
 3 5 1 2 4

 Part(2)
 rank(c(0.68,0.95,-0.99,-0.21,0.68))
 3.5 5.0 1.0 2.0 3.5

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




-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

[[alternative HTML version deleted]]

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


Re: [R] hist plot

2006-10-06 Thread David Barron
This is taken from the help for the hist function:

Typical plots with vertical bars are not histograms. Consider barplot
or plot(*, type = h) for such bar plots.

For example:
 x - rchisq(100, df = 4)

 op-hist(x, freq = FALSE, ylim = c(0, 0.2))
 plot(op$mids,op$counts,type=h)


On 06/10/06, Baoqiang Cao [EMAIL PROTECTED] wrote:
 Hi there,

 I really couldn't find out how to plot histogram with point/line instead of 
 rectangle for each bin? Any help please? Thanks!

 Best,
  -Cao

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Partition into quantiles

2006-10-05 Thread David Barron
You might also want to look at the function quantcut in the gtools
package (part of the gregmisc bundle).



On 05/10/06, Alberto Monteiro [EMAIL PROTECTED] wrote:
 Is there any function that divides a sample into N quantiles?

 For example, for N = 2, this would be the solution:

 x - rnorm(100)
 m - median(x)
 q - ifelse(x = median, 1, 2)

 Alberto Monteiro

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] xyplot

2006-10-05 Thread David Barron
If you include a conditioning factor (here it is the variable
groups) you will get more than one panel. To get loess curves for
the two groups, the easiest way is to use the type argument:

 xyplot(y ~ time, groups=group,data=df,type=c(p,smooth))


On 05/10/06, Osman Al-Radi [EMAIL PROTECTED] wrote:
 Hello,

 Thanks for your answer, however, the resulting graph has two panels with a
 loess curve per subject. I need a single panel with a loess curve per
 group..

 Osman

 On 10/5/06, Sundar Dorai-Raj [EMAIL PROTECTED] wrote:
 
 
 
  Osman Al-Radi said the following on 10/5/2006 3:43 PM:
   Hi,
  
   for the data below:
   time-c(rep(1:10,5))
   y-time+rnorm(50,5,2)
   subject-c(rep('a',10),rep('b',10),rep('c',10),rep('d',10),rep('e',10))
   group-c(rep('A',30),rep('B',20))
   df-data.frame(subject,group,time,y)
  
   I'd like to produce a plot with a single pannel with two loess curves
  one
   for each group. the code below does that but on two different pannels,
  I'd
   like to have both curves on the same pannel with different colors.
  
   xyplot(y~time|group, groups=subject,
   panel=function(...){
   panel.loess(...)
   }
   ,data=df)
  
  
 
  Simple:
 
  xyplot(y ~ time | group, data = df, groups = subject,
  panel = function(...) {
panel.superpose(...)
panel.superpose(panel.groups = panel.loess, ...)
  })
 
  HTH,
 
  --sundar
 



 --
 Osman O. Al-Radi, MD, MSc, FRCSC
 Fellow, Cardiovascular Surgery
 The Hospital for Sick Children
 University of Toronto, Canada

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] convert vector to matrix

2006-10-04 Thread David Barron
cbind always produces a matrix or data frame.  What the FAQ says is
that a subsetting operation *on* a matrix will result in redundant
dimensions being
dropped, not that you can't get a matrix with a redundant dimension
as a result of a function.

So,
 vec-1:10
 vec
 [1]  1  2  3  4  5  6  7  8  9 10
 cbind(vec)
  vec
 [1,]   1
 [2,]   2
 [3,]   3
 [4,]   4
 [5,]   5
 [6,]   6
 [7,]   7
 [8,]   8
 [9,]   9
[10,]  10
 mat-cbind(vec)
 dim(mat)
[1] 10  1
 mat[,1]
 [1]  1  2  3  4  5  6  7  8  9 10

takes us back to a vector again.

On 04/10/06, Alberto Monteiro [EMAIL PROTECTED] wrote:
 Gavin Simpson wrote:
 
  Did you even try to use cbind on your vector? I guess not as,
 
   vec - 1:10
   mat - cbind(vec)
   mat
 
 Why does mat remain a matrix instead of losing one dimension?
 I am reading the FAQ at...
 http://cran.us.r-project.org/doc/FAQ/R-FAQ.html#Why-do-my-matrices-lose-
 dimensions_003f
 ... and it seems that anything you do to mat should turn it back
 into a one-dimensional vector.

 Alberto Monteiro

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] bar chart with several lines

2006-10-02 Thread David Barron
This should be enough to show how to do it:

 dta - read.table(clipboard,dec=,,row.names=NULL)
 r - barplot(dta$use,ylim=c(-80,60))
 lines(r,dta$x1,type=b,col=red,pch=20)
 lines(r,dta$x2,type=b,col=blue,pch=21)


On 01/10/06, Marko Ekqvist [EMAIL PROTECTED] wrote:
 Hi,
 I have been some problems with producing bar graph with r. Here is my
 example data (link) and picture but I am not able to do that with r.
 Please any kind of help is welcome

 http://www.pasilankaista.com/~ekqvistmt/r/Page001.html

 Kind Regards,
 Marko

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] finding correlation between two matrices

2006-10-02 Thread David Barron
Have you looked at the function mantel.rtest in the ade4 package?

On 02/10/06, sima fakheran [EMAIL PROTECTED] wrote:
 Dear all,

 I would like to compare two distance matrices to find the correlation
 between those and create a XY plot.could you please kindly help me and
 let me know how I can do that using R.(Mantel test?).

 Your help is very much appreciated!! Many thanks!

 Regards,
 Sima Fakheran
 ...
 Sima Fakheran Esfahani
 PhD Student
 Institute of Environmental Sciences
 University of Zurich
 Winterthurerstrasse 190
 8057 Zurich
 Switzerland
 Tel: +41 1 635 61 18
 Fax:+41 1 635 57 11
 email:[EMAIL PROTECTED]
  http://www.uwinst.unizh.ch www.uwinst.unizh.ch


 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] line plot through NA

2006-10-02 Thread David Barron
I assume you mean that you want the first point to be connected by a
straight line to the third, etc. because fisrt and sixth points are
shown on the plot.  If so, you can use the approx function:


plot(approx(Day,V,n=length(Day)), type=l)
points(Day,V)

On 02 Oct 2006 15:31:59 +0100, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Dear R-help list,

 I hope I did not miss something obvious, because my question seems very
 simple, but I couln't figure out how to do it.

 If I have the following data:
 Day-c(1,2,3,4,5,6,7)
 V-c(5,NA,10,30,45,NA,10)
 than the line in plot

 plot(V~Day, type=b)

 will start with the 3rd value and stop stop at the 5th value because all NA
 are omitted. Is there now a parameter which can be added to the plot
 function so the line will start with with the first value and skip the NA
 values and can this than applied to xyplots.

 Many thanks

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Setting NA

2006-09-30 Thread David Barron
Would using the subset argument that is available in many functions
(eg lm) achieve what you want?

On 30/09/06, Anupam Tyagi [EMAIL PROTECTED] wrote:
 Is there a way to set NA values in R, without changing the dataframe? I would
 like to use different combinations of non-response values, as if they were NA
 for some of the computations. I don't want to change the dataframe each time I
 have to do this?
 Anupam.

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Inner product

2006-09-30 Thread David Barron
For inner product see ?%*%.  There is a norm function in the Matrix package.

On 30/09/06, Sonal Darbari [EMAIL PROTECTED] wrote:
 Hi,

 How do we find out the inner product  norm of eigen vectors in R?

 Lets say we have eigen vectors :
 x1 = 1,2,3 and x2 = 2,-3,4

 are there any functions buit in R which directly calculate the inner product
  norm of vectors?

 Thanks,
 Sonal.

 [[alternative HTML version deleted]]

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Any hot-deck imputation packages?

2006-09-27 Thread David Barron
I'm not sure if this is exactly what you're after, but it might be worth
looking at aregImpute in the Hmisc package.

On 27/09/06, Eleni Rapsomaniki [EMAIL PROTECTED] wrote:

 Hi

 I found on google that there is an implementation of hot-deck imputation
 in
 SAS:
 http://ideas.repec.org/c/boc/bocode/s366901.html

 Is there anything similar in R?

 Many Thanks
 Eleni Rapsomaniki

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




-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

[[alternative HTML version deleted]]

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


Re: [R] Constrained OLS regression

2006-09-27 Thread David Barron
Have a look at the linear.hypothesis function in the car package.  For example:

 mod.duncan - lm(prestige ~ income + education, data=Duncan)

 linear.hypothesis(mod.duncan, income + education = 1)
Linear hypothesis test

Hypothesis:
income + education = 1

Model 1: prestige ~ income + education
Model 2: restricted model

  Res.DfRSS Df Sum of Sq  F  Pr(F)
1 42 7506.7
2 43 8045.2 -1-538.5 3.0129 0.08994 .
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


On 27/09/06, Mesomeris, Spyros [CIR] [EMAIL PROTECTED] wrote:
 Hello R helpers,

 I am trying to do a linear OLS regression of y on two variables x1 and
 x2. I want to constrain the coefficients of x1 and x2 to sum up to 1.
 and therefore run a constrained OLS. Can anybody help with this? (I have
 seen some answers to similar questions but it was not clear to me what I
 need to do) - I have tried the lm function with offset but I must not
 have used it properly.

 Thanks,
 Spyros

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




-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Searching for keyword values in a text (configuration) file

2006-09-27 Thread David Barron
Something like this?

 library(Hmisc)
 t - readLines(clipboard)
 t
[1] DEVICE = 'PC' CPU_SPEED = '1999', '233'

 ix - grep(CPU_SPEED,t)
 loc - substring.location(t[ix],,)
 cpu - substring(t[ix],loc$first+2)
 cpu
[1] '233'


On 27/09/06, Andre Jung [EMAIL PROTECTED] wrote:
 Hi,

 I would like to read values from an ASCII text file that contains
 information in the following format:

 DEVICE = 'PC'
 CPU_SPEED = '1999', '233'
 ...

 It's like a config file.

 How can I e.g. get R to read the 2nd value of CPU_SPEED?
 How do I go through text files and search for keywords and their values?

 Thanks a lot,
 Andre

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] Converting text to numbers

2006-09-27 Thread David Barron
 Then, I tried to convert them to numbers using the following.
  Sample1$FCT2 - as.numeric(Sample1$FCT2)
  Sample1$OBS2 - as.numeric(Sample1$OBS2)


This is actually an FAQ.  Do the following and it should be fine:

 Sample1$FCT2 - as.numeric(as.character(Sample1$FCT2))
 Sample1$OBS2 - as.numeric(as.character(Sample1$OBS2))



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


Re: [R] printing a variable name in a for loop

2006-09-26 Thread David Barron
This would do it:

 v1 - 5
 v2 - 6
 v3 - 7

 vns - paste(v,1:3,sep=)
 for (i in 1:length(vns)) cat(Hello, vns[i], get(vns[i]), World\n, sep=,)

Hello,v1,5,World
Hello,v2,6,World
Hello,v3,7,World


On 24/09/06, Suzi Fei [EMAIL PROTECTED] wrote:
 Hello,

 How do you print a variable name in a for loop?

 I'm trying to construct a csv file that looks like this:


 Hello, variable1, value_of_variable1, World,
 Hello, variable2, value_of_variable2, World,
 Hello, variable3, value_of_variable3, World,


 Using this:

 for (variable in list(variable1, variable2, variable3)){

 cat(Hello,, ???variable???, variable, , World,)
 }

 This works fine if I'm trying to print the VALUE of variable, but I want to
 print the NAME of variable as well.

 Thanks,
 Suzi

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



-- 
=
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

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


  1   2   >