[R] About Error message

2012-06-30 Thread pigpigmeow
Hi again!
I have a question about R.
I have done gam in previous version of R with mgcv package and saved the
workspace. This workspace contains different models and I will do prediction
by these GAMs.

However, I install new version of R. and use the same workspace. when I type
summary(models), and the error message showed
Error in Predict.matrix.cr.smooth(object, dk$data) :  F is missing from cr
smooth - refit model with current mgcv.

this workspace is normal when I used previous version of R. What's wrong?!
Thank in advance.



--
View this message in context: 
http://r.789695.n4.nabble.com/About-Error-message-tp4634955.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] incorrect number of subscripts on matrix

2012-06-30 Thread Patrick Burns

Andre,

1) The matrix you created was called 'x.3', not 'x'.
I guess this could be an item in 'The R Inferno',
perhaps it falls into Circle 8.3.32.

2) You don't need a loop at all:

x.3 - matrix(rexp(3000, rate=2/3), nrow=1000)

This is Circle 3.

http://www.burns-stat.com/pages/Tutor/R_inferno.pdf

Pat

On 30/06/2012 05:09, andre bedon wrote:


Hi,
Wondering if anyone could help me out with this error.Im trying to fill a 
matrix with random numbers taken from an exponential distribution using a loop:
x.3-matrix(rep(0,3000),nrow=1000,byrow=T)for(i in 
1:1000){x[i,]-rexp(3,rate=2/3)}
I get the error message:
Error in x[i, ] - rexp(3, rate = 2/3) :   incorrect number of subscripts on 
matrix
Any ideas??? Appreciate any thoughts.   
[[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 Burns
pbu...@pburns.seanet.com
twitter: @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')

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


Re: [R] incorrect number of subscripts on matrix

2012-06-30 Thread Berend Hasselman

andre bedon wrote
 
 Hi,
 Wondering if anyone could help me out with this error.Im trying to fill a
 matrix with random numbers taken from an exponential distribution using a
 loop:
 x.3-matrix(rep(0,3000),nrow=1000,byrow=T)for(i in
 1:1000){x[i,]-rexp(3,rate=2/3)}
 I get the error message:
 Error in x[i, ] - rexp(3, rate = 2/3) :   incorrect number of subscripts
 on matrix
 Any ideas??? Appreciate any thoughts. 
   
 

If I run your example as given I get a different error message:

Error: unexpected 'for' in x.3-matrix(rep(0,3000),nrow=1000,byrow=T)for

How about doing

x-matrix(rep(0,3000),nrow=1000,byrow=T);for(i in
1:1000){x[i,]-rexp(3,rate=2/3)}

so that x is a matrix.

Berend


--
View this message in context: 
http://r.789695.n4.nabble.com/incorrect-number-of-subscripts-on-matrix-tp4634953p4634957.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] lattice histogram log and non log values

2012-06-30 Thread Deepayan Sarkar
On Thu, Jun 28, 2012 at 2:41 AM, LCOG1 jr...@lcog.org wrote:
 Hello all,
  Please consider the following

 library(lattice)
 Colors. -rep(brewer.pal(7, Dark2),2)
 color - 1

 Data.X.. - data.frame(UnitArea = c(rnorm(1000), rnorm(1000)), Type =
 c(rep(Base,1000),rep(Log,1000)))

                        histogram( ~ UnitArea |  Type, data = Data.X..,
          xlab = Unit Area, type = density,
          panel = function(x, ... ){
              panel.histogram(x, ...)
              panel.mathdensity(dmath = dnorm, col = black,
                                args = list(mean=mean(x),sd=sd(x)))
          }, col = Colors.[color], layout = c(1, 2),
                   scales=list(log = c(F,T),tick.number=list(8), rot = c(0, 
 90),
                 x = list(relation = 'free')))

 I want to plot on the same page distributions both observed values and the
 logged values.  I tried using the log parameter e.g. log = c(F,T) but I dont
 think this is right.    When I tried transforming the data before plotting
 the scales were all messed up. Guidance would be appreciated.  Thanks

The latter would be the better approach. You haven't given code, but
you probably didn't add 'breaks=NULL', and without it all panels will
have a common set of breakpoints, so scales effectively will be the
same in all panels.

This works for me:

xx - exp(rnorm(1000))

DF - data.frame(UnitArea = c(xx, log(xx)),
 Type = c(rep(Base,1000), rep(Log,1000)))

histogram( ~ UnitArea |  Type, data = DF,
  xlab = Unit Area, type = density,
  panel = function(x, ... ){
  panel.histogram(x, ...)
  panel.mathdensity(dmath = dnorm, col = black,
args = list(mean=mean(x), sd=sd(x)))
  },
  breaks = NULL,
  col = Colors.[color], layout = c(1, 2),
  scales = list(x = list(relation = 'free')))


 Also, is there a way to simply plot multiple panels like the base graphics
 package using  par(new = TRUE) in the following?  It just replaces the first
 plot so maybe I shouldn't be trying to use the lattice package with the base
 graphics package.

Yes, see ?plot.trellis.

-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] predicting expected number of events using a coxph model

2012-06-30 Thread peter dalgaard

On Jun 29, 2012, at 23:56 , agittens wrote:

 I fit a coxph model:
 
 coxphfit - coxph(Surv(sampledLifetime, !sampledCensoredQ) ~  curpbc6  +
 prevpbc6,  sampledTimeSeries)
 
 Now I'm trying to predict the expected number of events using a new dataset.
 The documentation suggests that
 
 coxPred - predict(coxphfit, newdata = testTimeSeries, type=expected)
 
 will do what I want, but I get the error
 
 Error in model.frame.default(data = testTimeSeries, formula =
 Surv(sampledLifetime,  : 
  variable lengths differ (found for 'curpbc6')
 
 when I do this. The dataframes sampledTimeSeries and testTimeSeries were
 constructed by taking rows from a larger dataframe, so they have the same
 data.
 
 What am I doing incorrectly?

Most likely referring to a variable not in testTimeSeries. (I kind of suspect 
that unlike predict.lm, predict.coxph does not ignore the left hand side of 
formulas. Does testTimeSeries contain a sampledLifetime column?)

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] the meaning of subscripts

2012-06-30 Thread Deepayan Sarkar
On Thu, Jun 28, 2012 at 9:27 PM, startend startend...@gmail.com wrote:
 Hi,

 Now i am dealing with longitudinal data set and I want to see the rough
 marginal plot for 2 variables separately.
 I found the code from one example here,

 reading -
 read.table(http://www.ats.ucla.edu/stat/R/examples/alda/data/reading_pp.txt;,
 header=T, sep=,)
 reading[reading$id %in% c(4, 27, 31, 33, 41, 49, 69, 77, 87), ]

 xyplot(piat~age | id
 , data=reading[reading$id %in% c(4, 27, 31, 33, 41, 49, 69, 77, 87),
 ],panel=function(x,y,*subscripts*){
        panel.xyplot(x, y, pch=16)
           panel.lmline(x,y, lty=4)
      panel.xyplot(reading$agegrp*[subscripts]*, y, pch=3)
      panel.lmline(reading$agegrp*[subscripts]*,y)
 }
 , ylim=c(0, 80), as.table=T, *subscripts*=T)

 I just don't know what the subscripts for and the meaning of that.
 Can someone kindly let me know how it works.

See ?xyplot, particularly the entry for 'panel'.

If a lattice plot has one or more conditioning variables ('id' here),
then the data used in each panel is a subset of the full data.
'subscripts' is an optional argument passed to the panel function that
allows you to obtain the association between the original rows of the
data and the data used in the panels. For example, if your data is

 x  y id
 1  1  1
 2  2  2
 3  3  1
 4  4  2
 5  5  1
 6  6  2
 7  7  1
 8  8  2
 9  9  1
10 10  2

and the formula is y ~ x | id, then the first panel (corresponding to
id = 1) will have subscripts=c(1, 3, 5, 7, 9), and the second will
have c(2, 4, 6, 8, 10).

For a more realistic example, see
http://lattice.r-forge.r-project.org/Vignettes/src/lattice-tricks/regression-lines.pdf
(page 12).

-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] graph from txt file

2012-06-30 Thread Rui Barradas

Hello,

Just set the attribute,

V(g)$date - as.POSIXct(as.POSIXlt(rep(315522000, 6), origin=1970-01-01))
V(g)$date


Rui Barradas

Em 30-06-2012 04:26, HIMANSHU MITTAL escreveu:

Thanks a lot.
But i have one more doubt
one of the attribute i have is time of edge formation

id1,id2,label,time
51,66,0,315522000
51,66,0,315522000
140,157,0,315522000
140,173,0,415522000
so is there any attribute for storing timestamps like for weight or color
or if i store it in color would i lose the information?

On Sat, Jun 30, 2012 at 2:56 AM, Rui Barradas ruipbarra...@sapo.pt
mailto:ruipbarra...@sapo.pt wrote:

Hello,

Package igraph can create graphs. Example:

dat - read.table(text=
node1  node2  attr1  attr2
2  1  2  3
3  2  3  2
4  3  4  2
6  5  1  4
, header=TRUE)
dat

vertices - as.vector( t(dat[, 1:2]) )

g - graph(vertices, directed=FALSE)
E(g)$weight - dat$attr1
E(g)$color - dat$attr2

plot(g, layout=layout.circle, edge.label=E(g)$weight,
edge.color=E(g)$color)


Also, you should post data examples like the posting guide says.
With your description, a small example like the one above would do.

Hope this helps,

Rui Barradas

Em 29-06-2012 19:05, HIMANSHU MITTAL escreveu:

yes i would prefer igraph, but it can be any r package as long
as it can
create the graph

On Fri, Jun 29, 2012 at 11:14 PM, Peter Ehlers
ehl...@ucalgary.ca mailto:ehl...@ucalgary.ca wrote:

On 2012-06-29 10:28, HIMANSHU MITTAL wrote:

Hi all,
I have a text file in which the graph info is stored as:
node1 node2 attr1 attr2
where there is an edge b/w node12 and attr12 are edge
atttributes

  is there any way to create a graph using such format in r?


The igraph package?

Peter Ehlers


Regards,
Himanshu Mittal

[[alternative HTML version deleted]]

**
R-help@r-project.org mailto:R-help@r-project.org
mailing list
https://stat.ethz.ch/mailman/*__*listinfo/r-help

https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.__ethz.ch/mailman/listinfo/r-__help
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/**
posting-guide.html
http://www.R-project.org/__posting-guide.html
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 mailto:R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/__listinfo/r-help
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/__posting-guide.html
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





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


Re: [R] plot background - excel gradient style background ?

2012-06-30 Thread Jim Lemon

On 06/30/2012 07:07 AM, jcrosbie wrote:

I have a number of different figures I wish to create with a gradient
background. In addition to the two examples I've uploaded I need a boxplot,
histogram, etc.


http://r.789695.n4.nabble.com/file/n4634932/fig1.png fig1.png
http://r.789695.n4.nabble.com/file/n4634932/fig2.png fig2.png


Hi jcrosbie,
Will this do?

library(plotrix)
plot(1:10,type=n)
xylim-par(usr)
gradient.rect(xylim[1],xylim[3],xylim[2],xylim[4],
 c(1,0,1),c(1,0,1),c(1,1,1),gradient=y) 


points(1:10)

Jim

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


Re: [R] Indifference curve

2012-06-30 Thread Rui Barradas

Hello,

Is this it?


u - function(x, y) 3*x^2 + 2*y

x - seq(-10, 10, by=1)
y - seq(0, 150, by=1)
a - c(100, 200, 300)

persp(x, y, outer(x, y, u), ticktype=detailed)
contour(x, y, outer(x, y, u), levels=a)

Hope this helps,

Rui Barradas

Em 28-06-2012 10:13, Akhil dua escreveu:

Hello everyone I am new to R

I need to plot 3 indifference curve for the level 100, 200 and 300

my utility function is of the form u(x,y)=3x^2+2y

I also need to draw contour line on it

can any one please tell me how to do it

[[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] About Error message

2012-06-30 Thread Bert Gunter
Ummm Read the error message and do what it says?

  F is missing from cr smooth - refit model with current mgcv. 

The older models appear to be incompatible with the newer version of mgcv/R
summary() methods. Read the new ?summary help. There may be a parameter you
can give it to make it work.

-- Bert


On Fri, Jun 29, 2012 at 9:59 PM, pigpigmeow gloryk...@hotmail.com wrote:

 Hi again!
 I have a question about R.
 I have done gam in previous version of R with mgcv package and saved the
 workspace. This workspace contains different models and I will do
 prediction
 by these GAMs.

 However, I install new version of R. and use the same workspace. when I
 type
 summary(models), and the error message showed
 Error in Predict.matrix.cr.smooth(object, dk$data) :  F is missing from cr
 smooth - refit model with current mgcv.

 this workspace is normal when I used previous version of R. What's wrong?!
 Thank in advance.



 --
 View this message in context:
 http://r.789695.n4.nabble.com/About-Error-message-tp4634955.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.




-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

[[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] Problem installing RBloomberg

2012-06-30 Thread yoda55
Thx for the info. 
I didn't know the package name changed.

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-installing-RBloomberg-tp4634624p4634959.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] Calling a .net DLL from R?

2012-06-30 Thread Cheng Li
Hi Everyone,

I am a newbie to R. I have a .net DLL developed by myself. Now I wan to
call this DLL from my R environment. After searching on the Internet, I
didn't get any clue. Dose anyone have any experience on this subject. Is
there any available package to do such work?

Regards,
Cheng

[[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 do I extract coefficient standard errors /CI for a coxme model

2012-06-30 Thread dunner
Hello, and thanks for your time

I'm trying to extract standard errors to produce confidence intervals from a
multivariable coxme  model object  so I can write a function that will print
a summary for some reproducible research. As far as I can glean, the SE is
produced on-the-fly by the print method. I'll dig into the source code if I
have to, but I'd rather not have to. 

Any help would be really appreciated.

Thanks 

Ross

--
View this message in context: 
http://r.789695.n4.nabble.com/How-do-I-extract-coefficient-standard-errors-CI-for-a-coxme-model-tp4634968.html
Sent from the R help mailing list archive at Nabble.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] package ‘rggobi’ is not available (for R version 2.15.0)

2012-06-30 Thread Uwe Ligges



On 29.06.2012 21:03, YTP wrote:



My criticism is aimed at the previous reply, which gave an arcane and not
helpful suggestion (granted, it may only seem that way to me because of my
own incompetence, but I don't know that the knowledge needed to understand
binary package and install from the sources is what you want to
require/assume of all R users) which was especially disappointing given the
much simpler solution that exists.

More aggravating is the GGobi website which only has a 64 bit download,
which required much work to find a 32 bit download, whereupon the package
RGGobi only produces a non-descriptive error message, which required days of
reading through many forums which only have complicated half-solutions, and
then find in the middle of the readme file that the package just doesn't
work with the latest version of R. Not to mention saying it's only available
for 32 bit installations is completely contradictory to only having the 64
bit version of GGobi available.

I still stand by saying that this is a very poor user experience in
acquiring a package and getting it to work.

To say the workaround I found only takes 5 seconds is akin to saying well
if you did the thing that works first you'd have solved your problem much
quicker, which is of course vacuously true, but ignores the time spent
beforehand which was orders of magnitude greater timewise.

My post is clearly about one specific package, there is no basis to think I
am criticizing the work done by some large group of CRAN maintainers,


Where large equals 3 for accepting submissions of source packages.

If you'd like to see an easier installation for ggobi, pelase contact 
the maintainers of that third party software. If you want to say 
something about Rggobi installation, please contact the package maintainer.


Best,
Uwe Ligges


 let

alone anyone in particular not associated with the one package relevant to
my post.


--
View this message in context: 
http://r.789695.n4.nabble.com/package-rggobi-is-not-available-for-R-version-2-15-0-tp4634763p4634925.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.


[R] Accessing named members of a list in an array

2012-06-30 Thread mlell08
Dear List,

I've created a two-dimensional array which shall contain a value and its
error, respectively.
These two values are concatenated in al list and bear the names sl and
sl_err

But I can't adress them using the $-notation.

a- array(list(NULL),dim=c(2,2))
a[[1,1]]- c(a=2,b=3)
a[[1,1]]$a
## Fehler in a[[1, 1]]$a : $ operator is invalid for atomic vectors
a[[1,1]][a]   # This works however.
## a
## 2

I always thought these two methods of indexing are equal? Is there any
way to use the $-Style indexing?

Thank you,
Moritz

-- 
GnuPG Key: 0x7340821E

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


Re: [R] Help

2012-06-30 Thread John Kane

   Hi Hannah,
   I have run both the original code and the code copied from the email and
   both seem to work just fine.
   I don't know why you are getting that error message.   Do you have both
   ggplot2 and reshape2 loaded?  Still that should not give you the error
   message you are getting. In fact given the data I supplied, I just don't
   understand what it is trying to say.
   I cannot even find a function [1]rq.fit.br.  Perhaps some other library that
   you have loaded is masking something in ggplot2 or reshape2.  Can any more
   savvy R users comment here?
   Here is a link to the output  which I think sounds like what you want.

   [2]http://www.mediafire.com/i/?sgc2evfen5vvckb
   It  only  has two columns of data since I'm too lazy to do more but in
   principle it does any number as along at the output device can show it.
   Here  is  my sessionInfo() in case we have some serious differences in
   settings.
   sessionInfo()
   R version 2.15.1 (2012-06-22)
   Platform: i686-pc-linux-gnu (32-bit)
   locale:
[1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
[3] LC_TIME=en_CA.UTF-8LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_CA.UTF-8LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C   LC_TELEPHONE=C
   [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C
   attached base packages:
   [1] stats graphics  grDevices utils datasets  methods   base
   other attached packages:
   [1] reshape2_1.2.1 ggplot2_0.9.1
   loaded via a namespace (and not attached):
[1]  colorspace_1.1-1dichromat_1.2-4 digest_0.5.2
   grid_2.15.1
[5]   labeling_0.1MASS_7.3-18 memoise_0.1
   munsell_0.3
[9]plyr_1.7.1proto_0.3-9.2 RColorBrewer_1.0-5
   scales_0.2.1
   [13] stringr_0.6



   John Kane
   Kingston ON Canada

   -Original Message-
   From: hannah@gmail.com
   Sent: Fri, 29 Jun 2012 21:31:55 -0400
   To: jrkrid...@inbox.com
   Subject: Re: [R] Help

   Hi Petr, David and John,
 Thanks for the reply. I am sorry that I did not make it very clear.
   One on top of another may not be the right expression.
   Actually what I wanted is the second option of David's. There
   are 10 columns in the plot and, in each column, there are three boxplots.
   Different colors can be used to distinguish the three boxplots in the
   same column.
   John, when I run the code, I got the message below:
   Error in [3]rq.fit.br(x, y, tau = tau, ...) : Singular design matrix
   In addition: Warning message:
   In [4]is.na(rows) : [5]is.na() applied to non-(list or vector) of type
   'NULL'
   Thanks again, everyone.
 Hannah
   2012/6/29 John Kane [6]jrkrid...@inbox.com

 I think I may understand what you want.
 I 'd say the first thing to do is to combine the 3 matrices into a single
 data frame with a column for the values of A, B C
 Here is a mock-up with something like what I mean. I just used two columns
 of data for the mock-up.
 Then, you can reshape the data using melt() from the reshape2 package and
 then graph the data using ggplot from the ggplot2 package.
 Is this something like what you want?
 =
 library(ggplot2)
 library(reshape2)
 A  -  data.frame( m = (rep(A, 10)) , b=rnorm(10), c = rnorm(10))
 B  -  data.frame( m = (rep(B, 10)) , b=rnorm(10), c = rnorm(10))
 C  -  data.frame( m = (rep(C, 10)) , b=rnorm(10), c = rnorm(10))
 mydata  -  rbind( A, B, C )
 names(mydata)  -  c( group, k1, k2 )
 mdata  -  melt(mydata)
 p  -  ggplot( mdata , aes(variable, value , colour = variable )) +
 geom_boxplot() +
   facet_grid( group ~ .)
 p
 ==
 John Kane
 Kingston ON Canada

-Original Message-
From: [7]hannah@gmail.com
Sent: Thu, 28 Jun 2012 16:29:54 -0400
To: [8]r-help@r-project.org
Subject: [R] Help
   
Dear all,
  I need some help on plotting multiple boxplots on one figure.
  I have three matrix A, B and C. Each of them is a 1000 by 10 matrix.
The 10 columns of all three matrix correspond to the
10 values of the same parameter, say k=1, ..., 10.
  I want to make a plot where x axis represents different values of k.
For each k value, I want to plot three boxplots, one on top of another.
For example, for k=1, I want to draw three boxplot based on the first
column of A, B and C respectively. Similarly, I do the same for the rest
of
k values.
  Can some one give me some hint on this?
  Thank you so much.
Hannah
   

  [[alternative HTML version deleted]]
   
__
[9]R-help@r-project.org mailing list
[10]https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting 

Re: [R] Accessing named members of a list in an array

2012-06-30 Thread David Winsemius


On Jun 30, 2012, at 9:35 AM, mlell08 wrote:


Dear List,

I've created a two-dimensional array which shall contain a value and  
its

error, respectively.
These two values are concatenated in al list and bear the names sl  
and

sl_err

But I can't adress them using the $-notation.

a- array(list(NULL),dim=c(2,2))
a[[1,1]]- c(a=2,b=3)
a[[1,1]]$a
## Fehler in a[[1, 1]]$a : $ operator is invalid for atomic vectors
a[[1,1]][a]   # This works however.
## a
## 2

I always thought these two methods of indexing are equal?


You thought wrong (on two accounts as it happens). The $ methods  
translate to [[ with a quoted argument and there is no matrix/array   
equivalent since vectors loose their names (if they had any to begin  
with) when they are put into a matrix or array. The equivalent method  
to x$a is x[[a]], not x[a].



Is there any
way to use the $-Style indexing?

Thank you,
Moritz

--
GnuPG Key: 0x7340821E

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] How do I extract coefficient standard errors /CI for a coxme model

2012-06-30 Thread David Winsemius


On Jun 30, 2012, at 8:33 AM, dunner wrote:


Hello, and thanks for your time

I'm trying to extract standard errors to produce confidence  
intervals from a
multivariable coxme  model object  so I can write a function that  
will print
a summary for some reproducible research. As far as I can glean, the  
SE is
produced on-the-fly by the print method. I'll dig into the source  
code if I

have to, but I'd rather not have to.


Have you tried:

sqrt(vcov(rfit))

--

David Winsemius, MD
West Hartford, CT

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


[R] Significance of interaction depends on factor reference level - lmer/AIC model averaging

2012-06-30 Thread Andy Robertson
Dear R users,

 

I am using lmer combined with AIC model selection and averaging (in the
MuMIn package) to try and assess how isotope values (which indicate diet)
vary within a population of animals.

 

I have multiple measures from individuals (variable 'Tattoo') and multiple
individuals within social groups within 4 locations (A, B, C ,D) crucially I
am interested if there are differences between sexes and age classes
(variable AGECAT2) and whether this differs with location.

However, whether or not I get a significant sex:location interaction depends
on which location is my reference level and I cannot understand why this is
the case. It seems to be due to the fact that the standard error associated
with my interactions varies depending on which level is the reference.

 

Any help or advice would be appreciated,

 

Andrew Robertson

 

Below is the example code of what I am doing and an example of the model
summary and model averaging results with location A as the ref level or
location B.

 

if A is the reference level...

 

#full model

Amodel-lmer(d15N~(AGECAT2+Sex+Location1+AGECAT2:Location1+Sex:Location1+AGE
CAT2:Sex+(1|Year)+(1|Location1/Socialgroup/Tattoo)), REML=FALSE,
data=nocubs)

 

#standardise model

Amodels-standardize(Amodel, standardize.y=FALSE)

 

#dredge models

summary(model.avg(get.models(Adredge,cumsum(weight)0.95)))

 

Then the average model coefficients indicate no sex by location interaction

 
Component models:
  df  logLikAICc Delta Weight
235   13 -765.33 1557.28  0.00   0.68
1235  15 -764.55 1559.91  2.63   0.18
3  9 -771.64 1561.57  4.29   0.08
12345 17 -763.67 1562.37  5.09   0.05
 
Term codes:
AGECAT2   c.Sex   Location1   AGECAT2:c.Sex
c.Sex:Location1 
  1   2   3   4
5 
 
Model-averaged coefficients: 
   Estimate Std. Error z value Pr(|z|)
(Intercept)8.673592   0.474524  18.279   2e-16 ***
c.Sex  0.095375   0.452065   0.2110.833
Location1B-3.972882   0.556575   7.138   2e-16 ***
Location1C-3.61   0.531858   6.831   2e-16 ***
Location1D-3.348665   0.539143   6.211   2e-16 ***
c.Sex:Location1B  -0.372653   0.513492   0.7260.468
c.Sex:Location1C   0.428299   0.511254   0.8380.402
c.Sex:Location1D  -0.757582   0.512586   1.4780.139
AGECAT2OLD-0.179772   0.150842   1.1920.233
AGECAT2YEARLING   -0.009596   0.132328   0.0730.942
AGECAT2OLD:c.Sex   0.045963   0.296471   0.1550.877
AGECAT2YEARLING:c.Sex -0.323985   0.268919   1.2050.228
---
 

And the full model summary looks like this..

 

 

Linear mixed model fit by maximum likelihood 

Formula: d15N ~ (AGECAT2 + Sex + Location1 + AGECAT2:Location1 +
Sex:Location1 +  AGECAT2:Sex + (1 | Year) + (1 |
Location1/Socialgroup/Tattoo)) 

   Data: nocubs 

  AIC  BIC logLik deviance REMLdev

1568 1670 -761.1 15221534

Random effects:

Groups NameVariance Std.Dev.

Tattoo:(Socialgroup:Location1) (Intercept) 0.35500  0.59582 

 Socialgroup:Location1  (Intercept) 0.35620  0.59682 

 Location1  (Intercept) 0.0  0.0 

 Year   (Intercept) 0.0  0.0 

 Residual   0.49584  0.70416 

Number of obs: 608, groups: Tattoo:(Socialgroup:Location1), 132;
Socialgroup:Location1, 22; Location1, 4; Year, 2

 

Fixed effects:

   Estimate Std. Error t value

(Intercept) 8.831790.52961  16.676

AGECAT2OLD -0.441010.41081  -1.074

AGECAT2YEARLING 0.018050.38698   0.047

SexMale-0.113460.51239  -0.221

Location1B -3.978800.63063  -6.309

Location1C -4.048160.60404  -6.702

Location1D -3.363890.63304  -5.314

AGECAT2OLD:Location1B   0.441980.54751   0.807

AGECAT2YEARLING:Location1B -0.221340.52784  -0.419

AGECAT2OLD:Location1C   0.206840.50157   0.412

AGECAT2YEARLING:Location1C  0.241320.47770   0.505

AGECAT2OLD:Location1D   0.536530.52778   1.017

AGECAT2YEARLING:Location1D  0.517550.51038   1.014

SexMale:Location1B -0.024420.57546  -0.042

SexMale:Location1C  0.746800.58128   1.285

SexMale:Location1D -0.418000.59505  -0.702

AGECAT2OLD:SexMale -0.089070.32513  -0.274

AGECAT2YEARLING:SexMale-0.401460.30409  -1.320

 

 

If location B is the reference level then the average model coefficients
indicate an age by sex interaction in location C.

 

Component models:
  df  logLikAICc Delta Weight
235   13 -765.33 1557.28  0.00   0.68
1235  15 -764.55 1559.91  2.63   0.18
3  9 -771.64 1561.57  4.29   0.08
12345 17 -763.67 1562.37  5.09   0.05
 
Term codes:
AGECAT2 

Re: [R] Binary Quadratic Opt?

2012-06-30 Thread menkes
Hi Khris,

If all your variables are binary then you may want to check CPLEX and/or
Gurobi (both provide a free academic license). 
http://www-01.ibm.com/software/integration/optimization/cplex-optimizer/
http://www.gurobi.com/products/additional-products-using-gurobi/r

The algorithms that CPLEX and Gurobi use for quadratic programming are
designed to work with convex objective functions, with the one exception
when all variables are binary.  In that case CPLEX and Gurobi apply some
transformation that in certain cases will allow you to solve binary
quadratic optimization problems.

Regards,
Menkes

--
View this message in context: 
http://r.789695.n4.nabble.com/Binary-Quadratic-Opt-tp4633521p4634971.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] graph from txt file

2012-06-30 Thread HIMANSHU MITTAL
Thanks a lot.
Just one more question.
me given the two node ids and the graph, can i find the corresponding edge
attributes( date and label)?

On Sat, Jun 30, 2012 at 2:10 PM, Rui Barradas ruipbarra...@sapo.pt wrote:

 Hello,

 Just set the attribute,

 V(g)$date - as.POSIXct(as.POSIXlt(rep(**315522000, 6),
 origin=1970-01-01))
 V(g)$date


 Rui Barradas

 Em 30-06-2012 04:26, HIMANSHU MITTAL escreveu:

 Thanks a lot.
 But i have one more doubt
 one of the attribute i have is time of edge formation

 id1,id2,label,time
 51,66,0,315522000
 51,66,0,315522000
 140,157,0,315522000
 140,173,0,415522000
 so is there any attribute for storing timestamps like for weight or color
 or if i store it in color would i lose the information?

 On Sat, Jun 30, 2012 at 2:56 AM, Rui Barradas ruipbarra...@sapo.pt
 mailto:ruipbarra...@sapo.pt wrote:

Hello,

Package igraph can create graphs. Example:

dat - read.table(text=
node1  node2  attr1  attr2
2  1  2  3
3  2  3  2
4  3  4  2
6  5  1  4
, header=TRUE)
dat

vertices - as.vector( t(dat[, 1:2]) )

g - graph(vertices, directed=FALSE)
E(g)$weight - dat$attr1
E(g)$color - dat$attr2

plot(g, layout=layout.circle, edge.label=E(g)$weight,
edge.color=E(g)$color)


Also, you should post data examples like the posting guide says.
With your description, a small example like the one above would do.

Hope this helps,

Rui Barradas

Em 29-06-2012 19:05, HIMANSHU MITTAL escreveu:

yes i would prefer igraph, but it can be any r package as long
as it can
create the graph

On Fri, Jun 29, 2012 at 11:14 PM, Peter Ehlers
ehl...@ucalgary.ca mailto:ehl...@ucalgary.ca wrote:

On 2012-06-29 10:28, HIMANSHU MITTAL wrote:

Hi all,
I have a text file in which the graph info is stored as:
node1 node2 attr1 attr2
where there is an edge b/w node12 and attr12 are edge
atttributes

  is there any way to create a graph using such format in
 r?


The igraph package?

Peter Ehlers


Regards,
Himanshu Mittal

[[alternative HTML version deleted]]

__**__**
R-help@r-project.org mailto:R-help@r-project.org
mailing list

 https://stat.ethz.ch/mailman/***__*listinfo/r-helphttps://stat.ethz.ch/mailman/*__*listinfo/r-help

 https://stat.ethz.ch/mailman/listinfo/r-helphttps://stat.ethz.ch/mailman/**listinfo/r-help
 https://**stat. 
 https://stat.__ethz.ch/mailman/**listinfo/r-__helphttp://ethz.ch/mailman/listinfo/r-__help


 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 
PLEASE do read the posting guide
 http://www.R-project.org/**
posting-guide.html

 http://www.R-project.org/__**posting-guide.htmlhttp://www.R-project.org/__posting-guide.html


 http://www.R-project.org/**posting-guide.htmlhttp://www.R-project.org/posting-guide.html
 

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




[[alternative HTML version deleted]]

__**__
R-help@r-project.org mailto:R-help@r-project.org mailing list

 https://stat.ethz.ch/mailman/_**_listinfo/r-helphttps://stat.ethz.ch/mailman/__listinfo/r-help


 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 
PLEASE do read the posting guide

 http://www.R-project.org/__**posting-guide.htmlhttp://www.R-project.org/__posting-guide.html


 http://www.R-project.org/**posting-guide.htmlhttp://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] Accessing named members of a list in an array

2012-06-30 Thread arun
Hi,

You can use these as well to access named members.

 a[1]
[[1]]
a b 
2 3 


 a[1][[1]][1]
a 
2 

 a[[1,1]][1]
a 
2 
 a[[1,1]][2]
b 
3 

 identical(a[[1,1]][a],a[[1,1]][1],a[1][[1]][1])
[1] TRUE


 a[[1,1]][[a]]
[1] 2
 a[[1,1]][[b]]
[1] 3

or,

 a[[c(1,2)]]
[1] 3
 a[[c(1,1)]]
[1] 2


a$ab-a[[1]]
 a$ab
a b 
2 3 
 a$ab[1]
a 
2 
a$ab1-a[[1]][1]
a$ab1
a 
2 


Hope this will be of some use for you


A.K.



- Original Message -
From: mlell08 mlel...@gmail.com
To: r-help@r-project.org
Cc: 
Sent: Saturday, June 30, 2012 9:35 AM
Subject: [R]  Accessing named members of a list in an array

Dear List,

I've created a two-dimensional array which shall contain a value and its
error, respectively.
These two values are concatenated in al list and bear the names sl and
sl_err

But I can't adress them using the $-notation.

a- array(list(NULL),dim=c(2,2))
a[[1,1]]- c(a=2,b=3)
a[[1,1]]$a
## Fehler in a[[1, 1]]$a : $ operator is invalid for atomic vectors
a[[1,1]][a]       # This works however.
## a
## 2

I always thought these two methods of indexing are equal? Is there any
way to use the $-Style indexing?

Thank you,
Moritz

-- 
GnuPG Key: 0x7340821E

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

2012-06-30 Thread Peter Ehlers

On 2012-06-30 07:04, John Kane wrote:


Hi Hannah,
I have run both the original code and the code copied from the email and
both seem to work just fine.
I don't know why you are getting that error message.   Do you have both
ggplot2 and reshape2 loaded?  Still that should not give you the error
message you are getting. In fact given the data I supplied, I just don't
understand what it is trying to say.
I cannot even find a function [1]rq.fit.br.

[...]

This function is in the quantreg *package*. So Hannah isn't
telling us the whole story.

Peter Ehlers

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


Re: [R] turning R expressions into functions?

2012-06-30 Thread Greg Snow
Look at the replicate function, it takes an expression (does not need
a function) and runs that expression the specified number of times.
Will that accomplish what you want without needing to worry about
substitute, quote, eval, etc.?

On Fri, Jun 29, 2012 at 11:36 AM, Jochen Voß v...@seehuhn.de wrote:
 [ please copy me on answers, since I am not subscribed to the list ]

 Dear all,

 I am trying to write an R function which uses system.time
 to determine which of a given list of R expressions executes
 fastest.  To work around the limited resolution of system.time,
 I want to convert the given expressions into functions which
 execute the given expressions a fixed number of times.
 My current attempt is as follows:

  FuncIt - function(k, expr) {
k - as.numeric(k)
expr - eval.parent(substitute(expr))
eval(substitute(function() { for (funcit.i in 1:k) { expr } }))
  }

 This works, but seems not very robust.
 My question: is there a better way of doing this?

 Here are some experiments.

 1) good: If I run the following using Rscript

  test1 - function(e1) {
e1 - substitute(e1)
FuncIt(100, e1)
  }

  f - test1(rnorm(1))
  print(f)

 then I get the following output:

  function ()
  {
  for (funcit.i in 1:100) {
  rnorm(1)
  }
  }
  environment: 0x102260c28

 This is what I want.  But why do I need the extra substitute
 in test1?  I only found by experiment that this is needed.


 2) bad: If I try to call FuncIt directly, it fails:

  f - FuncIt(100, rnorm(1))
  print(f)

 has the output:

  function ()
  {
  for (funcit.i in 1:100) {
  -0.763894772833099
  }
  }
  environment: 0x102265790

 This is bad, since now 'rnorm(1)' already has been
 evaluated.  How do I prevent this from happening,
 without breaking the good case 1 above?


 3) ugly: If I run the same commands in the R gui on MacOS
 (R 2.15.1 released on 2012/06/22), I get different output:

 source(/Users/voss/project/statcomp/test.R)
  function() { for (funcit.i in 1:k) { expr } }
  environment: 0x19cc040
  function() { for (funcit.i in 1:k) { expr } }
  environment: 0x19bc884

 This is on the same machine using (as far as I can tell) the
 same R engine.  So why is the output different?


 Many thanks,
 Jochen
 --
 http://seehuhn.de/

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



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

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


Re: [R] Accessing named members of a list in an array

2012-06-30 Thread Peter Ehlers

On 2012-06-30 09:04, David Winsemius wrote:


On Jun 30, 2012, at 9:35 AM, mlell08 wrote:


Dear List,

I've created a two-dimensional array which shall contain a value and
its
error, respectively.
These two values are concatenated in al list and bear the names sl
and
sl_err

But I can't adress them using the $-notation.

a- array(list(NULL),dim=c(2,2))
a[[1,1]]- c(a=2,b=3)
a[[1,1]]$a
## Fehler in a[[1, 1]]$a : $ operator is invalid for atomic vectors
a[[1,1]][a]   # This works however.
## a
## 2

I always thought these two methods of indexing are equal?


You thought wrong (on two accounts as it happens). The $ methods
translate to [[ with a quoted argument and there is no matrix/array
equivalent since vectors loose their names (if they had any to begin
with) when they are put into a matrix or array. The equivalent method
to x$a is x[[a]], not x[a].


Actually, to be picky (and David knows this), quoting the
help page (and the OP should have read this):
 x$name is equivalent to x[[name, exact = FALSE]] .

In my view, there is far too much eagerness to use $ rather
than getting accustomed to the other, more powerful, extraction
methods.

Peter Ehlers

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


Re: [R] Significance of interaction depends on factor reference level - lmer/AIC model averaging

2012-06-30 Thread Bert Gunter
1. This has nothing to do with R. It's your lack of understanding of linear
models issues. See ?contrasts and ?contrast for the specific, but I doubt
that you will understand how these fit in with the underlying statistical
issues (and I would be delighted to be wrong). So, in order of (my
)preference, you should try:

a) Consult a local statistician;
b) Post on r-sig-mixed-models
c) Post on a statistical advice list like stats.stackexchange.com

.
Cheers,
Bert


On Sat, Jun 30, 2012 at 9:44 AM, Andy Robertson ar...@exeter.ac.uk wrote:

 Dear R users,



 I am using lmer combined with AIC model selection and averaging (in the
 MuMIn package) to try and assess how isotope values (which indicate diet)
 vary within a population of animals.



 I have multiple measures from individuals (variable 'Tattoo') and multiple
 individuals within social groups within 4 locations (A, B, C ,D) crucially
 I
 am interested if there are differences between sexes and age classes
 (variable AGECAT2) and whether this differs with location.

 However, whether or not I get a significant sex:location interaction
 depends
 on which location is my reference level and I cannot understand why this is
 the case. It seems to be due to the fact that the standard error associated
 with my interactions varies depending on which level is the reference.



 Any help or advice would be appreciated,



 Andrew Robertson



 Below is the example code of what I am doing and an example of the model
 summary and model averaging results with location A as the ref level or
 location B.



 if A is the reference level...



 #full model


 Amodel-lmer(d15N~(AGECAT2+Sex+Location1+AGECAT2:Location1+Sex:Location1+AGE
 CAT2:Sex+(1|Year)+(1|Location1/Socialgroup/Tattoo)), REML=FALSE,
 data=nocubs)



 #standardise model

 Amodels-standardize(Amodel, standardize.y=FALSE)



 #dredge models

 summary(model.avg(get.models(Adredge,cumsum(weight)0.95)))



 Then the average model coefficients indicate no sex by location interaction


 Component models:
   df  logLikAICc Delta Weight
 235   13 -765.33 1557.28  0.00   0.68
 1235  15 -764.55 1559.91  2.63   0.18
 3  9 -771.64 1561.57  4.29   0.08
 12345 17 -763.67 1562.37  5.09   0.05

 Term codes:
 AGECAT2   c.Sex   Location1   AGECAT2:c.Sex
 c.Sex:Location1
   1   2   3   4
 5

 Model-averaged coefficients:
Estimate Std. Error z value Pr(|z|)
 (Intercept)8.673592   0.474524  18.279   2e-16 ***
 c.Sex  0.095375   0.452065   0.2110.833
 Location1B-3.972882   0.556575   7.138   2e-16 ***
 Location1C-3.61   0.531858   6.831   2e-16 ***
 Location1D-3.348665   0.539143   6.211   2e-16 ***
 c.Sex:Location1B  -0.372653   0.513492   0.7260.468
 c.Sex:Location1C   0.428299   0.511254   0.8380.402
 c.Sex:Location1D  -0.757582   0.512586   1.4780.139
 AGECAT2OLD-0.179772   0.150842   1.1920.233
 AGECAT2YEARLING   -0.009596   0.132328   0.0730.942
 AGECAT2OLD:c.Sex   0.045963   0.296471   0.1550.877
 AGECAT2YEARLING:c.Sex -0.323985   0.268919   1.2050.228
 ---


 And the full model summary looks like this..





 Linear mixed model fit by maximum likelihood

 Formula: d15N ~ (AGECAT2 + Sex + Location1 + AGECAT2:Location1 +
 Sex:Location1 +  AGECAT2:Sex + (1 | Year) + (1 |
 Location1/Socialgroup/Tattoo))

Data: nocubs

   AIC  BIC logLik deviance REMLdev

 1568 1670 -761.1 15221534

 Random effects:

 Groups NameVariance Std.Dev.

 Tattoo:(Socialgroup:Location1) (Intercept) 0.35500  0.59582

  Socialgroup:Location1  (Intercept) 0.35620  0.59682

  Location1  (Intercept) 0.0  0.0

  Year   (Intercept) 0.0  0.0

  Residual   0.49584  0.70416

 Number of obs: 608, groups: Tattoo:(Socialgroup:Location1), 132;
 Socialgroup:Location1, 22; Location1, 4; Year, 2



 Fixed effects:

Estimate Std. Error t value

 (Intercept) 8.831790.52961  16.676

 AGECAT2OLD -0.441010.41081  -1.074

 AGECAT2YEARLING 0.018050.38698   0.047

 SexMale-0.113460.51239  -0.221

 Location1B -3.978800.63063  -6.309

 Location1C -4.048160.60404  -6.702

 Location1D -3.363890.63304  -5.314

 AGECAT2OLD:Location1B   0.441980.54751   0.807

 AGECAT2YEARLING:Location1B -0.221340.52784  -0.419

 AGECAT2OLD:Location1C   0.206840.50157   0.412

 AGECAT2YEARLING:Location1C  0.241320.47770   0.505

 AGECAT2OLD:Location1D   0.536530.52778   1.017

 AGECAT2YEARLING:Location1D  0.517550.51038   1.014

 SexMale:Location1B -0.024420.57546  -0.042

 SexMale:Location1C  

Re: [R] plot background - excel gradient style background ?

2012-06-30 Thread Greg Snow
Here are examples of a histogram and a boxplot using rasterImage to
make the background:

bg - matrix( c('#ff','#ff','#ff'), ncol=1 )


tmp - hist(iris$Sepal.Width)
xylim - par('usr')
rasterImage(bg, xylim[1], xylim[3], xylim[2], xylim[4])
plot(tmp, add=TRUE, lwd=3)



plot( Petal.Length ~ Species, data=iris )
xylim - par('usr')
rasterImage(bg, xylim[1], xylim[3], xylim[2], xylim[4])
plot( Petal.Length ~ Species, data=iris, add=TRUE )



On Fri, Jun 29, 2012 at 3:07 PM, jcrosbie ja...@crosb.ie wrote:
 I have a number of different figures I wish to create with a gradient
 background. In addition to the two examples I've uploaded I need a boxplot,
 histogram, etc.


 http://r.789695.n4.nabble.com/file/n4634932/fig1.png fig1.png
 http://r.789695.n4.nabble.com/file/n4634932/fig2.png fig2.png

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/plot-background-excel-gradient-style-background-tp4632138p4634932.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.



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

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


Re: [R] graph from txt file

2012-06-30 Thread Rui Barradas

Hello,

The answer to the question is yes.
But first a note. Your vertex ids start at 51 and the greater is 173. 
igraph vertices (and edges) are automatically numbered starting at 1, in 
this latest package version. Previous versions vertex numbers were zero 
based. If you look online you will almost surely find code with this 
previous behaviour. In your example, this means that you are creating a 
graph with 173 vertices when in fact it only has 5.

So, I've redid the ids 1 to 5 and used your numbers as vertex labels.


dat - read.csv(text=
id1,id2,label,time
1,2,0,315522000
1,2,0,315522000
3,4,0,315522000
3,5,0,415522000
, header=TRUE)

vertices - as.vector( t(dat[, 1:2]) )
vlabels - c(51, 66, 140, 157, 173)

g - graph(vertices, directed=FALSE)
V(g)$label - vlabels
E(g)$label - dat$label
E(g)$time - as.POSIXct(as.POSIXlt(dat$time, origin=1970-01-01))

plot(g, layout=layout.circle, edge.label=E(g)$weight, edge.color=E(g)$color)

# Finally, this is what you want.
vert.incident - c(1, 2)
e - get.edge.ids(g, vp=vert.incident, directed=FALSE)
E(g)[e]$time

If the egde doesn't exist it returns zero. So, you should test it for 
positiveness to avoid trying to index E(g) with an invalid index number.


Hope this helps,

Rui Barradas

Em 30-06-2012 15:20, HIMANSHU MITTAL escreveu:

Thanks a lot.
Just one more question.
me given the two node ids and the graph, can i find the corresponding
edge attributes( date and label)?

On Sat, Jun 30, 2012 at 2:10 PM, Rui Barradas ruipbarra...@sapo.pt
mailto:ruipbarra...@sapo.pt wrote:

Hello,

Just set the attribute,

V(g)$date - as.POSIXct(as.POSIXlt(rep(__315522000, 6),
origin=1970-01-01))
V(g)$date


Rui Barradas

Em 30-06-2012 04:26, HIMANSHU MITTAL escreveu:

Thanks a lot.
But i have one more doubt
one of the attribute i have is time of edge formation

id1,id2,label,time
51,66,0,315522000
51,66,0,315522000
140,157,0,315522000
140,173,0,415522000
so is there any attribute for storing timestamps like for weight
or color
or if i store it in color would i lose the information?

On Sat, Jun 30, 2012 at 2:56 AM, Rui Barradas
ruipbarra...@sapo.pt mailto:ruipbarra...@sapo.pt
mailto:ruipbarra...@sapo.pt mailto:ruipbarra...@sapo.pt wrote:

Hello,

Package igraph can create graphs. Example:

dat - read.table(text=
node1  node2  attr1  attr2
2  1  2  3
3  2  3  2
4  3  4  2
6  5  1  4
, header=TRUE)
dat

vertices - as.vector( t(dat[, 1:2]) )

g - graph(vertices, directed=FALSE)
E(g)$weight - dat$attr1
E(g)$color - dat$attr2

plot(g, layout=layout.circle, edge.label=E(g)$weight,
edge.color=E(g)$color)


Also, you should post data examples like the posting guide says.
With your description, a small example like the one above
would do.

Hope this helps,

Rui Barradas

Em 29-06-2012 19:05, HIMANSHU MITTAL escreveu:

yes i would prefer igraph, but it can be any r package
as long
as it can
create the graph

On Fri, Jun 29, 2012 at 11:14 PM, Peter Ehlers
ehl...@ucalgary.ca mailto:ehl...@ucalgary.ca
mailto:ehl...@ucalgary.ca mailto:ehl...@ucalgary.ca wrote:

On 2012-06-29 10:28, HIMANSHU MITTAL wrote:

Hi all,
I have a text file in which the graph info is
stored as:
node1 node2 attr1 attr2
where there is an edge b/w node12 and attr12
are edge
atttributes

  is there any way to create a graph using such
format in r?


The igraph package?

Peter Ehlers


Regards,
Himanshu Mittal

[[alternative HTML version deleted]]

__**
R-help@r-project.org mailto:R-help@r-project.org
mailto:R-help@r-project.org mailto:R-help@r-project.org
mailing list
https://stat.ethz.ch/mailman/**listinfo/r-help
https://stat.ethz.ch/mailman/*__*listinfo/r-help

  https://stat.ethz.ch/mailman/__**listinfo/r-help
https://stat.ethz.ch/mailman/**listinfo/r-helphttps://__stat. 
https://stat.__ethz.ch/mailman/__listinfo/r-__help
http://ethz.ch/mailman/listinfo/r-__help

https://stat.ethz.ch/mailman/__listinfo/r-help
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide

Re: [R] turning R expressions into functions?

2012-06-30 Thread Dirk Eddelbuettel

On 30 June 2012 at 11:39, Greg Snow wrote:
| Look at the replicate function, it takes an expression (does not need
| a function) and runs that expression the specified number of times.
| Will that accomplish what you want without needing to worry about
| substitute, quote, eval, etc.?

And also look at the existing benchmark packages 'rbenchmark' and
'microbenchmark':

   R library(microbenchmark)
   R x - 5; microbenchmark( 1/x, x^-1 )
   Unit: nanoseconds
 expr minlq medianuq  max
   1  1/x 296 322.5341 364.0 6298
   2 x^-1 516 548.5570 591.5 5422
   R 

Dirk

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.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] Help

2012-06-30 Thread li li
The following is what I get when I run the code.


 library(ggplot2)
Loading required package: reshape
Loading required package: plyr

Attaching package: 'reshape'

The following object(s) are masked from 'package:plyr':

rename, round_any

Loading required package: grid
Loading required package: proto
 library(reshape2)

Attaching package: 'reshape2'

The following object(s) are masked from 'package:reshape':

colsplit, melt, recast


 A  -  data.frame( m = (rep(A, 10)) , b=rnorm(10), c = rnorm(10))
 B  -  data.frame( m = (rep(B, 10)) , b=rnorm(10), c = rnorm(10))
 C  -  data.frame( m = (rep(C, 10)) , b=rnorm(10), c = rnorm(10))

 mydata  -  rbind( A, B, C )
 names(mydata)  -  c( group, k1, k2 )
 mdata  -  melt(mydata)
Using group as id variables

 p  -  ggplot( mdata , aes(variable, value , colour = variable )) +
geom_boxplot() +
+   facet_grid( group ~ .)
 p
Error in rq.fit.br(x, y, tau = tau, ...) : Singular design matrix
In addition: Warning message:
In is.na(rows) : is.na() applied to non-(list or vector) of type 'NULL'



And my session info is as below:


 sessionInfo()
R version 2.12.2 (2011-02-25)
Platform: i386-apple-darwin9.8.0/i386 (32-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] quantreg_4.71 SparseM_0.89  reshape2_1.1  ggplot2_0.8.9 proto_0.3-9.2
[6] reshape_0.8.4 plyr_1.6

loaded via a namespace (and not attached):
[1] stringr_0.5


When I tried to load package ggplot, I was asked to also load some of the
other packages, for example plyr. Thanks.
Hannah

2012/6/30 Peter Ehlers ehl...@ucalgary.ca

 On 2012-06-30 07:04, John Kane wrote:


Hi Hannah,
I have run both the original code and the code copied from the email
 and
both seem to work just fine.
I don't know why you are getting that error message.   Do you have both
ggplot2 and reshape2 loaded?  Still that should not give you the error
message you are getting. In fact given the data I supplied, I just
 don't
understand what it is trying to say.
I cannot even find a function [1]rq.fit.br.

 [...]

 This function is in the quantreg *package*. So Hannah isn't
 telling us the whole story.

 Peter Ehlers



[[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] Help

2012-06-30 Thread John Kane
It looks like we have different versions of software loaded.
I have R version 2.15.0 (2012-03-30) 

My packages.
reshape2_1.2.1 ggplot2_0.9.0

Hannah's packages.
R version 2.12.2 (2011-02-25)
 quantreg_4.71 SparseM_0.89  reshape2_1.1  ggplot2_0.8.9 proto_0.3-9.2
[6] reshape_0.8.4 plyr_1.6


It looks like quantreg is causing a problem since Peter says that the function 
is in the quantreg *package*.

The first step would probably be to make sure that quantreg is not loaded and 
try the code again.  It probably would work with an older version of ggplot2 
and the old version of reshape.  The command : unattach(package::quantreg) 
should work.  

Retry the code and see what happens.

However I I think that you need to upgrade your version of R, and both  ggplot2 
and reshape2.  .  If I remember correctly your version of ggplot2 is loading 
reshape and plyr automatically as you mention below.  The newer version does 
not and one need to explicitly load reshape2.and plyr.  So  it is possible that 
 reshape_0;8.4 is masking reshape2_1.2.1 which can cause problems.

I'd suggest upgrading R,  , make sure that quantreg is not being loaded 
automatically, or if it is unattach it( see above|),  and then upgrade both 
reshape2 and ggplot to to the most recent versions and see what happens running 
the code from my first post.


Best of luck.

John Kane
Kingston ON Canada


 -Original Message-
 From: hannah@gmail.com
 Sent: Sat, 30 Jun 2012 14:59:19 -0400
 To: ehl...@ucalgary.ca
 Subject: Re: [R] Help
 
 The following is what I get when I run the code.
 
 
 library(ggplot2)
 Loading required package: reshape
 Loading required package: plyr
 
 Attaching package: 'reshape'
 
 The following object(s) are masked from 'package:plyr':
 
 rename, round_any
 
 Loading required package: grid
 Loading required package: proto
 library(reshape2)
 
 Attaching package: 'reshape2'
 
 The following object(s) are masked from 'package:reshape':
 
 colsplit, melt, recast
 
 
 A  -  data.frame( m = (rep(A, 10)) , b=rnorm(10), c = rnorm(10))
 B  -  data.frame( m = (rep(B, 10)) , b=rnorm(10), c = rnorm(10))
 C  -  data.frame( m = (rep(C, 10)) , b=rnorm(10), c = rnorm(10))
 
 mydata  -  rbind( A, B, C )
 names(mydata)  -  c( group, k1, k2 )
 mdata  -  melt(mydata)
 Using group as id variables
 
 p  -  ggplot( mdata , aes(variable, value , colour = variable )) +
 geom_boxplot() +
 +   facet_grid( group ~ .)
 p
 Error in rq.fit.br(x, y, tau = tau, ...) : Singular design matrix
 In addition: Warning message:
 In is.na(rows) : is.na() applied to non-(list or vector) of type 'NULL'
 
 
 
 And my session info is as below:
 
 
 sessionInfo()
 R version 2.12.2 (2011-02-25)
 Platform: i386-apple-darwin9.8.0/i386 (32-bit)
 
 locale:
 [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
 
 attached base packages:
 [1] grid  stats graphics  grDevices utils datasets  methods
 [8] base
 
 other attached packages:
 [1] quantreg_4.71 SparseM_0.89  reshape2_1.1  ggplot2_0.8.9 proto_0.3-9.2
 [6] reshape_0.8.4 plyr_1.6
 
 loaded via a namespace (and not attached):
 [1] stringr_0.5
 
 
 When I tried to load package ggplot, I was asked to also load some of the
 other packages, for example plyr. Thanks.
 Hannah
 
 2012/6/30 Peter Ehlers ehl...@ucalgary.ca
 
 On 2012-06-30 07:04, John Kane wrote:
 
 
Hi Hannah,
I have run both the original code and the code copied from the email
 and
both seem to work just fine.
I don't know why you are getting that error message.   Do you have
 both
ggplot2 and reshape2 loaded?  Still that should not give you the
 error
message you are getting. In fact given the data I supplied, I just
 don't
understand what it is trying to say.
I cannot even find a function [1]rq.fit.br.
 
 [...]
 
 This function is in the quantreg *package*. So Hannah isn't
 telling us the whole story.
 
 Peter Ehlers
 
 
 
   [[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.


FREE ONLINE PHOTOSHARING - Share your photos online with your friends and 
family!
Visit http://www.inbox.com/photosharing to find out more!

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

2012-06-30 Thread solafah bh
Hello
I want to use this function in R (wilcox.test) , is this function can 
approximate the statistic automatically  if the sample size is large or not??
 
Regards
Sulafah
[[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] loop in list

2012-06-30 Thread solafah bh
Hello
I have a loop to sample 20 samples and I want to put them in one list, how I 
can make this?? 
 
Regards
Sulafah
[[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] Using Pers. Dictionary with Aspell in R

2012-06-30 Thread Ribbis
My goal is to use Aspell 0.60 with a personal dictionary within R.  Running
WinXP, R 2.15.1, and Cygwin's install of Aspell 0.60.  Using a test file
with 2/5 words misspelled:
SpellTest.txt
test
text
txxt
endeavour
mytzlplk

and dictionary files (aspell.en.pws, and spell.en.prepl respectively) of: 
personal_ws-1.1 en 0
mytzlplk

personal_repl-1.1 en 0
mytzlplk superman

and R expression of:
SpellOut- aspell(SpellTest,
  program=SpellProg,
  control=c(--master='en_US.multi'
--add-extra-dicts='en_GB.multi' ' -p ./aspell.en.pws'))

makes no suggestion for mytzlplk but finds txxt and allows endeavour.  
As seen in:
 print(SpellOut$Suggestions)
[[1]]
 [1] text  TWX   TeX   Tex   tax   tux   taxi  xxxi 
 [9] xxxv  tax's tux's
 summary(SpellOut)
Possibly mis-spelled words:
[1] mytzlplk txxt 

Directly using aspell in the line command within Cygwin terminal finds the
personal dictionary just fine:
echo mytzlplk | aspell -a --master='en_US.multi' -p ./aspell.en.pws

Not sure how to get R to recognize the personal dictionary file.  Any
assistance would be appreciated.  Thanks.

--
View this message in context: 
http://r.789695.n4.nabble.com/Using-Pers-Dictionary-with-Aspell-in-R-tp4634996.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 adjust the start of a series to zero? (i.e. subtract the first value from the sequence)

2012-06-30 Thread Kristiina Hurme
Hello, 
I'd have a time series, where I am plotting the means and sd of a distance
for a variety of positions along a bird's bill. I'd like to set each line
(represented by point) to start at zero, so that I can look at the
absolute change along the series. At the moment I only know how to do that
in Excel, by subtracting the value of time 1, point 1 from all other times
for point 1. My actual data set has many points ( 20 per bird, only 3 shown
here), so I would love to make this faster in R. Ideally, I would have
another column titled adj_mean for the adjusted means. 

Here is an example. 

 sort2v4
point time  meansd
1   11 52.501000 1.5073927
3   12 54.501818 0.8510329
4   13 56.601739 1.5787222
5   14 57.20 1.2292726
6   15 59.30 2.2632327
7   16 57.800893 1.4745218
8   17 55.303508 2.2661855
9   18 51.100943 1.8540025
10  19 50.60 1.7126977
2   1   10 52.904716 1.1010460
111 21 50.605963 1.2633969
113 22 52.203828 0.7890765
114 23 54.100909 1.1013344
115 24 55.00 1.1547005
116 25 57.001725 1.6341500
117 26 55.003591 1.5652438
118 27 52.911089 1.7373914
119 28 49.204022 1.0350809
120 29 48.904103 0.8747568
112 2   10 50.915700 0.8765483
131 31 48.608228 0.8433913
133 32 49.307101 0.4827703
134 33 51.310824 0.9424023
135 34 52.413350 0.6997860
136 35 54.116723 1.1927297
137 36 52.618161 1.1686288
138 37 49.822764 1.6303473
139 38 47.107336 1.2013356
140 39 47.104214 1.1986148
132 3   10 48.719484 0.6765047

and I would like it to look like this... (which I did in Excel). The start
of each time 1-10 has an adj_mean of 0. 
 sort2v4   
point   timemeansd  adj_mean
1   1   1   52.501  1.5073927   0
3   1   2   54.501818   0.8510329   2.000818
4   1   3   56.601739   1.5787222   4.100739
5   1   4   57.21.2292726   4.699
6   1   5   59.32.2632327   6.799
7   1   6   57.800893   1.4745218   5.299893
8   1   7   55.303508   2.2661855   2.802508
9   1   8   51.100943   1.8540025   -1.400057
10  1   9   50.61.7126977   -1.901
2   1   10  52.904716   1.1010460.403716
111 2   1   50.605963   1.2633969   0
113 2   2   52.203828   0.7890765   1.597865
114 2   3   54.100909   1.1013344   3.494946
115 2   4   55  1.1547005   4.394037
116 2   5   57.001725   1.63415 6.395762
117 2   6   55.003591   1.5652438   4.397628
118 2   7   52.911089   1.7373914   2.305126
119 2   8   49.204022   1.0350809   -1.401941
120 2   9   48.904103   0.8747568   -1.70186
112 2   10  50.9157 0.8765483   0.309737
131 3   1   48.608228   0.8433913   0
133 3   2   49.307101   0.4827703   0.698873
134 3   3   51.310824   0.9424023   2.702596
135 3   4   52.413350.6997863.805122
136 3   5   54.116723   1.1927297   5.508495
137 3   6   52.618161   1.1686288   4.009933
138 3   7   49.822764   1.6303473   1.214536
139 3   8   47.107336   1.2013356   -1.500892
140 3   9   47.104214   1.1986148   -1.504014
132 3   10  48.719484   0.6765047   0.111256

Thank you so much for your help. 
Kristiina

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-adjust-the-start-of-a-series-to-zero-i-e-subtract-the-first-value-from-the-sequence-tp4634999.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] loop in list

2012-06-30 Thread Greg Snow
Instead of a loop you can use the replicate or lapply functions which
will create lists for you.

otherwise you can start with an empty list (mylist - list() )

then add to the list in each iteration of the loop:

for(i in 1:10) {
mylist[[i]] - myfunction(i)
}



On Sat, Jun 30, 2012 at 1:34 PM, solafah bh solafa...@yahoo.com wrote:
 Hello
 I have a loop to sample 20 samples and I want to put them in one list, how I 
 can make this??

 Regards
 Sulafah
 [[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.




-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

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


Re: [R] How to adjust the start of a series to zero? (i.e. subtract the first value from the sequence)

2012-06-30 Thread Phil Spector

Kristiina -
   If the data will always be sorted so that the first time 
for a point appears first in the data frame, you can use:


sort2v4$adj_mean = sort2v4$mean - 
ave(sort2v4$mean,sort2v4$point,FUN=function(x)x[1])

Otherwise, something like this should work:

firstmeans = subset(sort2v4,time==1,select=c(point,mean))
names(firstmeans)[2] = 'adj'
sort2v4 = merge(sort2v4,firstmeans)
sort2v4$adj_mean = with(sort2v4,mean-adj)
sort2v4$adj = NULL

   In the future, you may want to learn about the dput function, which makes
it a little easier for others to reproduce your data.

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Sat, 30 Jun 2012, Kristiina Hurme wrote:


Hello,
I'd have a time series, where I am plotting the means and sd of a distance
for a variety of positions along a bird's bill. I'd like to set each line
(represented by point) to start at zero, so that I can look at the
absolute change along the series. At the moment I only know how to do that
in Excel, by subtracting the value of time 1, point 1 from all other times
for point 1. My actual data set has many points ( 20 per bird, only 3 shown
here), so I would love to make this faster in R. Ideally, I would have
another column titled adj_mean for the adjusted means.

Here is an example.


sort2v4

   point time  meansd
1   11 52.501000 1.5073927
3   12 54.501818 0.8510329
4   13 56.601739 1.5787222
5   14 57.20 1.2292726
6   15 59.30 2.2632327
7   16 57.800893 1.4745218
8   17 55.303508 2.2661855
9   18 51.100943 1.8540025
10  19 50.60 1.7126977
2   1   10 52.904716 1.1010460
111 21 50.605963 1.2633969
113 22 52.203828 0.7890765
114 23 54.100909 1.1013344
115 24 55.00 1.1547005
116 25 57.001725 1.6341500
117 26 55.003591 1.5652438
118 27 52.911089 1.7373914
119 28 49.204022 1.0350809
120 29 48.904103 0.8747568
112 2   10 50.915700 0.8765483
131 31 48.608228 0.8433913
133 32 49.307101 0.4827703
134 33 51.310824 0.9424023
135 34 52.413350 0.6997860
136 35 54.116723 1.1927297
137 36 52.618161 1.1686288
138 37 49.822764 1.6303473
139 38 47.107336 1.2013356
140 39 47.104214 1.1986148
132 3   10 48.719484 0.6765047

and I would like it to look like this... (which I did in Excel). The start
of each time 1-10 has an adj_mean of 0.

sort2v4

point   timemeansd  adj_mean
1   1   1   52.501  1.5073927   0
3   1   2   54.501818   0.8510329   2.000818
4   1   3   56.601739   1.5787222   4.100739
5   1   4   57.21.2292726   4.699
6   1   5   59.32.2632327   6.799
7   1   6   57.800893   1.4745218   5.299893
8   1   7   55.303508   2.2661855   2.802508
9   1   8   51.100943   1.8540025   -1.400057
10  1   9   50.61.7126977   -1.901
2   1   10  52.904716   1.1010460.403716
111 2   1   50.605963   1.2633969   0
113 2   2   52.203828   0.7890765   1.597865
114 2   3   54.100909   1.1013344   3.494946
115 2   4   55  1.1547005   4.394037
116 2   5   57.001725   1.63415 6.395762
117 2   6   55.003591   1.5652438   4.397628
118 2   7   52.911089   1.7373914   2.305126
119 2   8   49.204022   1.0350809   -1.401941
120 2   9   48.904103   0.8747568   -1.70186
112 2   10  50.9157 0.8765483   0.309737
131 3   1   48.608228   0.8433913   0
133 3   2   49.307101   0.4827703   0.698873
134 3   3   51.310824   0.9424023   2.702596
135 3   4   52.413350.6997863.805122
136 3   5   54.116723   1.1927297   5.508495
137 3   6   52.618161   1.1686288   4.009933
138 3   7   49.822764   1.6303473   1.214536
139 3   8   47.107336   1.2013356   -1.500892
140 3   9   47.104214   1.1986148   -1.504014
132 3   10  48.719484   0.6765047   0.111256

Thank you so much for your help.
Kristiina

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-adjust-the-start-of-a-series-to-zero-i-e-subtract-the-first-value-from-the-sequence-tp4634999.html
Sent from the R help mailing list archive at Nabble.com.


Re: [R] How to adjust the start of a series to zero? (i.e. subtract the first value from the sequence)

2012-06-30 Thread Rui Barradas

Hello,

Try, where 'dat' is your dataset,

dd - lapply(split(dat, dat$point), function(x) x$mean - x$mean[1])
dat$adj_mean - NA
for(i in names(dd))
dat$adj_mean[dat$point == i] - dd[[i]]
rm(dd)  # clean-up

Now 'dat' has one extra column, with the adjusted mean values.

Hope this helps,

Rui Barradas

Em 30-06-2012 22:21, Kristiina Hurme escreveu:

Hello,
I'd have a time series, where I am plotting the means and sd of a distance
for a variety of positions along a bird's bill. I'd like to set each line
(represented by point) to start at zero, so that I can look at the
absolute change along the series. At the moment I only know how to do that
in Excel, by subtracting the value of time 1, point 1 from all other times
for point 1. My actual data set has many points ( 20 per bird, only 3 shown
here), so I would love to make this faster in R. Ideally, I would have
another column titled adj_mean for the adjusted means.

Here is an example.


sort2v4

 point time  meansd
1   11 52.501000 1.5073927
3   12 54.501818 0.8510329
4   13 56.601739 1.5787222
5   14 57.20 1.2292726
6   15 59.30 2.2632327
7   16 57.800893 1.4745218
8   17 55.303508 2.2661855
9   18 51.100943 1.8540025
10  19 50.60 1.7126977
2   1   10 52.904716 1.1010460
111 21 50.605963 1.2633969
113 22 52.203828 0.7890765
114 23 54.100909 1.1013344
115 24 55.00 1.1547005
116 25 57.001725 1.6341500
117 26 55.003591 1.5652438
118 27 52.911089 1.7373914
119 28 49.204022 1.0350809
120 29 48.904103 0.8747568
112 2   10 50.915700 0.8765483
131 31 48.608228 0.8433913
133 32 49.307101 0.4827703
134 33 51.310824 0.9424023
135 34 52.413350 0.6997860
136 35 54.116723 1.1927297
137 36 52.618161 1.1686288
138 37 49.822764 1.6303473
139 38 47.107336 1.2013356
140 39 47.104214 1.1986148
132 3   10 48.719484 0.6765047

and I would like it to look like this... (which I did in Excel). The start
of each time 1-10 has an adj_mean of 0.

sort2v4 

point   timemeansd  adj_mean
1   1   1   52.501  1.5073927   0
3   1   2   54.501818   0.8510329   2.000818
4   1   3   56.601739   1.5787222   4.100739
5   1   4   57.21.2292726   4.699
6   1   5   59.32.2632327   6.799
7   1   6   57.800893   1.4745218   5.299893
8   1   7   55.303508   2.2661855   2.802508
9   1   8   51.100943   1.8540025   -1.400057
10  1   9   50.61.7126977   -1.901
2   1   10  52.904716   1.1010460.403716
111 2   1   50.605963   1.2633969   0
113 2   2   52.203828   0.7890765   1.597865
114 2   3   54.100909   1.1013344   3.494946
115 2   4   55  1.1547005   4.394037
116 2   5   57.001725   1.63415 6.395762
117 2   6   55.003591   1.5652438   4.397628
118 2   7   52.911089   1.7373914   2.305126
119 2   8   49.204022   1.0350809   -1.401941
120 2   9   48.904103   0.8747568   -1.70186
112 2   10  50.9157 0.8765483   0.309737
131 3   1   48.608228   0.8433913   0
133 3   2   49.307101   0.4827703   0.698873
134 3   3   51.310824   0.9424023   2.702596
135 3   4   52.413350.6997863.805122
136 3   5   54.116723   1.1927297   5.508495
137 3   6   52.618161   1.1686288   4.009933
138 3   7   49.822764   1.6303473   1.214536
139 3   8   47.107336   1.2013356   -1.500892
140 3   9   47.104214   1.1986148   -1.504014
132 3   10  48.719484   0.6765047   0.111256

Thank you so much for your help.
Kristiina

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-adjust-the-start-of-a-series-to-zero-i-e-subtract-the-first-value-from-the-sequence-tp4634999.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] Covariance structure for lme

2012-06-30 Thread apcoble
This bit helped me to match lme results in R with SAS,  try 

options(contrasts=c(contr.sum,contr.poly))  

before lme model.

--
View this message in context: 
http://r.789695.n4.nabble.com/Covariance-structure-for-lme-tp4630413p4635005.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] Adjusting length of series

2012-06-30 Thread Lekgatlhamang, lexi Setlhare
Hi
I have a follow up question, relating to subsetting to list items. After using 
the list and min(sapply()) method to adjust the length of the variables, I 
specify a dynamic regression equation using the variables in the list. My list 
looks like this:
Dcr- 
list(Dcre1=DCred1,Dcre2=DCred2,Dcre3=DCred3,Dbobc1=DBoBC1,Dbobc2=DBoBC2,Dbobc3=DBoBC3,...)
By specifying the list items with names, I thought I could end by referencing 
them (or subsetting the list) as, eg., Dcr$Dcre1 and get DCred1, Dcr$Dbobc1 and 
get DBoBC1, etc so that the explanatory variables of the equation can be easily 
associated with their respective original names. This way, I would avoid 
specifying the list as Dcr-list(Dcr1, Dcr2, Dcr, 3..., Dcr15) and then 
subsetting the list using Dcr[[1]][1:29], Dcr[[[2]][1:29], ..., Dcr[[15]][1:29] 
because the list has many variables (15) and referencing the variables with 
numbers makes them lose their original names.
When I specify the list as Dcr- list(Dcr1, Dcr2, ..., Dcr15), then the 
regression equation specified as:
# Regression
regCred- 
lm(Dcr[[1]][1:29]~Dcr[[2]][1:29]+Dcr[[3]][1:29]+Dcr[[4]][1:29]+Dcr[[5]][1:29]+Dcr[[6]][1:29]+...)
runs without problems - the results are shown here below:
Call:
lm(formula = Dcr[[1]][1:29] ~ Dcr[[2]][1:29] + Dcr[[3]][1:29] + 
Dcr[[4]][1:29] + Dcr[[5]][1:29] + Dcr[[6]][1:29])
Residuals:
Min  1Q  Median  3Q Max 
-86.293 -33.586  -9.969  40.147 117.965 
Coefficients:
Estimate Std. Error t value Pr(|t|) 
(Intercept)81.02064   13.28632   6.098 3.21e-06 ***
Dcr[[2]][1:29] -0.974070.11081  -8.791 8.20e-09 ***
Dcr[[3]][1:29] -0.279500.05899  -4.738 8.95e-05 ***
Dcr[[4]][1:29] -0.079610.04856  -1.6390.115 
Dcr[[5]][1:29] -0.071800.05515  -1.3020.206 
Dcr[[6]][1:29] -0.015620.02086  -0.7490.462 

But when I specify the list with names as shown above, then the equation does 
not run - as shown by the following error message
 # Regression
 regCred- lm(Dcr[[1]][1:29]~Dcr[[2]][1:29]+Dcr[[3]][1:29]+Dcr[[4]][1:29]+
+ Dcr[[5]][1:29]+Dcr$Dbobc3)
Error in model.frame.default(formula = Dcr[[1]][1:29] ~ Dcr[[2]][1:29] +  : 
variable lengths differ (found for 'Dcr$Dbobc3')
 Dcr[[5]][1:29]+Dcr$Dbobc3[1:29])
Error: unexpected ')' in Dcr[[5]][1:29]+Dcr$Dbobc3[1:29])

NB: In the equation with error message, only the last term is specified by 
referencing its name (ie., Dcr$Dbobc3[1:29]. Also note that the error occurs 
whether I append '[1:29]' to Dcr$Dbobc or not.
How do I resolve this?
Thanks. Lexi

NB: I tried typing the above in the same email Petr used to reply me, but the 
email could not be delivered due to size problems
[[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] loop in list

2012-06-30 Thread arun
Hi,

Try this,

list1-list()
vec-rnorm(15,25)

for(i in 1:20)
{
list1[[i]]-sample(vec,replace=FALSE)
}
list1

[[1]]
 [1] 24.28594 25.05309 25.48962 24.71479 22.48122 25.41300 25.26129 25.15602
 [9] 24.91442 23.65078 26.84776 24.85934 25.00111 24.16320 27.05351

[[2]]
 [1] 24.91442 24.28594 25.05309 24.16320 24.71479 22.48122 25.26129 26.84776
 [9] 25.00111 25.41300 27.05351 25.48962 25.15602 24.85934 23.65078
---


A.K.



- Original Message -
From: solafah bh solafa...@yahoo.com
To: R help mailing list r-help@r-project.org
Cc: 
Sent: Saturday, June 30, 2012 3:34 PM
Subject: [R] loop in list

Hello
I have a loop to sample 20 samples and I want to put them in one list, how I 
can make this?? 
 
Regards
Sulafah
    [[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 adjust the start of a series to zero? (i.e. subtract the first value from the sequence)

2012-06-30 Thread arun
HI,

Try this:
#dat1: data

dat2-split(dat1,dat1$point)
adjmeanlist-lapply(dat2,function(x)x[,3]-x[,3][1])
dat3-data.frame(dat1,adjmean=unlist(adjmeanlist))
 head(dat3)
  point time mean    sd  adjmean
1 1    1 52.50100 1.5073927 0.00
3 1    2 54.50182 0.8510329 2.000818
4 1    3 56.60174 1.5787222 4.100739
5 1    4 57.2 1.2292726 4.699000
6 1    5 59.3 2.2632327 6.799000
7 1    6 57.80089 1.4745218 5.299893



A.K.



- Original Message -
From: Kristiina Hurme kristiina.hu...@uconn.edu
To: r-help@r-project.org
Cc: 
Sent: Saturday, June 30, 2012 5:21 PM
Subject: [R] How to adjust the start of a series to zero? (i.e. subtract the 
first value from the sequence)

Hello, 
I'd have a time series, where I am plotting the means and sd of a distance
for a variety of positions along a bird's bill. I'd like to set each line
(represented by point) to start at zero, so that I can look at the
absolute change along the series. At the moment I only know how to do that
in Excel, by subtracting the value of time 1, point 1 from all other times
for point 1. My actual data set has many points ( 20 per bird, only 3 shown
here), so I would love to make this faster in R. Ideally, I would have
another column titled adj_mean for the adjusted means. 

Here is an example. 

 sort2v4
    point time      mean        sd
1       1    1 52.501000 1.5073927
3       1    2 54.501818 0.8510329
4       1    3 56.601739 1.5787222
5       1    4 57.20 1.2292726
6       1    5 59.30 2.2632327
7       1    6 57.800893 1.4745218
8       1    7 55.303508 2.2661855
9       1    8 51.100943 1.8540025
10      1    9 50.60 1.7126977
2       1   10 52.904716 1.1010460
111     2    1 50.605963 1.2633969
113     2    2 52.203828 0.7890765
114     2    3 54.100909 1.1013344
115     2    4 55.00 1.1547005
116     2    5 57.001725 1.6341500
117     2    6 55.003591 1.5652438
118     2    7 52.911089 1.7373914
119     2    8 49.204022 1.0350809
120     2    9 48.904103 0.8747568
112     2   10 50.915700 0.8765483
131     3    1 48.608228 0.8433913
133     3    2 49.307101 0.4827703
134     3    3 51.310824 0.9424023
135     3    4 52.413350 0.6997860
136     3    5 54.116723 1.1927297
137     3    6 52.618161 1.1686288
138     3    7 49.822764 1.6303473
139     3    8 47.107336 1.2013356
140     3    9 47.104214 1.1986148
132     3   10 48.719484 0.6765047

and I would like it to look like this... (which I did in Excel). The start
of each time 1-10 has an adj_mean of 0. 
 sort2v4                    
    point    time    mean    sd    adj_mean
1    1    1    52.501    1.5073927    0
3    1    2    54.501818    0.8510329    2.000818
4    1    3    56.601739    1.5787222    4.100739
5    1    4    57.2    1.2292726    4.699
6    1    5    59.3    2.2632327    6.799
7    1    6    57.800893    1.4745218    5.299893
8    1    7    55.303508    2.2661855    2.802508
9    1    8    51.100943    1.8540025    -1.400057
10    1    9    50.6    1.7126977    -1.901
2    1    10    52.904716    1.101046    0.403716
111    2    1    50.605963    1.2633969    0
113    2    2    52.203828    0.7890765    1.597865
114    2    3    54.100909    1.1013344    3.494946
115    2    4    55    1.1547005    4.394037
116    2    5    57.001725    1.63415    6.395762
117    2    6    55.003591    1.5652438    4.397628
118    2    7    52.911089    1.7373914    2.305126
119    2    8    49.204022    1.0350809    -1.401941
120    2    9    48.904103    0.8747568    -1.70186
112    2    10    50.9157    0.8765483    0.309737
131    3    1    48.608228    0.8433913    0
133    3    2    49.307101    0.4827703    0.698873
134    3    3    51.310824    0.9424023    2.702596
135    3    4    52.41335    0.699786    3.805122
136    3    5    54.116723    1.1927297    5.508495
137    3    6    52.618161    1.1686288    4.009933
138    3    7    49.822764    1.6303473    1.214536
139    3    8    47.107336    1.2013356    -1.500892
140    3    9    47.104214    1.1986148    -1.504014
132    3    10    48.719484    0.6765047    0.111256

Thank you so much for your help. 
Kristiina

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-adjust-the-start-of-a-series-to-zero-i-e-subtract-the-first-value-from-the-sequence-tp4634999.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] loop in list

2012-06-30 Thread Rui Barradas

Hello,

You can avoid the loop using lapply.

f - function(x) sample(100, 10)
samp.list - lapply(1:20, f)

will choose 20 samples of 10 integers up to 100 and put them in a list. 
All you need is to write a function f(). f() must have an argument, even 
if it doesn't use it. If you need other arguments to be processed by 
f(), define it and call it as, for instance using the example above,


f - function(x, ...) sample(100, 10, ...)
lapply(1:20, f)  # the same
lapply(1:20, f, replace=TRUE) # a second argument

See ?lapply

Hope this helps,

Rui Barradas

Em 30-06-2012 20:34, solafah bh escreveu:

Hello
I have a loop to sample 20 samples and I want to put them in one list, how I 
can make this??

Regards
Sulafah
[[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] loop in list

2012-06-30 Thread R. Michael Weylandt michael.weyla...@gmail.com
I might think replicate() is slightly more idiomatic, but I'm not in a position 
to check if simplify=FALSE will keep a list. 

Best,
Michael

On Jun 30, 2012, at 7:13 PM, Rui Barradas ruipbarra...@sapo.pt wrote:

 Hello,
 
 You can avoid the loop using lapply.
 
 f - function(x) sample(100, 10)
 samp.list - lapply(1:20, f)
 
 will choose 20 samples of 10 integers up to 100 and put them in a list. All 
 you need is to write a function f(). f() must have an argument, even if it 
 doesn't use it. If you need other arguments to be processed by f(), define it 
 and call it as, for instance using the example above,
 
 f - function(x, ...) sample(100, 10, ...)
 lapply(1:20, f)  # the same
 lapply(1:20, f, replace=TRUE) # a second argument
 
 See ?lapply
 
 Hope this helps,
 
 Rui Barradas
 
 Em 30-06-2012 20:34, solafah bh escreveu:
 Hello
 I have a loop to sample 20 samples and I want to put them in one list, how I 
 can make this??
 
 Regards
 Sulafah
[[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] Adjusting length of series

2012-06-30 Thread David Winsemius


On Jun 30, 2012, at 6:04 PM, Lekgatlhamang, lexi Setlhare wrote:


Hi
I have a follow up question, relating to subsetting to list items.  
After using the list and min(sapply()) method to adjust the length  
of the variables, I specify a dynamic regression equation using the  
variables in the list. My list looks like this:
Dcr-  
list 
(Dcre1 
= 
DCred1 
,Dcre2 
=DCred2,Dcre3=DCred3,Dbobc1=DBoBC1,Dbobc2=DBoBC2,Dbobc3=DBoBC3,...)


This should ahve been done like this:

Dcr- data.frame(Dcre1=DCred1, Dcre2=DCred2, Dcre3=DCred3,  
Dbobc1=DBoBC1, Dbobc2=DBoBC2, Dbobc3=DBoBC3)


By specifying the list items with names, I thought I could end by  
referencing them (or subsetting the list) as, eg., Dcr$Dcre1 and get  
DCred1, Dcr$Dbobc1 and get DBoBC1, etc so that the explanatory  
variables of the equation can be easily associated with their  
respective original names. This way, I would avoid specifying the  
list as Dcr-list(Dcr1, Dcr2, Dcr, 3..., Dcr15) and then subsetting  
the list using Dcr[[1]][1:29], Dcr[[[2]][1:29], ..., Dcr[[15]][1:29]  
because the list has many variables (15) and referencing the  
variables with numbers makes them lose their original names.
When I specify the list as Dcr- list(Dcr1, Dcr2, ..., Dcr15), then  
the regression equation specified as:

# Regression
regCred- lm(Dcr[[1]][1:29]~Dcr[[2]][1:29]+Dcr[[3]][1:29]+Dcr[[4]] 
[1:29]+Dcr[[5]][1:29]+Dcr[[6]][1:29]+...)


And the you could have done


regCred- lm(Dcre1 ~ . , data=Dcr [ , 1:29] )


(Leaving out the , ...)



runs without problems - the results are shown here below:
Call:
lm(formula = Dcr[[1]][1:29] ~ Dcr[[2]][1:29] + Dcr[[3]][1:29] +
Dcr[[4]][1:29] + Dcr[[5]][1:29] + Dcr[[6]][1:29])
Residuals:
Min  1Q  Median  3Q Max
-86.293 -33.586  -9.969  40.147 117.965
Coefficients:
Estimate Std. Error t value Pr(|t|)
(Intercept)81.02064   13.28632   6.098 3.21e-06 ***
Dcr[[2]][1:29] -0.974070.11081  -8.791 8.20e-09 ***
Dcr[[3]][1:29] -0.279500.05899  -4.738 8.95e-05 ***
Dcr[[4]][1:29] -0.079610.04856  -1.6390.115
Dcr[[5]][1:29] -0.071800.05515  -1.3020.206
Dcr[[6]][1:29] -0.015620.02086  -0.7490.462

But when I specify the list with names as shown above, then the  
equation does not run - as shown by the following error message

# Regression
regCred- lm(Dcr[[1]][1:29]~Dcr[[2]][1:29]+Dcr[[3]][1:29]+Dcr[[4]] 
[1:29]+

+ Dcr[[5]][1:29]+Dcr$Dbobc3)
Error in model.frame.default(formula = Dcr[[1]][1:29] ~ Dcr[[2]] 
[1:29] +  :

variable lengths differ (found for 'Dcr$Dbobc3')

Dcr[[5]][1:29]+Dcr$Dbobc3[1:29])

Error: unexpected ')' in Dcr[[5]][1:29]+Dcr$Dbobc3[1:29])

NB: In the equation with error message, only the last term is  
specified by referencing its name (ie., Dcr$Dbobc3[1:29]. Also note  
that the error occurs whether I append '[1:29]' to Dcr$Dbobc or not.

How do I resolve this?


You should have offered str(Dcr)



Thanks. Lexi

NB: I tried typing the above in the same email Petr used to reply  
me, but the email could not be delivered due to size problems

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] approximation of test

2012-06-30 Thread David Winsemius


On Jun 30, 2012, at 3:38 PM, solafah bh wrote:


Hello
I want to use this function in R (wilcox.test) , is this function  
can approximate the statistic automatically  if the sample size is  
large or not??


Why don't you test it?



Regards
Sulafah
[[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.


David Winsemius, MD
West Hartford, CT

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


Re: [R] Adjusting length of series

2012-06-30 Thread David Winsemius


On Jun 30, 2012, at 8:47 PM, David Winsemius wrote:



On Jun 30, 2012, at 6:04 PM, Lekgatlhamang, lexi Setlhare wrote:


Hi
I have a follow up question, relating to subsetting to list items.  
After using the list and min(sapply()) method to adjust the length  
of the variables, I specify a dynamic regression equation using the  
variables in the list. My list looks like this:
Dcr-  
list 
(Dcre1 
= 
DCred1 
,Dcre2 
=DCred2,Dcre3=DCred3,Dbobc1=DBoBC1,Dbobc2=DBoBC2,Dbobc3=DBoBC3,...)


This should ahve been done like this:

Dcr- data.frame(Dcre1=DCred1, Dcre2=DCred2, Dcre3=DCred3,  
Dbobc1=DBoBC1, Dbobc2=DBoBC2, Dbobc3=DBoBC3)


By specifying the list items with names, I thought I could end by  
referencing them (or subsetting the list) as, eg., Dcr$Dcre1 and  
get DCred1, Dcr$Dbobc1 and get DBoBC1, etc so that the explanatory  
variables of the equation can be easily associated with their  
respective original names. This way, I would avoid specifying the  
list as Dcr-list(Dcr1, Dcr2, Dcr, 3..., Dcr15) and then subsetting  
the list using Dcr[[1]][1:29], Dcr[[[2]][1:29], ..., Dcr[[15]] 
[1:29] because the list has many variables (15) and referencing the  
variables with numbers makes them lose their original names.
When I specify the list as Dcr- list(Dcr1, Dcr2, ..., Dcr15), then  
the regression equation specified as:

# Regression
regCred- lm(Dcr[[1]][1:29]~Dcr[[2]][1:29]+Dcr[[3]][1:29]+Dcr[[4]] 
[1:29]+Dcr[[5]][1:29]+Dcr[[6]][1:29]+...)


And the you could have done


regCred- lm(Dcre1 ~ . , data=Dcr [ , 1:29] )


Oh, Nuts! I meant to type:

regCred- lm(Dcre1 ~ . , data=Dcr [ 1:29, ] )


(Leaving out the , ...)



runs without problems - the results are shown here below:
Call:
lm(formula = Dcr[[1]][1:29] ~ Dcr[[2]][1:29] + Dcr[[3]][1:29] +
Dcr[[4]][1:29] + Dcr[[5]][1:29] + Dcr[[6]][1:29])
Residuals:
Min  1Q  Median  3Q Max
-86.293 -33.586  -9.969  40.147 117.965
Coefficients:
Estimate Std. Error t value Pr(|t|)
(Intercept)81.02064   13.28632   6.098 3.21e-06 ***
Dcr[[2]][1:29] -0.974070.11081  -8.791 8.20e-09 ***
Dcr[[3]][1:29] -0.279500.05899  -4.738 8.95e-05 ***
Dcr[[4]][1:29] -0.079610.04856  -1.6390.115
Dcr[[5]][1:29] -0.071800.05515  -1.3020.206
Dcr[[6]][1:29] -0.015620.02086  -0.7490.462

But when I specify the list with names as shown above, then the  
equation does not run - as shown by the following error message

# Regression
regCred- lm(Dcr[[1]][1:29]~Dcr[[2]][1:29]+Dcr[[3]][1:29]+Dcr[[4]] 
[1:29]+

+ Dcr[[5]][1:29]+Dcr$Dbobc3)
Error in model.frame.default(formula = Dcr[[1]][1:29] ~ Dcr[[2]] 
[1:29] +  :

variable lengths differ (found for 'Dcr$Dbobc3')

Dcr[[5]][1:29]+Dcr$Dbobc3[1:29])

Error: unexpected ')' in Dcr[[5]][1:29]+Dcr$Dbobc3[1:29])

NB: In the equation with error message, only the last term is  
specified by referencing its name (ie., Dcr$Dbobc3[1:29]. Also note  
that the error occurs whether I append '[1:29]' to Dcr$Dbobc or not.

How do I resolve this?



This still applies:

You should have offered str(Dcr)






David Winsemius, MD
West Hartford, CT

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


Re: [R] Help

2012-06-30 Thread li li
Hi John,
  It worked. Thanks a lot!
Hannah

2012/6/30 John Kane jrkrid...@inbox.com

 It looks like we have different versions of software loaded.
 I have R version 2.15.0 (2012-03-30)

 My packages.
 reshape2_1.2.1 ggplot2_0.9.0

 Hannah's packages.
 R version 2.12.2 (2011-02-25)
  quantreg_4.71 SparseM_0.89  reshape2_1.1  ggplot2_0.8.9 proto_0.3-9.2
 [6] reshape_0.8.4 plyr_1.6


 It looks like quantreg is causing a problem since Peter says that the
 function is in the quantreg *package*.

 The first step would probably be to make sure that quantreg is not loaded
 and try the code again.  It probably would work with an older version of
 ggplot2 and the old version of reshape.  The command :
 unattach(package::quantreg) should work.

 Retry the code and see what happens.

 However I I think that you need to upgrade your version of R, and both
  ggplot2 and reshape2.  .  If I remember correctly your version of ggplot2
 is loading reshape and plyr automatically as you mention below.  The newer
 version does not and one need to explicitly load reshape2.and plyr.  So  it
 is possible that  reshape_0;8.4 is masking reshape2_1.2.1 which can cause
 problems.

 I'd suggest upgrading R,  , make sure that quantreg is not being loaded
 automatically, or if it is unattach it( see above|),  and then upgrade both
 reshape2 and ggplot to to the most recent versions and see what happens
 running the code from my first post.


 Best of luck.

 John Kane
 Kingston ON Canada


  -Original Message-
  From: hannah@gmail.com
  Sent: Sat, 30 Jun 2012 14:59:19 -0400
  To: ehl...@ucalgary.ca
  Subject: Re: [R] Help
 
  The following is what I get when I run the code.
 
 
  library(ggplot2)
  Loading required package: reshape
  Loading required package: plyr
 
  Attaching package: 'reshape'
 
  The following object(s) are masked from 'package:plyr':
 
  rename, round_any
 
  Loading required package: grid
  Loading required package: proto
  library(reshape2)
 
  Attaching package: 'reshape2'
 
  The following object(s) are masked from 'package:reshape':
 
  colsplit, melt, recast
 
 
  A  -  data.frame( m = (rep(A, 10)) , b=rnorm(10), c = rnorm(10))
  B  -  data.frame( m = (rep(B, 10)) , b=rnorm(10), c = rnorm(10))
  C  -  data.frame( m = (rep(C, 10)) , b=rnorm(10), c = rnorm(10))
 
  mydata  -  rbind( A, B, C )
  names(mydata)  -  c( group, k1, k2 )
  mdata  -  melt(mydata)
  Using group as id variables
 
  p  -  ggplot( mdata , aes(variable, value , colour = variable )) +
  geom_boxplot() +
  +   facet_grid( group ~ .)
  p
  Error in rq.fit.br(x, y, tau = tau, ...) : Singular design matrix
  In addition: Warning message:
  In is.na(rows) : is.na() applied to non-(list or vector) of type 'NULL'
 
 
 
  And my session info is as below:
 
 
  sessionInfo()
  R version 2.12.2 (2011-02-25)
  Platform: i386-apple-darwin9.8.0/i386 (32-bit)
 
  locale:
  [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
 
  attached base packages:
  [1] grid  stats graphics  grDevices utils datasets  methods
  [8] base
 
  other attached packages:
  [1] quantreg_4.71 SparseM_0.89  reshape2_1.1  ggplot2_0.8.9 proto_0.3-9.2
  [6] reshape_0.8.4 plyr_1.6
 
  loaded via a namespace (and not attached):
  [1] stringr_0.5
 
 
  When I tried to load package ggplot, I was asked to also load some of the
  other packages, for example plyr. Thanks.
  Hannah
 
  2012/6/30 Peter Ehlers ehl...@ucalgary.ca
 
  On 2012-06-30 07:04, John Kane wrote:
 
 
 Hi Hannah,
 I have run both the original code and the code copied from the email
  and
 both seem to work just fine.
 I don't know why you are getting that error message.   Do you have
  both
 ggplot2 and reshape2 loaded?  Still that should not give you the
  error
 message you are getting. In fact given the data I supplied, I just
  don't
 understand what it is trying to say.
 I cannot even find a function [1]rq.fit.br.
 
  [...]
 
  This function is in the quantreg *package*. So Hannah isn't
  telling us the whole story.
 
  Peter Ehlers
 
 
 
[[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.

 
 FREE ONLINE PHOTOSHARING - Share your photos online with your friends and
 family!
 Visit http://www.inbox.com/photosharing to find out more!




[[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] Adjusting length of series

2012-06-30 Thread arun
Hello,
Try this:


Dcr-lapply(1:5,function(x) rnorm(10,15)) 
names(Dcr)- c(Dcre1,Dcre2,Dcre3,Dcre4,Dcre5)
#Works
regCred-lm(Dcr[[1]]~Dcr[[2]]+Dcr[[3]])
 summary(regCred)
#Works
 regCred2-lm(Dcre1~Dcre2+Dcre3,data=Dcr)
 summary(regCred)
# Do not work
regCred3-lm(Dcr[[1]][1:5]~Dcr[[4]][1:5]+Dcre5,data=Dcr)
Error in model.frame.default(formula = Dcr[[1]][1:5] ~ Dcr[[4]][1:5] +  : 
  variable lengths differ (found for 'Dcre5')
#I guess this is what happened in your example, when different variable lengths 
are used


#If you had used,

regCred3-lm(Dcr[[1]][1:5]~Dcr[[4]][1:5]+Dcre5[1:5],data=Dcr)
 summary(regCred3)
#it works
#this also works

regCred4-lm(Dcre1[1:5]~Dcre2[1:5]+Dcre3[6:10],data=Dcr)

Or you could convert the list to dataframe

 Dcr2-data.frame(Dcre1=Dcr$Dcre1,Dcre2=Dcr$Dcre2,Dcre3=Dcr$Dcre3)

#testing whether list and dataframe converted results are same
#From dataframe 

regCred5-lm(Dcre1~Dcre2+Dcre3,data=Dcr2[1:5,])
 summary(regCred5)

Call:
lm(formula = Dcre1 ~ Dcre2 + Dcre3, data = Dcr2[1:5, ])

Residuals:
   1    2    3    4    5 
-0.01262  0.09888  0.07133 -0.08494 -0.07265 

Coefficients:
    Estimate Std. Error t value Pr(|t|)   
(Intercept) 16.53707    0.99604  16.603  0.00361 **
Dcre2   -0.27890    0.04185  -6.665  0.02178 * 
Dcre3    0.21874    0.04643   4.711  0.04222 * 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
 
#Same model using list

regCred6-lm(Dcre1[1:5]~Dcre2[1:5]+Dcre3[1:5],data=Dcr)
 summary(regCred6)

Call:
lm(formula = Dcre1[1:5] ~ Dcre2[1:5] + Dcre3[1:5], data = Dcr)

Residuals:
   1    2    3    4    5 
-0.01262  0.09888  0.07133 -0.08494 -0.07265 

Coefficients:
    Estimate Std. Error t value Pr(|t|)   
(Intercept) 16.53707    0.99604  16.603  0.00361 **
Dcre2[1:5]  -0.27890    0.04185  -6.665  0.02178 * 
Dcre3[1:5]   0.21874    0.04643   4.711  0.04222 * 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.1173 on 2 degrees of freedom
Multiple R-squared: 0.9739,    Adjusted R-squared: 0.9478 
F-statistic: 37.28 on 2 and 2 DF,  p-value: 0.02612 



The difference is in the names of the coefficients.  

names(coef(regCred6))
[1] (Intercept) Dcre2[1:5]  Dcre3[1:5] 
which you can change by,
names(regCred6$coef)-names(regCred5$coef)
 regCred6$coef
(Intercept)   Dcre2   Dcre3 
 16.5370694  -0.2788988   0.2187360 


Though, it won't change the names of coefficients in the summary.  I tried 
several ways, but so far not successful.  I think in that case, the easiest way 
is to assign the subset to a new variable and run the analysis.

e.g.

Dcre1new-Dcre1[1:5]



Hope this was helpful.

A.K.







- Original Message -
From: Lekgatlhamang, lexi Setlhare lexisetlh...@yahoo.com
To: r-help@r-project.org r-help@r-project.org
Cc: 
Sent: Saturday, June 30, 2012 6:04 PM
Subject: [R]  Adjusting length of series

Hi
I have a follow up question, relating to subsetting to list items. After using 
the list and min(sapply()) method to adjust the length of the variables, I 
specify a dynamic regression equation using the variables in the list. My list 
looks like this:
Dcr- 
list(Dcre1=DCred1,Dcre2=DCred2,Dcre3=DCred3,Dbobc1=DBoBC1,Dbobc2=DBoBC2,Dbobc3=DBoBC3,...)
By specifying the list items with names, I thought I could end by referencing 
them (or subsetting the list) as, eg., Dcr$Dcre1 and get DCred1, Dcr$Dbobc1 and 
get DBoBC1, etc so that the explanatory variables of the equation can be easily 
associated with their respective original names. This way, I would avoid 
specifying the list as Dcr-list(Dcr1, Dcr2, Dcr, 3..., Dcr15) and then 
subsetting the list using Dcr[[1]][1:29], Dcr[[[2]][1:29], ..., Dcr[[15]][1:29] 
because the list has many variables (15) and referencing the variables with 
numbers makes them lose their original names.
When I specify the list as Dcr- list(Dcr1, Dcr2, ..., Dcr15), then the 
regression equation specified as:
# Regression
regCred- 
lm(Dcr[[1]][1:29]~Dcr[[2]][1:29]+Dcr[[3]][1:29]+Dcr[[4]][1:29]+Dcr[[5]][1:29]+Dcr[[6]][1:29]+...)
runs without problems - the results are shown here below:
Call:
lm(formula = Dcr[[1]][1:29] ~ Dcr[[2]][1:29] + Dcr[[3]][1:29] + 
Dcr[[4]][1:29] + Dcr[[5]][1:29] + Dcr[[6]][1:29])
Residuals:
Min      1Q  Median      3Q     Max 
-86.293 -33.586  -9.969  40.147 117.965 
Coefficients:
Estimate Std. Error t value Pr(|t|) 
(Intercept)    81.02064   13.28632   6.098 3.21e-06 ***
Dcr[[2]][1:29] -0.97407    0.11081  -8.791 8.20e-09 ***
Dcr[[3]][1:29] -0.27950    0.05899  -4.738 8.95e-05 ***
Dcr[[4]][1:29] -0.07961    0.04856  -1.639    0.115 
Dcr[[5]][1:29] -0.07180    0.05515  -1.302    0.206 
Dcr[[6]][1:29] -0.01562    0.02086  -0.749    0.462 

But when I specify the list with names as shown above, then the equation does 
not run - as shown by the following error message
 # Regression
 regCred- lm(Dcr[[1]][1:29]~Dcr[[2]][1:29]+Dcr[[3]][1:29]+Dcr[[4]][1:29]+
+ Dcr[[5]][1:29]+Dcr$Dbobc3)

[R] Batch file rename basing on a look up table need help_New to R_A little bit complicated

2012-06-30 Thread wxx3dodu
Hello, all
I'm pretty new to R and I wish to accomplish the following task

I have many files need to do this task. I simplify the situation to five
files. Their names are
001
232
242
123
132

I'd like to change the name of each file (column 1) to the name in column 2
in the following table
column1column2
001  ewr
232  eda
242  gdg
123  sgs
132  ger

I'm wondering if anyone could point out a way to do it.
Thank you very much in advance!



--
View this message in context: 
http://r.789695.n4.nabble.com/Batch-file-rename-basing-on-a-look-up-table-need-help-New-to-R-A-little-bit-complicated-tp4635015.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] significant difference between Gompertz hazard parameters?

2012-06-30 Thread piltdownpunk
Hello, all.

I have co-opted a number of functions that can be used to plot the
hazard/survival functions and associated density distribution for a Gompertz
mortality model, given known parameters.  The Gompertz hazard model has been
shown to fit relatively well to the human adult lifespan.  For example, if I
wanted to plot the hazard (i.e., mortality) functions:

pop1 - function (t)
{
x=c(0.03286343, 0.04271132)
a3-x[1]
b3-x[2]
shift-15 # only considering mortality after 15 years

h.t-a3*exp(b3*(t-shift))
return-h.t
}

pop2 - function (t)
{
x=c(0.02207778, 0.04580059)
a3-x[1]
b3-x[2]
shift-15 # only considering mortality after 15 years

h.t-a3*exp(b3*(t-shift))
return-h.t
}

ylab.name - expression(paste(italic(h),(,italic(a),)))
plot(seq(15,80,1),pop1(seq(15,80,1)),type='l',ylab=ylab.name,xlab='Age
(years)',ylim=c(0,0.8))
lines(seq(15,80,1),pop2(seq(15,80,1)),lty=2)

How may I test for a significant difference in the hazard parameters that
define the mortality experience for these two populations?  Thanks in
advance.

Regards,
Trey

-
Trey Batey---Anthropology Instructor
Division of Social Sciences
Mt. Hood Community College
Gresham, OR  97030
Alt. Email:  trey.batey[at]mhcc[dot]edu
--
View this message in context: 
http://r.789695.n4.nabble.com/significant-difference-between-Gompertz-hazard-parameters-tp4635018.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] dcc in 'bootRes' package

2012-06-30 Thread andresholz
Hi Xanthe,
I'm running in the exact same issue.  
Were you able to solve it? Could you please give me a hand?
Thanks!
Andres


--
View this message in context: 
http://r.789695.n4.nabble.com/dcc-in-bootRes-package-tp380p4635017.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 adjust the start of a series to zero? (i.e. subtract the first value from the sequence)

2012-06-30 Thread Bert Gunter
Simpler:

dat1$adj_mean -  within(dat1, ave(mean, point, FUN = function(x)x-x[1]))

ave() is a very handy function for this sort of thing.
within()  saves typing.

-- Bert

On Sat, Jun 30, 2012 at 4:16 PM, arun smartpink...@yahoo.com wrote:

 HI,

 Try this:
 #dat1: data

 dat2-split(dat1,dat1$point)
 adjmeanlist-lapply(dat2,function(x)x[,3]-x[,3][1])
 dat3-data.frame(dat1,adjmean=unlist(adjmeanlist))
  head(dat3)
   point time meansd  adjmean
 1 11 52.50100 1.5073927 0.00
 3 12 54.50182 0.8510329 2.000818
 4 13 56.60174 1.5787222 4.100739
 5 14 57.2 1.2292726 4.699000
 6 15 59.3 2.2632327 6.799000
 7 16 57.80089 1.4745218 5.299893



 A.K.



 - Original Message -
 From: Kristiina Hurme kristiina.hu...@uconn.edu
 To: r-help@r-project.org
 Cc:
 Sent: Saturday, June 30, 2012 5:21 PM
 Subject: [R] How to adjust the start of a series to zero? (i.e. subtract
 the first value from the sequence)

 Hello,
 I'd have a time series, where I am plotting the means and sd of a distance
 for a variety of positions along a bird's bill. I'd like to set each line
 (represented by point) to start at zero, so that I can look at the
 absolute change along the series. At the moment I only know how to do that
 in Excel, by subtracting the value of time 1, point 1 from all other times
 for point 1. My actual data set has many points ( 20 per bird, only 3 shown
 here), so I would love to make this faster in R. Ideally, I would have
 another column titled adj_mean for the adjusted means.

 Here is an example.

  sort2v4
 point time  meansd
 1   11 52.501000 1.5073927
 3   12 54.501818 0.8510329
 4   13 56.601739 1.5787222
 5   14 57.20 1.2292726
 6   15 59.30 2.2632327
 7   16 57.800893 1.4745218
 8   17 55.303508 2.2661855
 9   18 51.100943 1.8540025
 10  19 50.60 1.7126977
 2   1   10 52.904716 1.1010460
 111 21 50.605963 1.2633969
 113 22 52.203828 0.7890765
 114 23 54.100909 1.1013344
 115 24 55.00 1.1547005
 116 25 57.001725 1.6341500
 117 26 55.003591 1.5652438
 118 27 52.911089 1.7373914
 119 28 49.204022 1.0350809
 120 29 48.904103 0.8747568
 112 2   10 50.915700 0.8765483
 131 31 48.608228 0.8433913
 133 32 49.307101 0.4827703
 134 33 51.310824 0.9424023
 135 34 52.413350 0.6997860
 136 35 54.116723 1.1927297
 137 36 52.618161 1.1686288
 138 37 49.822764 1.6303473
 139 38 47.107336 1.2013356
 140 39 47.104214 1.1986148
 132 3   10 48.719484 0.6765047

 and I would like it to look like this... (which I did in Excel). The start
 of each time 1-10 has an adj_mean of 0.
  sort2v4
 pointtimemeansdadj_mean
 11152.5011.50739270
 31254.5018180.85103292.000818
 41356.6017391.57872224.100739
 51457.21.22927264.699
 61559.32.26323276.799
 71657.8008931.47452185.299893
 81755.3035082.26618552.802508
 91851.1009431.8540025-1.400057
 101950.61.7126977-1.901
 211052.9047161.1010460.403716
 1112150.6059631.26339690
 1132252.2038280.78907651.597865
 1142354.1009091.10133443.494946
 11524551.15470054.394037
 1162557.0017251.634156.395762
 1172655.0035911.56524384.397628
 1182752.9110891.73739142.305126
 1192849.2040221.0350809-1.401941
 1202948.9041030.8747568-1.70186
 11221050.91570.87654830.309737
 1313148.6082280.84339130
 1333249.3071010.48277030.698873
 1343351.3108240.94240232.702596
 1353452.413350.6997863.805122
 1363554.1167231.19272975.508495
 1373652.6181611.16862884.009933
 1383749.8227641.63034731.214536
 1393847.1073361.2013356-1.500892
 1403947.1042141.1986148-1.504014
 13231048.7194840.67650470.111256

 Thank you so much for your help.
 Kristiina

 --
 View this message in context:
 http://r.789695.n4.nabble.com/How-to-adjust-the-start-of-a-series-to-zero-i-e-subtract-the-first-value-from-the-sequence-tp4634999.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.