Re: [R] sum with dates

2011-12-12 Thread Jorge I Velez
Hi Ana,

Check section 4 of http://www.jstatsoft.org/v40/i03/paper for more
alternatives.

HTH,
Jorge.-


On Mon, Dec 12, 2011 at 9:39 PM, Ana <> wrote:

> How do I sum 15 years to my dataset?
>
> original dataset
> datesval
> 12001-01-121.2
> 22001-02-121.2
> 32001-03-121.2
>
> result
> datesval
> 1 2016-01-12 1.2
> 22016-02-12 1.2
> 32016-03-12 1.2
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] sum with dates

2011-12-12 Thread Enrico Schumann


If "adding x years to a date" means "increase the  part of a date by 
x", then it should be easiest to manipulate the character representation 
of your date.


dates <- as.Date(c("2001-01-12","2001-02-12","2001-03-12"))

addYear <- function(d,addyears) {
Y <- as.numeric(strftime(d, "%Y")) + addyears
as.Date(paste(Y, strftime(d,"-%m-%d"), sep = ""))
}

## (There are leapyears with more than 365 days.)
dates + 365*15
addYear(dates,15)

That said, you cannot "go one year ahead" from February 29, unless you 
go ahead by 4, 8, 12, ... years (unless the new year is divisible by 100 
but not by 400). One possibility would be to leave such dates as Feb 28.


addYear <- function(d,addyears) {
Y <- as.numeric(strftime(d, "%Y")) + addyears
YisLeapyear <- Y%%400==0L | ((Y%%4==0L) & !(Y%%100==0L))
mdpart <- strftime(d,"-%m-%d")
mdpart <- ifelse(mdpart == "-02-29" & YisLeapyear,
 mdpart, "-02-28")
as.Date(paste(Y, mdpart, sep = ""))

}

dates <- as.Date(c("2001-01-12","2001-02-12","2001-03-12",
   "1899-02-28","1896-02-29","2000-03-01"))
addYear(dates,4)
addYear(dates,5)
addYear(dates,8)



Regards,
Enrico



Am 13.12.2011 04:17, schrieb R. Michael Weylandt:

It depends how your dates are stored, but generally you can just add
365*15 to them. E.g.,

print(x<- Sys.Date())
print(x + 365*15)

So for you,

dataset$dates<- dataset$dates + 365*15

Michael

On Mon, Dec 12, 2011 at 9:39 PM, Ana  wrote:

How do I sum 15 years to my dataset?

original dataset
 datesval
12001-01-121.2
22001-02-121.2
32001-03-121.2

result
 datesval
1 2016-01-12 1.2
22016-02-12 1.2
32016-03-12 1.2

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


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



--
Enrico Schumann
Lucerne, Switzerland
http://nmof.net/

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


Re: [R] Creating appropriate time axis for data

2011-12-12 Thread Jeff Newmiller
"Does not support natively" isn't accurate. It is common to import date/time 
values as character and then use strptime or as.Date or other conversion 
function as desired. This may at first seem tedious, but it does provide 
flexibility.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Tony Stocker  wrote:

>2011/12/12 Uwe Ligges :
>> On 12.12.2011 17:44, Tony Stocker wrote:
>
>Sorry for the double post but the first message was held for so long
>that I figured there was a problem with the email address I was using
>so I unsubscribed that one and resubscribed the other one.
>
>>>
>>> Hello,
>>>
>>> I am dealing with data stored in a database as a 'time' object.  I
>>> export the data from the database to a text file and utilize the
>>> 'time_to_sec()'
>>
>>
>> I get
>>
>>> time_to_sec
>> Error: object 'time_to_sec' not found
>>
>> If it is in a package, please tell us which one you are referring to.
>
>The time_to_sec() function is inside the database (in this case
>MySQL).  I'm using it solely because R doesn't want to deal with the
>times as normally outputted (HH:MM:SS) because it sees them as a
>character object and not a numerical or time object.  By converting
>these time fields to seconds when I export them from the database I
>provide something that R can work with natively apparently.
>>
>>
>>> seconds.  However when I visualize the data in charts I do not want
>a
>>> scale that runs from 25200-64800 seconds, but rather in the HH:MM:SS
>>> format.  Is there a relatively straight-forward and easy to use way
>to
>>> do this?
>>
>>
>> Yes, e.g.:
>>
>> t <- strptime(c("07:00:00", "18:00:00"), "%H:%M:%S")
>> y <- rnorm(2)
>> plot(t, x)
>>
>Does this method supercede  the original y-axis label or supplement
>it?  Will the data be correctly located along the y-axis if it's in
>seconds?
>
>I thought I had looked at strptime() and it required day/date info to
>be listed not just time.  Based on your example I'm assuming that I
>was incorrect in that assumption.
>
>Thanks for this suggestion I'll give it a try with my data and see if
>it does what I'd like it to do.  I appreciate the help.
>
>> Uwe Ligges
>
>-Tony
>
>__
>R-help@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/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] Inverse matrix using eigendecomposition

2011-12-12 Thread Berend Hasselman

wwreith wrote
> 
> General goal: Write R code to find the inverse matrix of an nxn positive
> definite symmetric matrix. Use solve() to verify your code works.
> 
> Started with a 3x3 matrix example to build the code, but something dosen't
> seem to be working. I just don't know where I am going wrong.
> 
> ##Example matrix I found online
> A<-c(4,1,-1,1,2,1,-1,1,2)
> m<-matrix(A,nrow=3,ncol=3)
> 
> ##Caculate the eigen vectors and eigenvalues
> E<-eigen(m, sym=TRUE)
> Q<-E$vectors
> V<-E$values
> n<-nrow(m)
> 
> ##normalize the eigenvectors
> for(i in 1:n){
>   Q[,i]<-Q[,i]/sqrt(sum(Q[,i]^2))
> }
> 
> ##verify dot product of vectors are orthogonal
> sum(Q[,1]*Q[,2])
> sum(Q[,1]*Q[,3])
> sum(Q[,2]*Q[,3])
> 
> ##Begin creating QDQ^T matrix. Where Q are orthonormal eigenvectors, and D
> is a diagonal matrix with 1/eigenvalues on the diagonal. and Q^T is the
> transpose of Q. 
> 
> R<-t(Q)
> D<-mat.or.vec(n,n)
> for(i in 1:n) {
>   D[i,i]<-1/V[i]
>   }
> P<-Q*D*R
> 
> ## P should be the inverse of the matrix m. Check using 
> 
> solve(m)
> 
> ## solve(m) does not equal P? Any ideas of what I am missing/not
> understanding?
> 

Homework questions are not answered.

But to give you a hint: look in the "An Introduction to R" manual Chapter 5
"Array and Matrices" especially section 5.7 "Matrix facilities".
(http://cran.r-project.org/doc/manuals/R-intro.html)

You should be able to work out what's wrong in your script (a single
statement).

Berend

--
View this message in context: 
http://r.789695.n4.nabble.com/Inverse-matrix-using-eigendecomposition-tp4188673p415.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] calculating logit parameters (odd ratio is exactly one or zero)

2011-12-12 Thread wim nursal
Dear Uwe and David,

Yes, definitely i was wrong.  The expression in R should be:

glm(cbind(FD, 12 - FD) ~ Fsize, family=binomial, data=subFS)

Call:  glm(formula = cbind(FD, 12 - FD) ~ Fsize, family = binomial,
data = subFS)

Coefficients:
(Intercept)Fsize
 0.6381  -0.1203

Degrees of Freedom: 29 Total (i.e. Null);  28 Residual
Null Deviance:  193.3
Residual Deviance: 179.9AIC: 245.1


(the direction of Fsize is as expected).

I am not sure with your second statement mentioning that "R can deal with
perfect separation".  Despite of convergence issue, does R take into
account zero or infinite odds value or leave them to calculate the
parameters? How? I need to know the basic of this calculation since so far
I haven't found any literature discuss this problem and the way to handle
this (well, someone need to understand this as well :) )
David, i'm thinking to use LDA as well but i cannot comment this time.

Thanks for any clarification.

Best,
Wim

Research Officer
CIFOR-Indonesia













On Tue, Dec 13, 2011 at 4:08 AM, David Winsemius wrote:

>
> On Dec 12, 2011, at 3:51 PM, Uwe Ligges wrote:
>
>  1. The formula you used is not for a logistic but an ordinal regression
>> (since you are using the default gaussian family rather than
>> family="binomial" or whatever.
>>
>
> this this then produce one version of the "Armitage linear test of trend"?
>
>
>
>> 2. R (nor any other software) can deal with perfect separation (nor
>> quasi-separation) of classes, since the problem is not well defined in such
>> a case as you found out already. R will give a warning in that case, that
>> the Fisher Scoring does not converge.
>>
>> LDA will give perfect results in such a case (well, unless the within
>> class covariance matrix is singular).
>>
>> Best,
>> Uwe Ligges
>>
>>
>>
>> On 12.12.2011 11:46, wim nursal wrote:
>>
>>> Dear statistician experts,
>>>
>>> Sorry if this is a trivial question, or the old same question (i don't
>>> know
>>> what is the efficient key word for this issue).
>>> In order to understand the calculation of parameter of logistic
>>> regression,
>>>  I did an exercise through spreadsheet following the procedural example
>>> from a literature, or the available spreadsheet (with calculation
>>> formula).
>>> I ended up with infinity (divided by zero) when the odd ratio is exactly
>>> 1
>>> (FD=12) or invalid number when odd ratio is zero (MFD = 0) after log.
>>> I am wondering  how R through GLM function (particularly logit or
>>> logistic
>>> regression) treats the odds ratios or log odd ratios that is exatcly one
>>> or
>>> zeros.
>>>
>>> The sample data is like this:
>>> #HH Fsize FD
>>> 1 1.29472 0
>>> 2 1.6184 0
>>> 3 2.4276 1
>>> 4 2.4276 2
>>> 5 20.23 2
>>> 6 1.6184 3
>>> 7 1.820 3
>>> 8 0.4046 3
>>> 9 6.069 4
>>> 10 2.6299 4
>>> 11 0.72828 5
>>> 12 2.4276 5
>>> 13 6.069 7
>>> 14 4.8552 7
>>> 15 2.32645 7
>>> 16 1.6184 8
>>> 17 1.0115 8
>>> 18 1.0115 8
>>> 19 5.2598 9
>>> 20 2.023 10
>>> 21 0.6069 10
>>> 22 1.2138 11
>>> 23 0.8092 11
>>> 24 1.4161 11
>>> 25 0.6069 11
>>> 26 3.440 11
>>> 27 1.2138 12
>>> 28 1.2138 12
>>> 29 0.4046 12
>>> 30 1.2138 12
>>>
>>> Fsize is the farm size (acre or hectare).  Food deficit (FD) is the
>>> number
>>> of months (last year from the survey took place) that an household had
>>> bought food-grains (minimum = 0 month, maximum = 12 months or whole year
>>> deficit).
>>> Even though I "jitter"-ed the minimum or maximum FD value only (eg.
>>> FD=0+1e-6 or FD=12-1e-6), nothing changed to the result.
>>>
>>> The formula I used is like this:
>>> --**--**--
>>> glm(FD ~ Fsize, data = subFS)
>>> --
>>> Coefficients:
>>> (Intercept)Fsize
>>> 7.7913  -0.3092
>>>
>>> Degrees of Freedom: 29 Total (i.e. Null);  28 Residual
>>> Null Deviance:  463
>>> Residual Deviance: 425.5AIC: 170.7
>>> --**--**--
>>>
>>> I appreciate for any clarification.
>>>
>>> Best wishes,
>>> Wim
>>>
>>>
>>>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>

[[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] Please delete my e-mail judit.barr...@montana.edu

2011-12-12 Thread Barroso, Judit
Please,
I am receiving lot of e-mails that I do not want.
Please could you delete my e-mail.

Thank,
Judit

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Thomas Adams
Sent: Monday, December 12, 2011 3:22 PM
To: Bert Gunter
Cc: r-help@r-project.org
Subject: Re: [R] Boxplot of multiple vectors with different lengths

Bert,

I may be mistaken, but I thought Ryan wrote "write code that automatically 
*imports
data* from different files (with different lengths-just one variable)", so, I 
was referring to doing something with the data before it gets into R. I 
understand that one should not need to write out data and then re-read it in 
some way. As I said, those more experienced with R will probably offer better 
ideas.

Tom

On Mon, Dec 12, 2011 at 5:05 PM, Bert Gunter  wrote:

> Sorry -- previous versiuon prematurely sent. Full version is:
>
>  Yikes!  You should never have to do this sort of thing (writing stuff  
> out to files, etc.)
>
>  What is wanted, I believe, is ?do.call as in
>
>  do.call(boxplot, z)
>
>  where z is list(a,b,c)   as Sarah described.
>
>  However, I think you might do even better in terms of controlling  
> options, labels, etc. if you would get the data into standard flat  
> file format (data frame) as
>
> Result Source
>  1a
>  3   b
> 2 b
>  5 c
> ... etc.
>
> (This is easy to do in R and via many packages.) and then use he 
> formula interface in the lattice ?bwplot  function for th eplot.
>
> Cheers,
> Bert
>
> >
> > result
> >
> > On Mon, Dec 12, 2011 at 1:43 PM, Thomas Adams 
> > 
> wrote:
> >> Ryan,
> >>
> >> I think you could do what you want by having the vector data 
> >> written to separate files; then create a file containing the 
> >> individual file
> names. In
> >> R, read the file containing the list of file names and loop through 
> >> this reading in the individual vector files. Maybe this is an 
> >> inelegant,
> brute
> >> force approach, but it has worked for me with essentially the same
> problem.
> >>
> >> Tom
> >>
> >> On Mon, Dec 12, 2011 at 4:24 PM, Ryan Utz  wrote:
> >>
> >>> Hello,
> >>>
> >>> I'm attempting to write a code that automatically imports data 
> >>> from different files (with different lengths-just one variable) 
> >>> and makes
> tidy
> >>> box plots for comparison. I can successfully import the data and
> create a
> >>> list of the vectors I want to compare. But I cannot, for the life 
> >>> of
> me,
> >>> figure out how to generate box plots using the "list" option. 
> >>> Suppose
> these
> >>> are my data:
> >>>
> >>> a<-c(1,1,1,1,2,3,2,1,2,3)
> >>> b<-c(2,2,2,3,4,4,4,3,3)
> >>> c<-c(4,3,3,2,3,4,5,3,3,3,4,4,5,6,3,2)
> >>>
> >>> And this is my list of the vectors I'm interested in:
> >>>
> >>>  z<-list(c("a","b","c"))
> >>>
> >>> Well, this successfully generates the kind of boxplot I want:
> >>>
> >>> boxplot(a,b,c)
> >>>
> >>> But this does not:
> >>>
> >>> boxplot(z)
> >>>
> >>> Because I'm trying to write an automatic plot-generator as the 
> >>> amount
> of
> >>> data I'm working with will typically vary, I need to write this to
> handle
> >>> any number of data vectors.
> >>>
> >>> I've tried every imaginable means of tweaking the name of "z", 
> >>> with
> zero
> >>> success. And I've scoured the help pages for about 45 minutes 
> >>> (just to preempt any "read the help" responses). Please help!
> >>>
> >>> Thanks,
> >>> Ryan
> >>>
> >>> --
> >>>
> >>> Ryan Utz, Ph.D.
> >>> Aquatic Ecologist/STREON Scientist National Ecological Observatory 
> >>> Network
> >>>
> >>> Home/Cell: (724) 272-7769
> >>> Work: (720) 836-2488
> >>>
> >>>[[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.
> >>>
> >>
> >>
> >>
> >> --
> >>
> >> Thomas E Adams
> >> National Weather Service
> >> Ohio River Forecast Center
> >> 1901 South State Route 134
> >> Wilmington, OH 45177
> >> EMAIL:  thomas.ad...@noaa.gov
> >> VOICE:  937-383-0528
> >> FAX:937-383-0033
> >>
> >>[[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.
> >
> >
> >
> > --
> >
> > 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
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info

[R] Forcing gwr to the origin

2011-12-12 Thread Barroso, Judit
I need to force the GWR(geographic weighted regression) to the origin(0,0).
Could you tell me what is the code?
I tried writing -1 as in the lm but it does not work.

Thanks in advance,
Judit

[[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] tcplot documentation in evd package

2011-12-12 Thread Mike Harwood
Hello, and please advise regarding any errors/omissions on my part.
However, the documentation for R's tcplot function in the evd package
appears to contain an error.  I am using evd version 2.2-4 in R 2.14.0
with Windows XP.

> data(portpirie)
> mrlplot(portpirie)  ## No Error

> tlim <- c(3.6, 4.2)

> tcplot(portpirie, tlim) ## Line from documentation
Error in fpot(data, u[1], model = model, cmax = cmax, r = r, ulow =
ulow,  :
  `x' must be a non-empty numeric vector


> tcplot(portpirie, tlim=c(3.6, 4.2)) ## explicitly specifying the threshold 
> limits
Error in fpot(data, u[1], model = model, cmax = cmax, r = r, ulow =
ulow,  :
  `x' must be a non-empty numeric vector

tcplot(portpirie$SeaLevel, tlim) ## Resolves Issue

gpd.fitrange(portpirie$SeaLevel, 3.6, 4.2) ## An alternative, still
naming the SeaLevel vector

Please advise.  Thanks!

Mike

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


Re: [R] Creating appropriate time axis for data

2011-12-12 Thread Tony Stocker
2011/12/12 Uwe Ligges :
> On 12.12.2011 17:44, Tony Stocker wrote:

Sorry for the double post but the first message was held for so long
that I figured there was a problem with the email address I was using
so I unsubscribed that one and resubscribed the other one.

>>
>> Hello,
>>
>> I am dealing with data stored in a database as a 'time' object.  I
>> export the data from the database to a text file and utilize the
>> 'time_to_sec()'
>
>
> I get
>
>> time_to_sec
> Error: object 'time_to_sec' not found
>
> If it is in a package, please tell us which one you are referring to.

The time_to_sec() function is inside the database (in this case
MySQL).  I'm using it solely because R doesn't want to deal with the
times as normally outputted (HH:MM:SS) because it sees them as a
character object and not a numerical or time object.  By converting
these time fields to seconds when I export them from the database I
provide something that R can work with natively apparently.
>
>
>> seconds.  However when I visualize the data in charts I do not want a
>> scale that runs from 25200-64800 seconds, but rather in the HH:MM:SS
>> format.  Is there a relatively straight-forward and easy to use way to
>> do this?
>
>
> Yes, e.g.:
>
> t <- strptime(c("07:00:00", "18:00:00"), "%H:%M:%S")
> y <- rnorm(2)
> plot(t, x)
>
Does this method supercede  the original y-axis label or supplement
it?  Will the data be correctly located along the y-axis if it's in
seconds?

I thought I had looked at strptime() and it required day/date info to
be listed not just time.  Based on your example I'm assuming that I
was incorrect in that assumption.

Thanks for this suggestion I'll give it a try with my data and see if
it does what I'd like it to do.  I appreciate the help.

> Uwe Ligges

-Tony

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


Re: [R] Boxplot of multiple vectors with different lengths

2011-12-12 Thread Trevor Carey-Smith

On 12/13/2011 12:14 PM, Ryan Utz wrote:

My vectors names are neatly stored in a character vector of their own. This
happens based on how they were imported. So, say I have vectors a, b and c,
all with numeric-only contents. Then I have another vector, say z, that
looks like this:

z<-c("a","b","c")

Is there really no way to tell boxplot to plot the contents of a, b and c
while only referencing z?!


here is one solution if I understand your requirement:

aa <- rnorm(20)
bb <- runif(30)
cc <- rexp(40)
z <- c("aa","bb","cc")
l <- lapply(z,get)
boxplot(l)

Although as Sarah said, this will fail if you use 'c' as a variable name
as the list would then contain the function c() rather than the variable
you previously defined.

Regards,
Trevor


Why is this so difficult?? Again, this is part
of an automated process, so the number of incoming data sets, etc. will
vary, which is why I'm seeking a solution this way.



On Mon, Dec 12, 2011 at 4:09 PM, Vining, Kelly
wrote:



Ryan,
Do you necessarily have to use "list"? Have you tried the usecols=TRUE
option in boxplot?

Cheers,
--Kelly V.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Ryan Utz
Sent: Monday, December 12, 2011 1:24 PM
To: r-help@r-project.org
Subject: [R] Boxplot of multiple vectors with different lengths

Hello,

I'm attempting to write a code that automatically imports data from
different files (with different lengths-just one variable) and makes tidy
box plots for comparison. I can successfully import the data and create a
list of the vectors I want to compare. But I cannot, for the life of me,
figure out how to generate box plots using the "list" option. Suppose these
are my data:

a<-c(1,1,1,1,2,3,2,1,2,3)
b<-c(2,2,2,3,4,4,4,3,3)
c<-c(4,3,3,2,3,4,5,3,3,3,4,4,5,6,3,2)

And this is my list of the vectors I'm interested in:

  z<-list(c("a","b","c"))

Well, this successfully generates the kind of boxplot I want:

boxplot(a,b,c)

But this does not:

boxplot(z)

Because I'm trying to write an automatic plot-generator as the amount of
data I'm working with will typically vary, I need to write this to handle
any number of data vectors.

I've tried every imaginable means of tweaking the name of "z", with zero
success. And I've scoured the help pages for about 45 minutes (just to
preempt any "read the help" responses). Please help!

Thanks,
Ryan

--

Ryan Utz, Ph.D.
Aquatic Ecologist/STREON Scientist
National Ecological Observatory Network

Home/Cell: (724) 272-7769
Work: (720) 836-2488

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






--
Please consider the environment before printing this email.
NIWA is the trading name of the National Institute of Water & Atmospheric 
Research Ltd.

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

2011-12-12 Thread wwreith
General goal: Write R code to find the inverse matrix of an nxn positive
definite symmetric matrix. Use solve() to verify your code works.

Started with a 3x3 matrix example to build the code, but something dosen't
seem to be working. I just don't know where I am going wrong.

##Example matrix I found online
A<-c(4,1,-1,1,2,1,-1,1,2)
m<-matrix(A,nrow=3,ncol=3)

##Caculate the eigen vectors and eigenvalues
E<-eigen(m, sym=TRUE)
Q<-E$vectors
V<-E$values
n<-nrow(m)

##normalize the eigenvectors
for(i in 1:n){
  Q[,i]<-Q[,i]/sqrt(sum(Q[,i]^2))
}

##verify dot product of vectors are orthogonal
sum(Q[,1]*Q[,2])
sum(Q[,1]*Q[,3])
sum(Q[,2]*Q[,3])

##Begin creating QDQ^T matrix. Where Q are orthonormal eigenvectors, and D
is a diagonal matrix with 1/eigenvalues on the diagonal. and Q^T is the
transpose of Q. 

R<-t(Q)
D<-mat.or.vec(n,n)
for(i in 1:n) {
  D[i,i]<-1/V[i]
  }
P<-Q*D*R

## P should be the inverse of the matrix m. Check using 

solve(m)

## solve(m) does not equal P? Any ideas of what I am missing/not
understanding?

--
View this message in context: 
http://r.789695.n4.nabble.com/Inverse-matrix-using-eigendecomposition-tp4188673p4188673.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] sum with dates

2011-12-12 Thread R. Michael Weylandt
It depends how your dates are stored, but generally you can just add
365*15 to them. E.g.,

print(x <- Sys.Date())
print(x + 365*15)

So for you,

dataset$dates <- dataset$dates + 365*15

Michael

On Mon, Dec 12, 2011 at 9:39 PM, Ana  wrote:
> How do I sum 15 years to my dataset?
>
> original dataset
>         dates        val
> 1    2001-01-12    1.2
> 2    2001-02-12    1.2
> 3    2001-03-12    1.2
>
> result
>         dates        val
> 1 2016-01-12 1.2
> 2    2016-02-12 1.2
> 3    2016-03-12 1.2
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] sum with dates

2011-12-12 Thread Ana
How do I sum 15 years to my dataset?

original dataset
 datesval
12001-01-121.2
22001-02-121.2
32001-03-121.2

result
 datesval
12016-01-121.2
22016-02-121.2
32016-03-121.2

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


[R] Importing a complex XML file (SDMX format)

2011-12-12 Thread andrewH
Hi folks!

I am trying to read a large XML file from the Fed that contains quarterly
Flow of Funds data since the 1950s.  It contains lots of individual tables
in something called the "Statistical Data and Metadata eXchange format"
(SDMX format). 

I am not sure if I need something specific to the SDMX format to read the
file, or just to use the XML  package correctly. The XML package includes
over 70 documented functions and frankly I have not been able to figure
where to start. This is the first time I have ever needed to open up an XML
file of any kind, so I am starting from scratch.

I would be very grateful for advice on either reading an arbitrary but
complex XML file or from anyone who has succeeded in opening an XML file in
SDMX format. 

Warmest regards, andrewH



--
View this message in context: 
http://r.789695.n4.nabble.com/Importing-a-complex-XML-file-SDMX-format-tp4188411p4188411.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] Plotting a date variable after GAM

2011-12-12 Thread Shige Song
Dear All,

I am fitting a simple GAM model using the "gam" function in the "mgcv"
package. The only independent variable is a continuous variable
representing the time of the event (in year and month) coded so that
"0" represents January 1960, "1" represents February 1960, etc. Now
when I try to plot the results, my x-axis ranges from "-200" to "200",
what I want is to convert these number into something like "1950-01"
or "Jan. 1950". What is the best way to do this?

Many thanks.

Best,
Shige

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


Re: [R] Polygon

2011-12-12 Thread Carl Witthoft
Please read the posting guide and provide a (small) reproducible example 
of your data.


The statement "...output does not seem good."  is not very useful. 
Please explain what you would like the polygon area to look like, and 
why you don't like the way it came out.  Links to posted images of the 
chart would help too.




From: Komine 
Date: Mon, 12 Dec 2011 06:58:56 -0800 (PST)

Hi everybody,
I have a matrix with 3 columns (Date, MeanArea and SdArea). I want to 
draw a figure showing the variable MeanArea in terms of the Date. But 
instead to use the variable SdArea as bar error, I want to use “polygon 
error”. I use this code but the output does not seem good. 
PolyPoly


y <-MeanArea
x <-SdArea
z <-Date

matplot(x,cbind(y,z),type="n")
polygon(c(x,rev(x)),c(y,rev(z)),col="grey50")
Thank you in advance
--

Sent from my Cray XK6
"Pendeo-navem mei anguillae plena est."

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


Re: [R] Boxplot of multiple vectors with different lengths

2011-12-12 Thread William Dunlap
If you have already made numeric vectors called "a", "b", and "c"
   a <- 1:10
   b <- sqrt(1:200)
   c <- log2(1:500)
and a character vector "z" containing their names
   z <- c("a", "b", "c")
then make a list containing the data with them with
   dataList <- lapply(z, get, envir=environment())
   names(dataList) <- z
and make your boxplots with
   boxplot(dataList)

Then forget about using the variables "a", "b", and "c"
and use dataList[["a"]], dataList[["b"]], etc. instead.
You may want to use a shorter name than dataList. 

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of Ryan Utz
> Sent: Monday, December 12, 2011 3:15 PM
> To: r-help@r-project.org
> Subject: Re: [R] Boxplot of multiple vectors with different lengths
> 
> Thanks for the help, everyone. However, no solution yet...
> 
> My vectors names are neatly stored in a character vector of their own. This
> happens based on how they were imported. So, say I have vectors a, b and c,
> all with numeric-only contents. Then I have another vector, say z, that
> looks like this:
> 
> z<-c("a","b","c")
> 
> Is there really no way to tell boxplot to plot the contents of a, b and c
> while only referencing z?! Why is this so difficult?? Again, this is part
> of an automated process, so the number of incoming data sets, etc. will
> vary, which is why I'm seeking a solution this way.
> 
> 
> 
> On Mon, Dec 12, 2011 at 4:09 PM, Vining, Kelly  > wrote:
> 
> > Ryan,
> > Do you necessarily have to use "list"? Have you tried the usecols=TRUE
> > option in boxplot?
> >
> > Cheers,
> > --Kelly V.
> >
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> > On Behalf Of Ryan Utz
> > Sent: Monday, December 12, 2011 1:24 PM
> > To: r-help@r-project.org
> > Subject: [R] Boxplot of multiple vectors with different lengths
> >
> > Hello,
> >
> > I'm attempting to write a code that automatically imports data from
> > different files (with different lengths-just one variable) and makes tidy
> > box plots for comparison. I can successfully import the data and create a
> > list of the vectors I want to compare. But I cannot, for the life of me,
> > figure out how to generate box plots using the "list" option. Suppose these
> > are my data:
> >
> > a<-c(1,1,1,1,2,3,2,1,2,3)
> > b<-c(2,2,2,3,4,4,4,3,3)
> > c<-c(4,3,3,2,3,4,5,3,3,3,4,4,5,6,3,2)
> >
> > And this is my list of the vectors I'm interested in:
> >
> >  z<-list(c("a","b","c"))
> >
> > Well, this successfully generates the kind of boxplot I want:
> >
> > boxplot(a,b,c)
> >
> > But this does not:
> >
> > boxplot(z)
> >
> > Because I'm trying to write an automatic plot-generator as the amount of
> > data I'm working with will typically vary, I need to write this to handle
> > any number of data vectors.
> >
> > I've tried every imaginable means of tweaking the name of "z", with zero
> > success. And I've scoured the help pages for about 45 minutes (just to
> > preempt any "read the help" responses). Please help!
> >
> > Thanks,
> > Ryan
> >
> > --
> >
> > Ryan Utz, Ph.D.
> > Aquatic Ecologist/STREON Scientist
> > National Ecological Observatory Network
> >
> > Home/Cell: (724) 272-7769
> > Work: (720) 836-2488
> >
> > [[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.
> >
> 
> 
> 
> --
> 
> Ryan Utz, Ph.D.
> Aquatic Ecologist/STREON Scientist
> National Ecological Observatory Network
> 
> Home/Cell: (724) 272-7769
> Work: (720) 836-2488
> 
>   [[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] axis tick colors: only one value allowed?

2011-12-12 Thread Carl Witthoft

Hi,
So far as I can tell, the 'col.ticks' parameter for axis() only uses the 
first value provided.  E.g.:


 plot(0:1,0:1, col.ticks=c('blue','red','green'))  #all ticks are blue

Just wondering if there's a different option in the basic plot commands 
that can handle multiple colors, and also whether ggplot and/or lattice 
allow for multiple tick colors.


Background: I ran into this limit while trying to colorize the ticks as 
plotted by rug() .   There's an easy workaround, as the output of rug() 
can be duplicated with something along the lines of


> points(mydata, rep(0.5, length(mydata)), 
col=rainbow(20)[mydata*20/max(mydata)] )


So I can create color rugplots, but do wonder about enhancements to the 
plot routines (albeit pretty silly enhancements).


As another side note: calling rug() with color set to '#0033'  lets 
you see dense regions as darker than sparse regions, without having to 
resort to calling  jitter() first.



Carl


--

Sent from my Cray XK6
"Pendeo-navem mei anguillae plena est."

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


Re: [R] Overlaying density plot on forest plot

2011-12-12 Thread Viechtbauer Wolfgang (STAT)
Here is an example. It requires a bit of extra work, but that's the beauty of R 
-- you can essentially customize a graph to your taste with low-level 
functions. I also added the prediction interval using the addcred argument (as 
suggested by Michael), since it gives the same information as that fancy normal 
distribution at the bottom. Essentially, that distribution is just 
window-dressing. I am not sure if I would go as far as calling that 
"chart-junk", but it's certainly somewhat gratuitous. Well, I hope the code 
below gives you enough of an idea so that you can adjust this to your specific 
case.


library(metafor)

### load BCG vaccine data
data(dat.bcg)

### meta-analysis of the log relative risks using a random-effects model
res <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, measure="RR", 
   slab=paste(author, year, sep=", "), method="REML")

### forest plot with extra annotations
forest(res, slab=paste(dat.bcg$author, dat.bcg$year, sep=", "), 
   xlim=c(-16, 6), at=log(c(.05, .25, 1, 4)), atransf=exp,
   ilab=cbind(dat.bcg$tpos, dat.bcg$tneg, dat.bcg$cpos, dat.bcg$cneg), 
   ilab.xpos=c(-9.5,-8,-6,-4.5), cex=.7, ylim=c(-3,16), addcred=TRUE)
text(c(-9.5,-8,-6,-4.5), 15, c("TB+", "TB-", "TB+", "TB-"), font=2, cex=.70)
text(c(-8.75,-5.25), 16, c("Vaccinated", "Control"), font=2, cex=.70)
text(-16,15, "Author(s) and Year", pos=4, font=2, cex=.70)
text(6,  15, "Relative Risk [95% CI]", pos=2, font=2, cex=.70)
text(-16,  -2.5, "Prediction Distribution", pos=4, cex=.70)

### add prediction distribution
res <- predict(res)
pred.m <- res$pred
pred.s <- (res$cr.ub - res$cr.lb) / (2*1.96)
xs <- seq(-2.5,1,.01)
cords.xs <- c(-2,xs,-2)
cords.ys <- c(0, 1.5*dnorm(xs, pred.m, sd=pred.s), 0) - 3
polygon(cords.xs, cords.ys, col="darkgray", border=NA)
ptext <- paste(round(exp(res$pred),2), " [ ", round(exp(res$cr.lb),2), " , ", 
round(exp(res$cr.ub),2), "]", sep="")
text(6, -2.5, ptext, pos=2, cex=.70)

--   
Wolfgang Viechtbauer, Ph.D., Statistician   
Department of Psychiatry and Psychology   
School for Mental Health and Neuroscience   
Faculty of Health, Medicine, and Life Sciences   
Maastricht University, P.O. Box 616 (VIJV1)   
6200 MD Maastricht, The Netherlands   
+31 (43) 368-5248 | http://www.wvbauer.com   

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Michael Dewey
> Sent: Monday, December 12, 2011 18:50
> To: Frank Peter; r-help@r-project.org
> Subject: Re: [R] Overlaying density plot on forest plot
> 
> At 15:09 11/12/2011, you wrote:
> >Dear Michael,
> >
> >Thanks for the email. This is the kind of forest plot, I want to
> >replicate
> >
> >http://www.biomedcentral.com/1471-2334/11/122/figure/F2
> 
> It would be helpful to cc to r-help in case someone else there knows
> better.
> 
> If you follow my suggestion you get a similar plot to sub-plot A in your
> example but the credible interval is shown as a dashed line superimposed
> on the summary diamond and not as a normal density as shown in sub-plot A.
> Whether that is what you want is up to you I think.
> 
> >Regards
> >Frank Peter
> >
> > Original Message 
> >From: Michael Dewey 
> >To: "Frank Peter" , r-help@r-project.org
> >Subject: Re: [R] Overlaying density plot on forest plot
> >Date: Sun, 11 Dec 2011 14:20:13 +
> >
> > > At 07:16 10/12/2011, Frank Peter wrote:
> > > >Dear R User,
> > > >
> > > >Please, I am new to R. I want to overlay density plot for
> > > >predictive interval pooled result in meta-analysis.
> > > >http://addictedtor.free.fr/graphiques/graphcode.php?graph=114
> > >
> > > It is hard to be sure from your rather brief question but does the
> > > addcred parameter to forest.rma in package metafor do what you want?
> > >
> > > >
> > > >
> > > >Regards
> > > >Frank Peter
> > >
> > > Michael Dewey
> > > i...@aghmed.fsnet.co.uk
> > > http://www.aghmed.fsnet.co.uk/home.html

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


[R] rodbc -- save result to a table

2011-12-12 Thread Hui Du
Hi All,

I am pretty new for RODBC. I want to save my table to a DB, so I 
used something like

sqlSave(db, a, 'Forecast_Result', rownames = FALSE);

But I got an error
Error in sqlSave(db, a, "Forecast_Result", rownames = FALSE) :
  table 'Forecast_Result' already exists

Yes, that table has been created before. But I need to overwrite the content in 
that table now. Obviously, I should use sqlUpdate. But sqlUpdate is to update 
existing table. So it seems to me I should use sqlSave first time when the 
table is not there and then use sqlUpdate for further update. How to test if 
the table is already there or not?  Or, if there is a simpler logic to solve my 
problem, please advise me.

Many thanks.

HXD

[[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] Maximum discrepancy palette

2011-12-12 Thread Michael Sumner
Try the RColorBrewer package, with function ?brewer.pal

You probably want a Qualitative palette, the details are in that
function's help page.

Cheers, Mike.

On Tue, Dec 13, 2011 at 10:14 AM, Etienne B. Racine  wrote:
> I'm looking for a palette that would maximize the discrepancy with
> neighbouring elements.
>
> I have a raster image of objects tagged with integers. I'd like to
> highlight the different objects by using a palette that would maximize this
> difference with neighbours as close numbers tend to be neighbours. Of,
> course, I don't expect this to be color-blind safe are even beautiful, but,
> I'd like to have a good chance of separating neighbours.
>
> It looks a bit like :
>
> x <- structure(c(1, 1, 2, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 3,
> 2, 1, 1, 1, NA, NA, 3, 1, 4, 4, 3, 3, 3, 4, 4, 3, 3, 3, 3), .Dim = c(6L,
> 6L))
> image(x)
> # i've tried things like
> image(x, col = sample(rainbow(5)))
>
> But with number of objects increasing (~80), I tend to have same colours
> (or very close ones) as neighbours.
>
> Does that palette exist ?
>
> Thanks,
> Etienne
>
>        [[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.



-- 
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: mdsum...@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] Boxplot of multiple vectors with different lengths

2011-12-12 Thread Bert Gunter
Thomas:

I stand corrected. Thank you.

-- Bert

On Mon, Dec 12, 2011 at 2:21 PM, Thomas Adams  wrote:
> Bert,
>
> I may be mistaken, but I thought Ryan wrote "write code that automatically
> imports data from different files (with different lengths-just one
> variable)", so, I was referring to doing something with the data before it
> gets into R. I understand that one should not need to write out data and
> then re-read it in some way. As I said, those more experienced with R will
> probably offer better ideas.
>
> Tom
>
> On Mon, Dec 12, 2011 at 5:05 PM, Bert Gunter  wrote:
>>
>> Sorry -- previous versiuon prematurely sent. Full version is:
>>
>>  Yikes!  You should never have to do this sort of thing (writing stuff
>>  out to files, etc.)
>>
>>  What is wanted, I believe, is ?do.call as in
>>
>>  do.call(boxplot, z)
>>
>>  where z is list(a,b,c)   as Sarah described.
>>
>>  However, I think you might do even better in terms of controlling
>>  options, labels, etc. if you would get the data into standard flat
>>  file format (data frame) as
>>
>> Result     Source
>>  1            a
>>  3           b
>> 2             b
>>  5         c
>> ... etc.
>>
>> (This is easy to do in R and via many packages.)
>> and then use he formula interface in the lattice ?bwplot  function for th
>> eplot.
>>
>> Cheers,
>> Bert
>>
>> >
>> > result
>> >
>> > On Mon, Dec 12, 2011 at 1:43 PM, Thomas Adams 
>> > wrote:
>> >> Ryan,
>> >>
>> >> I think you could do what you want by having the vector data written to
>> >> separate files; then create a file containing the individual file
>> >> names. In
>> >> R, read the file containing the list of file names and loop through
>> >> this
>> >> reading in the individual vector files. Maybe this is an inelegant,
>> >> brute
>> >> force approach, but it has worked for me with essentially the same
>> >> problem.
>> >>
>> >> Tom
>> >>
>> >> On Mon, Dec 12, 2011 at 4:24 PM, Ryan Utz  wrote:
>> >>
>> >>> Hello,
>> >>>
>> >>> I'm attempting to write a code that automatically imports data from
>> >>> different files (with different lengths-just one variable) and makes
>> >>> tidy
>> >>> box plots for comparison. I can successfully import the data and
>> >>> create a
>> >>> list of the vectors I want to compare. But I cannot, for the life of
>> >>> me,
>> >>> figure out how to generate box plots using the "list" option. Suppose
>> >>> these
>> >>> are my data:
>> >>>
>> >>> a<-c(1,1,1,1,2,3,2,1,2,3)
>> >>> b<-c(2,2,2,3,4,4,4,3,3)
>> >>> c<-c(4,3,3,2,3,4,5,3,3,3,4,4,5,6,3,2)
>> >>>
>> >>> And this is my list of the vectors I'm interested in:
>> >>>
>> >>>  z<-list(c("a","b","c"))
>> >>>
>> >>> Well, this successfully generates the kind of boxplot I want:
>> >>>
>> >>> boxplot(a,b,c)
>> >>>
>> >>> But this does not:
>> >>>
>> >>> boxplot(z)
>> >>>
>> >>> Because I'm trying to write an automatic plot-generator as the amount
>> >>> of
>> >>> data I'm working with will typically vary, I need to write this to
>> >>> handle
>> >>> any number of data vectors.
>> >>>
>> >>> I've tried every imaginable means of tweaking the name of "z", with
>> >>> zero
>> >>> success. And I've scoured the help pages for about 45 minutes (just to
>> >>> preempt any "read the help" responses). Please help!
>> >>>
>> >>> Thanks,
>> >>> Ryan
>> >>>
>> >>> --
>> >>>
>> >>> Ryan Utz, Ph.D.
>> >>> Aquatic Ecologist/STREON Scientist
>> >>> National Ecological Observatory Network
>> >>>
>> >>> Home/Cell: (724) 272-7769
>> >>> Work: (720) 836-2488
>> >>>
>> >>>        [[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.
>> >>>
>> >>
>> >>
>> >>
>> >> --
>> >>
>> >> Thomas E Adams
>> >> National Weather Service
>> >> Ohio River Forecast Center
>> >> 1901 South State Route 134
>> >> Wilmington, OH 45177
>> >> EMAIL:  thomas.ad...@noaa.gov
>> >> VOICE:  937-383-0528
>> >> FAX:    937-383-0033
>> >>
>> >>        [[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.
>> >
>> >
>> >
>> > --
>> >
>> > 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
>>
>>
>>
>> --
>>
>> Bert Gunter
>> Genentech Nonclinical Biostatistics
>>
>> Internal Contact Info:
>> Phone: 467-7374
>> Website:
>>
>> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/

Re: [R] Boxplot of multiple vectors with different lengths

2011-12-12 Thread Peter Ehlers

On 2011-12-12 15:14, Ryan Utz wrote:

Thanks for the help, everyone. However, no solution yet...

My vectors names are neatly stored in a character vector of their own. This
happens based on how they were imported. So, say I have vectors a, b and c,
all with numeric-only contents. Then I have another vector, say z, that
looks like this:

z<-c("a","b","c")

Is there really no way to tell boxplot to plot the contents of a, b and c
while only referencing z?! Why is this so difficult?? Again, this is part
of an automated process, so the number of incoming data sets, etc. will
vary, which is why I'm seeking a solution this way.



I thought that Bert had given you the answer; try this:

  aa <- runif(15)
  bb <- rnorm(30)
  cc <- rnorm(50,sd=2)
  z <- c(aa,bb,cc)
  g <- rep(LETTERS[1:3],c(length(aa),length(bb),length(cc)))
  boxplot(z ~ g)


Peter Ehlers




On Mon, Dec 12, 2011 at 4:09 PM, Vining, Kelly
wrote:



Ryan,
Do you necessarily have to use "list"? Have you tried the usecols=TRUE
option in boxplot?

Cheers,
--Kelly V.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Ryan Utz
Sent: Monday, December 12, 2011 1:24 PM
To: r-help@r-project.org
Subject: [R] Boxplot of multiple vectors with different lengths

Hello,

I'm attempting to write a code that automatically imports data from
different files (with different lengths-just one variable) and makes tidy
box plots for comparison. I can successfully import the data and create a
list of the vectors I want to compare. But I cannot, for the life of me,
figure out how to generate box plots using the "list" option. Suppose these
are my data:

a<-c(1,1,1,1,2,3,2,1,2,3)
b<-c(2,2,2,3,4,4,4,3,3)
c<-c(4,3,3,2,3,4,5,3,3,3,4,4,5,6,3,2)

And this is my list of the vectors I'm interested in:

  z<-list(c("a","b","c"))

Well, this successfully generates the kind of boxplot I want:

boxplot(a,b,c)

But this does not:

boxplot(z)

Because I'm trying to write an automatic plot-generator as the amount of
data I'm working with will typically vary, I need to write this to handle
any number of data vectors.

I've tried every imaginable means of tweaking the name of "z", with zero
success. And I've scoured the help pages for about 45 minutes (just to
preempt any "read the help" responses). Please help!

Thanks,
Ryan

--

Ryan Utz, Ph.D.
Aquatic Ecologist/STREON Scientist
National Ecological Observatory Network

Home/Cell: (724) 272-7769
Work: (720) 836-2488

 [[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] Boxplot of multiple vectors with different lengths

2011-12-12 Thread Ryan Utz
Thanks for the help, everyone. However, no solution yet...

My vectors names are neatly stored in a character vector of their own. This
happens based on how they were imported. So, say I have vectors a, b and c,
all with numeric-only contents. Then I have another vector, say z, that
looks like this:

z<-c("a","b","c")

Is there really no way to tell boxplot to plot the contents of a, b and c
while only referencing z?! Why is this so difficult?? Again, this is part
of an automated process, so the number of incoming data sets, etc. will
vary, which is why I'm seeking a solution this way.



On Mon, Dec 12, 2011 at 4:09 PM, Vining, Kelly  wrote:

> Ryan,
> Do you necessarily have to use "list"? Have you tried the usecols=TRUE
> option in boxplot?
>
> Cheers,
> --Kelly V.
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Ryan Utz
> Sent: Monday, December 12, 2011 1:24 PM
> To: r-help@r-project.org
> Subject: [R] Boxplot of multiple vectors with different lengths
>
> Hello,
>
> I'm attempting to write a code that automatically imports data from
> different files (with different lengths-just one variable) and makes tidy
> box plots for comparison. I can successfully import the data and create a
> list of the vectors I want to compare. But I cannot, for the life of me,
> figure out how to generate box plots using the "list" option. Suppose these
> are my data:
>
> a<-c(1,1,1,1,2,3,2,1,2,3)
> b<-c(2,2,2,3,4,4,4,3,3)
> c<-c(4,3,3,2,3,4,5,3,3,3,4,4,5,6,3,2)
>
> And this is my list of the vectors I'm interested in:
>
>  z<-list(c("a","b","c"))
>
> Well, this successfully generates the kind of boxplot I want:
>
> boxplot(a,b,c)
>
> But this does not:
>
> boxplot(z)
>
> Because I'm trying to write an automatic plot-generator as the amount of
> data I'm working with will typically vary, I need to write this to handle
> any number of data vectors.
>
> I've tried every imaginable means of tweaking the name of "z", with zero
> success. And I've scoured the help pages for about 45 minutes (just to
> preempt any "read the help" responses). Please help!
>
> Thanks,
> Ryan
>
> --
>
> Ryan Utz, Ph.D.
> Aquatic Ecologist/STREON Scientist
> National Ecological Observatory Network
>
> Home/Cell: (724) 272-7769
> Work: (720) 836-2488
>
> [[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.
>



-- 

Ryan Utz, Ph.D.
Aquatic Ecologist/STREON Scientist
National Ecological Observatory Network

Home/Cell: (724) 272-7769
Work: (720) 836-2488

[[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] Maximum discrepancy palette

2011-12-12 Thread Etienne B. Racine
I'm looking for a palette that would maximize the discrepancy with
neighbouring elements.

I have a raster image of objects tagged with integers. I'd like to
highlight the different objects by using a palette that would maximize this
difference with neighbours as close numbers tend to be neighbours. Of,
course, I don't expect this to be color-blind safe are even beautiful, but,
I'd like to have a good chance of separating neighbours.

It looks a bit like :

x <- structure(c(1, 1, 2, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 3,
2, 1, 1, 1, NA, NA, 3, 1, 4, 4, 3, 3, 3, 4, 4, 3, 3, 3, 3), .Dim = c(6L,
6L))
image(x)
# i've tried things like
image(x, col = sample(rainbow(5)))

But with number of objects increasing (~80), I tend to have same colours
(or very close ones) as neighbours.

Does that palette exist ?

Thanks,
Etienne

[[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] Boxplot of multiple vectors with different lengths

2011-12-12 Thread Vining, Kelly
Ryan,
Do you necessarily have to use "list"? Have you tried the usecols=TRUE option 
in boxplot?

Cheers,
--Kelly V.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Ryan Utz
Sent: Monday, December 12, 2011 1:24 PM
To: r-help@r-project.org
Subject: [R] Boxplot of multiple vectors with different lengths

Hello,

I'm attempting to write a code that automatically imports data from different 
files (with different lengths-just one variable) and makes tidy box plots for 
comparison. I can successfully import the data and create a list of the vectors 
I want to compare. But I cannot, for the life of me, figure out how to generate 
box plots using the "list" option. Suppose these are my data:

a<-c(1,1,1,1,2,3,2,1,2,3)
b<-c(2,2,2,3,4,4,4,3,3)
c<-c(4,3,3,2,3,4,5,3,3,3,4,4,5,6,3,2)

And this is my list of the vectors I'm interested in:

 z<-list(c("a","b","c"))

Well, this successfully generates the kind of boxplot I want:

boxplot(a,b,c)

But this does not:

boxplot(z)

Because I'm trying to write an automatic plot-generator as the amount of data 
I'm working with will typically vary, I need to write this to handle any number 
of data vectors.

I've tried every imaginable means of tweaking the name of "z", with zero 
success. And I've scoured the help pages for about 45 minutes (just to preempt 
any "read the help" responses). Please help!

Thanks,
Ryan

-- 

Ryan Utz, Ph.D.
Aquatic Ecologist/STREON Scientist
National Ecological Observatory Network

Home/Cell: (724) 272-7769
Work: (720) 836-2488

[[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] question about fixed and random factors in aov

2011-12-12 Thread Szymek Drobniak
Dear R users,

I know that it was considered many times but having searched through dozens
of posts I have only added to my confusion. My question is - is it possible
to correctly analyse simple mixed (fully)crossed (factorial) 2-way ANOVA?

Assume we have factor A (fixed) and B (random). In the model with an
interaction A should be tested against interaction, B and A:B against
residual variance. Specifying aov(response~A*B) gives wrong answer (wrong F
ratios, especially for fixed term as it's tested using residuals).
Specyfying aov(response~A*B+Error(A:B) specifies correct error term for
fixed effect, but wrong for random effect. And now I'm a bit confused - is
it possible to analyse such data using aov (or any alternative to aov) - or
it's better to switch to lme or lmer (which are better for mixed models but
are at first difficult to understand for students, especially in terms of
random interactions)?

Sorry for posting the same/similar question again - maybe at least it would
clarify the problem for future visitors.

Cheers,
sz.

-- 
Szymon Drobniak || Population Ecology Group
Institute of Environmental Sciences, Jagiellonian University
ul. Gronostajowa 7, 30-387 Kraków, POLAND
tel.: +48 12 664 51 79 fax: +48 12 664 69 12

www.eko.uj.edu.pl/drobniak

[[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] Boxplot of multiple vectors with different lengths

2011-12-12 Thread Thomas Adams
Bert,

I may be mistaken, but I thought Ryan wrote "write code that
automatically *imports
data* from different files (with different lengths-just one variable)", so,
I was referring to doing something with the data before it gets into R. I
understand that one should not need to write out data and then re-read it
in some way. As I said, those more experienced with R will probably offer
better ideas.

Tom

On Mon, Dec 12, 2011 at 5:05 PM, Bert Gunter  wrote:

> Sorry -- previous versiuon prematurely sent. Full version is:
>
>  Yikes!  You should never have to do this sort of thing (writing stuff
>  out to files, etc.)
>
>  What is wanted, I believe, is ?do.call as in
>
>  do.call(boxplot, z)
>
>  where z is list(a,b,c)   as Sarah described.
>
>  However, I think you might do even better in terms of controlling
>  options, labels, etc. if you would get the data into standard flat
>  file format (data frame) as
>
> Result Source
>  1a
>  3   b
> 2 b
>  5 c
> ... etc.
>
> (This is easy to do in R and via many packages.)
> and then use he formula interface in the lattice ?bwplot  function for th
> eplot.
>
> Cheers,
> Bert
>
> >
> > result
> >
> > On Mon, Dec 12, 2011 at 1:43 PM, Thomas Adams 
> wrote:
> >> Ryan,
> >>
> >> I think you could do what you want by having the vector data written to
> >> separate files; then create a file containing the individual file
> names. In
> >> R, read the file containing the list of file names and loop through this
> >> reading in the individual vector files. Maybe this is an inelegant,
> brute
> >> force approach, but it has worked for me with essentially the same
> problem.
> >>
> >> Tom
> >>
> >> On Mon, Dec 12, 2011 at 4:24 PM, Ryan Utz  wrote:
> >>
> >>> Hello,
> >>>
> >>> I'm attempting to write a code that automatically imports data from
> >>> different files (with different lengths-just one variable) and makes
> tidy
> >>> box plots for comparison. I can successfully import the data and
> create a
> >>> list of the vectors I want to compare. But I cannot, for the life of
> me,
> >>> figure out how to generate box plots using the "list" option. Suppose
> these
> >>> are my data:
> >>>
> >>> a<-c(1,1,1,1,2,3,2,1,2,3)
> >>> b<-c(2,2,2,3,4,4,4,3,3)
> >>> c<-c(4,3,3,2,3,4,5,3,3,3,4,4,5,6,3,2)
> >>>
> >>> And this is my list of the vectors I'm interested in:
> >>>
> >>>  z<-list(c("a","b","c"))
> >>>
> >>> Well, this successfully generates the kind of boxplot I want:
> >>>
> >>> boxplot(a,b,c)
> >>>
> >>> But this does not:
> >>>
> >>> boxplot(z)
> >>>
> >>> Because I'm trying to write an automatic plot-generator as the amount
> of
> >>> data I'm working with will typically vary, I need to write this to
> handle
> >>> any number of data vectors.
> >>>
> >>> I've tried every imaginable means of tweaking the name of "z", with
> zero
> >>> success. And I've scoured the help pages for about 45 minutes (just to
> >>> preempt any "read the help" responses). Please help!
> >>>
> >>> Thanks,
> >>> Ryan
> >>>
> >>> --
> >>>
> >>> Ryan Utz, Ph.D.
> >>> Aquatic Ecologist/STREON Scientist
> >>> National Ecological Observatory Network
> >>>
> >>> Home/Cell: (724) 272-7769
> >>> Work: (720) 836-2488
> >>>
> >>>[[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.
> >>>
> >>
> >>
> >>
> >> --
> >>
> >> Thomas E Adams
> >> National Weather Service
> >> Ohio River Forecast Center
> >> 1901 South State Route 134
> >> Wilmington, OH 45177
> >> EMAIL:  thomas.ad...@noaa.gov
> >> VOICE:  937-383-0528
> >> FAX:937-383-0033
> >>
> >>[[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.
> >
> >
> >
> > --
> >
> > 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
>
>
>
> --
>
> 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
>



-- 

Thomas E Adams
National Weather Service
Ohio River Forecast Center
1901 South State Route 134
Wilmington, OH 45177
EMAIL:  thomas.ad...@noaa.gov
VOICE:  937-383-0528
FAX:937-383-0033

[[alternative HTML version deleted]]

__
R-help@r-project.org mai

Re: [R] Boxplot of multiple vectors with different lengths

2011-12-12 Thread Bert Gunter
Sorry -- previous versiuon prematurely sent. Full version is:

 Yikes!  You should never have to do this sort of thing (writing stuff
 out to files, etc.)

 What is wanted, I believe, is ?do.call as in

 do.call(boxplot, z)

 where z is list(a,b,c)   as Sarah described.

 However, I think you might do even better in terms of controlling
 options, labels, etc. if you would get the data into standard flat
 file format (data frame) as

Result Source
 1a
  3   b
2 b
  5 c
... etc.

(This is easy to do in R and via many packages.)
and then use he formula interface in the lattice ?bwplot  function for th eplot.

Cheers,
Bert

>
> result
>
> On Mon, Dec 12, 2011 at 1:43 PM, Thomas Adams  wrote:
>> Ryan,
>>
>> I think you could do what you want by having the vector data written to
>> separate files; then create a file containing the individual file names. In
>> R, read the file containing the list of file names and loop through this
>> reading in the individual vector files. Maybe this is an inelegant, brute
>> force approach, but it has worked for me with essentially the same problem.
>>
>> Tom
>>
>> On Mon, Dec 12, 2011 at 4:24 PM, Ryan Utz  wrote:
>>
>>> Hello,
>>>
>>> I'm attempting to write a code that automatically imports data from
>>> different files (with different lengths-just one variable) and makes tidy
>>> box plots for comparison. I can successfully import the data and create a
>>> list of the vectors I want to compare. But I cannot, for the life of me,
>>> figure out how to generate box plots using the "list" option. Suppose these
>>> are my data:
>>>
>>> a<-c(1,1,1,1,2,3,2,1,2,3)
>>> b<-c(2,2,2,3,4,4,4,3,3)
>>> c<-c(4,3,3,2,3,4,5,3,3,3,4,4,5,6,3,2)
>>>
>>> And this is my list of the vectors I'm interested in:
>>>
>>>  z<-list(c("a","b","c"))
>>>
>>> Well, this successfully generates the kind of boxplot I want:
>>>
>>> boxplot(a,b,c)
>>>
>>> But this does not:
>>>
>>> boxplot(z)
>>>
>>> Because I'm trying to write an automatic plot-generator as the amount of
>>> data I'm working with will typically vary, I need to write this to handle
>>> any number of data vectors.
>>>
>>> I've tried every imaginable means of tweaking the name of "z", with zero
>>> success. And I've scoured the help pages for about 45 minutes (just to
>>> preempt any "read the help" responses). Please help!
>>>
>>> Thanks,
>>> Ryan
>>>
>>> --
>>>
>>> Ryan Utz, Ph.D.
>>> Aquatic Ecologist/STREON Scientist
>>> National Ecological Observatory Network
>>>
>>> Home/Cell: (724) 272-7769
>>> Work: (720) 836-2488
>>>
>>>        [[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.
>>>
>>
>>
>>
>> --
>>
>> Thomas E Adams
>> National Weather Service
>> Ohio River Forecast Center
>> 1901 South State Route 134
>> Wilmington, OH 45177
>> EMAIL:  thomas.ad...@noaa.gov
>> VOICE:  937-383-0528
>> FAX:    937-383-0033
>>
>>        [[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.
>
>
>
> --
>
> 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



-- 

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

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


Re: [R] not complete character in csv file

2011-12-12 Thread Rolf Turner

On 13/12/11 04:39, threshold wrote:

Indeed in txt it looks fine. Anyway, I must stay without 0 because csv is THE
format.


It may well be the case that csv is THE format, but csv is not the problem.
Excel is the problem.

The solution is:  Don't use Excel!!!  (This is excellent advice in any  
case.)


cheers,

Rolf Turner

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


Re: [R] Boxplot of multiple vectors with different lengths

2011-12-12 Thread Thomas Adams
Ryan,

I think you could do what you want by having the vector data written to
separate files; then create a file containing the individual file names. In
R, read the file containing the list of file names and loop through this
reading in the individual vector files. Maybe this is an inelegant, brute
force approach, but it has worked for me with essentially the same problem.

Tom

On Mon, Dec 12, 2011 at 4:24 PM, Ryan Utz  wrote:

> Hello,
>
> I'm attempting to write a code that automatically imports data from
> different files (with different lengths-just one variable) and makes tidy
> box plots for comparison. I can successfully import the data and create a
> list of the vectors I want to compare. But I cannot, for the life of me,
> figure out how to generate box plots using the "list" option. Suppose these
> are my data:
>
> a<-c(1,1,1,1,2,3,2,1,2,3)
> b<-c(2,2,2,3,4,4,4,3,3)
> c<-c(4,3,3,2,3,4,5,3,3,3,4,4,5,6,3,2)
>
> And this is my list of the vectors I'm interested in:
>
>  z<-list(c("a","b","c"))
>
> Well, this successfully generates the kind of boxplot I want:
>
> boxplot(a,b,c)
>
> But this does not:
>
> boxplot(z)
>
> Because I'm trying to write an automatic plot-generator as the amount of
> data I'm working with will typically vary, I need to write this to handle
> any number of data vectors.
>
> I've tried every imaginable means of tweaking the name of "z", with zero
> success. And I've scoured the help pages for about 45 minutes (just to
> preempt any "read the help" responses). Please help!
>
> Thanks,
> Ryan
>
> --
>
> Ryan Utz, Ph.D.
> Aquatic Ecologist/STREON Scientist
> National Ecological Observatory Network
>
> Home/Cell: (724) 272-7769
> Work: (720) 836-2488
>
>[[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.
>



-- 

Thomas E Adams
National Weather Service
Ohio River Forecast Center
1901 South State Route 134
Wilmington, OH 45177
EMAIL:  thomas.ad...@noaa.gov
VOICE:  937-383-0528
FAX:937-383-0033

[[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] Boxplot of multiple vectors with different lengths

2011-12-12 Thread Sarah Goslee
Hi,

On Mon, Dec 12, 2011 at 4:24 PM, Ryan Utz  wrote:
> Hello,
>
> I'm attempting to write a code that automatically imports data from
> different files (with different lengths-just one variable) and makes tidy
> box plots for comparison. I can successfully import the data and create a
> list of the vectors I want to compare. But I cannot, for the life of me,
> figure out how to generate box plots using the "list" option. Suppose these
> are my data:
>
> a<-c(1,1,1,1,2,3,2,1,2,3)
> b<-c(2,2,2,3,4,4,4,3,3)
> c<-c(4,3,3,2,3,4,5,3,3,3,4,4,5,6,3,2)
>
> And this is my list of the vectors I'm interested in:
>
>  z<-list(c("a","b","c"))

Did you look at z? You've made a list with a single element containing
three characters:

> z
[[1]]
[1] "a" "b" "c"

You need instead:
z <- list(a, b, c)

Also, don't call a variable c - that's a built-in function and using
the name elsewhere can cause all kinds of problems (look at your own
code line, where you use c as a function and as a variable. although
that wasn't a problem here).

Sarah

> Well, this successfully generates the kind of boxplot I want:
>
> boxplot(a,b,c)
>
> But this does not:
>
> boxplot(z)
>
> Because I'm trying to write an automatic plot-generator as the amount of
> data I'm working with will typically vary, I need to write this to handle
> any number of data vectors.
>
> I've tried every imaginable means of tweaking the name of "z", with zero
> success. And I've scoured the help pages for about 45 minutes (just to
> preempt any "read the help" responses). Please help!
>
> Thanks,
> Ryan
>


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Formatting probability data to produce confusion matrix for binary data for logistric regression

2011-12-12 Thread Sally Ann Sims
Hello R folks,

I’m looking to produce a confusion matrix using the command:  
cmx(PData,threshold=0.49,na.rm=FALSE) for a logistic regression model (1 is 
habitat, 0 is nonhabitat).

To compile my PData data file (csv file) (as in the example above), I’m using 
the output of the predict(glm) function.  Is there a way to export the output 
of the predict function (which formats itself as shown below)  so that I can 
export it into Excel as two columns (i.e., sample ID and probability?).  At 
present, when I try copy and paste, it ends up in one cell and is not easily 
manipulated.

R output format example:

  1 2 3 4 5 
6 7 8 91011 
   12   
0.526278645   0.989458044   0.834739251  -1.207218093   0.957373344   
0.988643146  -0.356652329   0.889463121   0.858587923   0.270430050   
1.000781325   0.999526931   
 1314151617 
   181920212223 
   24   
0.991809010   0.751469061  -0.740746896   0.249451379   0.992102707   
0.528213419   0.336177573  -0.944476861   1.000292603   0.273345885   
0.994184267  -1.419114223   



Or is there another function for entering probabilities into my data file to 
calculate a confusion matrix?

Thank you,
Sally
[[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] Boxplot of multiple vectors with different lengths

2011-12-12 Thread Ryan Utz
Hello,

I'm attempting to write a code that automatically imports data from
different files (with different lengths-just one variable) and makes tidy
box plots for comparison. I can successfully import the data and create a
list of the vectors I want to compare. But I cannot, for the life of me,
figure out how to generate box plots using the "list" option. Suppose these
are my data:

a<-c(1,1,1,1,2,3,2,1,2,3)
b<-c(2,2,2,3,4,4,4,3,3)
c<-c(4,3,3,2,3,4,5,3,3,3,4,4,5,6,3,2)

And this is my list of the vectors I'm interested in:

 z<-list(c("a","b","c"))

Well, this successfully generates the kind of boxplot I want:

boxplot(a,b,c)

But this does not:

boxplot(z)

Because I'm trying to write an automatic plot-generator as the amount of
data I'm working with will typically vary, I need to write this to handle
any number of data vectors.

I've tried every imaginable means of tweaking the name of "z", with zero
success. And I've scoured the help pages for about 45 minutes (just to
preempt any "read the help" responses). Please help!

Thanks,
Ryan

-- 

Ryan Utz, Ph.D.
Aquatic Ecologist/STREON Scientist
National Ecological Observatory Network

Home/Cell: (724) 272-7769
Work: (720) 836-2488

[[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] windrose color ramp issue

2011-12-12 Thread Adrienne Wootten
Greetings!

I'm having an issue with the windrose produced by the windrose
function from the circular package.  For our weather stations in North
Carolina I'm helping with a script which takes hourly wind speed and
direction data to create windroses for our end users.  One of the
stations in the mountains frequently reaches wind speed of 40 to 60
mph and in storms can reach wind speed over 80 mph.  This has brought
up an issue with the color ramp.

Currently the color ramp works one of two ways:

#1) Holding the pedal colors fixed:

incrspeeds = 2 # fills out the increments argument
pedalcolors =  
c("darkblue","blue","royalblue","darkturquoise","forestgreen","green","yellowgreen","yellow4","yellow","orange","red","darkred","violetred","mediumorchid","purple")

#or 2) Making the pedal colors dynamic based on the increments and the
max wind speed.

incrspeeds = 2 # fills out the increments argument

breaks=seq(0,round(maxwind),incrspeeds) # maxwind is the maximum wind speed
numcolors=length(breaks)

if(numcolors>length(pedalcolors)){
pedalcolors=rev(rainbow(numcolors))
}

# In either case the result ends up in the wind rose function

rose=windrose(wr,breaks=NULL,bins=numpedals,increment=incrspeeds,main=NULL,fill.col=pedalcolors,plot.mids=FALSE,units="degrees",template="geographics",ticks=FALSE,osize=0.05,cir.ind
=0.05,cex=0.9,zero=NULL,rotation=NULL,right=FALSE,shrink=NULL,label.freq=TRUE,calm=c("0"),number.calm=TRUE)

The issue when there are really large wind speeds in the first case,
the windrose wraps the color ramp twice in both the legend and the
windrose itself, and then gives only white for the remaining bands of
each pedal.  For the second case, when pedalcolors will have the same
number of colors as numcolors, the legend has the right color ramp,
but the pedals of the windrose don't have all the colors that are
passed to it.  Say pedalcolors has 40 colors, which are included in
the legend, but the windrose only includes the first 16 colors in
pedalcolors.

Any thoughts as to why this might be happening in either case?  Thanks!

Adrienne

-- 
Adrienne Wootten
Graduate Research Assistant
State Climate Office of North Carolina
Department of Marine, Earth and Atmospheric Sciences
North Carolina State University

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


Re: [R] calculating logit parameters (odd ratio is exactly one or zero)

2011-12-12 Thread David Winsemius


On Dec 12, 2011, at 3:51 PM, Uwe Ligges wrote:

1. The formula you used is not for a logistic but an ordinal  
regression (since you are using the default gaussian family rather  
than family="binomial" or whatever.


this this then produce one version of the "Armitage linear test of  
trend"?




2. R (nor any other software) can deal with perfect separation (nor  
quasi-separation) of classes, since the problem is not well defined  
in such a case as you found out already. R will give a warning in  
that case, that the Fisher Scoring does not converge.


LDA will give perfect results in such a case (well, unless the  
within class covariance matrix is singular).


Best,
Uwe Ligges



On 12.12.2011 11:46, wim nursal wrote:

Dear statistician experts,

Sorry if this is a trivial question, or the old same question (i  
don't know

what is the efficient key word for this issue).
In order to understand the calculation of parameter of logistic  
regression,
 I did an exercise through spreadsheet following the procedural  
example
from a literature, or the available spreadsheet (with calculation  
formula).
I ended up with infinity (divided by zero) when the odd ratio is  
exactly 1

(FD=12) or invalid number when odd ratio is zero (MFD = 0) after log.
I am wondering  how R through GLM function (particularly logit or  
logistic
regression) treats the odds ratios or log odd ratios that is  
exatcly one or

zeros.

The sample data is like this:
#HH Fsize FD
1 1.29472 0
2 1.6184 0
3 2.4276 1
4 2.4276 2
5 20.23 2
6 1.6184 3
7 1.820 3
8 0.4046 3
9 6.069 4
10 2.6299 4
11 0.72828 5
12 2.4276 5
13 6.069 7
14 4.8552 7
15 2.32645 7
16 1.6184 8
17 1.0115 8
18 1.0115 8
19 5.2598 9
20 2.023 10
21 0.6069 10
22 1.2138 11
23 0.8092 11
24 1.4161 11
25 0.6069 11
26 3.440 11
27 1.2138 12
28 1.2138 12
29 0.4046 12
30 1.2138 12

Fsize is the farm size (acre or hectare).  Food deficit (FD) is the  
number
of months (last year from the survey took place) that an household  
had
bought food-grains (minimum = 0 month, maximum = 12 months or whole  
year

deficit).
Even though I "jitter"-ed the minimum or maximum FD value only (eg.
FD=0+1e-6 or FD=12-1e-6), nothing changed to the result.

The formula I used is like this:
--
glm(FD ~ Fsize, data = subFS)
--
Coefficients:
(Intercept)Fsize
 7.7913  -0.3092

Degrees of Freedom: 29 Total (i.e. Null);  28 Residual
Null Deviance:  463
Residual Deviance: 425.5AIC: 170.7
--

I appreciate for any clarification.

Best wishes,
Wim




David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] categorical variables

2011-12-12 Thread David Winsemius


On Dec 12, 2011, at 3:38 PM, Uwe Ligges wrote:




On 12.12.2011 19:36, Brian Jensvold wrote:

I am doing a logistic regression, and by accident I included a field
which has the 2digit abbreviation for all 50 states labeled "st".   
I was
surprised to see that the glm did not come up with an error message  
but

instead appears to have automatically broken down this field into
individual fields (stAK and stAL).  Does R really know to turn all
categorical variables in binary dummy variables?


Yes.


I have tried answering
the question on my own and have found:



When including categorical variables in a regression, the default  
in R

is to

set the first level as the base.  Is there an option to specify a
different

level as the base?


Well, reorder to levels of the factor and use the most appropriate  
base level as the first one. This simplifies life since it is from  
now on the base level for all the models you try to fit.




My next/same question is what does it mean to "set the first level as
the base" does this mean it turns each value into a unique binary
result?


What is a "unique binary result"?

Actually, the base level is inlcuded in the intercept of your model  
and you see the differences for the other levels.


Just to expand a bit on Uwe's efforts, for which we are all in his  
debt. You might see that there is one missing state level, "AK'  
perhaps, that would generally be included in the reference level. I  
would have thought it to be AK but apparently you see that  
abbreviation. Factor variables get handled auto-magically by  
regression functions.


Uwe Ligges



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] calculating logit parameters (odd ratio is exactly one or zero)

2011-12-12 Thread Uwe Ligges
1. The formula you used is not for a logistic but an ordinal regression 
(since you are using the default gaussian family rather than 
family="binomial" or whatever.


2. R (nor any other software) can deal with perfect separation (nor 
quasi-separation) of classes, since the problem is not well defined in 
such a case as you found out already. R will give a warning in that 
case, that the Fisher Scoring does not converge.


LDA will give perfect results in such a case (well, unless the within 
class covariance matrix is singular).


Best,
Uwe Ligges



On 12.12.2011 11:46, wim nursal wrote:

Dear statistician experts,

Sorry if this is a trivial question, or the old same question (i don't know
what is the efficient key word for this issue).
In order to understand the calculation of parameter of logistic regression,
  I did an exercise through spreadsheet following the procedural example
from a literature, or the available spreadsheet (with calculation formula).
I ended up with infinity (divided by zero) when the odd ratio is exactly 1
(FD=12) or invalid number when odd ratio is zero (MFD = 0) after log.
I am wondering  how R through GLM function (particularly logit or logistic
regression) treats the odds ratios or log odd ratios that is exatcly one or
zeros.

The sample data is like this:
#HH Fsize FD
1 1.29472 0
2 1.6184 0
3 2.4276 1
4 2.4276 2
5 20.23 2
6 1.6184 3
7 1.820 3
8 0.4046 3
9 6.069 4
10 2.6299 4
11 0.72828 5
12 2.4276 5
13 6.069 7
14 4.8552 7
15 2.32645 7
16 1.6184 8
17 1.0115 8
18 1.0115 8
19 5.2598 9
20 2.023 10
21 0.6069 10
22 1.2138 11
23 0.8092 11
24 1.4161 11
25 0.6069 11
26 3.440 11
27 1.2138 12
28 1.2138 12
29 0.4046 12
30 1.2138 12

Fsize is the farm size (acre or hectare).  Food deficit (FD) is the number
of months (last year from the survey took place) that an household had
bought food-grains (minimum = 0 month, maximum = 12 months or whole year
deficit).
Even though I "jitter"-ed the minimum or maximum FD value only (eg.
FD=0+1e-6 or FD=12-1e-6), nothing changed to the result.

The formula I used is like this:
--
glm(FD ~ Fsize, data = subFS)
--
Coefficients:
(Intercept)Fsize
  7.7913  -0.3092

Degrees of Freedom: 29 Total (i.e. Null);  28 Residual
Null Deviance:  463
Residual Deviance: 425.5AIC: 170.7
--

I appreciate for any clarification.

Best wishes,
Wim

[[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] categorical variables

2011-12-12 Thread Uwe Ligges



On 12.12.2011 19:36, Brian Jensvold wrote:

I am doing a logistic regression, and by accident I included a field
which has the 2digit abbreviation for all 50 states labeled "st".  I was
surprised to see that the glm did not come up with an error message but
instead appears to have automatically broken down this field into
individual fields (stAK and stAL).  Does R really know to turn all
categorical variables in binary dummy variables?


Yes.


I have tried answering
the question on my own and have found:



When including categorical variables in a regression, the default in R
is to

set the first level as the base.  Is there an option to specify a
different

level as the base?


Well, reorder to levels of the factor and use the most appropriate base 
level as the first one. This simplifies life since it is from now on the 
base level for all the models you try to fit.




My next/same question is what does it mean to "set the first level as
the base" does this mean it turns each value into a unique binary
result?


What is a "unique binary result"?

Actually, the base level is inlcuded in the intercept of your model and 
you see the differences for the other levels.


Uwe Ligges






 CONFIDENTIALITY NOTICE


This message (including any attachments) is intended onl...{{dropped:21}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Creating appropriate time axis for data

2011-12-12 Thread Uwe Ligges



On 12.12.2011 17:44, Tony Stocker wrote:

Hello,

I am dealing with data stored in a database as a 'time' object.  I
export the data from the database to a text file and utilize the
'time_to_sec()'


I get

> time_to_sec
Error: object 'time_to_sec' not found

If it is in a package, please tell us which one you are referring to.


function of the database to convert the human readable
time (HH:MM:SS) to seconds so that I can use R to do analysis and
create charts of the data.  I do not need or use days or dates in the
data, and the data range is from 07:00:00 to 18:00:00 or 25200-64800
seconds.  However when I visualize the data in charts I do not want a
scale that runs from 25200-64800 seconds, but rather in the HH:MM:SS
format.  Is there a relatively straight-forward and easy to use way to
do this?


Yes, e.g.:

t <- strptime(c("07:00:00", "18:00:00"), "%H:%M:%S")
y <- rnorm(2)
plot(t, x)

Uwe Ligges





Thanks,
Tony

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 with charting time in seconds as HH:MM:SS on charts

2011-12-12 Thread Uwe Ligges

Please post only once!

Uwe Ligges


On 12.12.2011 20:32, Tony Stocker wrote:

Hello,

I am dealing with data stored in a database as a 'time' object.  I
export the data from the database to a text file and utilize the
'time_to_sec()' function of the database to convert the human readable
time (HH:MM:SS) to seconds so that I can use R to do analysis and
create charts of the data.  I do not need or use days or dates in the
data, and the data range is from 07:00:00 to 18:00:00 or 25200-64800
seconds.  However when I visualize the data in charts I do not want a
scale that runs from 25200-64800 seconds, but rather in the HH:MM:SS
format.  Is there a relatively straight-forward and easy to use way to
do this?

Thanks,
Tony

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

2011-12-12 Thread William Dunlap
I would recommend using data.frame(var1, var2, ...)
and not cbind.data.frame(var1, var2, ...).  I consider
it bad form to directly call a method of a generic function.
Sometimes it leads to errors, as a method should be
free to assume that its inputs are of the class it
was declared to accept.   In the particular case of
cbind.data.frame, I think it just calls data.frame.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of Sarah Goslee
> Sent: Monday, December 12, 2011 11:50 AM
> To: Jose Bustos Melo
> Cc: r-help@r-project.org
> Subject: Re: [R] Variables from a Dataframe
> 
> Without a reproducible example it's impossible to say for certain,
> but I'd try
> cbind.data.frame() instead of cbind().
> 
> You need to have a data frame, not a matrix, for the result.
> 
> Sarah
> 
> On Mon, Dec 12, 2011 at 2:44 PM, Jose Bustos Melo  
> wrote:
> > Hello everyone,
> >
> > I want make a variable selection  from a dataframe, but when I build this 
> > new object (using cbind)
> the new table (which is a matrix) I lost all the original factor names in the 
> variables. I get
> 1,2,3
> >
> > Someone would be so kind and tell me if there's is a ny way to get 
> > variables in a dataframe, but not
> changing these factor to numbers?
> >
> > Thank you all.
> > José
> 
> --
> Sarah Goslee
> http://www.functionaldiversity.org
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Variables from a Dataframe

2011-12-12 Thread Sarah Goslee
I'm glad that worked for you. It's a good idea to reply to the
list, as well as me, so that there's public acknowledgment of
a working solution, and so that the answer appears in the
archives.

Sarah

On Mon, Dec 12, 2011 at 2:56 PM, Jose Bustos Melo  wrote:
> Thank you Sarah!!... that works well, thank you a lot!!! Always I get so
> upset when I get stuck with some code.
>
> have a good day!
> José
>
> 
> De: Sarah Goslee 
> Para: Jose Bustos Melo 
> CC: "r-help@r-project.org" 
> Enviado: lunes 12 de diciembre de 2011 16:50
> Asunto: Re: [R] Variables from a Dataframe
>
> Without a reproducible example it's impossible to say for certain,
> but I'd try
> cbind.data.frame() instead of cbind().
>
> You need to have a data frame, not a matrix, for the result.
>
> Sarah
>
>
> On Mon, Dec 12, 2011 at 2:44 PM, Jose Bustos Melo 
> wrote:
>> Hello everyone,
>>
>> I want make a variable selection  from a dataframe, but when I build this
>> new object (using cbind) the new table (which is a matrix) I lost all the
>> original factor names in the variables. I get 1,2,3
>>
>> Someone would be so kind and tell me if there's is a ny way to get
>> variables in a dataframe, but not changing these factor to numbers?
>>
>> Thank you all.
>> José
>
> --

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


Re: [R] Orthoblique rotation on eigenvectors (SAS VARCLUS)

2011-12-12 Thread larrydag
I really like your varclus function Frank.  I have a question about the
quartimax rotation of the 1st two eigen vectors as the SAS VARCLUS algorithm
dictates.  According to the SAS user guide example of VARCLUS the only thing
needed to perform the cluster analysis is the variable correlation matrix. 
Is that the case?  The following is the SAS user guide example website.

http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_varclus_sect020.htm

Larry



--
View this message in context: 
http://r.789695.n4.nabble.com/Orthoblique-rotation-on-eigenvectors-SAS-VARCLUS-tp3438695p4187270.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 with charting time in seconds as HH:MM:SS on charts

2011-12-12 Thread Tony Stocker
Hello,

I am dealing with data stored in a database as a 'time' object.  I
export the data from the database to a text file and utilize the
'time_to_sec()' function of the database to convert the human readable
time (HH:MM:SS) to seconds so that I can use R to do analysis and
create charts of the data.  I do not need or use days or dates in the
data, and the data range is from 07:00:00 to 18:00:00 or 25200-64800
seconds.  However when I visualize the data in charts I do not want a
scale that runs from 25200-64800 seconds, but rather in the HH:MM:SS
format.  Is there a relatively straight-forward and easy to use way to
do this?

Thanks,
Tony

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


Re: [R] Variables from a Dataframe

2011-12-12 Thread Paul Menzel
Dear Jose,


Am Montag, den 12.12.2011, 19:44 + schrieb Jose Bustos Melo:
> Hello everyone,
> 
> I want make a variable selection from a dataframe, but when I build this new 
> object (using cbind) the new table (which is a matrix) I lost all the 
> original factor names in the variables. I get 1,2,3
> 
> Someone would be so kind and tell me if there's is a ny way to get variables 
> in a dataframe, but not changing these factor to numbers?

please provide a reproducible example as written in the posting guide.

[…]

>   [[alternative HTML version deleted]]

Read [1] to just send plain text messages.


Thanks,

Paul


[1] http://email.about.com/od/yahoomailtips/qt/et_plain_text.htm


signature.asc
Description: This is a digitally signed message part
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Variables from a Dataframe

2011-12-12 Thread Sarah Goslee
Without a reproducible example it's impossible to say for certain,
but I'd try
cbind.data.frame() instead of cbind().

You need to have a data frame, not a matrix, for the result.

Sarah

On Mon, Dec 12, 2011 at 2:44 PM, Jose Bustos Melo  wrote:
> Hello everyone,
>
> I want make a variable selection  from a dataframe, but when I build this new 
> object (using cbind) the new table (which is a matrix) I lost all the 
> original factor names in the variables. I get 1,2,3
>
> Someone would be so kind and tell me if there's is a ny way to get variables 
> in a dataframe, but not changing these factor to numbers?
>
> Thank you all.
> José

-- 
Sarah Goslee
http://www.functionaldiversity.org

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

2011-12-12 Thread Jose Bustos Melo
Hello everyone,

I want make a variable selection  from a dataframe, but when I build this new 
object (using cbind) the new table (which is a matrix) I lost all the original 
factor names in the variables. I get 1,2,3

Someone would be so kind and tell me if there's is a ny way to get variables in 
a dataframe, but not changing these factor to numbers?

Thank you all.
José
[[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] k-folds cross validation with conditional logistic

2011-12-12 Thread Terry Therneau
--begin inclusion --
I have a matched-case control dataset that I'm using conditional
logistic regression (clogit in survival) to analyze.  I'm trying to
conduct k-folds cross validation on my top models but all of the
packages I can find (CVbinary in DAAG, KVX) won't work with clogit
models.  Is there any easy way to do this in R?
-end inclusion --

 The clogit funciton is simply a wrapper for coxph.  
clogit(case ~ ...  
turns into
coxph(Surv(dummy, case) ~ ...
where "dummy" is a vector of ones.

Do the packages support coxph models?

Terry T

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


Re: [R] multiple comparison of interaction of ANCOVA

2011-12-12 Thread Richard M. Heiberger
...

On Mon, Dec 12, 2011 at 7:00 AM, Jinsong Zhao  wrote:

> Apart from the data set here, is there a way to do multiple comparison on
> the interaction of one way analysis of covariance?
>
Interaction in ancova usually means the slopes are different.

...

BTW, when loading HH package, the TukeyHSD() from stats package can not be
use. The following is the output:

> library(HH)
Warning messages:
1: package 'HH' was built under R version 2.13.2
2: package 'mvtnorm' was built under R version 2.13.2
3: package 'leaps' was built under R version 2.13.2
4: package 'RColorBrewer' was built under R version 2.13.2
5: package 'latticeExtra' was built under R version 2.13.2
> TukeyHSD(mydata.aov)
 height
All those warnings say your version of R is very out of date. R-2.14.0 is
current.
R-2.14.1 is scheduled to be released at the end of December.

...

After detach(package:HH), TukeyHSD(mydata.aov) can output the correct
results.

Thank you for alterting me to the conflict.
The problem arises because the returned object from TukeyHSD has class
[1] "multicomp" "TukeyHSD"
and the print.multicomp method in HH picks it up.  The stats package itself
has no "multicomp" methods.  The workaround to get the printed TukeyHSD
output when HH is loaded is to use the long statements
stats:::print.TukeyHSD(TukeyHSD(mydata.aov))
plot.TukeyHSD(TukeyHSD(mydata.aov))
I will detect that conflict in the next release of HH and prevent it from
happening.

A better solution is to use glht in the multcomp package instead of
TukeyHSD.
Then the statement is
confint(glht(mydata.aov, linfct=mcp(Trt="Tukey")))

glht is better because it does not have the limitations of TukeyHSD.
TukeyHSD is not applicable in your example because TukeyHSD doesn't work
with covariates.
The documentation ?TukeyHSD says "non-factor terms these will be dropped
with a warning".

With glht and the HH package loaded, you can get a better plot.
glht.mmc(mydata.aov, linfct=mcp(Trt="Tukey"))
plot(glht.mmc(mydata.aov, linfct=mcp(Trt="Tukey")))
With the MMC plot ?HH:::MMC, "Each contrast is plotted at a height which is
the weighted
average of the means being compared"






Thanks again.

Regards,
Jinsong



 Rich
>> On Sun, Dec 11, 2011 at 7:15 AM, Jinsong Zhao >  > wrote:
>>
>>Hi there,
>>
>>The following data is obtained from a long-term experiments.
>>
>> > mydata <- read.table(textConnection("
>>+y year Trt
>>+ 9.37 1993   A
>>+ 8.21 1995   A
>>+ 8.11 1999   A
>>+ 7.22 2007   A
>>+ 7.81 2010   A
>>+10.85 1993   B
>>+12.83 1995   B
>>+13.21 1999   B
>>+13.70 2007   B
>>+15.15 2010   B
>>+ 5.69 1993   C
>>+ 5.76 1995   C
>>+ 6.39 1999   C
>>+ 5.73 2007   C
>>+ 5.55 2010   C"), header = TRUE)
>> > closeAllConnections()
>>
>>The experiments is designed without replication, thus I have to use
>>ANCOVA or linear mixed effect model to analyze the data. In the
>>model, variable year is coded as a continuous variable, and Trt is
>>factor variable.
>>
>> > mydata.aov <- aov(y~Trt*year, mydata)
>> > anova(mydata.aov)
>>Analysis of Variance Table
>>
>>Response: y
>>  Df  Sum Sq Mean Sq  F valuePr(>F)
>>Trt2 140.106  70.053 197.9581 3.639e-08 ***
>>year   1   0.610   0.610   1.7246  0.221600
>>Trt:year   2   8.804   4.402  12.4387  0.002567 **
>>Residuals  9   3.185   0.354
>>---
>>Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>>
>>As you have seen, the interaction effect is significant. I hope to
>>use TukeyHSD() or glht() to do multiple comparison on Trt:year.
>>However, for variable year is not a factor, they all give error
>>messages.
>>
>>I try to follow the demo("MMC.WoodEnergy") in HH package, as follwoing:
>>
>> > library(HH)
>> > mca.1993 <- mcalinfct(mydata.aov, "Trt")
>> > non.zero <- mca.1993[,5:6] != 0
>> > mca.1993[,5:6][non.zero] <- 1993 * sign(mca.1993[,5:6][non.zero])
>> > summary(glht(mydata.aov, linfct=mca.1993))
>>
>> Simultaneous Tests for General Linear Hypotheses
>>
>>Fit: aov(formula = y ~ Trt * year, data = mydata)
>>
>>Linear Hypotheses:
>>   Estimate Std. Error t value Pr(>|t|)
>>B - A == 0   2.8779 0.5801   4.961  0.00215 **
>>C - A == 0  -2.8845 0.5801  -4.972  0.00191 **
>>C - B == 0  -5.7624 0.5801  -9.933 < 0.001 ***
>>---
>>Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>>(Adjusted p values reported -- single-step method)
>>
>>It can give comparison between levels of Trt within one year, e.g.,
>>1993.
>>
>>Is it possible to do multiple comparison for the following pairs:
>>
>>A.1995 - A.1993
>>B.1995 - A.1993
>>C.1995 - A.1993
>>
>>Any suggestions or comments will be really appreciated. Thanks in
>>advance

Re: [R] Lagged values problem requiring short solution time

2011-12-12 Thread Rui Barradas
Kevin,

Your problem seems to have three restrictions: (1) abs(x[i] - x[i-1]) >=
delta (2) y[i] >= x[i]
and (3) minimize sum(y-x). If this is the case I believe I have a better
solution, with a smaller sum
and in much less time.
The problem is restriction (2). If the diffs are negative you can't subtract
negative,
 the new y[i] would be less than x[i]. So, add. Here is the code:

fun1 <- your code

fun2 <- function(x, delta){
n <- length(x) # don't need 
to
create a work y
if(abs(x[1] - x[n]) < delta) x[1] <- x[n] + delta # special case, wraps
around.
ix <- which(abs(x[2:n] - x[2:n - 1]) < delta) # make up an index 
vector
x[ix] <- x[ix - 1] + delta# and use it. 
x
}

# First test both

x = runif(10,1,5)
y1 <- fun1(x, delta=0.75); s1 <- sum(y1 - x)
y2 <- fun2(x, delta=0.75); s2 <- sum(y2 - x)
# and display results
rbind(fun1=c(y=y1, s=s1), c(diff(c(y1,y1[1])), NA),
fun2=c(y=y2, s=s2), c(diff(c(y2,y2[1])), NA),
x=c(x, NA), c(diff(c(x,x[1])), NA))

# now time them!
x <- runif(10^5, 1, 5)
t1 <- system.time(for(i in 1:10^2) y1 <- fun1(x, delta=0.75))[c(1, 3)]
t2 <- system.time(for(i in 1:10^2) y2 <- fun2(x, delta=0.75))[c(1, 3)]
rbind(fun1=t1, fun2=t2, ratio=t1/t2)
#
# Sample run
#
  user.self  elapsed
fun1   26.99000 29.6
fun20.92000  1.09000
ratio  29.33696 27.15596

29 times faster!

I hope it's usefull

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/Lagged-values-problem-requiring-short-solution-time-tp4184566p4186786.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] Creating appropriate time axis for data

2011-12-12 Thread Tony Stocker
Hello,

I am dealing with data stored in a database as a 'time' object.  I
export the data from the database to a text file and utilize the
'time_to_sec()' function of the database to convert the human readable
time (HH:MM:SS) to seconds so that I can use R to do analysis and
create charts of the data.  I do not need or use days or dates in the
data, and the data range is from 07:00:00 to 18:00:00 or 25200-64800
seconds.  However when I visualize the data in charts I do not want a
scale that runs from 25200-64800 seconds, but rather in the HH:MM:SS
format.  Is there a relatively straight-forward and easy to use way to
do this?

Thanks,
Tony

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


Re: [R] Lagged values problem requiring short solution time

2011-12-12 Thread Rui Barradas
Kevin,

I'm sorry, but my code has a bug
The correction is:

1) delete the two lines with 'ix'
2) replace them with

for(i in 2:n)
if(abs(x[i] - x[i-1]) < delta) x[i] <- x[i-1] + delta

That's it. The problem is that it's back to slowness.

Sorry, once again,

Rui Barradas

--
View this message in context: 
http://r.789695.n4.nabble.com/Lagged-values-problem-requiring-short-solution-time-tp4184566p4187126.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] not complete character in csv file

2011-12-12 Thread threshold
right,

Table <- data.frame(matrix(0,8,3))
day = "Monday"
Table[1,1]=day 
Table[1,2]=3

works, thanks a lot. robert

--
View this message in context: 
http://r.789695.n4.nabble.com/not-complete-character-in-csv-file-tp4185785p4186639.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] shorter way of coding

2011-12-12 Thread Mintewab Bezabih
Dear Paul and Sarah

Thanks for the suggestion. I have provided my data here in to make the results 
reproducable. I am actually trying to do interpoliation of climate data where 
x1 and x2 are my latitude and longitude and sum64-sum 368 are my rainfall 
observations which I need to regress against x1 and x2. In the previous I was 
trying to get my story clear so I did not go into details. 

Now when I run your suggestion below, I get the following error message. Is 
there anything in your instruction that I did not get right?
many thanks
mintewab

listOfForumlas = paste(1:300, "~s(x1,x2, k=100)")
listofResults = lapply(listOfForumlas, function(f) {
b<-gam(as.formula(f),data=dat)
vis.gam(b)
fitted(b)
  })

Error in model.frame.default(formula = 1 ~ 1 + x1+ x2, data = dat,  : 
  variable lengths differ (found for 'x1')


Från: Paul Hiemstra [paul.hiems...@knmi.nl]
Skickat: den 12 december 2011 14:42
Till: Mintewab Bezabih
Kopia: r-help@r-project.org
Ämne: Re: [R] shorter way of coding

On 12/12/2011 01:16 PM, Mintewab Bezabih wrote:
> Dear R users,
>
> I am using the code below to generate a fitted value of b. I have about 300 
> different values for for y (y1, y2, ...y300) which means I will have to write 
> the code below 300 times to generate the 300 different fitted values for y. 
> Is there a short way of doing that ?
>
> Many thanks in advance
> Mintewab
>
> library(mgcv)
> dat <- read.table("e:/minti's laptop/C/GBG/allround_survey/rainfallGPS.csv", 
> header=T, sep=",")
> b<-gam(y1~s(x1, x2, k=100),data=dat)
> vis.gam(b)
> fitted(b)
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Hi Mintewab,

Something along these lines should work:

listOfForumlas = paste(1:300, "~s(x1, x2, k=100)")
listofResults = lapply(listOfForumlas, function(f) {
b<-gam(as.formula(f),data=dat)
vis.gam(b)
fitted(b)
  })

But as Sarah already commented, without a reproducible piece of example
code we cannot present any working solutions.

cheers,
Paul

--
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770

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

2011-12-12 Thread Brian Jensvold
I am doing a logistic regression, and by accident I included a field
which has the 2digit abbreviation for all 50 states labeled "st".  I was
surprised to see that the glm did not come up with an error message but
instead appears to have automatically broken down this field into
individual fields (stAK and stAL).  Does R really know to turn all
categorical variables in binary dummy variables?  I have tried answering
the question on my own and have found:



When including categorical variables in a regression, the default in R
is to

set the first level as the base.  Is there an option to specify a
different

level as the base?



My next/same question is what does it mean to "set the first level as
the base" does this mean it turns each value into a unique binary
result?



CONFIDENTIALITY NOTICE
 

This message (including any attachments) is intended onl...{{dropped:21}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Improve a browse through list items - Transform a loop to apply-able function.

2011-12-12 Thread Robin Cura
Hello,

I'm currently trying to convert a slow and ugly script I made, so that it's
faster and can be computed on a computer grid with the multicore package.
My problem is that I don't see how to turn some loops into an "apply-able"
function.

Here's an example of my loops :
I got a list of dataframes (or matrices like here), and I need to browse
each cell of those many dataframes to compute a mean (or standard deviation
like here).

Here's a example script :

a <- b <- c <- d <- result <- matrix(nrow=3, ncol=3)
a[] <- sample.int(n=100,size=9,replace=TRUE)
b[] <- sample.int(n=100,size=9,replace=TRUE)
c[] <- sample.int(n=100,size=9,replace=TRUE)
d[] <- sample.int(n=100,size=9,replace=TRUE)
result[] <- NA
mylist <- list(a,b,c,d)

for (row in 1:3)
{
  for (col in 1:3)
  {
tmpList <- log(mylist[[1]][row, col])
for (listitem in 2:4)
{
  tmpList <- c(tmpList, log(mylist[[listitem]][row, col]))
}
result[row, col] <- sd(tmpList)
  }
}

Considering I have to look at the same cell in each dataframe, I don't
understand how I could turn this into a function, considering I need the
row and column number to iterate.

I succeeded improving my script duration a lot, but such loops are really
long to run, considering that my lists contains like 100 dataframes, who
all contains thousands of values.

Any help would be really appreciated

Thanks in advance,

Robin

[[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] Automated Regressions

2011-12-12 Thread Frederic Andrieu
Hi Ryan,

My name is Frederic Andrieu and I work for Mango Solutions in the UK. It looks 
like you have swapped the a and c in this for loop statement:

This "for (c in a(1:2000)) {" should be this "for (a in c(1:2000)) {"

Which is why the for loop is not running, I would suggest something like this:
#

Require(RODBC)

myChannel <- odbcConnect(dsn = "myDSN")
sqlString1 <- "SELECT myTable.Contries FROM myTable GROUP BY myTable.Countries;"
myContries <- sqlQuery(channel = myChannel, query = sqlString1)

# myContries is now a table of counties with 1 column and as many rows as there 
are countries

# Then this is the function that will do the legwork myLm <- function(myCountry 
= myCountries[1]){
print(myCountry)
sqlString2 <- paste("SELECT myTable.* FROM myTable WHERE 
(((myTable.Countries)=", myCountry,")); ", sep = "")
myData <- sqlQuery(channel = myChannel, query = sqlString2)
myOut <- summary(lm(Quant ~ UPE + Mon, data = myData))$coeff
myOut <- data.frame(myOut)
colnames(myOut) <- c("Estimate", "Std. Error",  " tvalue"," 
Pr(>|t|)")
myOut <- data.frame(myCountry, myOut)
return(myOut)
}

# Applying the function
myAnalysis <- lapply(myCountries, myLm)
myAnalysis <- do.call(rbind, myAnalysis)

#

Let me know if this helps.

Best regards,

Frederic Andrieu

M: +44(0)07813 526 123
T: +44 (0)1249 766 801  
F: +44 (0)1249 767 707
www.mango-solutions.com 
Unit 2 Greenways Business Park
Bellinger Close
Chippenham
Wilts
SN15 1BN
UK 



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of ryanSt
Sent: 12 December 2011 14:59
To: r-help@r-project.org
Subject: [R] Automated Regressions

Hello R-Experts,

I've got a question, concerning the automation of a number of regressions
(lm) with the help of a loop (for i in ).

The situation is as follows (the code follows after that):
I have my data in an access database. I have historical data for 2000 parts,
for each of this parts I want to do a regression analysis, so I need to do
2000 regressions (just for one country, there are also more countries). So
this would be a lot of manual effort. 
What I want to do is to automate this routine. I have already established a
database connection via RODBC.
So I can acces every part with its distinct code by a SQL Query. For every
part, the SQL Query has to be adapted for the parts name.
My idea was to generate the SQL Code in Excel for ervery part and save this
as an txt-file. So I can define the SQL-Codes as an object (SQL_Code <-
load.table("...txt, header = FALSE). 
In the next step I can build a loop, which tells R to go through the object
SQL_Code line for line, using the text for the SQL Query.


The code is as follows:
SQL Code in the sqlparts.txt. file: "SELECT table.* FROM table WHERE
((table.part) = '2929AAD766')" (2000 lines for all parts, each part has a
distinct code)

SQL_Code <- load.table("sqlparts.txt", header = FALSE)

Loop: 
for (c in a(1:2000)) {

Dataset <- sqlQuery(Database, SQL_Code[a,1])

print(summary(lm(Quant~ UPE + Mon, data = Dataset)))
}


Unfortunately, this loop doesn't work. I think, it's because R does not
interpret the object SQL_Code as text, so the sqlQuery is incomplete.

Can anybody help me with that problem?

Thank you in advance.

Greets
Ryan




--
View this message in context: 
http://r.789695.n4.nabble.com/Automated-Regressions-tp4186280p4186280.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.
LEGAL NOTICE
This message is intended for the use o...{{dropped:10}}

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


Re: [R] Automated Regressions

2011-12-12 Thread B77S
I don't know why you had "c in a(1:2000))"  
c is a function see ?c ...
and you want "a" (the row number in SQL_Code) to change with each iteration
in the loop.


Perhaps this might work (I'm not saying this is the best option, just a
potential fix for what you have): 

for (a in 1:2000) {
Dataset <- sqlQuery(Database, SQL_Code[a,1])
print(summary(lm(Quant~ UPE + Mon, data = Dataset)))
}







ryanSt wrote
> 
> Hello R-Experts,
> 
> I've got a question, concerning the automation of a number of regressions
> (lm) with the help of a loop (for i in ).
> 
> The situation is as follows (the code follows after that):
> I have my data in an access database. I have historical data for 2000
> parts, for each of this parts I want to do a regression analysis, so I
> need to do 2000 regressions (just for one country, there are also more
> countries). So this would be a lot of manual effort. 
> What I want to do is to automate this routine. I have already established
> a database connection via RODBC.
> So I can acces every part with its distinct code by a SQL Query. For every
> part, the SQL Query has to be adapted for the parts name.
> My idea was to generate the SQL Code in Excel for ervery part and save
> this as an txt-file. So I can define the SQL-Codes as an object (SQL_Code
> <- load.table("...txt, header = FALSE). 
> In the next step I can build a loop, which tells R to go through the
> object SQL_Code line for line, using the text for the SQL Query.
> 
> 
> The code is as follows:
> SQL Code in the sqlparts.txt. file: "SELECT table.* FROM table WHERE
> ((table.part) = '2929AAD766')" (2000 lines for all parts, each part has a
> distinct code)
> 
> SQL_Code <- load.table("sqlparts.txt", header = FALSE)
> 
> Loop: 
> for (c in a(1:2000)) {
> 
> Dataset <- sqlQuery(Database, SQL_Code[a,1])
> 
> print(summary(lm(Quant~ UPE + Mon, data = Dataset)))
> }
> 
> 
> Unfortunately, this loop doesn't work. I think, it's because R does not
> interpret the object SQL_Code as text, so the sqlQuery is incomplete.
> 
> Can anybody help me with that problem?
> 
> Thank you in advance.
> 
> Greets
> Ryan
> 


--
View this message in context: 
http://r.789695.n4.nabble.com/Automated-Regressions-tp4186280p4187109.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] unlist() list of dates

2011-12-12 Thread Ana
Thanks!

Another question also related to the same type of files:

How can I transform it into a time series
as.ts()

I also endup having the same problem, the dates are transformed into a
list of numbers

My file looks like this
  datesval
12001-01-121.2
22001-02-121.2
22001-03-121.2

(...)

class: data.frame

On Mon, Dec 12, 2011 at 6:30 PM, William Dunlap  wrote:
> There are methods of the "c" function for things of class "POSIXlt" and "Date"
> so do.call("c", dataList) works instead of unlist:
>  > dateList <- list(LastWeekend=as.POSIXlt(sprintf("2011-12-%d", 10:11)),
>  +                  Today=as.POSIXlt("2011-12-12"))
>  > z <- do.call("c", dateList)
>  > z
>      LastWeekend1     LastWeekend2            Today
>  "2011-12-10 PST" "2011-12-11 PST" "2011-12-12 PST"
>  > str(z)
>   POSIXlt[1:3], format: "2011-12-10" "2011-12-11" "2011-12-12"
>   - attr(*, "names")="LastWeekend1" "LastWeekend2" "Today"
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
>> Behalf Of Ana
>> Sent: Monday, December 12, 2011 9:03 AM
>> To: r-help@r-project.org
>> Subject: [R] unlist() list of dates
>>
>> how can I keep the date info after doing unlist to a list of dates?
>>
>> I have a list of dates were observations were made for each station in
>> each month
>>
>> list.obs[[station]][month]
>>
>> [1] "1979-01-01" "1979-01-10" "1979-01-25"
>>
>> [1]     0     1     2     3
>>
>> when i try to unlist i loose the date info.
>>
>> what am I doing wrong?
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] Overlaying density plot on forest plot

2011-12-12 Thread Michael Dewey

At 15:09 11/12/2011, you wrote:

Dear Michael,

Thanks for the email. This is the kind of forest plot, I want to replicate

http://www.biomedcentral.com/1471-2334/11/122/figure/F2


It would be helpful to cc to r-help in case someone else there knows better.

If you follow my suggestion you get a similar plot to sub-plot A in 
your example but the credible interval is shown as a dashed line 
superimposed on the summary diamond and not as a normal density as 
shown in sub-plot A. Whether that is what you want is up to you I think.



Regards
Frank Peter

 Original Message 
From: Michael Dewey 
To: "Frank Peter" , r-help@r-project.org
Subject: Re: [R] Overlaying density plot on forest plot
Date: Sun, 11 Dec 2011 14:20:13 +

> At 07:16 10/12/2011, Frank Peter wrote:
> >Dear R User,
> >
> >Please, I am new to R. I want to overlay density plot for predictive
> >interval pooled result in meta-analysis.
> >http://addictedtor.free.fr/graphiques/graphcode.php?graph=114
>
> It is hard to be sure from your rather brief question but does the
> addcred parameter to forest.rma in package metafor do what you want?
>
> >
> >
> >Regards
> >Frank Peter
>
> Michael Dewey
> i...@aghmed.fsnet.co.uk
> http://www.aghmed.fsnet.co.uk/home.html


Michael Dewey
i...@aghmed.fsnet.co.uk
http://www.aghmed.fsnet.co.uk/home.html

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


Re: [R] unlist() list of dates

2011-12-12 Thread William Dunlap
There are methods of the "c" function for things of class "POSIXlt" and "Date"
so do.call("c", dataList) works instead of unlist:
  > dateList <- list(LastWeekend=as.POSIXlt(sprintf("2011-12-%d", 10:11)),
  +  Today=as.POSIXlt("2011-12-12"))
  > z <- do.call("c", dateList)
  > z
  LastWeekend1 LastWeekend2Today
  "2011-12-10 PST" "2011-12-11 PST" "2011-12-12 PST"
  > str(z)
   POSIXlt[1:3], format: "2011-12-10" "2011-12-11" "2011-12-12"
   - attr(*, "names")="LastWeekend1" "LastWeekend2" "Today"

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of Ana
> Sent: Monday, December 12, 2011 9:03 AM
> To: r-help@r-project.org
> Subject: [R] unlist() list of dates
> 
> how can I keep the date info after doing unlist to a list of dates?
> 
> I have a list of dates were observations were made for each station in
> each month
> 
> list.obs[[station]][month]
> 
> [1] "1979-01-01" "1979-01-10" "1979-01-25"
> 
> [1] 0 1 2 3
> 
> when i try to unlist i loose the date info.
> 
> what am I doing wrong?
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] unlist() list of dates

2011-12-12 Thread Ana
how can I keep the date info after doing unlist to a list of dates?

I have a list of dates were observations were made for each station in
each month

list.obs[[station]][month]

[1] "1979-01-01" "1979-01-10" "1979-01-25"

[1] 0 1 2 3

when i try to unlist i loose the date info.

what am I doing wrong?

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


Re: [R] For loop indicies

2011-12-12 Thread Thomas Chesney
Ah. I did a Silly Thing, and thank you for all the responses helping me track 
it down.

The issue lay not in the for (i in 1:C) but in the line VectorName[i] <- ...

That's the one that didn't like 0.


Thomas

From: Enrico Schumann [enricoschum...@yahoo.de]
Sent: Monday, December 12, 2011 11:59 AM
To: Thomas Chesney
Cc: r-help@r-project.org
Subject: Re: [R] For loop indicies

You may want to check how your loop "misses out" the zero:

C <- 5
for (i in 0:C) print(i)

## gives me

[1] 0
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5


Regards,
Enrico

Am 12.12.2011 12:44, schrieb Thomas Chesney:
> I would like to run a for loop with an index going from 0 to 499 but the 
> following seems to miss out the first value:
>
> C<- 499
> for (i in 0:C)
>
> The alternative is:
>
> C<- 500
> for (i in 1:C)
> {
> #Then every time I use i, I replace it with i-1
> }
>
> Is this a good way to do it or is tere a better way?
>
> Thank you,
>
> ThomasThis message and any attachment are intended solely for the addressee 
> and may contain confidential information. If you have received this message 
> in error, please send it back to me, and immediately delete it.   Please do 
> not use, copy or disclose the information contained in this message or in any 
> attachment.  Any views or opinions expressed by the author of this email do 
> not necessarily reflect the views of the University of Nottingham.
>
> This message has been checked for viruses but the contents of an attachment
> may still contain software viruses which could damage your computer system:
> you are advised to perform your own checks. Email communications with the
> University of Nottingham may be monitored as permitted by UK legislation.
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

--
Enrico Schumann
Lucerne, Switzerland
http://nmof.net/

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


Re: [R] shorter way of coding

2011-12-12 Thread Sarah Goslee
That's not a reproducible example. Paul suggested a list of formulas,
but I recommended creating a list of y variables.

In your attempt, you didn't include the y in the name of the dependent
variable; that's probably why it doesn't work.

Look at this:

> y.list <- list(y1=runif(10), y2 <- runif(10), y3 <- runif(10))
> x1 <- 1:10
> lapply(y.list, function(y)lm(y ~ x1))
$y1

Call:
lm(formula = y ~ x1)

Coefficients:
(Intercept)   x1
0.56392 -0.02586


[[2]]

Call:
lm(formula = y ~ x1)

Coefficients:
(Intercept)   x1
0.66375 -0.03519


[[3]]

Call:
lm(formula = y ~ x1)

Coefficients:
(Intercept)   x1
0.29106  0.02845

Sarah

On Mon, Dec 12, 2011 at 11:21 AM, Mintewab Bezabih
 wrote:
> Dear Paul and Sarah
>
> Thanks for the suggestion. I have provided my data here in to make the 
> results reproducable. I am actually trying to do interpoliation of climate 
> data where x1 and x2 are my latitude and longitude and sum64-sum 368 are my 
> rainfall observations which I need to regress against x1 and x2. In the 
> previous I was trying to get my story clear so I did not go into details.
>
> Now when I run your suggestion below, I get the following error message. Is 
> there anything in your instruction that I did not get right?
> many thanks
> mintewab
>
> listOfForumlas = paste(1:300, "~s(x1,x2, k=100)")
> listofResults = lapply(listOfForumlas, function(f) {
>    b<-gam(as.formula(f),data=dat)
>    vis.gam(b)
>    fitted(b)
>  })
>
> Error in model.frame.default(formula = 1 ~ 1 + x1+ x2, data = dat,  :
>  variable lengths differ (found for 'x1')
> 
> Från: Paul Hiemstra [paul.hiems...@knmi.nl]
> Skickat: den 12 december 2011 14:42
> Till: Mintewab Bezabih
> Kopia: r-help@r-project.org
> Ämne: Re: [R] shorter way of coding
>
> On 12/12/2011 01:16 PM, Mintewab Bezabih wrote:
>> Dear R users,
>>
>> I am using the code below to generate a fitted value of b. I have about 300 
>> different values for for y (y1, y2, ...y300) which means I will have to 
>> write the code below 300 times to generate the 300 different fitted values 
>> for y. Is there a short way of doing that ?
>>
>> Many thanks in advance
>> Mintewab
>>
>> library(mgcv)
>> dat <- read.table("e:/minti's laptop/C/GBG/allround_survey/rainfallGPS.csv", 
>> header=T, sep=",")
>> b<-gam(y1~s(x1, x2, k=100),data=dat)
>> vis.gam(b)
>> fitted(b)
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> Hi Mintewab,
>
> Something along these lines should work:
>
> listOfForumlas = paste(1:300, "~s(x1, x2, k=100)")
> listofResults = lapply(listOfForumlas, function(f) {
>    b<-gam(as.formula(f),data=dat)
>    vis.gam(b)
>    fitted(b)
>  })
>
> But as Sarah already commented, without a reproducible piece of example
> code we cannot present any working solutions.
>
> cheers,
> Paul
>
-- 
Sarah Goslee
http://www.functionaldiversity.org

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


Re: [R] shorter way of coding

2011-12-12 Thread Mintewab Bezabih
Dear Paul and Sarah

Thanks for the suggestion. I have provided my data here in to make the results 
reproducable. I am actually trying to do interpoliation of climate data where 
x1 and x2 are my latitude and longitude and sum64-sum 368 are my rainfall 
observations which I need to regress against x1 and x2. In the previous I was 
trying to get my story clear so I did not go into details. 

Now when I run your suggestion below, I get the following error message. Is 
there anything in your instruction that I did not get right?
many thanks
mintewab

listOfForumlas = paste(1:300, "~s(x1,x2, k=100)")
listofResults = lapply(listOfForumlas, function(f) {
b<-gam(as.formula(f),data=dat)
vis.gam(b)
fitted(b)
  })

Error in model.frame.default(formula = 1 ~ 1 + x1+ x2, data = dat,  : 
  variable lengths differ (found for 'x1')

Från: Paul Hiemstra [paul.hiems...@knmi.nl]
Skickat: den 12 december 2011 14:42
Till: Mintewab Bezabih
Kopia: r-help@r-project.org
Ämne: Re: [R] shorter way of coding

On 12/12/2011 01:16 PM, Mintewab Bezabih wrote:
> Dear R users,
>
> I am using the code below to generate a fitted value of b. I have about 300 
> different values for for y (y1, y2, ...y300) which means I will have to write 
> the code below 300 times to generate the 300 different fitted values for y. 
> Is there a short way of doing that ?
>
> Many thanks in advance
> Mintewab
>
> library(mgcv)
> dat <- read.table("e:/minti's laptop/C/GBG/allround_survey/rainfallGPS.csv", 
> header=T, sep=",")
> b<-gam(y1~s(x1, x2, k=100),data=dat)
> vis.gam(b)
> fitted(b)
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Hi Mintewab,

Something along these lines should work:

listOfForumlas = paste(1:300, "~s(x1, x2, k=100)")
listofResults = lapply(listOfForumlas, function(f) {
b<-gam(as.formula(f),data=dat)
vis.gam(b)
fitted(b)
  })

But as Sarah already commented, without a reproducible piece of example
code we cannot present any working solutions.

cheers,
Paul

--
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770

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


Re: [R] [solved] littler: Use for batch processing of data sets: How to pass filename?

2011-12-12 Thread Paul Menzel
Am Montag, den 12.12.2011, 09:41 -0500 schrieb R. Michael Weylandt :
> Why can't you just replace "temp/data" with filename (no quotes)? I'm not 
> sure I get the question...

… no I am feeling silly and I do not know where I screwed up before.
Here is the full working example.

#!/usr/bin/env r

if (is.null(argv) | length(argv)!=1) {

  cat("Usage: auswertung.r datafile \n")
  q()

}

filename <- as.character(argv[1])

d = data.frame(x=scan(filename))
write(sum(d$x), paste(filename, ".result", sep=""), ncolumns=1)


Thank you very much,

Paul


signature.asc
Description: This is a digitally signed message part
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] not complete character in csv file

2011-12-12 Thread R. Michael Weylandt
Matrix (which is secretly a vector) can only have one mode
(numeric/factor/character/etc.) for all its elements. If you need
multiple types, go to a data frame

Michael


On Mon, Dec 12, 2011 at 10:39 AM, threshold  wrote:
> Indeed in txt it looks fine. Anyway, I must stay without 0 because csv is THE
> format.
>
> I got another question. why for
> Table <- matrix(0,8,3)
> day = "Monday"
> Table[1,1]=day
>
> all other elements become characters too?
>
> Thanks, robert
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/not-complete-character-in-csv-file-tp4185785p4186427.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] Color2D.matplot uniform color range

2011-12-12 Thread jalfaro
Hi Jim, 
Thanks so much for your help. I have read several of your responses on this
mailing list and they have helped me out quite a bit as I have gotten more
and more used to R. 

I am still a little confused here by your response. 
I think you understood my requirements correctly. 
In your words:
 I want to anchor the extremes of the scales regardless of the values in the
matrix.
 I want 1 color gradient for values between 0 and 1 with a lowerbound cutoff
at 0.5.
 I want a second color gradient for values between 1 and infinity with an
upper bound cutoff at 3. 

The function now reads as follows: 

make_Q_figure<-function(filename,alias){
 h0  <- read.csv(file=filename,head=TRUE,sep=",",row.names=1)
 d =data.matrix(h0)
 cellcolors<-matrix(NA,nrow=20,ncol=20)
 d <- d[ind,ind]
 cellcolors[d >= 1 & d < 3]<- color.scale(c(1,3,d[d >= 1 & d < 3]),
cs1=1,cs2=c(1,0),cs3=c(1,0))[-1:2]
 cellcolors[d<1]<- 
color.scale(c(0,1,d[d<1]),cs1=c(0,0,1),cs2=c(0,0,1),cs3=1)[-1:2]
 cellcolors[d >= 2]<-"red"

color2D.matplot(d,cellcolors=cellcolors,show.values=F,na.color="white",axes=FALSE,main=alias,
xlab="",ylab="")
 axis(1,at=0.5:19.5,labels=colnames(d))
 axis(2,at=0.5:19.5,labels=rev(rownames(d)))
}

However when I execute this function I get the following error: 
Error in color.scale(c(0, 1, d[d < 1]), cs1 = c(0, 0, 1), cs2 = c(0, 0,  :
  only 0's may be mixed with negative subscripts

An example input csv file is: 

aa,A,R,N,D,C,Q,E,G,H,I,L,K,M,F,P,S,T,W,Y,V
A,1.1140,0.9914,0.9706,0.8975,1.0217,1.0151,0.9699,1.0449,1.0126,0.9413,0.9421,0.9766,1.0411,0.9941,0.9243,1.0839,1.1340,0.9732,1.0073,1.0044
R,1.0339,1.0072,0.9642,0.8936,0.9424,0.9915,0.9497,0.9779,0.9896,0.8998,0.9120,0.9646,1.0300,0.9165,0.8856,1.0652,1.0880,0.9213,0.9342,0.9397
N,1.0469,0.9763,1.0613,0.9658,0.9817,0.9640,0.9389,1.0283,1.0294,0.9500,0.9556,0.9869,1.0569,0.9745,0.8287,1.0937,1.0944,0.9701,0.9641,0.9884
D,1.1241,1.0373,1.0358,1.0939,1.0107,1.0260,0.9840,1.0536,1.0727,0.9664,0.9869,1.0481,1.0917,0.9881,0.8351,1.1279,1.1123,0.9908,1.0066,1.0002
C,1.1007,1.0999,1.1280,1.0687,1.1967,1.0964,1.0631,1.1275,1.1668,1.0799,1.0139,1.1009,1.1200,1.0839,0.9009,1.2096,1.2340,1.0837,1.0998,1.1335
Q,1.0078,0.9555,0.9715,0.8813,0.9310,1.0032,0.9339,0.9630,0.9888,0.8811,0.8916,0.9519,0.9993,0.9103,0.8907,1.0625,1.0831,0.9088,0.9300,0.9307
E,1.0494,0.9865,0.9888,0.9247,0.9567,1.0004,1.0270,0.9890,1.0097,0.9088,0.9178,0.9850,1.0252,0.9212,0.8782,1.0737,1.0774,0.9312,0.9447,0.9420
G,0.9900,0.9683,0.9508,0.9162,0.9446,0.9667,0.9472,1.0452,0.9802,0.9247,0.9090,0.9654,0.9940,0.9374,0.8313,1.0343,1.0438,0.9344,0.9401,0.9566
H,1.0022,0.9459,0.9861,0.9343,0.9768,0.9539,0.9241,0.9879,1.0092,0.9259,0.9188,0.9654,1.0090,0.9431,0.8232,1.0544,1.0691,0.9491,0.9503,0.9638
I,1.1463,1.0799,1.0597,1.0151,1.0423,1.0985,1.0570,1.0798,1.0935,1.1005,1.0237,1.0886,1.1383,1.0321,0.8786,1.1389,1.1474,1.0277,1.0343,1.0586
L,1.1444,1.0699,1.0298,0.9750,1.0644,1.0824,1.0402,1.0620,1.0632,1.0042,1.1011,1.0647,1.1253,1.0344,0.9406,1.1156,1.1558,1.0184,1.0373,1.0522
K,1.0350,0.9731,0.9734,0.8856,0.9367,0.9806,0.9329,0.9691,0.9766,0.8962,0.9017,1.0117,1.0164,0.9055,0.8749,1.0328,1.0741,0.9186,0.9302,0.9368
M,1.0612,0.9880,0.9691,0.8914,1.0045,1.0106,0.9690,0.9982,1.0007,0.9349,0.9354,0.9917,1.0036,0.9645,0.9135,1.0471,1.1036,0.9514,0.9740,0.9891
F,1.0519,1.0216,1.0005,0.9571,1.0007,1.0317,0.9909,1.0316,1.0331,0.9821,0.9543,1.0234,1.0531,1.0339,0.8453,1.0861,1.0924,0.9854,0.9858,1.0067
P,0.9846,0.9434,1.0646,1.0543,1.1314,0.9283,0.9357,0.9992,1.0420,0.9883,0.9021,0.9587,0.9830,1.0039,1.0833,1.1387,1.1995,0.9996,1.0210,1.0942
S,0.9851,0.9363,0.9945,0.9485,0.9796,0.9339,0.9174,0.9884,1.0167,0.9337,0.9257,0.9559,1.0246,0.9555,0.8253,1.0447,1.0810,0.9563,0.9570,0.9705
T,0.9587,0.9272,0.9929,0.9602,0.9720,0.9393,0.9115,0.9778,1.0061,0.9354,0.8981,0.9410,0.9701,0.9597,0.7789,1.0650,1.0307,0.9527,0.9650,0.9840
W,1.0231,1.0003,0.9884,0.9447,0.9893,1.0085,0.9943,1.0159,1.0221,0.9541,0.9519,1.0093,1.0434,0.9722,0.8250,1.0622,1.0816,1.0213,0.9804,0.9858
Y,1.0189,1.0075,1.0157,0.9667,1.0037,1.0136,0.9807,1.0238,1.0340,0.9744,0.9282,0.9984,1.0230,0.9903,0.8184,1.0894,1.0973,0.9789,1.0340,1.0086
V,1.0992,1.0823,1.0724,1.0346,1.0629,1.0855,1.0544,1.0968,1.0998,1.0226,0.9972,1.0936,1.1162,1.0423,0.8329,1.1742,1.1807,1.0351,1.0512,1.1072



I'm not seeing the problem here. 

Thanks so much Jim. 
Jav



--
View this message in context: 
http://r.789695.n4.nabble.com/Color2D-matplot-uniform-color-range-tp4184701p4186339.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] no non-missing arguments to max; returning -Inf

2011-12-12 Thread R. Michael Weylandt
The dput() command is essential in doing so. 

Michael

On Dec 11, 2011, at 8:50 AM, Tal Galili  wrote:

> Yes -
> E-mail us reproducible code...
> 
> 
> Contact
> Details:---
> Contact me: tal.gal...@gmail.com |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
> --
> 
> 
> 
> 
> On Sun, Dec 11, 2011 at 10:25 AM, George Kumar  wrote:
> 
>> Hi,
>> 
>> I just wanted to object of class xts, zoo and I got the error
>> no non-missing arguments to max; returning -Inf
>> After all the values were printed. Tried searching on this forum, but no
>> luck.
>> Anyone has any idea ?
>> 
>> Thanks.
>> George
>> 
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/no-non-missing-arguments-to-max-returning-Inf-tp4182296p4182296.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.
>> 
> 
>[[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] not complete character in csv file

2011-12-12 Thread threshold
Indeed in txt it looks fine. Anyway, I must stay without 0 because csv is THE
format.

I got another question. why for 
Table <- matrix(0,8,3)
day = "Monday"
Table[1,1]=day

all other elements become characters too?

Thanks, robert


--
View this message in context: 
http://r.789695.n4.nabble.com/not-complete-character-in-csv-file-tp4185785p4186427.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] [R-SIG-Finance] Question about fitting seasonal ARIMA in R?

2011-12-12 Thread Zachary Mayer
Hi Michael,

As far as I know, there is no Arima function in R that allows multiple
seasonal patterns.  There's 2 approaches you can take:
1. Use a matrix of dummy variables (e.g. jan/feb/mar/...dec and
mon/tues/wed/...sun) as an xreg term in the arima function.
2. Use a matrix of Fourrier terms to represent the different seasonal
patterns.

Rob Hyndman outlines the second approach on his
blog,
which might be a good starting point.  The primary disadvantage of these
approaches is that the seasonal term is assumed to be fixed over time.

-Zach

On Sun, Dec 11, 2011 at 9:56 PM, Michael  wrote:

> sorry for the re-post...
>
> On Sun, Dec 11, 2011 at 8:22 PM, Michael  wrote:
>
> > Hi all,
> >
> > I just couldn't find a R function which can fit multiple seasonal
> > patters...  i.e. in the following code:
> >
> > *arima(x = data, order = c(p, d, q), seasonal = list(order = c(P, D, Q),
> > period = S), ...
> > ***
> > *
> > there can be only one "period", am I right?
> >
> > What if the data seem to have three different seasonality cycles, 5, 12,
> > 21?
> >
> > Thanks a lot!
> > *
> >
>
>[[alternative HTML version deleted]]
>
> ___
> r-sig-fina...@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>

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

2011-12-12 Thread Komine
Hi everybody,
I have a matrix with 3 columns (Date, MeanArea and SdArea). I want to draw a
figure showing the variable MeanArea in terms of the Date. But instead to
use the variable SdArea as bar error, I want to use “polygon error”. I use
this code but the output does not seem good. 
Polyhttp://r.789695.n4.nabble.com/Polygon-tp4186283p4186283.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] Automated Regressions

2011-12-12 Thread ryanSt
Hello R-Experts,

I've got a question, concerning the automation of a number of regressions
(lm) with the help of a loop (for i in ).

The situation is as follows (the code follows after that):
I have my data in an access database. I have historical data for 2000 parts,
for each of this parts I want to do a regression analysis, so I need to do
2000 regressions (just for one country, there are also more countries). So
this would be a lot of manual effort. 
What I want to do is to automate this routine. I have already established a
database connection via RODBC.
So I can acces every part with its distinct code by a SQL Query. For every
part, the SQL Query has to be adapted for the parts name.
My idea was to generate the SQL Code in Excel for ervery part and save this
as an txt-file. So I can define the SQL-Codes as an object (SQL_Code <-
load.table("...txt, header = FALSE). 
In the next step I can build a loop, which tells R to go through the object
SQL_Code line for line, using the text for the SQL Query.


The code is as follows:
SQL Code in the sqlparts.txt. file: "SELECT table.* FROM table WHERE
((table.part) = '2929AAD766')" (2000 lines for all parts, each part has a
distinct code)

SQL_Code <- load.table("sqlparts.txt", header = FALSE)

Loop: 
for (c in a(1:2000)) {

Dataset <- sqlQuery(Database, SQL_Code[a,1])

print(summary(lm(Quant~ UPE + Mon, data = Dataset)))
}


Unfortunately, this loop doesn't work. I think, it's because R does not
interpret the object SQL_Code as text, so the sqlQuery is incomplete.

Can anybody help me with that problem?

Thank you in advance.

Greets
Ryan




--
View this message in context: 
http://r.789695.n4.nabble.com/Automated-Regressions-tp4186280p4186280.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] i can't read large NETCDF file like CRU

2011-12-12 Thread David William Pierce
On Mon, Dec 12, 2011 at 2:19 AM, tony333  wrote:

> i use library(ncdf) to read this file as follow
> library(ncdf)
> sst.nc = open.ncdf(title)
> lonall = get.var.ncdf(sst.nc,'lon')
> latall = get.var.ncdf(sst.nc,'lat')
> precip = get.var.ncdf(sst.nc,'pre')
> close(sst.nc)
> if i use this method my pc freeze and not respond until i restart it is
> there
>

As Paul already mentioned, more information would be useful, but here's a
suggestion. If you have a data set that is too big to fit in your
computer's memory, read it in one timestep at a time and process that
timestep. For example, you could get the number of timesteps in the
variable like this:

varname = 'pre'
sst.nc = open.ncdf(file)
varsize = sst.nc$var[[varname]]$size
nt = dim( varsize )[3]

Then read in one timestep at a time and process it:

for( itstep in 1:nt ) {
data = get.var.ncdf( sst.nc, varname, start=c(1,1,itstep),
count=c(-1,-1,1))
...process one timestep of the data here ...
}

Regards,

--Dave

-- 
Dr. David W. Pierce
Division of Climate, Atmospheric Science, and Physical Oceanography
Scripps Institution of Oceanography, La Jolla, California, USA
(858) 534-8276 (voice)  /  (858) 534-8561 (fax)dpie...@ucsd.edu

[[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] serial.test

2011-12-12 Thread Alemtsehai Abate
Dear R users,
I want to test for serial correlation in each equation of VAR.
The multivariate version of this test, for a vector X of class VAR  for
instance is

var.ser<-serial.test(X,lags.pt=16,type="PT.adjusted") ###  in the vars
package

Would any of you suggest me how to modify this to test for serial corr. in
each equation of VAR please?

Thanks

Tsegaye

[[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] Please sign me out from the r-help group. Thanks!

2011-12-12 Thread Sarah Goslee
Please sign yourself out, using the linke that appears at the bottom of
each and every message from the list.

On Mon, Dec 12, 2011 at 9:48 AM, Kaigang Li  wrote:
>
>        [[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 colour labels (each label with a colour) in a dendrogram?

2011-12-12 Thread barbara costa
Thanks a lot. I didn't find that. I prefered the option with class
discovery package which we have to install from OOMPA project.
barbara

On 12 December 2011 11:58, Sarah Goslee  wrote:

> Did you try this:
>
> http://r.789695.n4.nabble.com/coloring-leaves-in-a-hclust-or-dendrogram-plot-td795496.html
>
> or this:
>
>
> http://bioinformatics.mdanderson.org/Software/OOMPA/ClassDiscovery/html/plotColoredClusters.html
>
> edgetext labels the segments, I think, and is not what I understand
> you to want, which is colors for the labels themselves. Thus, the
> above suggestions, which I found with about 30 seconds of Googling.
>
> Sarah
>
> On Mon, Dec 12, 2011 at 5:10 AM, barbara costa 
> wrote:
> > Hello to all,
> > I still have this doubt.
> > I'd like to colour the different labels of my dendrogram each one with a
> > different colour. How can I do? I guess I could do using edgetext and
> then
> > t.col or lab.col but I don't know how to add edgetext to my dendrogram.
> Can
> > you help me please?
> >
> > Example:
> >
> > require(graphics); require(utils)
> > hc <- hclust(dist(USArrests), "ave")
> >  (dend1 <- as.dendrogram(hc))
> > plot(dend1)
> > labels (USArrests) [[1]] # to know how many cities (labels) = 50
> >
> > nP <- list(col=3:2, cex=c(2.0, 0.75), pch= 21:22,
> >bg= c("light blue", "pink"),
> >lab.cex = 0.75, lab.col = 1:50) # or use a palette:
> > palette(rainbow(50))
> >
> > plot(dend1, edgePar=nP, dLeaf=1, edge.root = TRUE)
> >
> > # this option is not correct. I want each of my labels (text) have a
> > different colour but that is not what is happening. How can I do that?
> >
> > I'd appreciate your help.
> > thanks a lot again.
> > Barbara
> >
> > On 9 December 2011 13:44, barbara costa  wrote:
> >>
> >> I'm sorry.
> >>
> >>  (dend1 <- as.dendrogram(hc))
> >>
> >> On 9 December 2011 12:10, Sarah Goslee  wrote:
> >>>
> >>> Hi,
> >>>
> >>> On Fri, Dec 9, 2011 at 6:57 AM, barbara costa 
> >>> wrote:
> >>> > Hello to all,
> >>> > I'd like to colour the different labels of my dendrogram. How can I
> do?
> >>> > I
> >>> > guess I could to using *edgetext* and then* t.col* or *lab.col* but I
> >>> > don't
> >>> > know how to add edgetext to my dendrogram. Can you help me please?
> >>> >
> >>> > Example:
> >>> >
> >>> > require(graphics); require(utils)
> >>> >
> >>> > hc <- hclust(dist(USArrests), "ave")
> >>> > plot(dend1)
> >>> > labels (USArrests) [[1]] # to know how many cities (labels) = 50
> >>>
> >>>
> >>> > require(graphics); require(utils)
> >>> >
> >>> > hc <- hclust(dist(USArrests), "ave")
> >>> > plot(dend1)
> >>> Error in plot(dend1) : object 'dend1' not found
> >>>
> >>> What's dend1?
> >>>
> >>> > nP <- list(col=3:2, cex=c(2.0, 0.75), pch= 21:22,
> >>> >   bg= c("light blue", "pink"),
> >>> >   lab.cex = 0.75, lab.col = 1:50) # or use a palette:
> >>> > palette(rainbow(50))
> >>> >
> >>> > plot(dend1, edgePar=nP, dLeaf=1, edge.root = TRUE)
> >>> >
> >>> > # this option is not correct. I want each of my labels (text) have a
> >>> > different colour but that is not what is happening. How can I do
> that?
> >>> >
> >>> > I'd appreciate your help.
> >>> > thanks a lot
> >>> > Barbara
> >>> >
> >>>
> >>>
> >>> --
> >>> Sarah Goslee
> >>> http://www.functionaldiversity.org
> >>
> >>
> >
>

[[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] Please sign me out from the r-help group. Thanks!

2011-12-12 Thread Kaigang Li

[[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] littler: Use for batch processing of data sets: How to pass filename?

2011-12-12 Thread R. Michael Weylandt
Why can't you just replace "temp/data" with filename (no quotes)? I'm not sure 
I get the question...

Michael

On Dec 12, 2011, at 5:26 AM, Paul Menzel  
wrote:

> Dear R folks,
> 
> 
> I have several data sets I want to process automatically using R. I
> found littler [1] and thought this will do the trick.
> 
> 1. Read in data file to a data frame using `scan()`.
> 2. Do linear regression.
> 3. Write the data and the coefficients back to a file.
> 
>#!/usr/bin/env r
> 
>if (is.null(argv) | length(argv)!=1) {
> 
>  cat("Usage: auswertung.r datafile \n")
>  q()
> 
>}
> 
>filename <- as.character(argv[1])
> 
>d = data.frame(x=scan("/tmp/data"))
>write(sum(d$x), "/tmp/data.result", ncolumns=1)
> 
> Could someone help me how I can substitude `/tmp/data` with the value
> stored in `filename`? I do not get it to work using `do.Call` or
> `paste()`.
> 
> 
> Thanks,
> 
> Paul
> 
> 
> [1] http://code.google.com/p/littler/
> 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Bioconductor. MA plot for qPCR array

2011-12-12 Thread R. Michael Weylandt
This question is perhaps best asked on the specialized Bioconductor mailing 
list. The audience there is quite knowledgeable and will certainly be able to 
help. 

Michael

On Dec 11, 2011, at 8:08 AM, ali_protocol  
wrote:

> Dear all,
> 
> Is there anyway too generate MA plot for 2 qPCR assays (an array of 2x 400).
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Bioconductor-MA-plot-for-qPCR-array-tp4182805p4182805.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] not complete character in csv file

2011-12-12 Thread David Winsemius


On Dec 12, 2011, at 7:23 AM, threshold wrote:


Dear R users, I got the following problem. Given that


data[3,2]

[1] "010252"

Code:
intro <- data.frame()
intro[1,1] <- as.character(data[3,2])
write.csv(intro, file='intro.csv')

In 'intro.csv' file I am loosing the 0 in frot of 10252, which I  
need. Is

there a way to keep the full character saved? R 2.13.2 (64 bit).


Let me guess. The way you are looking at the output is with Excel and  
you are bothered by the fact that Excel will drop leading zeros from  
items it can interpret as numbers.


If you  use Excel as a viewer, you get what Excel thinks you should  
get. My attempt to format the range where the data will be loaded as  
"Text", and then load from the CSV file, failed to preserve the  
leading "0" using Excel 2011 (for Mac). That strategy used to work for  
me in prior versions of Excel at least for preventinting from  
converting text to dates, but the MS people seem to have decided to be  
even more "helpful".


--
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] "plinear"

2011-12-12 Thread Liam Brown
I was wondering if there is way to place constraints upon the "plinear" 
algorithm of nls, or rather is there a manner in which this can be achieved 
because nls does not allow this to be done.



I only want to place constraints on one of the nonlinear parameters, a, such 
that it is between 0 and 1. I have attempted to use a=pnorm(a*) , but then the 
fitting procedure becomes overcomplicated and convergence does not occur in 
many cases including ones I know or suspect to be useful. I have not attempted 
other similar functions because I want to see if there is an alternative 
approach although if you have an alternative to pnorm to suggest which is less 
complcated but maps from the real numbers to [0,1] that may be useful.



I have looked at gnm package but this is no more helpful. Any suggestions would 
be welcome. Basically, has the algorithm of Golub and Pereyra even been 
writtten to be applied with constraints in R, anywhere and by anyone? I believe 
it is possible to do so.



Thank you

Liam Brown

[[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/command for creating a table of panel models ?

2011-12-12 Thread ManuelS
Thank you! I'm going to look into that straight away.

Manu

--
View this message in context: 
http://r.789695.n4.nabble.com/Package-command-for-creating-a-table-of-panel-models-tp4185744p4186077.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] shorter way of coding

2011-12-12 Thread Petr PIKAL
Hi
> 
> Dear R users, 
> 
> I am using the code below to generate a fitted value of b. I have about 
> 300 different values for for y (y1, y2, ...y300) which means I will have 

> to write the code below 300 times to generate the 300 different fitted 
> values for y. Is there a short way of doing that ?

With lm you can use several dependent variables to get result, but I do 
not know if it works with gam.

You can put y1 - y300 to list and than use lapply or for cycle to do the 
analysis and store results in a list (list.y).

something like (untested)

for (i in 1:300) {

b[i] <- gam(list.y[i]~s(x1,x2, k=100, data=dat)

}

Regards
Petr



> 
> Many thanks in advance
> Mintewab 
> 
> library(mgcv)
> dat <- read.table("e:/minti's laptop/C/GBG/allround_survey/
> rainfallGPS.csv", header=T, sep=",") 
> b<-gam(y1~s(x1, x2, k=100),data=dat)
> vis.gam(b)
> fitted(b)
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] i can't read large NETCDF file like CRU

2011-12-12 Thread Paul Hiemstra
On 12/12/2011 10:19 AM, tony333 wrote:
> i use library(ncdf) to read this file as follow 
> library(ncdf)
> sst.nc = open.ncdf(title)
> lonall = get.var.ncdf(sst.nc,'lon')
> latall = get.var.ncdf(sst.nc,'lat')
> precip = get.var.ncdf(sst.nc,'pre')
> close(sst.nc)
> if i use this method my pc freeze and not respond until i restart it is
> there 
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/i-can-t-read-large-NETCDF-file-like-CRU-tp4185435p4185435.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.

Hi Tony,

We are sympathetic to your cause, but without more information helping
you is really hard. Please consult the posting guide:

PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

for some more hints.

regards,
Paul

ps This question might be more suitable for R-sig-geo
ps2 You could use the raster package to analyse the data on the harddrive (not 
reading all data in from disk)



-- 
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770

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


Re: [R] Script analysing

2011-12-12 Thread Paul Hiemstra
On 12/12/2011 10:39 AM, Alexander wrote:
> Hello,
> I am trying to write a script to analyse R scripts, which contain only
> functions. Therefor, I want to test the R script if it contains onyl correct
> code. Is there a nicer and more efficent function than
>
> test <- try(source("someRscript"))
> if(class(test) == "try-error"){
> print("Not executable")
> }
>
> ?
>
> Another question : Does a package exist to analyse functions? For example to
> get all defined function names, argument, nestings, etc...
> Does a package exists which creates a flowchart of a script which contains a
> sequel of functions?
>
> Thank you
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Script-analysing-tp4185492p4185492.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.

...which is one of the first hits on google when googling for "R analyse
code".

Paul

-- 
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770

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


Re: [R] not complete character in csv file

2011-12-12 Thread Jean V Adams
threshold wrote on 12/12/2011 06:23:33 AM:

> Dear R users, I got the following problem. Given that
> 
> > data[3,2]
> [1] "010252"
> 
> Code:
> intro <- data.frame()
> intro[1,1] <- as.character(data[3,2])
> write.csv(intro, file='intro.csv')
> 
> In 'intro.csv' file I am loosing the 0 in frot of 10252, which I need. 
Is
> there a way to keep the full character saved? R 2.13.2 (64 bit).
> 
> Thanks, robert


When I submit similar code (below), the csv file keeps the 0 in front of 
the 10252.
intro <- data.frame()
intro[1,1] <- "010252"
write.csv(intro, file='intro.csv')
Have you tried viewing the csv file with a text editor (e.g., Notepad)? If 
you view the csv file in spreadsheet software (e.g., Excel) it may format 
the values as numbers automatically.

Jean
[[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] Script analysing

2011-12-12 Thread Paul Hiemstra
On 12/12/2011 10:39 AM, Alexander wrote:
> Hello,
> I am trying to write a script to analyse R scripts, which contain only
> functions. Therefor, I want to test the R script if it contains onyl correct
> code. Is there a nicer and more efficent function than
>
> test <- try(source("someRscript"))
> if(class(test) == "try-error"){
> print("Not executable")
> }
>
> ?
>
> Another question : Does a package exist to analyse functions? For example to
> get all defined function names, argument, nestings, etc...
> Does a package exists which creates a flowchart of a script which contains a
> sequel of functions?
>
> Thank you
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Script-analysing-tp4185492p4185492.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.

Hi,

The codetools package comes to mind.

cheers,
Paul

-- 
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770

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


Re: [R] shorter way of coding

2011-12-12 Thread Paul Hiemstra
On 12/12/2011 01:16 PM, Mintewab Bezabih wrote:
> Dear R users, 
>
> I am using the code below to generate a fitted value of b. I have about 300 
> different values for for y (y1, y2, ...y300) which means I will have to write 
> the code below 300 times to generate the 300 different fitted values for y. 
> Is there a short way of doing that ?
>
> Many thanks in advance
> Mintewab 
>
> library(mgcv)
> dat <- read.table("e:/minti's laptop/C/GBG/allround_survey/rainfallGPS.csv", 
> header=T, sep=",") 
> b<-gam(y1~s(x1, x2, k=100),data=dat)
> vis.gam(b)
> fitted(b)
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Hi Mintewab,

Something along these lines should work:

listOfForumlas = paste(1:300, "~s(x1, x2, k=100)")
listofResults = lapply(listOfForumlas, function(f) {
b<-gam(as.formula(f),data=dat)
vis.gam(b)
fitted(b)
  })

But as Sarah already commented, without a reproducible piece of example
code we cannot present any working solutions.

cheers,
Paul

-- 
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770

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


Re: [R] shorter way of coding

2011-12-12 Thread Sarah Goslee
This isn't a reproducible example, so I can't provide code,
but I would put all the y variables in a list and use lapply().

Sarah

On Mon, Dec 12, 2011 at 8:16 AM, Mintewab Bezabih
 wrote:
> Dear R users,
>
> I am using the code below to generate a fitted value of b. I have about 300 
> different values for for y (y1, y2, ...y300) which means I will have to write 
> the code below 300 times to generate the 300 different fitted values for y. 
> Is there a short way of doing that ?
>
> Many thanks in advance
> Mintewab
>
> library(mgcv)
> dat <- read.table("e:/minti's laptop/C/GBG/allround_survey/rainfallGPS.csv", 
> header=T, sep=",")
> b<-gam(y1~s(x1, x2, k=100),data=dat)
> vis.gam(b)
> fitted(b)

-- 
Sarah Goslee
http://www.functionaldiversity.org

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


Re: [R] prop.test() and the simultaneous confidence interval for multiple proportions in R

2011-12-12 Thread Jean V Adams
?prop.test
The very first line in the help file on the function prop.test():
"prop.test can be used for testing the null that the proportions 
(probabilities of success) in several groups are the same ..."

How to interpret the results of the prop.test() you ran?  The proportion 
preferring Condition 1 with stimulus A was 75%, that with B was 83%, and 
that with C was 67%.  Are these three proportions the same?  No, X2_2 = 
0.89, P = 0.64.

A search on-line yielded some "R code to find simultaneous confidence 
intervals for binomial proportions" based on Agresti et al. (2008). 
Perhaps you would find that useful.
http://www.stat.ufl.edu/~aa/cda/R/multcomp/ryu-simultaneous.pdf

Jean


angelo.arc...@virgilio.it wrote on 12/08/2011 03:58:38 PM:

> Dear list members,
> I want to perform in R the analysis "simultaneous confidence 
> interval for multiple proportions", as illustrated in the article of
> Agresti et al. (2008) "Simultaneous confidence intervals for 
> comparing binomial parameter", Biometrics 64, 1270-1275.
> 
> If I am not wrong the R function implementing the Agresti et al. 
> method is prop.test(). I ask an help because I have some 
> difficulties in reading the output of that function.
> 
> As a case study, I need to apply such analysis on the following 
> simple prolbem:
> 
> I did an experiment in which 12 participants had to choose between 3
> conditions when provided with 3 stimuli.
> 
> Stimulus  Condition1  Condition2 Condition 3
> A9  1  2
> B   10  2  0
> C8  2  2
> 
> My goal is to prove that it is not by chance that Condition 1 is 
> preferred rather than the other two conditions.
> 
> So, I apply the function prop.test(), summing the values of 
> Conditions 2 and 3):
> 
> table<-matrix(c(9,3,10,2,8,4),ncol=2,byrow=T)
> rownames(table)<-c("stimulusA","stimulusB","stimulusC")
> colnames(table)<-c("Condition1","Conditions2and3")
> 
> > table
>   Condition1 Conditions2and3
> stimulusA  9   3
> stimulusB 10   2
> stimulusC  8   4
> 
> 
> prop.test(table)
> 
> > prop.test(table)
> 
> 3-sample test for equality of proportions without continuity 
correction
> 
> data:  table 
> X-squared = 0.8889, df = 2, p-value = 0.6412
> alternative hypothesis: two.sided 
> sample estimates:
>prop 1prop 2prop 3 
> 0.750 0.833 0.667 
> 
> Warning message:
> In prop.test(table) : Chi-squared approximation may be incorrect
> 
> I don't understand where I can deduct that Condition1 is more 
> preferred than Conditions 2 and 3. 
> Should I simply look at the p-value?
> 
> The fact is that  tried with a more extreme example, but the p-value
> results still above 0.05:
> This is the table I used:
> 
> > table2
>   Condition1 Condition2
> stimulusA 12  0
> stimulusB 10  2
> stimulusC 11  1
> 
> > table2<-matrix(c(12,0,10,2,11,1),ncol=2,byrow=T)
> > rownames(table2)<-c("stimulusA","stimulusB","stimulusC")
> >  colnames(table2)<-c("Condition1","Condition2")
> >  prop.test(table2)
> 
> 3-sample test for equality of proportions without continuity 
correction
> 
> data:  table2 
> X-squared = 2.1818, df = 2, p-value = 0.3359
> alternative hypothesis: two.sided 
> sample estimates:
>prop 1prop 2prop 3 
> 1.000 0.833 0.917 
> 
> Warning message:
> In prop.test(table2) : Chi-squared approximation may be incorrect
> 
> 
> 
> Could you please enlighten me?
> 
> 
> Thanks in advance
[[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] shorter way of coding

2011-12-12 Thread Mintewab Bezabih
Dear R users, 

I am using the code below to generate a fitted value of b. I have about 300 
different values for for y (y1, y2, ...y300) which means I will have to write 
the code below 300 times to generate the 300 different fitted values for y. Is 
there a short way of doing that ?

Many thanks in advance
Mintewab 

library(mgcv)
dat <- read.table("e:/minti's laptop/C/GBG/allround_survey/rainfallGPS.csv", 
header=T, sep=",") 
b<-gam(y1~s(x1, x2, k=100),data=dat)
vis.gam(b)
fitted(b)
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Dividing rows when time is overlapping

2011-12-12 Thread Jean V Adams
PEL wrote on 12/07/2011 02:37:42 PM:

> Hi all,
> 
> I have dataframe that was created from the fusion of two dataframes. 
Both
> spanned over the same time intervall but contained different 
information.
> When I put them together, the info overlapped since there is no holes in 
the
> time interval of one of the dataframe. Here is an example where the rows
> "sp=A and B" are part of a first df and the rows "sp=C" come from a 
second.
> The first dataframe is continuous but the second consists of sporadic
> events. The final dataframe looks like this: 
> 
> start   end sp
> 2010-06-01 17:00:002010-06-01 19:30:00 A
> 2010-06-01 19:30:012010-06-01 20:00:00 B
> 2010-06-01 19:45:002010-06-01 19:55:00 C
> 2010-06-01 20:00:012010-06-01 20:30:00 A
> 2010-06-01 20:05:002010-06-01 20:10:00 C
> 2010-06-01 20:12:002010-06-01 20:15:00 C
> 2010-06-01 20:30:012010-06-01 20:40:00 B
> 2010-06-01 20:35:002010-06-01 20:40:10 C
> 2010-06-01 20:40:012010-06-01 20:50:00 A
> 
> I would like to prioritize "C" so when it overlaps the time interval of
> another "sp", the time interval of "A" or "B" is cut accordingly. As 
seen in
> the example, I sometimes have multiple events of "C" that overlap a 
single
> event of "A" or "B". The result would be this:
> 
> start   end sp
> 2010-06-01 17:00:002010-06-01 19:30:00 A
> 2010-06-01 19:30:012010-06-01 19:44:59 B
> 2010-06-01 19:45:002010-06-01 19:55:00 C
> 2010-06-01 19:55:012010-06-01 20:00:00 B
> 2010-06-01 20:00:012010-06-01 20:04:59 A
> 2010-06-01 20:05:002010-06-01 20:10:00 C
> 2010-06-01 20:10:012010-06-01 20:11:59 A
> 2010-06-01 20:12:002010-06-01 20:15:00 C
> 2010-06-01 20:15:012010-06-01 20:30:00 A
> 2010-06-01 20:30:012010-06-01 20:34:59 B
> 2010-06-01 20:35:002010-06-01 20:40:10 C
> 2010-06-01 20:40:112010-06-01 20:50:00 A
> 
> My date/time columns are in POSIXct. Don't hesitate to ask if something 
is
> unclear.
> 
> Thanks in advance


The code below isn't pretty, but it works, at least on the example you 
provided.

It's helpful to provide your example data as working code, for example 
using the function dput().

Jean


df1 <- structure(list(start = structure(c(1275429600, 1275438601, 
1275439500, 
1275440401, 1275440700, 1275441120, 1275442201, 1275442500, 1275442801), 
class = c("POSIXct", "POSIXt")), end = structure(c(1275438600, 1275440400, 

1275440100, 1275442200, 1275441000, 1275441300, 1275442800, 1275442810, 
1275443400), class = c("POSIXct", "POSIXt")), sp = c("A", 
"B", "C", "A", "C", "C", "B", "C", "A")), .Names = c("start", 
"end", "sp"), row.names = c(NA, -9L), class = "data.frame")

# rearrange data so that all of the times are in one column
len1 <- dim(df1)[1] 
df2 <- data.frame(time=c(df1$start, df1$end), point=rep(c("start", "end"), 
c(len1, len1)), letter=c(df1$sp, df1$sp))
df2 <- df2[order(df2$time), ]

# create a new variable that indicates what long-segment (A or B) other 
sub-segments (C) are in
len2 <- dim(df2)[1]
df2$within <- df2$letter
last <- df2$letter[1]
for(i in 2:len2) if(df2$letter[i]=="C") df2$within[i] <- last else last <- 
df2$letter[i]

# for every sub-segment start, add a new long-segment end 1-second before 
it
newABends <- df2[df2$point=="start" & df2$letter=="C", ]
newABends$time <- newABends$time - 1
newABends$point <- "end"
newABends$letter <- newABends$within

# for every sub-segment end, add a new long-segment start 1-second after 
it
newABstarts <- df2[df2$point=="end" & df2$letter=="C", ]
newABstarts$time <- newABstarts$time + 1
newABstarts$point <- "start"
newABstarts$letter <- newABstarts$within

# combine the original data with the new long-segment starts and ends
df3 <- rbind(df2, newABends, newABstarts)
df3 <- df3[order(df3$time), ]

# get rid of any long-segment bits within sub-segments
len3 <- dim(df3)[1]
startC <- seq(from=len3)[df3$point=="start" & df3$letter=="C"]
endC <- seq(from=len3)[df3$point=="end" & df3$letter=="C"]
startendC <- lapply(seq(along=startC), function(i) seq(startC[i], 
endC[i]))
remove.rows <- unlist(lapply(startendC, function(x) x[-c(1, length(x))]))
df4 <- df3[-remove.rows, ]

# rearrange data so that start and end times are in different columns
df4s <- df4[df4$point=="start", c("time")]
df4e <- df4[df4$point=="end", c("time", "letter")]
names(df4s) <- c("start")
names(df4e) <- c("end", "letter")
cbind(df4s, df4e)
[[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] not complete character in csv file

2011-12-12 Thread threshold
Dear R users, I got the following problem. Given that

> data[3,2]
[1] "010252"

Code:
intro <- data.frame()
intro[1,1] <- as.character(data[3,2])
write.csv(intro, file='intro.csv')

In 'intro.csv' file I am loosing the 0 in frot of 10252, which I need. Is
there a way to keep the full character saved? R 2.13.2 (64 bit).

Thanks, robert



--
View this message in context: 
http://r.789695.n4.nabble.com/not-complete-character-in-csv-file-tp4185785p4185785.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] round Date object to 10 minutes intervals?

2011-12-12 Thread kmay
Dear Mr. Ripley,

your answer perfectly fits my needs, thank you very much.
(And yes, rounding 5 to even is what I wanted).


Prof Brian Ripley wrote
> 
> t2 <- strptime(timeStamp, format="%d.%m.%Y %H:%M")
> t2$min <- round(t2$min, -1)
>> format(t2, "%d.%m.%Y %H:%M")
> [1] "31.03.2011 09:30" "31.03.2011 09:40" "31.03.2011 10:00" "31.03.2011
> 10:10"
> [5] "31.03.2011 10:30" "31.03.2011 10:40" "31.03.2011 10:50" "01.04.2011
> 00:00"
> 


Prof Brian Ripley wrote
>  
> t2$min <- 10*floor((t2$min + 5)/10)
> t2$min <- 10*floor((t2$min + 4)/10)
> 
This really got me thinking and as a result increased my understanding of
maths & R ,
a big thanks to you  



--
View this message in context: 
http://r.789695.n4.nabble.com/round-Date-object-to-10-minutes-intervals-tp4185496p4185776.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] Colours for sunflowerplot

2011-12-12 Thread Nicola Van Wilgen

Hi Jim,

I think this will work well for what I need it for - thanks a lot!

I would still be interested (for interest sake) if anyone knows how to
get this to work using sunflower plot.

Thanks again,

Nicola

-Original Message-
From: Jim Lemon [mailto:j...@bitwrit.com.au] 
Sent: 12 December 2011 11:18 AM
To: Nicola Van Wilgen
Cc: r-help@r-project.org; victo...@saeon.ac.za
Subject: Re: [R] Colours for sunflowerplot

On 12/12/2011 06:00 PM, Nicola Van Wilgen wrote:
> Dear fellow R users,
>
>
>
> I would like to draw a "sunflowerplot" because I have data (decade by
> month) that plots multiple times on the same x-y co-ordinates. Further
I
> would like to colour each of the points/sunflower leaves on the plot
> according to the group they belong to (i.e. which type of event each
> represents within that decade and month). I thought that this would be
> relatively straight forward - I have a series of x and y co-ords and a
> colour associated with each and I just use the column with the colours
> in it to colour-code the points using col = column.name when calling
the
> plot.
>
>
>
> However, the sunflower plot uses the function "xy.coords" to calculate
> the number of times that multiple points are plotted at the same
> coordinates and in so doing creates a new dataset (x.coords, y.coords
> and the number of times each is repeated) and this dataset no longer
has
> the colours associated with the individual points. The colours in a
> resultant plot merely plot in the original order.
>
>
>
> I would like to know whether there is a way of associating the correct
> colours with individual points that are now represented by the
xy.coords
> output.
>
Hi Nicola,
I couldn't figure out a way to make sunflowerplot use the original 
colors, but this might help you:

extremes.decade<-
  read.csv("extremes_decade.csv",stringsAsFactors=FALSE)
library(plotrix)
extreme.clusters<-
  cluster.overplot(extremes.decade$Decade,extremes.decade$Month,
  col=extremes.decade$Extreme)
plot(extreme.clusters,col=extreme.clusters$col)

Jim


This e-mail communication and any attachments are confidential and are intended 
only for the individual(s) or entity named above and others who have been
specifically authorized to receive it. If you are not the intended recipient, 
please do not copy, use or disclose the contents of this communication to 
others. 
Please notify the sender that you have received this email in error by replying 
to the e-mail or by telephoning the sender. Please then delete the e-mail and 
any copies of it. This information may contain private, confidential or 
privileged material. 
Thank you. 


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


[R] calculating logit parameters (odd ratio is exactly one or zero)

2011-12-12 Thread wim nursal
Dear statistician experts,

Sorry if this is a trivial question, or the old same question (i don't know
what is the efficient key word for this issue).
In order to understand the calculation of parameter of logistic regression,
 I did an exercise through spreadsheet following the procedural example
from a literature, or the available spreadsheet (with calculation formula).
I ended up with infinity (divided by zero) when the odd ratio is exactly 1
(FD=12) or invalid number when odd ratio is zero (MFD = 0) after log.
I am wondering  how R through GLM function (particularly logit or logistic
regression) treats the odds ratios or log odd ratios that is exatcly one or
zeros.

The sample data is like this:
#HH Fsize FD
1 1.29472 0
2 1.6184 0
3 2.4276 1
4 2.4276 2
5 20.23 2
6 1.6184 3
7 1.820 3
8 0.4046 3
9 6.069 4
10 2.6299 4
11 0.72828 5
12 2.4276 5
13 6.069 7
14 4.8552 7
15 2.32645 7
16 1.6184 8
17 1.0115 8
18 1.0115 8
19 5.2598 9
20 2.023 10
21 0.6069 10
22 1.2138 11
23 0.8092 11
24 1.4161 11
25 0.6069 11
26 3.440 11
27 1.2138 12
28 1.2138 12
29 0.4046 12
30 1.2138 12

Fsize is the farm size (acre or hectare).  Food deficit (FD) is the number
of months (last year from the survey took place) that an household had
bought food-grains (minimum = 0 month, maximum = 12 months or whole year
deficit).
Even though I "jitter"-ed the minimum or maximum FD value only (eg.
FD=0+1e-6 or FD=12-1e-6), nothing changed to the result.

The formula I used is like this:
--
glm(FD ~ Fsize, data = subFS)
--
Coefficients:
(Intercept)Fsize
 7.7913  -0.3092

Degrees of Freedom: 29 Total (i.e. Null);  28 Residual
Null Deviance:  463
Residual Deviance: 425.5AIC: 170.7
--

I appreciate for any clarification.

Best wishes,
Wim

[[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] Rsolnp package: warning messages

2011-12-12 Thread Diogo Alagador


Dear,

I am using the solnp command (package Rsolnp) for a problem with  
equality and inequality constraints.
I am not getting convergence for my problem but apart that I get 1  
warning per iteration saying: ?In cbind(temp, funv) :  number of rows  
of result is not a multiple of vector length (arg 1)?.
I checked for equality and inequality functions and they seem fine to  
me. Where this message comes from?


Interestingly also is that using different seed values the direction  
of optimization of my (negative-value) function is always for  
maximization. How can this occur?


Below you may find the code for ease of consultation.

Thanks in advance,
My best regards,

Diogo André Alagador
Univ. Évora, Portugal



## the code:
###
###
## DATA

N=7
BR=12
br=c(1,1,2,3,2,1,1,2,1,1,1,1)

A=c(1,0,0,0,1,0,0,0,0)
B=c(0,0,0,0,1,0,0,0,0)
C=c(1,1,0,1,0,0,1,0,0)
D=c(0,1,0,0,1,0,0,0,0)
E=c(0,0,1,0,0,0,0,0,0)
F=c(0,0,1,0,1,0,1,0,0)
G=c(0,1,1,0,0,0,0,0,0)
H=c(2,1,0,1,2,0,1,0,0)
I=c(0,2,3,0,2,0,1,0,0)
J=c(0,1,3,0,1,0,1,0,0)
K=c(0,1,2,0,1,0,1,0,0)
L=c(1,0,0,0,2,0,0,0,0)

mat=rbind(A,B,C,D,E,F,G,H,I,J,K,L)

CELL=dim(mat)[2]

###
###
## MAX FUNCTION

budget=2

library(Rsolnp)

# the objective function to maximize
#NOTE: by default the solver minimizes the objective. therefore the  
original minus sign is not used


obj=function(x){
all1=sum(mat%*%x)
Hp=0
for (j in 1:BR){
p_b=mat[j,]%*%x/all1
Hp=Hp+p_b*log(p_b)*br[j]
}
return(Hp)
}

# the equality constraint function:

equal1=function(x){
all2=sum(mat%*%x)

sum_pterm=sum(mat[1:N,]%*%x/all2)
sum_x=sum(x)

return(c(sum_pterm,sum_x))
}

# the right hand side for the constraint
eqB=c(1,budget)


# the inequality function
inequal1=function(x){
all3=sum(mat%*%x)
p_b=mat[1:BR,]%*%x/all3
return(as.vector(p_b))
}

#the lower limit for inequalities
ineqLB=rep(0.1,BR)

#the upper limit for the inequalities
ineqUB=rep(1.1,BR)


# the lower and upper bounds for the variables
LB=rep(0,CELL)
UB=rep(1,CELL)

#the seed for variables
cells0=rep(.3,9)

#solving the problem
sol=solnp(cells0,fun=obj,eqfun=equal1,eqB=eqB,ineqfun  
=inequal1,ineqLB=ineqLB,ineqUB=ineqUB,LB=LB,UB=UB,control=list(outer.iter=400))

cells=sol$pars
cells
equal1(cells)

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


Re: [R] color2D.maplot fixed color range

2011-12-12 Thread David Winsemius


On Dec 11, 2011, at 10:19 PM, jalfaro wrote:


Hello,
Were you ever able to find a solution to your problem?
I have been trying on and off to solve this problem for several  
months now.

I would love to hear if you found a solution.


Neither the person who posted the problem a year ago or you have  
provided a workable example. It seems to me that using findInterval to  
construct an index into the colcolors vector might work but without an  
example on which to test I won't know for sure. Rather than working on  
this "for months" why not following the Posting Guide?


--

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.


  1   2   >