Re: [R] [ how can sample from f(x)~x^(a-1)

2009-12-26 Thread GlenB


khazaei said:
> how can sample from f(x)~x^(a-1)*ind(0,min(b,-log(u)) in R?
> where a and b is positive constand and   0http://n4.nabble.com/how-can-sample-from-f-x-x-a-1-tp978822p979342.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] Is SEM package of R suitable for sem analysis

2009-12-26 Thread Wincent
Besides sem package, OpenMx (http://openmx.psyc.virginia.edu/) is
another option for R users.

Best

2009/12/27 Joe King :
> I am going to take SEM this next quarter in my doctoral program. My
> suggestion is to use the program your professor suggests and try to
> re-create your models in R using the SEM package. We are not going to use
> AMOS though we use EQS, and another prof on campus who teaches it in a
> different department uses LISREL, so since SEM hasn't been implemented in
> most commercial software and you need specialty software for it, it may be
> best to know several different software programs if you want to do SEM type
> work. I do have a feeling since R is growing so rapidly it wont take time
> for people in the community to create packages or develop existing packages
> equal to or greater than commercial software! LONG LIVE R :)
>
> Joe King
> 206-913-2912
> j...@joepking.com
> "Never throughout history has a man who lived a life of ease left a name
> worth remembering." --Theodore Roosevelt
>
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf Of Reeyarn_???_10928113
> Sent: Saturday, December 26, 2009 3:50 AM
> To: R-help@r-project.org
> Subject: [R] Is SEM package of R suitable for sem analysis
>
> Dears,
>
> I'm a college student and In doing my statistics homework.
>
> I use R with SEM package as my tool for sem analysis,
> but my teacher told me AMOS is more suitable for such analysis.
>
> Could someone help tell me whether it is true
> that some commercial software is better accepted in academic fields?
>
> Sorry if I should not post such topics here.
>
> --
> Best Regards,
> Reeyarn T. Lee
>
> Accounting Dept, Guanghua School of Management,
> Peking University, Beijing, P.R. China
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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.
>



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

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


Re: [R] How to manipulate tables

2009-12-26 Thread David Winsemius


On Dec 26, 2009, at 4:56 PM, James Rome wrote:


Thanks David.

I wanted to calculate the Poisson distribution from my histograms to  
see

how closely they match it. So the formula is something like
pprob=((lambda**cnts)/factorial(cnts))*exp(lambda)


(Please don't reply privately.)

You have two vectors of different lengths, the lambdas and the counts,  
and you need to create the 2-way combinations in a form that can be  
supplied to a function.



And I was hoping to do it for the whole table at once.


Something like this?

> lambdas <-scan()   # scan can read a sequence of numbers separated  
by white space.


1: 0.199190283 0.013765182 0.006477733 0.017813765 0.093117409  
0.160323887

7: 0.401619433
8:
Read 7 items

> ldf <- expand.grid(lambdas, 1:15)
> str(ldf)
'data.frame':   105 obs. of  2 variables:
$ Var1: num  0.19919 0.01377 0.00648 0.01781 0.09312 ...
$ Var2: int  1 1 1 1 1 1 1 2 2 2 ...
- attr(*, "out.attrs")=List of 2
 ..$ dim : int  7 15
 ..$ dimnames:List of 2
 .. ..$ Var1: chr  "Var1=0.199190283" "Var1=0.013765182"  
"Var1=0.006477733" "Var1=0.017813765" ...

 .. ..$ Var2: chr  "Var2= 1" "Var2= 2" "Var2= 3" "Var2= 4" ...

> ldf$countprob <- (ldf$Var1**ldf$Var2)/ factorial(ldf$Var2)*exp(ldf 
$Var1)

> ldf
  Var1 Var2 countprob
1   0.1991902831 2.430946e-01
2   0.0137651821 1.395597e-02
3   0.0064777331 6.519830e-03
4   0.0178137651 1.813394e-02
snipped remaining 100 lines...

--
David


Jim Rome

On 12/26/09 2:28 PM, David Winsemius wrote:


On Dec 26, 2009, at 2:02 PM, James Rome wrote:


I am sorry to be bothering the list so much.

I made a table of counts of flight arrivals by hour:


No, you made a list of tables, which is different.

cnts=tapply(Arrival4,list(Hour),table). There are up to 15  
arrivals in a

bin.


Why not work with something more regular, like (this is all guesswork
and untested in absence of test data objects):

table(Arrival4, factor(Hour, levels=1:15)  )?
# or use whatever your max(arrivals) might be.


xx <- factor(sample(1:10, 4))
xx

[1] 9 4 7 1
Levels: 1 4 7 9


table(factor(xx, levels=1:10) )


1  2  3  4  5  6  7  8  9 10
1  0  0  1  0  0  1  0  1  0



cnts


$`0`

1  2  3  4  5  6  7  8  9 10 13
1  2  5  9  2  7  5  4  2  4  1

$`1`

1 2 3 4
3 2 2 1

$`2`

1 3
2 2
.  . .

My first problem is how to get this table filled in with the 0  
slots.

E.g., I want
$`0`

1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
1  2  5  9  2  7  5  4  2  4   0   0   1   0   0

for all 24 hours. The elements of the tables are lists, but I do not
seem to be able to extract the names of each list, which I think  
would

allow this manipulation.

My second problem is that I want to compute probability  
distributions. I

have
lambda
0   1   2   4   5
6   7
0.199190283 0.013765182 0.006477733 0.017813765 0.093117409  
0.160323887

0.401619433
8   9  10  11  12
13  14
0.191093117 0.177327935 0.318218623 0.404858300 0.463157895  
0.495546559

0.435627530
   15  16  17  18  19
20  21
0.418623482 0.307692308 0.405668016 0.484210526 0.580566802  
0.585425101

0.519028340
   22  23
0.556275304 0.503643725

and I need to calculate lambda**cnts for each bin, and each hour.  
I am

also unsure of how to do this.


Can you give a justification for this procedure? (I'm not saying it  
is

nonsense, only that it does not make make sense to me. So perhaps
there is some mathematical property about which I need education.)



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] Is SEM package of R suitable for sem analysis

2009-12-26 Thread Joe King
Your welcome, I wanted to say I agree with Bruno that the comparative
software is very expensive, even more prohibitively so for students and even
though MPlus is good I think R will catch up rapidly and even overtake those
as people who use these modeling techniques become more integrated into the
R community.

Joe King
206-913-2912
j...@joepking.com
"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Reeyarn_???_10928113
Sent: Saturday, December 26, 2009 6:27 PM
To: R-help@r-project.org
Subject: Re: [R] Is SEM package of R suitable for sem analysis

Dear Bruno and Joe,

Thanks for advising!


Reeyarn

On Sat, Dec 26, 2009 at 9:32 PM, Bruno Falissard 
wrote:

> A few years ago it could have been true, but now the package has improved
> (especially with the bootstrap procedure).
> At the moment there is no argument to recommend AMOS.

On Sun, Dec 27, 2009 at 12:30 AM, Joe King  wrote:

> I am going to take SEM this next quarter in my doctoral program. My
> suggestion is to use the program your professor suggests and try to
> re-create your models in R using the SEM package.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Multiple CHOLMOD errors when attempting poisson glmm

2009-12-26 Thread Gabor Grothendieck
On Sat, Dec 26, 2009 at 1:21 PM, Marielle Postava-Davig
 wrote:
> I was actually curious if there was another version of lme4 I could use.

You could try glmmPQL in the MASS package.

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


Re: [R] Is SEM package of R suitable for sem analysis

2009-12-26 Thread Reeyarn_李智洋_10928113
Dear Bruno and Joe,

Thanks for advising!


Reeyarn

On Sat, Dec 26, 2009 at 9:32 PM, Bruno Falissard  wrote:

> A few years ago it could have been true, but now the package has improved
> (especially with the bootstrap procedure).
> At the moment there is no argument to recommend AMOS.

On Sun, Dec 27, 2009 at 12:30 AM, Joe King  wrote:

> I am going to take SEM this next quarter in my doctoral program. My
> suggestion is to use the program your professor suggests and try to
> re-create your models in R using the SEM package.

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


Re: [R] Is there a problem with lattice axes?

2009-12-26 Thread Ted Harding
OK, I take it all back" (See original below). I had overlooked

A: That the Y Label for the histograms I drew was
   "Percent of Total", and that there is a parameter 'type
   for which type="percent" is the default.

B: That the histograms I used as an example had N=100 for
   the case with largest N, so in that case the percentages
   were the same as the counts, and hence not diagnostic.

The proper solution (giving rise to the outcome "A:" which
I describe at the end) is to use type="count".

Apologies for the noise!
Ted.

On 26-Dec-09 22:03:48, Ted Harding wrote:
> Thanks, Dennis, that does it! And, now that you have pointed
> it out, I finally found that particular case lurking deep in
> "?xyplot".
> 
> This still leaves the question: When the (default) "same" is
> used, why does histogram() plot the bar-heights as if "free"
> had been used? The result is that all but one of the histograms
> would be read on the wrong scale. If that were the information
> one supplied to someone else, to represent count data, without
> indicating that this was happening, then the reader would be
> misled about the numbers.
> 
> Ted.
> [copying my reply above to a private response also to the list]
> 
> On 26-Dec-09 20:38:28, Dennis Murphy wrote:
>> scales = free, perhaps?
>> 
>> On Sat, Dec 26, 2009 at 12:07 PM, Ted Harding
>> wrote:
>> 
>>> After answering a previous post by James Rome:
>>> "Re: [R] Why do histogram bars vary their width?"
>>>
>>> I noticed that the lateral axis scales in the lattice histogram
>>> which I used for illustration are inconsistent with the frequencies.
>>> The example was:
>>>
>>> set.seed(54321)
>>>  X <- c(rnorm(100),rnorm(50,1.0,0.5),rnorm(25,-1.0,0.5),rnorm(10))
>>>  F <- factor(c(rep(0,100),rep(1,50),rep(2,25),rep(3,10)))
>>> # The default:
>>>  histogram(~X | F)
>>> # Your choice (number of breaks)
>>>  histogram(~X | F, breaks=10)
>>> # Explicit specification of break-points:
>>>  histogram(~X | F, breaks=0.5*(-6:6))
>>>
>>> In the third of these, you will see that the frequency scales are
>>> marked at marked at 0,10,20,30,40,50 throughout. This is appropriate
>>> for the bottom-left histogram (Level of F=0, N=100), and the
>>> displayed frequencies do indeed (by eye) seem to add up to 100.
>>> It is certainly not right for the top-right histogram (F=3,N=10),
>>> where the displayed scale needs to be 0,1,2,3 (giving 1+3+5+1=10),
>>> i.e. divided by 10; but at least this one is readily re-scalable
>>> "by eye". However, it is neither right nor readily re-scalable
>>> for the other two:
>>>
>>>  F=1, N=50, apparent sum = 2+10+44+22+18+4=100
>>>  F=2, N=25, apparent sum = 8+32+48+12 =100
>>>
>>> Clearly, while in principle it would be possible to have
>>>  A: an axis lower-left  (F=0,N=100) scaled 0,10,  20,  30,  40,  50
>>>  B: an axis lower-right (F=1,N= 50) scaled 0, 5,  10,  15,  20,  25
>>>  C: an axis upper-left  (F=2,N= 25) scaled 0, 2.5, 5.0, 7.5,10.0,12.5
>>>  D: an axis upper-right (F=3,N= 10) scaled 0, 1,   2,   3,   4,   5
>>> in this 2x2 case, it could not work for say a 3x3 lattice.
>>>
>>> The right thing to do when there is a common vertical scale
>>> along a row is to scale each plot itself accordinng to the
>>> vertical scale for the row. Instead, it seems to have chosen
>>> a vertical scale for each histogram as plotted so that the
>>> histiogram bars will nicely fill the panel window in each case,
>>> disregarding the vertical scaling which has been determined
>>> according to the histogram with the largest N.
>>>
>>> Thus one could have a scale 0,10,20,30,40 for the bottom row,
>>> with the lower right-hand histogram bars being half the height
>>> they have as displayed by the above, and either
>>>  A: the same scale for the upper row as for the bottom row,
>>> but with the left-hand histogram bars 1/4 the height
>>> and the right-hand histogram bars 1/10 the height
>>> or
>>>  B: a scale 0,2.5,5.0,7.5,10 with the left-hand histogram
>>> bars just as they are now, and the right-hand histogram
>>> bars 1/2.5 the hright.
>>>
>>> Or maybe there is an option lurking somewhere in the lattice
>>> documentation which looks after this sort of thing -- but I
>>> have not been able to find it despite have spent some time
>>> searching.
>>>
>>> R version 2.10.0 (2009-10-26)
>>> lattice version: 0.17-26 (2009/10/05)
>>>
>>> Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 26-Dec-09   Time: 23:21:27
-- XFMail --

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


Re: [R] Is there a problem with lattice axes?

2009-12-26 Thread Ted Harding
Thanks, Dennis, that does it! And, now that you have pointed
it out, I finally found that particular case lurking deep in
"?xyplot".

This still leaves the question: When the (default) "same" is
used, why does histogram() plot the bar-heights as if "free"
had been used? The result is that all but one of the histograms
would be read on the wrong scale. If that were the information
one supplied to someone else, to represent count data, without
indicating that this was happening, then the reader would be
misled about the numbers.

Ted.
[copying my reply above to a private response also to the list]

On 26-Dec-09 20:38:28, Dennis Murphy wrote:
> scales = free, perhaps?
> 
> On Sat, Dec 26, 2009 at 12:07 PM, Ted Harding
> wrote:
> 
>> After answering a previous post by James Rome:
>> "Re: [R] Why do histogram bars vary their width?"
>>
>> I noticed that the lateral axis scales in the lattice histogram
>> which I used for illustration are inconsistent with the frequencies.
>> The example was:
>>
>> set.seed(54321)
>>  X <- c(rnorm(100),rnorm(50,1.0,0.5),rnorm(25,-1.0,0.5),rnorm(10))
>>  F <- factor(c(rep(0,100),rep(1,50),rep(2,25),rep(3,10)))
>> # The default:
>>  histogram(~X | F)
>> # Your choice (number of breaks)
>>  histogram(~X | F, breaks=10)
>> # Explicit specification of break-points:
>>  histogram(~X | F, breaks=0.5*(-6:6))
>>
>> In the third of these, you will see that the frequency scales are
>> marked at marked at 0,10,20,30,40,50 throughout. This is appropriate
>> for the bottom-left histogram (Level of F=0, N=100), and the
>> displayed frequencies do indeed (by eye) seem to add up to 100.
>> It is certainly not right for the top-right histogram (F=3,N=10),
>> where the displayed scale needs to be 0,1,2,3 (giving 1+3+5+1=10),
>> i.e. divided by 10; but at least this one is readily re-scalable
>> "by eye". However, it is neither right nor readily re-scalable
>> for the other two:
>>
>>  F=1, N=50, apparent sum = 2+10+44+22+18+4=100
>>  F=2, N=25, apparent sum = 8+32+48+12 =100
>>
>> Clearly, while in principle it would be possible to have
>>  A: an axis lower-left  (F=0,N=100) scaled 0,10,  20,  30,  40,  50
>>  B: an axis lower-right (F=1,N= 50) scaled 0, 5,  10,  15,  20,  25
>>  C: an axis upper-left  (F=2,N= 25) scaled 0, 2.5, 5.0, 7.5,10.0,12.5
>>  D: an axis upper-right (F=3,N= 10) scaled 0, 1,   2,   3,   4,   5
>> in this 2x2 case, it could not work for say a 3x3 lattice.
>>
>> The right thing to do when there is a common vertical scale
>> along a row is to scale each plot itself accordinng to the
>> vertical scale for the row. Instead, it seems to have chosen
>> a vertical scale for each histogram as plotted so that the
>> histiogram bars will nicely fill the panel window in each case,
>> disregarding the vertical scaling which has been determined
>> according to the histogram with the largest N.
>>
>> Thus one could have a scale 0,10,20,30,40 for the bottom row,
>> with the lower right-hand histogram bars being half the height
>> they have as displayed by the above, and either
>>  A: the same scale for the upper row as for the bottom row,
>> but with the left-hand histogram bars 1/4 the height
>> and the right-hand histogram bars 1/10 the height
>> or
>>  B: a scale 0,2.5,5.0,7.5,10 with the left-hand histogram
>> bars just as they are now, and the right-hand histogram
>> bars 1/2.5 the hright.
>>
>> Or maybe there is an option lurking somewhere in the lattice
>> documentation which looks after this sort of thing -- but I
>> have not been able to find it despite have spent some time
>> searching.
>>
>> R version 2.10.0 (2009-10-26)
>> lattice version: 0.17-26 (2009/10/05)
>>
>> Ted.
>>
>>
>>
>> 
>> E-Mail: (Ted Harding) 
>> Fax-to-email: +44 (0)870 094 0861
>> Date: 26-Dec-09   Time: 20:07:51
>> -- XFMail --
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 26-Dec-09   Time: 22:03:45
-- XFMail --

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


Re: [R] Question regarding if statement in while loop

2009-12-26 Thread Carl Witthoft


Sounds like what you want is  either   try() or trycatch() -- check out 
the documentation.  Basically, putting your eblest() function inside a 
try() call allows you to return an error message if eblest crashes 
without crashing your main loop.


BTW,  for debugging purposes, I'd recommend creating a simple loop with 
an input some of whose values are guaranteed to cause a problem.  For 
example:


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

i<-1
while(i<=length(xin)){
sqrt(xin[i])
}


Carl



I'm running R version 2.9.2 on a PC.

I'm having a problem with a loop, and have tried using an if statement 
within to fix it, but to no avail.

Any advice would be appreciated.

Here is my code:

eblest <- function(i,dir, sterr, weight, aux) { n <- nrow(dir)
Y <- as.matrix(dir[,i], ncol=1)
sigma2ei <- as.matrix(sterr[,i]^2, ncol=1)
w <- as.matrix((weight[,3])*(sigma2ei), ncol=1)
X <- as.matrix(subset(aux, select=c(3,5:7,9:10,13)))
a <<- EBLUP.area(Y,cbind(w,1),sigma2ei,n)#The EBLUP.area
function is a function already in R.
}

  # It gives a bunch of output, some of what I need.

#THIS IS THE LOOP I'M HAVING A PROBLEM WITH: results <- 
data.frame(length=nrow(dir5)) i <- 3

while (i <=some number) {
eblest(i, dir5, sterr5, weight5, aux5)
out <<- cbind(i, a$EBLUP, a$mse)
results <- cbind(results, out)
i <- i+1
}

I have tried running the eblest function for a specific set of input (i, 
dir5, etc as in the function) This function runs ok. However, sometimes 
eblest does not create the expected output, sometimes due to the 
solution being singular or other reasons. I'm not so concerned about 
that at this point - it's a function of the data.


My problem is that, as you can see, after eblest runs, the "out" pieces 
of information are bound together in the results matrix. When the eblest 
does not run correctly, the loop stops.  For example, when i=3 and i=4, 
eblest runs ok, and I get a maxtrix with the following columns:


i EBLUP se.EBLUP i EBLUP se.EBLUP
3   xy4abh


...but when it loops back around to start i=5, I get an error because 
the solution is singular. But I don't want the loop to stop (I have ~100 
of these i's for which I need to execute this function.


So I would like to set an if condition that will cause the loop to step 
ahead (in this case, to 6), and continue looping...Something like "if 
exists("out")=FALSE next, else..." However, when I tried that, the 
results matrix was empty created at all.


In case it helps, "out" has a "numeric" mode, and is a "matrix"...

I've written these functions and loops using online help and examples 
I've found on websites, but clearly I'm missing something.


Thanks for any help you can give!!

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


Re: [R] [BioC] How to do RMA without summary to probeset level?

2009-12-26 Thread Max Kuhn
You'll need to use calls to bg.correct and the other functions in
sequence and save the probe values along the way.

See the example in ?normalize.AffyBatch.normalize2Reference in the
caret package.

Also, don't email R help about this. Keep it on the bioC mailing list.

Max

On Sat, Dec 26, 2009 at 2:52 PM, Peng Yu  wrote:
> I think that you misunderstood me.
>
> As far as I know, RMA does three things: background correction,
> quantile normalization, and summary from probes to probesets. I want
> the probe values after background correction and quantile
> normalization but before the summary.
>
> On Sat, Dec 26, 2009 at 12:07 PM, Benilton Carvalho  
> wrote:
>> pm(data)
>>
>> b
>>
>> On Dec 26, 2009, at 2:21 PM, Peng Yu wrote:
>>
>>> I use the following code to do RMA. I'm wondering how get the probe
>>> level values before the summary to the probeset level values.
>>>
>>> library(oligo)
>>> data<-read.celfiles(list.celfiles(data_dir, full.names=TRUE))
>>> eset<-rma(data)
>>> write.exprs(eset, file='output_file_name', sep="\t")
>>>
>>> ___
>>> Bioconductor mailing list
>>> bioconduc...@stat.math.ethz.ch
>>> https://stat.ethz.ch/mailman/listinfo/bioconductor
>>> Search the archives: 
>>> http://news.gmane.org/gmane.science.biology.informatics.conductor
>>
>>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 

Max

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


Re: [R] [GGPLOT] Legends at different layers

2009-12-26 Thread Megh

Hi Hadley, recently I run this code however got following error (this error
seems not be there at 1st time) :

>   dat <- data.frame(x = rnorm(100))
>   dat1 <- data.frame(
+ x = c(0,0),
+ y = c(1,0),
+ Label = c("Point1", "Point2")
+   )
> 
> 
> ggplot(dat, aes(x)) +
+   geom_histogram(aes(fill = ..count..)) +
+   geom_point(aes(x, y, colour = Label), data = dat1, size = 4) +
+   scale_fill_gradient("Count", low = "green", high = "red", legend=F)
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
Error in col2rgb(colour, TRUE) : invalid color name 'Point1'


Am I missing something? I would also like to know how to put legend for
"Points", but not for Histogram? Dose latest version allow me to do that? I
am using following version of ggplot2 :

> packageDescription("ggplot2")
Package: ggplot2
Type: Package
Title: An implementation of the Grammar of Graphics
Version: 0.8.5
Author: Hadley Wickham 
Maintainer: Hadley Wickham 

...

Any suggestion will be highly appreciated.

Thanks,



hadley wickham wrote:
> 
> You mean:
> 
> dat <- data.frame(x = rnorm(100))
> dat1 <- data.frame(
>   x = c(0,0),
>   y = c(1,0),
>   Label = c("Point1", "Point2")
> )
> 
> 
> ggplot(dat, aes(x)) +
>   geom_histogram(aes(fill = ..count..)) +
>   geom_point(aes(x, y, colour = Label), data = dat1, size = 4) +
>   scale_fill_gradient("Count", low = "green", high = "red")
> 
> 
> Unfortunately not.  In the future, you will be able to do +
> scale_colour_discrete(legend = F)
> 
> Hadley
> 
> On Mon, Dec 7, 2009 at 11:17 AM, Megh  wrote:
>>
>> Here I have following code :
>>
>> dat = rnorm(100)
>> ggplot() + geom_histogram(aes(dat, fill=..count..)) +
>> scale_fill_gradient("Count", low="green", high="red") +
>> opts(legend.position="none")
>> # Above is without any legend
>>
>> ## Now I want to place two points with legends
>> dat1 <- data.frame(c(0,0), c(1,0)); Label <- c("Point1", "Point2")
>> last_plot() + geom_point(aes(dat1[,1], dat1[,2], colour=Label), size=4)
>> # Here I am not getting any legend for "points"
>>
>> I want GGPLOT should show the legend for "points" NOT for "histogram". Is
>> there any option?
>>
>> Thanks,
>>
>> --
>> View this message in context:
>> http://n4.nabble.com/GGPLOT-Legends-at-different-layers-tp954527p954527.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.
>>
> 
> 
> 
> -- 
> http://had.co.nz/
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://n4.nabble.com/GGPLOT-Legends-at-different-layers-tp954527p979185.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] something similar to %include() in sas?

2009-12-26 Thread Wensui Liu
thanks, all,
i think source() is the right one i am looking for.

On Sat, Dec 26, 2009 at 3:13 PM, David Winsemius wrote:

>
> On Dec 26, 2009, at 3:10 PM, Wensui Liu wrote:
>
>  i am just wondering if there is an effective way to include other external
>> codes into the program.
>>
>>
> ?source
>
>>
>>  --
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>


-- 
==
WenSui Liu
Blog   : statcompute.spaces.live.com
Tough Times Never Last. But Tough People Do.  - Robert Schuller
==

[[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] something similar to %include() in sas?

2009-12-26 Thread Gabor Grothendieck
source("abc.R") if you want to run the code in the abc.R file at that
point.  Or if you are looking for a macro facility see defmacro in
gtools which is based on Thomas Lumley's R News 1/3 article where
defmacro is presented.

On Sat, Dec 26, 2009 at 3:10 PM, Wensui Liu  wrote:
> i am just wondering if there is an effective way to include other external
> codes into the program.
>
> thanks.
>
>        [[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] something similar to %include() in sas?

2009-12-26 Thread Jim Holtman

?source

What is the problem you are trying to solve?

Sent from my iPhone.

On Dec 26, 2009, at 15:10, Wensui Liu  wrote:

i am just wondering if there is an effective way to include other  
external

codes into the program.

thanks.

   [[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] something similar to %include() in sas?

2009-12-26 Thread David Winsemius


On Dec 26, 2009, at 3:10 PM, Wensui Liu wrote:

i am just wondering if there is an effective way to include other  
external

codes into the program.



?source



--

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.


[R] something similar to %include() in sas?

2009-12-26 Thread Wensui Liu
i am just wondering if there is an effective way to include other external
codes into the program.

thanks.

[[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] Is there a problem with lattice axes?

2009-12-26 Thread Ted Harding
After answering a previous post by James Rome:
"Re: [R] Why do histogram bars vary their width?"

I noticed that the lateral axis scales in the lattice histogram
which I used for illustration are inconsistent with the frequencies.
The example was:

set.seed(54321)
 X <- c(rnorm(100),rnorm(50,1.0,0.5),rnorm(25,-1.0,0.5),rnorm(10))
  F <- factor(c(rep(0,100),rep(1,50),rep(2,25),rep(3,10)))
# The default:
  histogram(~X | F)
# Your choice (number of breaks)
  histogram(~X | F, breaks=10)
# Explicit specification of break-points:
  histogram(~X | F, breaks=0.5*(-6:6))

In the third of these, you will see that the frequency scales are
marked at marked at 0,10,20,30,40,50 throughout. This is appropriate
for the bottom-left histogram (Level of F=0, N=100), and the
displayed frequencies do indeed (by eye) seem to add up to 100.
It is certainly not right for the top-right histogram (F=3,N=10),
where the displayed scale needs to be 0,1,2,3 (giving 1+3+5+1=10),
i.e. divided by 10; but at least this one is readily re-scalable
"by eye". However, it is neither right nor readily re-scalable
for the other two:

  F=1, N=50, apparent sum = 2+10+44+22+18+4=100
  F=2, N=25, apparent sum = 8+32+48+12 =100

Clearly, while in principle it would be possible to have
  A: an axis lower-left  (F=0,N=100) scaled 0,10,  20,  30,  40,  50
  B: an axis lower-right (F=1,N= 50) scaled 0, 5,  10,  15,  20,  25
  C: an axis upper-left  (F=2,N= 25) scaled 0, 2.5, 5.0, 7.5,10.0,12.5
  D: an axis upper-right (F=3,N= 10) scaled 0, 1,   2,   3,   4,   5
in this 2x2 case, it could not work for say a 3x3 lattice.

The right thing to do when there is a common vertical scale
along a row is to scale each plot itself accordinng to the
vertical scale for the row. Instead, it seems to have chosen
a vertical scale for each histogram as plotted so that the
histiogram bars will nicely fill the panel window in each case,
disregarding the vertical scaling which has been determined
according to the histogram with the largest N.

Thus one could have a scale 0,10,20,30,40 for the bottom row,
with the lower right-hand histogram bars being half the height
they have as displayed by the above, and either
  A: the same scale for the upper row as for the bottom row,
 but with the left-hand histogram bars 1/4 the height
 and the right-hand histogram bars 1/10 the height
or
  B: a scale 0,2.5,5.0,7.5,10 with the left-hand histogram
 bars just as they are now, and the right-hand histogram
 bars 1/2.5 the hright.

Or maybe there is an option lurking somewhere in the lattice
documentation which looks after this sort of thing -- but I
have not been able to find it despite have spent some time
searching.

R version 2.10.0 (2009-10-26)
lattice version: 0.17-26 (2009/10/05)

Ted.




E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 26-Dec-09   Time: 20:07:51
-- XFMail --

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


Re: [R] How to manipulate tables

2009-12-26 Thread William Dunlap
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of James Rome
> Sent: Saturday, December 26, 2009 11:03 AM
> To: r-help@r-project.org
> Subject: [R] How to manipulate tables
> 
> I am sorry to be bothering the list so much.
> 
> I made a table of counts of flight arrivals by hour:
> cnts=tapply(Arrival4,list(Hour),table). There are up to 15 
> arrivals in a
> bin.
> > cnts
> $`0`
> 
>  1  2  3  4  5  6  7  8  9 10 13
>  1  2  5  9  2  7  5  4  2  4  1
> 
> $`1`
> 
> 1 2 3 4
> 3 2 2 1
> 
> $`2`
> 
> 1 3
> 2 2
> .  . .
> 
> My first problem is how to get this table filled in with the 0 slots.
> E.g., I want
> $`0`
> 
>  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
>  1  2  5  9  2  7  5  4  2  4   0   0   1   0   0
> 
> for all 24 hours. The elements of the tables are lists, but I do not
> seem to be able to extract the names of each list, which I think would
> allow this manipulation.

Let's make a fake dataset to demonstrate things more easily.
  set.seed(1)
  data <- data.frame(Arrival4=rpois(50, 4)+1,
 Hour=sample(0:4, replace=TRUE, size=50))
Your tapply(,FUN=table) approach with this data gives
  > with(data, tapply(Arrival4,list(Hour),table))
  $`0`

  3 4 6 8 
  2 2 1 1 

  $`1`

  3 4 5 6 7 8 
  3 2 2 3 1 3 
  ... 2 more one dimensional tables, `3` and `4` ...

I prefer making a two dimensional table so the rows and
columns have common meanings
  > tab <- with(data, table(Hour, Arrival4))
  > tab
  Arrival4
  Hour 1 2 3 4 5 6 7 8 11
 0 0 0 2 2 0 1 0 1  0
 1 0 0 3 2 2 3 1 3  0
 2 0 2 0 2 3 3 0 0  0
 3 0 0 0 0 2 4 4 0  1
 4 1 0 2 3 1 2 0 0  0
  > tab[2,] # 2nd row (Hour==1)
   1  2  3  4  5  6  7  8 11 
   0  0  3  2  2  3  1  3  0
  > tab["1",] # would give the same as tab[2,]

But this is missing columns for Arrival4 in c(10,12,13,14,15).
If you make Arrival4 a factor with levels 1:15 the table will
include entries for each level.  In the following we don't actually
change Arrival4 itself, but create a factor using its data
when we call table().
  > tab <- with(data, table(Hour,
Arrival4=factor(Arrival4,levels=1:15)))
  > tab
  Arrival4
  Hour 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
 0 0 0 2 2 0 1 0 1 0  0  0  0  0  0  0
 1 0 0 3 2 2 3 1 3 0  0  0  0  0  0  0
 2 0 2 0 2 3 3 0 0 0  0  0  0  0  0  0
 3 0 0 0 0 2 4 4 0 0  0  1  0  0  0  0
 4 1 0 2 3 1 2 0 0 0  0  0  0  0  0  0
  > tab[2,] # 2nd row (Hour==1)
   1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 
   0  0  3  2  2  3  1  3  0  0  0  0  0  0  0  

If you have no data for certain hours, you may have
to use the same technique for Hour.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 
 
> My second problem is that I want to compute probability 
> distributions. I
> have
> lambda
>   0   1   2   4   5  
> 6   7
> 0.199190283 0.013765182 0.006477733 0.017813765 0.093117409 
> 0.160323887
> 0.401619433
>   8   9  10  11  12 
> 13  14
> 0.191093117 0.177327935 0.318218623 0.404858300 0.463157895 
> 0.495546559
> 0.435627530
>  15  16  17  18  19 
> 20  21
> 0.418623482 0.307692308 0.405668016 0.484210526 0.580566802 
> 0.585425101
> 0.519028340
>  22  23
> 0.556275304 0.503643725
> 
> and I need to calculate lambda**cnts for each bin, and each hour. I am
> also unsure of how to do this.
> 
> Thanks in advance kind people on this list
> Jim Rome
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] [BioC] How to do RMA without summary to probeset level?

2009-12-26 Thread Peng Yu
I think that you misunderstood me.

As far as I know, RMA does three things: background correction,
quantile normalization, and summary from probes to probesets. I want
the probe values after background correction and quantile
normalization but before the summary.

On Sat, Dec 26, 2009 at 12:07 PM, Benilton Carvalho  wrote:
> pm(data)
>
> b
>
> On Dec 26, 2009, at 2:21 PM, Peng Yu wrote:
>
>> I use the following code to do RMA. I'm wondering how get the probe
>> level values before the summary to the probeset level values.
>>
>> library(oligo)
>> data<-read.celfiles(list.celfiles(data_dir, full.names=TRUE))
>> eset<-rma(data)
>> write.exprs(eset, file='output_file_name', sep="\t")
>>
>> ___
>> Bioconductor mailing list
>> bioconduc...@stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/bioconductor
>> Search the archives: 
>> http://news.gmane.org/gmane.science.biology.informatics.conductor
>
>

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

2009-12-26 Thread David Winsemius


On Dec 26, 2009, at 2:02 PM, James Rome wrote:


I am sorry to be bothering the list so much.

I made a table of counts of flight arrivals by hour:


No, you made a list of tables, which is different.

cnts=tapply(Arrival4,list(Hour),table). There are up to 15 arrivals  
in a

bin.


Why not work with something more regular, like (this is all guesswork  
and untested in absence of test data objects):


table(Arrival4, factor(Hour, levels=1:15)  )?
# or use whatever your max(arrivals) might be.

> xx <- factor(sample(1:10, 4))
> xx
[1] 9 4 7 1
Levels: 1 4 7 9

> table(factor(xx, levels=1:10) )

 1  2  3  4  5  6  7  8  9 10
 1  0  0  1  0  0  1  0  1  0



cnts


$`0`

1  2  3  4  5  6  7  8  9 10 13
1  2  5  9  2  7  5  4  2  4  1

$`1`

1 2 3 4
3 2 2 1

$`2`

1 3
2 2
.  . .

My first problem is how to get this table filled in with the 0 slots.
E.g., I want
$`0`

1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
1  2  5  9  2  7  5  4  2  4   0   0   1   0   0

for all 24 hours. The elements of the tables are lists, but I do not
seem to be able to extract the names of each list, which I think would
allow this manipulation.

My second problem is that I want to compute probability  
distributions. I

have
lambda
 0   1   2   4   5
6   7
0.199190283 0.013765182 0.006477733 0.017813765 0.093117409  
0.160323887

0.401619433
 8   9  10  11  12
13  14
0.191093117 0.177327935 0.318218623 0.404858300 0.463157895  
0.495546559

0.435627530
15  16  17  18  19
20  21
0.418623482 0.307692308 0.405668016 0.484210526 0.580566802  
0.585425101

0.519028340
22  23
0.556275304 0.503643725

and I need to calculate lambda**cnts for each bin, and each hour. I am
also unsure of how to do this.


Can you give a justification for this procedure? (I'm not saying it is  
nonsense, only that it does not make make sense to me. So perhaps  
there is some mathematical property about which I need education.)


--

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.


[R] How to manipulate tables

2009-12-26 Thread James Rome
I am sorry to be bothering the list so much.

I made a table of counts of flight arrivals by hour:
cnts=tapply(Arrival4,list(Hour),table). There are up to 15 arrivals in a
bin.
> cnts
$`0`

 1  2  3  4  5  6  7  8  9 10 13
 1  2  5  9  2  7  5  4  2  4  1

$`1`

1 2 3 4
3 2 2 1

$`2`

1 3
2 2
.  . .

My first problem is how to get this table filled in with the 0 slots.
E.g., I want
$`0`

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
 1  2  5  9  2  7  5  4  2  4   0   0   1   0   0

for all 24 hours. The elements of the tables are lists, but I do not
seem to be able to extract the names of each list, which I think would
allow this manipulation.

My second problem is that I want to compute probability distributions. I
have
lambda
  0   1   2   4   5  
6   7
0.199190283 0.013765182 0.006477733 0.017813765 0.093117409 0.160323887
0.401619433
  8   9  10  11  12 
13  14
0.191093117 0.177327935 0.318218623 0.404858300 0.463157895 0.495546559
0.435627530
 15  16  17  18  19 
20  21
0.418623482 0.307692308 0.405668016 0.484210526 0.580566802 0.585425101
0.519028340
 22  23
0.556275304 0.503643725

and I need to calculate lambda**cnts for each bin, and each hour. I am
also unsure of how to do this.

Thanks in advance kind people on this list
Jim Rome

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


Re: [R] if else does not return right value

2009-12-26 Thread Muhammad Rahiz

Thanks David and Patrick,

I need to use two statements for the if condition specified. Since the 
first statement feeds into the second, the ifelse function may just work 
for the dataset. I'm not sure if there will be issues later but I've 
tested it and it works.


x <- as.matrix(read.table("test.txt"))

Original code;

if (x < 20){
y <- x + 100 # statement 1a
... # statement 1b
} else {
y <- x -100 # statement 2a
... # statement 2b
}

New code:

n0 <- x + 100
n1 <- n0 + 0

m0 <- x - 100
m1 <- m0 - 0

ifelse(x < 20, n1, m1)


Muhammad

Muhammad Rahiz  |  Doctoral Student in Regional Climate Modeling

Climate Research Laboratory, School of Geography & the Environment  
Oxford University Centre for the Environment
South Parks Road, Oxford, OX1 3QY, United Kingdom 
Tel: +44 (0)1865-285194	 Mobile: +44 (0)7854-625974

Email: muhammad.ra...@ouce.ox.ac.uk

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


Re: [R] if else does not return right value

2009-12-26 Thread David Winsemius

See below:

On Dec 26, 2009, at 12:58 PM, Muhammad Rahiz wrote:


Hi all,

I'm not getting the right results for values that are >99 using the  
if else function. The following illustrates the problem


> x <- as.matrix(read.table("test.txt"))
> x
 V1 V2 V3
[1,]  47  1 43
[2,]  83  2 42
[3,]   1  3 41
[4,]  39  4 40
[5,]  23  5 39
[6,]  23  6 38
[7,]  39  7 37
[8,]  32  8 36
[9,]  73  9 35
[10,] 124 10 34

Specifying the followng condition,

if ( x <20){
y <- x +100
} else {
y <- x -100
}

> y
V1  V2  V3
[1,] -53 -99 -57
[2,] -17 -98 -58
[3,] -99 -97 -59
[4,] -61 -96 -60
[5,] -77 -95 -61
[6,] -77 -94 -62
[7,] -61 -93 -63
[8,] -68 -92 -64
[9,] -27 -91 -65
[10,]  24 -90 -66

The output generated contains 'errors.

For example, given that x < 20,
for x = 1, the output should be x+100 = 1 + 100 = 101.
However, the generated output is -99.

In addition, there is the following warning message which I don't  
know what it means

  the condition has length > 1 and only the first element will be used

The problem is solved if I use the ifelse function but I want to  
specify the code as following;


if (/condition/) {
/statement 1a
statement 1b
/} else {
/statement 2a
statement 2b
/}


If that is your firm desire, then you need to run an indexed loop or  
an apply function over the individual values of the "if" evaluated on  
contents of x. The "if" function is not vectorized.


y <- apply(x, 1:2,function(xx)
   if (xx <20){
  xx+100
  }else{
  xx-100
 } )

> y
   V1  V2  V3
 [1,] -53 101 -57
 [2,] -17 102 -58
 [3,] 101 103 -59
 [4,] -61 104 -60
 [5,] -77 105 -61
 [6,] -77 106 -62
 [7,] -61 107 -63
 [8,] -68 108 -64
 [9,] -27 109 -65
[10,]  24 110 -66



Thanks.

Muhammad

--


--
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] Question regarding if statement in while loop

2009-12-26 Thread Stephan Kolassa

Hi Stephanie,

it sounds like R's exception handling may help, something like this:

foo <- try(eblest(i, dir5, sterr5, weight5, aux5))
if ( class(foo) == "try-error" ) next

Take a look at ?try.

HTH,
Stephan


Stephanie Coffey schrieb:

Hi all,
I'm running R version 2.9.2 on a PC.

I'm having a problem with a loop, and have tried using an if statement
within to fix it, but to no avail.
Any advice would be appreciated.

Here is my code:
*
eblest <- function(i,dir, sterr, weight, aux) {
n <- nrow(dir)
Y <- as.matrix(dir[,i], ncol=1)
sigma2ei <- as.matrix(sterr[,i]^2, ncol=1)
w <- as.matrix((weight[,3])*(sigma2ei), ncol=1)
X <- as.matrix(subset(aux, select=c(3,5:7,9:10,13)))
a <<- EBLUP.area(Y,cbind(w,1),sigma2ei,n)#The EBLUP.area
function is a function already in R.
}
  # It gives a bunch of output, some of what I need.

#THIS IS THE LOOP I'M HAVING A PROBLEM WITH:
results <- data.frame(length=nrow(dir5))
i <- 3
while (i <=some number) {
eblest(i, dir5, sterr5, weight5, aux5)
out <<- cbind(i, a$EBLUP, a$mse)
results <- cbind(results, out)
i <- i+1
}
***
I have tried running the eblest function for a specific set of input
(i, dir5, etc as in the function) This function runs ok.
However, sometimes eblest does not create the expected output,
sometimes due to the solution being singular or other reasons.
I'm not so concerned about that at this point - it's a function of the data.

My problem is that, as you can see, after eblest runs, the "out"
pieces of information are bound together in the results matrix.
When the eblest does not run correctly, the loop stops.  For example,
when i=3 and i=4, eblest runs ok, and I get a maxtrix with the
following columns:

iEBLUP se.EBLUP i EBLUP se.EBLUP
3   xy4abh

...but when it loops back around to start i=5, I get an error because
the solution is singular.  But I don't want the loop to stop (I have
~100 of these i's for which I need to execute this function.

So I would like to set an if condition that will cause the loop to
step ahead (in this case, to 6), and continue looping...Something like
"if exists("out")=FALSE next, else..."  However, when I tried that,
the results matrix was empty created at all.

In case it helps, "out" has a "numeric" mode, and is a "matrix"...

I've written these functions and loops using online help and examples
I've found on websites, but clearly I'm missing something.

Thanks for any help you can give!!

~Stephanie Coffey

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Why do histogram bars vary their width?

2009-12-26 Thread Ted Harding
On 26-Dec-09 15:33:45, James Rome wrote:
> histogram(~(Arrival4) | as.factor(Hour), type="count",
> breaks=16,ylab="Arrival Count",
>   xlab="Arrival Rate/4",main="Friday EWR A22R D22L Configiration",
>   layout=c(6,4), par.strip.text=list(cex=0.7))
> 
> Why do I get plots with different bar widths? See attached.
> 
> Thanks,
> Jim Rome

Read the 'breaks' section under "Arguments:" in ?histogram
in the lattice package.

If you choose to use the default method:
  breaks = seq_len(1 + nlevels(x)) - 0.5
when 'x' is a factor, and
  breaks = do.breaks(endpoints, nint)
otherwise, or if you specify the numerical break-points explicitly,
as for instance in
  breaks = (0:15)
then the same set of break-points will be used for each histogram
across all panels. If you use another specification, such as yours:
  breaks=15
then:

  "Other values of 'breaks' are possible, in which case they
   affect the display in each panel differently."

which is what you are seeing. Compare the three histogram plots
from the following code:

  X <- c(rnorm(100),rnorm(50,1.0,0.5),rnorm(25,-1.0,0.5),rnorm(10))
  F <- factor(c(rep(0,100),rep(1,50),rep(2,25),rep(3,10)))
# The default:
  histogram(~X | F)
# Your choice (number of breaks)
  histogram(~X | F, breaks=10)
# Explicit specification of break-points:
  histogram(~X | F, breaks=0.5*(-6:6))

Hoping this helps,
Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 26-Dec-09   Time: 18:28:32
-- XFMail --

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


[R] Question regarding if statement in while loop

2009-12-26 Thread Stephanie Coffey
Hi all,
I'm running R version 2.9.2 on a PC.

I'm having a problem with a loop, and have tried using an if statement
within to fix it, but to no avail.
Any advice would be appreciated.

Here is my code:
*
eblest <- function(i,dir, sterr, weight, aux) {
n <- nrow(dir)
Y <- as.matrix(dir[,i], ncol=1)
sigma2ei <- as.matrix(sterr[,i]^2, ncol=1)
w <- as.matrix((weight[,3])*(sigma2ei), ncol=1)
X <- as.matrix(subset(aux, select=c(3,5:7,9:10,13)))
a <<- EBLUP.area(Y,cbind(w,1),sigma2ei,n)#The EBLUP.area
function is a function already in R.
}
  # It gives a bunch of output, some of what I need.

#THIS IS THE LOOP I'M HAVING A PROBLEM WITH:
results <- data.frame(length=nrow(dir5))
i <- 3
while (i <=some number) {
eblest(i, dir5, sterr5, weight5, aux5)
out <<- cbind(i, a$EBLUP, a$mse)
results <- cbind(results, out)
i <- i+1
}
***
I have tried running the eblest function for a specific set of input
(i, dir5, etc as in the function) This function runs ok.
However, sometimes eblest does not create the expected output,
sometimes due to the solution being singular or other reasons.
I'm not so concerned about that at this point - it's a function of the data.

My problem is that, as you can see, after eblest runs, the "out"
pieces of information are bound together in the results matrix.
When the eblest does not run correctly, the loop stops.  For example,
when i=3 and i=4, eblest runs ok, and I get a maxtrix with the
following columns:

iEBLUP se.EBLUP i EBLUP se.EBLUP
3   x            y    4    abh

...but when it loops back around to start i=5, I get an error because
the solution is singular.  But I don't want the loop to stop (I have
~100 of these i's for which I need to execute this function.

So I would like to set an if condition that will cause the loop to
step ahead (in this case, to 6), and continue looping...Something like
"if exists("out")=FALSE next, else..."  However, when I tried that,
the results matrix was empty created at all.

In case it helps, "out" has a "numeric" mode, and is a "matrix"...

I've written these functions and loops using online help and examples
I've found on websites, but clearly I'm missing something.

Thanks for any help you can give!!

~Stephanie Coffey

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 CHOLMOD errors when attempting poisson glmm

2009-12-26 Thread Marielle Postava-Davig
Thank you so much for replying.  The data set I used for this particular
output has 600 entries.  The original had 1657 lines so I've already reduced
it considerably.  Here is a copy of the entire output with lme4 package
information:

> substrate=read.csv(file.choose(),header=T)
> attach(substrate)
> library(lme4)
Loading required package: Matrix
Loading required package: lattice

Attaching package: 'Matrix'


The following object(s) are masked from package:stats :

 contr.helmert,
 contr.poly,
 contr.SAS,
 contr.sum,
 contr.treatment,
 xtabs


The following object(s) are masked from package:base :

 rcond

>
model1=lmer(totalcfus~habitat*temp*moisture*light+location+(1|habitat/colony/location),family=poisson,control=list(msVerbose=1))
  0: 553377.59:  1.00573 0.620530 0.169516  26.3904 -13.1266 -33.2286
-21.1955 -21.1064 -0.590761 -0.217403 -0.0342272 -0.960593 -0.0962517
0.441626  1.20575 0.718621 0.680580 0.171006 0.403729 0.278822 0.275395
0.00707767 0.0225599 0.0854869 0.0533373 0.0243451 0.00114120 0.000403226
-0.00566960 -0.0143715 -0.00931896 -0.00879323 -0.000753236 -0.00335745
-0.00178054 -0.000788027 -0.000288944 -0.000909455 -0.000839295 -0.000309293
-1.35885e-05 9.76120e-06 3.57035e-05 2.78985e-05 1.01880e-05
CHOLMOD warning: %h
Error in mer_finalize(ans) :
  Cholmod error `not positive definite' at
file:../Cholesky/t_cholmod_rowfac.c, line 432

I was actually curious if there was another version of lme4 I could use.  I
use a mac laptop that is about 6 years old and runs on the Tiger OS
10.4.11.  I found another version of lme4 that would not work on my
operating system.

I had a feeling singularities might be my problem, but had run out of ideas
for eliminating them without losing the majority of my data set.  I also
have not determined how to correctly enter year into the model, and I feel
that may be important.  I have nests I sampled multiple years that may also
be causing problems.  I greatly appreciate any advice you can give me.

Cheers,
Marielle

On Fri, Dec 25, 2009 at 11:24 AM, Douglas Bates  wrote:

> On Thu, Dec 24, 2009 at 1:03 PM, postava-davig.m
>  wrote:
> >
> > Hello,
>
> > I have been attempting to run a poisson glmm using lme4 for some time now
> > and have had a lot of trouble.  I would say 9 times out of 10 I receive
> the
> > following warning:
>
> > CHOLMOD warning:  %h
> > Error in mer_finalize(ans) :
> >  Cholmod error `not positive definite' at
> > file:../Cholesky/t_cholmod_rowfac.c, line 432
>
> That is an (admittedly obscure) indication that the Cholesky
> factorization of a matrix derived from the random-effects model matrix
> cannot be performed.
>
> > My data are counts of microbe colony forming units (CFUs) collected from
> > termite cuticles and the surrounding environment over a 3 year period.  I
> am
> > attempting to analyze the effect of several factors on these counts
> (termite
> > nest volume, temperature, humidity, light, incubation temperature,
> habitat,
> > year, sample location, etc.) to determine which account for the variance
> in
> > microbial communities.  These data are observations, so there are many
> > missing valueswhich may be part of the problem.  I've tried many
> > different combinations of variables, and also have tried reducing my data
> > set to remove as many NA's and confounding variables as possible, but I
> > still can't get any models to work consistently.  One most recent attempt
> > had the following output:
>
>
>  
> model1=lmer(totalcfus~habitat*temp*moisture*light+location+(1|habitat/colony/location),family=poisson,control=list(msVerbose=1))
> >  0: 553377.59:  1.00573 0.620530 0.169516  26.3904 -13.1266 -33.2286
> > -21.1955 -21.1064 -0.590761 -0.217403 -0.0342272 -0.960593 -0.0962517
> > 0.441626  1.20575 0.718621 0.680580 0.171006 0.403729 0.278822 0.275395
> > 0.00707767 0.0225599 0.0854869 0.0533373 0.0243451 0.00114120 0.000403226
> > -0.00566960 -0.0143715 -0.00931896 -0.00879323 -0.000753236 -0.00335745
> > -0.00178054 -0.000788027 -0.000288944 -0.000909455 -0.000839295
> -0.000309293
> > -1.35885e-05 9.76120e-06 3.57035e-05 2.78985e-05 1.01880e-05
> > CHOLMOD warning:  %h
> > Error in mer_finalize(ans) :
> >  Cholmod error `not positive definite' at
> > file:../Cholesky/t_cholmod_rowfac.c, line 432
>
> Thank you for including the output from verbose = TRUE.  It would also
> help if you included the output from sessionInfo() so we can see which
> version of R you are using and which version of the lme4 package you
> are using.
>
> How many observations are used in this fit?  As you can see, the
> number of parameters being fit is very large and encountering
> singularities is not unexpected.
>
> May I suggest that we move this discussion to the
> r-sig-mixed-mod...@r-project.org mailing list, which I have cc:d on
> this reply?  That list is specifically intended for discussions of
> this type.
> > I have to admit that I'm at a loss, and have been unable to determine

[R] if else does not return right value

2009-12-26 Thread Muhammad Rahiz

Hi all,

I'm not getting the right results for values that are >99 using the if 
else function. The following illustrates the problem


> x <- as.matrix(read.table("test.txt"))
> x
  V1 V2 V3
[1,]  47  1 43
[2,]  83  2 42
[3,]   1  3 41
[4,]  39  4 40
[5,]  23  5 39
[6,]  23  6 38
[7,]  39  7 37
[8,]  32  8 36
[9,]  73  9 35
[10,] 124 10 34

Specifying the followng condition,

if ( x <20){
y <- x +100
} else {
y <- x -100
}

> y
 V1  V2  V3
[1,] -53 -99 -57
[2,] -17 -98 -58
[3,] -99 -97 -59
[4,] -61 -96 -60
[5,] -77 -95 -61
[6,] -77 -94 -62
[7,] -61 -93 -63
[8,] -68 -92 -64
[9,] -27 -91 -65
[10,]  24 -90 -66

The output generated contains 'errors.

For example, given that x < 20,
for x = 1, the output should be x+100 = 1 + 100 = 101.
However, the generated output is -99.

In addition, there is the following warning message which I don't know 
what it means

   the condition has length > 1 and only the first element will be used

The problem is solved if I use the ifelse function but I want to specify 
the code as following;


if (/condition/) {
/statement 1a
statement 1b
/} else {
/statement 2a
statement 2b
/}

Thanks.

Muhammad

--
Muhammad Rahiz  |  Doctoral Student in Regional Climate Modeling

Climate Research Laboratory, School of Geography & the Environment  
Oxford University Centre for the Environment
South Parks Road, Oxford, OX1 3QY, United Kingdom 
Tel: +44 (0)1865-285194	 Mobile: +44 (0)7854-625974

Email: muhammad.ra...@ouce.ox.ac.uk

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


Re: [R] Is SEM package of R suitable for sem analysis

2009-12-26 Thread Joe King
I am going to take SEM this next quarter in my doctoral program. My
suggestion is to use the program your professor suggests and try to
re-create your models in R using the SEM package. We are not going to use
AMOS though we use EQS, and another prof on campus who teaches it in a
different department uses LISREL, so since SEM hasn't been implemented in
most commercial software and you need specialty software for it, it may be
best to know several different software programs if you want to do SEM type
work. I do have a feeling since R is growing so rapidly it wont take time
for people in the community to create packages or develop existing packages
equal to or greater than commercial software! LONG LIVE R :)

Joe King
206-913-2912
j...@joepking.com
"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Reeyarn_???_10928113
Sent: Saturday, December 26, 2009 3:50 AM
To: R-help@r-project.org
Subject: [R] Is SEM package of R suitable for sem analysis

Dears,

I'm a college student and In doing my statistics homework.

I use R with SEM package as my tool for sem analysis,
but my teacher told me AMOS is more suitable for such analysis.

Could someone help tell me whether it is true
that some commercial software is better accepted in academic fields?

Sorry if I should not post such topics here.

-- 
Best Regards,
Reeyarn T. Lee

Accounting Dept, Guanghua School of Management,
Peking University, Beijing, P.R. China

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Fwd: Why do histogram bars vary their width?

2009-12-26 Thread David Winsemius


On Dec 26, 2009, at 10:38 AM, James Rome wrote:


I did

histogram(~(Arrival4) | as.factor(Hour), type="count",
breaks=16,ylab="Arrival Count",
 xlab="Arrival Rate/4",main="Friday EWR A22R D22L Configiration",
 layout=c(6,4), par.strip.text=list(cex=0.7))

Why do I get plots with different bar widths? See http://dl.dropbox.com/u/537118/Friday.pdf 
.


Although

bins=seq(-.5,15.5,1)


 identical(seq_len(1 + nlevels(x)) - 0.5 , seq(-.5,15.5,1) )
[1] FALSE



histogram(~(Arrival4) | as.factor(Hour), type="count",  
breaks=bins,ylab="Arrival Count",

 xlab="Arrival Rate/4",main="Friday EWR A22R D22L Configiration",
 layout=c(6,4), par.strip.text=list(cex=0.7))

seems to work properly.

Thanks,
Jim Rome

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Reading Input file

2009-12-26 Thread jim holtman
Use

newrate[[i]] <- read.csv(rates[i])

better yet, use a list and lapply

newrate <- lapply(paste('rate', 1:4, '.csv', sep=''), read.csv)

On Sat, Dec 26, 2009 at 8:09 AM, Maithili Shiva wrote:

> Dear R helpers / Johannes Sir,
>
> Unfortunately it didn't work.
>
> I am getting following warning messages.
>
> 1: In neweate[i] = read.csv(rates[i]) :
>   number of items to replace is not a multiple of replacement length.
> 2:  similar message
> 3:  similar message
> 4: similar message
>
> Let me be specific in my problem.
>
> I have three csv files as
>
> rate1.csv
> r1r2r3r4r5 r6
> 10.1   10.25   10.25   10.50   10.5010.75
>
> rate2.csv
> r1r2r3r4r5 r6
> 15.1   15.45   15.45   15.70   15.7015.90
>
> rate3.csv
> r1r2r3r4r5 r6
> 18.3   18.50   18.50   18.65   18.6518.95
>
> Normally I can read these files as
>
> newrate1  =  read.csv('rate1.csv'')
> newrate2  =  read.csv('rate2.csv')
> newrate3  =  read.csv('rate3.csv')
>
> However, due to some other requirement first I have to define following R
> code
>
> n = 3
>
> rate_name = NULL
>
> for (i in 1:n)
>
> rate_name[i] = (paste(`rate', i, ‘.csv`, sep = ‘’))
>
> # rate_name gives "rate1.csv" "rate2.csv" "ratë3.csv"
>
>
> ### MY TASK
>
> I need to use the rate_names to read the actual rate1.csv, rate2.csv and
> rate3.csv files.
>
> When I use the following code
>
> newrate <- list()
> for (i in 1:n)
>{
> newrate[i] = read.csv(rate_name[i])
>}
>
> I get following warning messages
>
> 1: In newrate[i] = read.csv(rate_name[i]) :
>   number of items to replace is not a multiple of replacement length
> 2: similar message
> 3: similar message
>
>
> ## APPROACH II
>
> PPP = matrix(data = rate_name, nrow = 1, ncol = 3, byrow = FALSE)
> X = matrix(data = NA, nrow = 3, ncol = 6, byrow = FALSE)
>
> for (j in 1:3)
> X = read.csv(PPP[1, j])
>
> # X returns  (i.e. only first record is taken)
>
> r1r2r3r4r5 r6
> 10.1   10.25   10.25   10.50   10.5010.75
>
>
> Please guide
>
> With regards
>
> Maithili
>
>
> --- On Sat, 26/12/09, Johannes Signer  wrote:
>
>
> From: Johannes Signer 
> Subject: Re: [R] Reading Input file
> To: "Maithili Shiva" 
> Cc: r-help@r-project.org
> Date: Saturday, 26 December, 2009, 9:42 AM
>
>
>
>
>
> On Sat, Dec 26, 2009 at 10:21 AM, Maithili Shiva 
> wrote:
>
>
>
> Dear R helpers
>
> I have some files in my say 'WORK' directory and the file names are say
> rate1.csv, rate2.csv, rate3.csv, rate4.csv
>
> Because of some other requirement, I need to run the following commands
>
> n = 4
>
> rates = NULL
>
> for (i in 1:n)
>
> rates[i] = (paste(`rate', i, ‘.csv`, sep = ‘’))
>
> # this gives me "rate1.csv" "rate2.csv" and so on
>
> #My problem is now I need to relate these file names with actual files and
> read these files
> # There are files rate1.csv, rate2.csv, rate3.csv, rate4.csv in my WORK
> directory.
>
>
> # If I individually define
>
> PPP = read.csv(‘rate[1]’)
> PPP  # When I run PPP in R, it gives contents of the file rate1.csv
> i.e. I am able to read the required rate1 file. But if I run following
> commands, I get errors.
>
> newrate = NULL
>
>
> Maybe try:
>
> newrate <- list()
>
> and leave everything else as it is.
>
> just an idea,
>
>
> for (i in 1:n)
>{
> newrate[i] = read.csv(rates[i])
>}
>
> I need to read all these four files for my further analysis. Please guide.
>
>
> Regards
>
> Maithili
>
>
>
>
>  The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.
>[[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.
>
>
>
>
>
> [[elided Yahoo spam]]
>
>[[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>


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

What is the problem that you are trying to solve?

[[alternative HTML version deleted]]

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


Re: [R] Help with SVM package Kernlab

2009-12-26 Thread Vishal Thapar
Hi David,

Thank you so much for the pointer. I get it now. I did try the
str(testSeq_df) and since it gave me more than 2 factors for each column, I
believed that it was fine. I get the point clearly now. Thanks again for all
your help. I really appreciate it.

Sincerely,

vishal

On Sat, Dec 26, 2009 at 8:26 AM, David Winsemius wrote:

>
> On Dec 26, 2009, at 3:53 AM, Vishal Thapar wrote:
>
>  Hi All,
>>
>> Thank you for your replies so far. I was hoping I could get some more
>> input from you on this issue. It seems to me that I have hit a dead end here
>> and would really appreciate some feedback. I have followed all the
>> suggestions you have mentioned but they still this is stuck. Earlier I
>> thought that it was a "factor" issue but now even that is not the error.
>> Here is the script and the error. Thanks for your help. I have attached the
>> sample test file as well as the training file in case you would like to run
>> it locally.
>> -
>> library(seqinr)
>> library("kernlab")
>>
>
>
> > str(mars500_1_df)
> 'data.frame':   256 obs. of  501 variables:
> All of which are factors with 4 levels
>
>
>  testSeq_fa=read.fasta("temp1.fasta")
>> testSeq_seq=t(getSequence(testSeq_fa))
>> testSeq_df=as.data.frame(testSeq_seq,stringsAsFactors=FALSE)
>> testSeq_df = cbind(Class="-",testSeq_df)
>> testSeq_df = data.frame(lapply(testSeq_df,factor))
>>
> > str(testSeq_df)
> 'data.frame':   20 obs. of  501 variables:
>
> $ V9   : Factor w/ 3 levels "a","c","t": 2 1 2 1 3 2 3 2 3 1 ...
> $ V9   : Factor w/ 3 levels "a","c","t": 2 1 2 1 3 2 3 2 3 1 ...
> $ V26  : Factor w/ 3 levels "a","g","t": 2 1 1 1 1 3 1 3 1 3 ...
> ...and about 10 more...
>
> So I think you were closer but not quite there yet.
> > for(i in 11:501){if (length(levels(testSeq_df[,i])) == 3)
>levels(testSeq_df[,i])<- c(a="a",g="g",c="c",c="t")}
>
>
> > predict(mars500_1,testSeq_df)
>  [1] - - - - + - + - - - - + + + - - - - - +
> Levels: - +
>
> YES, it WAS (and still is) a "factor issue". You were shown how to look at
> objects with str. Why have you not adopted the practice?
>
> --
>
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>


-- 
Vishal Thapar, Ph.D.
Post Doctoral Researcher
Cold Spring Harbor Lab
Williams Bldg

1 Bungtown Road
Cold Spring Harbor, NY - 11724

[[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] Fwd: Why do histogram bars vary their width?

2009-12-26 Thread James Rome
I did

histogram(~(Arrival4) | as.factor(Hour), type="count",
breaks=16,ylab="Arrival Count",
  xlab="Arrival Rate/4",main="Friday EWR A22R D22L Configiration",
  layout=c(6,4), par.strip.text=list(cex=0.7))

Why do I get plots with different bar widths? See 
http://dl.dropbox.com/u/537118/Friday.pdf.

Although

bins=seq(-.5,15.5,1)

histogram(~(Arrival4) | as.factor(Hour), type="count", 
breaks=bins,ylab="Arrival Count",
  xlab="Arrival Rate/4",main="Friday EWR A22R D22L Configiration",
  layout=c(6,4), par.strip.text=list(cex=0.7))

seems to work properly.

Thanks,
Jim Rome

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 can sample from f(x)~x^(a-1)

2009-12-26 Thread Michael Erickson
On Fri, Dec 25, 2009 at 8:07 AM,  wrote:

> Hello all
> how can sample from f(x)~x^(a-1)*ind(0,min(b,-log(u)) in R?
> where a and b is positive constand and   0

If the idea is that X is a random variable, then you need to decide what
kind of random variable it is.  For example, if you wanted to assume that it
was a random uniform variable roughly on the interval of -infinity to
infinity, you can do something like:

runif(1, -1e100, 1e+100)^(a-1)*ind(0,min(b,-log(u)))

(I'm not sure whether my limits are a good stand-in for -infinity to
+infinity.)

There are a number of functions that all start with r that sample from
various distributions -- rnorm(), runif(), rexp(), ...  Once you decide what
X is, it is pretty straightforward.

I was going to look at your function, but I don't know what ind() is, so I
was stuck.

Michael

[[alternative HTML version deleted]]

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


Re: [R] Help with SVM package Kernlab

2009-12-26 Thread David Winsemius


On Dec 26, 2009, at 3:53 AM, Vishal Thapar wrote:


Hi All,

Thank you for your replies so far. I was hoping I could get some  
more input from you on this issue. It seems to me that I have hit a  
dead end here and would really appreciate some feedback. I have  
followed all the suggestions you have mentioned but they still this  
is stuck. Earlier I thought that it was a "factor" issue but now  
even that is not the error. Here is the script and the error. Thanks  
for your help. I have attached the sample test file as well as the  
training file in case you would like to run it locally.

-
library(seqinr)
library("kernlab")



> str(mars500_1_df)
'data.frame':   256 obs. of  501 variables:
All of which are factors with 4 levels


testSeq_fa=read.fasta("temp1.fasta")
testSeq_seq=t(getSequence(testSeq_fa))
testSeq_df=as.data.frame(testSeq_seq,stringsAsFactors=FALSE)
testSeq_df = cbind(Class="-",testSeq_df)
testSeq_df = data.frame(lapply(testSeq_df,factor))

> str(testSeq_df)
'data.frame':   20 obs. of  501 variables:

$ V9   : Factor w/ 3 levels "a","c","t": 2 1 2 1 3 2 3 2 3 1 ...
$ V9   : Factor w/ 3 levels "a","c","t": 2 1 2 1 3 2 3 2 3 1 ...
$ V26  : Factor w/ 3 levels "a","g","t": 2 1 1 1 1 3 1 3 1 3 ...
...and about 10 more...

So I think you were closer but not quite there yet.
> for(i in 11:501){if (length(levels(testSeq_df[,i])) == 3)
levels(testSeq_df[,i])<- c(a="a",g="g",c="c",c="t")}

> predict(mars500_1,testSeq_df)
 [1] - - - - + - + - - - - + + + - - - - - +
Levels: - +

YES, it WAS (and still is) a "factor issue". You were shown how to  
look at objects with str. Why have you not adopted the practice?


--

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] Help with SVM package Kernlab

2009-12-26 Thread David Winsemius
Perhaps my response is not showing up on the r-help list due to the  
large number of recipients generated by the reply-all option  
triggering some sort of spam filter. So I am trimming them.


On Dec 26, 2009, at 3:53 AM, Vishal Thapar wrote:


Hi All,

Thank you for your replies so far. I was hoping I could get some  
more input from you on this issue. It seems to me that I have hit a  
dead end here and would really appreciate some feedback. I have  
followed all the suggestions you have mentioned but they still this  
is stuck. Earlier I thought that it was a "factor" issue but now  
even that is not the error. Here is the script and the error. Thanks  
for your help. I have attached the sample test file as well as the  
training file in case you would like to run it locally.

-
library(seqinr)
library("kernlab")

### Reading in the data
mars500_1_fasta = read.fasta("toClassify500_1.fasta")
mars500_1_seq = t(getSequence(mars500_1_fasta)) # get the sequences  
from the fasta object
mars500_1_df = as.data.frame(mars500_1_seq,stringsAsFactors=FALSE) #  
convert it to a Data Frame
class = append(rep("+",times=128),rep("-",times=128)) # add the  
Class field to the data frame for classification

mars500_1_df = cbind(Class=class,mars500_1_df)
mars500_1_df = data.frame(lapply(mars500_1_df,factor)) #Finally  
apply the factor() function

#
# Call the ksvm() function to create a model
mars500_1 <- ksvm(Class ~ ., data = mars500_1_df, kernel = "rbfdot",  
kpar = "automatic", C = 60, cross = 3, prob.model = TRUE)


> str(mars500_1_df)
'data.frame':   256 obs. of  501 variables:
All of which are factors with 4 levels


testSeq_fa=read.fasta("temp1.fasta")
testSeq_seq=t(getSequence(testSeq_fa))
testSeq_df=as.data.frame(testSeq_seq,stringsAsFactors=FALSE)
testSeq_df = cbind(Class="-",testSeq_df)
testSeq_df = data.frame(lapply(testSeq_df,factor))

> str(testSeq_df)
'data.frame':   20 obs. of  501 variables:

$ V9   : Factor w/ 3 levels "a","c","t": 2 1 2 1 3 2 3 2 3 1 ...
$ V9   : Factor w/ 3 levels "a","c","t": 2 1 2 1 3 2 3 2 3 1 ...
$ V26  : Factor w/ 3 levels "a","g","t": 2 1 1 1 1 3 1 3 1 3 ...
...and about 10 more...

So I think you were closer but not quite there yet.
> for(i in 11:501){if (length(levels(testSeq_df[,i])) == 3)
   levels(testSeq_df[,i])<- c(a="a",g="g",c="c",c="t")}

> predict(mars500_1,testSeq_df)
[1] - - - - + - + - - - - + + + - - - - - +
Levels: - +

YES, it WAS (and still is) a "factor issue".



testSeq_fa=read.fasta("temp1.fasta")
testSeq_seq=t(getSequence(testSeq_fa))
testSeq_df=as.data.frame(testSeq_seq,stringsAsFactors=FALSE)
testSeq_df = cbind(Class="-",testSeq_df)
testSeq_df = data.frame(lapply(testSeq_df,factor))
predict(mars500_1,testSeq_df)

Error in .local(object, ...) : test vector does not match model !

Thanks in advance.

Sincerely,

Vishal


On Fri, Dec 25, 2009 at 8:10 AM, Vishal Thapar  
 wrote:

Hi,

I seem to have made some headway on this problem but its still not  
solved. It seems like this is a "factor" issue. When I read my  
training set, I read it with read.csv() which converts each of the  
columns as "factors". From this if I take a single row as my



Williams Bldg

1 Bungtown Road
Cold Spring Harbor, NY - 11724




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] Reading Input file

2009-12-26 Thread John Kane
First of all there seems to be something wrong with your equation
> rate_name[i] = (paste(`rate', i, ‘.csv`, sep = ‘’))

Try this
rate_name[i] <- paste("rate",i,".csv", sep="")


I am not 

--- On Sat, 12/26/09, Maithili Shiva  wrote:

> From: Maithili Shiva 
> Subject: Re: [R] Reading Input file
> To: "Johannes Signer" 
> Cc: r-help@r-project.org
> Received: Saturday, December 26, 2009, 8:09 AM
> Dear R helpers / Johannes Sir,
>  
> Unfortunately it didn't work.
> 
> I am getting following warning messages.
>  
> 1: In neweate[i] = read.csv(rates[i]) :
>   number of items to replace is not a multiple of
> replacement length.
> 2:  similar message
> 3:  similar message
> 4: similar message
>  
> Let me be specific in my problem.
>  
> I have three csv files as 
>  
> rate1.csv
> r1    r2    r3   
> r4    r5 r6
> 10.1   10.25   10.25   10.50   10.50    10.75
>  
> rate2.csv
> r1    r2    r3   
> r4    r5 r6
> 15.1   15.45   15.45   15.70   15.70    15.90
>  
> rate3.csv
> r1    r2    r3   
> r4    r5 r6
> 18.3   18.50   18.50   18.65   18.65    18.95
>  
> Normally I can read these files as 
>  
> newrate1  =  read.csv('rate1.csv'')
> newrate2  =  read.csv('rate2.csv')
> newrate3  =  read.csv('rate3.csv')
>  
> However, due to some other requirement first I have to
> define following R code
>  
> n = 3 
>  
> rate_name = NULL
>  
> for (i in 1:n)
> 
> rate_name[i] = (paste(`rate', i, ‘.csv`, sep = ‘’))
> 
> # rate_name gives "rate1.csv" "rate2.csv" "ratë3.csv"
>  
>  
> ### MY TASK
>  
> I need to use the rate_names to read the actual rate1.csv,
> rate2.csv and rate3.csv files.
>  
> When I use the following code
>  
> newrate <- list()
> for (i in 1:n)
>    {
>     newrate[i] = read.csv(rate_name[i])
>    }
> 
> I get following warning messages
>  
> 1: In newrate[i] = read.csv(rate_name[i]) :
>   number of items to replace is not a multiple of
> replacement length
> 2: similar message
> 3: similar message
>  
>  
> ## APPROACH II
>  
> PPP = matrix(data = rate_name, nrow = 1, ncol = 3, byrow =
> FALSE)
> X = matrix(data = NA, nrow = 3, ncol = 6, byrow = FALSE)
>  
> for (j in 1:3)
> X = read.csv(PPP[1, j])
>  
> # X returns  (i.e. only first record is taken)
>  
> r1    r2    r3   
> r4    r5 r6
> 10.1   10.25   10.25   10.50   10.50    10.75
>  
>  
> Please guide
>  
> With regards
>  
> Maithili
>  
>  
> --- On Sat, 26/12/09, Johannes Signer 
> wrote:
> 
> 
> From: Johannes Signer 
> Subject: Re: [R] Reading Input file
> To: "Maithili Shiva" 
> Cc: r-help@r-project.org
> Date: Saturday, 26 December, 2009, 9:42 AM
> 
> 
> 
> 
> 
> On Sat, Dec 26, 2009 at 10:21 AM, Maithili Shiva 
> wrote:
> 
> 
> 
> Dear R helpers
>  
> I have some files in my say 'WORK' directory and the file
> names are say rate1.csv, rate2.csv, rate3.csv, rate4.csv
>  
> Because of some other requirement, I need to run the
> following commands
>  
> n = 4 
>  
> rates = NULL
>  
> for (i in 1:n)
> 
> rates[i] = (paste(`rate', i, ‘.csv`, sep = ‘’))
>  
> # this gives me "rate1.csv" "rate2.csv" and so on
>  
> #My problem is now I need to relate these file names with
> actual files and read these files
> # There are files rate1.csv, rate2.csv, rate3.csv,
> rate4.csv in my WORK directory.
>  
>  
> # If I individually define
>  
> PPP = read.csv(‘rate[1]’)
> PPP  # When I run PPP in R, it gives contents of
> the file rate1.csv i.e. I am able to read the required rate1
> file. But if I run following commands, I get errors.
>  
> newrate = NULL
>  
> 
> Maybe try:
> 
> newrate <- list()
> 
> and leave everything else as it is.
> 
> just an idea, 
> 
>  
> for (i in 1:n)
>    {
>     newrate[i] = read.csv(rates[i])
>    }
>  
> I need to read all these four files for my further
> analysis. Please guide.
>  
>  
> Regards
>  
> Maithili
>  
>  
> 
> 
>      The INTERNET now has a personality. YOURS! See your
> Yahoo! Homepage.
>        [[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.
> 
> 
> 
> 
> 
> [[elided Yahoo spam]]
> 
>     [[alternative HTML version deleted]]
> 
> 
> -Inline Attachment Follows-
> 
> __
> R-help@r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
> 


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

__
R-help@r-project.or

Re: [R] Is SEM package of R suitable for sem analysis

2009-12-26 Thread Bruno Falissard
A few years ago it could have been true, but now the package has improved
(especially with the bootstrap procedure).
At the moment there is no argument to recommend AMOS.
Of course, some software like Mplus are actually better, but very
specialized (and rather expensive).
This is only a personal point of view.
Bruno




Bruno Falissard
INSERM U669, PSIGIAM
"Paris Sud Innovation Group in Adolescent Mental Health"
Maison de Solenn
97 Boulevard de Port Royal
75679 Paris cedex 14, France
tel : (+33) 6 81 82 70 76
fax : (+33) 1 58 41 28 43
web site : http://perso.wanadoo.fr/bruno.falissard/



-Message d'origine-
De : r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] De
la part de Reeyarn_???_10928113
Envoyé : samedi 26 décembre 2009 12:50
À : R-help@r-project.org
Objet : [R] Is SEM package of R suitable for sem analysis


Dears,

I'm a college student and In doing my statistics homework.

I use R with SEM package as my tool for sem analysis,
but my teacher told me AMOS is more suitable for such analysis.

Could someone help tell me whether it is true
that some commercial software is better accepted in academic fields?

Sorry if I should not post such topics here.

-- 
Best Regards,
Reeyarn T. Lee

Accounting Dept, Guanghua School of Management,
Peking University, Beijing, P.R. China

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

2009-12-26 Thread Maithili Shiva
Dear R helpers / Johannes Sir,
 
Unfortunately it didn't work.

I am getting following warning messages.
 
1: In neweate[i] = read.csv(rates[i]) :
  number of items to replace is not a multiple of replacement length.
2:  similar message
3:  similar message
4: similar message
 
Let me be specific in my problem.
 
I have three csv files as 
 
rate1.csv
r1        r2        r3        r4        
r5         r6
10.1   10.25   10.25   10.50   10.50    10.75
 
rate2.csv
r1        r2        r3        r4        
r5         r6
15.1   15.45   15.45   15.70   15.70    15.90
 
rate3.csv
r1        r2        r3        r4        
r5         r6
18.3   18.50   18.50   18.65   18.65    18.95
 
Normally I can read these files as 
 
newrate1  =  read.csv('rate1.csv'')
newrate2  =  read.csv('rate2.csv')
newrate3  =  read.csv('rate3.csv')
 
However, due to some other requirement first I have to define following R code
 
n = 3 
 
rate_name = NULL
 
for (i in 1:n)

rate_name[i] = (paste(`rate', i, ‘.csv`, sep = ‘’))

# rate_name gives "rate1.csv" "rate2.csv" "ratë3.csv"
 
 
### MY TASK
 
I need to use the rate_names to read the actual rate1.csv, rate2.csv and 
rate3.csv files.
 
When I use the following code
 
newrate <- list()
for (i in 1:n)
   {
    newrate[i] = read.csv(rate_name[i])
   }

I get following warning messages
 
1: In newrate[i] = read.csv(rate_name[i]) :
  number of items to replace is not a multiple of replacement length
2: similar message
3: similar message
 
 
## APPROACH II
 
PPP = matrix(data = rate_name, nrow = 1, ncol = 3, byrow = FALSE)
X = matrix(data = NA, nrow = 3, ncol = 6, byrow = FALSE)
 
for (j in 1:3)
X = read.csv(PPP[1, j])
 
# X returns  (i.e. only first record is taken)
 
r1        r2        r3        r4        
r5         r6
10.1   10.25   10.25   10.50   10.50    10.75
 
 
Please guide
 
With regards
 
Maithili
 
 
--- On Sat, 26/12/09, Johannes Signer  wrote:


From: Johannes Signer 
Subject: Re: [R] Reading Input file
To: "Maithili Shiva" 
Cc: r-help@r-project.org
Date: Saturday, 26 December, 2009, 9:42 AM





On Sat, Dec 26, 2009 at 10:21 AM, Maithili Shiva  
wrote:



Dear R helpers
 
I have some files in my say 'WORK' directory and the file names are say 
rate1.csv, rate2.csv, rate3.csv, rate4.csv
 
Because of some other requirement, I need to run the following commands
 
n = 4 
 
rates = NULL
 
for (i in 1:n)

rates[i] = (paste(`rate', i, ‘.csv`, sep = ‘’))
 
# this gives me "rate1.csv" "rate2.csv" and so on
 
#My problem is now I need to relate these file names with actual files and read 
these files
# There are files rate1.csv, rate2.csv, rate3.csv, rate4.csv in my WORK 
directory.
 
 
# If I individually define
 
PPP = read.csv(‘rate[1]’)
PPP      # When I run PPP in R, it gives contents of the file rate1.csv 
i.e. I am able to read the required rate1 file. But if I run following 
commands, I get errors.
 
newrate = NULL
 

Maybe try:

newrate <- list()

and leave everything else as it is.

just an idea, 

 
for (i in 1:n)
   {
    newrate[i] = read.csv(rates[i])
   }
 
I need to read all these four files for my further analysis. Please guide.
 
 
Regards
 
Maithili
 
 


     The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.
       [[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.





[[elided Yahoo spam]]

[[alternative HTML version deleted]]

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


Re: [R] Help with SVM package Kernlab

2009-12-26 Thread Vishal Thapar
Hi All,

Thank you for your replies so far. I was hoping I could get some more input
from you on this issue. It seems to me that I have hit a dead end here and
would really appreciate some feedback. I have followed all the suggestions
you have mentioned but they still this is stuck. Earlier I thought that it
was a "factor" issue but now even that is not the error. Here is the script
and the error. Thanks for your help. I have attached the sample test file as
well as the training file in case you would like to run it locally.
-
library(seqinr)
library("kernlab")

### Reading in the data
mars500_1_fasta = read.fasta("toClassify500_1.fasta")
mars500_1_seq = t(getSequence(mars500_1_fasta)) # get the sequences from the
fasta object
mars500_1_df = as.data.frame(mars500_1_seq,stringsAsFactors=FALSE) # convert
it to a Data Frame
class = append(rep("+",times=128),rep("-",times=128)) # add the Class field
to the data frame for classification
mars500_1_df = cbind(Class=class,mars500_1_df)
mars500_1_df = data.frame(lapply(mars500_1_df,factor)) #Finally apply the
factor() function
#
# Call the ksvm() function to create a model
mars500_1 <- ksvm(Class ~ ., data = mars500_1_df, kernel = "rbfdot", kpar =
"automatic", C = 60, cross = 3, prob.model = TRUE)

testSeq_fa=read.fasta("temp1.fasta")
testSeq_seq=t(getSequence(testSeq_fa))
testSeq_df=as.data.frame(testSeq_seq,stringsAsFactors=FALSE)
testSeq_df = cbind(Class="-",testSeq_df)
testSeq_df = data.frame(lapply(testSeq_df,factor))
predict(mars500_1,testSeq_df)

Error in .local(object, ...) : test vector does not match model !

Thanks in advance.

Sincerely,

Vishal


On Fri, Dec 25, 2009 at 8:10 AM, Vishal Thapar wrote:

> Hi,
>
> I seem to have made some headway on this problem but its still not solved.
> It seems like this is a "factor" issue. When I read my training set, I read
> it with read.csv() which converts each of the columns as "factors". From
> this if I take a single row as my testSeq, it works great. On the other
> hand, when I read in my test sequence from a Fasta file, I am using the
> "seqinr" package's function "readFasta()" or if read a sequence directly
> from a file I am using "scan()": eg:
>
> train500 = read.csv("toClassify500_1.csv",header=TRUE) # reading the
> training set
> modelforSVM <- ksvm(Class ~ ., data = train500, kernel = "rbfdot", kpar =
> "automatic", C = 60, cross = 3, prob.model = TRUE)
> Now if I do:
> tindex =sample(1:dim(train500)[1], 1)
> testSeq=train500[tindex,]
> predict(modelforSVM, testSeq);
> It works great.
>
> BUT if I do:
>
> my.file=file("chr4_seqs.fasta", open="r")
> chr4Seq = scan(my.file,list("",""),nlines=2) # read the data from a fasta
> file using scan()
>
> seqId = chr4Seq[[1]];
> testSeq = as.data.frame(t(s2c(toupper(chr4Seq[[2]]
>  # the s2c function just converts the "STRING" to char vector "S" "T" "R"
> "I" "N" "G"
>
>
> predict(modelforSVM, testSeq);
> Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") :   contrasts
> can be applied only to factors with 2 or more levels
> -
> If I apply factor() to testSeq, it still doesn't work : eg:
>
> testSeq=data.frame(lapply(testSeq,factor))
> I still get Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") :
>   contrasts can be applied only to factors with 2 or more levels
>
> Another thing I tried was reading the fasta file using the readFasta()
> function and taking a sample input from the training set itself:
>
> data500_1_fasta = read.fasta("toClassify500.fasta") # read a fasta file via
> the seqinr package
> data500_1_seq = t(getSequence(data500_1_fasta)) # get the sequences from
> it, 256 sequences, first 128 are +, next 128 are -
> data500_1_df = as.data.frame(data500_1_seq) #make a data frame from it
> class = append(rep("+",times=128),rep("-",times=128)) # add the class
> column to it
> data500_1_df = cbind(Class=class,data500_1_df)
> data500_1_df = data.frame(lapply(data500_1_df,factor)) #finally apply the
> factor() on the data frame
>
> #Now train and get the model
>
> modelforSVM <- ksvm(Class ~ ., data = data500_1_df, kernel = "rbfdot", kpar
> = "automatic", C = 60, cross = 3, prob.model = TRUE)
>
> and finally:
> tindex =sample(1:dim(data500_1_df)[1], 1)
> testSeq=data500_1_df[tindex,]
>
> predict(modelforSVM, testSeq);
>
> Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") :   contrasts
> can be applied only to factors with 2 or more levels
>
> I am very confused at this point. What am I doing wrong? How do I use the
> factor() function properly so that I don't get this error? Am I in the right
> direction at all?
>
> Thanks in anticipation of your help.
>
> -vishal
>
>
>
>


-- 
Vishal Thapar, Ph.D.
Post Doctoral Researcher
Cold Spring Harbor Lab
Williams Bldg

1 Bungtown Road
Cold Spring Harbor, NY - 11724
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the postin

[R] Is SEM package of R suitable for sem analysis

2009-12-26 Thread Reeyarn_李智洋_10928113
Dears,

I'm a college student and In doing my statistics homework.

I use R with SEM package as my tool for sem analysis,
but my teacher told me AMOS is more suitable for such analysis.

Could someone help tell me whether it is true
that some commercial software is better accepted in academic fields?

Sorry if I should not post such topics here.

-- 
Best Regards,
Reeyarn T. Lee

Accounting Dept, Guanghua School of Management,
Peking University, Beijing, P.R. China

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


Re: [R] String question

2009-12-26 Thread Peter Dalgaard

Knut Krueger wrote:



Will this do?

temp <- paste("m", 1:3, sep="",collapse=",")

  

Unfortunately not, because I explained the example not detailed enough.
The string could have different Items, like November, December, Monday, 
Tuesday, Daylight and so on
Therefore I must count the Items of the string separated by "," or 
change the vector to a string


The right hint was there, I think:

> paste(c("m1","m2","m3"),collapse=",")
[1] "m1,m2,m3"


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

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


Re: [R] Reading Input file

2009-12-26 Thread Johannes Signer
On Sat, Dec 26, 2009 at 10:21 AM, Maithili Shiva
wrote:

>
>
> Dear R helpers
>
> I have some files in my say 'WORK' directory and the file names are say
> rate1.csv, rate2.csv, rate3.csv, rate4.csv
>
> Because of some other requirement, I need to run the following commands
>
> n = 4
>
> rates = NULL
>
> for (i in 1:n)
>
> rates[i] = (paste(`rate', i, ‘.csv`, sep = ‘’))
>
> # this gives me "rate1.csv" "rate2.csv" and so on
>
> #My problem is now I need to relate these file names with actual files and
> read these files
> # There are files rate1.csv, rate2.csv, rate3.csv, rate4.csv in my WORK
> directory.
>
>
> # If I individually define
>
> PPP = read.csv(‘rate[1]’)
> PPP  # When I run PPP in R, it gives contents of the file rate1.csv
> i.e. I am able to read the required rate1 file. But if I run following
> commands, I get errors.
>
> newrate = NULL
>
>
Maybe try:

newrate <- list()

and leave everything else as it is.

just an idea,



> for (i in 1:n)
>{
> newrate[i] = read.csv(rates[i])
>}
>
> I need to read all these four files for my further analysis. Please guide.
>
>
> Regards
>
> Maithili
>
>
>
>
>  The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.
>[[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

[[alternative HTML version 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] Reading Input file

2009-12-26 Thread Maithili Shiva


Dear R helpers
 
I have some files in my say 'WORK' directory and the file names are say 
rate1.csv, rate2.csv, rate3.csv, rate4.csv
 
Because of some other requirement, I need to run the following commands
 
n = 4  
 
rates = NULL
 
for (i in 1:n)

rates[i] = (paste(`rate', i, ‘.csv`, sep = ‘’))
 
# this gives me "rate1.csv" "rate2.csv" and so on 
 
#My problem is now I need to relate these file names with actual files and read 
these files
# There are files rate1.csv, rate2.csv, rate3.csv, rate4.csv in my WORK 
directory.
 
 
# If I individually define 
 
PPP = read.csv(‘rate[1]’) 
PPP      # When I run PPP in R, it gives contents of the file rate1.csv 
i.e. I am able to read the required rate1 file. But if I run following 
commands, I get errors. 
  
newrate = NULL 
  
for (i in 1:n) 
   {
    newrate[i] = read.csv(rates[i]) 
   } 
  
I need to read all these four files for my further analysis. Please guide. 
  
  
Regards 
  
Maithili 
  
 


  The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. 
[[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.