[R] Built-in Code behind SVM

2009-04-09 Thread Shubha Vishwanath Karanth
Hi R,

 

I need to see the inner code behind the function "svm" in the package
e1071. I enter svm in the console and get the below output.

 

> svm

function (x, ...) 

UseMethod("svm")



 

Is there any way I can look into the code of what svm (support vector
machine) is doing? 

 

Thanks a lot for your help...

 

Thanks and Regards, Shubha

This e-mail may contain confidential and/or privileged i...{{dropped:13}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 automatically select certain columns using for loop in dataframe

2009-04-09 Thread milton ruser
In fact you can use only

for (each_name in col_names) {
   sub.data <- subset( all.data,
   select = c( paste("NUM_", each_name, sep = '') ,
   paste("NAME_", each_name, sep = '') )
 )
 sub.data.2<-subset(sub.data, !is.na(sub.data[,2]))
print(sub.data.2)
}
Because:

!is.na( paste("NAME_", each_name, sep = '') )
only test if the result of the paste() is not null, and never will be null.
Maybe you need to improve and way of evaluate if the expression
that paste() result is null or not... but I don't know how do that.

bests..

miltinho

On Thu, Apr 9, 2009 at 11:30 PM, milton ruser wrote:

> Hi Ferry,
>
> It is not so elegant, but you can try
>
> for (each_name in col_names) {
>
>sub.data <- subset( all.data,
>!is.na( paste("NAME_", each_name, sep = '') ),
>select = c( paste("NUM_", each_name, sep = '') ,
> paste("NAME_", each_name, sep = '') )
>  )
> sub.data.2<-subset(sub.data, !is.na(sub.data[,2]))
>print(sub.data.2)
>
> }
>
>
> On Thu, Apr 9, 2009 at 6:30 PM, Ferry  wrote:
>
>> Hi,
>>
>> I am trying to display / print certain columns in my data frame that share
>> certain condition (for example, part of the column name). I am using for
>> loop, as follow:
>>
>> # below is the sample data structure
>> all.data <- data.frame( NUM_A = 1:5, NAME_A = c("Andy", "Andrew", "Angus",
>> "Alex", "Argo"),
>>NUM_B = 1:5, NAME_B = c(NA, "Barn", "Bolton",
>> "Bravo", NA),
>>NUM_C = 1:5, NAME_C = c("Candy", NA, "Cecil",
>> "Crayon", "Corey"),
>>NUM_D = 1:5, NAME_D = c("David", "Delta", NA, NA,
>> "Dummy") )
>>
>> col_names <- c("A", "B", "C", "D")
>>
>> > all.data
>>  NUM_A NAME_A NUM_B NAME_B NUM_C NAME_C NUM_D NAME_D
>> 1 1   Andy 11  Candy 1  David
>> 2 2 Andrew 2   Barn 22  Delta
>> 3 3  Angus 3 Bolton 3  Cecil 3   
>> 4 4   Alex 4  Bravo 4 Crayon 4   
>> 5 5   Argo 55  Corey 5  Dummy
>> >
>>
>> Then for each col_names, I want to display the columns:
>>
>> for (each_name in col_names) {
>>
>>sub.data <- subset( all.data,
>>!is.na( paste("NAME_", each_name, sep = '') ),
>>select = c( paste("NUM_", each_name, sep = '')
>> ,
>> paste("NAME_", each_name, sep = '') )
>>  )
>>print(sub.data)
>> }
>>
>> the "incorrect" result:
>>
>> NUM_A NAME_A
>> 1 1   Andy
>> 2 2 Andrew
>> 3 3  Angus
>> 4 4   Alex
>> 5 5   Argo
>>  NUM_B NAME_B
>> 1 1   
>> 2 2   Barn
>> 3 3 Bolton
>> 4 4  Bravo
>> 5 5   
>>  NUM_C NAME_C
>> 1 1  Candy
>> 2 2   
>> 3 3  Cecil
>> 4 4 Crayon
>> 5 5  Corey
>>  NUM_D NAME_D
>> 1 1  David
>> 2 2  Delta
>> 3 3   
>> 4 4   
>> 5 5  Dummy
>> >
>>
>> What I want to achieve is that the result should only display the NUM and
>> NAME that is not NA. Here, the NA can be NULL, or zero (or other specific
>> values).
>>
>> the "correct" result:
>>
>> NUM_A NAME_A
>> 1 1   Andy
>> 2 2 Andrew
>> 3 3  Angus
>> 4 4   Alex
>> 5 5   Argo
>>  NUM_B NAME_B
>>  2 2   Barn
>> 3 3 Bolton
>> 4 4  Bravo
>>   NUM_C NAME_C
>> 1 1  Candy
>>  3 3  Cecil
>> 4 4 Crayon
>> 5 5  Corey
>>  NUM_D NAME_D
>> 1 1  David
>> 2 2  Delta
>> 5 5  Dummy
>> >
>>
>> I am guessing that I don't use the correct type on the following statement
>> (within the subset in the loop):
>> !is.na( paste("NAME_", each_name, sep = '') )
>>
>> But then, I might be completely using a wrong approach.
>>
>> Any idea is definitely appreciated.
>>
>> Thank you,
>>
>> Ferry
>>
>>[[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.


Re: [R] how to automatically select certain columns using for loop in dataframe

2009-04-09 Thread milton ruser
Hi Ferry,

It is not so elegant, but you can try

for (each_name in col_names) {

   sub.data <- subset( all.data,
   !is.na( paste("NAME_", each_name, sep = '') ),
   select = c( paste("NUM_", each_name, sep = '') ,
paste("NAME_", each_name, sep = '') )
 )
sub.data.2<-subset(sub.data, !is.na(sub.data[,2]))
   print(sub.data.2)
}


On Thu, Apr 9, 2009 at 6:30 PM, Ferry  wrote:

> Hi,
>
> I am trying to display / print certain columns in my data frame that share
> certain condition (for example, part of the column name). I am using for
> loop, as follow:
>
> # below is the sample data structure
> all.data <- data.frame( NUM_A = 1:5, NAME_A = c("Andy", "Andrew", "Angus",
> "Alex", "Argo"),
>NUM_B = 1:5, NAME_B = c(NA, "Barn", "Bolton",
> "Bravo", NA),
>NUM_C = 1:5, NAME_C = c("Candy", NA, "Cecil",
> "Crayon", "Corey"),
>NUM_D = 1:5, NAME_D = c("David", "Delta", NA, NA,
> "Dummy") )
>
> col_names <- c("A", "B", "C", "D")
>
> > all.data
>  NUM_A NAME_A NUM_B NAME_B NUM_C NAME_C NUM_D NAME_D
> 1 1   Andy 11  Candy 1  David
> 2 2 Andrew 2   Barn 22  Delta
> 3 3  Angus 3 Bolton 3  Cecil 3   
> 4 4   Alex 4  Bravo 4 Crayon 4   
> 5 5   Argo 55  Corey 5  Dummy
> >
>
> Then for each col_names, I want to display the columns:
>
> for (each_name in col_names) {
>
>sub.data <- subset( all.data,
>!is.na( paste("NAME_", each_name, sep = '') ),
>select = c( paste("NUM_", each_name, sep = '') ,
> paste("NAME_", each_name, sep = '') )
>  )
>print(sub.data)
> }
>
> the "incorrect" result:
>
> NUM_A NAME_A
> 1 1   Andy
> 2 2 Andrew
> 3 3  Angus
> 4 4   Alex
> 5 5   Argo
>  NUM_B NAME_B
> 1 1   
> 2 2   Barn
> 3 3 Bolton
> 4 4  Bravo
> 5 5   
>  NUM_C NAME_C
> 1 1  Candy
> 2 2   
> 3 3  Cecil
> 4 4 Crayon
> 5 5  Corey
>  NUM_D NAME_D
> 1 1  David
> 2 2  Delta
> 3 3   
> 4 4   
> 5 5  Dummy
> >
>
> What I want to achieve is that the result should only display the NUM and
> NAME that is not NA. Here, the NA can be NULL, or zero (or other specific
> values).
>
> the "correct" result:
>
> NUM_A NAME_A
> 1 1   Andy
> 2 2 Andrew
> 3 3  Angus
> 4 4   Alex
> 5 5   Argo
>  NUM_B NAME_B
>  2 2   Barn
> 3 3 Bolton
> 4 4  Bravo
>   NUM_C NAME_C
> 1 1  Candy
>  3 3  Cecil
> 4 4 Crayon
> 5 5  Corey
>  NUM_D NAME_D
> 1 1  David
> 2 2  Delta
> 5 5  Dummy
> >
>
> I am guessing that I don't use the correct type on the following statement
> (within the subset in the loop):
> !is.na( paste("NAME_", each_name, sep = '') )
>
> But then, I might be completely using a wrong approach.
>
> Any idea is definitely appreciated.
>
> Thank you,
>
> Ferry
>
>[[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.


Re: [R] Subset a data frame for plotting

2009-04-09 Thread David Winsemius
Jim's points are well taken. I wonder if you might get greater  
efficiency by examining the opportunities in the lattice or ggplot2  
packages that allow specification of grouping variables. It might get  
tedious creating all those micro-data.frames and might not really be  
necessary.

From the first example on the xyplots help page:

library(lattice)
Depth <- equal.count(quakes$depth, number=8, overlap=.1) # Depth is  
used for grouping

xyplot(lat ~ long | Depth, data = quakes)
update(trellis.last.object(),
   strip = strip.custom(strip.names = TRUE, strip.levels = TRUE),
   par.strip.text = list(cex = 0.75),
   aspect = "iso")

--
David Winsemius
On Apr 9, 2009, at 9:32 PM, jim holtman wrote:


I am not sure what you are trying to assign a value to '200706183<-';
does not look like a valid object name.  This should work:

x200706183<-subset(AllData, ID == 200706183)

Notice the use of the '==' for the logical compare.

On Thu, Apr 9, 2009 at 8:58 PM, Paul Warren Simonin
 wrote:

Hello,

 I have a question regarding how to subset/select parts of a data  
frame

(matrix) in order to plot data associated only with this subset.
Specifically I have a large data frame in which one column contains  
ID

values (dates), and other columns contain data I would like to plot
(temperature, light, etc.). I would like to break up this large  
matrix so as
to plot data associated with specific ID values (dates) separately.  
I have
learned of several commands that supposedly subset matrices in this  
manner

and have tried the following code with no success:

200706183<-subset(AllData, ID = 200706183)
200706183<-gx.subset(AllData, ID == 200706183)
200706183<-subset(x=AllData, AllData$ID = 200706183)
200706183<-gx.subset(x=AllData, AllData$ID == 200706183)

In using this code my plan was to create smaller data frame objects  
which I
could then plot. My first question, though, is whether this is the  
correct
approach. Is there a more efficient way I can create plots  
conditional on

certain criteria such as "code = 200706183" ?
 If I do need to first create separate smaller data frames, how do  
I go

about doing this? Am I missing something in the above commands?
 Any other advice is certainly welcome too, as I admit to being a  
bit new to

R. Thank you very much for any answers, tips, suggestions, etc.!

Best wishes,
Paul Simonin

--
Paul W. Simonin
Graduate Research Assistant, MS Program
Vermont Cooperative Fish and Wildlife Research Unit
The Rubenstein School of Environment and Natural Resources
University of Vermont
81 Carrigan Dr.
Burlington, VT 05405
Ph:802-656-3153

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Subset a data frame for plotting

2009-04-09 Thread jim holtman
I am not sure what you are trying to assign a value to '200706183<-';
does not look like a valid object name.  This should work:

x200706183<-subset(AllData, ID == 200706183)

Notice the use of the '==' for the logical compare.

On Thu, Apr 9, 2009 at 8:58 PM, Paul Warren Simonin
 wrote:
> Hello,
>
>  I have a question regarding how to subset/select parts of a data frame
> (matrix) in order to plot data associated only with this subset.
> Specifically I have a large data frame in which one column contains ID
> values (dates), and other columns contain data I would like to plot
> (temperature, light, etc.). I would like to break up this large matrix so as
> to plot data associated with specific ID values (dates) separately. I have
> learned of several commands that supposedly subset matrices in this manner
> and have tried the following code with no success:
>
> 200706183<-subset(AllData, ID = 200706183)
> 200706183<-gx.subset(AllData, ID == 200706183)
> 200706183<-subset(x=AllData, AllData$ID = 200706183)
> 200706183<-gx.subset(x=AllData, AllData$ID == 200706183)
>
> In using this code my plan was to create smaller data frame objects which I
> could then plot. My first question, though, is whether this is the correct
> approach. Is there a more efficient way I can create plots conditional on
> certain criteria such as "code = 200706183" ?
>  If I do need to first create separate smaller data frames, how do I go
> about doing this? Am I missing something in the above commands?
>  Any other advice is certainly welcome too, as I admit to being a bit new to
> R. Thank you very much for any answers, tips, suggestions, etc.!
>
> Best wishes,
> Paul Simonin
>
> --
> Paul W. Simonin
> Graduate Research Assistant, MS Program
> Vermont Cooperative Fish and Wildlife Research Unit
> The Rubenstein School of Environment and Natural Resources
> University of Vermont
> 81 Carrigan Dr.
> Burlington, VT 05405
> Ph:802-656-3153
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Subset a data frame for plotting

2009-04-09 Thread Paul Warren Simonin

Hello,

  I have a question regarding how to subset/select parts of a data  
frame (matrix) in order to plot data associated only with this subset.  
Specifically I have a large data frame in which one column contains ID  
values (dates), and other columns contain data I would like to plot  
(temperature, light, etc.). I would like to break up this large matrix  
so as to plot data associated with specific ID values (dates)  
separately. I have learned of several commands that supposedly subset  
matrices in this manner and have tried the following code with no  
success:


200706183<-subset(AllData, ID = 200706183)
200706183<-gx.subset(AllData, ID == 200706183)
200706183<-subset(x=AllData, AllData$ID = 200706183)
200706183<-gx.subset(x=AllData, AllData$ID == 200706183)

In using this code my plan was to create smaller data frame objects  
which I could then plot. My first question, though, is whether this is  
the correct approach. Is there a more efficient way I can create plots  
conditional on certain criteria such as "code = 200706183" ?
  If I do need to first create separate smaller data frames, how do I  
go about doing this? Am I missing something in the above commands?
  Any other advice is certainly welcome too, as I admit to being a  
bit new to R. Thank you very much for any answers, tips, suggestions,  
etc.!


Best wishes,
Paul Simonin

--
Paul W. Simonin
Graduate Research Assistant, MS Program
Vermont Cooperative Fish and Wildlife Research Unit
The Rubenstein School of Environment and Natural Resources
University of Vermont
81 Carrigan Dr.
Burlington, VT 05405
Ph:802-656-3153

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


Re: [R] Random Cluster Generation Question

2009-04-09 Thread David Winsemius

Try:
> clust <- rMatClust(10, 0.05, 50)
> plot(clust)
> Y <- rThomas(10, 0.05, 50)
> plot(Y)


On Apr 9, 2009, at 7:28 PM, Jason L. Simms wrote:


Hello,

Thanks for your note.  I recognize that the points per cluster is
random, and also that it is possible to set the mean number of points
per cluster through the function.  What I was hoping was that I could
specify a maximum number of points overall across all clusters, but
conceptually I don't know how that could even be implemented.  I ended
up adjusting the parameters of the function until I produced right
around 2,000 points in a 10x10 box, and then I just multiplied
everything by 100.  Not sure whether it's perfect, but I suspect that
it will work for my needs currently.

I'll look into the rThomas() function, too.  I am much more of an
applied stats person, so the subtle (or even not-so-subtle)
differences and advantages/disadvantages between a Thomas Process and
a Matern Process are unclear to me at the moment.

Jason

On Thu, Apr 9, 2009 at 7:06 PM, David Winsemius > wrote:


On Apr 9, 2009, at 5:01 PM, Jason L. Simms wrote:


Hello,

I am fairly new to R, but I am not new to programming at all.  I  
want

to generate random clusters in a 1,000x1,000 box such that I end up
with a total of about 2,000 points.  Once done, I need to export the
X,Y coordinates of the points.

I have looked around, and it seems that the spatstat package has  
what
I need.  The rMatClust() function can generate random clusters,  
but I

have run into some problems.

First, I can't seem to specify that I want x number of points.


The number of points per cluster IS random.

So, right now it appears that if I want around 2,000 total points  
that I

must play around with the parameters of the function (e.g., mean
number of points per cluster, cluster radius, etc.) until I end up
with roughly 2,000 points.

More problematic, however, is that specifying a 1,000x1,000 box is  
too

much to handle.  I have been running the following function for over
24 hours straight on a decent computer and it has not stopped yet:

clust <- rMatClust(1, 50, 5, win=owin(c(0,1000),c(0,1000)))


It might well be due to the 1000 x 1000 dimensions but it is  
because of your
parameters. It took a significant amount of time to yield 4-10  
points on a 1
x 1 window. Whereas this particular invocation much more quickly  
produced
2707 points with a mean of 100 points per uniform cluster within a  
1 x 1

square:

Y <- rMatClust(20, 0.05, 100)

If you wanted the x and y dimensions to be in the range of 0-1000,   
couldn't

you just multiply the x and y values inside Y by 1000.
 Y$x <- 1000*Y$x
 Y$y <- 1000*Y$y
 plot(Y) # cannot see any points, probably because the plot.kkpm  
method is

using
# internal ranges inside that Y object. So you might loose the  
ability to

use
# other functions in that package
 plot(Y$x, Y$y)  # as expected and took seconds at most.

I would think that the most important task would be deciding on the  
function
that controls the intensity process of the "offspring points". The  
points in
this simple example clearly violate my notions of randomness  
because of the

sharp edges at the cluster boundaries. So, you may want to examine
rThomas(...) in the same package.

There is, of course, a SIG spatial stats mailing list full of  
people better

qualified than I on such questions.


Clearly, I need to rethink my strategy.  Could I generate the points
in a 10x10 box with a radius of .5 and then multiply out the  
resulting
point coordinates by 100?  Is there another package that might  
meet my

needs better than spatstat for easy cluster generation?

Any suggestions are appreciated.
--
Jason L. Simms, M.A.
USF Graduate Multidisciplinary Scholar


David Winsemius, MD
Heritage Laboratories
West Hartford, CT






--
Jason L. Simms, M.A.
USF Graduate Multidisciplinary Scholar
Co-President, Graduate Assistants United
Ph.D. / M.P.H. Student
Departments of Anthropology and Environmental and Occupational Health
University of South Florida


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] Los Angeles area R users group's first meeting

2009-04-09 Thread Szilard Pafka
We would like to invite you to the Los Angeles area R user group's first
meeting. This group is aimed to bring together practitioners (from
industry and academia alike) in order to exchange knowledge and
experience in solving data analysis/statistical problems by using R.
More information about the group at:
http://www.meetup.com/LAarea-R-usergroup/

Meeting: Four case studies of using R

The goal of this first meeting is to bring together people of a wide
range of interests related to R and to open a forum for discussions and
further interaction.

Agenda:

- Introduction
- Using R in research (Jan de Leeuw, UCLA)
- Using R in applications related to credit card transactions (Szilard
Pafka, Epoch)
- Using R in teaching (Rob Gould, UCLA)
- Using R in consulting (Brigid Brett-Esborn, UCLA)
- Q&A, general discussions
- Discussions/networking

We plan 15 minutes for each speaker and for the general discussions.
Then participants are encouraged to initiate discussions with each other
(the place is reserved until 9pm). Bottled water and cookies will be
available free of charge.

Please RSVP on meetup.com (http://www.meetup.com/LAarea-R-usergroup/) as
places are limited.

Those who are unfamiliar with R but would like to get basic hands-on
knowledge (installation, working with data, plotting etc.) are welcome
to attend the “Basic R” course (free) of the UCLA Statistical Consulting
Center, 5-7pm (right before the meetup) in the same room. Please email
to su...@stat.ucla.edu as places are limited. You can also download the
notes, or attend the course at another time at your convenience (see
http://scc.stat.ucla.edu/mini-courses/ ).

Our speakers:
- Jan de Leeuw is Distinguished Professor and Chair at UCLA Department
of Statistics. He is also Editor in Chief of the Journal of Statistical
Software (the primary journal for publishing work related to R) and the
Journal of Multivariate Analysis.
- Szilard Pafka, PhD is Chief Scientist at Epoch, a credit card
transactions processor. He uses R for various data analysis, statistical
modeling and visualization projects. Previously, he worked on a variety
of research problems ranging from physics to financial prices.
- Rob Gould received his PhD from UC San Diego in 1994 and has been at
UCLA since. He is director of the UCLA Center for Statistics Education,
Associate Director of Professional Development of the Consortium of the
Advancement of Undergraduate Statistics Education, and former chair of
the ASA Advisory Committee on Teacher Enhancement.
- Brigid Brett-Esborn is a PhD student in the Department of Statistics
at UCLA.  She also works as a consultant with the Department's
Statistical Consulting Center and the Statistical Computing group within
UCLA's Academic Technology Services department.  She has contributed to
the Journal of Statistical Software.

Time and venue:
May 7, 2009, Thursday, 7-9pm
UCLA Boelter Hall Room 9413
(this room is next to the Statistical Consulting Center, Boelter Hall 9434)
The only way to access the venue is from the southeast corner of Boelter
Hall (southeast elevator/southeast stairwell). Directions here:
http://scc.stat.ucla.edu/contact-us/map/
To find Boelter Hall on campus: http://maps.ucla.edu/campus/
Information on how to get to UCLA: http://www.ucla.edu/map/

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


Re: [R] CFA in R/sem package

2009-04-09 Thread Jarrett Byrnes
Sure, something like that.  Store each model as an element of a list,  
and then use something like


for(i in 1:4){
indices<-combn(1:4, i)
for (j in 1:length(indices[1,])){
  new.model<-combine.models(model.pieces[ indices[,j] ] )
  #code for analysis
}
}

Or, if this doesn't fit your problem exactly, some similar approach.

On Apr 9, 2009, at 4:23 PM, Iuri Gavronski wrote:


Jarret,

I've donwloaded the zip file and installed, but maybe have lost some
pre-req check. I have manually installed sna.

Anyway, which would be the approach you suggest? Making (using my
example) 4 different models, one for each construct, then use
combine.models and add.to.models to create the 12 models to be
compared?

Best,

Iuri.

On Thu, Apr 9, 2009 at 8:13 PM, Jarrett Byrnes   
wrote:
install.packages("sem-additions",repos="http://R-Forge.R- 
project.org")


Sorry, it's sem-additions on r-forge.  Not sem.additions, which is  
what I
had originally called it.  But they won't take . in the name of a  
package.


On Apr 9, 2009, at 4:07 PM, Iuri Gavronski wrote:


Jarret,

Look:


install.packages("sem.additions", repos="http://R-Forge.R-project.org 
")


Warning message:
package ‘sem.additions’ is not available




Best,

Iuri.

On Thu, Apr 9, 2009 at 3:10 PM, Jarrett Byrnes 
wrote:


Ivan,

I recently put together the sem.additions package over at R forge  
in part
for just such a multiple model problem.  THere are a variety of  
methods

that
make it easy to add/delete links that could be automated with a  
for loop

and
something from the combn package, I think.

http://r-forge.r-project.org/projects/sem-additions/

-Jarrett

On Apr 9, 2009, at 6:39 AM, Iuri Gavronski wrote:


Hi,

I am not sure if R-help is the right forum for my question. If  
not,

please let me know.

I have to do some discriminant validity tests with some  
constructs. I
am using the method of doing a CFA constraining the correlation  
of a

pair of the constructs to 1 and comparing the chi-square of this
constrained model to the unconstrained model. If the chi-square
difference is not significant, then I cannot reject the null
hypothesis that the two constructs are equal.

Well, if you are going to test, say, 4 constructs (A, B, C, and  
D),
you will have to have 2*C(4,2) = 12 models to test, 5  
constructs, 20

models, and so forth. A tedious and error prone process...

So far, I have been using AMOS for that shake, given that 1) my
university has the license, 2) my other colleagues use it, and  
3) I

know it ;)

I would like to know if any of you use R, namely the sem  
package, for

that application and if you can share your thoughts/experiences on
using it. I don't thing I would have problems "porting" my  
models to
R/sem, but I would like to know if there is an optimized process  
of
doing that tests, without manually coding all the dozens of  
models.


Best,

Iuri.

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


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



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



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


Re: [R] Random Cluster Generation Question

2009-04-09 Thread Jason L. Simms
Hello,

Thanks for your note.  I recognize that the points per cluster is
random, and also that it is possible to set the mean number of points
per cluster through the function.  What I was hoping was that I could
specify a maximum number of points overall across all clusters, but
conceptually I don't know how that could even be implemented.  I ended
up adjusting the parameters of the function until I produced right
around 2,000 points in a 10x10 box, and then I just multiplied
everything by 100.  Not sure whether it's perfect, but I suspect that
it will work for my needs currently.

I'll look into the rThomas() function, too.  I am much more of an
applied stats person, so the subtle (or even not-so-subtle)
differences and advantages/disadvantages between a Thomas Process and
a Matern Process are unclear to me at the moment.

Jason

On Thu, Apr 9, 2009 at 7:06 PM, David Winsemius  wrote:
>
> On Apr 9, 2009, at 5:01 PM, Jason L. Simms wrote:
>
>> Hello,
>>
>> I am fairly new to R, but I am not new to programming at all.  I want
>> to generate random clusters in a 1,000x1,000 box such that I end up
>> with a total of about 2,000 points.  Once done, I need to export the
>> X,Y coordinates of the points.
>>
>> I have looked around, and it seems that the spatstat package has what
>> I need.  The rMatClust() function can generate random clusters, but I
>> have run into some problems.
>>
>> First, I can't seem to specify that I want x number of points.
>
> The number of points per cluster IS random.
>
>> So, right now it appears that if I want around 2,000 total points that I
>> must play around with the parameters of the function (e.g., mean
>> number of points per cluster, cluster radius, etc.) until I end up
>> with roughly 2,000 points.
>>
>> More problematic, however, is that specifying a 1,000x1,000 box is too
>> much to handle.  I have been running the following function for over
>> 24 hours straight on a decent computer and it has not stopped yet:
>>
>> clust <- rMatClust(1, 50, 5, win=owin(c(0,1000),c(0,1000)))
>
> It might well be due to the 1000 x 1000 dimensions but it is because of your
> parameters. It took a significant amount of time to yield 4-10 points on a 1
> x 1 window. Whereas this particular invocation much more quickly produced
> 2707 points with a mean of 100 points per uniform cluster within a 1 x 1
> square:
>
> Y <- rMatClust(20, 0.05, 100)
>
> If you wanted the x and y dimensions to be in the range of 0-1000,  couldn't
> you just multiply the x and y values inside Y by 1000.
>  Y$x <- 1000*Y$x
>  Y$y <- 1000*Y$y
>  plot(Y) # cannot see any points, probably because the plot.kkpm method is
> using
> # internal ranges inside that Y object. So you might loose the ability to
> use
> # other functions in that package
>  plot(Y$x, Y$y)  # as expected and took seconds at most.
>
> I would think that the most important task would be deciding on the function
> that controls the intensity process of the "offspring points". The points in
> this simple example clearly violate my notions of randomness because of the
> sharp edges at the cluster boundaries. So, you may want to examine
> rThomas(...) in the same package.
>
> There is, of course, a SIG spatial stats mailing list full of people better
> qualified than I on such questions.
>>
>> Clearly, I need to rethink my strategy.  Could I generate the points
>> in a 10x10 box with a radius of .5 and then multiply out the resulting
>> point coordinates by 100?  Is there another package that might meet my
>> needs better than spatstat for easy cluster generation?
>>
>> Any suggestions are appreciated.
>> --
>> Jason L. Simms, M.A.
>> USF Graduate Multidisciplinary Scholar
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>



-- 
Jason L. Simms, M.A.
USF Graduate Multidisciplinary Scholar
Co-President, Graduate Assistants United
Ph.D. / M.P.H. Student
Departments of Anthropology and Environmental and Occupational Health
University of South Florida

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


Re: [R] CFA in R/sem package

2009-04-09 Thread Iuri Gavronski
Jarret,

I've donwloaded the zip file and installed, but maybe have lost some
pre-req check. I have manually installed sna.

Anyway, which would be the approach you suggest? Making (using my
example) 4 different models, one for each construct, then use
combine.models and add.to.models to create the 12 models to be
compared?

Best,

Iuri.

On Thu, Apr 9, 2009 at 8:13 PM, Jarrett Byrnes  wrote:
> install.packages("sem-additions",repos="http://R-Forge.R-project.org";)
>
> Sorry, it's sem-additions on r-forge.  Not sem.additions, which is what I
> had originally called it.  But they won't take . in the name of a package.
>
> On Apr 9, 2009, at 4:07 PM, Iuri Gavronski wrote:
>
>> Jarret,
>>
>> Look:
>>>
>>> install.packages("sem.additions", repos="http://R-Forge.R-project.org";)
>>
>> Warning message:
>> package ‘sem.additions’ is not available
>>>
>>
>> Best,
>>
>> Iuri.
>>
>> On Thu, Apr 9, 2009 at 3:10 PM, Jarrett Byrnes 
>> wrote:
>>>
>>> Ivan,
>>>
>>> I recently put together the sem.additions package over at R forge in part
>>> for just such a multiple model problem.  THere are a variety of methods
>>> that
>>> make it easy to add/delete links that could be automated with a for loop
>>> and
>>> something from the combn package, I think.
>>>
>>> http://r-forge.r-project.org/projects/sem-additions/
>>>
>>> -Jarrett
>>>
>>> On Apr 9, 2009, at 6:39 AM, Iuri Gavronski wrote:
>>>
 Hi,

 I am not sure if R-help is the right forum for my question. If not,
 please let me know.

 I have to do some discriminant validity tests with some constructs. I
 am using the method of doing a CFA constraining the correlation of a
 pair of the constructs to 1 and comparing the chi-square of this
 constrained model to the unconstrained model. If the chi-square
 difference is not significant, then I cannot reject the null
 hypothesis that the two constructs are equal.

 Well, if you are going to test, say, 4 constructs (A, B, C, and D),
 you will have to have 2*C(4,2) = 12 models to test, 5 constructs, 20
 models, and so forth. A tedious and error prone process...

 So far, I have been using AMOS for that shake, given that 1) my
 university has the license, 2) my other colleagues use it, and 3) I
 know it ;)

 I would like to know if any of you use R, namely the sem package, for
 that application and if you can share your thoughts/experiences on
 using it. I don't thing I would have problems "porting" my models to
 R/sem, but I would like to know if there is an optimized process of
 doing that tests, without manually coding all the dozens of models.

 Best,

 Iuri.

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

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


Re: [R] puzzling lm.fit errors

2009-04-09 Thread Ted Harding
On 09-Apr-09 22:53:51, Brendan Morse wrote:
> Hi everyone, I am running a monte carlo and am getting an error that I 
> haven't the slightest clue where to begin figuring it out. The error  
> is as follows:
> 
> Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...)
>:
>0 (non-NA) cases
> In addition: Warning message:
> In ltm.fit(X, betas, constraint, formula, con) :
>Hessian matrix at convergence is not positive definite; unstable  
> solution.
> 
> The puzzling aspect though is that it successfully runs a number of  
> complete iterations before this occurs. I am not sure what or where  
> this is going on.
> 
> Any suggestions?
> 
> Thanks very much (in advance)
> - Brendan

This is the sort of thing that can happen is the covariates in your
linear model lead to a model matrix which singular (or nearly so).
In other words, at least one of your covariate vectors is a linear
combination of the others (or nearly so).

The facts that (a) you are doing a Monte Carlo simulationm and
(b) you get a number of satisfactory runs and then it fails, suggest
that you are randomly creating covariate (independent-variable) values
as well as dependent-variable values.

If that is so, then the structure of your model may be such that it
is relatively likely for such singularity to arise. While not
particularly likely for continuous covariates, near-singularity can
nevertheless happen. It can be much more likely if you are generating
random levels of factors, since only a finite number of combinations
are possible, and sooner or later you will definitely hit exact
collinarity. And if you are using a fairly large number of covariates,
and not a large number of cases, then it can become really likely!

I'm only guessing, of course, and you can either agree with, or deny,
the above suggestions. Either way, it would help in clarifying the
problem to know the details of how your Monte Carlo simulation is
supposed to work.

Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 10-Apr-09   Time: 00:23:04
-- 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] CFA in R/sem package

2009-04-09 Thread Jarrett Byrnes

install.packages("sem-additions",repos="http://R-Forge.R-project.org";)

Sorry, it's sem-additions on r-forge.  Not sem.additions, which is  
what I had originally called it.  But they won't take . in the name of  
a package.


On Apr 9, 2009, at 4:07 PM, Iuri Gavronski wrote:


Jarret,

Look:
install.packages("sem.additions", repos="http://R-Forge.R- 
project.org")

Warning message:
package ‘sem.additions’ is not available




Best,

Iuri.

On Thu, Apr 9, 2009 at 3:10 PM, Jarrett Byrnes   
wrote:

Ivan,

I recently put together the sem.additions package over at R forge  
in part
for just such a multiple model problem.  THere are a variety of  
methods that
make it easy to add/delete links that could be automated with a for  
loop and

something from the combn package, I think.

http://r-forge.r-project.org/projects/sem-additions/

-Jarrett

On Apr 9, 2009, at 6:39 AM, Iuri Gavronski wrote:


Hi,

I am not sure if R-help is the right forum for my question. If not,
please let me know.

I have to do some discriminant validity tests with some  
constructs. I

am using the method of doing a CFA constraining the correlation of a
pair of the constructs to 1 and comparing the chi-square of this
constrained model to the unconstrained model. If the chi-square
difference is not significant, then I cannot reject the null
hypothesis that the two constructs are equal.

Well, if you are going to test, say, 4 constructs (A, B, C, and D),
you will have to have 2*C(4,2) = 12 models to test, 5 constructs, 20
models, and so forth. A tedious and error prone process...

So far, I have been using AMOS for that shake, given that 1) my
university has the license, 2) my other colleagues use it, and 3) I
know it ;)

I would like to know if any of you use R, namely the sem package,  
for

that application and if you can share your thoughts/experiences on
using it. I don't thing I would have problems "porting" my models to
R/sem, but I would like to know if there is an optimized process of
doing that tests, without manually coding all the dozens of models.

Best,

Iuri.

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


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



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


Re: [R] CFA in R/sem package

2009-04-09 Thread Iuri Gavronski
Jarret,

Look:
> install.packages("sem.additions", repos="http://R-Forge.R-project.org";)
Warning message:
package ‘sem.additions’ is not available
>

Best,

Iuri.

On Thu, Apr 9, 2009 at 3:10 PM, Jarrett Byrnes  wrote:
> Ivan,
>
> I recently put together the sem.additions package over at R forge in part
> for just such a multiple model problem.  THere are a variety of methods that
> make it easy to add/delete links that could be automated with a for loop and
> something from the combn package, I think.
>
> http://r-forge.r-project.org/projects/sem-additions/
>
> -Jarrett
>
> On Apr 9, 2009, at 6:39 AM, Iuri Gavronski wrote:
>
>> Hi,
>>
>> I am not sure if R-help is the right forum for my question. If not,
>> please let me know.
>>
>> I have to do some discriminant validity tests with some constructs. I
>> am using the method of doing a CFA constraining the correlation of a
>> pair of the constructs to 1 and comparing the chi-square of this
>> constrained model to the unconstrained model. If the chi-square
>> difference is not significant, then I cannot reject the null
>> hypothesis that the two constructs are equal.
>>
>> Well, if you are going to test, say, 4 constructs (A, B, C, and D),
>> you will have to have 2*C(4,2) = 12 models to test, 5 constructs, 20
>> models, and so forth. A tedious and error prone process...
>>
>> So far, I have been using AMOS for that shake, given that 1) my
>> university has the license, 2) my other colleagues use it, and 3) I
>> know it ;)
>>
>> I would like to know if any of you use R, namely the sem package, for
>> that application and if you can share your thoughts/experiences on
>> using it. I don't thing I would have problems "porting" my models to
>> R/sem, but I would like to know if there is an optimized process of
>> doing that tests, without manually coding all the dozens of models.
>>
>> Best,
>>
>> Iuri.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] Random Cluster Generation Question

2009-04-09 Thread David Winsemius


On Apr 9, 2009, at 5:01 PM, Jason L. Simms wrote:


Hello,

I am fairly new to R, but I am not new to programming at all.  I want
to generate random clusters in a 1,000x1,000 box such that I end up
with a total of about 2,000 points.  Once done, I need to export the
X,Y coordinates of the points.

I have looked around, and it seems that the spatstat package has what
I need.  The rMatClust() function can generate random clusters, but I
have run into some problems.

First, I can't seem to specify that I want x number of points.


The number of points per cluster IS random.

So, right now it appears that if I want around 2,000 total points  
that I

must play around with the parameters of the function (e.g., mean
number of points per cluster, cluster radius, etc.) until I end up
with roughly 2,000 points.

More problematic, however, is that specifying a 1,000x1,000 box is too
much to handle.  I have been running the following function for over
24 hours straight on a decent computer and it has not stopped yet:

clust <- rMatClust(1, 50, 5, win=owin(c(0,1000),c(0,1000)))


It might well be due to the 1000 x 1000 dimensions but it is because  
of your parameters. It took a significant amount of time to yield 4-10  
points on a 1 x 1 window. Whereas this particular invocation much more  
quickly produced 2707 points with a mean of 100 points per uniform  
cluster within a 1 x 1 square:


Y <- rMatClust(20, 0.05, 100)

If you wanted the x and y dimensions to be in the range of 0-1000,   
couldn't you just multiply the x and y values inside Y by 1000.

 Y$x <- 1000*Y$x
 Y$y <- 1000*Y$y
 plot(Y) # cannot see any points, probably because the plot.kkpm  
method is using
# internal ranges inside that Y object. So you might loose the ability  
to use

# other functions in that package
 plot(Y$x, Y$y)  # as expected and took seconds at most.

I would think that the most important task would be deciding on the  
function that controls the intensity process of the "offspring  
points". The points in this simple example clearly violate my notions  
of randomness because of the sharp edges at the cluster boundaries.  
So, you may want to examine rThomas(...) in the same package.


There is, of course, a SIG spatial stats mailing list full of people  
better qualified than I on such questions.


Clearly, I need to rethink my strategy.  Could I generate the points
in a 10x10 box with a radius of .5 and then multiply out the resulting
point coordinates by 100?  Is there another package that might meet my
needs better than spatstat for easy cluster generation?

Any suggestions are appreciated.
--
Jason L. Simms, M.A.
USF Graduate Multidisciplinary Scholar


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] puzzling lm.fit errors

2009-04-09 Thread Brendan Morse
Hi everyone, I am running a monte carlo and am getting an error that I  
haven't the slightest clue where to begin figuring it out. The error  
is as follows:


Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
  0 (non-NA) cases
In addition: Warning message:
In ltm.fit(X, betas, constraint, formula, con) :
  Hessian matrix at convergence is not positive definite; unstable  
solution.



The puzzling aspect though is that it successfully runs a number of  
complete iterations before this occurs. I am not sure what or where  
this is going on.


Any suggestions?

Thanks very much (in advance)
- Brendan

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


Re: [R] arima on defined lags

2009-04-09 Thread Gad Abraham

Gerard M. Keogh wrote:


Dear all,

The standard call to ARIMA in the base package such as

  arima(y,c(5,0,0),include.mean=FALSE)

  gives a full 5th order lag polynomial model with for example coeffs

  Coefficients:
   ar1ar2  ar3 ar4  ar5
0.4715  0.067  -0.1772  0.0256  -0.2550
  s.e.  0.1421  0.158   0.1569  0.1602   0.1469


Is it possible (I doubt it but am just checking) to define a more
parsimonous lag1 and lag 5 model with coeff ar1 and ar5?
Or do I need one of the other TS packages?


You can specify the "fixed" argument (with transform.pars=FALSE):

> arima(x, c(5, 0, 0), fixed=c(NA, 0, 0, 0, NA), include.mean=FALSE, 
transform.pars=FALSE)


Call:
arima(x = x, order = c(5, 0, 0), include.mean = FALSE, transform.pars = 
FALSE,

fixed = c(NA, 0, 0, 0, NA))

Coefficients:
  ar1  ar2  ar3  ar4 ar5
  -0.0483000  0.1355
s.e.   0.1010000  0.1031


--
Gad Abraham
Dept. CSSE and NICTA
The University of Melbourne
Parkville 3010, Victoria, Australia
email: gabra...@csse.unimelb.edu.au
web: http://www.csse.unimelb.edu.au/~gabraham

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


Re: [R] Cross-platforms solution to export R graphs

2009-04-09 Thread Emmanuel Charpentier
Le jeudi 09 avril 2009 à 15:04 +0200, Philippe Grosjean a écrit :
> Hello Rusers,
> 
> I have worked on a R Wiki page for solutions in exporting R graphs, 
> especially, the often-asked questions:
> - How can I export R graphs in vectorized format (EMF) for inclusion in 
>   MS Word or OpenOffice outside of Windows?
> - What is the best solution(s) for post-editing/annotating R graphs.
> 
> The page is at: 
> http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-misc:export.
> 
> I would be happy to receive your comments and suggestions to improve 
> this document.

Well, if you insist ...

The PDF import plugin in OpenOffice is still beta, and some report deem
it difficult to install correctly an/or flaky.  Having checked that both
MSWord (>=2000) and OpenOffice (>=2.4) import and display correctly (i.
e. vectorially, including fonts) EPS files, I switched to this format,
most notably for use with the marvellous Max Kuhn's odfWeave package,
which is a *must* for us working in state/administrative/corporate salt
mines, where \LaTeX is deemed obscene and plain \TeX causes seizures ...
The point is that this format doesn't need any intermediary step, thus
allowing for automatisation. Be aware, however, that the embedded EPS
images are not editable in-place by OpenOffice nor, as far as I know, by
MS Word. But my point was to *avoid* post-production as much as humanly
possible (I tend to be inhumanly lazy...).

HTH,

Emmanuel Charpentier

> All the best,
> 
> PhG

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 automatically select certain columns using for loop in dataframe

2009-04-09 Thread Ferry
Hi,

I am trying to display / print certain columns in my data frame that share
certain condition (for example, part of the column name). I am using for
loop, as follow:

# below is the sample data structure
all.data <- data.frame( NUM_A = 1:5, NAME_A = c("Andy", "Andrew", "Angus",
"Alex", "Argo"),
NUM_B = 1:5, NAME_B = c(NA, "Barn", "Bolton",
"Bravo", NA),
NUM_C = 1:5, NAME_C = c("Candy", NA, "Cecil",
"Crayon", "Corey"),
NUM_D = 1:5, NAME_D = c("David", "Delta", NA, NA,
"Dummy") )

col_names <- c("A", "B", "C", "D")

> all.data
  NUM_A NAME_A NUM_B NAME_B NUM_C NAME_C NUM_D NAME_D
1 1   Andy 11  Candy 1  David
2 2 Andrew 2   Barn 22  Delta
3 3  Angus 3 Bolton 3  Cecil 3   
4 4   Alex 4  Bravo 4 Crayon 4   
5 5   Argo 55  Corey 5  Dummy
>

Then for each col_names, I want to display the columns:

for (each_name in col_names) {

sub.data <- subset( all.data,
!is.na( paste("NAME_", each_name, sep = '') ),
select = c( paste("NUM_", each_name, sep = '') ,
paste("NAME_", each_name, sep = '') )
  )
print(sub.data)
}

the "incorrect" result:

NUM_A NAME_A
1 1   Andy
2 2 Andrew
3 3  Angus
4 4   Alex
5 5   Argo
  NUM_B NAME_B
1 1   
2 2   Barn
3 3 Bolton
4 4  Bravo
5 5   
  NUM_C NAME_C
1 1  Candy
2 2   
3 3  Cecil
4 4 Crayon
5 5  Corey
  NUM_D NAME_D
1 1  David
2 2  Delta
3 3   
4 4   
5 5  Dummy
>

What I want to achieve is that the result should only display the NUM and
NAME that is not NA. Here, the NA can be NULL, or zero (or other specific
values).

the "correct" result:

NUM_A NAME_A
1 1   Andy
2 2 Andrew
3 3  Angus
4 4   Alex
5 5   Argo
  NUM_B NAME_B
 2 2   Barn
3 3 Bolton
4 4  Bravo
   NUM_C NAME_C
1 1  Candy
 3 3  Cecil
4 4 Crayon
5 5  Corey
  NUM_D NAME_D
1 1  David
2 2  Delta
5 5  Dummy
>

I am guessing that I don't use the correct type on the following statement
(within the subset in the loop):
!is.na( paste("NAME_", each_name, sep = '') )

But then, I might be completely using a wrong approach.

Any idea is definitely appreciated.

Thank you,

Ferry

[[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] Convert bits to numbers in base 10

2009-04-09 Thread Gang Chen
Yes, such a concise and elegant solution!

Thanks a lot!

Gang

On Thu, Apr 9, 2009 at 5:51 PM, Marc Schwartz  wrote:
> I suspect that Gang was looking for something along the lines of:
>
>> sum(2 ^ (which(as.logical(rev(nn))) - 1))
> [1] 74
>
> You might also want to look at the digitsBase() function in Martin's sfsmisc
> package on CRAN.
>
> HTH,
>
> Marc Schwartz
>
> On Apr 9, 2009, at 4:34 PM, Jorge Ivan Velez wrote:
>
>> Dear Gang,
>> Try this:
>>
>> nn <- c(1, 0, 0, 1, 0, 1,0)
>> paste(nn,sep="",collapse="")
>>
>> See ?paste for more information.
>>
>> HTH,
>>
>> Jorge
>>
>>
>> On Thu, Apr 9, 2009 at 5:23 PM, Gang Chen  wrote:
>>
>>> I have some bits stored like the following variable nn
>>>
>>> (nn <- c(1, 0, 0, 1, 0, 1,0))
>>> [1] 1 0 0 1 0 1 0
>>>
>>> not in the format of
>>>
>>> 1001010
>>>
>>> and I need to convert them to numbers in base 10. What's an easy way to
>>> do
>>> it?
>>>
>>> TIA,
>>> Gang
>
>

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


Re: [R] Convert bits to numbers in base 10

2009-04-09 Thread Michael Conklin
Alternatively

(nn <- c(1, 0, 0, 1, 0, 1,0))
 [1] 1 0 0 1 0 1 0

  sum(2^(0:(length(nn)-1))*nn)

but of course it depends if your bits are stored big-endian or little-endian
so you might want


  sum(2^((length(nn)-1):0)*nn)


I like Marc's approach better (certainly more elegant). If you have the big vs 
little endian issue you can just remove the rev from Marc's code below.

Michael Conklin


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Marc Schwartz
Sent: Thursday, April 09, 2009 4:51 PM
To: Jorge Ivan Velez
Cc: R-help; Gang Chen
Subject: Re: [R] Convert bits to numbers in base 10

I suspect that Gang was looking for something along the lines of:

 > sum(2 ^ (which(as.logical(rev(nn))) - 1))
[1] 74

You might also want to look at the digitsBase() function in Martin's
sfsmisc package on CRAN.

HTH,

Marc Schwartz

On Apr 9, 2009, at 4:34 PM, Jorge Ivan Velez wrote:

> Dear Gang,
> Try this:
>
> nn <- c(1, 0, 0, 1, 0, 1,0)
> paste(nn,sep="",collapse="")
>
> See ?paste for more information.
>
> HTH,
>
> Jorge
>
>
> On Thu, Apr 9, 2009 at 5:23 PM, Gang Chen  wrote:
>
>> I have some bits stored like the following variable nn
>>
>> (nn <- c(1, 0, 0, 1, 0, 1,0))
>> [1] 1 0 0 1 0 1 0
>>
>> not in the format of
>>
>> 1001010
>>
>> and I need to convert them to numbers in base 10. What's an easy
>> way to do
>> it?
>>
>> TIA,
>> Gang

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Convert bits to numbers in base 10

2009-04-09 Thread Marc Schwartz

I suspect that Gang was looking for something along the lines of:

> sum(2 ^ (which(as.logical(rev(nn))) - 1))
[1] 74

You might also want to look at the digitsBase() function in Martin's  
sfsmisc package on CRAN.


HTH,

Marc Schwartz

On Apr 9, 2009, at 4:34 PM, Jorge Ivan Velez wrote:


Dear Gang,
Try this:

nn <- c(1, 0, 0, 1, 0, 1,0)
paste(nn,sep="",collapse="")

See ?paste for more information.

HTH,

Jorge


On Thu, Apr 9, 2009 at 5:23 PM, Gang Chen  wrote:


I have some bits stored like the following variable nn

(nn <- c(1, 0, 0, 1, 0, 1,0))
[1] 1 0 0 1 0 1 0

not in the format of

1001010

and I need to convert them to numbers in base 10. What's an easy  
way to do

it?

TIA,
Gang


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


Re: [R] Convert bits to numbers in base 10

2009-04-09 Thread Jorge Ivan Velez
Dear Gang,
Try this:

nn <- c(1, 0, 0, 1, 0, 1,0)
paste(nn,sep="",collapse="")

See ?paste for more information.

HTH,

Jorge


On Thu, Apr 9, 2009 at 5:23 PM, Gang Chen  wrote:

> I have some bits stored like the following variable nn
>
> (nn <- c(1, 0, 0, 1, 0, 1,0))
> [1] 1 0 0 1 0 1 0
>
> not in the format of
>
> 1001010
>
> and I need to convert them to numbers in base 10. What's an easy way to do
> it?
>
> TIA,
> Gang
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Convert bits to numbers in base 10

2009-04-09 Thread Gang Chen
I have some bits stored like the following variable nn

(nn <- c(1, 0, 0, 1, 0, 1,0))
[1] 1 0 0 1 0 1 0

not in the format of

1001010

and I need to convert them to numbers in base 10. What's an easy way to do it?

TIA,
Gang

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

2009-04-09 Thread Jason L. Simms
Hello,

I am fairly new to R, but I am not new to programming at all.  I want
to generate random clusters in a 1,000x1,000 box such that I end up
with a total of about 2,000 points.  Once done, I need to export the
X,Y coordinates of the points.

I have looked around, and it seems that the spatstat package has what
I need.  The rMatClust() function can generate random clusters, but I
have run into some problems.

First, I can't seem to specify that I want x number of points.  So,
right now it appears that if I want around 2,000 total points that I
must play around with the parameters of the function (e.g., mean
number of points per cluster, cluster radius, etc.) until I end up
with roughly 2,000 points.

More problematic, however, is that specifying a 1,000x1,000 box is too
much to handle.  I have been running the following function for over
24 hours straight on a decent computer and it has not stopped yet:

clust <- rMatClust(1, 50, 5, win=owin(c(0,1000),c(0,1000)))

Clearly, I need to rethink my strategy.  Could I generate the points
in a 10x10 box with a radius of .5 and then multiply out the resulting
point coordinates by 100?  Is there another package that might meet my
needs better than spatstat for easy cluster generation?

Any suggestions are appreciated.

All the best,
Jason Simms

-- 
Jason L. Simms, M.A.
USF Graduate Multidisciplinary Scholar
Co-President, Graduate Assistants United
Ph.D. / M.P.H. Student
Departments of Anthropology and Environmental and Occupational Health
University of South Florida

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


Re: [R] Error in saveLog(currentLogFileName

2009-04-09 Thread David Winsemius


On Apr 9, 2009, at 2:17 PM, Prew, Paul wrote:


David,  thank you for your helpful reply.

a) The sessionInfo goof is actually kind of enlightening.  I'm  
assuming that the purpose of adding the "()" symbols is to tell R  
that sessionInfo is a function to be invoked, and leaving "()"  
empty  says to use default arguments?


Yes. Exactly.




b)  In the R GUI, I end my session by using the menu File > Exit.  A  
dialog appears, asking, "Save workspace image?", and I choose Yes.


In fact, I just did it and got a message, never seen this one before

"Console not found.  Error in structure(.External"dotTclObjv:,objv,	 
PACKAGE - "tcltk"), class = "tclObj"):[tcl]invalid command name ". 
6.1".


I am not an expert in the Windows GUI, but as a former user of it, I  
would wonder if my installation of tcltk had gotten corrupted and  
would try to reinstall. Caveat: That advice could be worth what you  
paid for it.




Closed that message, another similar message was behind it, but now  
the command name was "17.1"


c) yes, agreed --- John Fox has been helpful to me a couple of  
times.  I like the R Commander (it automatically adds those pesky  
details like () that elude me), but I can't go the CRAN to get  
packages from it, so I end up back at the GUI to install a package.   
John has told me that moving back and forth between the GUI and  
Commander is not how Commander was intended to be used.  Perhaps  
this practice has led to some of the present confusions.


Let's say I save a script or history or similar file that I would  
like to recall at a later time,
If I save the file using RCommander, should I only open the file  
using R Commander?  Ditto for R GUI?  Regardless of which platform  
I'm saving the files with, they seem to have some of the same  
extensions, ".R", ".r", ".Rdata", etc.


I doubt that would be necessary, assuming the scripts do not have  
function calls that depend on R Commander being around. Files with .r  
extensions are just text files by another name.


I could not find a saveLog function with R-search restricted to  
functions but did find it as an argument to RCmdr. IIRC, RCmdr uses  
Tck/Tl extensively.


--
David




Thanks,
Paul

Paul Prew  |  Statistician
651-795-5942   |   fax 651-204-7504
Ecolab Research Center  | Mail Stop ESC-F4412-A
655 Lone Oak Drive  |  Eagan, MN 55121-1560

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net]
Sent: Thursday, April 09, 2009 12:17 PM
To: Prew, Paul
Cc: r-help@r-project.org
Subject: Re: [R] Error in saveLog(currentLogFileName

This is just two suggestions and a guess.

a) When you desire the information from sessionInfo ,you need to  
type :

sessionInfo()   # not sessionInfo

... results come from function calls and all you got was the
sessionInfo code produced by the implicit print function to which you
gave the argument sessionInfo.

b) Tell us exactly the methods you used to save "my script", "my
workspace", "etc"?

c) As a guess, you had the Zelig package loaded under R-Commander
yesterday but not today. The right person to ask this question of
might be one of those package maintainers. (John Fox is very good
about supporting R-Commander.)





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] numbers not behaving as expected

2009-04-09 Thread Thomas Lumley

On Thu, 9 Apr 2009 steve_fried...@nps.gov wrote:



My apologies for sending a binary file.  I was following advice from
someone (from this list) who insisted I send data via dput.  I guess that
is frown upon.



dput() creates a text file, not a binary file.  The problem is probably that 
your email software did not identify the file as text.

 -thomas

Thomas Lumley   Assoc. Professor, Biostatistics
tlum...@u.washington.eduUniversity of Washington, Seattle

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


Re: [R] running a .r script and saving the output to a file

2009-04-09 Thread David Winsemius


On Apr 9, 2009, at 2:21 PM, Gagan Pabla wrote:


I  first I saved the following commands in a whatever.r file.

data<-read.csv(file="whatever.csv", head=TRUE, sep=",")


#this is where you put the first sink:
sink("comm.docx")   # but it is not going to be in .docx format, but  
in text format.


summary(data$SQFT)
hist(data$STAMP)
hist(data$STAMP, col='blue')
hist(data$SHIP, col='blue')


# to get back output to the console, you close the "sunken" output file.
sink()

None of this will get you histograms, however. Sink does not deal with  
those. For that you need Sweave or odfWeave.


--
David Winsemius

then I clicked File Menu-> source and chose  whatever.r, it runs the
commands and produces the histograms and stuff.
then I did
sink("comm.docx")
sink()

It creates an empty file "comm.docx". Now my problem is that I want  
to run
the commands in whatever.r file( this part is working )  and then  
save the

output(has graphs hists etc) in a file.

How do I do that ? Your help will be greatly appreciated!!

Gagan

[[alternative HTML version deleted]]

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


David Winsemius, MD
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] numbers not behaving as expected

2009-04-09 Thread Stavros Macrakis
On Thu, Apr 9, 2009 at 2:05 PM,   wrote:
> WetMonths <- Cell.ave[Cell.ave$month  >= "5" and Cell.ave$month <= "11",]
> Error: unexpected symbol in "WetMonths <- Cell.ave[Cell.ave$month  >= "5"
> and"  Cell.ave$month <= "11",]

a) you are comparing with the *string* "5", not the *number* 5 (as I
mentioned before)
b) you are now writing "and" rather than "&"

The following works fine for me:

WetMonths <- Cell.ave[Cell.ave$month  >=  5 & Cell.ave$month <= 11,]

Better?

 -s

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] running a .r script and saving the output to a file

2009-04-09 Thread Gagan Pabla
I  first I saved the following commands in a whatever.r file.

data<-read.csv(file="whatever.csv", head=TRUE, sep=",")
summary(data$SQFT)
hist(data$STAMP)
hist(data$STAMP, col='blue')
hist(data$SHIP, col='blue')

then I clicked File Menu-> source and chose  whatever.r, it runs the
commands and produces the histograms and stuff.
then I did
sink("comm.docx")
sink()

It creates an empty file "comm.docx". Now my problem is that I want to run
the commands in whatever.r file( this part is working )  and then save the
output(has graphs hists etc) in a file.

How do I do that ? Your help will be greatly appreciated!!

Gagan

[[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] Error in saveLog(currentLogFileName

2009-04-09 Thread Prew, Paul
David,  thank you for your helpful reply.

a) The sessionInfo goof is actually kind of enlightening.  I'm assuming that 
the purpose of adding the "()" symbols is to tell R that sessionInfo is a 
function to be invoked, and leaving "()" empty  says to use default arguments?

b)  In the R GUI, I end my session by using the menu File > Exit.  A dialog 
appears, asking, "Save workspace image?", and I choose Yes.

In fact, I just did it and got a message, never seen this one before

"Console not found.  Error in structure(.External"dotTclObjv:,objv, PACKAGE 
- "tcltk"), class = "tclObj"):[tcl]invalid command name ".6.1".

Closed that message, another similar message was behind it, but now the command 
name was "17.1"

c) yes, agreed --- John Fox has been helpful to me a couple of times.  I like 
the R Commander (it automatically adds those pesky details like () that elude 
me), but I can't go the CRAN to get packages from it, so I end up back at the 
GUI to install a package.  John has told me that moving back and forth between 
the GUI and Commander is not how Commander was intended to be used.  Perhaps 
this practice has led to some of the present confusions.

Let's say I save a script or history or similar file that I would like to 
recall at a later time,
If I save the file using RCommander, should I only open the file using R 
Commander?  Ditto for R GUI?  Regardless of which platform I'm saving the files 
with, they seem to have some of the same extensions, ".R", ".r", ".Rdata", etc.

Thanks,
Paul

Paul Prew  |  Statistician
651-795-5942   |   fax 651-204-7504 
Ecolab Research Center  | Mail Stop ESC-F4412-A 
655 Lone Oak Drive  |  Eagan, MN 55121-1560 

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Thursday, April 09, 2009 12:17 PM
To: Prew, Paul
Cc: r-help@r-project.org
Subject: Re: [R] Error in saveLog(currentLogFileName

This is just two suggestions and a guess.

a) When you desire the information from sessionInfo ,you need to type :
sessionInfo()   # not sessionInfo

... results come from function calls and all you got was the  
sessionInfo code produced by the implicit print function to which you  
gave the argument sessionInfo.

b) Tell us exactly the methods you used to save "my script", "my  
workspace", "etc"?

c) As a guess, you had the Zelig package loaded under R-Commander  
yesterday but not today. The right person to ask this question of  
might be one of those package maintainers. (John Fox is very good  
about supporting R-Commander.)



On Apr 9, 2009, at 12:18 PM, Prew, Paul wrote:

> Hello,  very basic question from a user who is baffled by the  
> workings of computers in general
>
> When logging off R, a dialog box asked if I wanted to save my log,   
> I chose yes.  Then I noticed that the following message appeared in  
> the Command Window
>
> Error in saveLog(currentLogFileName) :
>  unused argument(s) ("C:/Documents and Settings/prewpj/My Documents/ 
> Data/Analyses/Healthcare/Hand Care Panel Test_KMolinaro/ 
> soapfeel_ZeligMixedLogit.R")
>
> My attempts to find  the parameters that saveLog requires haven’t  
> been successful, so I’m wondering if someone on this list could  
> advise me.  Yesterday, I saved several files:  my script, my  
> workspace, etc. to the above filepath, but today they are not  
> there.  A Windows search of my C:drive using the names of the files  
> came up empty.  They didn’t show up when I listed the objects from  
> the default R directory, either --- ls() command didn’t list  
> yesterday’s files.
>
> Further, the sessionInfo output is like nothing I’ve seen before.   
> Typically, it starts out with
> “R version 2.8.1 (2008-12-22)
> i386-pc-mingw32
> …
>
> Thank you, Paul
>
>> ?saveLog
> No documentation for 'saveLog' in specified packages and libraries:
> you could try '??saveLog'
>> ??saveLog
> No help files found with alias or concept or title matching 'saveLog'
> using fuzzy matching.
>> help.search(saveLog)
> Error in help.search(saveLog) : object "saveLog" not found
>> help.search("saveLog")
> No help files found with alias or concept or title matching  
> 'saveLog' using fuzzy matching.
>
>> sessionInfo
> function (package = NULL)
> {
>z <- list()
>z$R.version <- R.Version()
>z$locale <- Sys.getlocale()
>if (is.null(package)) {
>package <- grep("^package:", search(), value = TRUE)
>keep <- sapply(package, function(x) x == "package:base" ||
>!is.null(attr(as.environment(x), "path")))
>package <- sub("^package:", "", package[keep])
>}
>pkgDesc <- lapply(package, packageDescription)
>if (length(package) == 0)
>stop("no valid packages were specified")
>basePkgs <- sapply(pkgDesc, function(x) !is.null(x$Priority) &&
>x$Priority == "base")
>z$basePkgs <- package[basePkgs]
>if (any(!basePkgs)) {
>z$otherPkgs <- pkgDesc[!basePkgs]
>names(z$otherPkgs) <- package[!basePkgs]
>}
>loadedOnly

Re: [R] CFA in R/sem package

2009-04-09 Thread Jarrett Byrnes

Ivan,

I recently put together the sem.additions package over at R forge in  
part for just such a multiple model problem.  THere are a variety of  
methods that make it easy to add/delete links that could be automated  
with a for loop and something from the combn package, I think.


http://r-forge.r-project.org/projects/sem-additions/

-Jarrett

On Apr 9, 2009, at 6:39 AM, Iuri Gavronski wrote:


Hi,

I am not sure if R-help is the right forum for my question. If not,
please let me know.

I have to do some discriminant validity tests with some constructs. I
am using the method of doing a CFA constraining the correlation of a
pair of the constructs to 1 and comparing the chi-square of this
constrained model to the unconstrained model. If the chi-square
difference is not significant, then I cannot reject the null
hypothesis that the two constructs are equal.

Well, if you are going to test, say, 4 constructs (A, B, C, and D),
you will have to have 2*C(4,2) = 12 models to test, 5 constructs, 20
models, and so forth. A tedious and error prone process...

So far, I have been using AMOS for that shake, given that 1) my
university has the license, 2) my other colleagues use it, and 3) I
know it ;)

I would like to know if any of you use R, namely the sem package, for
that application and if you can share your thoughts/experiences on
using it. I don't thing I would have problems "porting" my models to
R/sem, but I would like to know if there is an optimized process of
doing that tests, without manually coding all the dozens of models.

Best,

Iuri.

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

2009-04-09 Thread Steve_Friedman

My apologies for sending a binary file.  I was following advice from
someone (from this list) who insisted I send data via dput.  I guess that
is frown upon.

Anyway.  here is a Cellave.txt file.


Stavros,  here is the output following your suggestion.

WetMonths <- Cell.ave[Cell.ave$month  >= "5" and Cell.ave$month <= "11",]
Error: unexpected symbol in "WetMonths <- Cell.ave[Cell.ave$month  >= "5"
and"  Cell.ave$month <= "11",]

I think the problem lies in leading characters for months with values 1,
10, 11, and 12.  These get very confused.


(See attached file: Cellave.txt)

Steve Friedman Ph. D.
Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)
Homestead, Florida 33034

steve_fried...@nps.gov
Office (305) 224 - 4282
Fax (305) 224 - 4147


   
 Stavros Macrakis  
  To
 Sent by:  steve_fried...@nps.gov  
 macra...@gmail.co  cc
 m r-help@r-project.org
   Subject
   Re: [R] numbers not behaving as 
 04/09/2009 01:51  expected
 PM AST
   
   
   
   
   




On Thu, Apr 9, 2009 at 1:39 PM,   wrote:
> I have a data.frame Cell.ave (attached and created via dput(Cell.ave,
> "Cell.ave")

I'm afraid your attachment didn't make it into the r-help mail.
Mailing list policy forbids binary attachments other than PS and PDF,
but should be forwarding plaintext attachments, I think.  Perhaps it
requires that the extension be ".txt" or something...?

Anyway... the problem seems diagnosable just from your code:

> WetSeasonMonths <- Cell.ave[Cell.ave$month  >= "5" & Cell.ave$month <=
> "11",]

There is no *string* which is >= "5" and <= "11".  Why aren't you
comparing numerically?

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


Re: [R] request: maximum depth reached problem

2009-04-09 Thread Uwe Ligges



Muhammad Azam wrote:

Dear R community
Hope all of you are fine. I have a question regarding the an error message. Actually, I 
am trying to generate classification trees using "tree" package. It works well 
but for some datasets e.g., wine, yeast, boston housing etc. it gives an error message.

Error in tree(V14 ~ ., data = training.data, method = c("recursive.partitioning"),  : 
maximum depth reached


The structure of getting output is given below:

iris.tr = tree(Species ~., data=training.data, method=c("recursive.partitioning"), split 
= c("gini"), control=tree.control(nobs = 150, minsize = 5, mincut = 2))

Any suggestion will be appreciated to handle the above problem. Thanks and



Please do not cross-post and only post to the correct mailing list.
I'd suggest to use package rpart (as the tree maintainer suggests) or 
other tree generating packages.


Uwe Ligges





best regards

Muhammad Azam 



  
	[[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] R interpreter not recognized

2009-04-09 Thread Stefan Evert

Dear Maria,

this is quite probably my faul, in some way.  The UCS software has  
been abandoned a bit recently, as I'm planning to rewrite it into a  
pure R package.  On the other hand, I still use the software  
occasionally, so it should work with recent R versions.



I am trying to install a program based on R, but I am receiving the
following error message:
r...@darkstar:/home/maria/UCS# perl System/Install.perl
Error: Can't run the R interpreter (/usr/local/bin/R).
Please make sure that R is installed and specify the fully qualified
filename of the R interpreter with -R if necessary (see "doc/ 
install.txt").


This either means that your R installation is damaged and Install.perl  
can't run the command "R --version"; or that it has problems parsing  
the output of this command, so it thinks there's something wrong with R.


What do you get if you type

/usr/local/bin/R --version

in a shell window?

Which version of UCS are you trying to install?  The message printed  
by "R --version" was changed some time ago (in early 2006, or so), so  
the Install.perl script stopped working at that time.  You need to  
download UCS-0.5-prerelease, which works for me (version 0.4 will not).


If you still can't get it to work, please contact me off-list so we  
can figure out the problem.


Cheers,
Stefan



[ stefan.ev...@uos.de | http://purl.org/stefan.evert ]

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


Re: [R] numbers not behaving as expected

2009-04-09 Thread Uwe Ligges



steve_fried...@nps.gov wrote:

If someone can explain this odd behavior I'd appreciate it.

I have a data.frame Cell.ave (attached and created via dput(Cell.ave,
"Cell.ave")
which contains three columns of parameters year, month and AveRain.

I need to subset the data.frame by months such that

DrySeaonMonths are 1,2,3,4, 11, and 12 or Jan - April, November and
December

and

WetSeasonMonths are 5:10 or May-October.

I'm using the following code:


DrySeasonMonths <- Cell.ave[Cell.ave$month < "5" & Cell.ave$month !=

"10",]

table(DrySeasonMonth$month)

12   34 11   12
 36   36  36  36  36   36

#  this is expected since the data is for 36 years

WetSeasonMonths <- Cell.ave[Cell.ave$month  >= "5" & Cell.ave$month <=
"11",]
 WetSeasonMonths
[1] yearmonth   AveRain
<0 rows> (or 0-length row.names)

There is an obvious problem with how the values for month are being stored.
I've tried converting them to factors, which complines that the subsetting
routine is not appropriate for factors. And I've tried as.numeric which
also does not return an working dataframe.

all suggestions to solve this are appreciated.

Thanks Steve

(See attached file: Cell.ave)



In fact no longer attached (removed by mailing list), but it is 
sufficient if you just tell us the result of

str(Cell.ave$month)
instead.

Uwe Ligges





sessionInfo()
R version 2.8.1 (2008-12-22)
x86_64-redhat-linux-gnu

locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

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



Steve Friedman Ph. D.
Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)
Homestead, Florida 33034

steve_fried...@nps.gov
Office (305) 224 - 4282
Fax (305) 224 - 4147




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

2009-04-09 Thread Stavros Macrakis
On Thu, Apr 9, 2009 at 1:39 PM,   wrote:
> I have a data.frame Cell.ave (attached and created via dput(Cell.ave,
> "Cell.ave")

I'm afraid your attachment didn't make it into the r-help mail.
Mailing list policy forbids binary attachments other than PS and PDF,
but should be forwarding plaintext attachments, I think.  Perhaps it
requires that the extension be ".txt" or something...?

Anyway... the problem seems diagnosable just from your code:

> WetSeasonMonths <- Cell.ave[Cell.ave$month  >= "5" & Cell.ave$month <=
> "11",]

There is no *string* which is >= "5" and <= "11".  Why aren't you
comparing numerically?

 -s

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

2009-04-09 Thread Steve_Friedman

If someone can explain this odd behavior I'd appreciate it.

I have a data.frame Cell.ave (attached and created via dput(Cell.ave,
"Cell.ave")
which contains three columns of parameters year, month and AveRain.

I need to subset the data.frame by months such that

DrySeaonMonths are 1,2,3,4, 11, and 12 or Jan - April, November and
December

and

WetSeasonMonths are 5:10 or May-October.

I'm using the following code:

> DrySeasonMonths <- Cell.ave[Cell.ave$month < "5" & Cell.ave$month !=
"10",]
> table(DrySeasonMonth$month)
12   34 11   12
 36   36  36  36  36   36

#  this is expected since the data is for 36 years

WetSeasonMonths <- Cell.ave[Cell.ave$month  >= "5" & Cell.ave$month <=
"11",]
 WetSeasonMonths
[1] yearmonth   AveRain
<0 rows> (or 0-length row.names)
>

There is an obvious problem with how the values for month are being stored.
I've tried converting them to factors, which complines that the subsetting
routine is not appropriate for factors. And I've tried as.numeric which
also does not return an working dataframe.

all suggestions to solve this are appreciated.

Thanks Steve

(See attached file: Cell.ave)

sessionInfo()
R version 2.8.1 (2008-12-22)
x86_64-redhat-linux-gnu

locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

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



Steve Friedman Ph. D.
Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)
Homestead, Florida 33034

steve_fried...@nps.gov
Office (305) 224 - 4282
Fax (305) 224 - 4147__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] running a .r script and saving the output to a file

2009-04-09 Thread David Winsemius
If you just entered sink(),  it would turn *off* sink-ing. You need to  
tell R where to write the output that would otherwise go to the  
console. (Or if you did something like that then you need  to tell us  
exactly what you did try.)


?sink  # e.g. sink(file="... /test.txt") with correct path substituted  
for ...

?source

And perhaps read up on submitting batch jobs from the Windows command  
line. See Appendix B of:

http://cran.r-project.org/doc/manuals/R-intro.pdf

--
David Winsemius


On Apr 9, 2009, at 12:46 PM, Gagan Pabla wrote:


Hello,

I want to run the following commands as a script(.r or .bat) and  
save the

output in an external file through Windows OS.

data<-read.csv(file="wgatever.csv", head=TRUE, sep=",")

summary(data$SQFT)

hist(data$STAMP)

hist(data$STAMP, col='blue')

hist(data$SHIP, col='blue')



How could I do that? I have a great problem using the sink() function
because it produces empty file. Please help!

Gagan

[[alternative HTML version deleted]]

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


David Winsemius, MD
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] Error in saveLog(currentLogFileName

2009-04-09 Thread David Winsemius

This is just two suggestions and a guess.

a) When you desire the information from sessionInfo ,you need to type :
sessionInfo()   # not sessionInfo

... results come from function calls and all you got was the  
sessionInfo code produced by the implicit print function to which you  
gave the argument sessionInfo.


b) Tell us exactly the methods you used to save "my script", "my  
workspace", "etc"?


c) As a guess, you had the Zelig package loaded under R-Commander  
yesterday but not today. The right person to ask this question of  
might be one of those package maintainers. (John Fox is very good  
about supporting R-Commander.)




On Apr 9, 2009, at 12:18 PM, Prew, Paul wrote:

Hello,  very basic question from a user who is baffled by the  
workings of computers in general


When logging off R, a dialog box asked if I wanted to save my log,   
I chose yes.  Then I noticed that the following message appeared in  
the Command Window


Error in saveLog(currentLogFileName) :
 unused argument(s) ("C:/Documents and Settings/prewpj/My Documents/ 
Data/Analyses/Healthcare/Hand Care Panel Test_KMolinaro/ 
soapfeel_ZeligMixedLogit.R")


My attempts to find  the parameters that saveLog requires haven’t  
been successful, so I’m wondering if someone on this list could  
advise me.  Yesterday, I saved several files:  my script, my  
workspace, etc. to the above filepath, but today they are not  
there.  A Windows search of my C:drive using the names of the files  
came up empty.  They didn’t show up when I listed the objects from  
the default R directory, either --- ls() command didn’t list  
yesterday’s files.


Further, the sessionInfo output is like nothing I’ve seen before.   
Typically, it starts out with

“R version 2.8.1 (2008-12-22)
i386-pc-mingw32
…

Thank you, Paul


?saveLog

No documentation for 'saveLog' in specified packages and libraries:
you could try '??saveLog'

??saveLog

No help files found with alias or concept or title matching 'saveLog'
using fuzzy matching.

help.search(saveLog)

Error in help.search(saveLog) : object "saveLog" not found

help.search("saveLog")
No help files found with alias or concept or title matching  
'saveLog' using fuzzy matching.



sessionInfo

function (package = NULL)
{
   z <- list()
   z$R.version <- R.Version()
   z$locale <- Sys.getlocale()
   if (is.null(package)) {
   package <- grep("^package:", search(), value = TRUE)
   keep <- sapply(package, function(x) x == "package:base" ||
   !is.null(attr(as.environment(x), "path")))
   package <- sub("^package:", "", package[keep])
   }
   pkgDesc <- lapply(package, packageDescription)
   if (length(package) == 0)
   stop("no valid packages were specified")
   basePkgs <- sapply(pkgDesc, function(x) !is.null(x$Priority) &&
   x$Priority == "base")
   z$basePkgs <- package[basePkgs]
   if (any(!basePkgs)) {
   z$otherPkgs <- pkgDesc[!basePkgs]
   names(z$otherPkgs) <- package[!basePkgs]
   }
   loadedOnly <- loadedNamespaces()
   loadedOnly <- loadedOnly[!(loadedOnly %in% package)]
   if (length(loadedOnly)) {
   names(loadedOnly) <- loadedOnly
   pkgDesc <- c(pkgDesc, lapply(loadedOnly, packageDescription))
   z$loadedOnly <- pkgDesc[loadedOnly]
   }
   class(z) <- "sessionInfo"
   z
}


Paul Prew   ▪  Statistician
651-795-5942   ▪   fax 651-204-7504
Ecolab Research Center   ▪  Mail Stop ESC-F4412-A
655 Lone Oak Drive   ▪   Eagan, MN 55121-1560



CONFIDENTIALITY NOTICE:
This e-mail communication and any attachments may contain  
proprietary and privileged information for the use of the designated  
recipients named above.
Any unauthorized review, use, disclosure or distribution is  
prohibited.
If you are not the intended recipient, please contact the sender by  
reply e-mail and destroy all copies of the original message.



[[alternative HTML version deleted]]

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


David Winsemius, MD
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] running a .r script and saving the output to a file

2009-04-09 Thread Gagan Pabla
Hello,

I want to run the following commands as a script(.r or .bat) and save the
output in an external file through Windows OS.

data<-read.csv(file="wgatever.csv", head=TRUE, sep=",")

summary(data$SQFT)

 hist(data$STAMP)

 hist(data$STAMP, col='blue')

 hist(data$SHIP, col='blue')



How could I do that? I have a great problem using the sink() function
because it produces empty file. Please help!

Gagan

[[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] Error in saveLog(currentLogFileName

2009-04-09 Thread Prew, Paul
Hello,  very basic question from a user who is baffled by the workings of 
computers in general

When logging off R, a dialog box asked if I wanted to save my log,  I chose 
yes.  Then I noticed that the following message appeared in the Command Window

Error in saveLog(currentLogFileName) : 
  unused argument(s) ("C:/Documents and Settings/prewpj/My 
Documents/Data/Analyses/Healthcare/Hand Care Panel 
Test_KMolinaro/soapfeel_ZeligMixedLogit.R")

My attempts to find  the parameters that saveLog requires haven’t been 
successful, so I’m wondering if someone on this list could advise me.  
Yesterday, I saved several files:  my script, my workspace, etc. to the above 
filepath, but today they are not there.  A Windows search of my C:drive using 
the names of the files came up empty.  They didn’t show up when I listed the 
objects from the default R directory, either --- ls() command didn’t list 
yesterday’s files.

Further, the sessionInfo output is like nothing I’ve seen before.  Typically, 
it starts out with 
“R version 2.8.1 (2008-12-22) 
i386-pc-mingw32 
…

Thank you, Paul

> ?saveLog
No documentation for 'saveLog' in specified packages and libraries:
you could try '??saveLog'
> ??saveLog
No help files found with alias or concept or title matching 'saveLog'
using fuzzy matching.
> help.search(saveLog)
Error in help.search(saveLog) : object "saveLog" not found
> help.search("saveLog")
No help files found with alias or concept or title matching 'saveLog' using 
fuzzy matching.

> sessionInfo
function (package = NULL) 
{
z <- list()
z$R.version <- R.Version()
z$locale <- Sys.getlocale()
if (is.null(package)) {
package <- grep("^package:", search(), value = TRUE)
keep <- sapply(package, function(x) x == "package:base" || 
!is.null(attr(as.environment(x), "path")))
package <- sub("^package:", "", package[keep])
}
pkgDesc <- lapply(package, packageDescription)
if (length(package) == 0) 
stop("no valid packages were specified")
basePkgs <- sapply(pkgDesc, function(x) !is.null(x$Priority) && 
x$Priority == "base")
z$basePkgs <- package[basePkgs]
if (any(!basePkgs)) {
z$otherPkgs <- pkgDesc[!basePkgs]
names(z$otherPkgs) <- package[!basePkgs]
}
loadedOnly <- loadedNamespaces()
loadedOnly <- loadedOnly[!(loadedOnly %in% package)]
if (length(loadedOnly)) {
names(loadedOnly) <- loadedOnly
pkgDesc <- c(pkgDesc, lapply(loadedOnly, packageDescription))
z$loadedOnly <- pkgDesc[loadedOnly]
}
class(z) <- "sessionInfo"
z
}


Paul Prew   ▪  Statistician
651-795-5942   ▪   fax 651-204-7504 
Ecolab Research Center   ▪  Mail Stop ESC-F4412-A 
655 Lone Oak Drive   ▪   Eagan, MN 55121-1560 



CONFIDENTIALITY NOTICE: 
This e-mail communication and any attachments may contain proprietary and 
privileged information for the use of the designated recipients named above. 
Any unauthorized review, use, disclosure or distribution is prohibited. 
If you are not the intended recipient, please contact the sender by reply 
e-mail and destroy all copies of the original message.


[[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] xmlEventParse returning trimmed content?

2009-04-09 Thread Duncan Temple Lang

Hi Johannes

 I would "guess" that the trimming of the text occurs because
you do not specify trim = FALSE in the call to xmlEventParse().
If you specify this, you might well get the results you expect.
If not, can you post the actual file you are reading so we can
reproduce your results.

  D.

Johannes Graumann wrote:

Hello,

I wrote the function below and have the problem, that the "text" bit returns 
only a trimmed version (686 chars as far as I can see) of the content under 
the "fetchPeaks" condition.

Any hunches why that might be?

Thanks for pointer, Joh

xmlEventParse(fileName,
list(
  startElement=function(name, attrs){
if(name == "scan"){
  if(.GlobalEnv$ms2Scan == TRUE & .GlobalEnv$scanDone == TRUE){
cat(.GlobalEnv$scanNum,"\n")
MakeSpektrumEntry()
  }
  .GlobalEnv$scanDone <- FALSE
  .GlobalEnv$fetchPrecMz <- FALSE
  .GlobalEnv$fetchPeaks <- FALSE
  .GlobalEnv$ms2Scan <- FALSE
  if(attrs[["msLevel"]] == "2"){
.GlobalEnv$ms2Scan <- TRUE
.GlobalEnv$scanNum <- as.integer(attrs[["num"]])
  }
} else if(name == "precursorMz" & .GlobalEnv$ms2Scan == TRUE){
  .GlobalEnv$fetchPrecMz <- TRUE
} else if(name == "peaks" & .GlobalEnv$ms2Scan == TRUE){
  .GlobalEnv$fetchPeaks <- TRUE
}
  },
  text=function(text){
if(.GlobalEnv$fetchPrecMz == TRUE){
  .GlobalEnv$precursorMz <- as.numeric(text)
  .GlobalEnv$fetchPrecMz <- FALSE
}
if(.GlobalEnv$fetchPeaks == TRUE){
  .GlobalEnv$peaks <- text
  .GlobalEnv$fetchPeaks <- FALSE
  .GlobalEnv$scanDone <- TRUE
}
  }
)
  )

sessionInfo() 
R version 2.9.0 beta (2009-04-03 r48277) 
x86_64-pc-linux-gnu 


locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=en_US.UTF-8;LC_ADDRESS=en_US.UTF-8;LC_TELEPHONE=en_US.UTF-8;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=en_US.UTF-8

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


other attached packages:
 [1] caMassClass_1.6 MASS_7.2-46 digest_0.3.1caTools_1.9
 [5] bitops_1.0-4.1  rpart_3.1-43nnet_7.2-46 e1071_1.5-19   
 [9] class_7.2-46PROcess_1.19.1  Icens_1.15.2survival_2.35-4
[13] RCurl_0.94-1XML_2.3-0   rkward_0.5.0   


loaded via a namespace (and not attached):
[1] tools_2.9.0

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

2009-04-09 Thread Martin Morgan
HI Wudd Wudd -- not really answering your question, but it might pay
to refactor some of your R code first. For instance

  for(j in 2:nrow(ranklist)){
  phit <- sum(rep(1/Ns, sum(ranklist[1:j,2]==1)))
  pmiss <- sum(rep(1/(N-Ns), sum(ranklist[1:j,2]==0)))
  if((phit-pmiss)>score[i]) score[i] <- phit - pmiss
  }

might be replaced (you'd better check, I'm not sure I have your logic
correct) by

  phit <- (cumsum(ranklist[,2]==1) / Ns)[-1]
  pmiss <- (cumsum(ranklist[,2]==0) / (N - Ns))[-1]
  pmax <- max(phit - pmiss)
  if (pmax > score[i]) score[i] <- pmax

These should be much faster than your loop. Your earlier 'apply' might
also be replaced by rowMeans, etc. I think, and once simplified to
that level further higher-level reorganizations might be possible.

Hope that helps

Martin

wudd wudd  writes:

> Hi guys,
> I want to transfer the following code from R into .Call compatible form. How
> can i do that?
>
> Thanks!!!
>
> INT sim;
>  for(i in 1:sim){
>  if(i>2) genemat <- genemat[,sample(1:ncol(genemat))]
>  ranklist[,1] <- apply(genemat, 1, function(x){
>  (mean(x[cols]) -
> mean(x[-cols]))/sd(x)})
>  ranklist <- ranklist[order(ranklist[,1]),]
>  if(ranklist[1,2]==1) score[i] <- 1/Ns
>  if(ranklist[1,2]==0) score[i] <- -(1/(N-Ns))
>   for(j in 2:nrow(ranklist)){
>  phit <- sum(rep(1/Ns, sum(ranklist[1:j,2]==1)))
>  pmiss <- sum(rep(1/(N-Ns), sum(ranklist[1:j,2]==0)))
>  if((phit-pmiss)>score[i]) score[i] <- phit - pmiss
>  }
>  }
>
> I tried a little bit, but not enough knowledge in C.
> #include 
> #include 
> #include 
> #include 
> SEXP ESscore(SEXP Rgeneset, SEXP Rgenemat, SEXP Rranklist, SEXP sim)
> {
>  int nc = ncols(Rgenemat);
>  double *geneset = NUMERIC_DATA(Rgeneset);
>  double *genemat = NUMERIC_DATA(Rgenemat);
>
>  SEXP Rscore;
>  PROTECT(Rscore=NEW_NUMERIC(sim));
>  double *score = NUMERIC_DATA(Rscore);
>
>  for(i=1; i<=sim; i++){
>  if(i>2) {genemat <- genemat[,sample(1:nc)];}
>  for(k=1; k
>  }
>
> }
>
>   [[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.

-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

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


Re: [R] Cross-platforms solution to export R graphs

2009-04-09 Thread HBaize


Thank you Philippe. 
That is very helpful.



Philippe Grosjean wrote:
> 
> Hello Rusers,
> 
> I have worked on a R Wiki page for solutions in exporting R graphs, 
> especially, the often-asked questions:
> - How can I export R graphs in vectorized format (EMF) for inclusion in 
>   MS Word or OpenOffice outside of Windows?
> - What is the best solution(s) for post-editing/annotating R graphs.
> 
> The page is at: 
> http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-misc:export.
> 
> I would be happy to receive your comments and suggestions to improve 
> this document.
> All the best,
> 
> PhG
> -- 
> ..<°}))><
>   ) ) ) ) )
> ( ( ( ( (Prof. Philippe Grosjean
>   ) ) ) ) )
> ( ( ( ( (Numerical Ecology of Aquatic Systems
>   ) ) ) ) )   Mons-Hainaut University, Belgium
> ( ( ( ( (
> ..
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Cross-platforms-solution-to-export-R-graphs-tp22970668p22973759.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] re siduals

2009-04-09 Thread kayj

Hi All,

I am trying to fit a linear regression between the tool speed and the tool
type ( type A, Type B , Type C) where the response is the tool speed and the
regressor is the tool type.

I introduced two dummy variables X1 and X2  as follows

 X1  X2
Tool A   0   0
Tool B   0   1
Tool C   10


Model<-Lm (y~X1+X2)

My question is on the residual plot, it looks like three cluster because  I
have three tool types. Is such a plot is ok with the constant variance
assumption  and normality (below is a link for the plot)?I have never seen
such a plot of the residuals


http://www.nabble.com/file/p22972254/question.JPG question.JPG 
-- 
View this message in context: 
http://www.nabble.com/residuals-tp22972254p22972254.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] Genstat into R - Randomisation test

2009-04-09 Thread Robert A LaBudde

At 04:43 AM 4/9/2009, Tom Backer Johnsen wrote:

Peter Dalgaard wrote:
> Mike Lawrence wrote:
>> Looks like that code implements a non-exhaustive variant of the
>> randomization test, sometimes called a permutation test.
>
> Isn't it the other way around? (Permutation tests can be 
exhaustive by looking at all permutations, if a randomization test 
did that, then it wouldn't be random.)


Eugene Edgington wrote an early book (1980) on this subject called 
"Randomization tests", published by Dekker.  As far as I remember, 
he differentiates between "Systematic permutation" tests where one 
looks at all possible permutations.  This is of course prohibitive 
for anything beyond trivially small samples.  For larger samples he 
uses what he calls "Random permutations", where a random sample of 
the possible permutations is used.


Tom

Peter Dalgaard wrote:

Mike Lawrence wrote:

Looks like that code implements a non-exhaustive variant of the
randomization test, sometimes called a permutation test.
Isn't it the other way around? (Permutation tests can be exhaustive 
by looking at all permutations, if a randomization test did that, 
then it wouldn't be random.)


Edginton and Onghena make a similar distinction in their book, but I 
think such a distinction is without merit.


Do we distinguish between "exact" definite integrals and 
"approximate" ones obtained by numerical integration, of which Monte 
Carlo sampling is just one class of algorithms? Don't we just say: 
"The integral was evaluated numerically by the [whatever] method to 
an accuracy of [whatever], and the value was found to be [whatever]." 
Ditto for optimization problems.


A randomization test has one correct answer based upon theory. We are 
simply trying to calculate that answer's value when it is difficult 
to do so. Any approximate method that is used must be performed such 
that the error of approximation is trivial with respect to the 
contemplated use.


Doing Monte Carlo sampling to find an approximate answer to a 
randomization test, or to an optimization problem, or to a bootstrap 
distribution should be carried out with enough realizations to make 
sure the residual error is trivial.


As Monte Carlo sampling is a "random" sampling-based approximate 
method. The name does create confusion in terminology for 
"randomization" tests for bootstrapping.



Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: r...@lcfltd.com
Least Cost Formulations, Ltd.URL: http://lcfltd.com/
824 Timberlake Drive Tel: 757-467-0954
Virginia Beach, VA 23464-3239Fax: 757-467-2947

"Vere scire est per causas scire"

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


Re: [R] Convert data frame containing time stamps to time series

2009-04-09 Thread amvds
What is zoo? I cannot find anything about zoo int he documentation.

I did try as.ts() see below.

Thank you,
Alex van der Spek

> have you tried using zoo and then using the function as.ts()
>
> On Wed, Apr 8, 2009 at 11:56 AM,   wrote:
>> Converting dates is getting stranger still. I am coercing a data frame
>> into a ts as follows:
>>
>>
>> tst1<-as.POSIXct("1/21/09 5:01",format="%m/%d/%y %H:%M")
>> tst2<-as.POSIXct("1/28/09 3:40",format="%m/%d/%y %H:%M")
>> tsdat<-as.ts(dat,start=tst1,end=tst2,frequency=1)
>>
>> This generates a ts object. But strangely enough the first column of
>> that
>> matrix starts at the numeric value of 841 counts up to 1139 and then
>> starts at 1 again, only to count up from there. The restart at 1 occurs
>> at
>> the first day "1/21/09" at 10:00:00.
>>
>> What is so special about that time? This phenomenon happens several
>> times
>> in the long file. But the restart count is always a different number.
>> This creates a ramp with some bumps.
>>
>> Can anybody explain this?
>> Thanks in advance,
>> Alex van der Spek
>>
>>
>>> I read records using scan:
>>>
>>> dat<-data.frame(scan(file="KDA.csv",what=list(t="%m/%d/%y
>>> %H:%M",f=0,p=0,d=0,o=0,s=0,a=0,l=0,c=0),skip=2,sep=",",nmax=np,flush=TRUE,na.strings=c("I/OTimeout","ArcOff-line")))
>>>
>>> which results in:
>>>
 dat[1:5,]
>>>              t     f    p  d  o   s    a  l c
>>> 1 1/21/09 5:01 16151  8.2 76 30 282 1060 53 7
>>> 2 1/21/09 5:02 16256  8.3 76 23 282 1059 54 7
>>> 3 1/21/09 5:03 16150  8.4 76 26 282 1059 55 7
>>> 4 1/21/09 5:04 16150  9.0 76 25 282 1051 57 6
>>> 5 1/21/09 5:05 15543 10.4 76  7 282 1024 58 6
>>>
>>> I have been unable to find a way to convert this into a time series. I
>>> did
>>> read the manuals and came across a way to coerce a data frame to a ts
>>> object: as.ts()
>>>
>>> Trouble is I do not know how to keep the timestamps in column t in the
>>> data frame above. The t column is not strings. If I do:
>>>
>>> plot.ts(dat)
>>>
>>> I can see how the first graphics panel is indeed numbers not text. So I
>>> think scan converted the text correctly per the format string I put in.
>>>
>>> Much more difficult still. The datafiles I have contain invalid data,
>>> missing values and other none relevant information. I filter this out
>>> using subset which works brilliantly. However, how can I filter using
>>> subset and convert to a time series afterwards. Since after subsetting
>>> there will be 'holes' i.e. missing records. Can a ts object deal with
>>> missing records? If so, how? Just point me to a document. I can and
>>> will
>>> put in the work to figure it out myself.
>>>
>>> Thank you!
>>> Alex van der Spek
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/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.
>>
>
>
>
> --
> Stephen Sefick
>
> Let's not spend our time and resources thinking about things that are
> so little or so large that all they really do for us is puff us up and
> make us feel like gods.  We are mammals, and have not exhausted the
> annoying little problems of being mammals.
>
>   -K. Mullis
>
>

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


Re: [R] HELP to cbind several data.frame with a LOOP

2009-04-09 Thread jim holtman
I would use 'lapply' to create a list of the matrices:

result <- lapply(c(10,20,30,40,50), function(.num){
do.call(cbind, lapply(c('Tableanalysis_firenze',
'Tableanalysis_siena', 'Tableanalysis_lucca'), function(.file){
read.table(sprintf("%s_%d.txt", .file, .num), header=TRUE)
}))
})



On Thu, Apr 9, 2009 at 10:49 AM, Alessandro
 wrote:
> Dear R users,
>
>
>
> thank for help. SORRY I am seeing in google a maillist but I didn't find a
> solution for my problem
>
>
>
> I have several txt file (with the same number of column and HEADER) to merge
> together, this is an example:
>
>
>
> Tableanalysis_firenze_10.txt
>
> Tableanalysis_firenze_20.txt
>
> Tableanalysis_firenze_30.txt
>
> Tableanalysis_firenze_40.txt
>
> Tableanalysis_firenze_50.txt
>
> Tableanalysis_siena_10.txt
>
> Tableanalysis_siena_20.txt
>
> Tableanalysis_siena_30.txt
>
> Tableanalysis_siena_40.txt
>
> Tableanalysis_siena_50.txt
>
> Tableanalysis_lucca_10.txt
>
> Tableanalysis_lucca_20.txt
>
> Tableanalysis_lucca_30.txt
>
> Tableanalysis_lucca_40.txt
>
> Tableanalysis_lucca_50.txt
>
>
>
> I wish to combine a new txt file like this
>
>
>
> Tableanalysis_10 <- cbind(Tableanalysis_firenze_10, Tableanalysis_siena_10,
> Tableanalysis_lucca_10)
>
> Tableanalysis_20 <- cbind(Tableanalysis_firenze_20, Tableanalysis_siena_20,
> Tableanalysis_lucca_20)
>
> Tableanalysis_30 <- cbind(Tableanalysis_firenze_30, Tableanalysis_siena_30,
> Tableanalysis_lucca_30)
>
> Tableanalysis_40 <- cbind(Tableanalysis_firenze_40, Tableanalysis_siena_40,
> Tableanalysis_lucca_40)
>
> Tableanalysis_50 <- cbind(Tableanalysis_firenze_50, Tableanalysis_siena_50,
> Tableanalysis_lucca_50)
>
>
>
> Thanks
>
>
>
> Ale
>
>
>
>
>
>
>
>
>
>
>        [[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?

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


Re: [R] problems with integrate ... arguments

2009-04-09 Thread Duncan Murdoch

On 09/04/2009 10:19 AM, Ravi Varadhan wrote:

Richard,

Your function f() is already vectorized, and it works well (see below).  Therefore, you don't need to create f2().  


He did say that this was a simplified example.

The problem appears to be in Vectorize, which uses match.call() to get 
the args from the call to your f function.  match.call() can make 
substitutions for ... args, but only seems to do so for one level up, 
and the dots are being passed through two levels here:  ... as an arg to 
integrate, which creates a local function ff, and passes ... through it.


Not sure yet where to fix this...

Duncan Murdoch




f = function(x, const) 2^x + const

testval = 2


integrate(f, 0.5, 1, const=testval)

1.845111 with absolute error < 2.0e-14


Ravi. 




Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu


- Original Message -
From: Richard Morey 
Date: Thursday, April 9, 2009 8:10 am
Subject: [R] problems with integrate ... arguments
To: r-help@r-project.org



Hi everyone,
 
 I saw this problem dealt with here:
 
 
 but no one answered that request that I can tell. I'm having the same

 problem. I'm having problems passing arguments to functions that I'd
 like to integrate. I could swear this worked in the past, but I can't
 get it to work now. I'm running R on Windows.
 
 Here's my toy code to reproduce the problem:
 
 
 R.Version()$version.string

 # [1] "R version 2.8.1 (2008-12-22)"
 
 f=function(x,const)

 2^x+const
 
 f2=Vectorize(f,c("x"))
 
 testval=2
 
 f2(1:5,testval)

 # [1]  4  6 10 18 34
 # The vectorized function seems to work right.
 
 integrate(f2,.5,1,c=2)

 # Works. Returns
 # 1.845111 with absolute error < 2.0e-14
 
 integrate(f=f2,.5,1,const=testval)

 # Doesn't work. Returns
 # Error in eval(expr, envir, enclos) :
 #  ..1 used in an incorrect context, no ... to look in
 
 I understand that I don't have to Vectorize this function for it to

 work, but the more complicated functions I'm using require Vectorization.
 
 Why can't I pass the argument "const" as a variable, instead of a value?

   I don't understand this error.
 
 Thanks in advance,

 Richard Morey
 
 -- 
 Richard D. Morey

 Assistant Professor
 Psychometrics and Statistics
 Rijksuniversiteit Groningen / University of Groningen
 
 __

 R-help@r-project.org mailing list
 
 PLEASE do read the posting guide 
 and provide commented, minimal, self-contained, reproducible code.


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


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


[R] HELP to cbind several data.frame with a LOOP

2009-04-09 Thread Alessandro
Dear R users,

 

thank for help. SORRY I am seeing in google a maillist but I didn't find a
solution for my problem

 

I have several txt file (with the same number of column and HEADER) to merge
together, this is an example:

 

Tableanalysis_firenze_10.txt

Tableanalysis_firenze_20.txt

Tableanalysis_firenze_30.txt

Tableanalysis_firenze_40.txt

Tableanalysis_firenze_50.txt

Tableanalysis_siena_10.txt

Tableanalysis_siena_20.txt

Tableanalysis_siena_30.txt

Tableanalysis_siena_40.txt

Tableanalysis_siena_50.txt

Tableanalysis_lucca_10.txt

Tableanalysis_lucca_20.txt

Tableanalysis_lucca_30.txt

Tableanalysis_lucca_40.txt

Tableanalysis_lucca_50.txt

 

I wish to combine a new txt file like this

 

Tableanalysis_10 <- cbind(Tableanalysis_firenze_10, Tableanalysis_siena_10,
Tableanalysis_lucca_10)

Tableanalysis_20 <- cbind(Tableanalysis_firenze_20, Tableanalysis_siena_20,
Tableanalysis_lucca_20)

Tableanalysis_30 <- cbind(Tableanalysis_firenze_30, Tableanalysis_siena_30,
Tableanalysis_lucca_30)

Tableanalysis_40 <- cbind(Tableanalysis_firenze_40, Tableanalysis_siena_40,
Tableanalysis_lucca_40)

Tableanalysis_50 <- cbind(Tableanalysis_firenze_50, Tableanalysis_siena_50,
Tableanalysis_lucca_50)

 

Thanks

 

Ale

 

 

 

 


[[alternative HTML version deleted]]

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


[R] request: maximum depth reached problem

2009-04-09 Thread Muhammad Azam
Dear R community
Hope all of you are fine. I have a question regarding the an error message. 
Actually, I am trying to generate classification trees using "tree" package. It 
works well but for some datasets e.g., wine, yeast, boston housing etc. it 
gives an error message.

Error in tree(V14 ~ ., data = training.data, method = 
c("recursive.partitioning"),  : 
maximum depth reached

The structure of getting output is given below:

iris.tr = tree(Species ~., data=training.data, 
method=c("recursive.partitioning"), split = c("gini"), 
control=tree.control(nobs = 150, minsize = 5, mincut = 2))

Any suggestion will be appreciated to handle the above problem. Thanks and
  

best regards

Muhammad Azam 


  
[[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] problems with integrate ... arguments

2009-04-09 Thread Ravi Varadhan
Richard,

I didn't read the last part of your email that you "do" want to Vectorize your 
function.  Sorry about that.

Here is a solution using "sapply" to vectorize your function. 

f <- function(x, const) 2^x + const

f2 <- function(x, ...) sapply(x, function(x) f(x, ...) )

> integrate(f2, 0.5, 1, const=testval)
1.845111 with absolute error < 2.0e-14


Ravi.



Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu


- Original Message -
From: Richard Morey 
Date: Thursday, April 9, 2009 8:10 am
Subject: [R] problems with integrate ... arguments
To: r-help@r-project.org


> Hi everyone,
>  
>  I saw this problem dealt with here:
>  
>  
>  but no one answered that request that I can tell. I'm having the same
>  problem. I'm having problems passing arguments to functions that I'd
>  like to integrate. I could swear this worked in the past, but I can't
>  get it to work now. I'm running R on Windows.
>  
>  Here's my toy code to reproduce the problem:
>  
>  
>  R.Version()$version.string
>  # [1] "R version 2.8.1 (2008-12-22)"
>  
>  f=function(x,const)
>  2^x+const
>  
>  f2=Vectorize(f,c("x"))
>  
>  testval=2
>  
>  f2(1:5,testval)
>  # [1]  4  6 10 18 34
>  # The vectorized function seems to work right.
>  
>  integrate(f2,.5,1,c=2)
>  # Works. Returns
>  # 1.845111 with absolute error < 2.0e-14
>  
>  integrate(f=f2,.5,1,const=testval)
>  # Doesn't work. Returns
>  # Error in eval(expr, envir, enclos) :
>  #  ..1 used in an incorrect context, no ... to look in
>  
>  I understand that I don't have to Vectorize this function for it to
>  work, but the more complicated functions I'm using require Vectorization.
>  
>  Why can't I pass the argument "const" as a variable, instead of a value?
>I don't understand this error.
>  
>  Thanks in advance,
>  Richard Morey
>  
>  -- 
>  Richard D. Morey
>  Assistant Professor
>  Psychometrics and Statistics
>  Rijksuniversiteit Groningen / University of Groningen
>  
>  __
>  R-help@r-project.org mailing list
>  
>  PLEASE do read the posting guide 
>  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] Anova interaction not tested

2009-04-09 Thread Bert Gunter
 
Gabe:

Don't be silly. lme is not appropriate here --you have only one stratum!.
Use lm and you'll see what's going on. It also looks like you should do some
reading up on linear models. V&R's MASS or Peter Dalgaard's INTRO to
Statistics with R might be places to start.

Incidentallyy, Version 2.8.1 of R gives for the output of aov:

aov(speed~brand*material)
Call:
   aov(formula = speed ~ brand * material)

Terms:
   brand material Residuals
Sum of Squares  49.86190 13.50167  21.00500
Deg. of Freedom22 2

Residual standard error: 3.240756 
4 out of 9 effects not estimable
Estimated effects may be unbalanced
Warning messages:
1: In model.matrix.default(mt, mf, contrasts) :
  variable 'brand' converted to a factor
2: In model.matrix.default(mt, mf, contrasts) :
  variable 'material' converted to a factor

Seems like this should pretty much tell you what's going on -- if you
understand linear models. (and if you don't, why not, since you're using
them?)

Cheers,
Bert


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Gabriel Murray
Sent: Wednesday, April 08, 2009 4:08 PM
To: Patrick Connolly
Cc: r-help@r-project.org
Subject: Re: [R] Anova interaction not tested

Playing around with this some more, it looks like it may purely be due to
the way that R handles unbalanced data. I will investigate lme for this.

Best,
Gabe

On Wed, Apr 8, 2009 at 3:24 PM, Gabriel Murray  wrote:

> Here is some toy data to give an example. Imagine someone is test-riding
> several bicycles to decide which to buy, and measures their average speed
> during each test-ride. They want to assess the main effects and
interaction
> of brand and material on speed.
>
> SpeedSizeBrandMaterial
> 20 smallgiantsteel
> 25.1  mediumgiantsteel
> 25.2  medium  trekaluminum
> 26 smallcannondalecarbon
> 19.9  largegiantaluminum
> 21 mediumtrekcarbon
> 30 mediumcannondalecarbon
>
> This is the output I get:
>
> > fit = aov(Speed~Brand*Material, data=myData)
> > summary(fit)
> Df Sum Sq Mean Sq F value Pr(>F)
> Brand2 49.862  24.931  2.3738 0.2964
> Material 2 13.502   6.751  0.6428 0.6087
> Residuals2 21.005  10.503
>
>
> I suppose I am missing something very obvious here as to why the
> interaction is not reported, but I don't see what it is.
> Cheers,
>
> Gabe
>
>
>
> On Wed, Apr 8, 2009 at 1:34 PM, Patrick Connolly <
> p_conno...@slingshot.co.nz> wrote:
>
>> On Wed, 08-Apr-2009 at 12:59PM -0700, Gabriel Murray wrote:
>>
>> |> I've noticed with certain datasets that when I try to do an anova and
>> test
>> |> for main effects and interaction for two explanatory variables,
>> sometimes
>> |> the main effect results are given but not the interaction results. For
>> |> example,
>> |>
>> |> ex1 = aov(Score ~ var1*var2, data=myData)
>> |> summary(ex1)
>>
>> Could it be that there are no degrees of freedom left?
>>
>> That's about my best guess without enough information.
>>
>>
>> |> __
>> |> R-help@r-project.org mailing list
>> |> https://stat.ethz.ch/mailman/listinfo/r-help
>> |> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> |> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>> Nothing you sent is reproducible.
>>
>>
>> --
>> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>>___Patrick Connolly
>>  {~._.~}   Great minds discuss ideas
>>  _( Y )_ Average minds discuss events
>> (:_~*~_:)  Small minds discuss people
>>  (_)-(_)  . Eleanor Roosevelt
>>
>> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>>
>
>

[[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] better way of recoding factors in data frame?

2009-04-09 Thread Mohinder Datta

Thank you for your help!


--- On Thu, 4/9/09, Thomas Lumley  wrote:

> From: Thomas Lumley 
> Subject: Re: [R] better way of recoding factors in data frame?
> To: mohinder_da...@yahoo.com
> Cc: r-help@r-project.org
> Date: Thursday, April 9, 2009, 2:10 PM
> On Thu, 9 Apr 2009 mohinder_da...@yahoo.com
> wrote:
> 
> >
> > Hi all,
> >
> > I apologize in advance for the length of this post,
> but I wanted to make sure 
> > I was clear.
> 
> Good strategy.
> 
> 
> >I tried this:
> >
> >> myFrame2$newSex <- ifelse(myFrame2$newSex ==1
> || myFrame2$newSex == 2, myFrame2$newSex, 0)
> >
> 
> First, you need |, not ||, because || returns just a single
> value.
> 
> This still won't quite work, because the condition will be
> NA when newSex is NA (if you don't know a number then you
> don't know whether it is equal to 1 or 2).
> 
> So,
> myFrame2$newSex <- ifelse(myFrame2$newSex %in% c(1,2),
> myFrame2$newSex, 0)
> 
> or, slightly shorter
> myFrame2$newSex <- with(myFrame2, ifelse(newSex %in%
> c(1,2), newSex, 0)
> 
>      -thomas
> 
> Thomas Lumley       
>     Assoc. Professor, Biostatistics
> tlum...@u.washington.edu   
> University of Washington, Seattle
> 
> 
> 




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


Re: [R] problems with integrate ... arguments

2009-04-09 Thread Ravi Varadhan
Richard,

Your function f() is already vectorized, and it works well (see below).  
Therefore, you don't need to create f2().  

f = function(x, const) 2^x + const

testval = 2

> integrate(f, 0.5, 1, const=testval)
1.845111 with absolute error < 2.0e-14


Ravi. 



Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu


- Original Message -
From: Richard Morey 
Date: Thursday, April 9, 2009 8:10 am
Subject: [R] problems with integrate ... arguments
To: r-help@r-project.org


> Hi everyone,
>  
>  I saw this problem dealt with here:
>  
>  
>  but no one answered that request that I can tell. I'm having the same
>  problem. I'm having problems passing arguments to functions that I'd
>  like to integrate. I could swear this worked in the past, but I can't
>  get it to work now. I'm running R on Windows.
>  
>  Here's my toy code to reproduce the problem:
>  
>  
>  R.Version()$version.string
>  # [1] "R version 2.8.1 (2008-12-22)"
>  
>  f=function(x,const)
>  2^x+const
>  
>  f2=Vectorize(f,c("x"))
>  
>  testval=2
>  
>  f2(1:5,testval)
>  # [1]  4  6 10 18 34
>  # The vectorized function seems to work right.
>  
>  integrate(f2,.5,1,c=2)
>  # Works. Returns
>  # 1.845111 with absolute error < 2.0e-14
>  
>  integrate(f=f2,.5,1,const=testval)
>  # Doesn't work. Returns
>  # Error in eval(expr, envir, enclos) :
>  #  ..1 used in an incorrect context, no ... to look in
>  
>  I understand that I don't have to Vectorize this function for it to
>  work, but the more complicated functions I'm using require Vectorization.
>  
>  Why can't I pass the argument "const" as a variable, instead of a value?
>I don't understand this error.
>  
>  Thanks in advance,
>  Richard Morey
>  
>  -- 
>  Richard D. Morey
>  Assistant Professor
>  Psychometrics and Statistics
>  Rijksuniversiteit Groningen / University of Groningen
>  
>  __
>  R-help@r-project.org mailing list
>  
>  PLEASE do read the posting guide 
>  and provide commented, minimal, self-contained, reproducible code.

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


[R] xmlEventParse returning trimmed content?

2009-04-09 Thread Johannes Graumann
Hello,

I wrote the function below and have the problem, that the "text" bit returns 
only a trimmed version (686 chars as far as I can see) of the content under 
the "fetchPeaks" condition.
Any hunches why that might be?

Thanks for pointer, Joh

xmlEventParse(fileName,
list(
  startElement=function(name, attrs){
if(name == "scan"){
  if(.GlobalEnv$ms2Scan == TRUE & .GlobalEnv$scanDone == TRUE){
cat(.GlobalEnv$scanNum,"\n")
MakeSpektrumEntry()
  }
  .GlobalEnv$scanDone <- FALSE
  .GlobalEnv$fetchPrecMz <- FALSE
  .GlobalEnv$fetchPeaks <- FALSE
  .GlobalEnv$ms2Scan <- FALSE
  if(attrs[["msLevel"]] == "2"){
.GlobalEnv$ms2Scan <- TRUE
.GlobalEnv$scanNum <- as.integer(attrs[["num"]])
  }
} else if(name == "precursorMz" & .GlobalEnv$ms2Scan == TRUE){
  .GlobalEnv$fetchPrecMz <- TRUE
} else if(name == "peaks" & .GlobalEnv$ms2Scan == TRUE){
  .GlobalEnv$fetchPeaks <- TRUE
}
  },
  text=function(text){
if(.GlobalEnv$fetchPrecMz == TRUE){
  .GlobalEnv$precursorMz <- as.numeric(text)
  .GlobalEnv$fetchPrecMz <- FALSE
}
if(.GlobalEnv$fetchPeaks == TRUE){
  .GlobalEnv$peaks <- text
  .GlobalEnv$fetchPeaks <- FALSE
  .GlobalEnv$scanDone <- TRUE
}
  }
)
  )

> sessionInfo() 
R version 2.9.0 beta (2009-04-03 r48277) 
x86_64-pc-linux-gnu 

locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=en_US.UTF-8;LC_ADDRESS=en_US.UTF-8;LC_TELEPHONE=en_US.UTF-8;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=en_US.UTF-8

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

other attached packages:
 [1] caMassClass_1.6 MASS_7.2-46 digest_0.3.1caTools_1.9
 [5] bitops_1.0-4.1  rpart_3.1-43nnet_7.2-46 e1071_1.5-19   
 [9] class_7.2-46PROcess_1.19.1  Icens_1.15.2survival_2.35-4
[13] RCurl_0.94-1XML_2.3-0   rkward_0.5.0   

loaded via a namespace (and not attached):
[1] tools_2.9.0

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


Re: [R] Biexponential Fit

2009-04-09 Thread Katharine Mullen
Using algorithm="plinear" as shown by example below makes
sum-of-exponentials fitting problems better conditioned.

A1 <- 1
A2 <- 2
k1 <- -.5
k2 <- -2
x <- seq(1,10,length=200)
y <- A1*exp(k1*x) + A2*exp(k2*x) + .001*rnorm(200)

aa <- nls(y~cbind(exp(k1*x), exp(k2*x)), algorithm="plinear",
  start=list(k1=-.1, k2=-6), data=list(y=y, x=x), trace=TRUE)

On Thu, 9 Apr 2009, Peter Dalgaard wrote:

> Jonas Weickert wrote:
> > Hi,
> >
> > I want to do a biexponential Fit, i.e.
> >
> > y ~ A1*exp(k1*x) + A2*exp(k2*x)
> >
> > Is this possible? I tried nls() but it stopped with several (different)
> > errors. I'm using y and x as simple vectors and the formula for nls()
> > exactly as mentioned above.
>
> Yes, it is possible, with some reservations. There is even a
> self-starting model for it (SSbiexp), at least if k1,k2 are negative.
>
> The reservations are that you need good data and good starting values
> for the fit. The model is theoretically unidentifiable because you can
> switch 1 and 2 and get the same model, which becomes an issue if you
> start too fra from the optimum. Worse, if k1 and k2 are similar, the
> whole system becomes ill-conditioned. There's a rule of thumb requiring
> a factor of 5 or more between k1 and k2, for pharmacokinetic applications.
>
> > Thanks a lot!
> >
> > Jonas
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>
> --
> 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.
>

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


Re: [R] failed when merging two dataframes, why

2009-04-09 Thread Jun Shen
I would suggest use the same column names for the common columns. Say, use
"codetot" for both df1 and df2. Then you don't even have to specify by.x or
by.y, merge will do it automatically.

merge(df1,df2, all=TRUE).
Otherwise you have to
merge(df1,df2,by.x=c('popcode','codetot'),by.y=c('popcode','codetoto'),all=TRUE)

They both produce

 popcode codetot   p3need   areasec
1  BCPy01-01 BCPy01-01-1  100 0.5089434
2  BCPy01-01 BCPy01-01-2  100 0.6246381
3  BCPy01-01 BCPy01-01-3  100 0.4370059
4  BCPy01-02 BCPy01-02-1  92.5926 0.9253052
5  BCPy01-02 BCPy01-02-1  92.5926 0.6011810
6  BCPy01-02 BCPy01-02-1  100 0.9253052
7  BCPy01-02 BCPy01-02-1  100 0.6011810
8  BCPy01-02 BCPy01-02-2  92.5926 0.6710850
9  BCPy01-02 BCPy01-02-2  92.5926 0.7145839
10 BCPy01-02 BCPy01-02-2  100 0.6710850
11 BCPy01-02 BCPy01-02-2  100 0.7145839
12 BCPy01-02 BCPy01-02-3  92.5926 0.9515256
13 BCPy01-02 BCPy01-02-3  92.5926 0.6555006
14 BCPy01-02 BCPy01-02-3  100 0.9515256
15 BCPy01-02 BCPy01-02-3  100 0.6555006
16 BCPy01-03 BCPy01-03-1  100 0.8683875


On Thu, Apr 9, 2009 at 6:19 AM, Mao Jianfeng  wrote:

> Hi, R-listers,
>
> Failed, when I tried to merge df1 and df2 by "codetot" in df1 and
> "codetoto"
> in df2. I want to know the reason and how to merge them together. Data
> frames and codes I have used were listed as followed. Thanks a lot in
> advance.
>
> df1:
> popcode codetot   p3need
> BCPy01-01 BCPy01-01-1 100.
> BCPy01-01 BCPy01-01-2 100.
> BCPy01-01 BCPy01-01-3 100.
> BCPy01-02 BCPy01-02-1  92.5926
> BCPy01-02 BCPy01-02-1 100.
> BCPy01-02 BCPy01-02-2  92.5926
> BCPy01-02 BCPy01-02-2 100.
> BCPy01-02 BCPy01-02-3  92.5926
> BCPy01-02 BCPy01-02-3 100.
> BCPy01-03 BCPy01-03-1 100.
>
> df2:
> popcodecodetoto   areasec
> BCPy01-01 BCPy01-01-1 0.5089434
> BCPy01-01 BCPy01-01-2 0.6246381
> BCPy01-01 BCPy01-01-3 0.4370059
> BCPy01-02 BCPy01-02-1 0.9253052
> BCPy01-02 BCPy01-02-1 0.6011810
> BCPy01-02 BCPy01-02-2 0.6710850
> BCPy01-02 BCPy01-02-2 0.7145839
> BCPy01-02 BCPy01-02-3 0.9515256
> BCPy01-02 BCPy01-02-3 0.6555006
> BCPy01-03 BCPy01-03-1 0.8683875
>
> code:
> new1<-merge(df1,df2,by=c("popcode","popcode"),all=T) # It is processed
> well.
> But, it is not what I want.
> new2<-merge(df1,df2,by=c("codetot","codetoto"),all=T) # this one failed. I
> exactly want to do that.
>
> Mao J-F
> IBCAS, AC
>
>[[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.
>



-- 
Jun Shen PhD
PK/PD Scientist
BioPharma Services
Millipore Corporation
15 Research Park Dr.
St Charles, MO 63304
Direct: 636-720-1589

[[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] Maple and R

2009-04-09 Thread JLucke
I forgot. You can get the Bessel functions from Robin Hankin's GSL 
package. 

R. K. S. Hankin 2006. Introducing gsl, a wrapper for the Gnu Scientific 
Library. Rnews 6(4):24-26 


Joseph F. Lucke
Senior Statistician
Research Institute on Addictions
University at Buffalo
State University of New York
1021 Main Street
Buffalo, NY  14203-1016
Office: 716-887-6807
Fax: 716-887-2510
http://www.ria.buffalo.edu/profiles/lucke.html




Roslina Zakaria  
Sent by: r-help-boun...@r-project.org
04/07/2009 02:29 AM

To
r-help@r-project.org
cc

Subject
[R] Maple and R







Hi R-users,

Can Maple function be exported to R?
I have a jacobian matrix (4X4) from maple in algebraic form which involve 
modified Bessel function of the first kind.

I just wonder whether we can use algebraic form into R before the value of 
the parameters can be estimated.

Thank you so much for your attention and help.




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


[[alternative HTML version deleted]]

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


Re: [R] better way of recoding factors in data frame?

2009-04-09 Thread Thomas Lumley

On Thu, 9 Apr 2009 mohinder_da...@yahoo.com wrote:



Hi all,

I apologize in advance for the length of this post, but I wanted to make sure 
I was clear.


Good strategy.



I tried this:


myFrame2$newSex <- ifelse(myFrame2$newSex ==1 || myFrame2$newSex == 2, 
myFrame2$newSex, 0)




First, you need |, not ||, because || returns just a single value.

This still won't quite work, because the condition will be NA when newSex is NA 
(if you don't know a number then you don't know whether it is equal to 1 or 2).

So,
myFrame2$newSex <- ifelse(myFrame2$newSex %in% c(1,2), myFrame2$newSex, 0)

or, slightly shorter
myFrame2$newSex <- with(myFrame2, ifelse(newSex %in% c(1,2), newSex, 0)

-thomas

Thomas Lumley   Assoc. Professor, Biostatistics
tlum...@u.washington.eduUniversity of Washington, Seattle

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] better way of recoding factors in data frame?

2009-04-09 Thread mohinder_datta

Hi all,

I apologize in advance for the length of this post, but I wanted to make sure I 
was clear.

I am trying to merge two dataframes that share a number of rows (but some are 
unique to each data frame). Each row represents a subject in a study. The 
problem is that sex is coded differently in the two, including the way missing 
values are represented.

Here is an example of the merged dataframe:

> myFrame2
   SubjCode SubjSex          Sex
1      sub1       M         
2      sub2       F         
3      sub3       M         Male
4      sub4       M         
5      sub5       F         
6      sub6       F       Female
7      sub7                 
8      sub8                 
9      sub9         Not Recorded
10    sub10         Not Recorded

I then apply the following:

> myFrame2$SubjSex <- factor(myFrame2$SubjSex, levels = c('M','F'))
> myFrame2$SubjSex <- factor(myFrame2$SubjSex, labels = c('Male','Female'))
> myFrame2 <- transform(myFrame2, newSex = ifelse(is.na(SubjSex), Sex, SubjSex))

...and get this:
> myFrame2
   SubjCode SubjSex          Sex newSex
1      sub1    Male           1
2      sub2  Female           2
3      sub3    Male         Male      1
4      sub4    Male           1
5      sub5  Female           2
6      sub6  Female       Female      2
7      sub7              NA
8      sub8              NA
9      sub9     Not Recorded      3
10    sub10     Not Recorded      3

I need that last column to have just 1 (Male), 2 (Female) or 0 (Missing), and 
the only way I've come up with seems very kludgy:

> myFrame2$newSex[is.na(myFrame2$newSex)] <- 0
> myFrame2$newSex <- ifelse(myFrame2$newSex == 3, 0, myFrame2$newSex)

That gives me the right values for "newSex", but I'd like to positively select 
for the values I want to keep, rather than negatively selecting the ones to 
change - I tried this:

> myFrame2$newSex <- ifelse(myFrame2$newSex ==1 || myFrame2$newSex == 2, 
> myFrame2$newSex, 0)

But I just get 1 for every row in newSex. Does anyone know of a way to do this 
by positively selecting the values 1 and 2?


Thanks,
Mohinder






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


Re: [R] Maple and R

2009-04-09 Thread JLucke
You can export the Maple code to C or Fortran.  I actually found it easier 
to export it to Fortran and then use a text editor to change Fortran's 
assignment ='s to R's <-.  After additional tweaks for R, you can convert 
the script into an R function. 

Joseph F. Lucke
Senior Statistician
Research Institute on Addictions
University at Buffalo
State University of New York
1021 Main Street
Buffalo, NY  14203-1016
Office: 716-887-6807
Fax: 716-887-2510
http://www.ria.buffalo.edu/profiles/lucke.html




Roslina Zakaria  
Sent by: r-help-boun...@r-project.org
04/07/2009 02:29 AM

To
r-help@r-project.org
cc

Subject
[R] Maple and R







Hi R-users,

Can Maple function be exported to R?
I have a jacobian matrix (4X4) from maple in algebraic form which involve 
modified Bessel function of the first kind.

I just wonder whether we can use algebraic form into R before the value of 
the parameters can be estimated.

Thank you so much for your attention and help.




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

2009-04-09 Thread Iuri Gavronski
Hi,

I am not sure if R-help is the right forum for my question. If not,
please let me know.

I have to do some discriminant validity tests with some constructs. I
am using the method of doing a CFA constraining the correlation of a
pair of the constructs to 1 and comparing the chi-square of this
constrained model to the unconstrained model. If the chi-square
difference is not significant, then I cannot reject the null
hypothesis that the two constructs are equal.

Well, if you are going to test, say, 4 constructs (A, B, C, and D),
you will have to have 2*C(4,2) = 12 models to test, 5 constructs, 20
models, and so forth. A tedious and error prone process...

So far, I have been using AMOS for that shake, given that 1) my
university has the license, 2) my other colleagues use it, and 3) I
know it ;)

I would like to know if any of you use R, namely the sem package, for
that application and if you can share your thoughts/experiences on
using it. I don't thing I would have problems "porting" my models to
R/sem, but I would like to know if there is an optimized process of
doing that tests, without manually coding all the dozens of models.

Best,

Iuri.

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


Re: [R] seemingly unrelated regression

2009-04-09 Thread Ben Bolker



livia wrote:
> 
> Hello,
> 
> I am working on the model of seemingly unrelated regression. I came across
> with the error message:
> 
> Log determinant of residual covariance: NA 
> Warning messages:
>   NAs generated in: log(x)
> 
> I have three linear models which contain 21 explanatory variables and
> there are about 300 data points.
> 
> Could anyone please give some idea what is wrong with the model?
> 

We can't possibly help without knowing what functions and packages you are
trying to use
(the results of sessionInfo() would be useful), and most likely we can't
help
without a reproducible example ...

  Ben Bolker

-- 
View this message in context: 
http://www.nabble.com/seemingly-unrelated-regression-tp22970572p22971060.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] R segfaulting with glmnet on some data, not other

2009-04-09 Thread Kamalic Dan
Thanks, Gad.  Lisa's professor knows the glmnet authors, so we will forward 
this request directly to them.  Take care!

Dan





From: Gad Abraham 

Cc: r-help@r-project.org; lp...@bu.edu
Sent: Tuesday, April 7, 2009 10:26:26 PM
Subject: Re: [R] R segfaulting with glmnet on some data, not other

Kamalic Dan wrote:
> Hello R-help list,
> 
> 
> I have a piece of code written by a grad student here at BU which will 
> segfault when using one data set, but complete just fine using another.  Both 
> sets are just text files full of real numbers.
> 
> It seems like a bug within R.  It could be a bug within her data, but
> again, her data is just a bunch of floats, so her data could be
> triggering a bug within R.  I have tried this with two different rpm packages 
> of R for Linux (R-2.8.0-1.rh5 and R-2.8.1-1.rh5) as well as a fresh build 
> that I just did of the prerelease R-beta_2009-04-02_r48271.tar.gz
> I have also tried installing the absolute newest versions of  
> glmnet_1.1-3.tar.gz and Matrix_0.999375-23.tar.gz.  In all cases, the exact 
> same error occurs.
> 
[[elided Yahoo spam]]

>From your traceback it seems it's not a bug in R itself, but in the package 
>glmnet.

It's probably best to chase it up with the package authors since glmnet is not 
a base R package.

-- Gad Abraham
MEng Student, Dept. CSSE and NICTA
The University of Melbourne
Parkville 3010, Victoria, Australia
email: gabra...@csse.unimelb.edu.au
web: http://www.csse.unimelb.edu.au/~gabraham



  
[[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] seemingly unrelated regression

2009-04-09 Thread livia

Hello,

I am working on the model of seemingly unrelated regression. I came across
with the error message:

Log determinant of residual covariance: NA 
Warning messages:
  NAs generated in: log(x)

I have three linear models which contain 21 explanatory variables and there
are about 300 data points.

Could anyone please give some idea what is wrong with the model?
-- 
View this message in context: 
http://www.nabble.com/seemingly-unrelated-regression-tp22970572p22970572.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Cross-platforms solution to export R graphs

2009-04-09 Thread Philippe Grosjean

Hello Rusers,

I have worked on a R Wiki page for solutions in exporting R graphs, 
especially, the often-asked questions:
- How can I export R graphs in vectorized format (EMF) for inclusion in 
 MS Word or OpenOffice outside of Windows?

- What is the best solution(s) for post-editing/annotating R graphs.

The page is at: 
http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-misc:export.


I would be happy to receive your comments and suggestions to improve 
this document.

All the best,

PhG
--
..<°}))><
 ) ) ) ) )
( ( ( ( (Prof. Philippe Grosjean
 ) ) ) ) )
( ( ( ( (Numerical Ecology of Aquatic Systems
 ) ) ) ) )   Mons-Hainaut University, Belgium
( ( ( ( (
..

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

2009-04-09 Thread Matias Bordese
Hi Bob,

> I have tried several times to load biOps package after reading the posts in 
> this archive regarding the necessity of placing these two libs in the PATH 
> (libjpeg62.dll and libtiff3.dll).  I have tried locating the libs in several 
> directories that should have worked, but I still get the following message.
> --
>         Error in inDL(x, as.logical(local), as.logical(now), ...) :
>         unable to load shared library 'C:/Program 
> Files/R/R-2.8.1/library/biOps/libs/biOps.dll':
>         LoadLibrary failure:  The specified module could not be found.
>
>         Error: package/namespace load failed for 'biOps'
> -
> I am using R version 2.8.1 (2008-12-22) with Win-XP and Jaguar GUI
>
> Can anyone give me a hint about where to place the libs and how to get the 
> biOps package to work. It looks like the package could solve several of my 
> image processing problems.

It sounds like the required libraries are not correctly installed. In
a windows setup it is a kind of complex step to get it to work. We
have the idea to improve the installation step. I have a zip file
(that you can download here:
http://rapidshare.com/files/219274717/libs.zip.html) with the needed
dll's that you should decompress in the libs directoryof the biOps
package (something similar to C:/R-2.8.1/library/biOps/libs/). Tell me
if it helps. I hope you get it to work and solve you needs. Any
problem or question, just let me know.

Best regards,
Matías.

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


Re: [R] data.fram zero's

2009-04-09 Thread Dimitris Rizopoulos

well, you can first create a matrix and then turn into a data frame, e.g.,

mat <- matrix(0, 5, 10)
as.data.frame(mat)


I hope it helps.

Best,
Dimitris


Duijvesteijn, Naomi wrote:

   Hi all,


   A simple question which I don’t seem to be able to solve:


   I want to make a data.frame of 360 rows and 94228 column with only zero’s
   without having to type all these zero’s ;-)


   What is the easiest method?


   Thanks,

   Naomi

   
   
   
   Disclaimer:  De  informatie opgenomen in dit bericht (en bijlagen) kan

   vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde(n).
   Indien u dit bericht ten onrechte ontvangt, wordt u geacht de inhoud niet te
   gebruiken, de afzender direct te informeren en het bericht te vernietigen.
   Aan dit bericht kunnen geen rechten of plichten worden ontleend.

   
   

   Disclaimer: The information contained in this message may be confidential
   and is intended to be exclusively for the addressee. Should you receive this
   message unintentionally, you are expected not to use the contents herein, to
   notify the sender immediately and to destroy the message. No rights can be
   derived from this message.




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


--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

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


Re: [R] Sweave problem, with multicolumn tables from R to LaTeX

2009-04-09 Thread Christian Salas

hi Ista,
i did load xtable() before because i was comparing if using it was any 
different, but still i got the same problem.

I hope somebody can give us a solution or some tips soon!

thanks
c
---
Christian Salas E-mail:christian.sa...@yale.edu
PhD candidate   http://environment.yale.edu/salas
School of Forestry and Environmental Studies
Yale University Tel: +1-(203)-432 5126
360 Prospect St Fax:+1-(203)-432 3809
New Haven, CT 06511-2189Office: Room 35, Marsh Hall
USA

Yale Biometrics Lab  http://environment.yale.edu/biometrics
---





Ista Zahn wrote:

Hi Christian,
I've been having this problem as well. There are bug reports about
this (one of them mine):
http://biostat.mc.vanderbilt.edu/trac/Hmisc/ticket/25
http://biostat.mc.vanderbilt.edu/trac/Hmisc/ticket/28
so hopefully the developers are aware of the problem and will address
it in the next release.


By the way: what do you need the xtable library for? I see that you
loaded it, but never call any of the functions in your example code.

All the best,
Ista
From: Christian Salas 
To: r-help@r-project.org
Date: Wed, 08 Apr 2009 12:05:34 -0400
Subject: [R] Sweave problem, with multicolumn tables from R to LaTeX
Hi there,

I have been using the example provided bellow for a while, and It was
working without any problem. Nevertheless, just since 2-3 days is not
working, probably because I did update.packages(). I have tried to
re-install the older versions of the packages Hmisc() and xtable(),
but still does not work. Can you run this example, and tell me if you
got the same problems?

I use linux-ubuntu, and R 2.8.1

Here is my .Rnw file

%%%
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{Sweave}
\SweaveOpts{echo=TRUE}

\title{Why is not working this? a table from R having multi columns
names}
\author{Myself}
\date{\today}

\begin{document}
\maketitle

<>=
#Calling some packages
library(Hmisc)
library(xtable)

#version of the packages
packageDescription('Hmisc')$Version #version of Hmisc
packageDescription('xtable')$Version  #version of xtable

#version and features of my PC and R
R.version$platform
R.version$version.string
@

\section{The table ready to be exported}
An R table as an example.
<<>>=
tab.coef.allmodels <-
structure(c(246.8809, 153.6952, 43.6259, 1823.686, -4.0138, -53.8741,
-13.9552, -699.7154, 0, -3.0084, -0.5188, -41.7249, 4.0898,
2.0342, 0.2798, 25.636, 235.5128, 160.0244, 30.0147, 1523.0723,
3.7601, -53.9238, -3.9789, -597.1446, 0, -3.2745, -0.0025, -28.7418,
4.4203, 2.1606, 0.0124, 17.9259), .Dim = c(4L, 8L), .Dimnames = list(
   c("NHA", "GHA", "Hdom", "VHA"), c("Intercept", "stand2",
   "band3", "band7", "Intercept", "stand2", "band3", "band7"
   )))
tab.coef.allmodels
@

\section{Producing the \LaTeX\ table}
\subsection{Showing a simple output table, but not being
 the aimed one}

The following syntax produce Table \ref{tab:coefAllmod1}, which is not
what I want.
<>=
l <- latex(tab.coef.allmodels, file="tab.coefAllmod1.tex",
rowlabel="Model for",
 first.hline.double=FALSE,
 rowlabel.just="l",
caption="MLR and LME parameter estimates by stand variables",
 caption.loc="top", label="tab:coefAllmod1",where="!h")
@

\input{tab.coefAllmod1}


\subsection{What I want, but not getting it right}
The following syntax produce Table \ref{tab:coefAllmod2}, which
contains all the information that i want, but is not giving me
the correct format.
<>=
l <- latex(tab.coef.allmodels, file="tab.coefAllmod2.tex",
rowlabel="Model for",
 first.hline.double=FALSE,
 rowlabel.just="l",
cgroup=c("MLR","LME"),
n.cgroup=c(4,4),
caption="MLR and LME parameter estimates by stand variables",
 caption.loc="top", label="tab:coefAllmod2",where="!h")
@

\input{tab.coefAllmod2}

I have been using this
syntax for a while, and was working without any problem.
 Nevertheless, just since 2-3 days is not working, probably
 because I did {\tt update.packages()}.
 I have tried to re-install the older versions of the packages
 {\tt Hmisc()} and {\tt xtable()}, but still does not work.

\vspace{1in}
{\Large   {\bf What Am I missing here?}}

\end{document}

%%%

The the main .tex file, tables, the ouput pdf, and the .Rnw files are
in the following url, if you want to check them

http://environment.yale.edu/salas/questions/shortTable/multcolTable_short.tex
http://environment.yale.edu/salas/questions/shortTable/tab.coefAllmod1.tex
http://environment.yale.edu/salas/questions/shortTable/tab.coefAllmod2.tex
http://environment.yale.edu/salas/questions/shortTable/multcolTable_short.pdf
http://environment.yale.edu/salas/questions/shortTable/multcolTable_short.Rnw

thanks in advance for your help



__
R-help@r-project.org m

Re: [R] reading an image and adding a legend

2009-04-09 Thread Dieter Menne
Simon Pickett  bto.org> writes:

> But my code returns an error
> 
> x<-read.pnm("C:/Documents and Settings/simonp/My Documents/Simon BTO/RELU/GIS
data/ten km areas in analysis.bmp")
> Error in pm.readmagicnumber(con) : Not a PNM format file

Error message seems quite clear: bmp a non-supported format. Some year ago,
the wisdom was to convert your images using imagemagick

http://finzi.psych.upenn.edu/R/Rhelp02/archive/23131.html

But read.jpeg should work (another variant in rimage), if that's good enough
for your graphics

Dieter

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


[R] data.fram zero's

2009-04-09 Thread Duijvesteijn, Naomi

   Hi all,


   A simple question which I don’t seem to be able to solve:


   I want to make a data.frame of 360 rows and 94228 column with only zero’s
   without having to type all these zero’s ;-)


   What is the easiest method?


   Thanks,

   Naomi

   
   
   
   Disclaimer:  De  informatie opgenomen in dit bericht (en bijlagen) kan
   vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde(n).
   Indien u dit bericht ten onrechte ontvangt, wordt u geacht de inhoud niet te
   gebruiken, de afzender direct te informeren en het bericht te vernietigen.
   Aan dit bericht kunnen geen rechten of plichten worden ontleend.

   
   

   Disclaimer: The information contained in this message may be confidential
   and is intended to be exclusively for the addressee. Should you receive this
   message unintentionally, you are expected not to use the contents herein, to
   notify the sender immediately and to destroy the message. No rights can be
   derived from this message.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sweave problem, with multicolumn tables from R to LaTeX

2009-04-09 Thread Ista Zahn
Hi Christian,
I've been having this problem as well. There are bug reports about
this (one of them mine):
http://biostat.mc.vanderbilt.edu/trac/Hmisc/ticket/25
http://biostat.mc.vanderbilt.edu/trac/Hmisc/ticket/28
so hopefully the developers are aware of the problem and will address
it in the next release.


By the way: what do you need the xtable library for? I see that you
loaded it, but never call any of the functions in your example code.

All the best,
Ista
From: Christian Salas 
To: r-help@r-project.org
Date: Wed, 08 Apr 2009 12:05:34 -0400
Subject: [R] Sweave problem, with multicolumn tables from R to LaTeX
Hi there,

I have been using the example provided bellow for a while, and It was
working without any problem. Nevertheless, just since 2-3 days is not
working, probably because I did update.packages(). I have tried to
re-install the older versions of the packages Hmisc() and xtable(),
but still does not work. Can you run this example, and tell me if you
got the same problems?

I use linux-ubuntu, and R 2.8.1

Here is my .Rnw file

%%%
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{Sweave}
\SweaveOpts{echo=TRUE}

\title{Why is not working this? a table from R having multi columns
names}
\author{Myself}
\date{\today}

\begin{document}
\maketitle

<>=
#Calling some packages
library(Hmisc)
library(xtable)

#version of the packages
packageDescription('Hmisc')$Version #version of Hmisc
packageDescription('xtable')$Version  #version of xtable

#version and features of my PC and R
R.version$platform
R.version$version.string
@

\section{The table ready to be exported}
An R table as an example.
<<>>=
tab.coef.allmodels <-
structure(c(246.8809, 153.6952, 43.6259, 1823.686, -4.0138, -53.8741,
-13.9552, -699.7154, 0, -3.0084, -0.5188, -41.7249, 4.0898,
2.0342, 0.2798, 25.636, 235.5128, 160.0244, 30.0147, 1523.0723,
3.7601, -53.9238, -3.9789, -597.1446, 0, -3.2745, -0.0025, -28.7418,
4.4203, 2.1606, 0.0124, 17.9259), .Dim = c(4L, 8L), .Dimnames = list(
   c("NHA", "GHA", "Hdom", "VHA"), c("Intercept", "stand2",
   "band3", "band7", "Intercept", "stand2", "band3", "band7"
   )))
tab.coef.allmodels
@

\section{Producing the \LaTeX\ table}
\subsection{Showing a simple output table, but not being
 the aimed one}

The following syntax produce Table \ref{tab:coefAllmod1}, which is not
what I want.
<>=
l <- latex(tab.coef.allmodels, file="tab.coefAllmod1.tex",
rowlabel="Model for",
 first.hline.double=FALSE,
 rowlabel.just="l",
caption="MLR and LME parameter estimates by stand variables",
 caption.loc="top", label="tab:coefAllmod1",where="!h")
@

\input{tab.coefAllmod1}


\subsection{What I want, but not getting it right}
The following syntax produce Table \ref{tab:coefAllmod2}, which
contains all the information that i want, but is not giving me
the correct format.
<>=
l <- latex(tab.coef.allmodels, file="tab.coefAllmod2.tex",
rowlabel="Model for",
 first.hline.double=FALSE,
 rowlabel.just="l",
cgroup=c("MLR","LME"),
n.cgroup=c(4,4),
caption="MLR and LME parameter estimates by stand variables",
 caption.loc="top", label="tab:coefAllmod2",where="!h")
@

\input{tab.coefAllmod2}

I have been using this
syntax for a while, and was working without any problem.
 Nevertheless, just since 2-3 days is not working, probably
 because I did {\tt update.packages()}.
 I have tried to re-install the older versions of the packages
 {\tt Hmisc()} and {\tt xtable()}, but still does not work.

\vspace{1in}
{\Large   {\bf What Am I missing here?}}

\end{document}

%%%

The the main .tex file, tables, the ouput pdf, and the .Rnw files are
in the following url, if you want to check them

http://environment.yale.edu/salas/questions/shortTable/multcolTable_short.tex
http://environment.yale.edu/salas/questions/shortTable/tab.coefAllmod1.tex
http://environment.yale.edu/salas/questions/shortTable/tab.coefAllmod2.tex
http://environment.yale.edu/salas/questions/shortTable/multcolTable_short.pdf
http://environment.yale.edu/salas/questions/shortTable/multcolTable_short.Rnw

thanks in advance for your help

-- 
---
Christian Salas E-mail:christian.sa...@yale.edu
PhD candidate   http://environment.yale.edu/salas
School of Forestry and Environmental Studies
Yale University Tel: +1-(203)-432 5126
360 Prospect St Fax:+1-(203)-432 3809
New Haven, CT 06511-2189Office: Room 35, Marsh Hall
USA

Yale Biometrics Lab  http://environment.yale.edu/biometrics

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


Re: [R] problems with integrate ... arguments

2009-04-09 Thread Duncan Murdoch

On 09/04/2009 8:07 AM, Richard Morey wrote:

Hi everyone,

I saw this problem dealt with here:
http://markmail.org/search/list:r-project?q=integrate#query:list%3Ar-project%20integrate+page:1+mid:qczmyzr676pgmaaw+state:results

but no one answered that request that I can tell. I'm having the same
problem. I'm having problems passing arguments to functions that I'd
like to integrate. I could swear this worked in the past, but I can't
get it to work now. I'm running R on Windows.

Here's my toy code to reproduce the problem:


R.Version()$version.string
# [1] "R version 2.8.1 (2008-12-22)"

f=function(x,const)
2^x+const

f2=Vectorize(f,c("x"))

testval=2

f2(1:5,testval)
# [1]  4  6 10 18 34
# The vectorized function seems to work right.

integrate(f2,.5,1,c=2)
# Works. Returns
# 1.845111 with absolute error < 2.0e-14

integrate(f=f2,.5,1,const=testval)
# Doesn't work. Returns
# Error in eval(expr, envir, enclos) :
#  ..1 used in an incorrect context, no ... to look in

I understand that I don't have to Vectorize this function for it to
work, but the more complicated functions I'm using require Vectorization.

Why can't I pass the argument "const" as a variable, instead of a value?
  I don't understand this error.


I'm not sure what's happening exactly; both Vectorize and integrate do 
tricky things with evaluation frames, and it looks as though they are 
not interacting well.


As a workaround, I'd suggest using a single argument function f instead:

> makef <- function(const) {
+   return(function(x) 2^x + const)
+ }

makef(testval) will capture the value of testval, so we don't need to 
pass it, and then things work:


> f <- makef(testval)
> f2 <- Vectorize(f)
> integrate(f=f2, 0.5, 1)
1.845111 with absolute error < 2.0e-14

Duncan Murdoch

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


Re: [R] R interpreter not recognized

2009-04-09 Thread Maria I. Tchalakova
Hi Paul,

I am using Slackware 12.0.0.

Maria

On Thu, Apr 9, 2009 at 2:35 PM, Paul Smith  wrote:
> On Thu, Apr 9, 2009 at 9:01 AM, Maria I. Tchalakova
>  wrote:
>> I am trying to install a program based on R, but I am receiving the
>> following error message:
>> r...@darkstar:/home/maria/UCS# perl System/Install.perl
>> Error: Can't run the R interpreter (/usr/local/bin/R).
>> Please make sure that R is installed and specify the fully qualified
>> filename of the R interpreter with -R if necessary (see "doc/install.txt").
>>
>> I do have installed R, and I can see it (it is working also fine when I use 
>> it):
>>> which R
>>> /usr/local/bin/R
>> I have specified the location of the R interpreter with -R (or -rh)
>> /usr/local/bin/R" when running the program, but it still doesn't work.
>> I have also used -R /usr/local/lib/R/bin/R or -rh
>> /usr/local/lib/R/bin/R.
>> I have also added the locations to my search path.
>>
>> It seems that the problem comes from my environment, but I cannot
>> figure out what's wrong. Do you have any clues why the interpreter
>> cannot be found?
>
> Maria: what is the Linux distribution that you are using?
>
> Paul
>

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

2009-04-09 Thread enrico.fosco...@libero.it
Good morning to all,

I should find the zero of a specific function,

func(x,f.
me,c,t)=x+f.me*c-t

where 'c' and 't' are constants and 'f.me' is an other 
function of 'x'.
Actually, I am interested in considering 'f.me' as an 
expression().

Namely,

uniroot.me<-function(f.me,c,t){


func<-function(x,
f.me,c,t) x+eval(f.me)*c-t



uniroot(func,c(0,1),f.me=f.me,c=c,t=t)$root




}


uniroot.me(expression(x*(1-x)),c=1,t=1)

For instance, let me suppose 
that 'f.me=expression(x^a*(1-x))'. How should I do in order to introduce the 
new constant 'a' in function 'uniroot.me'?

Thank you very much,

Enrico 
Foscolo

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


Re: [R] Biexponential Fit

2009-04-09 Thread Jonas Weickert

Thank you! Now it's working.

Peter Dalgaard schrieb:

Jonas Weickert wrote:

Hi,

I want to do a biexponential Fit, i.e.

y ~ A1*exp(k1*x) + A2*exp(k2*x)

Is this possible? I tried nls() but it stopped with several 
(different) errors. I'm using y and x as simple vectors and the 
formula for nls() exactly as mentioned above.


Yes, it is possible, with some reservations. There is even a 
self-starting model for it (SSbiexp), at least if k1,k2 are negative.


The reservations are that you need good data and good starting values 
for the fit. The model is theoretically unidentifiable because you can 
switch 1 and 2 and get the same model, which becomes an issue if you 
start too fra from the optimum. Worse, if k1 and k2 are similar, the 
whole system becomes ill-conditioned. There's a rule of thumb requiring 
a factor of 5 or more between k1 and k2, for pharmacokinetic applications.



Thanks a lot!

Jonas

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

2009-04-09 Thread Jeffrey Horner

Jason Rupert wrote:
Related to the posting below, by any chance is there a "Template Engine" package for R? 


Indeed there is. It's called brew:

http://cran.r-project.org/web/packages/brew/index.html

Jeff



http://en.wikipedia.org/wiki/Template_processor

This may make this type of editing much easier?  Maybe...

Thanks again.



--- On Wed, 4/8/09, Jason Rupert  wrote:


From: Jason Rupert 
Subject: Re: [R] R File I/O Capability - Writing output to specific lines of 
existing file
To: "jim holtman" 
Cc: R-help@r-project.org
Date: Wednesday, April 8, 2009, 11:26 PM
Darn.

I was afraid of this.  Always kind of weak when it comes to
file I/O approaches, so I guess I will have to stretch and
try to put something together.   


Yeah.  The input flat text file is about 600 lines long.  I
will be replacing about 200.  I already have the template
for those 200 lines.  I guess I will just need to read down
to line 400 and replace until line 600.  

Thanks again for all the insights regarding this. 




--- On Wed, 4/8/09, jim holtman 
wrote:


From: jim holtman 
Subject: Re: [R] R File I/O Capability - Writing

output to specific lines of  existing file

To: jasonkrup...@yahoo.com
Cc: R-help@r-project.org
Date: Wednesday, April 8, 2009, 8:02 PM
You can always read in the initialization file, make the
updates to it and then write it back out.  If it is a text 
file, it would be very hard to write into the middle of 
it since there is no structure to the file.  You can read 
it in as a table (read.table) or just as lines
(readLines) and the make any changes you want.  You can use 
regular expressions if you want to put something in the 
middle of one of the lines you have read in.


On Wed, Apr 8, 2009 at 10:13 AM, Jason Rupert
 wrote:
Currently I am using the R "write"command
to output results to a *.txt file and then copying those
results into an initialization file.  In an attempt to
continue to automate the process I would like to have R
write to the location in the existing initialization file,
instead of me copying the data over.
By any chance are there any R commands to help?
Primarily, I will be using Windows, and the
initialization file is a simple flat file, i.e. not XML or
binary.

I looked at:
(a)

http://www.stat.ucl.ac.be/ISdidactique/Rhelp/library/R.io/html/00Index.html

(b) 
http://search.r-project.org/cgi-bin/namazu.cgi?query=File+I%2FO&max=100&result=normal&sort=score&idxname=functions&idxname=Rhelp08

But, this did not appear to provide the functionality
to edit an existing file by adding information to the middle
of the file.

Thank you again for any help and insight.






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

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


Re: [R] R interpreter not recognized

2009-04-09 Thread Paul Smith
On Thu, Apr 9, 2009 at 9:01 AM, Maria I. Tchalakova
 wrote:
> I am trying to install a program based on R, but I am receiving the
> following error message:
> r...@darkstar:/home/maria/UCS# perl System/Install.perl
> Error: Can't run the R interpreter (/usr/local/bin/R).
> Please make sure that R is installed and specify the fully qualified
> filename of the R interpreter with -R if necessary (see "doc/install.txt").
>
> I do have installed R, and I can see it (it is working also fine when I use 
> it):
>> which R
>> /usr/local/bin/R
> I have specified the location of the R interpreter with -R (or -rh)
> /usr/local/bin/R" when running the program, but it still doesn't work.
> I have also used -R /usr/local/lib/R/bin/R or -rh
> /usr/local/lib/R/bin/R.
> I have also added the locations to my search path.
>
> It seems that the problem comes from my environment, but I cannot
> figure out what's wrong. Do you have any clues why the interpreter
> cannot be found?

Maria: what is the Linux distribution that you are using?

Paul

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 an image and adding a legend

2009-04-09 Thread Simon Pickett
Hi all,

I would like to
1. Read in an arcmap image into R (I can export pretty much any type of image 
jpeg, bitmap etc from arcmap)
2. Use R to create a nice colour legend in the plot

First of all, Is this possible?

So far I'm stuck on point 1. I have tried read.pnm() from pixmap and 
read.jpeg() from rgl.

the pnm example provided works fine
x <- read.pnm(system.file("pictures/logo.ppm", package="pixmap")[1])
plot(x)
#draws an R logo, nice :-)

But my code returns an error

x<-read.pnm("C:/Documents and Settings/simonp/My Documents/Simon BTO/RELU/GIS 
data/ten km areas in analysis.bmp")
Error in pm.readmagicnumber(con) : Not a PNM format file

I have tried changing the dpi when I export the image but still no cigar.
I have dredged the help forum for related files and read the help files. My Os 
is windows XP and i'm running 2.8.1.

I feel I'm missing something obvious!
Thanks



Dr. Simon Pickett
Research Ecologist
Land Use Department
Terrestrial Unit
British Trust for Ornithology
The Nunnery
Thetford
Norfolk
IP242PU
01842750050

[[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] Biexponential Fit

2009-04-09 Thread Peter Dalgaard

Jonas Weickert wrote:

Hi,

I want to do a biexponential Fit, i.e.

y ~ A1*exp(k1*x) + A2*exp(k2*x)

Is this possible? I tried nls() but it stopped with several (different) 
errors. I'm using y and x as simple vectors and the formula for nls() 
exactly as mentioned above.


Yes, it is possible, with some reservations. There is even a 
self-starting model for it (SSbiexp), at least if k1,k2 are negative.


The reservations are that you need good data and good starting values 
for the fit. The model is theoretically unidentifiable because you can 
switch 1 and 2 and get the same model, which becomes an issue if you 
start too fra from the optimum. Worse, if k1 and k2 are similar, the 
whole system becomes ill-conditioned. There's a rule of thumb requiring 
a factor of 5 or more between k1 and k2, for pharmacokinetic applications.



Thanks a lot!

Jonas

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

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



--
   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] Template Engine Package for R?

2009-04-09 Thread Barry Rowlingson
On Thu, Apr 9, 2009 at 12:42 PM, Jason Rupert  wrote:
>
> Related to the posting below, by any chance is there a "Template Engine" 
> package for R?
>
> http://en.wikipedia.org/wiki/Template_processor
>
> This may make this type of editing much easier?  Maybe...

Have you tried the 'brew' package? It lets you embed tagged R
expressions inside text files:

http://ftp.heanet.ie/mirrors/cran.r-project.org/web/packages/brew/index.html

 (or a mirror near you)

Barry

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

2009-04-09 Thread Richard Morey
Hi everyone,

I saw this problem dealt with here:
http://markmail.org/search/list:r-project?q=integrate#query:list%3Ar-project%20integrate+page:1+mid:qczmyzr676pgmaaw+state:results

but no one answered that request that I can tell. I'm having the same
problem. I'm having problems passing arguments to functions that I'd
like to integrate. I could swear this worked in the past, but I can't
get it to work now. I'm running R on Windows.

Here's my toy code to reproduce the problem:


R.Version()$version.string
# [1] "R version 2.8.1 (2008-12-22)"

f=function(x,const)
2^x+const

f2=Vectorize(f,c("x"))

testval=2

f2(1:5,testval)
# [1]  4  6 10 18 34
# The vectorized function seems to work right.

integrate(f2,.5,1,c=2)
# Works. Returns
# 1.845111 with absolute error < 2.0e-14

integrate(f=f2,.5,1,const=testval)
# Doesn't work. Returns
# Error in eval(expr, envir, enclos) :
#  ..1 used in an incorrect context, no ... to look in

I understand that I don't have to Vectorize this function for it to
work, but the more complicated functions I'm using require Vectorization.

Why can't I pass the argument "const" as a variable, instead of a value?
  I don't understand this error.

Thanks in advance,
Richard Morey

-- 
Richard D. Morey
Assistant Professor
Psychometrics and Statistics
Rijksuniversiteit Groningen / University of Groningen

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


Re: [R] R File I/O Capability - Writing output to specific lines of existing file

2009-04-09 Thread jim holtman
With only 600 lines, it is relatively easy to read it in and replace
some lines.  For example (untested) is you wanted to replace lines
150:250 with your data, you would do

input <- readLines('filename')
input <- c(input[1:149], newData, input[251:length(input)])
writeLines(input, file='filename')

That does not seem too hard.

On Thu, Apr 9, 2009 at 12:26 AM, Jason Rupert  wrote:
>
> Darn.
>
> I was afraid of this.  Always kind of weak when it comes to file I/O 
> approaches, so I guess I will have to stretch and try to put something 
> together.
>
> Yeah.  The input flat text file is about 600 lines long.  I will be replacing 
> about 200.  I already have the template for those 200 lines.  I guess I will 
> just need to read down to line 400 and replace until line 600.
>
> Thanks again for all the insights regarding this.
>
>
>
> --- On Wed, 4/8/09, jim holtman  wrote:
>
>> From: jim holtman 
>> Subject: Re: [R] R File I/O Capability - Writing output to specific lines of 
>>  existing file
>> To: jasonkrup...@yahoo.com
>> Cc: R-help@r-project.org
>> Date: Wednesday, April 8, 2009, 8:02 PM
>> You can always read in the initialization file, make the
>> updates to it
>> and then write it back out.  If it is a text file, it would
>> be very
>> hard to write into the middle of it since there is no
>> structure to the
>> file.  You can read it in as a table (read.table) or just
>> as lines
>> (readLines) and the make any changes you want.  You can use
>> regular
>> expressions if you want to put something in the middle of
>> one of the
>> lines you have read in.
>>
>> On Wed, Apr 8, 2009 at 10:13 AM, Jason Rupert
>>  wrote:
>> >
>> > Currently I am using the R "write" command
>> to output results to a *.txt file and then copying those
>> results into an initialization file.  In an attempt to
>> continue to automate the process I would like to have R
>> write to the location in the existing initialization file,
>> instead of me copying the data over.
>> >
>> > By any chance are there any R commands to help?
>> >
>> > Primarily, I will be using Windows, and the
>> initialization file is a simple flat file, i.e. not XML or
>> binary.
>> >
>> > I looked at:
>> > (a)
>> http://www.stat.ucl.ac.be/ISdidactique/Rhelp/library/R.io/html/00Index.html
>> >
>> > (b)
>> http://search.r-project.org/cgi-bin/namazu.cgi?query=File+I%2FO&max=100&result=normal&sort=score&idxname=functions&idxname=Rhelp08
>> >
>> > But, this did not appear to provide the functionality
>> to edit an existing file by adding information to the middle
>> of the file.
>> >
>> > Thank you again for any help and insight.
>> >
>> > __
>> > R-help@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/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?
>
>
>
>



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

What is the problem that you are trying to solve?

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

2009-04-09 Thread Jason Rupert

Related to the posting below, by any chance is there a "Template Engine" 
package for R? 

http://en.wikipedia.org/wiki/Template_processor

This may make this type of editing much easier?  Maybe...

Thanks again.



--- On Wed, 4/8/09, Jason Rupert  wrote:

> From: Jason Rupert 
> Subject: Re: [R] R File I/O Capability - Writing output to specific lines of 
> existing file
> To: "jim holtman" 
> Cc: R-help@r-project.org
> Date: Wednesday, April 8, 2009, 11:26 PM
> Darn.
> 
> I was afraid of this.  Always kind of weak when it comes to
> file I/O approaches, so I guess I will have to stretch and
> try to put something together.   
> 
> Yeah.  The input flat text file is about 600 lines long.  I
> will be replacing about 200.  I already have the template
> for those 200 lines.  I guess I will just need to read down
> to line 400 and replace until line 600.  
> 
> Thanks again for all the insights regarding this. 
> 
> 
> 
> --- On Wed, 4/8/09, jim holtman 
> wrote:
> 
> > From: jim holtman 
> > Subject: Re: [R] R File I/O Capability - Writing
> output to specific lines of  existing file
> > To: jasonkrup...@yahoo.com
> > Cc: R-help@r-project.org
> > Date: Wednesday, April 8, 2009, 8:02 PM
> > You can always read in the initialization file, make the
> > updates to it and then write it back out.  If it is a text 
> > file, it would be very hard to write into the middle of 
> > it since there is no structure to the file.  You can read 
> > it in as a table (read.table) or just as lines
> > (readLines) and the make any changes you want.  You can use 
> > regular expressions if you want to put something in the 
> > middle of one of the lines you have read in.
> > 
> > On Wed, Apr 8, 2009 at 10:13 AM, Jason Rupert
> >  wrote:
> > >
> > Currently I am using the R "write"command
> > to output results to a *.txt file and then copying those
> > results into an initialization file.  In an attempt to
> > continue to automate the process I would like to have R
> > write to the location in the existing initialization file,
> > instead of me copying the data over.
> > By any chance are there any R commands to help?
> > Primarily, I will be using Windows, and the
> > initialization file is a simple flat file, i.e. not XML or
> > binary.
> >
> > I looked at:
> > (a)
> http://www.stat.ucl.ac.be/ISdidactique/Rhelp/library/R.io/html/00Index.html
> > (b) 
> > http://search.r-project.org/cgi-bin/namazu.cgi?query=File+I%2FO&max=100&result=normal&sort=score&idxname=functions&idxname=Rhelp08
> >
> > But, this did not appear to provide the functionality
> > to edit an existing file by adding information to the middle
> > of the file.
> >
> > Thank you again for any help and insight.
> >




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


Re: [R] failed when merging two dataframes, why

2009-04-09 Thread jim holtman
try this:

> merge(df1, df2, by.x='codetot',by.y='codetoto', all=TRUE)
   codetot popcode.x   p3need popcode.y   areasec
1  BCPy01-01-1 BCPy01-01 100. BCPy01-01 0.5089434
2  BCPy01-01-2 BCPy01-01 100. BCPy01-01 0.6246381
3  BCPy01-01-3 BCPy01-01 100. BCPy01-01 0.4370059
4  BCPy01-02-1 BCPy01-02  92.5926 BCPy01-02 0.9253052
5  BCPy01-02-1 BCPy01-02  92.5926 BCPy01-02 0.6011810
6  BCPy01-02-1 BCPy01-02 100. BCPy01-02 0.9253052
7  BCPy01-02-1 BCPy01-02 100. BCPy01-02 0.6011810
8  BCPy01-02-2 BCPy01-02  92.5926 BCPy01-02 0.6710850
9  BCPy01-02-2 BCPy01-02  92.5926 BCPy01-02 0.7145839
10 BCPy01-02-2 BCPy01-02 100. BCPy01-02 0.6710850
11 BCPy01-02-2 BCPy01-02 100. BCPy01-02 0.7145839
12 BCPy01-02-3 BCPy01-02  92.5926 BCPy01-02 0.9515256
13 BCPy01-02-3 BCPy01-02  92.5926 BCPy01-02 0.6555006
14 BCPy01-02-3 BCPy01-02 100. BCPy01-02 0.9515256
15 BCPy01-02-3 BCPy01-02 100. BCPy01-02 0.6555006
16 BCPy01-03-1 BCPy01-03 100. BCPy01-03 0.8683875
>


On Thu, Apr 9, 2009 at 7:19 AM, Mao Jianfeng  wrote:
> Hi, R-listers,
>
> Failed, when I tried to merge df1 and df2 by "codetot" in df1 and "codetoto"
> in df2. I want to know the reason and how to merge them together. Data
> frames and codes I have used were listed as followed. Thanks a lot in
> advance.
>
> df1:
> popcode     codetot   p3need
> BCPy01-01 BCPy01-01-1 100.
> BCPy01-01 BCPy01-01-2 100.
> BCPy01-01 BCPy01-01-3 100.
> BCPy01-02 BCPy01-02-1  92.5926
> BCPy01-02 BCPy01-02-1 100.
> BCPy01-02 BCPy01-02-2  92.5926
> BCPy01-02 BCPy01-02-2 100.
> BCPy01-02 BCPy01-02-3  92.5926
> BCPy01-02 BCPy01-02-3 100.
> BCPy01-03 BCPy01-03-1 100.
>
> df2:
> popcode    codetoto   areasec
> BCPy01-01 BCPy01-01-1 0.5089434
> BCPy01-01 BCPy01-01-2 0.6246381
> BCPy01-01 BCPy01-01-3 0.4370059
> BCPy01-02 BCPy01-02-1 0.9253052
> BCPy01-02 BCPy01-02-1 0.6011810
> BCPy01-02 BCPy01-02-2 0.6710850
> BCPy01-02 BCPy01-02-2 0.7145839
> BCPy01-02 BCPy01-02-3 0.9515256
> BCPy01-02 BCPy01-02-3 0.6555006
> BCPy01-03 BCPy01-03-1 0.8683875
>
> code:
> new1<-merge(df1,df2,by=c("popcode","popcode"),all=T) # It is processed well.
> But, it is not what I want.
> new2<-merge(df1,df2,by=c("codetot","codetoto"),all=T) # this one failed. I
> exactly want to do that.
>
> Mao J-F
> IBCAS, AC
>
>        [[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?

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


Re: [R] Does R support [:punct:] in regexps?

2009-04-09 Thread Duncan Murdoch

On 09/04/2009 7:10 AM, Daniel Brewer wrote:

Hello does R support [:punct:] in regular expressions?  I am trying to
strip all regular expressions for a vector of strings.


It does, but remember that the [] chars are part of the character class; 
you need extra [] brackets around the whole thing, and you don't want 
the slash delimiters:


> x <- c("yoda-yoda","billy!")
> gsub("[[:punct:]]","",x)
[1] "yodayoda" "billy"

Duncan Murdoch




x <- c("yoda-yoda","billy!")
gsub("/[:punct:]/","",x)

[1] "yoda-yoda" "billy!"

Thanks

Dan


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


Re: [R] change default output size when using Sweave

2009-04-09 Thread Franzini, Gabriele [Nervianoms]
Hi,
I had a similar problem, and I took the direction of squeezing the
output into a minipage, e.g.:

...
@
\begin{minipage}[c]{0.6\textwidth}
<>=
plot(...)
abline(...)
@
\end{minipage}
... 

HTH,
Gabriele Franzini 
ICT Applications Manager 
Nerviano Medical Sciences SRL 
Nerviano Italy 


-Original Message-
From: Mark Heckmann [mailto:mark.heckm...@gmx.de] 
Sent: 08 April 2009 10:31
To: 'Duncan Murdoch'
Cc: r-help@r-project.org
Subject: Re: [R] change default output size when using Sweave

Dear Duncan,

Thanks for the reply. This works, but unfortunately I need a different
solution.
My script is supposed to run completely automated and the graphics I
produce vary in size each time I run the script. But I want the graphics
to be fitted to my .pdf output without specifying the height argument
manually each time.
That is why I do not want a fixed height as a code chunk argument.
Actually I do not know if it is possible to have a variable placed in a
code chunk header. I tried the following which does not work:

<<>>=
size <- 3
@

<>=
   pushViewport(viewport(height = unit(80, "mm")))
   grid.rect()
   grid.text("I want this viewport to be the whole output size")
   popViewport()
@

So still I face the problem to have Sweave generate a .pdf graphic that
is just as big I want it to be.
 
In the Sweave Docu paragraph A.9 I discovered something I use as a
workaround. I produce the .pdf output manually (where I can control the
size) and add each graphic to LaTex manually as well.
 
<>=
for (i in 1){
file=paste("myfile", i, ".pdf", sep="")
pdf(file=file, paper="special", width=6, height=3)
   pushViewport(viewport(height = unit(5, "inches"))) 
   grid.rect()
   grid.text("I want this viewport to be the whole output size")
   popViewport()dev.off()
cat("\\includegraphics{", file, "}\n\n", sep="") } @

I use parenthesis around the code as it prints out something I do not
want if no parenthesis are used (I use Windows). 

I am not too happy with the solution. I would prefer a more
straightforward approach to define the size of the output graphic. I
wonder if there are some Sweave settings that can be modified. 

In the Sweave manual (A.11) I found the following to customize the par
settings for each figure:

options(SweaveHooks=list(fig=function() par(bg="red", fg="blue")))

I wonder if something similar could be done changing the size of the
default output device (pdf or eps) for each figure like
>pdf.options(height=2) or similar (it seems that this does not work)? 

I suppose this type of graphic customization is quite a common issue
when producing automated customized output/reports using R and Sweave
but I haven't found anything concerning this topic yet.

So I would be really glad if someone knows a solution.

TIA, Mark

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


[R] failed when merging two dataframes, why

2009-04-09 Thread Mao Jianfeng
Hi, R-listers,

Failed, when I tried to merge df1 and df2 by "codetot" in df1 and "codetoto"
in df2. I want to know the reason and how to merge them together. Data
frames and codes I have used were listed as followed. Thanks a lot in
advance.

df1:
popcode codetot   p3need
BCPy01-01 BCPy01-01-1 100.
BCPy01-01 BCPy01-01-2 100.
BCPy01-01 BCPy01-01-3 100.
BCPy01-02 BCPy01-02-1  92.5926
BCPy01-02 BCPy01-02-1 100.
BCPy01-02 BCPy01-02-2  92.5926
BCPy01-02 BCPy01-02-2 100.
BCPy01-02 BCPy01-02-3  92.5926
BCPy01-02 BCPy01-02-3 100.
BCPy01-03 BCPy01-03-1 100.

df2:
popcodecodetoto   areasec
BCPy01-01 BCPy01-01-1 0.5089434
BCPy01-01 BCPy01-01-2 0.6246381
BCPy01-01 BCPy01-01-3 0.4370059
BCPy01-02 BCPy01-02-1 0.9253052
BCPy01-02 BCPy01-02-1 0.6011810
BCPy01-02 BCPy01-02-2 0.6710850
BCPy01-02 BCPy01-02-2 0.7145839
BCPy01-02 BCPy01-02-3 0.9515256
BCPy01-02 BCPy01-02-3 0.6555006
BCPy01-03 BCPy01-03-1 0.8683875

code:
new1<-merge(df1,df2,by=c("popcode","popcode"),all=T) # It is processed well.
But, it is not what I want.
new2<-merge(df1,df2,by=c("codetot","codetoto"),all=T) # this one failed. I
exactly want to do that.

Mao J-F
IBCAS, AC

[[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] Multiple Hexbinplots in 2 columns with a Single Categorical Variable

2009-04-09 Thread Stuart Reece
Dear Ladies and Gentlemen,

 I have a fairly large database (N=13,000) and a single main categorical 
discriminator between the groups.

 I want to look at the time course of a number of continuous biochemical 
variables over chronologic age.

 Therefore I believe I need to prepare hexbinplots in two columns with simple 
regression lines in them (with useOuterStrips (in library(latticeExtra) if 
possible) and also single hexbinplots with two regression lines (panel.lmlines) 
corresponding to the two groups to facilitate data comparison.

 Tick marks and labels should be off in most panels, and the scale in each row 
will be different.

 I have some code written for the NHANES dataset in library(hexbin) which 
almost does this job, but leaves blank paper up the middle of the two columns 
of panels.

 I have been exploring lattice for this which almost gets me there but not 
quite.

 The code I have written is as follows.

 I would be ever so grateful for any advice anyone may be able to offer.

 With best wishes,

 Stuart Reece,

Australia.

 

 

useOuterStrips(hexbinplot(Transferin ~ Age | factor(Race) + factor(Sex), data = 
NHANES, type = "r",

   aspect = 1, 

   scales = 

   list(x =

 list(relation = "free", rot = 0,

 at=list(TRUE, TRUE, NULL, NULL)),

y = 

 list(relation = "free", rot = 0,

 at=list(TRUE, NULL, TRUE, NULL))),

   par.settings =   list(layout.heights = list(axis.panel = rep(c(1, 
0),c(1, 1,   par.strip.text = list(cex = 1)))

[[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] Does R support [:punct:] in regexps?

2009-04-09 Thread Daniel Brewer
Hello does R support [:punct:] in regular expressions?  I am trying to
strip all regular expressions for a vector of strings.

> x <- c("yoda-yoda","billy!")
> gsub("/[:punct:]/","",x)
[1] "yoda-yoda" "billy!"

Thanks

Dan
-- 
**
Daniel Brewer, Ph.D.

Institute of Cancer Research
Molecular Carcinogenesis
Email: daniel.bre...@icr.ac.uk
**

The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company 
Limited by Guarantee, Registered in England under Company No. 534147 with its 
Registered Office at 123 Old Brompton Road, London SW7 3RP.

This e-mail message is confidential and for use by the a...{{dropped:2}}

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


[R] arima on defined lags

2009-04-09 Thread Gerard M. Keogh


Dear all,

The standard call to ARIMA in the base package such as

  arima(y,c(5,0,0),include.mean=FALSE)

  gives a full 5th order lag polynomial model with for example coeffs

  Coefficients:
   ar1ar2  ar3 ar4  ar5
0.4715  0.067  -0.1772  0.0256  -0.2550
  s.e.  0.1421  0.158   0.1569  0.1602   0.1469


Is it possible (I doubt it but am just checking) to define a more
parsimonous lag1 and lag 5 model with coeff ar1 and ar5?
Or do I need one of the other TS packages?

thanks

Gerard


**
The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential and/or privileged material. Any 
review, retransmission, dissemination or other use of, or taking of any action 
in reliance upon, this information by persons or entities other than the 
intended recipient is prohibited. If you received this in error, please contact 
the sender and delete the material from any computer.  It is the policy of the 
Department of Justice, Equality and Law Reform and the Agencies and Offices 
using its IT services to disallow the sending of offensive material.
Should you consider that the material contained in this message is offensive 
you should contact the sender immediately and also mailminder[at]justice.ie.

Is le haghaidh an duine nó an eintitis ar a bhfuil sí dírithe, agus le haghaidh 
an duine nó an eintitis sin amháin, a bheartaítear an fhaisnéis a tarchuireadh 
agus féadfaidh sé go bhfuil ábhar faoi rún agus/nó faoi phribhléid inti. 
Toirmisctear aon athbhreithniú, atarchur nó leathadh a dhéanamh ar an 
bhfaisnéis seo, aon úsáid eile a bhaint aisti nó aon ghníomh a dhéanamh ar a 
hiontaoibh, ag daoine nó ag eintitis seachas an faighteoir beartaithe. Má fuair 
tú é seo trí dhearmad, téigh i dteagmháil leis an seoltóir, le do thoil, agus 
scrios an t-ábhar as aon ríomhaire. Is é beartas na Roinne Dlí agus Cirt, 
Comhionannais agus Athchóirithe Dlí, agus na nOifígí agus na nGníomhaireachtaí 
a úsáideann seirbhísí TF na Roinne, seoladh ábhair cholúil a dhícheadú.
Más rud é go measann tú gur ábhar colúil atá san ábhar atá sa teachtaireacht 
seo is ceart duit dul i dteagmháil leis an seoltóir láithreach agus le 
mailminder[ag]justice.ie chomh maith. 
***



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

2009-04-09 Thread Jonas Weickert

Hi,

I want to do a biexponential Fit, i.e.

y ~ A1*exp(k1*x) + A2*exp(k2*x)

Is this possible? I tried nls() but it stopped with several (different) 
errors. I'm using y and x as simple vectors and the formula for nls() 
exactly as mentioned above.


Thanks a lot!

Jonas

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


Re: [R] combine words and dataframe

2009-04-09 Thread Dieter Menne
Ravi S. Shankar  ambaresearch.com> writes:

> I am trying to get an output like this
> Hi
> Hello
> 1   a   b

# The easy way: good for logging of results, but commands print too,
# depending how you run it
df = data.frame(a=rep("a",3),b=rep("b",3))
sink(file="a.txt")
cat("Hello\n")
print(df)
sink()

# a bit better
cat("Hello\n",file="b.txt")
write.table(df,file="b.txt",append=TRUE,col.names=FALSE,
  row.names=FALSE,quote=FALSE)


Dieter

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


[R] problem with creating a netcdf file under script sh

2009-04-09 Thread Tu Anh Tran


Hi everyone, 
I try to make a netcdf file which disposes a difference between 2 variables of 
2netcdf files same dimension 
When I programmed under R, everything is ok but when I put the code under EOF 
of a sh script, an error occurs: 
"Error, passed variable has a dim that is NOT of class dim.ncdf!". My programme 
is: 

x1<-open.ncdf("file1.nc") 
x2<-open.ncdf("file2.nc") 
y1<-get.var.ncdf(x1,"a") 
y2<-get.var.ncdf(x2,"a") 
y<- y1-y2 
t<-var.def.ncdf("t",units="c",dim=x1$dim,-1) 
nc<-create.ncdf("test.nc",vars=t) 
put.var.ncdf(nc,t,y) 
close.ncdf(nc) 

Thanks in advance, 
T.A 




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


Re: [R] Genstat into R - Randomisation test

2009-04-09 Thread Tom Backer Johnsen

Peter Dalgaard wrote:
> Mike Lawrence wrote:
>> Looks like that code implements a non-exhaustive variant of the
>> randomization test, sometimes called a permutation test.
>
> Isn't it the other way around? (Permutation tests can be exhaustive 
by looking at all permutations, if a randomization test did that, then 
it wouldn't be random.)


Eugene Edgington wrote an early book (1980) on this subject called 
"Randomization tests", published by Dekker.  As far as I remember, he 
differentiates between "Systematic permutation" tests where one looks at 
all possible permutations.  This is of course prohibitive for anything 
beyond trivially small samples.  For larger samples he uses what he 
calls "Random permutations", where a random sample of the possible 
permutations is used.


Tom

Peter Dalgaard wrote:

Mike Lawrence wrote:

Looks like that code implements a non-exhaustive variant of the
randomization test, sometimes called a permutation test. 


Isn't it the other way around? (Permutation tests can be exhaustive by 
looking at all permutations, if a randomization test did that, then it 
wouldn't be random.)






--
++
| Tom Backer Johnsen, Psychometrics Unit,  Faculty of Psychology |
| University of Bergen, Christies gt. 12, N-5015 Bergen,  NORWAY |
| Tel : +47-5558-9185Fax : +47-5558-9879 |
| Email : bac...@psych.uib.noURL : http://www.galton.uib.no/ |
++

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

2009-04-09 Thread Chirantan Kundu
Hi,
I'm trying to invoke the function bond_prices from termstrc package.

Here is the code snippet:

library(termstrc)
data(eurobonds)
b <- matrix(rep(c(0,0,0, 1),1),nrow=1,byrow=TRUE)
group<-c("GERMANY")
colnames(b) <- c("beta0","beta1","beta2","tau1")
germaturities<-create_maturities_matrix(eurobonds$GERMANY)
bp<-bond_prices(method =
"Nelson/Siegel",b,germaturities,eurobonds$GERMANY$CASHFLOWS$CF)
bp

Running this, I get the following warning message:
In cf * discount_factors :
  longer object length is not a multiple of shorter object length

Also the values I get (bp) seems not correct (way too high). I'm not sure if
I need to change b.

I'm on Windows XP and using R-2.7.2 + *termstrc* 1.1.

Any help will be appreciated.
Regards,


Visit us at http://www.2pirad.com

[[alternative HTML version deleted]]

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


Re: [R] Constrined dependent optimization.

2009-04-09 Thread Hans W. Borchers

Kevin,

sorry I don't understand this sentence:
"It has been suggested that I do a cluster analysis. Wouldn't this bet
mepart way there?"

Let your products be numbered  1, ..., n,  and let p(i) be the location
where product i is stored (assigned to) in the warehouse. Then p is a
permutation of the set  1, ..., n  and the task is an "assignment" problem.

A sale v is simply a subset of  1, ..., n and the contribution to the target
function could, for example, be

f_v(p) = max( p(v) ) - min( p(v) )  for each sale v,

or whatever your evaluation criterion is. The total function to minimize
will then be  Sum( f_v)  for all historical sales v.

Because it is based on a distance, the whole task is called a "quadratic"
assignment problem (and is certainly not linear). 

In the literature you will find algorithms and tools mentioned to solve such
a task, and n = 20,000 is not that much nowadays. But the difference between 
n = 100  and  n = 20,000  is huge for tools not specialized to the task.

For the TSP, imagine two groups of cities very far apart. Then under some
mild restrictions it would not be reasonable to go back and forth between
these groups several times, and therefore the problem could be split into
two independent subproblems.

So the question of clustering belongs to the data preparation part.

Whether such really different classes of sales exist in your data, only you
can decide. In my experience, most of the time such preprocessing is not
worth doing and will not speed up the optimization procedure considerably.

Regards,  Hans Werner



rkevinburton wrote:
> 
> 
> It has been suggested that I do a cluster analysis. Wouldn't this bet
> mepart way there?
> 
> Thank you for your response I am looking up the book now.
> 
> Kevin
> 
>  "Hans W. Borchers"  wrote:
>>
>> Just in case you are still interested in theoretical aspects:
>>
>> In combinatorial optimization, the problem you describe is known as the
>> Quadratic (Sum) Assignment Problem (QAP or QSAP) and is well known to
>> arise in facility and warehouse layouts. The task itself is considered
>> hard, comparable to the Traveling Salesman Problem (TSP).
>>
>> I would clearly advise to turn to some specialized commercial software
>> for solving it, otherwise you will very likely get stuck in suboptimal
>> solutions miles away from the true optimum. And for a real commercial
>> situation this may be disastrous.
>>
>> Regards,  Hans Werner
>>
>> P.S.:   See for instance Cela: The Quadratic Assignment Problem. Theory
>> and Algorithms, Springer, 2000.  (Partly available at books.google.com)
>>
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Constrined-dependent-optimization.-tp22772520p22966416.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] .Call()

2009-04-09 Thread wudd wudd
Hi guys,
I want to transfer the following code from R into .Call compatible form. How
can i do that?

Thanks!!!

INT sim;
 for(i in 1:sim){
 if(i>2) genemat <- genemat[,sample(1:ncol(genemat))]
 ranklist[,1] <- apply(genemat, 1, function(x){
 (mean(x[cols]) -
mean(x[-cols]))/sd(x)})
 ranklist <- ranklist[order(ranklist[,1]),]
 if(ranklist[1,2]==1) score[i] <- 1/Ns
 if(ranklist[1,2]==0) score[i] <- -(1/(N-Ns))
  for(j in 2:nrow(ranklist)){
 phit <- sum(rep(1/Ns, sum(ranklist[1:j,2]==1)))
 pmiss <- sum(rep(1/(N-Ns), sum(ranklist[1:j,2]==0)))
 if((phit-pmiss)>score[i]) score[i] <- phit - pmiss
 }
 }

I tried a little bit, but not enough knowledge in C.
#include 
#include 
#include 
#include 
SEXP ESscore(SEXP Rgeneset, SEXP Rgenemat, SEXP Rranklist, SEXP sim)
{
 int nc = ncols(Rgenemat);
 double *geneset = NUMERIC_DATA(Rgeneset);
 double *genemat = NUMERIC_DATA(Rgenemat);

 SEXP Rscore;
 PROTECT(Rscore=NEW_NUMERIC(sim));
 double *score = NUMERIC_DATA(Rscore);

 for(i=1; i<=sim; i++){
 if(i>2) {genemat <- genemat[,sample(1:nc)];}
 for(k=1; khttps://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


  1   2   >