[R] write result in matrix using loop

2009-08-13 Thread Grześ

Hello,
I want call my function (use my database) and write every result in matrix
"wynik" but I always get an error: Error in wynik[, i] <- dodawanie(wzorzec,
wzorzec1) : 
  number of items to replace is not a multiple of replacement length

I'll be very happy if sb help me

 
dodawanie<- function ( wzorzec, wzorzec1){ 
wynik1<-wzorzec + wzorzec1 
wynik2<-wzorzec * wzorzec1 
wynik <- c(wynik1,wynik2) 
return (wynik) 
} 

df=data.frame(a=c(1,2,3),b=c(9,9,9),c=c(4,3,2)) # This is my database ;) 

wynik=matrix(0,nrow=10,ncol=2) 

# and my loop 
for(i in 1:ncol(df)){ 
procent_graniczny <- 10 
wzorzec=df[,i] 
wzorzec1=ifelse(df$a==3,1,ifelse(df$c==4,2,3)) 
wynik[,i] <- dodawanie ( wzorzec, wzorzec1)#  <-  Here is my problem
!!! I want in "wynik" have got result from my function (one by one)
} 


-- 
View this message in context: 
http://www.nabble.com/write-result-in-matrix-using-loop-tp24958820p24958820.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] email notification after error

2009-08-13 Thread caltechneurostudy

Does anybody know if it's possible to have R send an email or execute an
additional line of code in case an error is generated from a running script?
I am running R on a cluster and would like to have it kill the job if R
generates an error, but as it is, the job just keeps running until the
wallclock is done.

Thanks.
-- 
View this message in context: 
http://www.nabble.com/email-notification-after-error-tp24963220p24963220.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] randomForest question--problem with ntree

2009-08-13 Thread Mary Putt
Hi, 

I would like to use a random Forest model to get an idea about which variables 
from a dataset may have some prognostic significance in a smallish study. The 
default for the number of trees seems to be 500. I tried changing the default 
to ntree=2000 or ntree=200 and the results appear identical. Have changed mtry 
from mtry=5 to mtry=6 successfully. Have seen same problem on both a Windows 
machine and our linux system running 2.8 and 2.9. 

Sample code follws.

Thanks in advance for help. 

Mary


> m1<-as.formula(paste("as.factor(EAD)~", paste(names(clin_b)[c(5,7,10:36 )], 
> collapse="+")))
> m1
as.factor(EAD) ~ R_AGE + R_BMI + ASCITES...1L. + EOTAXIN + GM.CSF + 
IFNa + IL.10 + IL.12.p40.p70 + IL.13 + IL.15 + IL.17 + IL.2 + 
IL.4 + IL.5 + IL.6 + IL.7 + IL.8 + IL1.RA + IL2.R + IP.10 + 
MCP.1 + MIG + MIP.1a + MIP.1b + RANTES + TNFa + Male + diagnosis + 
race
> 
> 
> 
> 
> set.seed(12345)
> rF.bsl<-randomForest(m1, data=clin_b, na.action=na.omit, mtry=6, n.tree=2000)
> rF.bsl$ntree
[1] 500
> rF.bsl$mtry
[1] 6
> print(rF.bsl)

Call:
 randomForest(formula = m1, data = clin_b, mtry = 6, n.tree = 2000,  na.action 
= na.omit) 
   Type of random forest: classification
 Number of trees: 500
No. of variables tried at each split: 6

OOB estimate of  error rate: 39.66%
Confusion matrix:
   0 1 class.error
0 27 7   0.2058824
1 16 8   0.667
> 
> 
> set.seed(12345)
> rF.bsl<-randomForest(m1, data=clin_b, na.action=na.omit, mtry=6, n.tree=100)
> rF.bsl$ntree
[1] 500
> rF.bsl$mtry
[1] 6
> print(rF.bsl)

Call:
 randomForest(formula = m1, data = clin_b, mtry = 6, n.tree = 100,  
na.action = na.omit) 
   Type of random forest: classification
 Number of trees: 500
No. of variables tried at each split: 6

OOB estimate of  error rate: 39.66%
Confusion matrix:
   0 1 class.error
0 27 7   0.2058824
1 16 8   0.667
> 
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] R 2.9.2 Scheduled for August 24, 2009

2009-08-13 Thread Peter Dalgaard

This is to announce that we plan to release R version 2.9.2 on Monday,
August 24, 2009.

Release procedures start Friday, August 14.

Those directly involved should review the generic schedule at
http://developer.r-project.org/release-checklist.html

The source tarballs will be made available daily (barring build
troubles) and the tarballs can be picked up at

http://cran.r-project.org/src/base-prerelease/

a little later.

Binary builds are expected to appear starting Monday August 17 at the 
latest.


For the Core Team
Peter Dalgaard


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

___
r-annou...@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-announce
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 rename columns that start with numbers?

2009-08-13 Thread Patrick Connolly
On Thu, 13-Aug-2009 at 04:24PM -0600, Mark Na wrote:

|> Hello,
|> 
|> My dataframe has new columns that start with the number 1 or 2 (resulting
|> from a reshape cast command).
|> 
|> Instead of having these columns automatically renamed by R so start with the
|> letter X, I would like to rename these columns to start with the characters
|> "SURV_" (e.g., SURV_1, SURV_2).
|> 
|> I can't seen to use grep() to identify and rename the columns starting with
|> either 1 or 2.
|> 
|> Any help would be much appreciated, thanks!
|> 
|> (I know I could rename these manually, but the above is a simpler statement
|> of the actual problem, which involves several dozen columns, so that's why
|> I'd prefer not to so it manually)

Without knowing what your data looked liked before it was reshaped,
it's a bit hard to guess what would be a good way to avoid the
problem, but this might be a case where cure might be easier than
prevention.

If your dataframe has names like these:
> names(junk.df)
[1] "Fruit""January"  "February" "X1"   "X2"   "X3"   "X4"  

You can replace each incidence of "X" with "SURV_" this way:

> names(junk.df) <-  gsub("X", "SURV_", names(junk.df))
> names(junk.df)
[1] "Fruit""January"  "February" "SURV_1"   "SURV_2"   "SURV_3"   "SURV_4"  

If there are other instances where "X" is a desirable part of the
name, it would be a bit trickier, but not much.

HTH


|> 
|> Mark Na
|> 
|>  [[alternative HTML version deleted]]
|> 
|> __
|> R-help@r-project.org mailing list
|> https://stat.ethz.ch/mailman/listinfo/r-help
|> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
|> and provide commented, minimal, self-contained, reproducible code.

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

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


Re: [R] Solutions of equation systems

2009-08-13 Thread Moshe Olshansky
Is your system of equations linear?

--- On Fri, 14/8/09, Moreno Mancosu  wrote:

> From: Moreno Mancosu 
> Subject: [R] Solutions of equation systems
> To: r-help@r-project.org
> Received: Friday, 14 August, 2009, 2:29 AM
> Hello all!
> 
> Maybe it's a newbie question(in fact I _am_, a newbie), but
> I hope you'll find the solution.
> I have an equation system which has k equation and n
> variables (k I would like to obtain a description of the solutions
> (which can be the equation of lines or a plane, or
> everything else) with the lesser degree of freedom,
> obviously using R.
> In other words, I would like to obtain a result which is
> very similar to the results of Maxima or similar software.
> I tried to search on internet and i found the systemfit
> package, but I think it is not related with my problem.
> Any idea?
> 
> Thanks in advance,
> 
> Moreno
> 
> __
> R-help@r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>

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


Re: [R] Simulating points from GLM corresponding to new x-values

2009-08-13 Thread Jacob Nabe-Nielsen

Hi Cliff,

Excellent, just what I needed -- wish I had thought of that myself.  
Thanks a lot!


Jacob


On 13 Aug 2009, at 01:49, Clifford Long wrote:


Hi Jacob,

At the risk of embarrassing myself, I gave it a shot.  I'll throw this
out on the list, if for no other reason than perhaps someone with
higher wattage than myself might tear it apart and give you something
both useful and perhaps elegant (from an R coding standpoint).

(see the following ... it just ran for me, so I hope it will for  
you, too)


If this isn't what you need, I'll shut up and watch and learn from  
the others.


Regards,

Cliff


I tried to put together something that might work as an example ...
based on a simple linear regression model, but using the GLM routine.

Once the model was created, I used 'predict' based on the model
outcome and the original x values.

I then used 'predict' based on the model outcome and new x values,
along with a function for simulation of the distribution at the new x
values.

At the


#--
# Create sample data set to use with GLM
#   (assume first order linear model for now)
#--
b0 = 10
b1 = 0.3
x = sort(rep(seq(1,11, by=2), 10))

fn.y = function(x1){y1 = b0 + b1*x1 + rnorm(n=1, mean=0, sd=1)}

y = sapply(x, fn.y)


xydata = data.frame(cbind(x, y))


model1 = glm(y ~ x, family = gaussian, data = xydata)


#--
# Generate new x values
#   run new x values through 'predict'
#--

newx = data.frame(xnew = sort(rep(seq(2,10, by=2), 12)))

y.pred = predict(model1, newx, se.fit = TRUE)


#--
# Generate simulated values based on new x values
#   and function based on outcome of 'predict' routine
#--

fn.pred = function(fit, sefit){rnorm(n=1, mean=fit,  
sd=sefit*sqrt(60))}


pred.sim = sapply(y.pred$fit, fn.pred, y.pred$se.fit)


#--
# Generate simulated values based on orig x values
#   using 'simulate' routine
#--

y.sim = simulate(model1, nsim = 1)


#--
# Plot original x, y values
#   then add simulated y values from 'simulate' based on orig x values
#   and the add simulated values from 'predict' and function based on
new x values
#--
plot(x, y)
lines(x, y.sim$sim_1, col='red', type='p')
lines(newx[,1], pred.sim, col='darkblue', type='p')

#--
# END
#--



On Wed, Aug 12, 2009 at 2:51 PM, Jacob Nabe- 
Nielsen wrote:

Hi Cliff -- thanks for the suggestion.

I tried extracting the predicted mean and standard error using  
predict().
Afterwards I simulated the dependent variable using rnorm(), with  
mean and
standard deviation taken from the predict() function (sd =  
sqrt(n)*se). The
points obtained this way were scattered far too much (compared to  
points

obtained with simulate()) -- I am not quite sure why.

Unfortunately the documentation of the simulate() function does not  
provide
much information about how it is implemented, which makes it  
difficult to
judge which method is best (predict() or simulate(), and it is also  
unclear

whether simulate() can be applied to glms (with family=gaussian or
binomial).

Any suggestions for how to proceed?

Jacob


On 12 Aug 2009, at 13:11, Clifford Long wrote:


Would the "predict" routine (using 'newdata') do what you need?

Cliff Long
Hollister Incorporated



On Wed, Aug 12, 2009 at 4:33 AM, Jacob Nabe- 
Nielsen

wrote:


Dear List,

Does anyone know how to simulate data from a GLM object  
correponding

to values of the independent (x) variable that do not occur in the
original dataset?

I have tried using simulate(), but it generates a new value of the
dependent variable corresponding to each of the original x-values,
which is not what I need. Ideally I whould like to simulate new  
values
for GLM objects both with family="gaussian" and with  
family="binomial".


Thanks in advance,
Jacob

Jacob Nabe-Nielsen, PhD, MSc
Scientist
 --
Section for Climate Effects and System Modelling
Department of Arctic Environment
National Enviornmental Research Institute
Aarhus University
Frederiksborgvej 399, Postbox 358
4000 Roskilde, Denmark

email: n...@dmu.dk
fax: +45 4630 1914
phone: +45 4630 1944


  [[alternative HTML version deleted]]

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






__
R-help@r-project.org mailing list
ht

Re: [R] problem about t test

2009-08-13 Thread Moshe Olshansky
You could do the following:

y <- apply(dat,1,function(a) t.test(a[1:10],a[11:30])$p.value)

This will produce an array of 2 p-values.

--- On Fri, 14/8/09, Gina Liao  wrote:

> From: Gina Liao 
> Subject: [R] problem about t test
> To: r-h...@stat.math.ethz.ch
> Received: Friday, 14 August, 2009, 12:53 PM
> 
> Hello,
> I have a data frame >str(dat)'data.frame':  2
> obs. of 30 variables
> it contains two information-two types of cancers:stage A(A1
> to A10) and stage B(B1 to B20)  ##totally 30
> patients-2 sets of gene expression
> I'd like to find the lists for top 20 differentially
> expressed genes using t-test (by P-value).
> Here is my code, unfortunately it doesn't work...I need the
> help,please. I just learned R for two weeks, and hope you
> can give the hint!
> > A<-dat[,1:10] > B<-dat[,11:30]>
> bb<-function(t.test)+ { P.value.to.return <-
> t.test(A,B)$p.value+ return(P.value.to.return)+ }>
> aa<-t(apply(dat,1,bb))
> Thanks!!
> Best Regards,vie
> 
> 
> _
> 
> 
>     [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>

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


[R] problem about t test

2009-08-13 Thread Gina Liao

Hello,
I have a data frame >str(dat)'data.frame':  2 obs. of 30 variables
it contains two information-two types of cancers:stage A(A1 to A10) and stage 
B(B1 to B20)  ##totally 30 patients-2 sets of gene expression
I'd like to find the lists for top 20 differentially expressed genes using 
t-test (by P-value).
Here is my code, unfortunately it doesn't work...I need the help,please. I just 
learned R for two weeks, and hope you can give the hint!
> A<-dat[,1:10] > B<-dat[,11:30]> bb<-function(t.test)+ { P.value.to.return <- 
> t.test(A,B)$p.value+ return(P.value.to.return)+ }> aa<-t(apply(dat,1,bb))
Thanks!!
Best Regards,vie


_


[[alternative HTML version deleted]]

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


Re: [R] Plotting sigma symbol with unicode and turning into pdf

2009-08-13 Thread Paul Murrell

Hi


Jonathan R. Blaufuss wrote:

Paul, You solution worked out really well when I ran my code in R.
However, when I try to turn the plot into a pdf, the unicode string
no longer seems to function and instead of the sigma symbol there are
just two periods (See example code below).

The following is the code working in the R environment just like I
want it to look:

set.seed(1) 

> Data=rnorm(100,sd=1)
> plot(density(Data))
text(25000,0.4, 

> paste("\u03c3 = ",
>   format(round(sd(Data),digits=3),big.mark=",")),
>   font=2, col="blue")




Now when I try to turn the plot into a pdf, the sigma symbol no
longer appears. It is replaced by two periods.

pdf(file="C:/Rquestion.pdf")  

> ### Note: You can choose a place for this file to be saved
> set.seed(1)
> Data=rnorm(100,sd=1)
plot(density(Data)) 

> text(25000,0.4,
> paste("\u03c3 = ",
  format(round(sd(Data),digits=3),big.mark=",")), 

>   font=2, col="blue")

dev.off()


Is it possible to make the unicode string function when writing to a
pdf or do I need to form the sigma symbol some other way?



Here are a few suggestions (roughly in increasing order of complexity) ...

1.
The standard symbol font for PDF is actually quite "heavy", so you could 
try just doing the original plotmath approach.  Even though the sigma 
symbol is not bolded, it stands up reasonably well next to the bold 
digits (in PDF).


pdf(file="RquestionDefault.pdf")
set.seed(1)
Data=rnorm(100,sd=1)
plot(density(Data))
text(25000,0.3,
 bquote(bold(sigma==.(mySigma)),
list('mySigma'=format(round(sd(Data),digits=3),
  big.mark=","))),
 col='blue')
dev.off()

2.
The problem that you are seeing with the two dots in PDF is due to the 
fact that the (multibyte) Unicode sequence "\u03c3" has to be converted 
to a single byte "encoding" to be stored in the PDF file. 
Unfortunately, the default encoding (ISOLatin1) does not contain the 
'sigma' character, so the conversion fails (hence the dots).  You can 
specify an encoding that does contain the 'sigma' character, e.g., 
CP1253, but you also need to use a *font* that contains the 'sigma' 
character.  Here's an example of this solution that just uses the 
standard fonts that R knows about ...


pdfFonts(stdsym=Type1Font("standardsymbol",
   c("Helvetica.afm",
 "s05l.afm",
 "Helvetica-Oblique.afm",
 "Helvetica-BoldOblique.afm",
 "Symbol.afm"),
   encoding="CP1253"))

pdf("RquestionEncSym.pdf")
set.seed(1)
Data=rnorm(100,sd=1)
plot(density(Data))
text(25000,0.4,
paste("\u03c3 = ",
  format(round(sd(Data),digits=3),big.mark=",")),
family="stdsym", font=2, col="blue")
dev.off()

What this is doing is specifying a new font "family" that has the 
standard symbol font in the place where you would normally have the bold 
font.  Note that the encoding for this font is CP1253.  This new font 
family is then specified in the call to text(..., family="stdsym").


There are two unsatisfactory aspects to this solution:  the sigma symbol 
is still not bold (it is in fact just the same symbol as for solution 
1), PLUS the digits are now not bold either.  So this is not really a 
very good solution, but it demonstrates some of the ideas we need to get 
a better solution.


3.
The problem with the previous solution is that it used the standard 
symbol font for the entire piece of text that was being drawn (the sigma 
symbol and the digits).  If we go back to using plotmath expressions, we 
can improve on this because plotmath allows us to use different fonts 
for different parts of a single piece of text.  Here's a solution that 
demonstrates this approach ...


pdfFonts(stdsym=Type1Font("standardsymbol",
   c("Helvetica.afm",
 "Helvetica-Bold.afm",
 "s05l.afm",
 "Helvetica-BoldOblique.afm",
 "Symbol.afm"),
   encoding="CP1253"))

pdf("RquestionEncSym2.pdf")
set.seed(1)
Data=rnorm(100,sd=1)
plot(density(Data))
text(25000,0.3,
 bquote(bold(italic("\u03c3") == .(mySigma)),
list('mySigma'=format(round(sd(Data),digits=3),
  big.mark=","))),
 family="stdsym", col="blue")
dev.off()

The new font family is slightly different in this example (the standard 
symbol font is now in place of the italic font within the font family) 
and the major difference is the use of plotmath to draw the text.  In 
particular, the sigma symbol is being drawn with an italic font face, 
italic("\u03c3"), while the rest of the expression is bold.  This means 
that the digits remain bold while the sigma symbol comes from the 
standard symbol font.


Only problem is, the symbol character is STILL not bold.  But this 
example has demonstrated the ideas we need to propose a final possible 
solution.


4.
The extra step that we need, beyond the previous solution, is to make 

Re: [R] glm.nb versus glm estimation of theta.

2009-08-13 Thread Bill.Venables
Whoa!  Just hang on a minute.

theta is NOT the dispersion parameter.   Under the NB model, the variance of an 
observation is mu+mu^2/theta, so that's how theta enters the picture.  The 
smaller theta is the larger the variance.

glm(..., family = negative.binomial(theta = ), ...)  

will NOT estimate theta.  It will estimate a dispersion parameter, and if you 
get your  wrong, it could be a silly estimate.  One would hope the 
estimate of the dispersion parameter would be close to unity.

With your data try

mod2 <- glm(count ~ year + season + time + depth,
  family = negative.binomial(theta=mod$theta),link = "log",
  data = dat, control = glm.control(maxit=100, trace=T))

You should get the same estimates as you got with the negative binomial model 
(though standard errors, &c, will differ because you have cheated on that), and 
your dispersion parameter should be close to (though not necessarily equal to) 
unity.

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
hesicaia [dbo...@dal.ca]
Sent: 14 August 2009 04:31
To: r-help@r-project.org
Subject: [R]  glm.nb versus glm estimation of theta.

Hello,

I have a question regarding estimation of the dispersion parameter (theta)
for generalized linear models with the negative binomial error structure. As
I understand, there are two main methods to fit glm's using the nb error
structure in R: glm.nb() or glm() with the negative.binomial(theta) family.
Both functions are implemented through the MASS library. Fitting the model
using these two functions to the same data produces much different results
for me in terms of estimated theta and the coefficients, and I am not sure
why.

the following model:
mod<-glm.nb(count ~ year + season + time + depth,
link="log",data=dat,control=glm.control(maxit=100,trace=T))
estimates theta as 0.0109

while the following model:
mod2<-glm(count ~ year + season + time + depth,
family=negative.binomial(theta=100),link="log",data=dat,control=glm.control(maxit=100,trace=T))
will not accept 0.0109 as theta and instead estimates it as 1271 (these are
fisheries catch data and so are very overdispersed).

Fitting a quasipoisson model also yields a large dispersion parameter
(1300). The models also produce different coefficients and P-values, which
is disconcerting.

What am I doing wrong here? I've read through the help sections
(?negative.binomial,?glm.nb, and ?glm) but did not find any answers.

Any help and/or input is greatly appreciated!
Daniel.
--
View this message in context: 
http://www.nabble.com/glm.nb-versus-glm-estimation-of-theta.-tp24956438p24956438.html
Sent from the R help mailing list archive at Nabble.com.

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

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


Re: [R] Coding problem: How can I extract substring of function callwithin the function

2009-08-13 Thread Steve Lianoglou

Hi Joel,

On Aug 13, 2009, at 6:10 PM, Pitt, Joel wrote:

Your objections are quite cogent, but I believe they are  
misdirected. I'm not at all interested in having my students ignore  
the existence of NA's and that's precisely why I'm not using the  
Default package as someone else suggested. But the mere existence of  
missing values in a data set doesn't make computation of the mean  
entirely useless -- why else would the na.rm option be available.


I agree: it's certainly not useless to calc the mean of a series of  
numbers while ignoring NA's.


If a student using my version of mean uses it to find the mean of a  
variable that has missing values, the function first prints a  
warning message and only then returns a value. Here's an example


> length(x)
[1] 101
> mean(x)
Warning: x has 3 missing values.
[1] 51.69388


Looks nice.

My only goal in this project has been to provide them with a  
somewhat friendlyR version of R. It was not conceived as part of a  
quest to improve my programming proficiency


I didn't think you were pursuing this to improve your programming  
proficiency from the outset, I just wanted to point out that you found  
a situation which you wanted to work around for (i) your precise use  
case. But it was because you were trying to solve (i) that you  
stumbled on (ii) and wanted to just know how one might do this for  
curiosity's sake and increase your proficiency (perhaps for some other  
use case in the future).


It was simply for reason (ii) that prompted me to say something only  
because you might not have seen your approach as potentially  
handicapping your students' (maybe subconcious(?)) pursuit of  
proficiency. I just wanted to point out that this is what you *might*  
be doing in the short term. Then again, it might not be.


Everyone has their own style of teaching, and it's your prerogative to  
do it as you see fit. I wouldn't presume to know which way is best, so  
good luck with the upcoming semester :-)


-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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


Re: [R] joining two points in rgl

2009-08-13 Thread Duncan Murdoch

Nair, Murlidharan T wrote:

Hi!!

I need to draw a cylinder/tube joining two points. I am trying to make something presentable, I have been able to do it using lines3d. But is it possible to 
increase the thickness of the lines? The size parameter does not work. Does any one have any suggestions?
  
There's a new function cylinder3d  (in rgl 0.85) that probably does 
exactly what you want, but lwd is the parameter that controls line width.


Duncan Murdoch

Thanks ../Murli

library(rgl)
pts<-structure(list(x = c(-0.975688, -0.975688), y = c(9.258795, -9.258795
), z = c(-1.8, 1.8)), .Names = c("x", "y", "z"), class = "data.frame", 
row.names = c(NA,
-2L))

plot3d(pts$x,pts$y,pts$z, col="grey", size=2, box=FALSE, axes=FALSE, type="s")
lines3d(pts$x,pts$y,pts$z, col="grey", size=2)

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



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


Re: [R] Browser and Debug?

2009-08-13 Thread Duncan Murdoch

rkevinbur...@charter.net wrote:

If I am on Windows and don't have GDB it does'nt look like it is possible. Any 
tips?
  


For debugging without a debugger, you can always use the old-fashioned 
method of inserting print statements (Rprintf in C).  But you want to do 
this without a debugger *and* without a compiler.  I think you are 
indeed asking for more than can be reasonably expected.


If you want to relax the constraints a little, you might use some of the 
methods described on


http://www.stats.uwo.ca/faculty/murdoch/software/debuggingR/

I haven't updated it in a while, but I don't think there's much that has 
changed (other than REvolution's IDE, which I haven't had a chance to 
try yet).


Duncan Murdoch

Kevin
 roger koenker  wrote: 
  

At points of total desperation you can always consider
the time-honored, avuncular advice  --  RTFM,
in this case Section 4.4 of Writing R Extensions.


url:www.econ.uiuc.edu/~rogerRoger Koenker
emailrkoen...@uiuc.eduDepartment of Economics
vox: 217-333-4558University of Illinois
fax:   217-244-6678Urbana, IL 61801



On Aug 13, 2009, at 10:20 AM,  wrote:


This may be asking more than can be reasonably expected. But, any  
tips on debugging the 'C' and Fortran code without trying to put  
together all the tools to compile from source?


Kevin

 Erik Iverson  wrote:
  

This article might help:

http://www.biostat.jhsph.edu/~rpeng/docs/R-debug-tools.pdf

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org 
] On Behalf Of Inchallah Yarab

Sent: Thursday, August 13, 2009 9:40 AM
To: r-help@r-project.org
Subject: [R] Browser and Debug?

Hi,

Someone can explain to me how use Browser and Debug ?
thank you



[[alternative HTML version deleted]]

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

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


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


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



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 3-D surface graph from lmer mixed models?

2009-08-13 Thread Duncan Murdoch

willow1980 wrote:

Dear Professor Murdoch,
That is exactly the difficulty for me. I don't know how to make a prediction
with lmer using "expand.grid"; at the moment, I can use
“mo...@x%*%fixef(model)” to get predicted values for existing observational
data, but not data by "expand.grid". Actually, if I know this, I can then
use "persp" or "wireframe" to plot 3-D surface graph. Do you know or have
available code for this aim?
  


No, I've never used lmer. 


Duncan Murdoch

Sorry, this request must sound very lazy or stupid.
Thank you very much for helping!
Best regards,



Duncan Murdoch-2 wrote:
  
I only see two explanatory variables:  afr_c, byear_c.  If you have more 
than two, you can't use a surface plot:  surfaces are two dimensional.


All of the 3D surface functions want basically the same thing:  a matrix 
giving evaluations of a function at locations of the explanatory 
variables.  So you need to calculate that.  I'd do it by using 
expand.grid to create a large set of combinations of values of the 
explanatory variables, ask your model to do predictions at all of those 
locations, and then reshape the result into a matrix.


Duncan Murdoch

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








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


Re: [R] glm.nb versus glm estimation of theta.

2009-08-13 Thread Achim Zeileis

On Thu, 13 Aug 2009, hesicaia wrote:



Hello,

I have a question regarding estimation of the dispersion parameter (theta)
for generalized linear models with the negative binomial error structure. As


The theta is different from the dispersion. In the usual GLM notation:
E[y] = mu
  VAR[y] = dispersion * V(mu)

The function V() depends on the family and is
  Poisson: V(mu) = mu
  NB:  V(mu) = mu + 1/theta * mu^2

For both models, dispersion is known to be 1 (from the likelihood). 
However, a quasi-Poisson approach can be adopted where dispersion is 
estimated (but does not correspond to a specific likelihood).


Thus, dispersion and theta are really different things although both of 
them can be used to capture overdispersion.



I understand, there are two main methods to fit glm's using the nb error
structure in R: glm.nb() or glm() with the negative.binomial(theta) family.
Both functions are implemented through the MASS library. Fitting the model
using these two functions to the same data produces much different results
for me in terms of estimated theta and the coefficients, and I am not sure
why.


...because you tell them to do different things.


the following model:
mod<-glm.nb(count ~ year + season + time + depth,
link="log",data=dat,control=glm.control(maxit=100,trace=T))
estimates theta as 0.0109


This approach estimates theta (= 0.0109) and assumes that dispersion is 
known to be 1. The underlying estimated variance function is:

  VAR[y] = mu + 91.74312 * mu^2


while the following model:
mod2<-glm(count ~ year + season + time + depth,
family=negative.binomial(theta=100),link="log",data=dat,control=glm.control(maxit=100,trace=T))
will not accept 0.0109 as theta and instead estimates it as 1271 (these are
fisheries catch data and so are very overdispersed).


This does not estimate theta at all but keeps it fixed (= 100). By 
default, however, dispersion will be estimated by the summary() method, 
presumably leading to the value of 1271 you report. The underlying 
variance function would then be

  VAR[y] = 1271 * mu + 12.71 * mu^2


Fitting a quasipoisson model also yields a large dispersion parameter
(1300). The models also produce different coefficients and P-values, which
is disconcerting.


This implies yet another variance function, namely
  VAR[y] = 1300 * mu

If you want to get essentially the same result as
  summary(mod)
from using glm+negative.binomial you can do
  mod0 <- glm(count ~ year + season + time + depth, data = dat,
family = negative.binomial(theta = mod$theta),
control = glm.control(maxit = 100))
  summary(mod0, dispersion = 1)
(Note that link = "log" is not needed.)


What am I doing wrong here? I've read through the help sections
(?negative.binomial,?glm.nb, and ?glm) but did not find any answers.


I guess the authors of the "MASS" package would say that the software 
accompanies a book which should be consulted...and they would be right.
Reading the corresponding sections in MASS (the book) will surely be 
helpful. Consulting McCullagh & Nelder about some general GLM theory can't 
hurt either. Finally, some extended modeling (including excess zeros) is 
available in

  http://www.jstatsoft.org/v27/i08/
(Apologies for advertising this twice on the same day.)

hth,
Z


Any help and/or input is greatly appreciated!
Daniel.
--
View this message in context: 
http://www.nabble.com/glm.nb-versus-glm-estimation-of-theta.-tp24956438p24956438.html
Sent from the R help mailing list archive at Nabble.com.

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




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


Re: [R] Coding problem: How can I extract substring of function call within the function

2009-08-13 Thread Pitt, Joel
Hi,
 
As I said in my original email, I'm sure that many of you will doubt the wisdom 
of what I'm trying to do -- and I certainly share some of your misgivings. I 
have misgivings too about the use of "training wheels" for bicycles, but they 
are clearly useful for some people, and, in this instance, I think that 
smoothing students passage over what I have seen to be genuine stumbling blocks 
for them outweighs the drawbacks. I am not merely changing defaults -- if that 
was all I believe I would be doing students a disservice. My version of mean 
doesn't merely return a value in the presence of missing values, it prints a 
warning if missing values are pressent. I think the one step with my version
 
> mean(x)   # my version
Warning: x has 3 missing values.
[1] 51.69388
> base::mean(x)  
[1] NA
> length(x[is.na(x)])# oops, some missing values, I wonder 
> how many?
[1] 3  # not too bad, let's look find 
the mean without them
> base::mean(x,na.rm=T)
[1] 51.69388

It has some other useful features which I needn't go into here.
 
I have not yet used this package but plan to use it in my classes this fall, 
and I thought about using alternate names for my function versions (Mean vs. 
mean, Table vs. table, Hist vs. hist -- John Fox does that in his Rcmdr) but 
decided against it. I believe that by carefully explaining the difference 
between the versions in my package and the standard versions students will be 
able to adjust to using the standard version if and when they need or choose 
to. 
 
I have considerable experience using R in both introductory and moderately 
advanced classes, and despite my enthusiasm for it have had at best very mixed 
success. I am certainly not unique in belief that by making initial exposure to 
R fit more closely to student needs we will create more real R users in the 
long run. Clearly the several different versions of menu-driven front ends have 
the same goal. Since I believe the R console is the right environment for 
exploratory data analysis I prefer to avoid the menu driven detour.
 
Regards,
Joel
 
 



From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com]
Sent: Thu 8/13/2009 5:19 PM
To: Pitt, Joel
Cc: r-help@r-project.org
Subject: Re: [R] Coding problem: How can I extract substring of function call 
within the function



The Defaults package can be used to change the defaults of
functions and reset them back.

There is some question on whether all this is advisable.
It will invalidate any books, documentation, examples
in the help files that come with R and other
resources on R that they might have otherwise used
by introducing deliberate differences.  Later, to learn
standard R it will be harder since they will have to
unlearn what they learned.

If you really must do this I would suggest
using different names, e.g. mean2 or Mean,
so its clear one is using non-standard versions.
In that case you don't need rStd in the first place.

Even better, perhaps a one page cheat sheet of
common forms would be better than a package
full of trivially and annoyingly changed functions, e.g.

mean(x, na.rm = TRUE)  # mean of non-missings in x
barplot(x, beside = TRUE) # bar chart placing bars beside each other

On Thu, Aug 13, 2009 at 4:48 PM, Pitt, Joel wrote:
> In order to ease my students into the R environment I am developing a package 
> which installs a variety of utility functions as well as slightly modified 
> versions of some standard R functions -- e.g. mean, hist, barplot,  In my 
> versions of these standard R functions I either add options or alter some 
> defaults that seem to create difficulties for most of my students -- for 
> example, when they do barcharts for two dimensional tables they generally 
> want the bars to be side-by-side and stumble over the standard default of 
> besides=F, and my version of mean by default reports a mean value in the 
> presence of NA's after warning of that presence (but retains the option of 
> setting na.rm=F). (I don't doubt that some (if not many) of you will doubt 
> the wisdom of this, and I would be happy to discuss this in more detail on 
> other occasions.) You might want to think of my replacement R functions as a 
> kind of "training wheels" for R, and, in the spirit of training wheels I 
> include a fun!
 ct!
>  ion in my package that allows a user to revert to the standard version of 
> one or all functions without unloading the package (and loosing its 
> additional functionality). However, I want to add a function that allows a 
> user to revert to running the standard R version of a given function on a 
> one-off basis and that's where my problem comes up.
>
> I believe that it should be possible to write a function rStd with the usage 
> rStd(x,...) where x is a function -- e.g. mean, hist, barchart, and the 
> remaining parameters would be any of the param

Re: [R] shading between two smoothed curves

2009-08-13 Thread Debabrata Midya
Hi Gregory,
 
> I can plot out two nice curves using the following code, but I can't
figure out how to shade in the area lying between the two curves. 
 
Use polygon.
 
> ?polygon

>>> "Graves, Gregory"  14/08/2009 4:17 am >>>
I have a set of 52 weekly values, one is the desired high lake stage for
a week, and the other is the desired low lake stage for each week.  It
looks like this:



week

High

Low

1

16

14.5

2

16

14.5

3

15.95

14.45

4

15.84

14.34

5

15.73

14.23

6

15.61

14.11

7

15.5

14

8

15.38

13.88

9

15.25

13.75

10

15.13

13.63




52

15

13.5



I can plot out two nice curves using the following code, but I can't
figure out how to shade in the area lying between the two curves.  I
also can't figure out how to adjust the line weight as lwd doesn't seem
to affect scatter.smooth.  Thanks in advance.



l=11  #lower ylim

h=17  #upper ylim

par(new=F)

good <- complete.cases(week, high) #get rid of the NA error and only
using non-missing pairs

par(new=T)

scatter.smooth(week[good], high[good],family = "gaussian",span = .2,
ylim=c(l,h), type='n', lwd=2, color="blue", ylab="", xlab="")  

good <- complete.cases(week, low) 

par(new=T)

scatter.smooth(week[good], low[good],family = "gaussian",span = .2,
ylim=c(l,h), type='n', lwd=2, color="red", ylab="Stage, feet",
xlab="Week of Year")  #loess, lower span makes more irregular

par(new=F)



Gregory A. Graves

Lead Scientist

Everglades REstoration COoordination and VERification (RECOVER) 

Watershed Division

South Florida Water Management District

Phones:  DESK: 561 / 682 - 2429 

 CELL:  561 / 719 - 8157

 




[[alternative HTML version deleted]]

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


**

This email message, including any attached files, is confidential and
intended solely for the use of the individual or entity to whom it is
addressed. 

The NSW Department of Commerce prohibits the right to publish, 
copy, distribute or disclose any information contained in this email, 
or its attachments, by any party other than the intended recipient. 
If you have received this email in error please notify the sender and
delete it from your system.

No employee or agent is authorised to conclude any binding 
agreement on behalf of the NSW Department of Commerce by email. The
views or opinions presented in this email are solely those of the author
and do not necessarily represent those of the Department, 
except where the sender expressly, and with authority, states them to be
the views of NSW Department of Commerce.  

The NSW Department of Commerce accepts no liability for any loss or
damage arising from the use of this email and recommends that the
recipient check this email and any attached files for the presence of
viruses. 

**

[[alternative HTML version deleted]]

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


Re: [R] How to rename columns that start with numbers?

2009-08-13 Thread John Kane
Something like this. Create empty vector of correct length, paste values into 
it and then use names(mydata) <- myvector.

x  <- data.frame(aa=1:10, bb=letters[1:10])

myvector <- c(rep(NA,length(x)))
for (i in 1:length(names(x))) {
   myvector[i] <- paste("SURV_",i, sep="")
   }


--- On Thu, 8/13/09, Mark Na  wrote:

> From: Mark Na 
> Subject: [R] How to rename columns that start with numbers?
> To: r-help@r-project.org
> Received: Thursday, August 13, 2009, 6:24 PM
> Hello,
> 
> My dataframe has new columns that start with the number 1
> or 2 (resulting
> from a reshape cast command).
> 
> Instead of having these columns automatically renamed by R
> so start with the
> letter X, I would like to rename these columns to start
> with the characters
> "SURV_" (e.g., SURV_1, SURV_2).
> 
> I can't seen to use grep() to identify and rename the
> columns starting with
> either 1 or 2.
> 
> Any help would be much appreciated, thanks!
> 
> (I know I could rename these manually, but the above is a
> simpler statement
> of the actual problem, which involves several dozen
> columns, so that's why
> I'd prefer not to so it manually)
> 
> Mark Na
> 
>     [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
> 


  __
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your 
favourite sites. Download it now
http://ca.toolbar.yahoo.com.

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


Re: [R] R: how to get R interpreter to remember constant values without using any memory location

2009-08-13 Thread Don MacQueen
You can add or remove elements from a list without affecting the 
other elements. It is not necessary to update the list names when 
adding or removing elements.

Since list elements can be referred to by name, you don't have to 
worry about numbering them, or renumbering them, nor do you have to 
keep track of their index numbers if you don't want to.

Example:

>info <- list(a=1, b=2, c=3.4, d=75)

>  info$d
[1] 75
>  info[[4]]
[1] 75

>info <- c( info, list(q=3))

>  info$d
[1] 75
>  info[[4]]
[1] 75

>info <- info[ names(info) != 'c']

>  info$d
[1] 75
>  info[[4]]
[1] 3

Note that updating the names was not required. The position of the 
element named "d" changed, but not its name or value.

-Don

At 10:28 PM +0200 8/13/09,  wrote:
>Thank you for all your suggestiona.
>I tried to write a self-contained example which turned oiut to 
>confuse people's miind.
>I realized also the formulation of my question was unclear. Sorry for that.
>
>What I had in mind was something similar to Fortran Parameter declaration.
>I spent some time dealing with Monte Carlo codes for radiation 
>trasport. In this particular
>research filed it's pretty common to come across Fortran code, like it or not.
>For example, through Fortran Parameter declaration, I can assign a 
>name to a big floating-point number,
>something like  Parameter( A = 123E-15) without having the compiler 
>to allocate 32 (REAL data type)
>or 64 (DOUBLE data type) consecutive memory locations to accommodate 
>such a number.
>Of course the computer must save any constant data somewhere but 
>neglecting its data type,
>therefore saving memory space.
>
>In my R script I have to deal with a dynamically varying list of 
>references. Something simiilar to
>what LaTeX interpreter does when we use it to write a manuscript. 
>That is, we do not have to
>renumber the bibliography references list whenever we insert a  new 
>citation into, or remove an existing one
>from our manuscript. LaTeX takes care of that. We just cite 
>references through labels taht LaTeX translates into a dynamically
>ordered list of numbers.
>So, factors may work fine for me.
>Another possibility that downed on me may be to name the list 
>elements, although I
>will have to update the list names every time the list is updaed.
>
>Thank you again,
>Maura
>
>
>-Messaggio originale-
>Da: Don MacQueen [mailto:m...@llnl.gov]
>Inviato: gio 13/08/2009 21.17
>A: mau...@alice.it; r-h...@stat.math.ethz.ch
>Oggetto: Re: [R] how to get R interpreter to remember constant 
>values without   using any memory location
>
>Like Ben, I wonder what the reason for doing this is.
>
>First of all, the amount of memory indicated by your example is so
>small I can't imagine it would make any difference. If you have such
>a large number of values that the amount of memory is significant --
>and store them somewhere that isn't in memory (such as physical disk
>memory), then reading them into memory when you need to use them
>might affect performance a lot.
>
>Environment variables use memory also -- it's just someone else's
>memory (the OS instead of R).
>
>-Don
>
>At 4:05 PM +0200 8/13/09,  wrote:
>>Maybe I expect too much from a non compiled language.
>>Anyway, I wonder whether it is possible in R to set constant values
>>without using any memory location that would take useless space
>>bacause such values are not going to be changed along the program.
>>It's just a way to assign a mnemnic name tos some constant values.
>>For instance, I would like R interpreter to replace all occurrences
>>of mnemonic "Monday" with the number 1, "Tuesday"  with the number
>>2, "Wednesday  with the number 3, and so on ...  without having to
>>assign such values to memory locations.
>>Maybe environment variables are the way to go ?
>>
>>Thank you in advance for your advice,
>>Maura
>>
>>
>>
>>
>>tutti i telefonini TIM!
>>
>>
>>[[alternative HTML version deleted]]
>  >
>>__
>>R-help@r-project.org mailing list
>>https://**stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide 
>>http://**www.**R-project.org/posting-guide.html
>>and provide commented, minimal, self-contained, reproducible code.
>
>
>--
>--
>Don MacQueen
>Environmental Protection Department
>Lawrence Livermore National Laboratory
>Livermore, CA, USA
>925-423-1062
>--
>
>
>
>Alice Messenger ;-) chatti anche con gli amici di Windows Live 
>Messenger e tutti i telefonini TIM!
>Vai su 
>http://*maileservizi.alice.it/alice_messenger/index.html?pmk=footer


-- 
--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062

[R] How to rename columns that start with numbers?

2009-08-13 Thread Mark Na
Hello,

My dataframe has new columns that start with the number 1 or 2 (resulting
from a reshape cast command).

Instead of having these columns automatically renamed by R so start with the
letter X, I would like to rename these columns to start with the characters
"SURV_" (e.g., SURV_1, SURV_2).

I can't seen to use grep() to identify and rename the columns starting with
either 1 or 2.

Any help would be much appreciated, thanks!

(I know I could rename these manually, but the above is a simpler statement
of the actual problem, which involves several dozen columns, so that's why
I'd prefer not to so it manually)

Mark Na

[[alternative HTML version deleted]]

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


Re: [R] R code to reproduce (while studying) Bates & Watts 1988

2009-08-13 Thread Kevin Wright
library(nlme)
m2 <- gnls(conc  ~ t1*(1-t2*exp(-k*time)),
   data  = df.Chloride,
   start =  list(
 t1 = 35,
 t2 = 0.91,
 k = 0.22))
summary(m2)
plot(m2)
lag.plot(resid(m2), do.lines=FALSE)
acf(resid(m2))

m3 <- update(m2, corr=corAR1(.67))
summary(m3)
plot(m3)
lag.plot(resid(m3), do.lines=FALSE)
acf(resid(m3))

The residual plots for model m3 still show structure, unlike in Bates &
Watts, so maybe this is not the correct model?

Kevin



On Thu, Aug 13, 2009 at 6:11 AM, Ottorino-Luca Pantani <
ottorino-luca.pant...@unifi.it> wrote:

> Hi R users,
> I'm here trying to understand correlated residuals in nonlinear estimation.
>
> I'm reading/studying the book  Bates, D. M. and D. G. Watts, (1988),
> /Nonlinear regression analysis and its applications/, Wiley, NY. pages
> 92-94, trying to reproduce the figures and to find out the code in R to
> perform the necessary calculations.
> I also consulted Pinheiro and Bates, but without success
>
> Here below you'll find are my efforts.
> I'm in trouble at plotting the lag plot (fig 3.6 b) and in fitting the new
> model with autocorrelated residuals (most probably misusing "correlation =
> corAR1()" in updating a nls model).
>
> Could someone be so kind to help me ?
>
> Thanks a lot
> Ottorino
>
> "df.Chloride"<-
> structure(.Data = list(time = c(2.45, 2.55, 2.65, 2.75, 2.85, 2.95, 3.05,
> 3.15,
>   3.25, 3.35, 3.45, 3.55, 3.65, 3.75, 3.85, 3.95, 4.05, 4.15, 4.25, 4.35,
>   4.45, 4.55, 4.65, 4.75, 4.85, 4.95, 5.05, 5.15, 5.25, 5.35, 5.45, 5.55,
>   5.65, 5.75, 5.85, 5.95, 6.05, 6.15, 6.25, 6.35, 6.45, 6.55, 6.65, 6.75,
>   6.85, 6.95, 7.05, 7.15, 7.25, 7.35, 7.45, 7.55, 7.65, 7.75), conc = c(
>   17.3, 17.6, 17.9, 18.3, 18.5, 18.9, 19, 19.3, 19.8, 19.9, 20.2, 20.5,
>   20.6, 21.1, 21.5, 21.9, 22, 22.3, 22.6, 22.8, 23, 23.2, 23.4, 23.7,
>   24, 24.2, 24.5, 25, 25.4, 25.5, 25.9, 25.9, 26.3, 26.2, 26.5, 26.5,
>   26.6, 27, 27, 27, 27, 27.3, 27.8, 28.1, 28.1, 28.1, 28.4, 28.6, 29,
>   29.2, 29.3, 29.4, 29.4, 29.4)), row.names = c("1", "2", "3", "4", "5",
>   "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17",
>   "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
>   "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41",
>   "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53",
>   "54"), class = "data.frame", reference = "A1.9, p. 274")
>
> ##Figure 3.5,  pag 92
> plot(df.Chloride$time,  df.Chloride$conc,  pch  = 20)
>
> ## fitting the model
> nls.1 <- nls(conc  ~ t1*(1-t2*exp(-k*time)),
>data  = df.Chloride,
>start =  list(
>  t1 = 35,
>  t2 = 0.91,
>  k = 0.22))
>
> ##Figure 3.56a,   pag 93
> plot(nls.1,  pch  = 20)
>
> ##Figure 3.56b,   pag 93
> ???not the foggiest idea
>
> ##Figure 3.57,   pag 94
> acf(resid(nls.1),  xlim = c(1, 15),  lab = c(5, 4,  7))
>
> ##Try to fit a model with autocorrelated residues (Problems !!)
> nls.2 <- update(nls.1,  corr = corAR1(0.67))
>
> --
> Ottorino-Luca Pantani, Università di Firenze
> Dip. Scienza del Suolo e Nutrizione della Pianta
> P.zle Cascine 28 50144 Firenze Italia
> Tel 39 055 3288 202 (348 lab) Fax 39 055 333 273 olpant...@unifi.it
> http://www4.unifi.it/dssnp/
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] Coding problem: How can I extract substring of function callwithin the function

2009-08-13 Thread Pitt, Joel
Your objections are quite cogent, but I believe they are misdirected. I'm not 
at all interested in having my students ignore the existence of NA's and that's 
precisely why I'm not using the Default package as someone else suggested. But 
the mere existence of missing values in a data set doesn't make computation of 
the mean entirely useless -- why else would the na.rm option be available. If a 
student using my version of mean uses it to find the mean of a variable that 
has missing values, the function first prints a warning message and only then 
returns a value. Here's an example
 
> length(x)
[1] 101
> mean(x)
Warning: x has 3 missing values.
[1] 51.69388

My only goal in this project has been to provide them with a somewhat friendlyR 
version of R. It was not conceived as part of a quest to improve my programming 
proficiency, but my curiousity can be piqued when I run up against a 
programming problem.
 
Joel
 
 
 



From: Steve Lianoglou [mailto:mailinglist.honey...@gmail.com]
Sent: Thu 8/13/2009 5:55 PM
To: Pitt, Joel
Cc: Erik Iverson; r-help@r-project.org
Subject: Re: [R] Coding problem: How can I extract substring of function 
callwithin the function



Hi,

On Aug 13, 2009, at 5:30 PM, Pitt, Joel wrote:

> Thanks. It's a great solution to part of my problem. It provides the 
> functionally I want would be no harder for students to use than my 
> approach. I'm still interested in how to make what I was trying to 
> do work -- simply to add to my own R programming proficiency.

I wasn't going to really chime in, but I couldn't help it given the 
irony in your last sentence (sorry, I don't mean to sound like an ass).

I think trying to help your students with some "bumps on the road" is 
admirable, but this seems just a bit misdirected. As you say, you are 
on a quest to add to your R programming proficiency, and will apply 
this newly founded technique to actively handicap your students' 
proficiency.

I guess you're teaching some intro stat analysis class, and waving 
over the fact that functions like mean explicitly return NA in the 
presence of NA's, but this is important to know and recognize when 
analyzing any real data, because there will surely be NA's "in the 
wild." Knowing that you should consciously and deliberately deal with/
ignore them from the start might be a good first/early lesson for 
students to digest.

Like I said, I don't mean to sound like an ass, but I think glossing 
over details of working with data should be avoided. Your other 
additions, like adding options to plotting/graphing functions, seem 
less harmful to me. But if you're trampling over some base:: function 
for something trivial like changing the value of one default parameter 
to something else, you might as well just get them to learn how to use 
the ? asap as well.

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
   |  Memorial Sloan-Kettering Cancer Center
   |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact




[[alternative HTML version deleted]]

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


Re: [R] using package tm to find phrases

2009-08-13 Thread Ingo Feinerer
On Thu, Aug 13, 2009 at 03:36:22PM -0400, Mark Kimpel wrote:
> I am using the package "tm" for text-mining of abstracts and would like to use
> it to find instances of gene names that may contain white space. For instance
> "gene regulatory protein 1". The default behavior of tm is to parse this into 
> 4
> separate words, but I would like to use the class constructor "dictionary" to
> define phrases such as just mentioned.
> 
> Is this possible? If so, how?

Yes.

* In case you only need to find instances, you could use full text
  search on your corpus, e.g.

  R> tmIndex(yourCorpus, "gene regulatory protein 1")

  would return the indices of all documents in your corpus containing
  this phrase.

* If you need tokens (in a term-document matrix) of length 4, you could
  use a n-gram tokenizer (n = 4). See e.g.,
  http://tm.r-forge.r-project.org/faq.html#Bigrams. Then you can use
  the dictionary argument to store only your selection of gene
  names. I.e., something like

  R> yourTokenizer <- function(x) RWeka::NGramTokenizer(x, Weka_control(min = 
4, max = 4))
  R> TermDocumentMatrix(crude, control = list(tokenize = yourTokenizer, 
dictionary = yourDictionary))

  where yourDictionary contains the gene names (a character vector
  suffices) to be included in the term-document matrix.

* If you want to extract arbitrary patterns of different length that
  could match some gene names (and build a dictionary from that), you
  need some custom functionality. Regular expressions might be a good
  starting point ...

Best regards, Ingo

-- 
Ingo Feinerer
Vienna University of Technology
http://www.dbai.tuwien.ac.at/staff/feinerer

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


Re: [R] lm coefficients output confusing

2009-08-13 Thread Daniel Malter
I have answered a similar question just hours ago. Your question either
indicates an unfamiliarity with R or, more generally, an unfamiliarity with
regression analysis, or both.

Your anova indicates that the overall model is significant. That is, your
model is an improvement over the null model with just an intercept.  Thus,
the anova output tells you that there are significant differences between
the HR groups. This is also indicated by the F-test and p-value for the
F-test in the second model output (the summary.lm).

The question why R does not show HR2 or not just only HR indicates the lack
of understanding of R or regression. The fact that there are seven
coefficient estimates for HR3 through HR8 indicates that the HR variable is
coded as a factor. Consequently, R estimates the model using dummy variables
for each level of HR, except for the baseline, which is coded zero (this is
basically an analysis of variance, not of covariance). By standard, the
baseline is the smallest value (or lowest in alphabetical order) of a
factor-coded variable, which is HR=2 in your case. Since it is the baseline,
there is no estimate for a coefficient for HR2. All other estimated
coefficients compare the effect of HR=3 through HR8 relative to the group in
which HR=2.

If you want to include HR as a numeric variable in the regression (=
analysis of covariance), you have to code it as.numeric. Note, however, that
your results for the factor-coded HR variable indicate that the trend (if
any) is not linear.

For a comparison of all groups against one another from an analysis of
variance, I think there other methods, like the Bonferroni-Dunn test (as a
post-hoc test).

Best,
Daniel

-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
Auftrag von Ross Culloch
Gesendet: Thursday, August 13, 2009 4:46 PM
An: r-help@r-project.org
Betreff: [R] lm coefficients output confusing


Hi all,

I have an issue with the lm() function regarding the listing of the
coefficients. My data are below, showing a list of hours (HR) relating to
the time spent resting (R) by an individual animal. Simply i want to run a
lm() to run in an anova() to see if there is a significant difference in
resting between hours. 

   HR R
1   2 0.667
2   2 0.467
3   2 0.800
4   2 0.633
5   2 0.733
6   2 0.800
7   2 0.867
8   2 0.7857143
9   2 0.7826087
10  2 0.667
11  2 0.917
12  2 0.667
13  3 0.5294118
14  3 0.8541667
15  3 0.458
16  3 0.5882353
17  3 0.9347826
18  3 0.7878788
19  3 0.7857143
20  3 0.694
21  3 0.833
22  3 0.7450980
23  3 0.9230769
24  3 0.722
25  4 0.6571429
26  4 0.7241379
27  4 0.7391304
28  4 0.6571429
29  4 0.800
30  4 0.9130435
31  4 0.7187500
32  4 0.8437500
33  4 0.9230769
34  4 0.8571429
35  4 0.8695652
36  4 0.889
37  5 0.333
38  5 0.5365854
39  5 0.6774194
40  5 0.7142857
41  5 0.6904762
42  5 0.5483871
43  5 0.5952381
44  5 0.417
45  5 0.567
46  5 0.5952381
47  5 0.7894737
48  5 0.750
49  6 0.6268657
50  6 0.7187500
51  6 0.550
52  6 0.7164179
53  6 0.7656250
54  6 0.5869565
55  6 0.7164179
56  6 0.7031250
57  6 0.7230769
58  6 0.7462687
59  6 0.920
60  6 0.8536585
61  7 0.6379310
62  7 0.5357143
63  7 0.5227273
64  7 0.800
65  7 0.6724138
66  7 0.708
67  7 0.7241379
68  7 0.6938776
69  7 0.6545455
70  7 0.7931034
71  7 0.7560976
72  7 0.8684211
73  8 0.6727273
74  8 0.600
75  8 0.833
76  8 0.8181818
77  8 0.7818182
78  8 0.7647059
79  8 0.5818182
80  8 0.5918367
81  8 0.7450980
82  8 0.7818182
83  8 0.8048780
84  8 0.8684211


The script i'm using and output is as follows:

> anova(rdayml <- lm(R ~ HR, data=rdata2, na.action=na.exclude))
Analysis of Variance Table

Response: R
  Df  Sum Sq Mean Sq F value  Pr(>F)   
HR 6 0.25992 0.04332  3.1762 0.00774 **
Residuals 77 1.05021 0.01364   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
> 
> summary(rdayml <- lm(R ~ HR,data=rdata2))

Call:
lm(formula = R ~ HR, data = rdata2)

Residuals:
  Min1QMedian3Q   Max 
-0.279725 -0.065416  0.005593  0.077486  0.201070 

Coefficients:
 Estimate Std. Error t value Pr(>|t|)
(Intercept)  0.732082   0.033713  21.715   <2e-16 ***
HR3  0.005976   0.047678   0.125   0.9006
HR4  0.067232   0.047678   1.410   0.1625
HR5 -0.130935   0.047678  -2.746   0.0075 ** 
HR6 -0.013152   0.047678  -0.276   0.7834
HR7 -0.034807   0.047678  -0.730   0.4676
HR8  0.004971   0.047678   0.104   0.9172
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.1168 on 77 degrees of freedom
Multiple R-squared: 0.1984, Adjusted R-squared: 0.1359 
F-statistic: 3.176 on 6 and 77 DF,  p-value: 0.00774 


What i really don't understand

Re: [R] Coding problem: How can I extract substring of function callwithin the function

2009-08-13 Thread Steve Lianoglou

Hi,

On Aug 13, 2009, at 5:30 PM, Pitt, Joel wrote:

Thanks. It's a great solution to part of my problem. It provides the  
functionally I want would be no harder for students to use than my  
approach. I'm still interested in how to make what I was trying to  
do work -- simply to add to my own R programming proficiency.


I wasn't going to really chime in, but I couldn't help it given the  
irony in your last sentence (sorry, I don't mean to sound like an ass).


I think trying to help your students with some "bumps on the road" is  
admirable, but this seems just a bit misdirected. As you say, you are  
on a quest to add to your R programming proficiency, and will apply  
this newly founded technique to actively handicap your students'  
proficiency.


I guess you're teaching some intro stat analysis class, and waving  
over the fact that functions like mean explicitly return NA in the  
presence of NA's, but this is important to know and recognize when  
analyzing any real data, because there will surely be NA's "in the  
wild." Knowing that you should consciously and deliberately deal with/ 
ignore them from the start might be a good first/early lesson for  
students to digest.


Like I said, I don't mean to sound like an ass, but I think glossing  
over details of working with data should be avoided. Your other  
additions, like adding options to plotting/graphing functions, seem  
less harmful to me. But if you're trampling over some base:: function  
for something trivial like changing the value of one default parameter  
to something else, you might as well just get them to learn how to use  
the ? asap as well.


-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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


Re: [R] lm coefficients output confusing

2009-08-13 Thread Ted Harding
On 13-Aug-09 20:45:31, Ross Culloch wrote:
> 
> Hi all,
> 
> I have an issue with the lm() function regarding the listing of
> the coefficients. My data are below, showing a list of hours (HR)
> relating to the time spent resting (R) by an individual animal.
> Simply i want to run a lm() to run in an anova() to see if there
> is a significant difference in resting between hours. 
> 
>HR R
> 1   2 0.667
> 2   2 0.467
> 3   2 0.800
> 4   2 0.633
> 5   2 0.733
> 6   2 0.800
> 7   2 0.867
> 8   2 0.7857143
> 9   2 0.7826087
> 10  2 0.667
> 11  2 0.917
> 12  2 0.667
> 13  3 0.5294118
> 14  3 0.8541667
> 15  3 0.458
> 16  3 0.5882353
> 17  3 0.9347826
> 18  3 0.7878788
> 19  3 0.7857143
> 20  3 0.694
> 21  3 0.833
> 22  3 0.7450980
> 23  3 0.9230769
> 24  3 0.722
> 25  4 0.6571429
> 26  4 0.7241379
> 27  4 0.7391304
> 28  4 0.6571429
> 29  4 0.800
> 30  4 0.9130435
> 31  4 0.7187500
> 32  4 0.8437500
> 33  4 0.9230769
> 34  4 0.8571429
> 35  4 0.8695652
> 36  4 0.889
> 37  5 0.333
> 38  5 0.5365854
> 39  5 0.6774194
> 40  5 0.7142857
> 41  5 0.6904762
> 42  5 0.5483871
> 43  5 0.5952381
> 44  5 0.417
> 45  5 0.567
> 46  5 0.5952381
> 47  5 0.7894737
> 48  5 0.750
> 49  6 0.6268657
> 50  6 0.7187500
> 51  6 0.550
> 52  6 0.7164179
> 53  6 0.7656250
> 54  6 0.5869565
> 55  6 0.7164179
> 56  6 0.7031250
> 57  6 0.7230769
> 58  6 0.7462687
> 59  6 0.920
> 60  6 0.8536585
> 61  7 0.6379310
> 62  7 0.5357143
> 63  7 0.5227273
> 64  7 0.800
> 65  7 0.6724138
> 66  7 0.708
> 67  7 0.7241379
> 68  7 0.6938776
> 69  7 0.6545455
> 70  7 0.7931034
> 71  7 0.7560976
> 72  7 0.8684211
> 73  8 0.6727273
> 74  8 0.600
> 75  8 0.833
> 76  8 0.8181818
> 77  8 0.7818182
> 78  8 0.7647059
> 79  8 0.5818182
> 80  8 0.5918367
> 81  8 0.7450980
> 82  8 0.7818182
> 83  8 0.8048780
> 84  8 0.8684211
> 
> 
> The script i'm using and output is as follows:
> 
>> anova(rdayml <- lm(R ~ HR, data=rdata2, na.action=na.exclude)) 
> Analysis of Variance Table
> 
> Response: R
>   Df  Sum Sq Mean Sq F value  Pr(>F)   
> HR 6 0.25992 0.04332  3.1762 0.00774 **
> Residuals 77 1.05021 0.01364   
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’
> 0.1 ‘ ’ 1 
>> 
>> summary(rdayml <- lm(R ~ HR,data=rdata2))
> 
> Call:
> lm(formula = R ~ HR, data = rdata2)
> 
> Residuals:
>   Min >1QMedian3Q   Max 
> -0.279725 -0.065416  0.005593  0.077486  0.201070 
> 
> Coefficients:
>  Estimate Std. Error t value Pr(>|t|)
> (Intercept)  0.732082   0.033713  21.715   <2e-16 ***
> HR3  0.005976   0.047678   0.125   0.9006
> HR4  0.067232   0.047678   1.410   0.1625
> HR5 -0.130935   0.047678  -2.746   0.0075 ** 
> HR6 -0.013152   0.047678  -0.276   0.7834
> HR7 -0.034807   0.047678  -0.730   0.4676
> HR8  0.004971   0.047678   0.104   0.9172
> ---> Signif. codes:  0 ‘***’ 0.001 ‘**’ .01 ‘*’ 0.05
‘.’
> 0.1 ‘ ’ 1 
> 
> Residual standard error: 0.1168 on 77 degrees of freedom
> Multiple R-squared: 0.1984, Adjusted R-squared: 0.1359 
> F-statistic: 3.176 on 6 and 77 DF,  p-value: 0.00774 
> 
> 
> What i really don't understand is why the lm summary lists the hour
> numbers in the coefficient of the lm, as apposed to just reading HR?

What has apparently happened here is that HR has been read in as
a factor, nor a numerical covariate (which is probably what you wanted
anyway, since you seem to want to compare hours).

Hence HR is a factor with 7 levels: "2","3","4","5","6","7","8"
(I have wirtten them between "" to show that they will not be
interpreted numerically). When you get a coefficient from lm(),
e.g. for HR6, this is the coefficient for level "6" of HR, and
that is the standard way of writing a factor with its level in
the output of ln().

> On top of that if R does display the data like this then i don't
> understand why it omits hour 2?

This is because your have the Intercept in the model, so along
with the 7 levels of HR you now have 8 variables present for a
model with 7 coefficients. So one has to go (being redundant).
Conventionally this is the first level of the factor (though you
can arrange it differently if you want to). Hence HR2 is, in effect,
absorbed into the Intercept. In this case, the Intercept is equal
to the mean of the values for Hour 2.

If you were to add the coefficint for Intercept to the coefficient
for any level of HR, e.g.

   Intercept   HR5
  (0.732082) + (-0.130935)  =  0.601147

you should find that it is the same as the mean of the values in
Hour 5:

  (0.333+0.5365854+0.6774194+0.7142857+0.6904762+0.5483871+
   0.5952381+0.417+0.567+0.5952381+0.7894737+0.750)/12

  = 0.6011475

as indeed it is! The coefficient of a given level of HR is here
the difference between the mean for that hour and the mean

[R] joining two points in rgl

2009-08-13 Thread Nair, Murlidharan T

Hi!!

I need to draw a cylinder/tube joining two points. I am trying to make 
something presentable, I have been able to do it using lines3d. But is it 
possible to 
increase the thickness of the lines? The size parameter does not work. Does any 
one have any suggestions?

Thanks ../Murli

library(rgl)
pts<-structure(list(x = c(-0.975688, -0.975688), y = c(9.258795, -9.258795
), z = c(-1.8, 1.8)), .Names = c("x", "y", "z"), class = "data.frame", 
row.names = c(NA,
-2L))

plot3d(pts$x,pts$y,pts$z, col="grey", size=2, box=FALSE, axes=FALSE, type="s")
lines3d(pts$x,pts$y,pts$z, col="grey", size=2)

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


Re: [R] lm coefficients output confusing

2009-08-13 Thread Charles C. Berry

On Thu, 13 Aug 2009, Ross Culloch wrote:



Hi all,

I have an issue with the lm() function regarding the listing of the
coefficients. My data are below, showing a list of hours (HR) relating to
the time spent resting (R) by an individual animal. Simply i want to run a
lm() to run in an anova() to see if there is a significant difference in
resting between hours.


The problem is not with lm(), but with your data.

The listing below does not precisely represent your data; when I copy it 
to the clipboard and then use


dat <- read.table("clipboard")
lm(R~HR,dat)

I get a different result.

OTOH, when I use

summary(lm(R~as.factor(HR),rdata2))

I recap your results (up to labelling).

I suggest you try

str( rdata2 )

to get more insight into your data. I suspect that one or more of the 
values in HR was quoted in your data file or that you used colClasses to 
determine the class of data in each column and turned HR into a factor.


HTH,

Chuck



   HR R
1   2 0.667
2   2 0.467
3   2 0.800
4   2 0.633
5   2 0.733
6   2 0.800
7   2 0.867
8   2 0.7857143
9   2 0.7826087
10  2 0.667
11  2 0.917
12  2 0.667
13  3 0.5294118
14  3 0.8541667
15  3 0.458
16  3 0.5882353
17  3 0.9347826
18  3 0.7878788
19  3 0.7857143
20  3 0.694
21  3 0.833
22  3 0.7450980
23  3 0.9230769
24  3 0.722
25  4 0.6571429
26  4 0.7241379
27  4 0.7391304
28  4 0.6571429
29  4 0.800
30  4 0.9130435
31  4 0.7187500
32  4 0.8437500
33  4 0.9230769
34  4 0.8571429
35  4 0.8695652
36  4 0.889
37  5 0.333
38  5 0.5365854
39  5 0.6774194
40  5 0.7142857
41  5 0.6904762
42  5 0.5483871
43  5 0.5952381
44  5 0.417
45  5 0.567
46  5 0.5952381
47  5 0.7894737
48  5 0.750
49  6 0.6268657
50  6 0.7187500
51  6 0.550
52  6 0.7164179
53  6 0.7656250
54  6 0.5869565
55  6 0.7164179
56  6 0.7031250
57  6 0.7230769
58  6 0.7462687
59  6 0.920
60  6 0.8536585
61  7 0.6379310
62  7 0.5357143
63  7 0.5227273
64  7 0.800
65  7 0.6724138
66  7 0.708
67  7 0.7241379
68  7 0.6938776
69  7 0.6545455
70  7 0.7931034
71  7 0.7560976
72  7 0.8684211
73  8 0.6727273
74  8 0.600
75  8 0.833
76  8 0.8181818
77  8 0.7818182
78  8 0.7647059
79  8 0.5818182
80  8 0.5918367
81  8 0.7450980
82  8 0.7818182
83  8 0.8048780
84  8 0.8684211


The script i'm using and output is as follows:

> anova(rdayml <- lm(R ~ HR, data=rdata2, na.action=na.exclude)) 
Analysis of Variance Table


Response: R
  Df  Sum Sq Mean Sq F value  Pr(>F) 
HR 6 0.25992 0.04332  3.1762 0.00774 **
Residuals 77 1.05021 0.01364 
---
Signif. codes:  0 ???***??? 0.001 ???**??? 0.01 ???*??? 0.05 ???.??? 0.1 ??? ??? 1 
> 
> summary(rdayml <- lm(R ~ HR,data=rdata2))


Call:
lm(formula = R ~ HR, data = rdata2)

Residuals:
  Min1QMedian3Q   Max 
-0.279725 -0.065416  0.005593  0.077486  0.201070 


Coefficients:
 Estimate Std. Error t value Pr(>|t|) 
(Intercept)  0.732082   0.033713  21.715   <2e-16 ***
HR3  0.005976   0.047678   0.125   0.9006 
HR4  0.067232   0.047678   1.410   0.1625 
HR5 -0.130935   0.047678  -2.746   0.0075 ** 
HR6 -0.013152   0.047678  -0.276   0.7834 
HR7 -0.034807   0.047678  -0.730   0.4676 
HR8  0.004971   0.047678   0.104   0.9172 
---
Signif. codes:  0 ???***??? 0.001 ???**??? 0.01 ???*??? 0.05 ???.??? 0.1 ??? ??? 1 


Residual standard error: 0.1168 on 77 degrees of freedom
Multiple R-squared: 0.1984, Adjusted R-squared: 0.1359 
F-statistic: 3.176 on 6 and 77 DF,  p-value: 0.00774 



What i really don't understand is why the lm summary lists the hour numbers
in the coefficient of the lm, as apposed to just reading HR? On top of that
if R does display the data like this then i don't understand why it omits
hour 2? If i can get this to work correctly can I use the p value to
determine which of the hours is significantly different to the others - so
in this example hour 5 is significantly different? Or is it just a case of
using the p value from the anova to determine that there is a significant
difference between hours (in this case) and use a plot to determine which
hour(s) are likely to be the cause?

Any help or advice would be most useful!

Best wishes,

Ross


--
View this message in context: 
http://www.nabble.com/lm-coefficients-output-confusing-tp24958398p24958398.html
Sent from the R help mailing list archive at Nabble.com.

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



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  

Re: [R] Coding problem: How can I extract substring of function callwithin the function

2009-08-13 Thread Pitt, Joel
Thanks. It's a great solution to part of my problem. It provides the 
functionally I want would be no harder for students to use than my approach. 
I'm still interested in how to make what I was trying to do work -- simply to 
add to my own R programming proficiency. 
 
Joel



From: Erik Iverson [mailto:eiver...@nmdp.org]
Sent: Thu 8/13/2009 4:59 PM
To: Pitt, Joel; r-help@r-project.org
Subject: RE: Coding problem: How can I extract substring of function callwithin 
the function



Are you sure you just don't want to tell them about the :: operator?  It sounds 
easier than what you're proposing.

E.g.,

base::mean(c(1:10, NA))

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Pitt, Joel
Sent: Thursday, August 13, 2009 3:48 PM
To: r-help@r-project.org
Subject: [R] Coding problem: How can I extract substring of function call 
within the function

In order to ease my students into the R environment I am developing a package 
which installs a variety of utility functions as well as slightly modified 
versions of some standard R functions -- e.g. mean, hist, barplot,  In my 
versions of these standard R functions I either add options or alter some 
defaults that seem to create difficulties for most of my students -- for 
example, when they do barcharts for two dimensional tables they generally want 
the bars to be side-by-side and stumble over the standard default of besides=F, 
and my version of mean by default reports a mean value in the presence of NA's 
after warning of that presence (but retains the option of setting na.rm=F). (I 
don't doubt that some (if not many) of you will doubt the wisdom of this, and I 
would be happy to discuss this in more detail on other occasions.) You might 
want to think of my replacement R functions as a kind of "training wheels" for 
R, and, in the spirit of training wheels I include a funct!
 ion in my package that allows a user to revert to the standard version of one 
or all functions without unloading the package (and loosing its additional 
functionality). However, I want to add a function that allows a user to revert 
to running the standard R version of a given function on a one-off basis and 
that's where my problem comes up.

I believe that it should be possible to write a function rStd with the usage 
rStd(x,...) where x is a function -- e.g. mean, hist, barchart, and the 
remaining parameters would be any of the parameters that should be passed to 
the unmodified version of mean, hist, barchart... The problem I have is how to 
get ahold of that collection of parameters as a single character string. Now I 
know that sys.calls()[[1]] will give me the full text of the initial call, but 
the problem is to detach the ... above from that as a text string. If I could 
do that I'd be done.

Here's the incomplete code with comments -- see the gap set off by astericks.

rStd=function(x,...){
if(missing(x))  # must have a specified function
{
   cat("Error: No function specified\n");
   return(invisible(NULL));
}
z=as.character(substitute(x));
# must include code here to check that z is the name
# of one of our altered functions
# if z is an altered function, e.g., "mean"
# then concatenating "x" with z gives the overlaid
# function -- e.g. xmean is the standard mean
#***
# Now we need to get a hold of the ... text 
 *
#   
  *
w=sys.calls()[[1]];  # this gets me the whole text of the call  *
#   
  *
# and now here's where the problem arises *
# how to I get the ... text if I could get it and say   
   *
# assign it to the variable params  
 *
# I could then set  
*
#   
  *
cmd=sprintf("x%s(%s)",z,params) # see remarks above about z
   # and then it's done
eval(parse(text=cmd),sys.frame());
}


Any help would be much appreciated.

Regards
Joel
Joel Pitt, Ph.D.
Associate Professor & Chair
Mathematics & Computer Science
Georgian Court University
900 Lakewood Avenue
Lakewood, NJ 08540
732-987-2322

[[alternative HTML version deleted]]

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



[[alternative HTML version del

Re: [R] Coding problem: How can I extract substring of function call within the function

2009-08-13 Thread Gabor Grothendieck
The Defaults package can be used to change the defaults of
functions and reset them back.

There is some question on whether all this is advisable.
It will invalidate any books, documentation, examples
in the help files that come with R and other
resources on R that they might have otherwise used
by introducing deliberate differences.  Later, to learn
standard R it will be harder since they will have to
unlearn what they learned.

If you really must do this I would suggest
using different names, e.g. mean2 or Mean,
so its clear one is using non-standard versions.
In that case you don't need rStd in the first place.

Even better, perhaps a one page cheat sheet of
common forms would be better than a package
full of trivially and annoyingly changed functions, e.g.

mean(x, na.rm = TRUE)  # mean of non-missings in x
barplot(x, beside = TRUE) # bar chart placing bars beside each other

On Thu, Aug 13, 2009 at 4:48 PM, Pitt, Joel wrote:
> In order to ease my students into the R environment I am developing a package 
> which installs a variety of utility functions as well as slightly modified 
> versions of some standard R functions -- e.g. mean, hist, barplot,  In my 
> versions of these standard R functions I either add options or alter some 
> defaults that seem to create difficulties for most of my students -- for 
> example, when they do barcharts for two dimensional tables they generally 
> want the bars to be side-by-side and stumble over the standard default of 
> besides=F, and my version of mean by default reports a mean value in the 
> presence of NA's after warning of that presence (but retains the option of 
> setting na.rm=F). (I don't doubt that some (if not many) of you will doubt 
> the wisdom of this, and I would be happy to discuss this in more detail on 
> other occasions.) You might want to think of my replacement R functions as a 
> kind of "training wheels" for R, and, in the spirit of training wheels I 
> include a funct!
>  ion in my package that allows a user to revert to the standard version of 
> one or all functions without unloading the package (and loosing its 
> additional functionality). However, I want to add a function that allows a 
> user to revert to running the standard R version of a given function on a 
> one-off basis and that's where my problem comes up.
>
> I believe that it should be possible to write a function rStd with the usage 
> rStd(x,...) where x is a function -- e.g. mean, hist, barchart, and the 
> remaining parameters would be any of the parameters that should be passed to 
> the unmodified version of mean, hist, barchart... The problem I have is how 
> to get ahold of that collection of parameters as a single character string. 
> Now I know that sys.calls()[[1]] will give me the full text of the initial 
> call, but the problem is to detach the ... above from that as a text string. 
> If I could do that I'd be done.
>
> Here's the incomplete code with comments -- see the gap set off by astericks.
>
>    rStd=function(x,...){
>    if(missing(x))  # must have a specified function
>    {
>       cat("Error: No function specified\n");
>       return(invisible(NULL));
>    }
>    z=as.character(substitute(x));
>    # must include code here to check that z is the name
>    # of one of our altered functions
>    # if z is an altered function, e.g., "mean"
>    # then concatenating "x" with z gives the overlaid
>    # function -- e.g. xmean is the standard mean
>    
> #***
>    # Now we need to get a hold of the ... text                                
>   *
>    #                                                                          
>                    *
>    w=sys.calls()[[1]];  # this gets me the whole text of the call          *
>    #                                                                          
>                    *
>    # and now here's where the problem arises                                 *
>    # how to I get the ... text if I could get it and say                      
>     *
>    # assign it to the variable params                                         
>       *
>    # I could then set                                                         
>              *
>    #                                                                          
>                    *
>    cmd=sprintf("x%s(%s)",z,params) # see remarks above about z
>   # and then it's done
>    eval(parse(text=cmd),sys.frame());
> }
>
>
> Any help would be much appreciated.
>
> Regards
> Joel
> Joel Pitt, Ph.D.
> Associate Professor & Chair
> Mathematics & Computer Science
> Georgian Court University
> 900 Lakewood Avenue
> Lakewood, NJ 08540
> 732-987-2322
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.or

Re: [R] request: Help

2009-08-13 Thread Steve Lianoglou

Hi,

On Aug 13, 2009, at 3:43 PM, Sarjinder Singh wrote:


Dear Sir/Madam,

Good Day!

How can we make output file in R?

In FORTRAN, we could do as follows:

WRITE (42, 107) x, y
107  FORMAT ( 2x, F9.3, 2x, F4.2)

What is equivalent to this in R?


See:
 ?file
 ?cat
 ?sprintf

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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


Re: [R] Coding problem: How can I extract substring of function call within the function

2009-08-13 Thread Erik Iverson
Are you sure you just don't want to tell them about the :: operator?  It sounds 
easier than what you're proposing. 

E.g.,

base::mean(c(1:10, NA))

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Pitt, Joel
Sent: Thursday, August 13, 2009 3:48 PM
To: r-help@r-project.org
Subject: [R] Coding problem: How can I extract substring of function call 
within the function

In order to ease my students into the R environment I am developing a package 
which installs a variety of utility functions as well as slightly modified 
versions of some standard R functions -- e.g. mean, hist, barplot,  In my 
versions of these standard R functions I either add options or alter some 
defaults that seem to create difficulties for most of my students -- for 
example, when they do barcharts for two dimensional tables they generally want 
the bars to be side-by-side and stumble over the standard default of besides=F, 
and my version of mean by default reports a mean value in the presence of NA's 
after warning of that presence (but retains the option of setting na.rm=F). (I 
don't doubt that some (if not many) of you will doubt the wisdom of this, and I 
would be happy to discuss this in more detail on other occasions.) You might 
want to think of my replacement R functions as a kind of "training wheels" for 
R, and, in the spirit of training wheels I include a funct!
 ion in my package that allows a user to revert to the standard version of one 
or all functions without unloading the package (and loosing its additional 
functionality). However, I want to add a function that allows a user to revert 
to running the standard R version of a given function on a one-off basis and 
that's where my problem comes up.
 
I believe that it should be possible to write a function rStd with the usage 
rStd(x,...) where x is a function -- e.g. mean, hist, barchart, and the 
remaining parameters would be any of the parameters that should be passed to 
the unmodified version of mean, hist, barchart... The problem I have is how to 
get ahold of that collection of parameters as a single character string. Now I 
know that sys.calls()[[1]] will give me the full text of the initial call, but 
the problem is to detach the ... above from that as a text string. If I could 
do that I'd be done.
 
Here's the incomplete code with comments -- see the gap set off by astericks. 
 
rStd=function(x,...){
if(missing(x))  # must have a specified function
{
   cat("Error: No function specified\n");
   return(invisible(NULL));
}
z=as.character(substitute(x));
# must include code here to check that z is the name
# of one of our altered functions
# if z is an altered function, e.g., "mean"
# then concatenating "x" with z gives the overlaid
# function -- e.g. xmean is the standard mean
#***
# Now we need to get a hold of the ... text 
 *
#   
  *
w=sys.calls()[[1]];  # this gets me the whole text of the call  *
#   
  *
# and now here's where the problem arises *
# how to I get the ... text if I could get it and say   
   *
# assign it to the variable params  
 *
# I could then set  
*
#   
  *
cmd=sprintf("x%s(%s)",z,params) # see remarks above about z
   # and then it's done
eval(parse(text=cmd),sys.frame());
}
 
 
Any help would be much appreciated.
 
Regards
Joel
Joel Pitt, Ph.D.
Associate Professor & Chair
Mathematics & Computer Science
Georgian Court University
900 Lakewood Avenue
Lakewood, NJ 08540
732-987-2322

[[alternative HTML version deleted]]

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

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


[R] Coding problem: How can I extract substring of function call within the function

2009-08-13 Thread Pitt, Joel
In order to ease my students into the R environment I am developing a package 
which installs a variety of utility functions as well as slightly modified 
versions of some standard R functions -- e.g. mean, hist, barplot,  In my 
versions of these standard R functions I either add options or alter some 
defaults that seem to create difficulties for most of my students -- for 
example, when they do barcharts for two dimensional tables they generally want 
the bars to be side-by-side and stumble over the standard default of besides=F, 
and my version of mean by default reports a mean value in the presence of NA's 
after warning of that presence (but retains the option of setting na.rm=F). (I 
don't doubt that some (if not many) of you will doubt the wisdom of this, and I 
would be happy to discuss this in more detail on other occasions.) You might 
want to think of my replacement R functions as a kind of "training wheels" for 
R, and, in the spirit of training wheels I include a funct!
 ion in my package that allows a user to revert to the standard version of one 
or all functions without unloading the package (and loosing its additional 
functionality). However, I want to add a function that allows a user to revert 
to running the standard R version of a given function on a one-off basis and 
that's where my problem comes up.
 
I believe that it should be possible to write a function rStd with the usage 
rStd(x,...) where x is a function -- e.g. mean, hist, barchart, and the 
remaining parameters would be any of the parameters that should be passed to 
the unmodified version of mean, hist, barchart... The problem I have is how to 
get ahold of that collection of parameters as a single character string. Now I 
know that sys.calls()[[1]] will give me the full text of the initial call, but 
the problem is to detach the ... above from that as a text string. If I could 
do that I'd be done.
 
Here's the incomplete code with comments -- see the gap set off by astericks. 
 
rStd=function(x,...){
if(missing(x))  # must have a specified function
{
   cat("Error: No function specified\n");
   return(invisible(NULL));
}
z=as.character(substitute(x));
# must include code here to check that z is the name
# of one of our altered functions
# if z is an altered function, e.g., "mean"
# then concatenating "x" with z gives the overlaid
# function -- e.g. xmean is the standard mean
#***
# Now we need to get a hold of the ... text 
 *
#   
  *
w=sys.calls()[[1]];  # this gets me the whole text of the call  *
#   
  *
# and now here's where the problem arises *
# how to I get the ... text if I could get it and say   
   *
# assign it to the variable params  
 *
# I could then set  
*
#   
  *
cmd=sprintf("x%s(%s)",z,params) # see remarks above about z
   # and then it's done
eval(parse(text=cmd),sys.frame());
}
 
 
Any help would be much appreciated.
 
Regards
Joel
Joel Pitt, Ph.D.
Associate Professor & Chair
Mathematics & Computer Science
Georgian Court University
900 Lakewood Avenue
Lakewood, NJ 08540
732-987-2322

[[alternative HTML version deleted]]

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


[R] tick.number in ggplot2?

2009-08-13 Thread Ben Bolker

  Another dumb ggplot2 question:

  a facet plot with free x scale, lots of
different ranges, want to specify that the
x axis ticks be sparse -- only 2 or 3.  I was
about to say that I could figure out how to manually
set the ticks for each facet if necessary, but now
that I've looked around some more (at scale_continuous,
facet_grid, facet_wrap, the Book ...) I think I can't
even do that.  Looking at http://had.co.nz/ggplot2/facet_grid.html
and searching for "free" will show the problem I'm
trying to solve -- in the first few plots you come to that
way, the middle plots (corresponding to 6-cylinder engines)
have scrunched/overlapping x axis labels.
  I guess turning the x axis labels vertically would be
another solution, but I'd rather just make the ticks
sparser if there were a way to do that ...

  cheers
Ben Bolker


-- 
Ben Bolker
Associate professor, Biology Dep't, Univ. of Florida
bol...@ufl.edu / www.zoology.ufl.edu/bolker
GPG key: www.zoology.ufl.edu/bolker/benbolker-publickey.asc



signature.asc
Description: OpenPGP digital signature
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] lm coefficients output confusing

2009-08-13 Thread Ross Culloch

Hi all,

I have an issue with the lm() function regarding the listing of the
coefficients. My data are below, showing a list of hours (HR) relating to
the time spent resting (R) by an individual animal. Simply i want to run a
lm() to run in an anova() to see if there is a significant difference in
resting between hours. 

   HR R
1   2 0.667
2   2 0.467
3   2 0.800
4   2 0.633
5   2 0.733
6   2 0.800
7   2 0.867
8   2 0.7857143
9   2 0.7826087
10  2 0.667
11  2 0.917
12  2 0.667
13  3 0.5294118
14  3 0.8541667
15  3 0.458
16  3 0.5882353
17  3 0.9347826
18  3 0.7878788
19  3 0.7857143
20  3 0.694
21  3 0.833
22  3 0.7450980
23  3 0.9230769
24  3 0.722
25  4 0.6571429
26  4 0.7241379
27  4 0.7391304
28  4 0.6571429
29  4 0.800
30  4 0.9130435
31  4 0.7187500
32  4 0.8437500
33  4 0.9230769
34  4 0.8571429
35  4 0.8695652
36  4 0.889
37  5 0.333
38  5 0.5365854
39  5 0.6774194
40  5 0.7142857
41  5 0.6904762
42  5 0.5483871
43  5 0.5952381
44  5 0.417
45  5 0.567
46  5 0.5952381
47  5 0.7894737
48  5 0.750
49  6 0.6268657
50  6 0.7187500
51  6 0.550
52  6 0.7164179
53  6 0.7656250
54  6 0.5869565
55  6 0.7164179
56  6 0.7031250
57  6 0.7230769
58  6 0.7462687
59  6 0.920
60  6 0.8536585
61  7 0.6379310
62  7 0.5357143
63  7 0.5227273
64  7 0.800
65  7 0.6724138
66  7 0.708
67  7 0.7241379
68  7 0.6938776
69  7 0.6545455
70  7 0.7931034
71  7 0.7560976
72  7 0.8684211
73  8 0.6727273
74  8 0.600
75  8 0.833
76  8 0.8181818
77  8 0.7818182
78  8 0.7647059
79  8 0.5818182
80  8 0.5918367
81  8 0.7450980
82  8 0.7818182
83  8 0.8048780
84  8 0.8684211


The script i'm using and output is as follows:

> anova(rdayml <- lm(R ~ HR, data=rdata2, na.action=na.exclude)) 
Analysis of Variance Table

Response: R
  Df  Sum Sq Mean Sq F value  Pr(>F)   
HR 6 0.25992 0.04332  3.1762 0.00774 **
Residuals 77 1.05021 0.01364   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
> 
> summary(rdayml <- lm(R ~ HR,data=rdata2))

Call:
lm(formula = R ~ HR, data = rdata2)

Residuals:
  Min1QMedian3Q   Max 
-0.279725 -0.065416  0.005593  0.077486  0.201070 

Coefficients:
 Estimate Std. Error t value Pr(>|t|)
(Intercept)  0.732082   0.033713  21.715   <2e-16 ***
HR3  0.005976   0.047678   0.125   0.9006
HR4  0.067232   0.047678   1.410   0.1625
HR5 -0.130935   0.047678  -2.746   0.0075 ** 
HR6 -0.013152   0.047678  -0.276   0.7834
HR7 -0.034807   0.047678  -0.730   0.4676
HR8  0.004971   0.047678   0.104   0.9172
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.1168 on 77 degrees of freedom
Multiple R-squared: 0.1984, Adjusted R-squared: 0.1359 
F-statistic: 3.176 on 6 and 77 DF,  p-value: 0.00774 


What i really don't understand is why the lm summary lists the hour numbers
in the coefficient of the lm, as apposed to just reading HR? On top of that
if R does display the data like this then i don't understand why it omits
hour 2? If i can get this to work correctly can I use the p value to
determine which of the hours is significantly different to the others - so
in this example hour 5 is significantly different? Or is it just a case of
using the p value from the anova to determine that there is a significant
difference between hours (in this case) and use a plot to determine which
hour(s) are likely to be the cause?

Any help or advice would be most useful!

Best wishes,

Ross


-- 
View this message in context: 
http://www.nabble.com/lm-coefficients-output-confusing-tp24958398p24958398.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] R: how to get R interpreter to remember constant values without using any memory location

2009-08-13 Thread mauede
Thank you for all your suggestiona. 
I tried to write a self-contained example which turned oiut to confuse people's 
miind. 
I realized also the formulation of my question was unclear. Sorry for that.

What I had in mind was something similar to Fortran Parameter declaration.
I spent some time dealing with Monte Carlo codes for radiation trasport. In 
this particular 
research filed it's pretty common to come across Fortran code, like it or not.
For example, through Fortran Parameter declaration, I can assign a name to a 
big floating-point number, 
something like  Parameter( A = 123E-15) without having the compiler to allocate 
32 (REAL data type) 
or 64 (DOUBLE data type) consecutive memory locations to accommodate such a 
number.
Of course the computer must save any constant data somewhere but neglecting its 
data type,
therefore saving memory space.

In my R script I have to deal with a dynamically varying list of references. 
Something simiilar to 
what LaTeX interpreter does when we use it to write a manuscript. That is, we 
do not have to 
renumber the bibliography references list whenever we insert a  new citation 
into, or remove an existing one 
from our manuscript. LaTeX takes care of that. We just cite references through 
labels taht LaTeX translates into a dynamically
ordered list of numbers.
So, factors may work fine for me. 
Another possibility that downed on me may be to name the list elements, 
although I 
will have to update the list names every time the list is updaed. 

Thank you again,
Maura


-Messaggio originale-
Da: Don MacQueen [mailto:m...@llnl.gov]
Inviato: gio 13/08/2009 21.17
A: mau...@alice.it; r-h...@stat.math.ethz.ch
Oggetto: Re: [R] how to get R interpreter to remember constant values without   
using any memory location
 
Like Ben, I wonder what the reason for doing this is.

First of all, the amount of memory indicated by your example is so 
small I can't imagine it would make any difference. If you have such 
a large number of values that the amount of memory is significant -- 
and store them somewhere that isn't in memory (such as physical disk 
memory), then reading them into memory when you need to use them 
might affect performance a lot.

Environment variables use memory also -- it's just someone else's 
memory (the OS instead of R).

-Don

At 4:05 PM +0200 8/13/09,  wrote:
>Maybe I expect too much from a non compiled language.
>Anyway, I wonder whether it is possible in R to set constant values 
>without using any memory location that would take useless space
>bacause such values are not going to be changed along the program. 
>It's just a way to assign a mnemnic name tos some constant values.
>For instance, I would like R interpreter to replace all occurrences 
>of mnemonic "Monday" with the number 1, "Tuesday"  with the number 
>2, "Wednesday  with the number 3, and so on ...  without having to 
>assign such values to memory locations.
>Maybe environment variables are the way to go ? 
>
>Thank you in advance for your advice,
>Maura
>
>
>
>
>tutti i telefonini TIM!
>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list
>https://*stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.


-- 
--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
--




tutti i telefonini TIM!


[[alternative HTML version deleted]]

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


[R] request: Help

2009-08-13 Thread Sarjinder Singh
Dear Sir/Madam,
 
Good Day!
 
How can we make output file in R?
 
In FORTRAN, we could do as follows:
 
    WRITE (42, 107) x, y
107  FORMAT ( 2x, F9.3, 2x, F4.2)
 
What is equivalent to this in R?
 
With best regards,
 
Sarjinder
 
 
 
 
 
 
 


 


Updated web-page on Sept 6, 2004: 
 
www.geocities.com/sarjinder
 



  
[[alternative HTML version deleted]]

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


Re: [R] Browser and Debug?

2009-08-13 Thread rkevinburton
If I am on Windows and don't have GDB it does'nt look like it is possible. Any 
tips?

Kevin
 roger koenker  wrote: 
> At points of total desperation you can always consider
> the time-honored, avuncular advice  --  RTFM,
> in this case Section 4.4 of Writing R Extensions.
> 
> 
> url:www.econ.uiuc.edu/~rogerRoger Koenker
> emailrkoen...@uiuc.eduDepartment of Economics
> vox: 217-333-4558University of Illinois
> fax:   217-244-6678Urbana, IL 61801
> 
> 
> 
> On Aug 13, 2009, at 10:20 AM,  wrote:
> 
> > This may be asking more than can be reasonably expected. But, any  
> > tips on debugging the 'C' and Fortran code without trying to put  
> > together all the tools to compile from source?
> >
> > Kevin
> >
> >  Erik Iverson  wrote:
> >> This article might help:
> >>
> >> http://www.biostat.jhsph.edu/~rpeng/docs/R-debug-tools.pdf
> >>
> >> -Original Message-
> >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org 
> >> ] On Behalf Of Inchallah Yarab
> >> Sent: Thursday, August 13, 2009 9:40 AM
> >> To: r-help@r-project.org
> >> Subject: [R] Browser and Debug?
> >>
> >> Hi,
> >>
> >> Someone can explain to me how use Browser and Debug ?
> >> thank you
> >>
> >>
> >>
> >>[[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide 
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide 
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

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


[R] Finding minimum of time subset

2009-08-13 Thread Tim Clark
Dear List,

I have a data frame of data taken every few seconds.  I would like to subset 
the data to retain only the data taken on the quarter hour, and as close to the 
quarter hour as possible.  So far I have figured out how to subset the data to 
the quarter hour, but not how to keep only the minimum time for each quarter 
hour.  

For example:
mytime<-c("12:00:00","12:00:05","12:15:05","12:15:06","12:20:00","12:30:01","12:45:01","13:00:00","13:15:02")
subtime<-grep(pattern="[[:digit:]]+[[:punct:]]00[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]15[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]30[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]45[[:punct:]][[:digit:]]+",mytime)
mytime[subtime]

[1] "12:00:00" "12:00:05" "12:15:05" "12:15:06" "12:30:01" "12:45:01" 
"13:00:00" "13:15:02"

This gives me the data taken at quarter hour intervals (removes 12:20:00) but I 
am still left with multiple values at the quarter hours.  

I would like to obtain:

"12:00:00" "12:15:05" "12:30:01" "12:45:01" "13:00:00" "13:15:02"

Thanks!

Tim




Tim Clark
Department of Zoology 
University of Hawaii

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


Re: [R] Adding logical vectors

2009-08-13 Thread Ted Harding
On 13-Aug-09 19:21:36, David Huffer wrote:
> When adding several logical vectors I expect each vector will be
> coerced to integers and these vectors will then be added.
> 
> That doesn't always seem to be the case.
> 
> For example:
> 
>   > ( f1 <- as.factor ( sample ( "x" , 25 , rep = T ) ) )
>[1] x x x x x x x x x x x x x x x x x x x x x x x x x
>   Levels: x
>   > ( f2 <- as.factor ( sample ( "y" , 25 , rep = T ) ) )
>[1] y y y y y y y y y y y y y y y y y y y y y y y y y
>   Levels: y
>   > ( f3 <- as.factor ( sample ( "z" , 25 , rep = T ) ) )
>[1] z z z z z z z z z z z z z z z z z z z z z z z z z
>   Levels: z
>   >
>   > is.na ( f1 [ sample ( 1:25 , 4 ) ] ) <-
>   + is.na ( f2 [ sample ( 1:25 , 4 ) ] ) <-
>   + is.na ( f3 [ sample ( 1:25 , 4 ) ] ) <- TRUE
>   >
>   > ##  this returns a numeric vector:
>   >
>   > is.na ( f1 ) + is.na ( f2 ) + is.na ( f3 )
>[1] 0 0 0 0 0 1 1 0 0 0 1 0 0 1 0 0 1 0 1 2 2 0 1 0 1
>   >
>   > ##  but this returns a logical vector
>   >
>   > !is.na ( f1 ) + !is.na ( f2 ) + !is.na ( f3 )
>[1]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE
>[9]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE
>   [17] FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE
>   [25] FALSE
>   >
> 
> Can someone please explain why the returned value is a logical
> vector when I use the not operator but a numeric vector when I
> don't.
> 
> What is special about the !is.na? it returns an object of class
> logical just like the is.na function:
> 
>   > all.equal ( class ( !is.na ( f1 ) ) , class ( is.na ( f1 ) ) )
>   [1] TRUE
>   >
> 
> Thanks!

I think you need to compare:
[1]
  is.na ( f1 ) + !is.na ( f2 )
  # [1] 2 0 1 1 2 1 0 1 1 
  #[10] 1 0 2 1 1 0 1 1 2
  #[19] 1 1 1 1 1 1 1

with
[2]
  !is.na ( f1 ) + !is.na ( f2 )
  # [1] FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
  #[10] FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
  #[19] FALSE FALSE FALSE FALSE FALSE FALSE FALSE

and with
[3]
  (!is.na ( f1 )) + (!is.na ( f2 ))
  # [1] 1 1 2 2 1 2 1 2 2 2 1 1 2 2 1 2 2 1 2 2 2 2 2 2 2

In other words, I think you have been trapped by Precedence:
see '?Syntax'. What seems to happen is that

  is.na ( f1 ) + !is.na ( f2 )

evalutes is.na(f1) as a logical vector, !is.na(f2) as a logical
vector, and adds them getting a numerical result. See [1].

On the other hand, apparently

  !is.na ( f1 ) + !is.na ( f2 )

negates the result of [1] (compare the outputs of [1] and [2])
and hence produces a logical vector (because of the first "!").
In other words, the first "!" is applied to the result of
is.na ( f1 ) + !is.na ( f2 ).

In the form given in [3], the parentheses ensure that the logical
negations "!" are applied before the "+" is applied, so two logical
vectors are added, with a numerical result.

(I hope I've got this right)!
Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 13-Aug-09   Time: 20:50:51
-- XFMail --

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] using package tm to find phrases

2009-08-13 Thread Mark Kimpel
I am using the package "tm" for text-mining of abstracts and would like to
use it to find instances of gene names that may contain white space. For
instance "gene regulatory protein 1". The default behavior of tm is to parse
this into 4 separate words, but I would like to use the class constructor
"dictionary" to define phrases such as just mentioned.

Is this possible? If so, how?

Thanks,
Mark

Mark W. Kimpel MD  ** Neuroinformatics ** Dept. of Psychiatry
Indiana University School of Medicine

15032 Hunter Court, Westfield, IN  46074

(317) 490-5129 Work, & Mobile & VoiceMail

"The real problem is not whether machines think but whether men do." -- B.
F. Skinner
**

[[alternative HTML version deleted]]

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


[R] Data Envelopment Analysis

2009-08-13 Thread Thiagarajah Ramilan
Hi,
solict excuese if I am reposting I am not sure I properly posted the
previous message

In the past I have used a DEA package known as "FEAR" on R platform. I could
not see that package any more. Instead a new package is there DEA. I kindly
apreciate comments or recomendations.


Ramilan

[[alternative HTML version deleted]]

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


[R] Adding logical vectors

2009-08-13 Thread David Huffer
When adding several logical vectors I expect each vector will be
coerced to integers and these vectors will then be added.

That doesn't always seem to be the case.

For example:

  > ( f1 <- as.factor ( sample ( "x" , 25 , rep = T ) ) )
   [1] x x x x x x x x x x x x x x x x x x x x x x x x x
  Levels: x
  > ( f2 <- as.factor ( sample ( "y" , 25 , rep = T ) ) )
   [1] y y y y y y y y y y y y y y y y y y y y y y y y y
  Levels: y
  > ( f3 <- as.factor ( sample ( "z" , 25 , rep = T ) ) )
   [1] z z z z z z z z z z z z z z z z z z z z z z z z z
  Levels: z
  >
  > is.na ( f1 [ sample ( 1:25 , 4 ) ] ) <-
  + is.na ( f2 [ sample ( 1:25 , 4 ) ] ) <-
  + is.na ( f3 [ sample ( 1:25 , 4 ) ] ) <- TRUE
  >
  > ##  this returns a numeric vector:
  >
  > is.na ( f1 ) + is.na ( f2 ) + is.na ( f3 )
   [1] 0 0 0 0 0 1 1 0 0 0 1 0 0 1 0 0 1 0 1 2 2 0 1 0 1
  >
  > ##  but this returns a logical vector
  >
  > !is.na ( f1 ) + !is.na ( f2 ) + !is.na ( f3 )
   [1]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE
   [9]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE
  [17] FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE
  [25] FALSE
  >

Can someone please explain why the returned value is a logical
vector when I use the not operator but a numeric vector when I
don't.

What is special about the !is.na? it returns an object of class
logical just like the is.na function:

  > all.equal ( class ( !is.na ( f1 ) ) , class ( is.na ( f1 ) ) )
  [1] TRUE
  >

Thanks!

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


Re: [R] how to get R interpreter to remember constant values without using any memory location

2009-08-13 Thread Don MacQueen

Like Ben, I wonder what the reason for doing this is.

First of all, the amount of memory indicated by your example is so 
small I can't imagine it would make any difference. If you have such 
a large number of values that the amount of memory is significant -- 
and store them somewhere that isn't in memory (such as physical disk 
memory), then reading them into memory when you need to use them 
might affect performance a lot.


Environment variables use memory also -- it's just someone else's 
memory (the OS instead of R).


-Don

At 4:05 PM +0200 8/13/09,  wrote:

Maybe I expect too much from a non compiled language.
Anyway, I wonder whether it is possible in R to set constant values 
without using any memory location that would take useless space
bacause such values are not going to be changed along the program. 
It's just a way to assign a mnemnic name tos some constant values.
For instance, I would like R interpreter to replace all occurrences 
of mnemonic "Monday" with the number 1, "Tuesday"  with the number 
2, "Wednesday  with the number 3, and so on ...  without having to 
assign such values to memory locations.
Maybe environment variables are the way to go ? 


Thank you in advance for your advice,
Maura




tutti i telefonini TIM!


[[alternative HTML version deleted]]

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



--
--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 the n (number of observations) per conditional group

2009-08-13 Thread Dax
I found a work-around by just simply getting the sum of the
conditional values and dividing this by the mean. It's not elegant but
it works

On Aug 13, 3:11 pm, Dax  wrote:
> Hello all,
>
> I have a huge data set that I'm cleaning up a bit. I am extracted the
> means per condition, but also need to get the n. Strangely enough I am
> unable to find a function that could actually pull this off. I am
> unable to use replications or count the rows using nrow.
>
> What I am trying to obtain is the number of observations fitting
> something along the lines of "data$total[data$spp==1&data$gyro==1&data
> $salinity==0&data$day==i]"
>
> Can anyone help me?
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] glm.nb versus glm estimation of theta.

2009-08-13 Thread hesicaia

Hello,
 
I have a question regarding estimation of the dispersion parameter (theta)
for generalized linear models with the negative binomial error structure. As
I understand, there are two main methods to fit glm's using the nb error
structure in R: glm.nb() or glm() with the negative.binomial(theta) family.
Both functions are implemented through the MASS library. Fitting the model
using these two functions to the same data produces much different results
for me in terms of estimated theta and the coefficients, and I am not sure
why.

the following model:
mod<-glm.nb(count ~ year + season + time + depth,
link="log",data=dat,control=glm.control(maxit=100,trace=T))
estimates theta as 0.0109

while the following model:
mod2<-glm(count ~ year + season + time + depth,
family=negative.binomial(theta=100),link="log",data=dat,control=glm.control(maxit=100,trace=T))
will not accept 0.0109 as theta and instead estimates it as 1271 (these are
fisheries catch data and so are very overdispersed). 

Fitting a quasipoisson model also yields a large dispersion parameter
(1300). The models also produce different coefficients and P-values, which
is disconcerting. 

What am I doing wrong here? I've read through the help sections
(?negative.binomial,?glm.nb, and ?glm) but did not find any answers. 

Any help and/or input is greatly appreciated!
Daniel. 
-- 
View this message in context: 
http://www.nabble.com/glm.nb-versus-glm-estimation-of-theta.-tp24956438p24956438.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Need Advice: Considering Converting a Package from S3 to S4 -- reprise

2009-08-13 Thread Terry Therneau
I read the list in digest form which sometimes makes me late to respond.

Peter Dalgaard wrote:
 In all fairness, it should probably be noted that quite a few people 
swear BY S4 in addition to those who swear AT it.

  Lest I give the impression of only dislike -- the coxme package (major
rewrite nearly done, I'm now testing) depends heavily on the bdsmatrix
package which implements a very particular subset of sparse matrix
methods.  Coxme uses S3 classes, bdsmatrix use S4 classes, and I think I
made the right decision in both cases.  

  I'm glad people found the C++ reference enjoyable.
 Terry T.

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


Re: [R] psi not functioning in nlrob?

2009-08-13 Thread Keo Ormsby

I hadn't checked this, I only had used the default.
The problem stems from the reassigned weighs during nls iterations, 
where the psi.bisquare function can return some 0 weight values, which 
then returns some NaN values in the resid vector that is calculated by 
dividing residuals/weights.

Since the default na.action value is na.fail, this causes the nls to crash.
you can bypass this problem with
model3=nlrob(y~a1*x^a2,data=transient,psi=psi.bisquare, 
start=list(a1=0.02,a2=0.7), maxit=1000, na.action = na.omit)
but it will give you a lot of warning messages about a division of a 
different size vectors in -residuals(out)/sqrt(w), but will finish and 
calculate the parameters.
I don't know enough statistics to assure you that omiting values with 
weight=0 is sound from a mathematical standpoint, intuitively I would 
substitute them for 0.


Perhaps someone out there can help us with this?

Best wishes,
Keo.


Xiao Xiao escribió:

Thank you Keo!
After installing MASS the default "psi=psi.huber" is working now.
However I still can't get "psi=psi.bisquare" to work, and here's
another error message:
  

model3=nlrob(y~a1*x^a2,data=transient,psi=psi.bisquare, 
start=list(a1=0.02,a2=0.7),maxit=1000)


Error in na.fail.default(list(y = c(71.2600034232749, 148.175742933206,  :
  missing values in object

I don't know why there are missing values, I'm sure y is the right
length and there are no NAs in it. Could somebody help me with this
one please?

Thanks in advance,
Xiao
On Wed, Aug 12, 2009 at 11:47 PM, Keo
Ormsby wrote:
  

You have to install MASS package first.
Hope this does the trick.
Best,
Keo.

Xiao Xiao wrote:


Hi all,

I'm trying to fit a nonlinear regression by "nlrob":

 model3=nlrob(y~a1*x^a2,data=transient,psi=psi.bisquare,
start=list(a1=0.02,a2=0.7),maxit=1000)

However an error message keeps popping up saying that the function
psi.bisquare doesn't exist.

I also tried psi.huber, which is supposed to be the default for nlrob:

model3=nlrob(y~a1*x^a2,data=transient,psi=psi.huber,
start=list(a1=0.02,a2=0.7),maxit=1000)

But I still got the same error message - psi.huber doesn't exist.

Is the argument "psi" not available in nlrob?

Any help will be appreciated.

Best,
Xiao Xiao

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

  



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



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


Re: [R] shading between two smoothed curves

2009-08-13 Thread Bert Gunter
?polygon



Bert Gunter
Genentech Nonclinical Biostatisics

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Graves, Gregory
Sent: Thursday, August 13, 2009 11:17 AM
To: r-help@r-project.org
Subject: [R] shading between two smoothed curves

I have a set of 52 weekly values, one is the desired high lake stage for
a week, and the other is the desired low lake stage for each week.  It
looks like this:

 

week

High

Low

1

16

14.5

2

16

14.5

3

15.95

14.45

4

15.84

14.34

5

15.73

14.23

6

15.61

14.11

7

15.5

14

8

15.38

13.88

9

15.25

13.75

10

15.13

13.63




52

15

13.5

 

I can plot out two nice curves using the following code, but I can't
figure out how to shade in the area lying between the two curves.  I
also can't figure out how to adjust the line weight as lwd doesn't seem
to affect scatter.smooth.  Thanks in advance.

 

l=11  #lower ylim

h=17  #upper ylim

par(new=F)

good <- complete.cases(week, high) #get rid of the NA error and only
using non-missing pairs

par(new=T)

scatter.smooth(week[good], high[good],family = "gaussian",span = .2,
ylim=c(l,h), type='n', lwd=2, color="blue", ylab="", xlab="")  

good <- complete.cases(week, low) 

par(new=T)

scatter.smooth(week[good], low[good],family = "gaussian",span = .2,
ylim=c(l,h), type='n', lwd=2, color="red", ylab="Stage, feet",
xlab="Week of Year")  #loess, lower span makes more irregular

par(new=F)

 

Gregory A. Graves

Lead Scientist

Everglades REstoration COoordination and VERification (RECOVER) 

Watershed Division

South Florida Water Management District

Phones:  DESK: 561 / 682 - 2429 

 CELL:  561 / 719 - 8157

 

 


[[alternative HTML version deleted]]

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

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


Re: [R] how to get R interpreter to remember constant values without using any memory location

2009-08-13 Thread Ben Bolker



mauede wrote:
> 
> Maybe I expect too much from a non compiled language.
> Anyway, I wonder whether it is possible in R to set constant values
> without using any memory location that would take useless space 
> bacause such values are not going to be changed along the program. It's
> just a way to assign a mnemnic name tos some constant values.
> For instance, I would like R interpreter to replace all occurrences of
> mnemonic "Monday" with the number 1, "Tuesday"  with the number 2,
> "Wednesday  with the number 3, and so on ...  without having to assign
> such values to memory locations.
> Maybe environment variables are the way to go ?  
> 
> 

  It would help if you were a little bit more specific about what you wanted
to do and why.
My initial reaction is that this is exactly the thing that the "factor"
class in R is designed
to do -- maintain a list of unique names corresponding to integer codes, and
handle
them (almost) transparently.  (There are a few tricky aspects to dealing
safely/correctly
with factor conversions: see
http://wiki.r-project.org/rwiki/doku.php?id=tips:data-factors:factors )

  Ben Bolker
-- 
View this message in context: 
http://www.nabble.com/how-to-get-R-interpreter-to-remember-constant-values-without-using-any-memory-location-tp24955624p24956351.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Point-to-point Truncation with truncreg possible?

2009-08-13 Thread Vivek Ayer
Hi all,

Can you use the truncreg() function to do point-to-point truncation,
i.e., specify a different point=, for each point in your dataset. I
guess in that sense this would be a nonlinear fit.

Thanks,
Vivek

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 R interpreter to remember constant values without using any memory location

2009-08-13 Thread Ben Bolker



mauede wrote:
> 
> Maybe I expect too much from a non compiled language.
> Anyway, I wonder whether it is possible in R to set constant values
> without using any memory location that would take useless space 
> bacause such values are not going to be changed along the program. It's
> just a way to assign a mnemnic name tos some constant values.
> For instance, I would like R interpreter to replace all occurrences of
> mnemonic "Monday" with the number 1, "Tuesday"  with the number 2,
> "Wednesday  with the number 3, and so on ...  without having to assign
> such values to memory locations.
> Maybe environment variables are the way to go ?  
> 
> 

  It would help if you were a little bit more specific about what you wanted
to do and why.
My initial reaction is that this is exactly the thing that the "factor"
class in R is designed
to do -- maintain a list of unique names corresponding to integer codes, and
handle
them (almost) transparently.  (There are a few tricky aspects to dealing
safely/correctly
with factor conversions: see
http://wiki.r-project.org/rwiki/doku.php?id=tips:data-factors:factors )

  Ben Bolker
-- 
View this message in context: 
http://www.nabble.com/how-to-get-R-interpreter-to-remember-constant-values-without-using-any-memory-location-tp24955624p24956333.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] reading a string

2009-08-13 Thread Henrique Dallazuanna
Use readLines indeed.

On Thu, Aug 13, 2009 at 3:21 PM, Mohsen Jafarikia wrote:

> Hello All:
>
> I am having the following data file named "data.dat"
>
> Number of people
> Number of pets
> Age of trees
>
> ifn   <- "data.dat"
> dat <- read.table(ifn)
>
> colnames(dat)<-c("Variables")
>
> I want R to read all these in a string but when I ask R to read these,
> it gives me error because there more than one word in each line. Any
> comments to solve this problem?
>
> Thanks,
> Mohsen
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

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


Re: [R] how to get R interpreter to remember constant values without using any memory location

2009-08-13 Thread Ben Bolker



mauede wrote:
> 
> Maybe I expect too much from a non compiled language.
> Anyway, I wonder whether it is possible in R to set constant values
> without using any memory location that would take useless space 
> bacause such values are not going to be changed along the program. It's
> just a way to assign a mnemnic name tos some constant values.
> For instance, I would like R interpreter to replace all occurrences of
> mnemonic "Monday" with the number 1, "Tuesday"  with the number 2,
> "Wednesday  with the number 3, and so on ...  without having to assign
> such values to memory locations.
> Maybe environment variables are the way to go ?  
> 
> 

  It would help if you were a little bit more specific about what you wanted
to do and why.
My initial reaction is that this is exactly the thing that the "factor"
class in R is designed
to do -- maintain a list of unique names corresponding to integer codes, and
handle
them (almost) transparently.  (There are a few tricky aspects to dealing
safely/correctly
with factor conversions: see
http://wiki.r-project.org/rwiki/doku.php?id=tips:data-factors:factors )

  Ben Bolker
-- 
View this message in context: 
http://www.nabble.com/how-to-get-R-interpreter-to-remember-constant-values-without-using-any-memory-location-tp24955624p24956310.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] reading a string

2009-08-13 Thread Mohsen Jafarikia
Hello All:

I am having the following data file named "data.dat"

Number of people
Number of pets
Age of trees

ifn   <- "data.dat"
dat <- read.table(ifn)

colnames(dat)<-c("Variables")

I want R to read all these in a string but when I ask R to read these,
it gives me error because there more than one word in each line. Any
comments to solve this problem?

Thanks,
Mohsen

[[alternative HTML version deleted]]

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


[R] shading between two smoothed curves

2009-08-13 Thread Graves, Gregory
I have a set of 52 weekly values, one is the desired high lake stage for
a week, and the other is the desired low lake stage for each week.  It
looks like this:

 

week

High

Low

1

16

14.5

2

16

14.5

3

15.95

14.45

4

15.84

14.34

5

15.73

14.23

6

15.61

14.11

7

15.5

14

8

15.38

13.88

9

15.25

13.75

10

15.13

13.63




52

15

13.5

 

I can plot out two nice curves using the following code, but I can't
figure out how to shade in the area lying between the two curves.  I
also can't figure out how to adjust the line weight as lwd doesn't seem
to affect scatter.smooth.  Thanks in advance.

 

l=11  #lower ylim

h=17  #upper ylim

par(new=F)

good <- complete.cases(week, high) #get rid of the NA error and only
using non-missing pairs

par(new=T)

scatter.smooth(week[good], high[good],family = "gaussian",span = .2,
ylim=c(l,h), type='n', lwd=2, color="blue", ylab="", xlab="")  

good <- complete.cases(week, low) 

par(new=T)

scatter.smooth(week[good], low[good],family = "gaussian",span = .2,
ylim=c(l,h), type='n', lwd=2, color="red", ylab="Stage, feet",
xlab="Week of Year")  #loess, lower span makes more irregular

par(new=F)

 

Gregory A. Graves

Lead Scientist

Everglades REstoration COoordination and VERification (RECOVER) 

Watershed Division

South Florida Water Management District

Phones:  DESK: 561 / 682 - 2429 

 CELL:  561 / 719 - 8157

 

 


[[alternative HTML version deleted]]

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


Re: [R] how to get R interpreter to remember constant values without using any memory location

2009-08-13 Thread Ben Bolker



mauede wrote:
> 
> Maybe I expect too much from a non compiled language.
> Anyway, I wonder whether it is possible in R to set constant values
> without using any memory location that would take useless space 
> bacause such values are not going to be changed along the program. It's
> just a way to assign a mnemnic name tos some constant values.
> For instance, I would like R interpreter to replace all occurrences of
> mnemonic "Monday" with the number 1, "Tuesday"  with the number 2,
> "Wednesday  with the number 3, and so on ...  without having to assign
> such values to memory locations.
> Maybe environment variables are the way to go ?  
> 
> 

  It would help if you were a little bit more specific about what you wanted
to do and why.
My initial reaction is that this is exactly the thing that the "factor"
class in R is designed
to do -- maintain a list of unique names corresponding to integer codes, and
handle
them (almost) transparently.  (There are a few tricky aspects to dealing
safely/correctly
with factor conversions: see
http://wiki.r-project.org/rwiki/doku.php?id=tips:data-factors:factors )

  Ben Bolker
-- 
View this message in context: 
http://www.nabble.com/how-to-get-R-interpreter-to-remember-constant-values-without-using-any-memory-location-tp24955624p24956298.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] some help with plotting a beautiful structure using rgl

2009-08-13 Thread Nair, Murlidharan T
Ok, I was able to figure out one part by using rgl.spheres. I am still trying 
to insert text using rgl.texts. Does any one have a simple example? 


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Nair, Murlidharan T
Sent: Thursday, August 13, 2009 1:01 PM
To: r-help@r-project.org
Subject: [R] some help with plotting a beautiful structure using rgl

Hi!!

I need some help in using the correct required symbol when plotting my DNA 
structure  using rgl. I need to plot one strand using empty circles and the 
other using filled circles and if possible have sequence in the center.
I tried using pch and lty but have not been able to get it to do what I want. I 
am appending my code below. I have inserted comments when I need help.
Thanks../Murli
 
library(rgl)
library(scatterplot3d)
computed.DNA.Str<-structure(list(X = 1:42, x = c(-0.975688, 4.652834982, 
8.346905102, 
8.792265494, 5.763378778, 0.360110242, -5.410741675, -9.545558939, 
-10.41359287, -7.820469283, -2.87048497, 2.431822597, 5.780004735, 
5.864231475, -0.975688, -6.231531328, -9.096244856, -8.635565445, 
-4.93169249, 0.543553939, 5.641749313, 8.344319111, 7.415095348, 
3.257938171, -2.65307139, -8.1739403, -11.27397708, -11.05239614, 
0, 0, -0.074701006, -0.224103017, -0.373505029, -0.522907041, 
-0.672309052, -0.895991523, -1.193954453, -1.491917383, -1.789880313, 
-2.087843243, -2.459247906, -2.904094302), y = c(9.258795, 8.06401752, 
4.005465268, -1.499800943, -6.27267078, -8.411524903, -7.02084845, 
-2.355659798, 3.731366626, 9.104012958, 11.86675929, 11.12097881, 
7.538500525, 2.530292144, -9.258795, -6.917027485, -1.948188504, 
3.969960475, 8.447831953, 9.853576509, 7.728792788, 2.983125505, 
-2.290127499, -6.144106768, -6.950074829, -4.243530894, 1.04920276, 
7.296442545, 0, 0, 0.102817114, 0.308451342, 0.514085569, 0.719719797, 
0.925354025, 1.233226533, 1.643337323, 2.053448113, 2.463558902, 
2.873669692, 3.384864355, 3.997142893), z = c(-1.8, -5.19, -8.715110209, 
-12.46924956, -16.02528991, -19.31616462, -22.3760913, -25.15391125, 
-27.76053562, -30.76224274, -34.29278833, -38.28392979, -42.58508407, 
-47.00216668, 1.8, -1.59, -4.696196709, -7.756123397, -11.04699811, 
-14.60303845, -18.3571778, -22.4500669, -26.44120835, -29.97175395, 
-32.97346107, -35.58008544, -37.79845079, -40.14850635, 0, -3.39, 
-6.775228801, -10.1556864, -13.53614401, -16.91660161, -20.29705921, 
-23.66323008, -27.01511421, -30.36699834, -33.71888247, -37.07076661, 
-40.3989289, -43.70336934), seq = structure(c(2L, 2L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 
1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 1L, 1L), .Label = c("A", "T"), class = "factor")), .Names = 
c("X", 
"x", "y", "z", "seq"), class = "data.frame", row.names = c(NA, 
-42L))

dnaStr<-as.data.frame(computed.DNA.Str)
endPtlength<-length(dnaStr$x)
endPt1<-endPtlength/3
###
#The following code ensures that DNA is plotted in a cube
maxX<-max(dnaStr$x)
minX<-min(dnaStr$x)
minY<-min(dnaStr$y)
maxY<-max(dnaStr$y)
minZ<-min(dnaStr$z)
maxZ<-max(dnaStr$z)
difX<-abs(maxX-minX)
difY<-abs(maxY-minY)
difZ<-abs(maxZ-minZ)
angStrong<-round(max(difX,difY,difZ))
angStrongX<-(angStrong-difX)/2
angStrongY<-(angStrong-difY)/2
angStrongZ<-(angStrong-difZ)/2
minX<-minX-angStrongX
maxX<-maxX+angStrongX
minY<-minY-angStrongY
maxY<-maxY+angStrongY
minZ<-minZ-angStrongZ
maxZ<-maxZ+angStrongZ
###
#Plotting using rgl
###
#I would like to plot the following line using circles that are not filled

plot3dOut<-plot3d(dnaStr$x[1:endPt1],dnaStr$y[1:endPt1],dnaStr$z[1:endPt1], 
col="black", size=3, box=FALSE, axes=FALSE, lty="o", 
  xlim=c(minX,maxX), ylim=c(minY,maxY),zlim=c(minZ,maxZ), 
xlab="",ylab="",zlab="")


#I would like to plot the following lines using filled circles

points3d(dnaStr$x[(endPt1+1):(endPt1*2)],dnaStr$y[(endPt1+1):(endPt1*2)],dnaStr$z[(endPt1+1):(endPt1*2)],
 box=FALSE, col="black", axes=FALSE, size=3, pch=21)

#This is the center line, is it possible to put the sequence here using lty

lines3d(dnaStr$x[(endPt1*2+1):(endPtlength)],dnaStr$y[(endPt1*2+1):(endPtlength)],dnaStr$z[(endPt1*2+1):(endPtlength)],
 box=FALSE, col="black",axes=FALSE,size =1)
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

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

Re: [R] Fitting a quasipoisson distribution to univariate data

2009-08-13 Thread Achim Zeileis

On Thu, 13 Aug 2009, Nigel Harding wrote:


Dear all,
I am analyzing counts of seabirds made from line transects at sea.

I have been fitting Poisson and negative binomial distributions to the data
using the goodfit function from the vcd library. I would also like to
evaluate how well a quasi-poisson distribution fits the data. However, none
of the potentially suitable functions I have identified (goodfit(vcd),
fitdistr(MASS), fit.dist(gnlm)) includes the quasipoisson distribution as
one of their standard named distributions. Is the way forward to supply an
appropriate density function to fitdistr, or is there some easier way to fit
a quasipoisson distribution?


The quasi-Poisson model is not a likelihood model but a quasi-likelihood 
model. Thus, you specify mean and variance function but leave the rest of 
the likelihood unspecified. Therefore, there is no density function with 
predicted probabilities for each count etc.


The easiest way to fit that is to use glm(y ~ 1) which essentially 
computes mean(y) plus a dispersion parameter based on the residual sum of 
squares. For a discussion of Poisson, quasi-Poisson, negative binomial, 
zero-inflated and hurdle count regression models, you can look at:

  http://www.jstatsoft.org/v27/i08/

hth,
Z



Many thanks

Nigel Harding
Craigton Ecological Services
48 Craigend Drive West
Milngavie
Glasgow G62 7BG
T: 0141 956 4636
M: 07980 479261

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




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


[R] multiple downloads of data when evaluating plot() vs. xyplot()

2009-08-13 Thread Greg Hirson
I have noticed an interesting behavior when comparing how the base 
plot() function deals with a data argument that downloads data from the 
internet vs. how xyplot() in lattice performs the same task.


The goal is to plot hourly temperature data. The data is downloaded and 
formatted for R using the function cimishourly() in the package cimis. 
There is a line within the function that outputs the name of the file 
being downloaded using cat().


When using plot() to plot the data, the following is written to the console:

library(cimis)
plot(air_temp ~ datetime, data = cimishourly("006"))
Downloading:  ftp://ftpcimis.water.ca.gov/pub/hourly/hourly006.csv
Downloading:  ftp://ftpcimis.water.ca.gov/pub/hourly/hourly006.csv

When using xyplot() to perform the same plot, the data is only 
downloaded once:


library(lattice)
xyplot(air_temp ~ datetime, data = cimishourly("006"))
Downloading:  ftp://ftpcimis.water.ca.gov/pub/hourly/hourly006.csv

Is this caused by a difference in how the two functions evaluate the 
data argument?


Even more interesting, when adding a type = "l" argument to plot, the 
data is downloaded 3 times.


Thank you for your time,

Greg

--
Greg Hirson
ghir...@ucdavis.edu

Graduate Student
Agricultural and Environmental Chemistry

1106 Robert Mondavi Institute North
One Shields Avenue
Davis, CA 95616

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Fitting a quasipoisson distribution to univariate data

2009-08-13 Thread Nigel Harding
Dear all,
I am analyzing counts of seabirds made from line transects at sea.

I have been fitting Poisson and negative binomial distributions to the data
using the goodfit function from the vcd library. I would also like to
evaluate how well a quasi-poisson distribution fits the data. However, none
of the potentially suitable functions I have identified (goodfit(vcd),
fitdistr(MASS), fit.dist(gnlm)) includes the quasipoisson distribution as
one of their standard named distributions. Is the way forward to supply an
appropriate density function to fitdistr, or is there some easier way to fit
a quasipoisson distribution?

Many thanks

Nigel Harding
Craigton Ecological Services
48 Craigend Drive West
Milngavie
Glasgow G62 7BG
T: 0141 956 4636
M: 07980 479261

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


Re: [R] split number in a vector and then make a chron object out of it

2009-08-13 Thread Gabor Grothendieck
Try this:

as.chron(date.time, "%Y%m%d%H%M%S")


On Thu, Aug 13, 2009 at 12:59 PM, stephen sefick wrote:
> These are date and times in the format MMDDhhmmss.  I would like
> to take this column and make a chron object form them.  I have tried a
> couple of the split family of functions but they need character input
>
> here is the data:
>
> date.time <- c(19851001001500, 19851001003000, 19851001004500, 1985100101,
> 19851001011500, 19851001013000, 19851001014500, 1985100102,
> 19851001021500, 19851001023000, 19851001024500, 1985100103,
> 19851001031500, 19851001033000, 19851001034500, 1985100104,
> 19851001041500, 19851001043000, 19851001044500, 1985100105,
> 19851001051500, 19851001053000, 19851001054500, 1985100106,
> 19851001061500, 19851001063000, 19851001064500, 1985100107,
> 19851001071500, 19851001073000)
>
>
> thanks for the help,
> --
> Stephen Sefick
>
> Let's not spend our time and resources thinking about things that are
> so little or so large that all they really do for us is puff us up and
> make us feel like gods.  We are mammals, and have not exhausted the
> annoying little problems of being mammals.
>
>                                                                -K. Mullis
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] xyplot and subscripts

2009-08-13 Thread Deepayan Sarkar
On Thu, Aug 6, 2009 at 7:27 AM, Kito Palaxou wrote:
>
> Hi all,
>
> I have a data frame like this:
>
> DF <- data.frame(x = rnorm(10), y = rnorm(10), gr = rep(1:5, 2))
>
> and I make the following xy-plot:
>
> library(lattice)
> xyplot(y ~ x, data = DF, groups = gr, type = "b", col = 1)
>
>
> Is it possible that the two points that belong to the same group specified by
> DF$gr to have a different color -- that is for each pair of points connected 
> by
> the line, I want one to be black and the other red. I tried:

[Sorry for the late reply, I seem to have missed your mail before.]

You will need to handle color in a custom panel.groups function:

xyplot(y ~ x, data = DF, groups = gr, type = "b",
   panel = panel.superpose,
   panel.groups = function(x, y, ...) {
   panel.lines(x, y, col = "black")
   panel.points(x, y, pch = 16, col = c("black", "red"))
   })

-Deepayan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Efficiently Extracting Meta Data from TM Corpora

2009-08-13 Thread Shad Thomas

I'm using text miner (the "tm" package) to process large numbers of blog and 
message board postings (about 245,000). Does anyone have any advice for how to 
efficiently extract the meta data from a corpus of this size? 

TM does a great job of using MPI for many functions (e.g. tmMap) which greatly 
speed up the processing. However, the "meta" function that I need does not take 
advantage of MPI. 

I have two ideas: 
1) Find a way of running the meta function in parallel mode. Specifically, the 
code that I'm running is: 
urllist <- lapply(workingcorpus, meta, tag = "FeedUrl") 
Unfortunately, I receive the following error message when I try to use the 
command "parLapply" 
"Error in checkCluster(cl) : not a valid cluster 
Calls: parLapply ... is.vector -> clusterApply -> staticClusterApply -> 
checkCluster" 

2) Alternatively, I wonder if there might be a way of extracting all of the 
meta data into a data.frame that would be faster for processing? 

Thanks for any suggestions or ideas! 
Shad 


shad thomas | president | glass box research company | +1 (312) 451-3611 tel | 
shad.tho...@glassboxresearch.com | www.glassboxresearch.com 

[[alternative HTML version deleted]]

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


Re: [R] How to get the n (number of observations) per conditional group

2009-08-13 Thread John Kane
?length

--- On Thu, 8/13/09, Dax  wrote:

> From: Dax 
> Subject: [R] How to get the n (number of observations) per conditional group
> To: r-help@r-project.org
> Received: Thursday, August 13, 2009, 10:11 AM
> Hello all,
> 
> I have a huge data set that I'm cleaning up a bit. I am
> extracted the
> means per condition, but also need to get the n. Strangely
> enough I am
> unable to find a function that could actually pull this
> off. I am
> unable to use replications or count the rows using nrow.
> 
> What I am trying to obtain is the number of observations
> fitting
> something along the lines of
> "data$total[data$spp==1&data$gyro==1&data
> $salinity==0&data$day==i]"
> 
> Can anyone help me?
> 
> __
> R-help@r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
> 


  __
[[elided Yahoo spam]]

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


Re: [R] SOLVED: Lattice: How to do error bars

2009-08-13 Thread Deepayan Sarkar
On Wed, Aug 12, 2009 at 7:19 AM,  wrote:
> Thank you Gerrit,
>
> Your suggestion proved right after all:
>
> This does put error bars (dy) on the points. You only need to figure out
> the proper y axis scaling.
>
>> xyplot(y~x|f,data=xy,groups=dy,panel=function(x,y,groups,subscripts,...)
> {panel.xyplot(x,y,...)
> ;panel.segments(x,y+groups[subscripts],x,y-groups[subscripts],...)})

You might also want to check out the segplot function in latticeExtra
(it has a few rough edges, but should mostly work).

-Deepayan

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


Re: [R] split number in a vector and then make a chron object out of it

2009-08-13 Thread John Kane
I'm not sure that I understand your problem but if you want the vector in 
character rather than numeric try: 

library(Hmisc)
library(Hmisc)
time.date<- Cs(19851001001500, 19851001003000, 19851001004500, 1985100101,
19851001011500, 19851001013000, 19851001014500, 1985100102,
19851001021500, 19851001023000, 19851001024500, 1985100103,
19851001031500, 19851001033000, 19851001034500, 1985100104,
19851001041500, 19851001043000, 19851001044500, 1985100105,
19851001051500, 19851001053000, 19851001054500, 1985100106,
19851001061500, 19851001063000, 19851001064500, 1985100107,
19851001071500, 19851001073000)


--- On Thu, 8/13/09, stephen sefick  wrote:

> From: stephen sefick 
> Subject: [R] split number in a vector and then make a chron object out of it
> To: r-help@r-project.org
> Received: Thursday, August 13, 2009, 12:59 PM
> These are date and times in the
> format MMDDhhmmss.  I would like
> to take this column and make a chron object form
> them.  I have tried a
> couple of the split family of functions but they need
> character input
> 
> here is the data:
> 
> date.time <- c(19851001001500, 19851001003000,
> 19851001004500, 1985100101,
> 19851001011500, 19851001013000, 19851001014500,
> 1985100102,
> 19851001021500, 19851001023000, 19851001024500,
> 1985100103,
> 19851001031500, 19851001033000, 19851001034500,
> 1985100104,
> 19851001041500, 19851001043000, 19851001044500,
> 1985100105,
> 19851001051500, 19851001053000, 19851001054500,
> 1985100106,
> 19851001061500, 19851001063000, 19851001064500,
> 1985100107,
> 19851001071500, 19851001073000)
> 
> 
> thanks for the help,
> -- 
> Stephen Sefick
> 
> Let's not spend our time and resources thinking about
> things that are
> so little or so large that all they really do for us is
> puff us up and
> make us feel like gods.  We are mammals, and have not
> exhausted the
> annoying little problems of being mammals.
> 
>            
>            
>         -K. Mullis
> 
> __
> R-help@r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
> 


  __
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/

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


Re: [R] split number in a vector and then make a chron object out of it

2009-08-13 Thread Henrique Dallazuanna
Try this:

strptime(date.time, "%Y%m%d%H%M%s")

On Thu, Aug 13, 2009 at 1:59 PM, stephen sefick  wrote:

> These are date and times in the format MMDDhhmmss.  I would like
> to take this column and make a chron object form them.  I have tried a
> couple of the split family of functions but they need character input
>
> here is the data:
>
> date.time <- c(19851001001500, 19851001003000, 19851001004500,
> 1985100101,
> 19851001011500, 19851001013000, 19851001014500, 1985100102,
> 19851001021500, 19851001023000, 19851001024500, 1985100103,
> 19851001031500, 19851001033000, 19851001034500, 1985100104,
> 19851001041500, 19851001043000, 19851001044500, 1985100105,
> 19851001051500, 19851001053000, 19851001054500, 1985100106,
> 19851001061500, 19851001063000, 19851001064500, 1985100107,
> 19851001071500, 19851001073000)
>
>
> thanks for the help,
> --
> Stephen Sefick
>
> Let's not spend our time and resources thinking about things that are
> so little or so large that all they really do for us is puff us up and
> make us feel like gods.  We are mammals, and have not exhausted the
> annoying little problems of being mammals.
>
>-K. Mullis
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

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


[R] some help with plotting a beautiful structure using rgl

2009-08-13 Thread Nair, Murlidharan T
Hi!!

I need some help in using the correct required symbol when plotting my DNA 
structure  using rgl. I need to plot one strand using empty circles and the 
other using filled circles and if possible have sequence in the center.
I tried using pch and lty but have not been able to get it to do what I want. I 
am appending my code below. I have inserted comments when I need help.
Thanks../Murli
 
library(rgl)
library(scatterplot3d)
computed.DNA.Str<-structure(list(X = 1:42, x = c(-0.975688, 4.652834982, 
8.346905102, 
8.792265494, 5.763378778, 0.360110242, -5.410741675, -9.545558939, 
-10.41359287, -7.820469283, -2.87048497, 2.431822597, 5.780004735, 
5.864231475, -0.975688, -6.231531328, -9.096244856, -8.635565445, 
-4.93169249, 0.543553939, 5.641749313, 8.344319111, 7.415095348, 
3.257938171, -2.65307139, -8.1739403, -11.27397708, -11.05239614, 
0, 0, -0.074701006, -0.224103017, -0.373505029, -0.522907041, 
-0.672309052, -0.895991523, -1.193954453, -1.491917383, -1.789880313, 
-2.087843243, -2.459247906, -2.904094302), y = c(9.258795, 8.06401752, 
4.005465268, -1.499800943, -6.27267078, -8.411524903, -7.02084845, 
-2.355659798, 3.731366626, 9.104012958, 11.86675929, 11.12097881, 
7.538500525, 2.530292144, -9.258795, -6.917027485, -1.948188504, 
3.969960475, 8.447831953, 9.853576509, 7.728792788, 2.983125505, 
-2.290127499, -6.144106768, -6.950074829, -4.243530894, 1.04920276, 
7.296442545, 0, 0, 0.102817114, 0.308451342, 0.514085569, 0.719719797, 
0.925354025, 1.233226533, 1.643337323, 2.053448113, 2.463558902, 
2.873669692, 3.384864355, 3.997142893), z = c(-1.8, -5.19, -8.715110209, 
-12.46924956, -16.02528991, -19.31616462, -22.3760913, -25.15391125, 
-27.76053562, -30.76224274, -34.29278833, -38.28392979, -42.58508407, 
-47.00216668, 1.8, -1.59, -4.696196709, -7.756123397, -11.04699811, 
-14.60303845, -18.3571778, -22.4500669, -26.44120835, -29.97175395, 
-32.97346107, -35.58008544, -37.79845079, -40.14850635, 0, -3.39, 
-6.775228801, -10.1556864, -13.53614401, -16.91660161, -20.29705921, 
-23.66323008, -27.01511421, -30.36699834, -33.71888247, -37.07076661, 
-40.3989289, -43.70336934), seq = structure(c(2L, 2L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 
1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 1L, 1L), .Label = c("A", "T"), class = "factor")), .Names = 
c("X", 
"x", "y", "z", "seq"), class = "data.frame", row.names = c(NA, 
-42L))

dnaStr<-as.data.frame(computed.DNA.Str)
endPtlength<-length(dnaStr$x)
endPt1<-endPtlength/3
###
#The following code ensures that DNA is plotted in a cube
maxX<-max(dnaStr$x)
minX<-min(dnaStr$x)
minY<-min(dnaStr$y)
maxY<-max(dnaStr$y)
minZ<-min(dnaStr$z)
maxZ<-max(dnaStr$z)
difX<-abs(maxX-minX)
difY<-abs(maxY-minY)
difZ<-abs(maxZ-minZ)
angStrong<-round(max(difX,difY,difZ))
angStrongX<-(angStrong-difX)/2
angStrongY<-(angStrong-difY)/2
angStrongZ<-(angStrong-difZ)/2
minX<-minX-angStrongX
maxX<-maxX+angStrongX
minY<-minY-angStrongY
maxY<-maxY+angStrongY
minZ<-minZ-angStrongZ
maxZ<-maxZ+angStrongZ
###
#Plotting using rgl
###
#I would like to plot the following line using circles that are not filled

plot3dOut<-plot3d(dnaStr$x[1:endPt1],dnaStr$y[1:endPt1],dnaStr$z[1:endPt1], 
col="black", size=3, box=FALSE, axes=FALSE, lty="o", 
  xlim=c(minX,maxX), ylim=c(minY,maxY),zlim=c(minZ,maxZ), 
xlab="",ylab="",zlab="")


#I would like to plot the following lines using filled circles

points3d(dnaStr$x[(endPt1+1):(endPt1*2)],dnaStr$y[(endPt1+1):(endPt1*2)],dnaStr$z[(endPt1+1):(endPt1*2)],
 box=FALSE, col="black", axes=FALSE, size=3, pch=21)

#This is the center line, is it possible to put the sequence here using lty

lines3d(dnaStr$x[(endPt1*2+1):(endPtlength)],dnaStr$y[(endPt1*2+1):(endPtlength)],dnaStr$z[(endPt1*2+1):(endPtlength)],
 box=FALSE, col="black",axes=FALSE,size =1)
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] split number in a vector and then make a chron object out of it

2009-08-13 Thread stephen sefick
These are date and times in the format MMDDhhmmss.  I would like
to take this column and make a chron object form them.  I have tried a
couple of the split family of functions but they need character input

here is the data:

date.time <- c(19851001001500, 19851001003000, 19851001004500, 1985100101,
19851001011500, 19851001013000, 19851001014500, 1985100102,
19851001021500, 19851001023000, 19851001024500, 1985100103,
19851001031500, 19851001033000, 19851001034500, 1985100104,
19851001041500, 19851001043000, 19851001044500, 1985100105,
19851001051500, 19851001053000, 19851001054500, 1985100106,
19851001061500, 19851001063000, 19851001064500, 1985100107,
19851001071500, 19851001073000)


thanks for the help,
-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 3-D surface graph from lmer mixed models?

2009-08-13 Thread Deepayan Sarkar
On Thu, Aug 13, 2009 at 6:34 AM, willow1980 wrote:
>
> Dear Professor Murdoch,
> That is exactly the difficulty for me. I don't know how to make a prediction
> with lmer using "expand.grid"; at the moment, I can use
> “mo...@x%*%fixef(model)” to get predicted values for existing observational
> data, but not data by "expand.grid". Actually, if I know this, I can then
> use "persp" or "wireframe" to plot 3-D surface graph. Do you know or have
> available code for this aim?

?lattice::levelplot has an example of this (using a loess() fit), that
applies to wireframe as well.

-Deepayan

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

2009-08-13 Thread Moreno Mancosu

Hello all!

Maybe it's a newbie question(in fact I _am_, a newbie), but I hope 
you'll find the solution.

I have an equation system which has k equation and n variables (kI would like to obtain a description of the solutions (which can be the 
equation of lines or a plane, or everything else) with the lesser degree 
of freedom, obviously using R.
In other words, I would like to obtain a result which is very similar to 
the results of Maxima or similar software.
I tried to search on internet and i found the systemfit package, but I 
think it is not related with my problem.

Any idea?

Thanks in advance,

Moreno

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


Re: [R] FW: R graphics

2009-08-13 Thread Achim Zeileis



On Thu, 13 Aug 2009, Mcdonald, Grant wrote:




From: Mcdonald, Grant
Sent: 13 August 2009 13:08
To: r-help@R-project.org
Subject: R graphics

Dear sir,

I am trying to create a barplot showing propotions,

So my data is in the format of a vector containing 0s and 1s (i.e.successful or 
not) with a corresponding vector with two  catogorical levels.

successage
1 old
0young
0 young
1 old

I want to show a bar plot with a ylim=c(0,1) and an x-axis showing the two ages 
and the proportion of success only as filled bars.

after making success a factor and plotting against age using: plot(success~age)

the graphic shows age on the x and proportion on the yaxis as i want.  However 
for each age it shows the total proportion split into both success and 
failures.  I would however just like to show the prop successes without the 
failures stajed on top.


You can play around with the graphical parameters of ?spineplot. For 
example, I copied your data into a "dat.txt" file and read the data via


  ## read data
  dat <- read.table("dat.txt", header = TRUE)

  ## transform labels
  dat$successful <- factor(dat$successful, levels = 1:0, labels =
c("success", "failure"))
  dat$maleage <- factor(dat$maleage, labels = c("old", "young"))

And then you can produce various types of plots changing color, labeling 
etc.


  ## simple spine plot
  plot(successful ~ maleage, data = dat)

  ## hide failures and suppress y-axis labels
  plot(successful ~ maleage, data = dat, col = gray(c(0.3, 1)),
border = "transparent", yaxlabels = "")

Or you can also use barplot() and create this by hand:

  ## create table
  tab <- xtabs(~ maleage + successful, data = dat)

  ## simple barplot of success proportions
  barplot(prop.table(tab, 1)[,1])

  ## barplot with proportional x-axis and labeling etc.
  barplot(prop.table(tab, 1)[,1], width = margin.table(tab, 1),
col = gray(0.3), space = 0.1, ylim = c(0, 1),
ylab = "proportion of succsess")

hth,
Z


data frame is below:

successful  maleage
1   O
1   Y
1   Y
1   Y
1   O
1   O
1   Y
1   O
1   Y
1   O
1   O
1   Y
1   O
1   Y
1   Y
1   Y
1   O
1   O
1   Y
1   Y
1   O
1   Y
1   O
1   Y
1   Y
1   Y
1   O
1   Y
1   Y
1   O
1   Y
1   O
1   O
1   Y
1   O
1   Y
1   O
1   Y
1   Y
1   O
1   Y
1   Y
1   O
1   Y
1   Y
1   Y
1   O
1   O
1   Y
1   O
1   Y
1   Y
1   Y
1   Y
1   Y
1   Y
1   Y
1   Y
1   Y
1   O
1   Y
1   O
1   Y
1   Y
1   O
1   O
1   Y
1   Y
1   O
1   Y
1   O
1   Y
1   Y
1   Y
1   O
1   Y
1   O
1   Y
1   Y
1   Y
1   O
1   Y
1   O
1   Y
1   Y
1   O
1   Y
1   Y
1   O
1   O
1   Y
1   Y
1   Y
1   O
0   Y
NA  O
0   O
NA  Y
1   Y
1   O
NA  O
NA  Y
0   O
NA  Y
0   O
NA  Y
1   Y
1   O
0   O
0   Y
NA  O
0   Y
NA  O
0   Y
0   Y
NA  O
NA  O
NA  O
NA  Y
NA  Y
0   O
NA  O
NA  Y
NA  O
1   O
0   O
0   Y
NA  O
NA  Y
1   O
0   O
0   O
0   O
NA  Y
0   O
0   Y
NA  Y
0   O
NA  O
0   Y
NA  O
1   O
0   Y
NA  O
NA  O
NA  O
0   O
0   O
0   O
0   Y
0   O
0   O
0   O
0   Y
NA  O
0   Y
0   O
NA  Y
NA  O
0   O
NA  Y
NA  O
0   O
NA  O
NA  O
0   O
NA  Y
NA  O
NA  Y
0   O
NA  O
1   Y
NA  Y
NA  O
1   O
1   Y
0   O
0   Y
0   O
0   Y
0   Y
1   Y

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




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


Re: [R] paste first row string onto every string in column

2009-08-13 Thread Gene Leynes
I'm also a newbie, but I've been getting loads of utility out of the "grep"
function and it's cousin "gsub".

Using asterisks are tricky because * often means "anything of any length" in
a search pattern (e.g. delete *.* means delete all your files!).  To find
the literal * using grep you would need to put some \'s in front of *, so
that R knows you mean the character * and not "anything of any length".
eg:
> txt=c('a','a*')
> txt
[1] "a"  "a*"
> grep('\\*',txt) # tell me, where is the star?
[1] 2
> gsub('\\*', ' success',txt)  #Replace the star with " success"
[1] "a""a success"

However, with the grep/gsub commands there are some other important symbols:
^Pattern occurs at beginning
$Pattern occurs at end
.Means "anything", but only once
+Preceeding character occurs more than once... so
.+   Means "anything, more than once"

So, to strip off everything up to the first *, I would try something like
this:
> txt=c('aa*very important','a*important')
> txt
[1] "aa*very important" "a*important"
> gsub('^.+\\*', 'success',txt)
[1] "successvery important" "successimportant"

On Wed, Aug 12, 2009 at 11:06 AM, Jill Hollenbach wrote:

>
> Thanks so much everybody, this has been incredibly helpful--not only is my
> immediate issue solved but I've learned a lot in the process. The lapply
> solution is best for me, as I need flexibility to edit df's with varying
> numbers of columns.
>
> Now, one more question: after appending the string from the first line, I
> am
> manipulating the df further(recoding the original contents; this I have
> working fine), and afterwards I will need to strip back off that string. It
> seems relatively straightforward, except that, as shown in the example
> above
> (df2), there is an astersik involved (I need to remove all characters up to
> and including the asterisk) which seems problematic.
> Any suggestions?
> Many thanks,
> Jill
>
>
>
> Don MacQueen wrote:
> >
> > Let's start with something simple and relatively easy to understand,
> > since you're new to this.
> >
> > First, here's an example of the core of the idea:
> >>  paste('a',1:4)
> > [1] "a 1" "a 2" "a 3" "a 4"
> >
> > Make it a little closer to your situation:
> >>  paste('a*',1:4, sep='')
> > [1] "a*1" "a*2" "a*3" "a*4"
> >
> > Sometimes it helps to save the number of rows in your dataframe in a
> > new variable
> >
> > nr <- nrow(df)
> >
> > Then, for your first column, the "a*" in the above example is df$V1[1]
> > For the 1:4 in the example, you use  df$V1[ 2:nr]
> > Put it together and you have:
> >
> > dfnew <- df
> > dfnew$V1[ 2:nr] <- paste( dfnew$V1[1], dfnew$V1[ 2:nr] )
> >
> > But you can use "-1" instead of "2:nr", and you get
> >
> >dfnew$V1[ -1 ] <- paste( dfnew$V1[1], dfnew$V1[ -1] )
> >
> > That's how you can do it one column at a time.
> > Since you have only four columns, just do the same thing to V2, V3, and
> > V4.
> >
> > But if you want a more general method, one that works no matter how
> > many columns you have, and no matter what they are named, then you
> > can use lapply() to loop over the columns. This is what Patrick
> > Connolly suggested, which is
> >
> > as.data.frame(lapply(df, function(x) paste(x[1], x[-1], sep = "")))
> >
> > Note, though, that this will do it to all columns, so if you ever
> > happen to have a dataframe where you don't want to do all columns,
> > you'll have to be a little trickier with the lapply() solution.
> >
> > -Don
> >
> > At 6:48 PM -0700 8/11/09, Jill Hollenbach wrote:
> >>Hi,
> >>I am trying to edit a data frame such that the string in the first line
> is
> >>appended onto the beginning of each element in the subsequent rows. The
> data
> >>looks like this:
> >>
> >>>  df
> >>   V1   V2   V3   V4
> >>1   DPA1* DPA1* DPB1* DPB1*
> >>2   0103 0104 0401 0601
> >>3   0103 0103 0301 0402
> >>.
> >>.
> >>  and what I want is this:
> >>
> >>>dfnew
> >>   V1   V2   V3   V4
> >>1   DPA1* DPA1* DPB1* DPB1*
> >>2   DPA1*0103 DPA1*0104 DPB1*0401 DPB1*0601
> >>3   DPA1*0103 DPA1*0103 DPB1*0301 DPB1*0402
> >>
> >>any help is much appreciated, I am new to this and struggling.
> >>Jill
> >>
> >>___
> >>  Jill Hollenbach, PhD, MPH
> >> Assistant Staff Scientist
> >> Center for Genetics
> >> Children's Hospital Oakland Research Institute
> >> jhollenb...@chori.org
> >>
> >>--
> >>View this message in context:
> >>http://*www.*
> nabble.com/paste-first-row-string-onto-every-string-in-column-tp24928720p24928720.html
> >>Sent from the R help mailing list archive at Nabble.com.
> >>
> >>__
> >>R-help@r-project.org mailing list
> >>https://*stat.ethz.ch/mailman/listinfo/r-help
> >>PLEASE do read the posting guide
> http://*www.*R-project.org/posting-guide.html
> >>and provide commented, minimal, self-contained, reproducible code.
> >
> >
> > --
> > --
> > Don MacQueen
> > Environmental Protection Department
> > Lawrence Livermore Natio

Re: [R] metafor random effects meta-analysis

2009-08-13 Thread Viechtbauer Wolfgang (STAT)
Correct, it is not possible to fix the residual variance to 1 in the R version 
of lme(), which is what one (typically) wants to do in meta-analyses, where the 
sampling variances are assumed to be (approximately) known. This is however 
possible in S-Plus, if you have access to that. Adding:

control=lmeControl(sigma = 1)

to the lme() call will do the trick.

If that is not an option, then metafor will also not be a solution currently. 
The model you have in mind is more complicated than the one assumed by the 
rma.uni() function.

Let me see if I correctly understand the model. Let es_ij be the observed 
effect size for the ith species in the jth study. Take the example:

es_11 = mu + u_1 + v_1 + e_11
es_21 = mu + u_2 + v_1 + e_21
es_31 = mu + u_3 + v_1 + e_31
es_22 = mu + u_2 + v_2 + e_22
es_13 = mu + u_1 + v_3 + e_13
es_33 = mu + u_3 + v_3 + e_33
es_14 = mu + u_1 + v_4 + e_14
...

so, if I understand things correctly, you want a random effect for the species 
(the u's) and you want a random effect for studies (the v's) and the u's and 
v's are uncorrelated (and also uncorrelated with the e's). Moreover, the same 
u's (e.g., u_1) from different studies are also uncorrelated. So, the marginal 
variance-covariance matrix of the first study would look like this:

tau^2_u + tau^2_v + s^2_11  tau^2_v tau^2_v
tau^2_v tau^2_u + tau^2_v + s^2_21  tau^2_v
tau^2_v tau^2_v tau^2_u + tau^2_v + s^31

where s^2_11, s^2_21, and s^2_31 are the (approximately) known sampling 
variances.

If that is the model you have in mind (please correct me if I didn't get it 
right), then I can at least say that I am working on functions for the metafor 
package that will allow you to fit such a model in the future. The name 
rma.uni() (uni for univariate) hints at the fact that there will be something 
called rma.mv() (mv for multivariate) in a later version of the package. 
Essentially, the multivariate model allows two sets of random effects (plus the 
sampling errors), which covers the model you have in mind. These functions 
still need some extensive testing though before I will make them part of the 
package.

Best,

--
Wolfgang Viechtbauer
 Department of Methodology and Statistics
 School for Public Health and Primary Care
 University of Maastricht, The Netherlands
 http://www.wvbauer.com/



Original Message
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Mark Urban Sent: Thursday, August 13, 2009 16:25
To: r-help@r-project.org
Subject: [R] metafor random effects meta-analysis

> Hello,
>
> Great to see the new metafor package for meta-analysis.
>
> I would like to perform a meta-analysis in which I initially calculate
> the intercept of the model with a nested random-effects structure. In
> lme, this would be
>
> model<- lme(v3~1, random=~1|species/study, weights = varFixed(~Wt),
> method = "REML")
>
> where multiple effects sizes are measured for some studies and more than
> one study exists for some species.  I would like to treat species as a
> random effect rather than a fixed effect if possible.  I understand that
> lme will not give me the correct weighted answer (something to do with
> not being able to fix the variances at the lowest level?) so that I
> should use metafor.
>
> However, I only see that metafor accepts moderators and I'm assuming that
> they are treated as non-nested fixed factors, if for example I used:
>
> x<-cbind(species,study)
> rma.uni(yi=v3,sei=vi,mods=x, method="REML")
>
> Am I correct in thinking that I cannot obtain the correct weighted random
> effects intercept using lme?
>
> How can I obtain a weighted purely random-effects model with nested
> factors using metafor or have I misinterpreted something from the metafor
> manual?
>
> Thanks,
>
> Mark

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


Re: [R] Browser and Debug?

2009-08-13 Thread roger koenker

At points of total desperation you can always consider
the time-honored, avuncular advice  --  RTFM,
in this case Section 4.4 of Writing R Extensions.


url:www.econ.uiuc.edu/~rogerRoger Koenker
emailrkoen...@uiuc.eduDepartment of Economics
vox: 217-333-4558University of Illinois
fax:   217-244-6678Urbana, IL 61801



On Aug 13, 2009, at 10:20 AM,  wrote:

This may be asking more than can be reasonably expected. But, any  
tips on debugging the 'C' and Fortran code without trying to put  
together all the tools to compile from source?


Kevin

 Erik Iverson  wrote:

This article might help:

http://www.biostat.jhsph.edu/~rpeng/docs/R-debug-tools.pdf

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org 
] On Behalf Of Inchallah Yarab

Sent: Thursday, August 13, 2009 9:40 AM
To: r-help@r-project.org
Subject: [R] Browser and Debug?

Hi,

Someone can explain to me how use Browser and Debug ?
thank you



[[alternative HTML version deleted]]

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

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


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


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


Re: [R] Output to screen and file at the same time

2009-08-13 Thread Greg Snow
You may also want to look at ?TeachingDemos::txtStart as an alternative to 
sink, one advantage is that the commands as well as the output can be included. 
 With a little more work you can also include graphical output into a 
transcript file.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Michael Knudsen
> Sent: Thursday, August 13, 2009 7:13 AM
> To: Gabor Grothendieck
> Cc: r help
> Subject: Re: [R] Output to screen and file at the same time
> 
> On Thu, Aug 13, 2009 at 3:07 PM, Gabor
> Grothendieck wrote:
> 
> > See the split argument in ?sink
> 
> Thanks! I actually did check the manual for sink (it's true!) but
> somehow I managed to overlook the split argument.
> 
> --
> Michael Knudsen
> micknud...@gmail.com
> http://lifeofknudsen.blogspot.com/
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Yet another plotting hint - choosing the proper device to produce plots for Word

2009-08-13 Thread Jason Rupert
Magically, the eps version seems to fix the "not coloring in the lines" issue 
observed when using the WMF device - note that the issue was observed when 
viewing it on the screen and after printing it out.  

However, with eps, the color of the points when using pch 21 appears to stay 
within the boundary of the circle when viewed on the screen and when printed.  


Now, regarding the addition of a TIFF preview, I tried to uses GSView to add a 
preview via the following instructions:
http://pages.cs.wisc.edu/~ghost/gsview/gsviewen.htm#EPS_Preview
Unfortunately the "Add EPS Preview" option is greyed out for eps file generated 
with the following code shown below.

Do you have any further suggestions, about what I should try to produce a 
reasonable preview for the eps? 

Thank you again for any feedback and insights. 

postscript(file= as.character("TestFigure.eps"), height = 6, width = 7, 
pointsize = 10, paper = "special", onefile = FALSE, horizontal=F)
plot(-4:4, -4:4, type = "n")# setting up coord. system
points(rnorm(200), rnorm(200), col = "red", pch=20)
points(rnorm(100)/2, rnorm(100)/2, col = "blue", cex = 1.5, pch=20)
dev.off()


--- On Thu, 8/13/09, Gavin Simpson  wrote:

> From: Gavin Simpson 
> Subject: Re: [R] Yet another plotting hint - choosing the proper device to 
> produce plots for Word
> To: "Jason Rupert" 
> Cc: "Scott Sherrill-Mix" , r-help@r-project.org
> Date: Thursday, August 13, 2009, 7:34 AM
> 
> On Thu, 2009-08-13 at 04:53 -0700, Jason Rupert wrote:
> > Scott, 
> > 
> > Thanks for your response and insight. 
> > 
> > I call what I'm seeing - "Not coloring within the
> lines" :)
> > 
> > When using pch 19, 20, or 21, it looks like the fill
> does no stay
> > within the perimeter of the circle or properly fill
> the circle, i.e.
> > some blank area left.  It is demonstrated at the
> following Nabble post
> > location:    
> > 
> > http://n2.nabble.com/Unusual-Plotting-Artifacts-td3437365.html
> > 
> > I guess I would like to use a device that does not
> have this issue and
> > also provides image that look well electronically in
> Word and also
> > print well.  They need to look good when
> importing because most of the
> > reviews will be conducted electronically in Word, and
> it needs to look
> > good when printed because one or two folks will review
> a hard copy.
> 
> I wouldn't be so quick to blame the device itself - the
> rendered could
> also be having difficulties with metafiles, even MS own
> software has
> problems.
> 
> >   
> > 
> > You mentioned that EPS has a weakness because Word
> shows a low
> > resolution version.  Is there another device that
> gets around this
> > problem?  At this point filesize is not an
> issue.
> 
> You could add the preview yourself using ghostscript and
> gsview on
> Windows - IIRC you get a few options as to how the preview
> should be
> generated. It is still going to be low-res though, compared
> to the
> printed version.
> 
> Ultimately, vector based images are going to render better
> when printed
> throughout this process, so think about the ultimate
> delivery of this
> document and ease of conversion to things like PDF if that
> is on the
> cards. Bitmap images (PNG etc) might look good on screen
> but print
> poorly or loose resolution if manipulated etc.
> 
> Depends on the work flow you have in mind, but perhaps a
> high res PNG or
> TIFF might be better if file size is irrelevant if you have
> to use Word
> and have to review on screen.
> 
> G
> 
> >   
> > 
> > Thank you again for all your help and feedback. 
>   
> > 
> > 
> > 
> > 
> > 
> > --- On Thu, 8/13/09, Gavin Simpson 
> wrote:
> > 
> > > From: Gavin Simpson 
> > > Subject: Re: [R] Another Plotting Hint - changing
> fill color for points
> > > To: "Scott Sherrill-Mix" 
> > > Cc: "Jason Rupert" ,
> r-help@r-project.org
> > > Date: Thursday, August 13, 2009, 3:41 AM
> > > On Wed, 2009-08-12 at 23:36 -0400,
> > > Scott Sherrill-Mix wrote:
> > > > I don't really use Word or .wmf but maybe
> try a high
> > > pixel count .png e.g.
> > > >
> png('test.png',height=480*5,width=480*5,res=72*5)
> > > > plot(1:10, col = "red", bg = "grey", pch=21,
> cex
> > > =1.7)
> > > > dev.off()
> > > > 
> > > > 
> > > > Scott
> > > 
> > > An EPS is likely to give better resolution if the
> document
> > > is intended
> > > to be printed. An EPS image will likely also have
> a much
> > > smaller file
> > > size, if that is important.
> > > 
> > > One problem with EPS files in Word is that, at
> least in the
> > > versions I
> > > have used (up to Office 11), Word displays a low
> resolution
> > > preview of
> > > the image on screen, so it doesn't look quite so
> good on
> > > screen, but
> > > printing is fine.
> > > 
> > > Jason, did you print your document containing the
> wmf? What
> > > you might be
> > > seeing could just be the effects of antialiasing
> or some
> > > other
> > > processing going on to display the image in Word
> on screen
> > > and not be
> > > present in the printed

[R] how to extract the order of genes after clustering

2009-08-13 Thread Rnewbie

Dear all,

I used hclust() to generate a dendrogram. After clustering, I wanted to take
the order of the genes for further plotting purposes. Anyone has an idea how
I can reoder my raw gene list as it is shown in the dendrogram?

Thanks in advance. 
-- 
View this message in context: 
http://www.nabble.com/how-to-extract-the-order-of-genes-after-clustering-tp24954550p24954550.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to get the n (number of observations) per conditional group

2009-08-13 Thread Erik Iverson
We will only be able to help if you provide a reproducible example!  I'm sure 
this is a simple one-liner, but it's hard to tell from your example what it 
should be.  The functions table, length, tapply, and/or nrow may play a part 
though. 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Dax
Sent: Thursday, August 13, 2009 9:11 AM
To: r-help@r-project.org
Subject: [R] How to get the n (number of observations) per conditional group

Hello all,

I have a huge data set that I'm cleaning up a bit. I am extracted the
means per condition, but also need to get the n. Strangely enough I am
unable to find a function that could actually pull this off. I am
unable to use replications or count the rows using nrow.

What I am trying to obtain is the number of observations fitting
something along the lines of "data$total[data$spp==1&data$gyro==1&data
$salinity==0&data$day==i]"

Can anyone help me?

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

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


[R] FW: R graphics

2009-08-13 Thread Mcdonald, Grant


From: Mcdonald, Grant
Sent: 13 August 2009 13:08
To: r-help@R-project.org
Subject: R graphics

Dear sir,

I am trying to create a barplot showing propotions, 

 So my data is in the format of a vector containing 0s and 1s (i.e.successful 
or not) with a corresponding vector with two  catogorical levels.

successage
1 old
0young
0 young
1 old

I want to show a bar plot with a ylim=c(0,1) and an x-axis showing the two ages 
and the proportion of success only as filled bars.

after making success a factor and plotting against age using: plot(success~age)

the graphic shows age on the x and proportion on the yaxis as i want.  However 
for each age it shows the total proportion split into both success and 
failures.  I would however just like to show the prop successes without the 
failures stajed on top.

data frame is below:

successful  maleage
1   O
1   Y
1   Y
1   Y
1   O
1   O
1   Y
1   O
1   Y
1   O
1   O
1   Y
1   O
1   Y
1   Y
1   Y
1   O
1   O
1   Y
1   Y
1   O
1   Y
1   O
1   Y
1   Y
1   Y
1   O
1   Y
1   Y
1   O
1   Y
1   O
1   O
1   Y
1   O
1   Y
1   O
1   Y
1   Y
1   O
1   Y
1   Y
1   O
1   Y
1   Y
1   Y
1   O
1   O
1   Y
1   O
1   Y
1   Y
1   Y
1   Y
1   Y
1   Y
1   Y
1   Y
1   Y
1   O
1   Y
1   O
1   Y
1   Y
1   O
1   O
1   Y
1   Y
1   O
1   Y
1   O
1   Y
1   Y
1   Y
1   O
1   Y
1   O
1   Y
1   Y
1   Y
1   O
1   Y
1   O
1   Y
1   Y
1   O
1   Y
1   Y
1   O
1   O
1   Y
1   Y
1   Y
1   O
0   Y
NA  O
0   O
NA  Y
1   Y
1   O
NA  O
NA  Y
0   O
NA  Y
0   O
NA  Y
1   Y
1   O
0   O
0   Y
NA  O
0   Y
NA  O
0   Y
0   Y
NA  O
NA  O
NA  O
NA  Y
NA  Y
0   O
NA  O
NA  Y
NA  O
1   O
0   O
0   Y
NA  O
NA  Y
1   O
0   O
0   O
0   O
NA  Y
0   O
0   Y
NA  Y
0   O
NA  O
0   Y
NA  O
1   O
0   Y
NA  O
NA  O
NA  O
0   O
0   O
0   O
0   Y
0   O
0   O
0   O
0   Y
NA  O
0   Y
0   O
NA  Y
NA  O
0   O
NA  Y
NA  O
0   O
NA  O
NA  O
0   O
NA  Y
NA  O
NA  Y
0   O
NA  O
1   Y
NA  Y
NA  O
1   O
1   Y
0   O
0   Y
0   O
0   Y
0   Y
1   Y

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 3-D surface graph from lmer mixed models?

2009-08-13 Thread willow1980

Dear Professor Murdoch,
That is exactly the difficulty for me. I don't know how to make a prediction
with lmer using "expand.grid"; at the moment, I can use
“mo...@x%*%fixef(model)” to get predicted values for existing observational
data, but not data by "expand.grid". Actually, if I know this, I can then
use "persp" or "wireframe" to plot 3-D surface graph. Do you know or have
available code for this aim?
Sorry, this request must sound very lazy or stupid.
Thank you very much for helping!
Best regards,



Duncan Murdoch-2 wrote:
> 
> 
> I only see two explanatory variables:  afr_c, byear_c.  If you have more 
> than two, you can't use a surface plot:  surfaces are two dimensional.
> 
> All of the 3D surface functions want basically the same thing:  a matrix 
> giving evaluations of a function at locations of the explanatory 
> variables.  So you need to calculate that.  I'd do it by using 
> expand.grid to create a large set of combinations of values of the 
> explanatory variables, ask your model to do predictions at all of those 
> locations, and then reshape the result into a matrix.
> 
> Duncan Murdoch
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-plot-3-D-surface-graph-from-lmer-mixed-models--tp24952273p24954438.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] How to get the n (number of observations) per conditional group

2009-08-13 Thread Dax
Hello all,

I have a huge data set that I'm cleaning up a bit. I am extracted the
means per condition, but also need to get the n. Strangely enough I am
unable to find a function that could actually pull this off. I am
unable to use replications or count the rows using nrow.

What I am trying to obtain is the number of observations fitting
something along the lines of "data$total[data$spp==1&data$gyro==1&data
$salinity==0&data$day==i]"

Can anyone help me?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] [R-pkgs] dcemri: A package for medical image analysis

2009-08-13 Thread Brandon . J . Whitcher
dcemri 0.10 has been released on CRAN

"dcemri" is (to the best of my knowledge) the first public-domain software 
package for the quantitative analysis of dynamic contrast-enhanced MRI 
(DCE-MRI) and diffusion-weighted MRI (DW-MRI or DWI).  Data import and 
export is availble for ANALYZE or NIfTI data formats (sorry, no DICOM). 
Images are stored in neurological format regardless of the "handedness" of 
the data; i.e., simple reflections are allowed via the q-form or s-form 
codes in NIfTI.

Software development is currently under SourceForge via

http://www.dcemri.org

A mailing list has been established and feedback is appreciated.

Functionality includes:

Motion correction and co-registration via "fast template matching"
T1 quantification via multiple flip-angle acquistions (inversion recovery 
coming soon!)
Conversion to gadolinium contrast agent concentration
Parametric models for the arterial input function (AIF), both 
literature-based (Tofts-Kermode and Fritz-Hansen) and data-adaptive.
Kinetic parameter estimation using a variety of compartmental models 
(e.g., Kety, extended Kety, etc.)
Estimation via nonlinear regression (Levenburg-Marquardt optimization) or 
Bayesian methods (MCMC)
Semi-parametric methods via Bayesian P-splines (MCMC)

A detailed vignette has been included as a "tutorial" for the package and 
permission was obtained to include the simulated data from Buckley (2002; 
MRM).  Basic NIfTI data sets have also been provided.

Sincerely,

Brandon


---
This e-mail was sent by GlaxoSmithKline Services Unlimited 
(registered in England and Wales No. 1047315), which is a 
member of the GlaxoSmithKline group of companies. The 
registered address of GlaxoSmithKline Services Unlimited 
is 980 Great West Road, Brentford, Middlesex TW8 9GS.
---

[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

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


Re: [R] Browser and Debug?

2009-08-13 Thread rkevinburton
This may be asking more than can be reasonably expected. But, any tips on 
debugging the 'C' and Fortran code without trying to put together all the tools 
to compile from source?

Kevin

 Erik Iverson  wrote: 
> This article might help:
> 
> http://www.biostat.jhsph.edu/~rpeng/docs/R-debug-tools.pdf
> 
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of Inchallah Yarab
> Sent: Thursday, August 13, 2009 9:40 AM
> To: r-help@r-project.org
> Subject: [R] Browser and Debug?
> 
> Hi,
> 
> Someone can explain to me how use Browser and Debug ?
> thank you
> 
> 
>   
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Matrix addition function

2009-08-13 Thread Vitalie S.
On Thu, 13 Aug 2009 15:11:03 +0200, Michael Knudsen   
wrote:


On Thu, Aug 13, 2009 at 11:35 AM, Lina Rusyte  
wrote:


Hi Lina,

What function can I use for matrices addition? I couldn’t find any  
information about it in the manual or in the internet.
(A+B suits, when the number of matrixes is small, function sum()  
doesn’t suit for matrices addition, because it sums all variables in  
the matrices and produces as an answer single number, not a matrix).




Reduce is the function you need. It can be applied to any operator not  
just `+`:



M_list <- replicate(4, matrix(1, 2, 2), simplify=FALSE)
M_list

[[1]]
 [,1] [,2]
[1,]11
[2,]11

[[2]]
 [,1] [,2]
[1,]11
[2,]11

[[3]]
 [,1] [,2]
[1,]11
[2,]11

[[4]]
 [,1] [,2]
[1,]11
[2,]11


Reduce(`+`, M_list)

 [,1] [,2]
[1,]44
[2,]44







I don't know of any function doing that, but you could easily write a
one yourself. Suppese that X is a list of matrices. Then you could
e.g. do as follows:

matrixSum = function(X)
{
   N = length(X)
   if (N==2) return(X[[1]]+X[[2]])
   else return(matrixSum(X[[1:(N-1)]],X[[N]]))
}

I guess that one should do the trick.

Best,
Michael




--

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


Re: [R] prop.test() - need algorithm or reference

2009-08-13 Thread Ronggui Huang
The help page of prop.test gives you three references. Isn't it enough?
For example,

 Newcombe R.G. (1998) Two-Sided Confidence Intervals for the Single
 Proportion: Comparison of Seven Methods. _Statistics in Medicine_
 *17*, 857-872.

 Newcombe R.G. (1998) Interval Estimation for the Difference
 Between Independent Proportions: Comparison of Eleven Methods.
 _Statistics in Medicine_ *17*, 873-890.


2009/8/13  :
>
> Preparing a paper for a medical journal.
>
> Using the prop.test() function in R (v2.4.0)
>
> to compare two groups' response to data like the following.
>
> A sample of 100 individuals from Population I, 18 with positive readings
>
> from a certain test,
>
>  vs.
>
> A sample of 148 individuals from Population II, 61 with positive readings.
>
>
>
> Results look like this:
>
>
>
> R version 2.4.0 Patched (2006-11-25 r39997)
>
> ..
>
>> prop.test(c(18,61),c(100,148))
>
>
>
>        2-sample test for equality of proportions with continuity
>
> correction
>
>
>
>        data:  c(18, 61) out of c(100, 148)
>
>        X-squared = 13.7676, df = 1, p-value = 0.0002069
>
>        alternative hypothesis: two.sided
>
>        95 percent confidence interval:
>
>         -0.3498963 -0.1144280
>
>         sample estimates:
>
>            prop 1    prop 2
>
>            0.180 0.4121622
>
>
>
>
>
> Presumably the p-value measures that the likelihood
>
> that the two populations have the same proportion of
>
> response.  My question is this.  The reviewer of the
>
> paper has asked for a reference on the algorithm used
>
> to compute the p-value. The R Reference Manual is not
>
> clear on this.  Is this a standard algorithm that can
>
> be quoted by name (e.g., "Two-sample T Test")?  I
>
> do note that the manual quotes a 1927 article by E.B.
>
> Wilson.  Is the method of computation explained there?
>
>
>
> Thank you for any assistance you can provide.
>
>
>
> George Heine
>
> ghe...@mathnmaps.com
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

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


Re: [R] how to get R interpreter to remember constant values without using any memory location

2009-08-13 Thread Philipp Pagel
On Thu, Aug 13, 2009 at 04:05:07PM +0200, mau...@alice.it wrote:
> Maybe I expect too much from a non compiled language.
> Anyway, I wonder whether it is possible in R to set constant values
> without using any memory location that would take useless space
> bacause such values are not going to be changed along the program.

If not in memory, where would the data live? None of the compiled or
interpreted languages I have come accross implement magic.

cu
Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://webclu.bio.wzw.tum.de/~pagel/

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


Re: [R] Browser and Debug?

2009-08-13 Thread Erik Iverson
This article might help:

http://www.biostat.jhsph.edu/~rpeng/docs/R-debug-tools.pdf

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Inchallah Yarab
Sent: Thursday, August 13, 2009 9:40 AM
To: r-help@r-project.org
Subject: [R] Browser and Debug?

Hi,

Someone can explain to me how use Browser and Debug ?
thank you


  
[[alternative HTML version deleted]]

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

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


[R] prop.test() - need algorithm or reference

2009-08-13 Thread gheine

Preparing a paper for a medical journal.  

Using the prop.test() function in R (v2.4.0) 

to compare two groups' response to data like the following.

A sample of 100 individuals from Population I, 18 with positive readings

from a certain test,

  vs.

A sample of 148 individuals from Population II, 61 with positive readings.



Results look like this:



R version 2.4.0 Patched (2006-11-25 r39997)

..

> prop.test(c(18,61),c(100,148))



2-sample test for equality of proportions with continuity

correction



data:  c(18, 61) out of c(100, 148)

X-squared = 13.7676, df = 1, p-value = 0.0002069

alternative hypothesis: two.sided

95 percent confidence interval:

 -0.3498963 -0.1144280

 sample estimates:

prop 1prop 2

0.180 0.4121622





Presumably the p-value measures that the likelihood

that the two populations have the same proportion of

response.  My question is this.  The reviewer of the

paper has asked for a reference on the algorithm used

to compute the p-value. The R Reference Manual is not

clear on this.  Is this a standard algorithm that can

be quoted by name (e.g., "Two-sample T Test")?  I

do note that the manual quotes a 1927 article by E.B.

Wilson.  Is the method of computation explained there?



Thank you for any assistance you can provide.



George Heine

ghe...@mathnmaps.com

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


Re: [R] Validity check when setting slot

2009-08-13 Thread Vitalie S.

Hi,



RG> Hi,
RG> I'm wondering if the following behaviour is normal:

RG> setClass('A', representation(number='numeric'), RG>  
validity=function(object){ RG> if( obj...@number < -1 )  
return("Invalid number"); TRUE})

>> [1] "A"
RG> a <- new('A')
RG> a
>> An object of class “A”
>> Slot "number":
>> numeric(0)

RG> a...@number <- 0
RG> a...@number <- -3
RG> a
>> An object of class “A”
>> Slot "number":
>> [1] -3



Rewriting `@<-` will do the job:

setClass('A', representation(number='numeric'),
  validity=function(object){
if( obj...@number < -1 ) return("Invalid number")
TRUE}
)


setMethod("@<-",
signature(object = "A"),
function (object, name, value){
object <- callNextMethod(object, as.character(substitute(name)),  
value)

validObject(object)
return(object)
}
)



a <- new('A')
a...@number <- 23
a...@number <- -23

Error in validObject(object) : invalid class "A" object: Invalid number


By th way, it seems (to me) that there is a bug in callNextMethod above:

object <- callNextMethod(object, name, value)
or
object <- callNextMethod()

trigger an error:

Error in checkSlotAssignment(object, name, value) :
  "name" is not a slot in class "A"

-Vitalie

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

2009-08-13 Thread Inchallah Yarab
Hi,

Someone can explain to me how use Browser and Debug ?
thank you


  
[[alternative HTML version deleted]]

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


Re: [R] xyplot and subscripts

2009-08-13 Thread Juliet Hannah
I'm not sure how to do this in lattice, but here is an option
with ggplot2.

library(ggplot2)
set.seed(123)

# Make sure the data has a variable that indicates
# which group is red and which one is black
DF <- data.frame(x = rnorm(10), y = rnorm(10), gr = rep(1:5,
2),endpoint = c(rep("Red_Group",5),rep("Black_Group",5)))
p <- ggplot(DF,aes(x=x,y=y,group=gr))
p <- p+geom_line()
p <- p + geom_point(aes(colour=endpoint))
# Manually specify that you want the colors to be black and red
p <- p + scale_colour_manual("endpoint", c("Black_Group" = "black",
"Red_Group" = "red"))
p

Best,

Juliet

On Thu, Aug 6, 2009 at 10:27 AM, Kito Palaxou wrote:
>
> Hi all,
>
> I have a data frame like this:
>
> DF <- data.frame(x = rnorm(10), y = rnorm(10), gr = rep(1:5, 2))
>
> and I make the following xy-plot:
>
> library(lattice)
> xyplot(y ~ x, data = DF, groups = gr, type = "b", col = 1)
>
>
> Is it possible that the two points that belong to the same group specified by 
> DF$gr to have a different color -- that is for each pair of points connected 
> by the line, I want one to be black and the other red. I tried:
>
> xyplot(y ~ x, data = DF, groups = gr, type = "b", col = 1:2)
>
>
> but it doen't work. Is there any solution for this??
>
> Thanks a lot!
>
> Kito
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] When using randomForest, what's the effect to "set.seed"?

2009-08-13 Thread Daniel Malter

if you set a seed manually, it makes the results reproducible. That is, if
you set a specific seed, your randomForest procedure should produce the
exact same result every time (all others equal). As an example:

set.seed(1234)
rnorm(100)
rnorm(100)

set.seed(4531)
rnorm(100)
rnorm(100)

set.seed(1234)
rnorm(150)
rnorm(150)

Note that the last two random-normal draws (with seed 1234), even though
they are longer, reproduce the first 100 digits of the first two draws.

Without knowing the random forest library, I would think that the new seed
is set everytime to make sure that you don't draw one unlucky seed, but that
indeed setting different seeds aims at assuring "better randomness," as you
suggest.

Best,
Daniel


Chang, C-Y. wrote:
> 
> Greetings,
> 
> When reading the random forest manual by Liaw, in the examples 
> "set.seed" is always used before building a forest.
> Does it matter if I don't set the seed?
> If I set a different seed manually each time I build a forest, will this 
> give better randomness?
> 
> Thank you all in advance!
> 
> -- 
> 
> EcoInformatics Lab
> http://homepage.ntu.edu.tw/~complex/ecoinformatics_c.html
> 
> Chun-yi Chang "Ted"
> Ecoinformatics Lab
> Institute of Oceanography
> www.oc.ntu.edu.tw
> National Taiwan University
> Tel : +886-2-3366-9746
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/When-using-randomForest%2C-what%27s-the-effect-to-%22set.seed%22--tp24952511p24954825.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] metafor random effects meta-analysis

2009-08-13 Thread Mark Urban

Hello,

Great to see the new metafor package for meta-analysis.  

I would like to perform a meta-analysis in which I initially calculate the 
intercept of the model with a nested random-effects structure. In lme, this 
would be 

model<- lme(v3~1, random=~1|species/study, weights = varFixed(~Wt), method = 
"REML")

where multiple effects sizes are measured for some studies and more than one 
study exists for some species.  I would like to treat species as a random 
effect rather than a fixed effect if possible.  I understand that lme will not 
give me the correct weighted answer (something to do with not being able to fix 
the variances at the lowest level?) so that I should use metafor.

However, I only see that metafor accepts moderators and I'm assuming that they 
are treated as non-nested fixed factors, if for example I used:

x<-cbind(species,study)
rma.uni(yi=v3,sei=vi,mods=x, method="REML")

Am I correct in thinking that I cannot obtain the correct weighted random 
effects intercept using lme?

How can I obtain a weighted purely random-effects model with nested factors 
using metafor or have I misinterpreted something from the metafor manual?

Thanks,

Mark



_
Express your personality in color! Preview and select themes for Hotmail®. 

91::T:WLMTAGL:ON:WL:en-US:WM_HYGN_express:082009
[[alternative HTML version deleted]]

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


[R] how to get R interpreter to remember constant values without using any memory location

2009-08-13 Thread mauede
Maybe I expect too much from a non compiled language.
Anyway, I wonder whether it is possible in R to set constant values without 
using any memory location that would take useless space 
bacause such values are not going to be changed along the program. It's just a 
way to assign a mnemnic name tos some constant values.
For instance, I would like R interpreter to replace all occurrences of mnemonic 
"Monday" with the number 1, "Tuesday"  with the number 2, "Wednesday  with the 
number 3, and so on ...  without having to assign such values to memory 
locations.
Maybe environment variables are the way to go ?  

Thank you in advance for your advice,
Maura




tutti i telefonini TIM!


[[alternative HTML version deleted]]

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


[R] Whittle estimation for ARMA models

2009-08-13 Thread tzygmund mcfarlane
Hi,

Does anyone know of a package/script that will implement the Whittle
(1953) estimator for the parameters of an invertible stationary ARMA
time series model? The estimator is defined on, for example, pg. 378
of Brockwell & Davis (1991).

I assume that the internal call .whittle in this code due to Diethelm
Wuertz can be used, but I am unsure how:
http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/pkg/fArma/R/whittle.R?rev=2307&root=rmetrics

Thanks

@article{whittle1953estimation,
  title={{Estimation and information in stationary time series}},
  author={Whittle, P.},
  journal={Arkiv f{\\"o}r Matematik},
  volume={2},
  number={5},
  pages={423--434},
  year={1953},
  publisher={Springer}
}

@book{brockwell1991time,
  title={{Time series: theory and methods}},
  author={Brockwell, P.J. and Davis, R.A.},
  year={1991},
  publisher={Springer}
}

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

2009-08-13 Thread Achim Zeileis



On Thu, 13 Aug 2009, Mcdonald, Grant wrote:


Dear sir,

I am trying to create a barplot for two propotions, with proportions successful 
on the y and age on the x.  So my data is in the formate of one vector 
containing 0s and 1s (i.e.successful or not) with a corresponding two level 
vector of age.

successage
1 old
0young
0 young
1 old

Howeber i cannot find a way to stop r stacking the data using the code:  
plot(successfulYN~maleage) as it ends up showing both proportions as i only 
want the proportions of success to show.
also entering it as a table results in x axis being removed maybe though this 
is the only way
could you please offer any help?


A reproducible example would have been helpful (as the posting guide 
explains).


Using the data from ?spineplot:

  treatment <- factor(rep(c(1, 2), c(43, 41)), levels = c(1, 2),
labels = c("placebo", "treated"))
  improved <- factor(rep(c(1, 2, 3, 1, 2, 3), c(29, 7, 7, 13, 7, 21)),
levels = c(1, 2, 3), labels = c("none", "some", "marked"))

I think you have a plot which is similar to

  plot(treatment ~ improved)

showing P(treatment | improved) on the y-axis and P(improved) on the 
x-axis. And you want the same y-axis but an x-axis with equal widths on 
the x-axis, right? Then you can do


  ## store the underlying contingency table
  tab <- plot(treatment ~ improved)
  tab
  prop.table(tab, 1)

  ## plotting with P(improved) x-axis
  spineplot(tab)

  ## plotting with equi-sized bars
  spineplot(prop.table(tab, 1))

(Note that the order of the variables would typically be exchanged but 
this ordering makes the difference between the different plots more 
obvious.)


hth,
Z


Grant McDoanld

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




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


Re: [R] Matrix addition function

2009-08-13 Thread Gabor Grothendieck
If A, B and C are matrices then:

L <- list(A, B, C)
Reduce("+", L)


On Thu, Aug 13, 2009 at 5:35 AM, Lina Rusyte wrote:
> Hello,
>
> What function can I use for matrices addition? I couldn’t find any 
> information about it in the manual or in the internet.
> (A+B suits, when the number of matrixes is small, function sum() doesn’t suit 
> for matrices addition, because it sums all variables in the matrices and 
> produces as an answer single number, not a matrix).
>
> Best regards,
> Lina
>
>
>
>
>        [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

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


  1   2   >