[R] Odp: Newb question re. read.table...

2010-03-03 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 03.03.2010 22:50:59:

> I'm trying to get started with R, on Ubuntu. I worked through the
> tutorial, and have made a small tab-delimited subset of my data to try
> out (10 cases with about a dozens variables). But I can't seem to figure
> out how to actually refer to variables. I presume I'm missing something
> very simple, but quite a while searching the doc and the FAQ haven't
> helped me.
> 
> I'm loading the data with
> con <- read.table("tiny.txt", header=TRUE)
> 
> The first record is a set of variable names, tab-separated like the rest
> of the rows. There are no row labels, thus the same number of
> tab-delimited fields in the header record and the following records. The
> read.table returns silently, and I can get a reasonable summary(con).
> But if I try something like plot(rel,len), where rel and len are two of
> the labels from the header row, I get
> 
>  Error in plot(rel, len) : object 'rel' not found
> 
> I've tried many variations (different variables, adding "con." on the
> front, quoting, using field numbers instead of names, etc. I've also
> read what I can find on read.table, but I'm clearly missing some basic
> thing
> 
> Can somebody put me back on the right track? Is there some additional
> thing I have to do to make this into a "real" frame, or to bind
> variables names to header names, or something like that?

You have got several answers, I would recommend also to read chapter 6.3 
of R intro for manipulating data frame.

Regards
Petr


> 
> Thanks, and sorry for being dense
> 
> Steve
> 
> 
> 
> 
>[[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] Sub-setting a data frame by partial column names?

2010-03-03 Thread Sarah Henderson
Hi Jim, and thanks for your solution.  I figured one out for myself
about a minute after I posted this, and here it is if anyone else can
find it valuable:

subsetData<- bigData[,grep(partialName, colnames(bigData))]

This is smaller than your solution, but similar I think.

Cheers,

Sarah


On Thu, Mar 4, 2010 at 6:34 PM, Jim Lemon  wrote:
> On 03/04/2010 05:51 PM, Sarah Henderson wrote:
>>
>> Hi all --
>>
>> I think my Python brain is missing something crucial about string
>> operations in R, but I cannot figure this out.
>>
>> I have a large data frame with several groups of similar variables.
>> Similar variables are named according to their group, and I am now
>> writing a function to check correlations within groups.  I want to
>> subset the data frame by partial variable name, something along the
>> lines of this:
>>
>> partialName<- "XXX"
>> subsetData<- bigData[, partialName in colnames(bigData)]
>>
>> Where bigData might have 10 columns named "XXX1", "XXX2" etc.
>>
>
> Hi Sarah,
>
> Try this:
>
> column.names<-paste(sample(c("X","Y","Z"),100,TRUE),
>  sample(c("X","Y","Z"),100,TRUE),
>  sample(c("X","Y","Z"),100,TRUE),
>  sample(0:9,100,TRUE),sep="")
> column.names[grep("XXX",column.names,fixed=TRUE)]
>
> Jim
>

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


Re: [R] Sub-setting a data frame by partial column names?

2010-03-03 Thread Dieter Menne


Sarah Henderson wrote:
> 
> 
> I think my Python brain is missing something crucial about string
> operations in R, but I cannot figure this out.
> 
> I have a large data frame with several groups of similar variables.
> Similar variables are named according to their group, and I am now
> writing a function to check correlations within groups.  I want to
> subset the data frame by partial variable name, something along the
> lines of this:
> 

With thanks to Peter Dalgaard, who sent me this 10 years ago at my first
posting. You can do it in one line though, and use <- to be a real fReak.

d = data.frame(xxx1=1:10,xx2=1:10,yy2=1:10,axx=1:10)
selcols = grep("^xx", names(d))
d[,selcols]

Dieter

-- 
View this message in context: 
http://n4.nabble.com/Sub-setting-a-data-frame-by-partial-column-names-tp1577672p1577699.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] Sub-setting a data frame by partial column names?

2010-03-03 Thread Jim Lemon

On 03/04/2010 05:51 PM, Sarah Henderson wrote:

Hi all --

I think my Python brain is missing something crucial about string
operations in R, but I cannot figure this out.

I have a large data frame with several groups of similar variables.
Similar variables are named according to their group, and I am now
writing a function to check correlations within groups.  I want to
subset the data frame by partial variable name, something along the
lines of this:

partialName<- "XXX"
subsetData<- bigData[, partialName in colnames(bigData)]

Where bigData might have 10 columns named "XXX1", "XXX2" etc.



Hi Sarah,

Try this:

column.names<-paste(sample(c("X","Y","Z"),100,TRUE),
 sample(c("X","Y","Z"),100,TRUE),
 sample(c("X","Y","Z"),100,TRUE),
 sample(0:9,100,TRUE),sep="")
column.names[grep("XXX",column.names,fixed=TRUE)]

Jim

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


[R] Sub-setting a data frame by partial column names?

2010-03-03 Thread Sarah Henderson
Hi all --

I think my Python brain is missing something crucial about string
operations in R, but I cannot figure this out.

I have a large data frame with several groups of similar variables.
Similar variables are named according to their group, and I am now
writing a function to check correlations within groups.  I want to
subset the data frame by partial variable name, something along the
lines of this:

partialName <- "XXX"
subsetData <- bigData[, partialName in colnames(bigData)]

Where bigData might have 10 columns named "XXX1", "XXX2" etc.

Many thanks for any thoughts,

Sarah

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

2010-03-03 Thread Noah Silverman
Hi,

Looking for a function in R that can help me calculate a parameter that
maximizes the likelihood over groups of observations.

The general formula is:

p = exp(xb) / sum(exp(xb))

So, according to the formulas I've seen published, to do this "by group" is

product(p = exp(x_i * b_i) / sum(exp(x_i b_i)))

Where i represents a "group" and we iterate through each group.

Does anybody have any suggestions?

Thanks!


-N

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


Re: [R] two questions for R beginners

2010-03-03 Thread kMan
John,

I felt a short, somewhat strong reply was in order. One of the inherent
aspects of the language is that R demands more of an understanding from
users about what is taking place. Model formulae, for example, are close to
what one would use if they were to write the model on paper. I consider this
a strong feature. The confusing aspects that you point out are not the
result of syntax. Syntax in R is well specified and, I believe, far easier
to work with than many programming languages.

English is a confusing language. C++ is a confusing language. One may have
far more success learning, say, French if he/she does not like the syntax or
grammar of English, or visual Pascal if the syntax of C++ is not preferred,
rather than changing the language. If one wants to do business in a
particular area, then it generally behooves one to suck it up and learn the
native tongue or hire someone for that part. If one wants the program that
is the standard for other world class statistics packages, which also
happens to have a very amendable license agreement, then it behooves one to
suck it up and learn R. 

R is what it is. If someone does not like it, he/she can use something else,
pay far more for an inferior product which will also take longer to do a
calculation and handle less data at once, while risking that the content of
their understanding of statistics is diminished for it. Not that there is
not room for development in R, but the sort of development you demand will
evolve according to similar laws as those that govern economics and/or
change in spoken language.

You'd need major financial backing, and a strong influence over the culture
of those who use R to pull this off. Other than that, you'll have to wait
for the dialect to change over time from the cumulative effect of
contributions from people the world over who all want something different
out of the language.

If someone wants to take on the R challenge for him/herself, however, then
there is likely no better technical support in the world than the R
community, albeit perhaps after dispensing with some of the niceties.

Sincerely,
KeithC.

-Original Message-
From: John Sorkin [mailto:jsor...@grecc.umaryland.edu] 
Sent: Tuesday, March 02, 2010 4:46 AM
To: Karl Ove Hufthammer; r-h...@stat.math.ethz.ch
Subject: Re: [R] two questions for R beginners

Please take what follows not as an ad hominem statement, but rather as an
attempt to improve what is already an excellent program, that has been built
as a result of many, many hours of dedicated work by many, many unpaid,
unsung volunteers.

It troubles me a bit that when a confusing aspect of R is pointed out the
response is not to try to improve the language so as to avoid the confusion,
but rather to state that the confusion is inherent in the language. I
understand that to make changes that would avoid the confusing aspect of the
language that has been discussed in this thread would take time and effort
by an R wizard (which I am not), time and effort that would not be
compensated in the traditional sense. This does not mean that we should not
acknowledge the confusion. If we what R to be the de facto lingua franca of
statistical analysis doesn't it make sense to strive for syntax that is as
straight forward and consistent as possible? 

Again, please understand that my comment is made with deepest respect for
the many people who have unselfishly contributed to the R project. Many
thanks to each and every one of you.

John


>>> Karl Ove Hufthammer  3/2/2010 4:00 AM >>>
On Mon, 01 Mar 2010 10:00:07 -0500 Duncan Murdoch 
wrote:
> Suppose X is a dataframe or a matrix.  What would you expect to get 
> from X[1]?  What about as.vector(X), or as.numeric(X)?

All this of course depends on type of object one is speaking of. There are
plenty of surprises available, and it's best to use the most logical way of
extracting. E.g., to extract the top-left element of a 2D structure (data
frame or matrix), use 'X[1,1]'.

Luckily, R provides some shortcuts. For example, you can write 'X[2,3]' 
on a data frame, just as if it was a matrix, even though the underlying
structure is completely different. (This doesn't work on a normal list;
there you have to type the whole 'X[[2]][3]'.)

The behaviour of the 'as.' functions may sometimes be surprising, at least
for me. For example, 'as.data.frame' on a named vector gives a single-column
data frame, instead of a single-row data frame.

(I'm not sure what's the recommended way of converting a named vector to row
data frame, but 'as.data.frame(t(X))' works, even though both 'X' 
and 't(X)' looks like a row of numbers.)

> The point is that a dataframe is a list, and a matrix isn't.  If users 
> don't understand that, then they'll be confused somewhere.  Making 
> matrices more list-like in one respect will just move the confusion 
> elsewhere.  The solution is to understand the difference.

My main problem is not understanding the difference, which is easy, but
knowi

Re: [R] Setting graphical parameters

2010-03-03 Thread Rolf Turner

Do your own  homework!

It looks pretty trivial; what's your problem?

cheers,

Rolf Turner

On 4/03/2010, at 2:39 PM, Pitmaster wrote:

> 
> Hi guys... I have problem with this excersise... 
> 
> Consider the pressure data frame again.
> 
> (a) Plot pressure against temperature, and use the following
> command to pass a curve through these data:
> 
>> curve((0.168 + 0.007*x)ˆ(20/3), from=0, to=400, add=TRUE)
> 
> (b) Now, apply the power transformation y3/20 to the pressure data values.
> Plot these transformed values against temperature. Is a linear
> or nonlinear relationship evident now? Use the abline() function
> to pass a straight line through the points. (You need an intercept
> and slope for this – see the previous part of this question to obtain
> appropriate values.)
> 
> (c) Add a suitable title to the graph.
> 
> (d) Re-do the above plots, but use the mfrow() function to display
> them in a 2 × 1 layout on the graphics page. Repeat once again
> using a 1 × 2 layout.
> 
> DATA:
>> pressure
>   temperature pressure
> 10   0.0002
> 2   20   0.0012
> 3   40   0.0060
> 4   60   0.0300
> 5   80   0.0900
> 6  100   0.2700
> 7  120   0.7500
> 8  140   1.8500
> 9  160   4.2000
> 10 180   8.8000
> 11 200  17.3000
> 12 220  32.1000
> 13 240  57.
> 14 260  96.
> 15 280 157.
> 16 300 247.
> 17 320 376.
> 18 340 558.
> 19 360 806.
> 
> 
> Can anyone know the solution ?

##
Attention: 
This e-mail message is privileged and confidential. If you are not the 
intended recipient please delete the message and notify the sender. 
Any views or opinions presented are solely those of the author.

This e-mail has been scanned and cleared by MailMarshal 
www.marshalsoftware.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] Setting graphical parameters

2010-03-03 Thread Pitmaster

Hi guys... I have problem with this excersise... 

Consider the pressure data frame again.

(a) Plot pressure against temperature, and use the following
command to pass a curve through these data:

> curve((0.168 + 0.007*x)ˆ(20/3), from=0, to=400, add=TRUE)

(b) Now, apply the power transformation y3/20 to the pressure data values.
Plot these transformed values against temperature. Is a linear
or nonlinear relationship evident now? Use the abline() function
to pass a straight line through the points. (You need an intercept
and slope for this – see the previous part of this question to obtain
appropriate values.)

(c) Add a suitable title to the graph.

(d) Re-do the above plots, but use the mfrow() function to display
them in a 2 × 1 layout on the graphics page. Repeat once again
using a 1 × 2 layout.

DATA:
> pressure
   temperature pressure
10   0.0002
2   20   0.0012
3   40   0.0060
4   60   0.0300
5   80   0.0900
6  100   0.2700
7  120   0.7500
8  140   1.8500
9  160   4.2000
10 180   8.8000
11 200  17.3000
12 220  32.1000
13 240  57.
14 260  96.
15 280 157.
16 300 247.
17 320 376.
18 340 558.
19 360 806.


Can anyone know the solution ?
-- 
View this message in context: 
http://n4.nabble.com/Setting-graphical-parameters-tp1577529p1577529.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] Heatmap reordering of dendrogram to hierarchical clustering

2010-03-03 Thread Fearon Cassidy
Dear list members,

I have been using R to create a heatmap where my data has continous
variables from 0 to 100.
When I create the heatmap, although the branches are correct, they do not
order themselves so that the row with the most zeros is at one end and the
row with the most 100s is at the other, which is what I would like them to
do, so as to create a colour gradient down the graphic.
I have tried to use reorderfun to fix this, and although it makes some
change, the heatmap still does not look how I want.

Can you help? I have been using:

tmp <-read.table("Heat.txt",row.names=1,header=T)

mydata <- data.matrix(tmp)

rc <- rainbow(nrow(mydata),start=0, end=1)
cc <- rainbow(ncol(mydata), start=0, end=1)

hv <- heatmap(mydata, col = cm.colors(256), scale="column",
  RowSideColors = rc, ColSideColors = cc, margin=c(5,10),
xlab = "Gene", ylab= "Species",
main = "Heatmap", reorderfun = function(mydata,w)
reorder(mydata,0.0:100.0), Colv=NULL, Rowv=T)

Thnak you,

Fearon Cassidy
Department of Zoology
Trinity College Dublin

[[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] Conditional Logistic Regression in R

2010-03-03 Thread Dimitrij Kudriavcev
Hello.

I want to use conditional logistic regression to calculate the probability
of winning one of three players in golf. I was able to calculate these
probabilities in Stata10, and I now want to transfer the code in the R
Project, because it is can get data directly form MySQL. Unfortunately, I'm
novice in R and I can't calculate the probability using the predict function
when trying to get out of sample forecasts.

The code I use to built the regression is and generate predictions is:

predict (clogit (place ~ rating1+ rating2+rating3+strata(event_id), data =
a), b, type = "expected")

Here "a" - my original data, "b" - the new data, for which I want to
calculate probabilities. The sample is grouped by number of the event
(event_id).

What am I doing wrong? When I try to calculate the probability of the data
outside the sample, I get an error "Method not yet finished." Reading the
history of this mailing list, I found mention of this error back in 2008. Does
this mean that clogit function is no longer being developed and there is
another, more suitable function? I tried to replace clogit witch cph, but in
this case, the error was:

Error in names (Strata) <- paste ( "S", 1: nstrata, sep = ""):
  'names' attribute [2] must be the same length as the vector [0]

Can I use R Project to calculate the conditional probabilities, or am I
doomed to use Stata?

WBR
Dmitrij

[[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] extracting values conditonal on other values

2010-03-03 Thread Phil Spector

Toby -
   Thanks for the reproducible example!
   I think this will do what you want:

both = merge(test1,test2)
subset(both,time >= rise & time <= set)

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


On Wed, 3 Mar 2010, Toby Gass wrote:


Dear R helpers,

I have a dataframe (test1) containing the time of sunrise and sunset for each 
day of the year
for 3 years.  I have another dataframe (test2) containing measurements that are 
taken every
15 minutes, 24/7. I would like to extract all rows from test2 that occur 
between sunrise and
sunset for the appropriate date.  Can you suggest a good vectorized way to do 
this?  Keep in
mind that the sunrise/sunset dataframe has 1 row for each day, and the 
measurement
dataset has 96 rows for each day.  I'm hoping not to have to match strings...

The times (test1$rise, test1$set, and test2$time) in the example are rather 
ugly since I wasn't
sure how to generate a random hourly time series.  I would also use a standard 
date format
for the real thing but, again, wasn't sure how to generate dates for this 
example.

Example data:

test1 <- data.frame(year = gl(3, 30, 90, labels = c("2006", "2007", "2008")),
month =  gl(3, 10, 30, labels = c("1", "2", "3")),
day = rep(c(21:30, 19:28, 22:31),3),
rise = as.integer(runif(90, 700, 750)),
set = as.integer(runif(90, 1630,1745)))


test2 <- data.frame(year = gl(3, 2880, 8640, labels = c("2006", "2007", 
"2008")),
month = gl(3, 96, 288, labels = c("1", "2", "3")),
day = rep(c(21:30, 19:28, 22:31),3, each = 96),
time = 100*rep(seq(, 23.75,by= .25),90),
temp = runif(8640, -5, 15))

Thank you in advance,

Toby

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

2010-03-03 Thread Toby Gass
Dear R helpers,

I have a dataframe (test1) containing the time of sunrise and sunset for each 
day of the year 
for 3 years.  I have another dataframe (test2) containing measurements that are 
taken every 
15 minutes, 24/7. I would like to extract all rows from test2 that occur 
between sunrise and 
sunset for the appropriate date.  Can you suggest a good vectorized way to do 
this?  Keep in 
mind that the sunrise/sunset dataframe has 1 row for each day, and the 
measurement 
dataset has 96 rows for each day.  I'm hoping not to have to match strings...

The times (test1$rise, test1$set, and test2$time) in the example are rather 
ugly since I wasn't 
sure how to generate a random hourly time series.  I would also use a standard 
date format 
for the real thing but, again, wasn't sure how to generate dates for this 
example.

Example data:

test1 <- data.frame(year = gl(3, 30, 90, labels = c("2006", "2007", "2008")),
month =  gl(3, 10, 30, labels = c("1", "2", "3")),
day = rep(c(21:30, 19:28, 22:31),3),
rise = as.integer(runif(90, 700, 750)),
set = as.integer(runif(90, 1630,1745)))


test2 <- data.frame(year = gl(3, 2880, 8640, labels = c("2006", "2007", 
"2008")),
month = gl(3, 96, 288, labels = c("1", "2", "3")),
day = rep(c(21:30, 19:28, 22:31),3, each = 96),
time = 100*rep(seq(, 23.75,by= .25),90),
temp = runif(8640, -5, 15))

Thank you in advance,

Toby

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


Re: [R] cluster with mahalanobis distance

2010-03-03 Thread Phil Spector

Albyn -
   That's a very important fact that I overlooked in my 
original response.  Thanks for pointing it out.

 - Phil


On Wed, 3 Mar 2010, Albyn Jones wrote:


Note: this procedure assumes that all clusters have the same covariance matrix.

albyn

On Wed, Mar 03, 2010 at 01:23:37PM -0800, Phil Spector wrote:

The manhattan distance and the Mahalanobis distances are quite different.
One of the main differences is that a covariance matrix is necessary to
calculate the Mahalanobis
distance, so it's not easily accomodated by dist.  There is a function in
base R which does calculate the Mahalanobis
distance -- mahalanobis().  So if you pass a distance matrix
calculated by mahalanobis() to the clustering function, you'll
get what you want.
- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Wed, 3 Mar 2010, Tal Galili wrote:


when you create the distance function to put into the hclust, use:

dist(x, method = "manhattan")


Tal



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Wed, Mar 3, 2010 at 9:14 PM, naama  wrote:



How can I perform cluster analysis using the mahalanobis distance instead
of
the euclidean distance?
thank you
Naama Wolf

--
View this message in context:
http://n4.nabble.com/cluster-with-mahalanobis-distance-tp1577038p1577038.html
Sent from the R help mailing list archive at Nabble.com.

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



[[alternative HTML version deleted]]

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



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





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


[R] Using discrete choice data to estimate marginal willingness to pay (MWTP)

2010-03-03 Thread Paul Miller
Hello Everyone,
 
Can anyone show me how to use discrete choice data to estimate marginal 
willingness to pay? I've searched for simple information or code on how to do 
this but haven't found much.
 
The closest I've come is a paper titled "Introduction to Choice Experiments 
using R." The paper seems to have what I want but is not readily available and 
is written in Japanese.
 
Thanks,
 
Paul
 


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


[[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] counting the number of ones in a vector

2010-03-03 Thread Bert Gunter
x <- rep(c("A","B"),c(4,3))
table(x)['A']

Capiche?

Bert Gunter
Genentech Nonclinical Biostatistics
 
 
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Randall Wrong
Sent: Wednesday, March 03, 2010 3:03 PM
To: Nutter, Benjamin; Henrique Dallazuanna; Tobias Verbeke; David Reinke;
Gavin Simpson
Cc: r-help@r-project.org
Subject: Re: [R] counting the number of ones in a vector

Thanks to all of you !
(Benjamin Nutter, Henrique Dallazuanna, Tobias Verbeke, Jorge Ivan Velez,
David Reinke and Gavin Simpson)


x <- c(1, 1, 1, NA, NA, 2, 1, NA)

> table(x)["1"]
1
4

Why do I get two numbers ?

Thanks,
Randall



2010/2/26 Nutter, Benjamin 

> But if x has any missing values:
>
> > x <- c(1, 1, 1, NA, NA, 2, 1, NA)
> >
> > sum( x == 1)
> [1] NA
> >
> > sum(x==1, na.rm=TRUE)
> [1] 4
>
>
>
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Henrique Dallazuanna
> Sent: Friday, February 26, 2010 9:47 AM
> To: Randall Wrong
> Cc: r-help@r-project.org
> Subject: Re: [R] counting the number of ones in a vector
>
> Try:
>
> sum(x == 1)
>
> On Fri, Feb 26, 2010 at 11:40 AM, Randall Wrong 
> wrote:
> > Dear R users,
> >
> > I want to count the number of ones in a vector x.
> >
> > That's what I did : length( x[x==1] )
> >
> > Is that a good solution ?
> > Thank you very much,
> > Randall
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> >
http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Parana-Brasil
> 250 25' 40" S 490 16' 22" O
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
>
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
> ===
>
> P Please consider the environment before printing this e-mail
>
> Cleveland Clinic is ranked one of the top hospitals
> in America by U.S.News & World Report (2009).
> Visit us online at http://www.clevelandclinic.org for
> a complete listing of our services, staff and
> locations.
>
>
> Confidentiality Note:  This message is intended for use
>  only by the individual or entity to which it is addressed
> and may contain information that is privileged,
> confidential, and exempt from disclosure under applicable
> law.  If the reader of this message is not the intended
> recipient or the employee or agent responsible for
> delivering the message to the intended recipient, you are
> hereby notified that any dissemination, distribution or
> copying of this communication is strictly prohibited.  If
> you have received this communication in error,  please
> contact the sender immediately and destroy the material in
> its entirety, whether electronic or hard copy.  Thank you.
>
>

[[alternative HTML version deleted]]

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


Re: [R] Output from test script during R CMD check

2010-03-03 Thread Duncan Murdoch

On 03/03/2010 5:25 PM, DarioAustralia wrote:

Ah yes sorry about that it was a vague posting.

What I'd like to see when I do a R CMD check on the package and it gets to
the part where it runs the test script, I'd like to show to the user on the
screen the progress of the testing. What happens now is none of the
cat("Test X was successful. \n") statements that I have within the .R file
go to the screen. I did a search of the filesystem for a .Rout file that
maybe it was sending this output to, with the same filename as my test
script, but there isn't any. So I don't think R CMD BATCH is redirecting
this output to anywhere that I don't want it to go. Which means I'm lost to
where the output is actually going and how do I get it back onto the screen
?


If you run R CMD check mypkg, then you'll get a subdirectory created 
called mypkg.Rcheck.  If your package has tests, this subdir will itself 
have a tests subdir, and that will contain a .Rout file for your tests.


One way to monitor the tests would be to run them in the background and 
watch that file using "tail -f" (if you have tail, or can get it).


Duncan Murdoch

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


[R] Arithmethic operations on timeSeries objects

2010-03-03 Thread Luis Felipe Parra
Hello I have a time series object which I created from the following code
Fechas<-Datos[,1]
dat<-Datos[,2:ncol(Datos)]
datTS<-timeSeries(dat,Fechas)
I am trying to do know basic arithmethic operations on it as the following

datTS[3708,1]*2
Error en e1 * e2 : argumento no-numérico para operador binario

> datTS2[3708,1]-datTS2[3707,1]
Error en datTS2[3708, 1] - datTS2[3707, 1] : positions slot do not match
Which is the correct way of doing this? Thank you

Felipe PArra

[[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] repeated measures anova, car package

2010-03-03 Thread Kay Cichini



sorry, it should say "I copied the model from the car manual.."
more precise, I did the same as there in doing the lm(cbind()) call first an
then the av.ok, etc.  
-- 
View this message in context: 
http://n4.nabble.com/repeated-measures-anova-car-package-tp1573721p1577432.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] Zero inflated negative binomial

2010-03-03 Thread Achim Zeileis

On Thu, 4 Mar 2010, Rebecca Lawrence wrote:


Hi all,

I am running the following model:


glm89.nb <- glm.nb(AvGUD ~ Year*Trt*Micro)

where Year has 3 levels, Trt has 2 levels and Micro has 3 levels.

However when I run it has a zero inflated negative binomial (as I have lots
of zeros) I get the below error message:


Zinb <- zeroinfl(AvGUD ~ Year*Trt*Micro |1, data = AvGUD89, dist =

"negbin")
Error in optim(fn = loglikfun, gr = gradfun, par = c(start$count,
start$zero,  :
 non-finite value supplied by optim

For what I have read I think the problem is that for Year level 3 there is
no Trt 1 and for Year level 1 there is no Micro level 3.


Yes, in that case a number of coefficients are not identified. glm.nb() 
handles this more gracefully and sets the non-identified parameters to NA. 
I'll think about whether I can do something similar for zeroinfl/hurdle.


For the moment, here's a workaround: You can set up a data frame that 
contains only the identified regressors and call zeroinfl() with that. For 
illustration I use the quine data from the "MASS" package:


## packages and data
library("MASS")
library("pscl")
data("quine", package = "MASS")

## subset of data with some combination missing
quine2 <- subset(quine, !(Age == "F3" & Sex == "M"))

## glm.nb() works and yields some NA coefficients
fm1 <- glm.nb(Days ~ Eth * Sex * Age, data = quine2)

## zeroinfl() fails
fm2 <- zeroinfl(Days ~ Eth * Sex * Age | 1, data = quine2,
  dist = "negbin")

## set up version of data with non-identified regressors omitted
quine3 <- as.data.frame(model.matrix(fm1)) ## all regressors
quine3 <- quine3[, !is.na(coef(fm1))]  ## only identified
quine3 <- quine3[, -1] ## omit intercept
quine3$Days <- quine2$Days ## add response

## re-fit glm.nb()
fm1a <- glm.nb(Days ~ ., data = quine3)
## equivalent to previous fit
logLik(fm1a) - logLik(fm1)
coef(fm1a) - na.omit(coef(fm1))

## fit zeroinfl(), now works
fm2a <- zeroinfl(Days ~ . | 1, data = quine3, dist = "negbin")

hth,
Z


I cannot find a solution to this problem, is there any way I can solve this
so I can run the zero inflated model?

Thank you for your time
Rebecca

[[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 and screen (UNIX question)

2010-03-03 Thread Sarah Goslee
I've never had any trouble using R and screen with a remote connection.
You're detaching it first, right? (Just to start with the obvious question.)

What exactly are you doing, and what happens?

Sarah

On Wed, Mar 3, 2010 at 5:43 PM, Jonathan Greenberg
 wrote:
> I'm having a mixed experience with using R and UNIX's screen function
> -- sometimes when I close a connection that used screen, the R process
> is killed (which, in theory, it shouldn't be -- it should be running
> in the background).  Does anyone have any ideas on how well (or not) R
> behaves with screen, and if there any tricks to using R and SOME type
> of background program that doesn't require permanent connection?
>
> --j
>


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

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


Re: [R] two questions for R beginners

2010-03-03 Thread Jim Lemon

On 03/04/2010 08:20 AM, David Winsemius wrote:

...

Perhaps the print methods for data.frame and matrix
should announce the class of the object being printed.


Yes! An enthusiastic vote for highlighting this fundamental distinction.
There is already quite enough conflation of these two very dissimilar
object classes.

If so, please make it an option with an argument like "show.class" or 
"print.fancy" that can be set globally in options. Otherwise those of us 
who depend upon the sparse displays of R objects in our functions (e.g. 
in the prettyR package) will suffer the results.


Jim

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


Re: [R] counting the number of ones in a vector

2010-03-03 Thread Randall Wrong
Thanks to all of you !
(Benjamin Nutter, Henrique Dallazuanna, Tobias Verbeke, Jorge Ivan Velez,
David Reinke and Gavin Simpson)


x <- c(1, 1, 1, NA, NA, 2, 1, NA)

> table(x)["1"]
1
4

Why do I get two numbers ?

Thanks,
Randall



2010/2/26 Nutter, Benjamin 

> But if x has any missing values:
>
> > x <- c(1, 1, 1, NA, NA, 2, 1, NA)
> >
> > sum( x == 1)
> [1] NA
> >
> > sum(x==1, na.rm=TRUE)
> [1] 4
>
>
>
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Henrique Dallazuanna
> Sent: Friday, February 26, 2010 9:47 AM
> To: Randall Wrong
> Cc: r-help@r-project.org
> Subject: Re: [R] counting the number of ones in a vector
>
> Try:
>
> sum(x == 1)
>
> On Fri, Feb 26, 2010 at 11:40 AM, Randall Wrong 
> wrote:
> > Dear R users,
> >
> > I want to count the number of ones in a vector x.
> >
> > That's what I did : length( x[x==1] )
> >
> > Is that a good solution ?
> > Thank you very much,
> > Randall
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
> ===
>
> P Please consider the environment before printing this e-mail
>
> Cleveland Clinic is ranked one of the top hospitals
> in America by U.S.News & World Report (2009).
> Visit us online at http://www.clevelandclinic.org for
> a complete listing of our services, staff and
> locations.
>
>
> Confidentiality Note:  This message is intended for use
>  only by the individual or entity to which it is addressed
> and may contain information that is privileged,
> confidential, and exempt from disclosure under applicable
> law.  If the reader of this message is not the intended
> recipient or the employee or agent responsible for
> delivering the message to the intended recipient, you are
> hereby notified that any dissemination, distribution or
> copying of this communication is strictly prohibited.  If
> you have received this communication in error,  please
> contact the sender immediately and destroy the material in
> its entirety, whether electronic or hard copy.  Thank you.
>
>

[[alternative HTML version deleted]]

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


Re: [R] cluster with mahalanobis distance

2010-03-03 Thread Albyn Jones
Note: this procedure assumes that all clusters have the same covariance matrix.

albyn

On Wed, Mar 03, 2010 at 01:23:37PM -0800, Phil Spector wrote:
> The manhattan distance and the Mahalanobis distances are quite different.  
> One of the main differences is that a covariance matrix is necessary to 
> calculate the Mahalanobis
> distance, so it's not easily accomodated by dist.  There is a function in 
> base R which does calculate the Mahalanobis
> distance -- mahalanobis().  So if you pass a distance matrix
> calculated by mahalanobis() to the clustering function, you'll
> get what you want.
>   - Phil Spector
>Statistical Computing Facility
>Department of Statistics
>UC Berkeley
>spec...@stat.berkeley.edu
>
>
> On Wed, 3 Mar 2010, Tal Galili wrote:
>
>> when you create the distance function to put into the hclust, use:
>>
>> dist(x, method = "manhattan")
>>
>>
>> Tal
>>
>>
>>
>> Contact
>> Details:---
>> Contact me: tal.gal...@gmail.com |  972-52-7275845
>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
>> www.r-statistics.com (English)
>> --
>>
>>
>>
>>
>> On Wed, Mar 3, 2010 at 9:14 PM, naama  wrote:
>>
>>>
>>> How can I perform cluster analysis using the mahalanobis distance instead
>>> of
>>> the euclidean distance?
>>> thank you
>>> Naama Wolf
>>>
>>> --
>>> View this message in context:
>>> http://n4.nabble.com/cluster-with-mahalanobis-distance-tp1577038p1577038.html
>>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>  [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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

2010-03-03 Thread Roslina Zakaria
Hi all,
I have this data set:
## Empirical copula
## dt1 = ranking
## dt2 = observed uniform data associated with the ranking
 
Sample data, 
> dt1
    S_i   R_i
 [1,]   7.0  10.0
 [2,] 232.5 440.5
 [3,] 143.0 141.5
 [4,] 272.5 222.0
 [5,]  46.0  34.0
 [6,] 527.0 483.0
 [7,] 420.5 563.5
 [8,]  23.5  16.5
 [9,]  56.5  68.5
[10,] 341.5 382.5
 
> dt2
  unisk1 unisk2
 [1,]  0.008  0.010
 [2,]  0.298  0.615
 [3,]  0.194  0.187
 [4,]  0.357  0.297
 [5,]  0.067  0.048
 [6,]  0.767  0.687
 [7,]  0.573  0.805
 [8,]  0.032  0.025
 [9,]  0.082  0.094
[10,]  0.452  0.516
 
 
for S_i data below, I have divided by 691:
 
> cbind(dt1/(691+1),dt2)
 S_i    R_i unisk1 unisk2
 [1,] 0.01011561 0.01445087  0.008  0.010
 [2,] 0.33598266 0.63656069  0.298  0.615
 [3,] 0.20664740 0.20447977  0.194  0.187
 [4,] 0.39378613 0.32080925  0.357  0.297
 [5,] 0.06647399 0.04913295  0.067  0.048
 [6,] 0.76156069 0.69797688  0.767  0.687
 [7,] 0.60765896 0.81430636  0.573  0.805
 [8,] 0.03395954 0.02384393  0.032  0.025
 [9,] 0.08164740 0.09898844  0.082  0.094
[10,] 0.49349711 0.55274566  0.452  0.516
 
My code is
 
n <- 691
Cn_u1.u2 <- function(dt1,dt2,n)
 
{    cn  <- vector(length=n, mode="numeric")
    
    for (i in 1:n)
    { A <- as.numeric(dt1[i,1]/(n+1) <= dt2[1,1] & dt1[i,2]/(n+1) <= 
dt2[1,2])
  cn[i] <- sum(A)/n
   }
  cn
}
 
What I want to do is to compare all ranking value with each uni data at a time 
using logical and if the it is true=1 and else =0.  I use as.numeric() as what 
you suggested before.
 
For example: calculate all where ( S_i <= unisk1[1] and R_i <= unisk2[1]) and 
continue the process for all unisk1 and unisk2.  If n=691, I will have cn=691.
 
Thank you so much for your help.




  
[[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] R and screen (UNIX question)

2010-03-03 Thread Jonathan Greenberg
I'm having a mixed experience with using R and UNIX's screen function
-- sometimes when I close a connection that used screen, the R process
is killed (which, in theory, it shouldn't be -- it should be running
in the background).  Does anyone have any ideas on how well (or not) R
behaves with screen, and if there any tricks to using R and SOME type
of background program that doesn't require permanent connection?

--j

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


Re: [R] Output from test script during R CMD check

2010-03-03 Thread DarioAustralia

Ah yes sorry about that it was a vague posting.

What I'd like to see when I do a R CMD check on the package and it gets to
the part where it runs the test script, I'd like to show to the user on the
screen the progress of the testing. What happens now is none of the
cat("Test X was successful. \n") statements that I have within the .R file
go to the screen. I did a search of the filesystem for a .Rout file that
maybe it was sending this output to, with the same filename as my test
script, but there isn't any. So I don't think R CMD BATCH is redirecting
this output to anywhere that I don't want it to go. Which means I'm lost to
where the output is actually going and how do I get it back onto the screen
?

Thanks again,
  Dario.
-- 
View this message in context: 
http://n4.nabble.com/Output-from-test-script-during-R-CMD-check-tp1576046p1577361.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] Newb question re. read.table...

2010-03-03 Thread Rolf Turner

On 4/03/2010, at 10:50 AM, Steven DeRose wrote:

> I'm trying to get started with R, on Ubuntu. I worked through the
> tutorial, and have made a small tab-delimited subset of my data to try
> out (10 cases with about a dozens variables). But I can't seem to figure
> out how to actually refer to variables. I presume I'm missing something
> very simple, but quite a while searching the doc and the FAQ haven't
> helped me.
> 
> I'm loading the data with
>con <- read.table("tiny.txt", header=TRUE)
> 
> The first record is a set of variable names, tab-separated like the rest
> of the rows. There are no row labels, thus the same number of
> tab-delimited fields in the header record and the following records. The
> read.table returns silently, and I can get a reasonable summary(con).
> But if I try something like plot(rel,len), where rel and len are two of
> the labels from the header row, I get
> 
> Error in plot(rel, len) : object 'rel' not found
> 
> I've tried many variations (different variables, adding "con." on the
> front, quoting, using field numbers instead of names, etc. I've also
> read what I can find on read.table, but I'm clearly missing some basic
> thing
> 
> Can somebody put me back on the right track? Is there some additional
> thing I have to do to make this into a "real" frame, or to bind
> variables names to header names, or something like that?
> 
> Thanks, and sorry for being dense

You haven't got ``rel'' and ``len'' in your workspace.  They are
columns (components) of the data frame object ``con'' which ***is***
in your workspace.

There are various ways to access components of a data frame:

* plot(con$rel,con$len)
* plot(con[["rel"]],con[["len"]])
* plot(con[,"rel"],con[,"len"])
* with(con, plot(rel,len))

You should read enough R documentation so that you understand the
under-pinnings of these various syntaxes.

The last one, ``with(con ...'' turns (temporarily) the data frame ``con''
into a data base on your search path.  The components ``rel'' and ``len''
are then objects in this data base and thereby become accessible.

A fifth way to proceed (***NOT*** recommended) is to do:

attach(con)
plot(rel,len)
detach(con)

This is something like the ``with'' solution; with() automates the
attaching and detaching.

The difference is that if you ***have*** got objects ``rel'' and ``len''
in your workspace (and these are different from the columns of ``con'')
then the attach()---detach() procedure will use the objects in your
workspace.  They ``mask'' the columns of ``con''.  The with() procedure
is not beset with this problem.

HTH

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

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


Re: [R] Newb question re. read.table...

2010-03-03 Thread Ista Zahn
Hi Steve,
I think the problem is just that those variables are in the con
data.frame. If so you have several options:

1) with(con, plot(rel, len))
2) plot(con$rel, con$len)
3) attach(con); plot(rel, len)

Best,
Ista


On Wed, Mar 3, 2010 at 4:50 PM, Steven DeRose
 wrote:
> I'm trying to get started with R, on Ubuntu. I worked through the
> tutorial, and have made a small tab-delimited subset of my data to try
> out (10 cases with about a dozens variables). But I can't seem to figure
> out how to actually refer to variables. I presume I'm missing something
> very simple, but quite a while searching the doc and the FAQ haven't
> helped me.
>
> I'm loading the data with
>    con <- read.table("tiny.txt", header=TRUE)
>
> The first record is a set of variable names, tab-separated like the rest
> of the rows. There are no row labels, thus the same number of
> tab-delimited fields in the header record and the following records. The
> read.table returns silently, and I can get a reasonable summary(con).
> But if I try something like plot(rel,len), where rel and len are two of
> the labels from the header row, I get
>
>     Error in plot(rel, len) : object 'rel' not found
>
> I've tried many variations (different variables, adding "con." on the
> front, quoting, using field numbers instead of names, etc. I've also
> read what I can find on read.table, but I'm clearly missing some basic
> thing
>
> Can somebody put me back on the right track? Is there some additional
> thing I have to do to make this into a "real" frame, or to bind
> variables names to header names, or something like that?
>
> Thanks, and sorry for being dense
>
> Steve
>
>
>
>
>        [[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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

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


[R] Zero inflated negative binomial

2010-03-03 Thread Rebecca Lawrence
Hi all,

 I am running the following model:

> glm89.nb <- glm.nb(AvGUD ~ Year*Trt*Micro)
 where Year has 3 levels, Trt has 2 levels and Micro has 3 levels.

However when I run it has a zero inflated negative binomial (as I have lots
of zeros) I get the below error message:

> Zinb <- zeroinfl(AvGUD ~ Year*Trt*Micro |1, data = AvGUD89, dist =
"negbin")
Error in optim(fn = loglikfun, gr = gradfun, par = c(start$count,
start$zero,  :
  non-finite value supplied by optim

For what I have read I think the problem is that for Year level 3 there is
no Trt 1 and for Year level 1 there is no Micro level 3.
I cannot find a solution to this problem, is there any way I can solve this
so I can run the zero inflated model?

Thank you for your time
Rebecca

[[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] Working with combinations

2010-03-03 Thread Erich Neuwirth
The following code takes a combination of type n over k represented by an 
increasing sequence
as input an produces the lexicographically next combinations.
So you can single step through all possible combinations and apply your filter 
criteria
before you produce the next combination.


next.combin <- function(oldcomb,n){
   lcomb <- length(oldcomb)
   hole.pos <- last.hole.pos(oldcomb,n)
   if ((hole.pos == lcomb) & oldcomb[lcomb]==n) {
 return(NA)
   }
   newcomb<-oldcomb
   newcomb[hole.pos]<-oldcomb[hole.pos]+1
   return(newcomb)
}

last.hole.pos <- function(comb,n){
  lcomb <- length(comb)
  diffs <- comb[-1]-comb[-lcomb]
  if (max(diffs)==1) {
return(lcomb)
  } 
  diffpos <- which(diffs>1)
  return(diffpos[length(diffpos)])  
   
}

On Mar 3, 2010, at 7:35 PM, Herm Walsh wrote:

> Thanks David for the thoughts.  The challenge I have with this approach is 
> that the criteria I have is defined by a series of tests--which I do not 
> think I could substitute in in place of the logical indexing.
> 
> In the combinations code I was hoping there is a step where, each new 
> combination is added to the current list of combinations.  If this were the 
> case, I could put my series of tests in the code right there and then store 
> the combination if appropriate.
> 
> However, evalutating the code--which uses recursion--I am not sure if this 
> approach will work.  The combinations code is listed below.  Is there a 
> simple place(s) where I could insert my tests, operating on the current 
> combination?
> 
> function (n, r, v = 1:n, set = TRUE, repeats.allowed = FALSE) 
> {
> if (mode(n) != "numeric" || length(n) != 1 || n < 1 || (n%%1) != 
> 0) 
> stop("bad value of n")
> if (mode(r) != "numeric" || length(r) != 1 || r < 1 || (r%%1) != 
> 0) 
> stop("bad value of r")
> if (!is.atomic(v) || length(v) < n) 
> stop("v is either non-atomic or too short")
> if ((r > n) & repeats.allowed == FALSE) 
> stop("r > n and repeats.allowed=FALSE")
> if (set) {
> v <- unique(sort(v))
> if (length(v) < n) 
> stop("too few different elements")
> }
> v0 <- vector(mode(v), 0)
> if (repeats.allowed) 
> sub <- function(n, r, v) {
> if (r == 0) 
> v0
> else if (r == 1) 
> matrix(v, n, 1)
> else if (n == 1) 
> matrix(v, 1, r)
> else rbind(cbind(v[1], Recall(n, r - 1, v)), Recall(n - 
> 1, r, v[-1]))
> }
> else sub <- function(n, r, v) {
> if (r == 0) 
> v0
> else if (r == 1) 
> matrix(v, n, 1)
> else if (r == n) 
> matrix(v, 1, n)
> else rbind(cbind(v[1], Recall(n - 1, r - 1, v[-1])), 
> Recall(n - 1, r, v[-1]))
> }
> sub(n, r, v[1:n])
> }
> 
> 
> 
> 
> **
> 
>> I am working with the combinations function (available in the gtools 
>> package).  However, rather than store all of the possible combinations I 
>> would like to check each combination to see if it meets a certain criteria.  
>> If it does, I will then store it.
>> 
>> I have looked at the combinations code but am unsure where in the algorithm 
>> I would be able to operate on each combination.
> 
> Logical indexing:
> 
>> combinations(3,2,letters[1:3])[,1]=="a"
> [1]  TRUE  TRUE FALSE
> 
>> combinations(3,2,letters[1:3])[ combinations(3,2,letters[1:3])[,1]=="a", ]
> [,1] [,2]
> [1,] "a"  "b"
> [2,] "a"  "c"
> 
> --David 
> 
> 
> 
> 
>   [[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.

--
Erich Neuwirth
Didactic Center for Computer Science and Institute for Scientific Computing
University of Vienna





[[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] Newb question re. read.table...

2010-03-03 Thread Steven DeRose
I'm trying to get started with R, on Ubuntu. I worked through the
tutorial, and have made a small tab-delimited subset of my data to try
out (10 cases with about a dozens variables). But I can't seem to figure
out how to actually refer to variables. I presume I'm missing something
very simple, but quite a while searching the doc and the FAQ haven't
helped me.

I'm loading the data with
con <- read.table("tiny.txt", header=TRUE)

The first record is a set of variable names, tab-separated like the rest
of the rows. There are no row labels, thus the same number of
tab-delimited fields in the header record and the following records. The
read.table returns silently, and I can get a reasonable summary(con).
But if I try something like plot(rel,len), where rel and len are two of
the labels from the header row, I get

 Error in plot(rel, len) : object 'rel' not found

I've tried many variations (different variables, adding "con." on the
front, quoting, using field numbers instead of names, etc. I've also
read what I can find on read.table, but I'm clearly missing some basic
thing

Can somebody put me back on the right track? Is there some additional
thing I have to do to make this into a "real" frame, or to bind
variables names to header names, or something like that?

Thanks, and sorry for being dense

Steve




[[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] cluster with mahalanobis distance

2010-03-03 Thread Ravi Varadhan
"The manhattan distance and the Mahalanobis distances are quite different. "

This ought to be a candidate for "fortunes".

The way distances are perceived in New York city is very different from that in 
Calcutta (which is where Professor Prasant Chandra Mahalanobis lived)!  

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: Phil Spector 
Date: Wednesday, March 3, 2010 4:24 pm
Subject: Re: [R] cluster with mahalanobis distance
To: Tal Galili 
Cc: r-help@r-project.org, naama 


> The manhattan distance and the Mahalanobis distances are 
>  quite different.  One of the main differences is that 
>  a covariance matrix is necessary to calculate the Mahalanobis
>  distance, so it's not easily accomodated by dist.  There 
>  is a function in base R which does calculate the Mahalanobis
>  distance -- mahalanobis().  So if you pass a distance matrix
>  calculated by mahalanobis() to the clustering function, you'll
>  get what you want.
>   - Phil Spector
>Statistical Computing Facility
>Department of Statistics
>UC Berkeley
>spec...@stat.berkeley.edu
>  
>  
>  On Wed, 3 Mar 2010, Tal Galili wrote:
>  
>  > when you create the distance function to put into the hclust, use:
>  >
>  > dist(x, method = "manhattan")
>  >
>  >
>  > Tal
>  >
>  >
>  >
>  > Contact
>  > Details:---
>  > Contact me: tal.gal...@gmail.com |  972-52-7275845
>  > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il 
> (Hebrew) |
>  > www.r-statistics.com (English)
>  > 
> --
>  >
>  >
>  >
>  >
>  > On Wed, Mar 3, 2010 at 9:14 PM, naama  wrote:
>  >
>  >>
>  >> How can I perform cluster analysis using the mahalanobis distance 
> instead
>  >> of
>  >> the euclidean distance?
>  >> thank you
>  >> Naama Wolf
>  >>
>  >> --
>  >> View this message in context:
>  >> 
>  >> Sent from the R help mailing list archive at Nabble.com.
>  >>
>  >> __
>  >> R-help@r-project.org mailing list
>  >> 
>  >> PLEASE do read the posting guide
>  >> 
>  >> and provide commented, minimal, self-contained, reproducible code.
>  >>
>  >
>  >[[alternative HTML version deleted]]
>  >
>  > __
>  > 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
>  
>  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] Working with combinations

2010-03-03 Thread David Winsemius


On Mar 3, 2010, at 12:35 PM, Herm Walsh wrote:

Thanks David for the thoughts.  The challenge I have with this  
approach is that the criteria I have is defined by a series of  
tests--which I do not think I could substitute in in place of the  
logical indexing.


In the combinations code I was hoping there is a step where, each  
new combination is added to the current list of combinations.  If  
this were the case, I could put my series of tests in the code right  
there and then store the combination if appropriate.


However, evalutating the code--which uses recursion--I am not sure  
if this approach will work.  The combinations code is listed below.   
Is there a simple place(s) where I could insert my tests, operating  
on the current combination?

function (n, r, v = 1:n, set = TRUE, repeats.allowed = FALSE)
{
if (mode(n) != "numeric" || length(n) != 1 || n < 1 || (n%%1) !=
0)
stop("bad value of n")
if (mode(r) != "numeric" || length(r) != 1 || r < 1 || (r%%1) !=
0)
stop("bad value of r")
if (!is.atomic(v) || length(v) < n)
stop("v is either non-atomic or too short")
if ((r > n) & repeats.allowed == FALSE)
stop("r > n and repeats.allowed=FALSE")
if (set) {
v <- unique(sort(v))
if (length(v) < n)
stop("too few different elements")
}
v0 <- vector(mode(v), 0)
if (repeats.allowed)
sub <- function(n, r, v) {
if (r == 0)
v0
else if (r == 1)
matrix(v, n, 1)
else if (n == 1)
matrix(v, 1, r)

#---new---

else if (combo_true)

  Recall(n - 1, r, v[-1])
#

else rbind(cbind(v[1], Recall(n, r - 1, v)), Recall(n -
1, r, v[-1]))


# this would be the point at which one would decide whether to insert  
a new combination-row.
# You could insert an else if clause above it triggered by your  
combination criteria

}
else sub <- function(n, r, v) {
if (r == 0)
v0
else if (r == 1)
matrix(v, n, 1)
else if (r == n)
matrix(v, 1, n)
else rbind(cbind(v[1], Recall(n - 1, r - 1, v[-1])),
Recall(n - 1, r, v[-1]))


*Or here  or both


}
sub(n, r, v[1:n])
}



**

> I am working with the combinations function (available in the  
gtools package).  However, rather than store all of the possible  
combinations I would like to check each combination to see if it  
meets a certain criteria.  If it does, I will then store it.

>
> I have looked at the combinations code but am unsure where in the  
algorithm I would be able to operate on each combination.


Logical indexing:

> combinations(3,2,letters[1:3])[,1]=="a"
[1]  TRUE  TRUE FALSE

> combinations(3,2,letters[1:3])[ combinations(3,2,letters[1:3])[, 
1]=="a", ]

[,1] [,2]
[1,] "a"  "b"
[2,] "a"  "c"

--David




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


Re: [R] two questions for R beginners

2010-03-03 Thread David Winsemius


On Mar 3, 2010, at 12:15 PM, William Dunlap wrote:


If R made
  matrix$columnName
mean the same as
  matrix[, "columnName"]
(a vector) so matrices looked more like data.frames,
would we also want the following to work
as they do with data.frames?
  with(matrix, log(columnName)) # log of that column as a vector
  matrix["columnName"] # 1-column matrix
  matrix[["columnName"]] # vector equivalent of that 1-column matrix
  lm(responseColumn~predictorColumn, data=matrix)
  eval(quote(columnName), envir=matrix)
The last 2 bump into the rule allowing envir to be
a frame number (since a 1x1 matrix is currently taken
as the frame number now).

Perhaps the print methods for data.frame and matrix
should announce the class of the object being printed.


Yes! An enthusiastic vote for highlighting this fundamental  
distinction. There is already quite enough conflation of these two  
very dissimilar object classes.


--
David Winsemius


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Patrick Burns
Sent: Wednesday, March 03, 2010 2:44 AM
To: r-help@r-project.org
Subject: Re: [R] two questions for R beginners

I think Duncan's example of a list that is
a matrix is a compelling argument not to do
the change.

A matrix that is a list with both names and
dimnames *is* probably rare (but certainly
imaginable).  A matrix that is a list is not
so rare, and the proposed double meaning of
'$' would certainly be confusing in that case.

Pat


On 02/03/2010 17:55, Duncan Murdoch wrote:

On 02/03/2010 11:53 AM, William Dunlap wrote:

-Original Message-
From: r-help-boun...@r-project.org >

[mailto:r-help-boun...@r-project.org] On Behalf Of John Sorkin

Sent: Tuesday, March 02, 2010 3:46 AM
To: Karl Ove Hufthammer; r-h...@stat.math.ethz.ch
Subject: Re: [R] two questions for R beginners

Please take what follows not as an ad hominem statement, but >

rather as an attempt to improve what is already an excellent >
program, that has been built as a result of many, many hours > of
dedicated work by many, many unpaid, unsung volunteers.

It troubles me a bit that when a confusing aspect of R is >

pointed out the response is not to try to improve the >

language so as

to avoid the confusion, but rather to state > that the confusion is
inherent in the language. I understand > that to make changes that
would avoid the confusing aspect of > the language that has been
discussed in this thread would > take time and effort by

an R wizard

(which I am not), time > and effort that would not be

compensated in

the traditional > sense. This does not mean that we should not
acknowledge the > confusion. If we what R to be the de facto lingua
franca of > statistical analysis doesn't it make sense to

strive for >

syntax that is as straight forward and consistent as possible?
Whenever one changes the language that way old code
will break.

I think in this case not much code would break. Mostly when

people have

a matrix M and ask for M$column they'll get an error; the

proposal is

that they'll get the requested column. (It is possible to

have a list

with names that is also a matrix with dimnames, but I think

that is a

pretty unusual construction.) But I haven't been convinced that the
proposal is a net improvement to the language.
Duncan Murdoch


The developers can, with a lot of effort,
fix their own code, and perhaps even user-written code
on CRAN, but code that thousands of users have written
will break. There is a lot of code out there that was
written by trial and error and by folks who no longer
work at an institution: the code works but no one knows
exactly why it works. Telling folks they need to change
that code because we have a cleaner but different syntax
now is not good. Why would one spend time writing a
package that might stop working when R is "upgraded"?

I think the solution is not to change current semantics
but to write functions that behave better and encourage
users to use them, gradually abandoning the old constructs.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

Again, please understand that my comment is made with deepest >

respect for the many people who have unselfishly

contributed > to the

R project. Many thanks to each and every one of you.

John

Karl Ove Hufthammer  3/2/2010

4:00 AM >>>

On Mon, 01 Mar 2010 10:00:07 -0500 Duncan Murdoch >

 > wrote:

Suppose X is a dataframe or a matrix. What would you >

expect to

get from > > X[1]? What about as.vector(X), or as.numeric(X)?

All this of course depends on type of object one is

speaking > of.

There > are plenty of surprises available, and it's best

to use the >

most logical > way of extracting. E.g., to extract the top-left
element of a 2D > structure (data frame or matrix), use 'X[1,1]'.

Luckily, R provides some shortcuts. For example, you

can > write

'X[2,3]' > on a data frame, just as if it was a matrix,

Re: [R] cluster with mahalanobis distance

2010-03-03 Thread Phil Spector
The manhattan distance and the Mahalanobis distances are 
quite different.  One of the main differences is that 
a covariance matrix is necessary to calculate the Mahalanobis
distance, so it's not easily accomodated by dist.  There 
is a function in base R which does calculate the Mahalanobis

distance -- mahalanobis().  So if you pass a distance matrix
calculated by mahalanobis() to the clustering function, you'll
get what you want.
- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Wed, 3 Mar 2010, Tal Galili wrote:


when you create the distance function to put into the hclust, use:

dist(x, method = "manhattan")


Tal



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Wed, Mar 3, 2010 at 9:14 PM, naama  wrote:



How can I perform cluster analysis using the mahalanobis distance instead
of
the euclidean distance?
thank you
Naama Wolf

--
View this message in context:
http://n4.nabble.com/cluster-with-mahalanobis-distance-tp1577038p1577038.html
Sent from the R help mailing list archive at Nabble.com.

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



[[alternative HTML version deleted]]

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



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


[R] Screen settings for point of view in lattice and misc3d

2010-03-03 Thread Waichler, Scott R
I'm making some 3D plots with contour3d from misc3d and wireframe from lattice. 
 I want to view them from below; i.e. the negative z-axis.  I can't figure out 
how to do so.  I would like my point of view looking up from below, with the z, 
y, and x axes positive going away.  Can anyone tell me the correct settings for 
screen to achieve this?  Here is what I've found so far:

 screen=list(z=-40, x=-60, y=0), # looking down and away in negative x direction
 screen=list(z=40, x=60, y=0),  # domain turned upside down, looking up and 
away in neg. x direction
 screen=list(z=-40, x=60, y=0),  # domain turned upside down, looking up and 
away in pos. x direction
 screen=list(z=40, x=-60, y=0), # looking down and away in positive x 
direction


Scott Waichler
Pacific Northwest National Laboratory
P.O. Box 999, Richland, WA  99352
scott.waich...@pnl.gov
509-372-4423, 509-341-4051 (cell)

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


Re: [R] cluster with mahalanobis distance

2010-03-03 Thread Tal Galili
I am sorry,
After further inspection I fear my last answer was not correct, please
ignore it - and let's wait for other responders.

Tal

Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Wed, Mar 3, 2010 at 11:16 PM, Tal Galili  wrote:

> when you create the distance function to put into the hclust, use:
>
> dist(x, method = "manhattan")
>
>
> Tal
>
>
>
> Contact
> Details:---
> Contact me: tal.gal...@gmail.com |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
>
> --
>
>
>
>
>
> On Wed, Mar 3, 2010 at 9:14 PM, naama  wrote:
>
>>
>> How can I perform cluster analysis using the mahalanobis distance instead
>> of
>> the euclidean distance?
>> thank you
>> Naama Wolf
>>
>> --
>> View this message in context:
>> http://n4.nabble.com/cluster-with-mahalanobis-distance-tp1577038p1577038.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

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


Re: [R] cluster with mahalanobis distance

2010-03-03 Thread Tal Galili
when you create the distance function to put into the hclust, use:

dist(x, method = "manhattan")


Tal



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Wed, Mar 3, 2010 at 9:14 PM, naama  wrote:

>
> How can I perform cluster analysis using the mahalanobis distance instead
> of
> the euclidean distance?
> thank you
> Naama Wolf
>
> --
> View this message in context:
> http://n4.nabble.com/cluster-with-mahalanobis-distance-tp1577038p1577038.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] cluster with mahalanobis distance

2010-03-03 Thread naama

How can I perform cluster analysis using the mahalanobis distance instead of
the euclidean distance?
thank you 
Naama Wolf

-- 
View this message in context: 
http://n4.nabble.com/cluster-with-mahalanobis-distance-tp1577038p1577038.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] How to create a line and bar panel chart with two different axes?

2010-03-03 Thread DougNiu

I need to create a line and bar panel chart with two different axes. I tried
in lattice but couldn't get it worked. Here is my code:

data(barley)
barchart(yield ~ variety | site, data = barley,
  groups = year, layout = c(1,6), stack = F, 
  auto.key = list(points = FALSE, rectangles = TRUE, space =
"right"),
  ylab = "Barley Yield (bushels/acre)",
  scales = list(x = list(rot = 45)))

Suppose now I need to add two lines in each panel to show the cost (10^3
dollars) of each type (Svansota,,Trebi) at different locations
(Waseca,..., Grand Rapids) for 1931 and 1932.

Can any body tell me how I should do to create this chart with two different
axes (one is yield, the other is cost)?

Thank you in advance!

Doug
-- 
View this message in context: 
http://n4.nabble.com/How-to-create-a-line-and-bar-panel-chart-with-two-different-axes-tp1577173p1577173.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] Subset using partial values

2010-03-03 Thread David Winsemius


On Mar 3, 2010, at 9:04 AM, Newbie19_02 wrote:



Thanks again for the help but what I am having trouble with is that  
I get:


1012  CAO0103166 01/04/1999   I200
1016  CAO0103166 03/05/2000   I200
1024  CAO0103166 20/06/1997   I209
1025  CAO0103166 25/02/1999   I209
1027  CAO0103166 27/08/1999   I200
1058  CAO0107171 11/01/2002   N411
1104  CAO0113512 14/02/2003   I209



Use the "^' (caret) to represent the beginning of a string.

> tdt[grepl("^410*|^I25*", tdt$main_condition), ]
  ID PROCHI Date_admission main_condition
2  28394 CAO3121534 18/04/1999   I251
3  28395 CAO3121534 18/10/1993   4109
5  28397 CAO3121534 20/04/1999   I251
6  28398 CAO3121534 21/04/1999   I251
8  28400 CAO3121534 21/10/1993   4109
13 28405 CAO3121534 30/09/1997   I259

Or:

> subset(tdt, grepl("^410*|^I25*",main_condition))
  ID PROCHI Date_admission main_condition
2  28394 CAO3121534 18/04/1999   I251
3  28395 CAO3121534 18/10/1993   4109
5  28397 CAO3121534 20/04/1999   I251
6  28398 CAO3121534 21/04/1999   I251
8  28400 CAO3121534 21/10/1993   4109
13 28405 CAO3121534 30/09/1997   I259



I'm trying to avoid getting N411?

Thanks,
Natalie
--
View this message in context: 
http://n4.nabble.com/Subset-using-partial-values-tp1576614p1576683.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] two questions for R beginners

2010-03-03 Thread John Sorkin
Bill,
The points you make are well taken; one needs to know when to stop. 

I would suggest standardizing the methods used to refer to elements of a matrix 
and a dataframe and going no further. Why do I say this? A beginner, even a 
more experienced R users, probably envisions a dataframe and a matrix has 
having the same structure, but not the same contents. Both appear to be 
multi-dimensional structures that can store data, albeit data of different 
types. A matrix stores numerical values, a dataframe stores data of mixed 
types. This being the case it makes sense to assume that 
A%*%B will work when A and B are matrices, 
but C%*% D will not work when C and D are dataframes. 
This is quite logical and intuitive. It is an extension of the truism that one 
can perform the following arithmetic operation 2*3, but can't perform the 
following operation "Bill"*"John" (I use quotes to indicate that the names are 
proper names and not variable names). Despite the observation that on can 
reasonably expect that there are certain operations that one can perform on 
matrices, but not on dataframes (and conversely), the apparent similarity in 
structure of the two objects makes one assume (incorrectly at this time) that 
the syntax used to access elements of an array and a dataframe should be the 
same. I submit that having similar syntax for accessing elements of the two 
structures will assist users learn R. It will not cause them to assume that one 
can perform the exactly the same operations on the two structures.

I apologize to other members of the listserver for the length of this 
subthread. It appears that I have lost the argument, and have not convinced 
those who would need to make the changes to allow matrices and dataframes to 
have similar syntax for addressing elements of the respective structures. I do 
not expect I will be adding any additional comments to this thread, but will 
continue to follow contributions other people make. Perhaps I will learn that I 
am not the only person who feels that the syntax should be consistent, but 
given what I have read so far, I doubt it. I thank everyone who has contributed 
to the discussion.
John







John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)>>> "William 
Dunlap"  3/3/2010 1:15 PM >>>
If R made
   matrix$columnName
mean the same as
   matrix[, "columnName"]
(a vector) so matrices looked more like data.frames,
would we also want the following to work
as they do with data.frames?
   with(matrix, log(columnName)) # log of that column as a vector
   matrix["columnName"] # 1-column matrix
   matrix[["columnName"]] # vector equivalent of that 1-column matrix 
   lm(responseColumn~predictorColumn, data=matrix)
   eval(quote(columnName), envir=matrix)
The last 2 bump into the rule allowing envir to be
a frame number (since a 1x1 matrix is currently taken
as the frame number now).

Perhaps the print methods for data.frame and matrix
should announce the class of the object being printed.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Patrick Burns
> Sent: Wednesday, March 03, 2010 2:44 AM
> To: r-help@r-project.org 
> Subject: Re: [R] two questions for R beginners
> 
> I think Duncan's example of a list that is
> a matrix is a compelling argument not to do
> the change.
> 
> A matrix that is a list with both names and
> dimnames *is* probably rare (but certainly
> imaginable).  A matrix that is a list is not
> so rare, and the proposed double meaning of
> '$' would certainly be confusing in that case.
> 
> Pat
> 
> 
> On 02/03/2010 17:55, Duncan Murdoch wrote:
> > On 02/03/2010 11:53 AM, William Dunlap wrote:
> >> > -Original Message-
> >> > From: r-help-boun...@r-project.org >
> >> [mailto:r-help-boun...@r-project.org] On Behalf Of John Sorkin
> >> > Sent: Tuesday, March 02, 2010 3:46 AM
> >> > To: Karl Ove Hufthammer; r-h...@stat.math.ethz.ch 
> >> > Subject: Re: [R] two questions for R beginners
> >> > > Please take what follows not as an ad hominem statement, but >
> >> rather as an attempt to improve what is already an excellent >
> >> program, that has been built as a result of many, many hours > of
> >> dedicated work by many, many unpaid, unsung volunteers.
> >> > > It troubles me a bit that when a confusing aspect of R is >
> >> pointed out the response is not to try to improve the > 
> language so as
> >> to avoid the confusion, but rather to state > that the confusion is
> >> inherent in the language. I understand > that to make changes that
> >> would avoid the confusing aspect of > the language that has been
> >> discussed in this thread would > t

Re: [R] how to import map data (maptools?) from a html set of 'coords'

2010-03-03 Thread Henrique Dallazuanna
You can try this also:

plot(m <- matrix(v, ncol = 2, byrow = TRUE))
polygon(m)

On Wed, Mar 3, 2010 at 4:49 PM, sylvain willart
 wrote:
> SOLVED,
>
> example from the "Nord-Pas-de-Calais" region:
>
> 
> v <- 
> c(237,55,236,58,229,57,214,57,203,55,197,54,187,48,179,46,179,35,180,31,184,26,197,23,201,24,202,31,207,34,213,31,216,37,219,41,228,46,234,47,237,55)
>
> seqx <- seq(1,length(v),by=2)
> seqy <- seq(2,length(v),by=2)
>
> vx <- c()
> for (j in seqx) {
> vx <- c(vx,v[j])
>      }
> vy <- c()
> for (j in seqy) {
> vy <- c(vy,v[j])
>      }
> plot(vx,-vy)
> polygon(vx,-vy,border="red")
> 
>
> thanks for your tips,
>
> Sylvain
> Now, I just have to read it using maptools...
>
> 2010/3/3 sylvain willart :
>> Hi
>> thanks for your reply,
>> I'll try to better explain my request...
>> the data do not come from a file with a specific extension, this is
>> just some lines I copied pasted from a source html file
>>
>> The web page is:
>> http://www.insee.fr/fr/ppp/bases-de-donnees/donnees-detaillees/duicq/accueil.asp
>> it displays an (interactive) map of France with all the regions
>>
>> to access the source: edit/source , or Ctrl+U in a web browser
>>
>> By the middle of the html source file, there is an html object called
>> map ( ... ) with a set of coordinates representing the
>> polygons of each region,
>>
>> These coordinates are just location of points: x1,y1,x2,y2,x3,y3...
>> that draw polygons. They are not proper longitude or latitude and
>> their "origine" is just the corner of the image the html file
>> generates...
>>
>> I am aware those are not "real" geographic data (That's why I didn't
>> post my question to sig-geo, it looks more like a problem of
>> graphics), but these are the coordinates one need to "draw" a map (and
>> eventually import it to a more specific package like spatstat)
>>
>> So, what I would like to do is: using those coordinates to draw such a
>> map, and eventually use that map for distance or area calculus (which
>> do not need to be extremely precise...)
>>
>> sylvain
>>
>>
>> 2010/3/3 Michael Denslow :
>>> Hi Sylvian,
>>>
>>>
>>> On Tue, Mar 2, 2010 at 1:15 PM, sylvain willart
>>>  wrote:
 Dear R users,

 I would like to draw map and import it in maptools/spatstat packages.

 The 'raw data' I have come from a web page (...) and are
 basically a list of coordinates of a polygon.

 I would like to know how to import them in R; I checked the maptools
 packages, but all the examples use existing .dbf files.

 I just have a (serie of) text file(s) looking like this:

 For example, for the French Region Burgundy:

 >>> alt="Bourgogne"
 coords="208,121,211,115,221,113,224,115,225,120,229,122,232,128,251,125,255,
 130,256,136,266,138,268,148,267,154,263,160,267,168,267,180,262,
 175,256,178,254,184,248,184,243,187,237,187,232,185,234,181,227,
 171,216,171,212,166,211,155,208,149,208,135,211,132,213,125,208,
 121">
>>>
>>> It is not clear (to me) from your example what kind of file this is.
>>> Maybe XML, it does not look like GML. readOGR() in the rgdal package
>>> may be a better route to explore, but you need to determine what file
>>> structure is first.
>>>
 any idea welcome,

 sylvain

 (If anayone is interested with that type of data, they're available at
 the INSEE website
>>>
>>> I can not easily find an example on this site. Perhaps you could
>>> provide a direct link to the file. Lastly, I suspect that the
>>> r-sig-geo mailing list would get you some better answers.
>>>
>>> Michael
>>>
>>> --
>>> Michael Denslow
>>>
>>> I.W. Carpenter Jr. Herbarium [BOON]
>>> Department of Biology
>>> Appalachian State University
>>> Boone, North Carolina U.S.A.
>>> -- AND --
>>> Communications Manager
>>> Southeast Regional Network of Expertise and Collections
>>> sernec.org
>>>
>>> 36.214177, -81.681480 +/- 3103 meters
>>>
>>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

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


Re: [R] Loop

2010-03-03 Thread Henrique Dallazuanna
You are using a random function to generate this values(runif).

So, in each replication, the value is not equal.

On Wed, Mar 3, 2010 at 4:50 PM, Val  wrote:
> Thank you  Henrique,
>
> However,
>
> F1<-sum(!findInterval(colMeans(replicate(100, z1(100, 4))), 0.2:0.3))
> F2<-sum(findInterval(colMeans(replicate(100, z1(100, 4))), 0.2:0.3))
>
> the sum of the two (F1+F2) = number of replicates (in this case 100).
> Sometimes I do not  get that sum. Do you know why?
>
> Val
>
>
>
>
>
>
>
>
> On Wed, Mar 3, 2010 at 2:33 PM, Henrique Dallazuanna  wrote:
>> Try this:
>>
>> sum(!findInterval(colMeans(replicate(1000, z1(100, 4))), 0.2:0.3))
>>
>> On Wed, Mar 3, 2010 at 4:15 PM, Val  wrote:
>>> Hi all,
>>>
>>> Assume the following function that generate a random number.
>>>
>>> z1<-function (n, eta)
>>> {
>>>        wv <- runif(n)
>>>        wz <- (-1/eta) * log(wv)
>>>        wz
>>> }
>>> y <- z1(100,4)
>>> mean(y)
>>>
>>>
>>> I want to run this function  say  1000 times and I want to count if
>>> the mean(y) outside the following range 0.20 to 0.30.
>>>
>>> How do I do it in R?
>>>
>>> Thanks in advance
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>>
>> --
>> Henrique Dallazuanna
>> Curitiba-Paraná-Brasil
>> 25° 25' 40" S 49° 16' 22" O
>>
>



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

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


Re: [R] filtering signals per day

2010-03-03 Thread Peter Alspach
Tena koe Anna

The following appears to do what you want (anna is a dataframe
containing the data you provided):

anna$Test <- anna$Signals
anna[duplicated(paste(anna$Dates, anna$Signals)),'Test'] <- 0
anna
  Dates Signals Filtered.Signal Test
1  02-11-06   0   00
2  02-11-06   1   11
3  02-11-06   0   00
4  02-11-06   1   00
5  02-11-06   1   00
6  02-11-06   0   00
7  03-11-06   1   11
8  03-11-06   1   00
9  03-11-06   0   00
10 03-11-06   1   00
11 03-11-06   0   00

HTH 

Peter Alspach

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of anna
> Sent: Thursday, 4 March 2010 8:20 a.m.
> To: r-help@r-project.org
> Subject: [R] filtering signals per day
> 
> 
> Hello R lovers,
> I have a vector of dates and signals. I want to filter the 
> signals per day in a way that only the first signal of the 
> day remains like this:
> Dates   Signals   Filtered Signal
> 2006-11-02 00
> 2006-11-02 11
> 2006-11-02 00 
> 2006-11-02 10
> 2006-11-02 10 
> 2006-11-02 00
> 2006-11-03 11
> 2006-11-03 10 
> 2006-11-03 00
> 2006-11-03 10
> 2006-11-03 00
> 
> The thing is that I want to do it with matrix functions and 
> not doing a loop but I still have no clue even after having 
> spent time on it. Can somebody please help me? thank you!
> 
> 
> 
> -
> Anna Lippel
> --
> View this message in context: 
> http://n4.nabble.com/filtering-signals-per-day-tp1577044p1577044.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

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


Re: [R] filtering signals per day

2010-03-03 Thread Henrique Dallazuanna
Try this:

f$Filtered <- unlist(sapply(unstack(f, Signals ~ Dates),

function(.x)tabulate(which(as.logical(.x))[1], length(.x

On Wed, Mar 3, 2010 at 4:20 PM, anna  wrote:
>
> Hello R lovers,
> I have a vector of dates and signals. I want to filter the signals per day
> in a way that only the first signal of the day remains like this:
> Dates               Signals       Filtered Signal
> 2006-11-02         0                    0
> 2006-11-02         1                    1
> 2006-11-02         0                    0
> 2006-11-02         1                    0
> 2006-11-02         1                    0
> 2006-11-02         0                    0
> 2006-11-03         1                    1
> 2006-11-03         1                    0
> 2006-11-03         0                    0
> 2006-11-03         1                    0
> 2006-11-03         0                    0
>
> The thing is that I want to do it with matrix functions and not doing a loop
> but I still have no clue even after having spent time on it. Can somebody
> please help me? thank you!
>
>
>
> -
> Anna Lippel
> --
> View this message in context: 
> http://n4.nabble.com/filtering-signals-per-day-tp1577044p1577044.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.
>



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

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


Re: [R] filtering signals per day

2010-03-03 Thread anna

ifelse(ave(signals, dates , FUN=cumsum) = 1, 1, 0)
 

-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/filtering-signals-per-day-tp1577044p1577102.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Loop

2010-03-03 Thread Val
Thank you  Henrique,

However,

F1<-sum(!findInterval(colMeans(replicate(100, z1(100, 4))), 0.2:0.3))
F2<-sum(findInterval(colMeans(replicate(100, z1(100, 4))), 0.2:0.3))

the sum of the two (F1+F2) = number of replicates (in this case 100).
Sometimes I do not  get that sum. Do you know why?

Val








On Wed, Mar 3, 2010 at 2:33 PM, Henrique Dallazuanna  wrote:
> Try this:
>
> sum(!findInterval(colMeans(replicate(1000, z1(100, 4))), 0.2:0.3))
>
> On Wed, Mar 3, 2010 at 4:15 PM, Val  wrote:
>> Hi all,
>>
>> Assume the following function that generate a random number.
>>
>> z1<-function (n, eta)
>> {
>>        wv <- runif(n)
>>        wz <- (-1/eta) * log(wv)
>>        wz
>> }
>> y <- z1(100,4)
>> mean(y)
>>
>>
>> I want to run this function  say  1000 times and I want to count if
>> the mean(y) outside the following range 0.20 to 0.30.
>>
>> How do I do it in R?
>>
>> Thanks in advance
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 import map data (maptools?) from a html set of 'coords'

2010-03-03 Thread sylvain willart
SOLVED,

example from the "Nord-Pas-de-Calais" region:


v <- 
c(237,55,236,58,229,57,214,57,203,55,197,54,187,48,179,46,179,35,180,31,184,26,197,23,201,24,202,31,207,34,213,31,216,37,219,41,228,46,234,47,237,55)

seqx <- seq(1,length(v),by=2)
seqy <- seq(2,length(v),by=2)

vx <- c()
for (j in seqx) {
vx <- c(vx,v[j])
  }
vy <- c()
for (j in seqy) {
vy <- c(vy,v[j])
  }
plot(vx,-vy)
polygon(vx,-vy,border="red")


thanks for your tips,

Sylvain
Now, I just have to read it using maptools...

2010/3/3 sylvain willart :
> Hi
> thanks for your reply,
> I'll try to better explain my request...
> the data do not come from a file with a specific extension, this is
> just some lines I copied pasted from a source html file
>
> The web page is:
> http://www.insee.fr/fr/ppp/bases-de-donnees/donnees-detaillees/duicq/accueil.asp
> it displays an (interactive) map of France with all the regions
>
> to access the source: edit/source , or Ctrl+U in a web browser
>
> By the middle of the html source file, there is an html object called
> map ( ... ) with a set of coordinates representing the
> polygons of each region,
>
> These coordinates are just location of points: x1,y1,x2,y2,x3,y3...
> that draw polygons. They are not proper longitude or latitude and
> their "origine" is just the corner of the image the html file
> generates...
>
> I am aware those are not "real" geographic data (That's why I didn't
> post my question to sig-geo, it looks more like a problem of
> graphics), but these are the coordinates one need to "draw" a map (and
> eventually import it to a more specific package like spatstat)
>
> So, what I would like to do is: using those coordinates to draw such a
> map, and eventually use that map for distance or area calculus (which
> do not need to be extremely precise...)
>
> sylvain
>
>
> 2010/3/3 Michael Denslow :
>> Hi Sylvian,
>>
>>
>> On Tue, Mar 2, 2010 at 1:15 PM, sylvain willart
>>  wrote:
>>> Dear R users,
>>>
>>> I would like to draw map and import it in maptools/spatstat packages.
>>>
>>> The 'raw data' I have come from a web page (...) and are
>>> basically a list of coordinates of a polygon.
>>>
>>> I would like to know how to import them in R; I checked the maptools
>>> packages, but all the examples use existing .dbf files.
>>>
>>> I just have a (serie of) text file(s) looking like this:
>>>
>>> For example, for the French Region Burgundy:
>>>
>>> >> alt="Bourgogne"
>>> coords="208,121,211,115,221,113,224,115,225,120,229,122,232,128,251,125,255,
>>> 130,256,136,266,138,268,148,267,154,263,160,267,168,267,180,262,
>>> 175,256,178,254,184,248,184,243,187,237,187,232,185,234,181,227,
>>> 171,216,171,212,166,211,155,208,149,208,135,211,132,213,125,208,
>>> 121">
>>
>> It is not clear (to me) from your example what kind of file this is.
>> Maybe XML, it does not look like GML. readOGR() in the rgdal package
>> may be a better route to explore, but you need to determine what file
>> structure is first.
>>
>>> any idea welcome,
>>>
>>> sylvain
>>>
>>> (If anayone is interested with that type of data, they're available at
>>> the INSEE website
>>
>> I can not easily find an example on this site. Perhaps you could
>> provide a direct link to the file. Lastly, I suspect that the
>> r-sig-geo mailing list would get you some better answers.
>>
>> Michael
>>
>> --
>> Michael Denslow
>>
>> I.W. Carpenter Jr. Herbarium [BOON]
>> Department of Biology
>> Appalachian State University
>> Boone, North Carolina U.S.A.
>> -- AND --
>> Communications Manager
>> Southeast Regional Network of Expertise and Collections
>> sernec.org
>>
>> 36.214177, -81.681480 +/- 3103 meters
>>
>

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


Re: [R] Loop

2010-03-03 Thread Henrique Dallazuanna
Try this:

sum(!findInterval(colMeans(replicate(1000, z1(100, 4))), 0.2:0.3))

On Wed, Mar 3, 2010 at 4:15 PM, Val  wrote:
> Hi all,
>
> Assume the following function that generate a random number.
>
> z1<-function (n, eta)
> {
>        wv <- runif(n)
>        wz <- (-1/eta) * log(wv)
>        wz
> }
> y <- z1(100,4)
> mean(y)
>
>
> I want to run this function  say  1000 times and I want to count if
> the mean(y) outside the following range 0.20 to 0.30.
>
> How do I do it in R?
>
> Thanks in advance
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

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

2010-03-03 Thread anna

Hello R lovers,
I have a vector of dates and signals. I want to filter the signals per day
in a way that only the first signal of the day remains like this:
Dates   Signals   Filtered Signal
2006-11-02 00
2006-11-02 11
2006-11-02 00 
2006-11-02 10
2006-11-02 10 
2006-11-02 00
2006-11-03 11
2006-11-03 10 
2006-11-03 00
2006-11-03 10
2006-11-03 00

The thing is that I want to do it with matrix functions and not doing a loop
but I still have no clue even after having spent time on it. Can somebody
please help me? thank you!



-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/filtering-signals-per-day-tp1577044p1577044.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] Working with combinations

2010-03-03 Thread Herm Walsh
Thanks David for the thoughts.  The challenge I have with this approach is that 
the criteria I have is defined by a series of tests--which I do not think I 
could substitute in in place of the logical indexing.

In the combinations code I was hoping there is a step where, each new 
combination is added to the current list of combinations.  If this were the 
case, I could put my series of tests in the code right there and then store the 
combination if appropriate.

However, evalutating the code--which uses recursion--I am not sure if this 
approach will work.  The combinations code is listed below.  Is there a simple 
place(s) where I could insert my tests, operating on the current combination?

function (n, r, v = 1:n, set = TRUE, repeats.allowed = FALSE) 
{
    if (mode(n) != "numeric" || length(n) != 1 || n < 1 || (n%%1) != 
    0) 
    stop("bad value of n")
    if (mode(r) != "numeric" || length(r) != 1 || r < 1 || (r%%1) != 
    0) 
    stop("bad value of r")
    if (!is.atomic(v) || length(v) < n) 
    stop("v is either non-atomic or too short")
    if ((r > n) & repeats.allowed == FALSE) 
    stop("r > n and repeats.allowed=FALSE")
    if (set) {
    v <- unique(sort(v))
    if (length(v) < n) 
    stop("too few different elements")
    }
    v0 <- vector(mode(v), 0)
    if (repeats.allowed) 
    sub <- function(n, r, v) {
    if (r == 0) 
    v0
    else if (r == 1) 
    matrix(v, n, 1)
    else if (n == 1) 
    matrix(v, 1, r)
    else rbind(cbind(v[1], Recall(n, r - 1, v)), Recall(n - 
    1, r, v[-1]))
    }
    else sub <- function(n, r, v) {
    if (r == 0) 
    v0
    else if (r == 1) 
    matrix(v, n, 1)
    else if (r == n) 
    matrix(v, 1, n)
    else rbind(cbind(v[1], Recall(n - 1, r - 1, v[-1])), 
    Recall(n - 1, r, v[-1]))
    }
    sub(n, r, v[1:n])
}




**

> I am working with the combinations function (available in the gtools 
> package).  However, rather than store all of the possible combinations I 
> would like to check each combination to see if it meets a certain criteria.  
> If it does, I will then store it.
> 
> I have looked at the combinations code but am unsure where in the algorithm I 
> would be able to operate on each combination.

Logical indexing:

> combinations(3,2,letters[1:3])[,1]=="a"
[1]  TRUE  TRUE FALSE

> combinations(3,2,letters[1:3])[ combinations(3,2,letters[1:3])[,1]=="a", ]
    [,1] [,2]
[1,] "a"  "b"
[2,] "a"  "c"

--David 



  
[[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] filtering signals per day

2010-03-03 Thread anna

May doing a cumsum restricted on each date could help, I remember I read
someone doing this on a post...because once  i do this i will be able to
discriminate the numbers different from 1.

-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/filtering-signals-per-day-tp1577044p1577048.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] End of line marker?

2010-03-03 Thread jonas garcia
Dear R users,

I am trying to read a huge file in R. For some reason, only a part of the
file is read. When I further investigated, I found that in one of my
non-numeric columns, there is one odd character responsible for this, which
I reproduce bellow:

In case you cannot see it, it looks like a right arrow, but it is not the
one you get from microsoft word in menu "insert symbol".

I think my dat file is broken and that funny character is an EOL marker that
makes R not read the rest of the file. I am sure the character is there by
chance but I fear that it might be present in some other big files I have to
work with as well. So, is there any clever way to remove this inconvenient
character in R avoiding having to edit the file in notepad and remove it
manually?

 Code I am using:

read.csv("new3.dat", header=F)

Warning message:
In read.table(file = file, header = header, sep = sep, quote = quote,  :
  incomplete final line found by readTableHeader on 'new3.dat'

I am working with R 2.10.1 in windows XP.

Thanks in advance

Jonas

[[alternative HTML version deleted]]

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


[R] How to calculate Eigen values from LDA object

2010-03-03 Thread Robert Lonsinger
Can anybody explain to me how to calculate Eigen values for linear
discriminants, which have been identified in the scaling matrix of a LDA
analysis [lda()].

cheers
~~
Robert Lonsinger
Wildlife Grad. Research Assistant
New Mexico State University
Dept. of Fish, Wildlife, & Cons. Ecology
rob.lonsin...@gmail.com
484.459.1977
~~

[[alternative HTML version deleted]]

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


[R] Loop

2010-03-03 Thread Val
Hi all,

Assume the following function that generate a random number.

z1<-function (n, eta)
{
wv <- runif(n)
wz <- (-1/eta) * log(wv)
wz
}
y <- z1(100,4)
mean(y)


I want to run this function  say  1000 times and I want to count if
the mean(y) outside the following range 0.20 to 0.30.

How do I do it in R?

Thanks in advance

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


Re: [R] Three most useful R package

2010-03-03 Thread Greg Snow
I find myself loading the TeachingDemos package most often, though in my case 
there may be one of those chicken/egg things going on.

I also use MASS and rms quite a bit (if we are limited to 3, but I also use 
survival, Hmisc, and splines, but they are loaded with rms).

The package that I really want a copy of is the esp package.  This would allow 
the computer to do the analysis that I want without me actually having to give 
it the details, allow me to do the analysis that my client actually wants 
without wasting time by first doing the analysis that they told me they want, 
and answer questions from posters who do not give any of the details asked for 
in the posting guide.

I also want a package that when people misuse certain functions/techniques it 
will cause a small door on the side of their monitor/computer to open and a 
mechanical hand will come out and slap them upside the head.  But that package 
will not be useful until the hardware support is available.

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


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Ralf B
> Sent: Tuesday, March 02, 2010 1:14 PM
> To: r-help@r-project.org
> Subject: [R] Three most useful R package
> 
> Hi R-fans,
> 
> I would like put out a question to all R users on this list and hope
> it will create some feedback and discussion.
> 
> 1) What are your 3 most useful R package? and
> 
> 2) What R package do you still miss and why do you think it would make
> a useful addition?
> 
> Pulling answers together for these questions will serve as a guide for
> new users and help people who just want to get a hint where to look
> first. Happy replying!
> 
> Best,
> Ralf
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] two questions for R beginners

2010-03-03 Thread William Dunlap
If R made
   matrix$columnName
mean the same as
   matrix[, "columnName"]
(a vector) so matrices looked more like data.frames,
would we also want the following to work
as they do with data.frames?
   with(matrix, log(columnName)) # log of that column as a vector
   matrix["columnName"] # 1-column matrix
   matrix[["columnName"]] # vector equivalent of that 1-column matrix 
   lm(responseColumn~predictorColumn, data=matrix)
   eval(quote(columnName), envir=matrix)
The last 2 bump into the rule allowing envir to be
a frame number (since a 1x1 matrix is currently taken
as the frame number now).

Perhaps the print methods for data.frame and matrix
should announce the class of the object being printed.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Patrick Burns
> Sent: Wednesday, March 03, 2010 2:44 AM
> To: r-help@r-project.org
> Subject: Re: [R] two questions for R beginners
> 
> I think Duncan's example of a list that is
> a matrix is a compelling argument not to do
> the change.
> 
> A matrix that is a list with both names and
> dimnames *is* probably rare (but certainly
> imaginable).  A matrix that is a list is not
> so rare, and the proposed double meaning of
> '$' would certainly be confusing in that case.
> 
> Pat
> 
> 
> On 02/03/2010 17:55, Duncan Murdoch wrote:
> > On 02/03/2010 11:53 AM, William Dunlap wrote:
> >> > -Original Message-
> >> > From: r-help-boun...@r-project.org >
> >> [mailto:r-help-boun...@r-project.org] On Behalf Of John Sorkin
> >> > Sent: Tuesday, March 02, 2010 3:46 AM
> >> > To: Karl Ove Hufthammer; r-h...@stat.math.ethz.ch
> >> > Subject: Re: [R] two questions for R beginners
> >> > > Please take what follows not as an ad hominem statement, but >
> >> rather as an attempt to improve what is already an excellent >
> >> program, that has been built as a result of many, many hours > of
> >> dedicated work by many, many unpaid, unsung volunteers.
> >> > > It troubles me a bit that when a confusing aspect of R is >
> >> pointed out the response is not to try to improve the > 
> language so as
> >> to avoid the confusion, but rather to state > that the confusion is
> >> inherent in the language. I understand > that to make changes that
> >> would avoid the confusing aspect of > the language that has been
> >> discussed in this thread would > take time and effort by 
> an R wizard
> >> (which I am not), time > and effort that would not be 
> compensated in
> >> the traditional > sense. This does not mean that we should not
> >> acknowledge the > confusion. If we what R to be the de facto lingua
> >> franca of > statistical analysis doesn't it make sense to 
> strive for >
> >> syntax that is as straight forward and consistent as possible?
> >> Whenever one changes the language that way old code
> >> will break.
> > I think in this case not much code would break. Mostly when 
> people have
> > a matrix M and ask for M$column they'll get an error; the 
> proposal is
> > that they'll get the requested column. (It is possible to 
> have a list
> > with names that is also a matrix with dimnames, but I think 
> that is a
> > pretty unusual construction.) But I haven't been convinced that the
> > proposal is a net improvement to the language.
> > Duncan Murdoch
> >
> >> The developers can, with a lot of effort,
> >> fix their own code, and perhaps even user-written code
> >> on CRAN, but code that thousands of users have written
> >> will break. There is a lot of code out there that was
> >> written by trial and error and by folks who no longer
> >> work at an institution: the code works but no one knows
> >> exactly why it works. Telling folks they need to change
> >> that code because we have a cleaner but different syntax
> >> now is not good. Why would one spend time writing a
> >> package that might stop working when R is "upgraded"?
> >>
> >> I think the solution is not to change current semantics
> >> but to write functions that behave better and encourage
> >> users to use them, gradually abandoning the old constructs.
> >>
> >> Bill Dunlap
> >> Spotfire, TIBCO Software
> >> wdunlap tibco.com
> >> > > Again, please understand that my comment is made with deepest >
> >> respect for the many people who have unselfishly 
> contributed > to the
> >> R project. Many thanks to each and every one of you.
> >> > > John
> >> > > > >>> Karl Ove Hufthammer  3/2/2010 
> 4:00 AM >>>
> >> > On Mon, 01 Mar 2010 10:00:07 -0500 Duncan Murdoch >
> >>  > wrote:
> >> > > Suppose X is a dataframe or a matrix. What would you > 
> expect to
> >> get from > > X[1]? What about as.vector(X), or as.numeric(X)?
> >> > > All this of course depends on type of object one is 
> speaking > of.
> >> There > are plenty of surprises available, and it's best 
> to use the >
> >> most logical > way of extracting. E.g., to extract the top-left
> >> element of a 2D > structure (data 

Re: [R] R beginner

2010-03-03 Thread Dieter Menne


azman wrote:
> 
> i'am is new in R software.i have try to make a function but it can't give
> what it should.i dunno what have to do next.
> Can somebody help me to solve it.i'll very appreciate...
> 
> 

Your example is nice, because it is self-contained (even if there is a
buglet). When I run it, I got a message that "object  y1 is not found". That
comes from a line

if (y1<=0) ...

which suspiciously looks like a remainder of an old version that ended up at
the wrong place. Remove this, and also remove two {} below it which do no
harm, but are confusing. Program looked reasonably after this. I also
recommend to use good indentation, but it is possible that is has been
removed by the mailer.

If you are lost again by an error message from a deeply nested call: use

traceback()

immediately after the message.

Dieter




-- 
View this message in context: 
http://n4.nabble.com/R-beginner-tp1576033p1576971.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] Three most useful R package

2010-03-03 Thread Matthew Dowle
Dieter,

One way to check if a package is active, is by looking on r-forge. If you 
are referring to data.table you would have found it is actually very active 
at the moment and is far from abandoned.

What you may be referring to is a warning, not an error, with v1.2 on 
R2.10+.  That was fixed many moons ago. The r-forge version is where its at.

Rather than commenting in public about a warning on a package, and making a 
conclusion about its abandonment, and doing this without copying the 
maintainer, perhaps you could have contacted the maintainer to let him know 
you had found a problem.  That would have been a more community spirited 
action to take.  Doing that at the time you found out would have been 
helpful too rather than saving it up for now.  Or you can always check the 
svn logs yourself,  as the r-forge guys even made that trivial to do.

All,

Can we please now stop this thread ?  The crantastic people worked hard to 
provide a better solution.  If the community refuses to use crantastic, 
thats up to the community, but to start now filling up r-help with votes on 
packages when so much effort was put in to a much much better solution ages 
ago?  Its as quick to put your votes into crantastic as it is to write to 
r-help.  What your problem, folks, with crantastic?   The second reply 
mentioned crantastic but you all chose to ignore it,  it seems.  If you want 
to vote, use crantastic.  If you don't want to vote,  don't vote.  But using 
r-help to vote ?!  The better solution is right there: 
http://crantastic.org/

Matthew


"Dieter Menne"  wrote in message 
news:1267626882999-1576618.p...@n4.nabble.com...
>
>
> Rob Forler wrote:
>>
>> And data.table because it does aggregation about 50x times faster than
>> plyr
>> (which I used to use a lot).
>>
>>
>
> This is correct, from the error message its spits out one has to conclude
> that is was abandoned at R-version 2.4.x
>
> Dieter
>
>
>
>
> -- 
> View this message in context: 
> http://n4.nabble.com/Three-most-useful-R-package-tp1575671p1576618.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] Three most useful R package

2010-03-03 Thread Juliet Hannah
I use rms, lme4, ggplot2 frequently (also lattice and MASS).

On Tue, Mar 2, 2010 at 3:13 PM, Ralf B  wrote:
> Hi R-fans,
>
> I would like put out a question to all R users on this list and hope
> it will create some feedback and discussion.
>
> 1) What are your 3 most useful R package? and
>
> 2) What R package do you still miss and why do you think it would make
> a useful addition?
>
> Pulling answers together for these questions will serve as a guide for
> new users and help people who just want to get a hint where to look
> first. Happy replying!
>
> Best,
> Ralf
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] sem package and growth curves

2010-03-03 Thread Daniel Nordlund
Chuck and John,

Thank you both for your help.  I figured that my problem was trying to work 
through a new area for me, and trying to learn a new package for that area at 
the same time.  You have both provided examples that clarified things that I 
either didn't understand about SEM in general or had overlooked in the 
documentation for the sem package.

Again, this has been very helpful,

Dan 


Daniel Nordlund
Bothell, WA USA
 

> -Original Message-
> From: John Fox [mailto:j...@mcmaster.ca]
> Sent: Wednesday, March 03, 2010 7:19 AM
> To: 'Chuck Cleland'; 'Daniel Nordlund'
> Cc: 'r-help'
> Subject: RE: [R] sem package and growth curves
> 
> Dear Chuck and Daniel,
> 
> First, thanks Chuck for fielding the question, which I didn't notice in
> r-help.
> 
> I can get solutions for models A, B, and C using the automatic start
> values
> along with the argument par.size="startvalues" to sem() (as recommended in
> ?sem if there are convergence problems). For example, for Model A:
> 
>  snip -
> 
> > modA <- specify.model()
> 1: I -> ALC1, NA, 1
> 2: I -> ALC2, NA, 1
> 3: I -> ALC3, NA, 1
> 4: S -> ALC1, NA, 0
> 5: S -> ALC2, NA, 0.75
> 6: S -> ALC3, NA, 1.75
> 7: UNIT -> I, Mi, NA
> 8: UNIT -> S, Ms, NA
> 9: I <-> I, Vi, NA
> 10: S <-> S, Vs, NA
> 11: I <-> S, Cis, NA
> 12: ALC1 <-> ALC1, Vd1, NA
> 13: ALC2 <-> ALC2, Vd2, NA
> 14: ALC3 <-> ALC3, Vd3, NA
> 15:
> Read 14 records
> > sem.modA <- sem(modA, alc2.modA.raw, 1122, fixed.x="UNIT",
> par.size="startvalues", raw=TRUE)
> >
> > summary(sem.modA)
> 
> Model fit to raw moment matrix.
> 
>  Model Chisquare =  0.048207   Df =  1 Pr(>Chisq) = 0.82621
>  BIC =  -6.9747
> 
>  Normalized Residuals
> Min.  1st Qu.   Median Mean  3rd Qu. Max.
> -0.04050 -0.03790 -0.01600  0.00603  0.03200  0.09620
> 
>  Parameter Estimates
> Estimate  Std Error z value Pr(>|z|)
> Mi   0.225625 0.0106901 21.1059 0.e+00 I <--- UNIT
> Ms   0.035978 0.0073456  4.8979 9.6865e-07 S <--- UNIT
> Vi   0.087039 0.0071035 12.2530 0.e+00 I <--> I
> Vs   0.019764 0.0052178  3.7877 1.5205e-04 S <--> S
> Cis -0.012476 0.0045780 -2.7251 6.4282e-03 S <--> I
> Vd1  0.048428 0.0064146  7.5495 4.3743e-14 ALC1 <--> ALC1
> Vd2  0.075702 0.0044403 17.0488 0.e+00 ALC2 <--> ALC2
> Vd3  0.076698 0.0098901  7.7551 8.8818e-15 ALC3 <--> ALC3
> 
>  Iterations =  57
> 
>  snip -
> 
> Model D converges with the default setting of par.size:
> 
>  snip -
> 
> > alc2.modD.raw <- raw.moments(subset(alc2,
> + select=c('PEER1','PEER2','PEER3','ALC1','ALC2','ALC3','UNIT')))
> >
> > modD <- specify.model()
> 1: Ia -> ALC1, NA, 1
> 2: Ia -> ALC2, NA, 1
> 3: Ia -> ALC3, NA, 1
> 4: Sa -> ALC1, NA, 0
> 5: Sa -> ALC2, NA, 0.75
> 6: Sa -> ALC3, NA, 1.75
> 7: UNIT -> Ia, Mia, NA
> 8: UNIT -> Sa, Msa, NA
> 9: Ip -> PEER1, NA, 1
> 10: Ip -> PEER2, NA, 1
> 11: Ip -> PEER3, NA, 1
> 12: Sp -> PEER1, NA, 0
> 13: Sp -> PEER2, NA, 0.75
> 14: Sp -> PEER3, NA, 1.75
> 15: Ip -> Ia, B1, NA
> 16: Sp -> Ia, B2, NA
> 17: Ip -> Sa, B3, NA
> 18: Sp -> Sa, B4, NA
> 19: UNIT -> Ip, Mip, NA
> 20: UNIT -> Sp, Msp, NA
> 21: Ia <-> Ia, Via, NA
> 22: Sa <-> Sa, Vsa, NA
> 23: Ia <-> Sa, Cisa, NA
> 24: Ip <-> Ip, Vip, NA
> 25: Sp <-> Sp, Vsp, NA
> 26: Ip <-> Sp, Cisp, NA
> 27: ALC1 <-> ALC1, Vd1, NA
> 28: ALC2 <-> ALC2, Vd2, NA
> 29: ALC3 <-> ALC3, Vd3, NA
> 30: PEER1 <-> PEER1, Vd4, NA
> 31: PEER2 <-> PEER2, Vd5, NA
> 32: PEER3 <-> PEER3, Vd6, NA
> 33: ALC1 <-> PEER1, Cd1, NA
> 34: ALC2 <-> PEER2, Cd2, NA
> 35: ALC3 <-> PEER3, Cd3, NA
> 36:
> Read 35 records
> > sem.modD <- sem(modD, alc2.modD.raw, 1122, fixed.x=c("UNIT"), raw=TRUE)
> > summary(sem.modD)
> 
> Model fit to raw moment matrix.
> 
>  Model Chisquare =  11.557   Df =  4 Pr(>Chisq) = 0.020967
>  BIC =  -16.534
> 
>  Normalized Residuals
> Min.  1st Qu.   Median Mean  3rd Qu. Max.
> -0.91500 -0.39200  0.00105  0.09760  0.39900  1.61000
> 
>  Parameter Estimates
>  Estimate   Std Error z value  Pr(>|z|)
> Mia   0.0666214 0.0156727  4.25079 2.1302e-05 Ia <--- UNIT
> Msa   0.0083040 0.0147616  0.56254 5.7375e-01 Sa <--- UNIT
> B10.7985829 0.1028010  7.76824 7.9936e-15 Ia <--- Ip
> B20.0804315 0.1840470  0.43702 6.6210e-01 Ia <--- Sp
> B3   -0.1433386 0.0762547 -1.87973 6.0144e-02 Sa <--- Ip
> B40.5766956 0.1938673  2.97469 2.9328e-03 Sa <--- Sp
> Mip   0.1881743 0.0119530 15.74285 0.e+00 Ip <--- UNIT
> Msp   0.0961698 0.0096929  9.92167 0.e+00 Sp <--- UNIT
> Via   0.0421656 0.0074640  5.64920 1.6120e-08 Ia <--> Ia
> Vsa   0.0092181 0.0054564  1.68941 9.1140e-02 Sa <--> Sa
> Cisa -0.0063651 0.0051128 -1.24492 2.1316e-01 Sa <--> Ia
> Vip   0.0696837 0.0103795  6.71357 1.8991e-11 Ip <--> Ip
> Vsp   0.0284726 0.0089274  3.18936 1.4259e-03 Sp <--> Sp
> Cisp  0.0011771 0.0071251  0.16521 8.6878e-01 Sp <--> Ip
> Vd1   0.0480379 0.0063780  7.53177 4.9960e-14 ALC1 <--> ALC1
> Vd2   0.0762156 0.0044523 17.11821 0.e+00 ALC2 <--> ALC2
> Vd3   0.0762794 0.0097763  7.80249 5.9952e-15 ALC

Re: [R] Three most useful R package

2010-03-03 Thread Ralf B
Correct.

Ralf

---
Ralf Bierig
Post-Doctoral Associate
School of Communication and Information
Rutgers University
New Brunswick, NJ 08901-1071, USA



On Wed, Mar 3, 2010 at 4:16 AM, Philippe Grosjean
 wrote:
>
>
> On 03/03/10 09:26, Karl Ove Hufthammer wrote:
>>
>> On Tue, 2 Mar 2010 15:13:54 -0500 Ralf B  wrote:
>>>
>>> 1) What are your 3 most useful R package? and
>>
>> plyr
>> ggplot2
>> lattice
>>
>
> Well, as you ask the question, the three most useful R packages         are:
> base, stats and methods ;-) ... But I guess you mean: the three most useful
> OPTIONAL packages?
> Best,
>
> Philippe Grosjean
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] help R IRT simulation

2010-03-03 Thread Doran, Harold
The simRasch function in MiscPsycho package simulates person abilities using 
N(mu, sigma^2) and items from U(-x,x), which is not what you're asking for. 
But, I also am not sure how you would manipulate the other moments. However, 
item parameters tend not to be normally distributed in operational testing 
programs, so I am curious why one would do so.

Also, Rasch people really don't like to assume persons abilities are normally 
distributed. The JML procedures makes no assumptions about the shape of either 
distribution (persons, items) and MML procedures for Rasch tend to use 
non-parametric methods so you don't have assume an N(0, sigma^2) for the 
population distribution.

Of course, you can use N(0, sigma^2) for the population distribution for rasch 
in an MML procedure (or you can also use N(0,1) if you estimate a common 
slope), but the rasch community tends to not prefer this approach.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Stuart Luppescu
Sent: Wednesday, March 03, 2010 12:05 PM
To: Helen Lisman
Cc: r-help@r-project.org
Subject: Re: [R] help R IRT simulation

On Wed, 2010-03-03 at 09:45 -0600, Helen Lisman wrote:
> hello R,
> This is about simulation in psychomtrics in IRT in R. I want to simulate b
> parameters(item difficulty) with moments of fixed values of mean, st.d,
> skewness and kurtosis. Is there any specific IRT package in R with those
> functions to control those moments? I have seen other programs that can
> control mean and st.d but not skewness and kurtosis.

Interesting. I wrote a program in C to simulate item responses according
to the Rasch model, as well as the 2PL and 3PL models. I used either
normal or uniform distribution of the person and item parameters. I'm
assuming that you want to manipulate the skewness and kurtosis of the
generated item and/or person parameters, and then produce simulated item
responses. I don't know how you would manipulate the skewness and
kurtosis. I searched around and rnorm() doesn't include arguments for
skewness and kurtosis. kurtosis() functions exist in e1071 and
fUtilities, but they only return the kurtosis of the input data. Let me
know if you find something.
-- 
Stuart Luppescu 
University of Chicago

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

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


Re: [R] help R IRT simulation

2010-03-03 Thread Dimitris Rizopoulos
to simulate from IRT models have a look at function rmvlogis() from 
package ltm.



I hope it helps.

Best,
Dimitris


On 3/3/2010 6:05 PM, Stuart Luppescu wrote:

On Wed, 2010-03-03 at 09:45 -0600, Helen Lisman wrote:

hello R,
This is about simulation in psychomtrics in IRT in R. I want to simulate b
parameters(item difficulty) with moments of fixed values of mean, st.d,
skewness and kurtosis. Is there any specific IRT package in R with those
functions to control those moments? I have seen other programs that can
control mean and st.d but not skewness and kurtosis.


Interesting. I wrote a program in C to simulate item responses according
to the Rasch model, as well as the 2PL and 3PL models. I used either
normal or uniform distribution of the person and item parameters. I'm
assuming that you want to manipulate the skewness and kurtosis of the
generated item and/or person parameters, and then produce simulated item
responses. I don't know how you would manipulate the skewness and
kurtosis. I searched around and rnorm() doesn't include arguments for
skewness and kurtosis. kurtosis() functions exist in e1071 and
fUtilities, but they only return the kurtosis of the input data. Let me
know if you find something.


--
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] help R IRT simulation

2010-03-03 Thread Stuart Luppescu
On Wed, 2010-03-03 at 09:45 -0600, Helen Lisman wrote:
> hello R,
> This is about simulation in psychomtrics in IRT in R. I want to simulate b
> parameters(item difficulty) with moments of fixed values of mean, st.d,
> skewness and kurtosis. Is there any specific IRT package in R with those
> functions to control those moments? I have seen other programs that can
> control mean and st.d but not skewness and kurtosis.

Interesting. I wrote a program in C to simulate item responses according
to the Rasch model, as well as the 2PL and 3PL models. I used either
normal or uniform distribution of the person and item parameters. I'm
assuming that you want to manipulate the skewness and kurtosis of the
generated item and/or person parameters, and then produce simulated item
responses. I don't know how you would manipulate the skewness and
kurtosis. I searched around and rnorm() doesn't include arguments for
skewness and kurtosis. kurtosis() functions exist in e1071 and
fUtilities, but they only return the kurtosis of the input data. Let me
know if you find something.
-- 
Stuart Luppescu 
University of Chicago

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


Re: [R] somebody help me about this error message...

2010-03-03 Thread Greg Snow
Others answered your question.  I would however suggest that you asked the 
wrong question.

If you really feel the need for your future self to serve some serious penance 
for past or near future misdeeds, then continuing with this strategy is one way 
to do that (just please don't inflict your suffering on us when this ends up 
causing more problems than it solves).

If on the other hand, you want to avoid future headaches and become a better 
programmer, then learn to use lists rather than global variables.

a <- list()
for( i in 1:5 ) {
 a[[ paste('a',i,sep="") ]] <- 1:i
### or simpler a[[i]] <- 1:i
}

If you use the simpler version, then you could still get the names by:
names(a) <- paste('a', 1:5, sep="")

Then

a[[2]] <- 4
a[['a2']] <- 4
a$a2 <- 4
a <- within(a, a2<-4)

will all do the substitutions.

See the help for the within and with functions as well as fortune(236) and the 
last few lines of FAQ 7.21.


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


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Joseph Lee
> Sent: Friday, February 26, 2010 10:14 PM
> To: r-help@r-project.org
> Subject: [R] somebody help me about this error message...
> 
> 
> I created variables automatically like this way
> 
> for(i in 1:5){
>   nam <- paste("a",i,sep="")
>   assign(nam,1:i)
> }
> 
> and then, i want to insert a new data into "a2" variable. so, i did
> next
> sentence
> 
> paste("a",2,sep="") <- 4
> 
> so, i got this error message
> 
> Error in get(paste("a", 2, sep = ""))[1] <- 4 :
>   target of assignment expands to non-language object
> 
> anyone knows abou this error message and tell me how to solve thie
> problem,
> please..
> --
> View this message in context: http://n4.nabble.com/somebody-help-me-
> about-this-error-message-tp1571700p1571700.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Issue with length limit in write.table

2010-03-03 Thread alexia

Hi,

I have an issue with the write.table command:

I have a dataset, with many rows and 3 columns. I give a row example:

"alexia""roger","delphine"  "roger","bruno","sandra"

I fist process the data to be able to process the column entries as vectors:

mo<-readLines("c:\\data.txt",n=-1)
ms<-sapply(1:150,function(i) strsplit(mo[i],"\t"))
texts1<-unlist(lapply(1:150,function(i) ms[[i]][c(1)]))
texts2<-unlist(lapply(1:150,function(i) ms[[i]][c(2)]))
texts3<-unlist(lapply(1:150,function(i) ms[[i]][c(3)]))
texts<-cbind(texts1,texts2,texts3)
t<-matrix(texts,ncol=3)
y<-matrix(lapply(parse(text=paste("c(", t, ")")), eval), ncol=ncol(t))

Up to then, everything is fine. Then I compare column vectors to compute
common elements:

z <- cbind(y, "A-B"=apply(y, 1, function(ab) setdiff(ab[[2]], ab[[3]])))
a <- cbind(z, "A-B"=apply(z, 1, function(ab) setdiff(ab[[3]], ab[[2]])))
b <- cbind(a, "A-B"=apply(a, 1, function(ab) intersect(ab[[3]], ab[[2]])))
c<-lapply(b[,4],length)
d<-lapply(b[,5],length)
e<-lapply(b[,6],length)
f <- cbind(b, c, d, e)

Up to now, no problem.

It is when I write the following command that things go wrong:

write.table(f,"c:\\dataprocessed.txt", sep="\t")

At this point, columns entries are truncated at the 35th element. This means
that if I have 50 names in column 2 of row 36, then the .txt file only gives
the first 35.

Is there a way to solve this?

Thanks,

Alexia
-- 
View this message in context: 
http://n4.nabble.com/Issue-with-length-limit-in-write-table-tp1576863p1576863.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] Subset using partial values

2010-03-03 Thread Henrique Dallazuanna
What is your entire dataset and the code used to do this?

On Wed, Mar 3, 2010 at 12:04 PM, Newbie19_02  wrote:
>
> Thanks again for the help but what I am having trouble with is that I get:
>
> 1012  CAO0103166     01/04/1999           I200
> 1016  CAO0103166     03/05/2000           I200
> 1024  CAO0103166     20/06/1997           I209
> 1025  CAO0103166     25/02/1999           I209
> 1027  CAO0103166     27/08/1999           I200
> 1058  CAO0107171     11/01/2002           N411
> 1104  CAO0113512     14/02/2003           I209
>
>
> I'm trying to avoid getting N411?
>
> Thanks,
> Natalie
> --
> View this message in context: 
> http://n4.nabble.com/Subset-using-partial-values-tp1576614p1576683.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.
>



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

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


Re: [R] sem package and growth curves

2010-03-03 Thread Chuck Cleland
Dear John,

  Thanks very much for your message.  I should have looked at the help
page for sem() more closely.  Thanks again for your excellent work on
the package.

Regards,

Chuck

On 3/3/2010 10:18 AM, John Fox wrote:
> Dear Chuck and Daniel,
> 
> First, thanks Chuck for fielding the question, which I didn't notice in
> r-help.
> 
> I can get solutions for models A, B, and C using the automatic start values
> along with the argument par.size="startvalues" to sem() (as recommended in
> ?sem if there are convergence problems). For example, for Model A:
> 
>  snip -
> 
>> modA <- specify.model()
> 1: I -> ALC1, NA, 1
> 2: I -> ALC2, NA, 1
> 3: I -> ALC3, NA, 1
> 4: S -> ALC1, NA, 0
> 5: S -> ALC2, NA, 0.75
> 6: S -> ALC3, NA, 1.75
> 7: UNIT -> I, Mi, NA
> 8: UNIT -> S, Ms, NA
> 9: I <-> I, Vi, NA
> 10: S <-> S, Vs, NA
> 11: I <-> S, Cis, NA
> 12: ALC1 <-> ALC1, Vd1, NA
> 13: ALC2 <-> ALC2, Vd2, NA
> 14: ALC3 <-> ALC3, Vd3, NA
> 15: 
> Read 14 records
>> sem.modA <- sem(modA, alc2.modA.raw, 1122, fixed.x="UNIT",
> par.size="startvalues", raw=TRUE)
>> summary(sem.modA)
> 
> Model fit to raw moment matrix.
> 
>  Model Chisquare =  0.048207   Df =  1 Pr(>Chisq) = 0.82621
>  BIC =  -6.9747 
> 
>  Normalized Residuals
> Min.  1st Qu.   Median Mean  3rd Qu. Max. 
> -0.04050 -0.03790 -0.01600  0.00603  0.03200  0.09620 
> 
>  Parameter Estimates
> Estimate  Std Error z value Pr(>|z|) 
> Mi   0.225625 0.0106901 21.1059 0.e+00 I <--- UNIT   
> Ms   0.035978 0.0073456  4.8979 9.6865e-07 S <--- UNIT   
> Vi   0.087039 0.0071035 12.2530 0.e+00 I <--> I  
> Vs   0.019764 0.0052178  3.7877 1.5205e-04 S <--> S  
> Cis -0.012476 0.0045780 -2.7251 6.4282e-03 S <--> I  
> Vd1  0.048428 0.0064146  7.5495 4.3743e-14 ALC1 <--> ALC1
> Vd2  0.075702 0.0044403 17.0488 0.e+00 ALC2 <--> ALC2
> Vd3  0.076698 0.0098901  7.7551 8.8818e-15 ALC3 <--> ALC3
> 
>  Iterations =  57 
> 
>  snip -
> 
> Model D converges with the default setting of par.size:
> 
>  snip -
> 
>> alc2.modD.raw <- raw.moments(subset(alc2,
> + select=c('PEER1','PEER2','PEER3','ALC1','ALC2','ALC3','UNIT')))
>> modD <- specify.model()
> 1: Ia -> ALC1, NA, 1
> 2: Ia -> ALC2, NA, 1
> 3: Ia -> ALC3, NA, 1
> 4: Sa -> ALC1, NA, 0
> 5: Sa -> ALC2, NA, 0.75
> 6: Sa -> ALC3, NA, 1.75
> 7: UNIT -> Ia, Mia, NA
> 8: UNIT -> Sa, Msa, NA
> 9: Ip -> PEER1, NA, 1
> 10: Ip -> PEER2, NA, 1
> 11: Ip -> PEER3, NA, 1
> 12: Sp -> PEER1, NA, 0
> 13: Sp -> PEER2, NA, 0.75
> 14: Sp -> PEER3, NA, 1.75
> 15: Ip -> Ia, B1, NA
> 16: Sp -> Ia, B2, NA
> 17: Ip -> Sa, B3, NA
> 18: Sp -> Sa, B4, NA
> 19: UNIT -> Ip, Mip, NA
> 20: UNIT -> Sp, Msp, NA
> 21: Ia <-> Ia, Via, NA
> 22: Sa <-> Sa, Vsa, NA
> 23: Ia <-> Sa, Cisa, NA
> 24: Ip <-> Ip, Vip, NA
> 25: Sp <-> Sp, Vsp, NA
> 26: Ip <-> Sp, Cisp, NA
> 27: ALC1 <-> ALC1, Vd1, NA
> 28: ALC2 <-> ALC2, Vd2, NA
> 29: ALC3 <-> ALC3, Vd3, NA
> 30: PEER1 <-> PEER1, Vd4, NA
> 31: PEER2 <-> PEER2, Vd5, NA
> 32: PEER3 <-> PEER3, Vd6, NA
> 33: ALC1 <-> PEER1, Cd1, NA
> 34: ALC2 <-> PEER2, Cd2, NA
> 35: ALC3 <-> PEER3, Cd3, NA
> 36: 
> Read 35 records
>> sem.modD <- sem(modD, alc2.modD.raw, 1122, fixed.x=c("UNIT"), raw=TRUE)
>> summary(sem.modD)
> 
> Model fit to raw moment matrix.
> 
>  Model Chisquare =  11.557   Df =  4 Pr(>Chisq) = 0.020967
>  BIC =  -16.534 
> 
>  Normalized Residuals
> Min.  1st Qu.   Median Mean  3rd Qu. Max. 
> -0.91500 -0.39200  0.00105  0.09760  0.39900  1.61000 
> 
>  Parameter Estimates
>  Estimate   Std Error z value  Pr(>|z|)   
> Mia   0.0666214 0.0156727  4.25079 2.1302e-05 Ia <--- UNIT
> Msa   0.0083040 0.0147616  0.56254 5.7375e-01 Sa <--- UNIT
> B10.7985829 0.1028010  7.76824 7.9936e-15 Ia <--- Ip  
> B20.0804315 0.1840470  0.43702 6.6210e-01 Ia <--- Sp  
> B3   -0.1433386 0.0762547 -1.87973 6.0144e-02 Sa <--- Ip  
> B40.5766956 0.1938673  2.97469 2.9328e-03 Sa <--- Sp  
> Mip   0.1881743 0.0119530 15.74285 0.e+00 Ip <--- UNIT
> Msp   0.0961698 0.0096929  9.92167 0.e+00 Sp <--- UNIT
> Via   0.0421656 0.0074640  5.64920 1.6120e-08 Ia <--> Ia  
> Vsa   0.0092181 0.0054564  1.68941 9.1140e-02 Sa <--> Sa  
> Cisa -0.0063651 0.0051128 -1.24492 2.1316e-01 Sa <--> Ia  
> Vip   0.0696837 0.0103795  6.71357 1.8991e-11 Ip <--> Ip  
> Vsp   0.0284726 0.0089274  3.18936 1.4259e-03 Sp <--> Sp  
> Cisp  0.0011771 0.0071251  0.16521 8.6878e-01 Sp <--> Ip  
> Vd1   0.0480379 0.0063780  7.53177 4.9960e-14 ALC1 <--> ALC1  
> Vd2   0.0762156 0.0044523 17.11821 0.e+00 ALC2 <--> ALC2  
> Vd3   0.0762794 0.0097763  7.80249 5.9952e-15 ALC3 <--> ALC3  
> Vd4   0.1057875 0.0108526  9.74770 0.e+00 PEER1 <--> PEER1
> Vd5   0.1712811 0.0087037 19.67904 0.e+00 PEER2 <--> PEER2
> Vd6   0.1289592 0.0177027  7.28471 3.2241e-13 PEER3 <--> PEER3
> Cd1   0.0109322 0.0061562  1.77578 7.5769e-02 PEER1 <--> ALC1 
> Cd2   0.0339991 0.0046391  7.

Re: [R] Matching rows in a Data set? I'm Stuck!!

2010-03-03 Thread Marc Schwartz
On Mar 3, 2010, at 7:24 AM, BioStudent wrote:

> 
> Thanks!
> 
> I'm just trying to do it now but having issues with memory...
> 
> test <- merge(file1, file2, by.x = "col1")
> 
> will this give me the output I was hoping for
> 
> ID VALUE1 VALUE2
> 
> ?
> 
> Thanks


If you are going to use 'by.x' then you also need to use 'by.y' so that merge 
knows which column(s) to use in each data set for the matching. Otherwise, 
using my original example with 'by', the presumption is that the same column 
name is available in both datasets.

You can use multiple column names in both datasets to define data combinations 
that result in a unique one-to-one row pairing. The result will also depend 
upon the settings of 'all', 'all.x' and 'all.y'. Review the help file for 
merge(). The default behavior (all = FALSE) only returns the rows that match 
between the two datasets.

If the files are large and you are having memory allocation problems, then you 
basically have three choices:

1. Increase the amount of RAM that you have in the computer, which is limited 
if you are on a 32 bit OS.

2. Move to a 64 bit version of R on a 64 bit OS with sufficient RAM in the 
computer.

3. Perform your data management tasks using an appropriate database 
application, rather than in R. This can be done completely in the database and 
then export to R, or you can access the database from within R using one of the 
several methods available (eg. ODBC). See the R Import/Export Manual at 
http://cran.r-project.org/doc/manuals/R-data.html.

HTH,

Marc Schwartz

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


Re: [R] Three most useful R package

2010-03-03 Thread Cedrick W. Johnson

   I think Brian and Josh the two powerhouses behind quantmod and other finance
   related packages are working on a package called 'blotter' which is on
   r-forge which may be able to help you with keeping track and doing some
   testing of trading strategies.
   regards,
   cj
   
   On 3/3/2010 10:10 AM, ivan popivanov wrote:

1) quantmod, zoo, xts, TTR in no particular order, the first requires the other
s, so I can't really separate them.

2) There are plenty of packages for my needs (using R as a hobbyist), but my bi
ggest concern is that they lack active support. A package for complex testing o
f trading strategies would be nice, but it's hard to come up with a good design
.

Regards,

  

Date: Tue, 2 Mar 2010 15:13:54 -0500
From: [1]ralf.bie...@gmail.com
To: [2]r-h...@r-project.org
Subject: [R] Three most useful R package

Hi R-fans,

I would like put out a question to all R users on this list and hope
it will create some feedback and discussion.

1) What are your 3 most useful R package? and

2) What R package do you still miss and why do you think it would make
a useful addition?

Pulling answers together for these questions will serve as a guide for
new users and help people who just want to get a hint where to look
first. Happy replying!

Best,
Ralf

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



_
Stay in touch.

[[alternative HTML version deleted]]

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

References

   1. mailto:ralf.bie...@gmail.com
   2. mailto:r-help@r-project.org
   3. mailto:R-help@r-project.org
   4. https://stat.ethz.ch/mailman/listinfo/r-help
   5. http://www.R-project.org/posting-guide.html
   6. mailto:R-help@r-project.org
   7. https://stat.ethz.ch/mailman/listinfo/r-help
   8. http://www.R-project.org/posting-guide.html
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Odp: Loop overwrite and data output problems

2010-03-03 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 01.03.2010 16:36:27:

> 
> Hi Petr,
> 
> Thanks again for trying again with these data, I really appreciate it.
> 
> Your script works perfectly, but the problem I'm having is how to store 
the
> model results so after your script I would do: 
> 
>   m1.R<-glm(cbind(res$BEH_T, res$BEH_F) ~ res$SITE + res$YEAR +
> res$PRECIP_MM_DAY + res$PUP_AGE_EST + res$MO_AIR_TEMP, 
family="binomial")
>   mod<-dredge(m1.R)
> 
> where mod is a list not a vector. 
> 
> So your example has 10 iterations of the loop so there should therefore 
be
> 10 different mod[1,] that I want to store and that is what I can't work 
out
> how to do, for example I can do this:
> 
>  if (i>=1) print (mod[1,]) else print ("NO")}
> 
> And I will get a print of each of the 10 model outputs that I want, but 
I
> want to store these somewhere. I did try to adjust your value <- matrix
> section of the script but had no luck.
> 
> I hope this is a little clearer?

Well, I am still a bit unsure what is your problem. You used slower way 
but i believe you should use quicker one as you want to cycle it 100 times

Assuming your data are named data

dat.o<-data[order(data$ID2),]
len<-rle(dat.o$ID2)$lengths
shift.len<-c(0,cumsum(len))[-(length(len)+1)]

# declare object for storing your results (the structure depends on 
structure of the result)
mod<- vector(10, mode="list")

for(i in 1:10) {
samp<-sapply(lapply(split(dat.o$ID2, dat.o$ID2), function(x) 1:length(x)), 
sample, 1)
Sample.dat <- dat.o[shift.len+samp,]


# do any of your stuff here (put Sample.dat instead of res)

m1.R<-glm(cbind(res$BEH_T, res$BEH_F) ~ res$SITE + res$YEAR + 
res$PRECIP_MM_DAY + res$PUP_AGE_EST + res$MO_AIR_TEMP, family="binomial")
mod[[i]]<-dredge(m1.R)

}

then you shall get a list with 10 components each one for one result.
You can extract each component acccordingly

mod[[1]]

Regards
Petr


> 
> Thank you again for your help, I really appreciate it!
> 
> Ross
> 
> 
> -- 
> View this message in context: 
http://n4.nabble.com/Loop-overwrite-and-data-
> output-problems-tp1570593p1573703.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Matching rows in a Data set? I'm Stuck!!

2010-03-03 Thread BioStudent

Thanks!

I'm just trying to do it now but having issues with memory...

test <- merge(file1, file2, by.x = "col1")

will this give me the output I was hoping for

ID VALUE1 VALUE2

?

Thanks
-- 
View this message in context: 
http://n4.nabble.com/Matching-rows-in-a-Data-set-I-m-Stuck-tp1576432p1576523.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] Matching rows in a Data set? I'm Stuck!!

2010-03-03 Thread BioStudent

Unfortunately its complaining that 'by.x' and 'by.y' specify different
numbers of columns'.

I don't really see why that matters if your matching tbh... 

I'm having a few problems. Merge is definitely what I want but my files are
way too big and i'm having memory trouble. Plus I figures out the ID column
isn't unique but I guess i can just use by.y="anotheridentifyingcolumn" to
get around that.
-- 
View this message in context: 
http://n4.nabble.com/Matching-rows-in-a-Data-set-I-m-Stuck-tp1576432p1576544.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] Matching rows in a Data set? I'm Stuck!!

2010-03-03 Thread Albart

Hi,
 are your dataframes really called file1 and file2? Then, it will be
something like this:
 test 

Links:
--
[1]
http://n4.nabble.com/Matching-rows-in-a-Data-set-I-m-Stuck-tp1576432p1576523.html
[2]
 (link removed) =

-- 
View this message in context: 
http://n4.nabble.com/Matching-rows-in-a-Data-set-I-m-Stuck-tp1576432p1576573.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

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


Re: [R] Three most useful R package

2010-03-03 Thread kulwinder banipal

other than " base" :
   1. XML & Rcurl2. lattice3. Hmisc

> On Tue, Mar 2, 2010 at 10:13 PM, Ralf B  wrote:
> 
> > Hi R-fans,
> >
> > I would like put out a question to all R users on this list and hope
> > it will create some feedback and discussion.
> >
> > 1) What are your 3 most useful R package? and
> >
> > 2) What R package do you still miss and why do you think it would make
> > a useful addition?
> >
> > Pulling answers together for these questions will serve as a guide for
> > new users and help people who just want to get a hint where to look
> > first. Happy replying!
> >
> > Best,
> > Ralf
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/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.
  
_
Hotmail: Trusted email with powerful SPAM protection.

[[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 IRT simulation

2010-03-03 Thread Helen Lisman
hello R,
This is about simulation in psychomtrics in IRT in R. I want to simulate b
parameters(item difficulty) with moments of fixed values of mean, st.d,
skewness and kurtosis. Is there any specific IRT package in R with those
functions to control those moments? I have seen other programs that can
control mean and st.d but not skewness and kurtosis.

Thank you,
helen L

[[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] Odp: Trouble With for() Loops

2010-03-03 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 03.03.2010 08:27:27:

> Hello,
> 
> I'm trying to learn R (for fun!), and I've tried to find any previous 
> discussion of this problem (or something like it) and haven't found one.
> 
> When I run the following command, R seems to simply stop. I get no error 

> message, but I also have no ">" or "+" to type after (although I can 
> type). The only solution seems to be restarting the program. Here's the 
> code:
> 
> for(i in 1:150)
> for(j in 1:150)
> (average <-c(
> (if(NO[i]==1)
> {i*0}
> else
> {if(HA[i]==HA[j])
> {while(G[j]==1)
> {mean(PT[j:(i-1)])}}})))

Strange that you get no error. When I used your code I got

> for(i in 1:150)
+ for(j in 1:150)
+ (average <-c(
+ (if(NO[i]==1)
+ {i*0}
+ else
+ {if(HA[i]==HA[j])
+ {while(G[j]==1)
+ {mean(PT[j:(i-1)])}}})))
Error: object 'NO' not found


> 
> Also, if what I'm trying to do makes any sense and someone sees an 
> easier way of doing it, that would be great.

And what really you are trying to do? Use R like C+? No way, forget it. R 
is R C+ is C+.

Regards
Petr

> 
> Thanks!
> 
> Milo
> Undergraduate -- Reed College
> Portland, OR
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] two questions for R beginners

2010-03-03 Thread Petr PIKAL
Hi

that is why I consider matrix is just a vector with dimensions and 
data.frame is a rectangular structure similar to Excel table. That saved 
me a lot of surprises. 

But I must admit I am not a real beginner nowadays although I still learn 
when using R, reading help list and trying sometimes to help others.

Regards
Petr


"John Sorkin"  napsal dne 03.03.2010 
16:30:39:

> Petr,
> On the other hand . . .
> 
> > mat<-matrix(1:12, 3,4)
> > dat<-as.data.frame(mat)
> > mat
>  [,1] [,2] [,3] [,4]
> [1,]147   10
> [2,]258   11
> [3,]369   12
> > dat
>   V1 V2 V3 V4
> 1  1  4  7 10
> 2  2  5  8 11
> 3  3  6  9 12
> 
> What you are demonstrating by your example is the manner in which the 
data are
> organized deep in the guts of R, not the way people, especially R 
beginners 
> visualize objects in their mind. When I think of the integer sixty-nine, 
I 
> visualize 69, not 1000101 despite the fact that 69, as an integer is 
> represented in the computer as 1000101.
> John
> 
> 
> 
> 
> 
> 
> 
> John David Sorkin M.D., Ph.D.
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)>>> 
Petr 
> PIKAL  3/3/2010 9:44 AM >>>
> "John Sorkin"  napsal dne 01.03.2010 
> 15:19:10:
> 
> > If it looks like a duck and quacks like a duck, it ought to behave 
like 
> a duck.
> > 
> > To the user a matrix and a dataframe look alike . . . except a 
dataframe 
> can 
> 
> Well, matrix looks like a data.frame only on the first sight.
> 
> mat<-matrix(1:12, 3,4)
> dat<-as.data.frame(mat)
> 
> 
> str(dat)
> 'data.frame':   3 obs. of  4 variables:
>  $ V1: int  1 2 3
>  $ V2: int  4 5 6
>  $ V3: int  7 8 9
>  $ V4: int  10 11 12
> 
> str(mat)
>  int [1:3, 1:4] 1 2 3 4 5 6 7 8 9 10 ...
> 
> seems to me a pretty different look like.
> 
> Regards
> Petr
> 
> 
> > hold non-numeric values. Thus to the users, a matrix looks like a 
> special case
> > of a DF, or perhaps conversely. If you can address elements of one 
> structure 
> > using a given syntax, you should be able to address elements of the 
> other 
> > structure using the same syntax. To do otherwise leads to confusion 
and 
> is 
> > counter intuitive.
> > John
> > 
> > 
> > 
> > 
> > John David Sorkin M.D., Ph.D.
> > Chief, Biostatistics and Informatics
> > University of Maryland School of Medicine Division of Gerontology
> > Baltimore VA Medical Center
> > 10 North Greene Street
> > GRECC (BT/18/GR)
> > Baltimore, MD 21201-1524
> > (Phone) 410-605-7119
> > (Fax) 410-605-7913 (Please call phone number above prior to faxing)>>> 

> Petr 
> > PIKAL  3/1/2010 8:57 AM >>>
> > Hi
> > 
> > r-help-boun...@r-project.org napsal dne 01.03.2010 13:03:24:
> > 
> > < snip>
> > 
> > > > 
> > > > I understand that 2 dimensional rectangular matrix looks quite
> > > > similar to data frame however it is only a vector with dimensions.
> > > > As such it can have items of only one type (numeric, character, 
> ...).
> > > > And you can easily change dimensions of matrix.
> > > > 
> > > > matrix<-1:12
> > > > dim(matrix) <- c(2,6)
> > > > matrix
> > > > dim(matrix) <- c(2,2,3)
> > > > matrix
> > > > dim(matrix) <-NULL
> > > > matrix
> > > > 
> > > > So rectangular structure of printed matrix is a kind of 
coincidence
> > > > only, whereas rectangular structure of data frame is its main 
> feature.
> > > > 
> > > > Regards
> > > > Petr
> > > >> 
> > > >> -- 
> > > >> Karl Ove Hufthammer
> > > 
> > > Petr, I think that could be confusing! The way I see it is that
> > > a matrix is a special case of an array, whose "dimension" attribute
> > > is of length 2 (number of "rows", number of "columns"); and "row"
> > > and "column" refer to the rectangular display which you see when
> > > R prints to matrix. And this, of course, derives directly from
> > > the historic rectangular view of a matrix when written down.
> > > 
> > > When you went from "dim(matrix)<-c(2,6)" to "dim(matrix)<-c(2,2,3)"
> > > you stripped it of its special title of "matrix" and cast it out
> > > into the motley mob of arrays (some of whom are matrices, but
> > > "matrix" no longer is).
> > > 
> > > So the "rectangular structure of printed matrix" is not a 
coincidence,
> > > but is its main feature!
> > 
> > Ok. Point taken. However I feel that possibility to manipulate 
> > matrix/array dimensions by simple changing them as I  showed above 
> > together with perceiving matrix as a **vector with dimensions** 
> prevented 
> > me especially in early days from using matrices instead of data frames 

> and 
> > vice versa. 
> > 
> > Consider cbind and rbind confusing results for vectors with unequal 
> mode. 
> > Far to often we can see something like that
> > 
> > > cbind(1:2,letters[1:2])
> >  [,1] [,2]
> > [1,] "1"  "a" 
> > [2,] "2"  "b" 
> > 

Re: [R] [stats-rosuda-devel] R: R help unavailable

2010-03-03 Thread Simon Urbanek


On Mar 3, 2010, at 7:45 ,   wrote:


Actually the problem exists only if I use JGR.



Make sure you upgrade JGR. You need JGR 1.7 or higher to work with R  
2.10. If you have any questions, please use the JGR mailing list stats- 
rosuda-devel.


Thanks,
Simon



If I launch R from a terminal window then the text on-line help works.
It used to work with JGR too but with R version 2.9.0.
Now, JGR shows the new R version is running but the on-line help is  
no more available from JGR.
Perhaps JGR implementors will come up with some suggestion to fix  
this problem.

Thank you,
Maura

-Messaggio originale-
Da: Duncan Murdoch [mailto:murd...@stats.uwo.ca]
Inviato: mer 03/03/2010 12.58
A: mau...@alice.it
Cc: r-h...@stat.math.ethz.ch
Oggetto: Re: [R] R help unavailable

On 03/03/2010 6:39 AM, mau...@alice.it wrote:
> I have recently replaced R-2.9.0 with R-2.10.1 Patched. Apparently  
the installation completed successfully
> but right now I realized that the on-line help does not work any  
more.
> When I type "?" a message pops up warning that "Help  
will not be available. Path not found" ... regardless of the R- 
command.

> How can I get back R on-line man pages ?

You could switch to text-based help by editing RHOME/etc/Rprofile.site
or your personal Rprofile, but you probably want to fix the bigger
problem, which is that your system can't open the URLs that R is  
giving

it.  Can you open any URL?  E.g. does
browseURL("http://www.r-project.org";)  open that web page?  If not,  
the

problem is that your system doesn't know how to open a browser.

Duncan Murdoch


> Thank you very much,
> Maura
>
>
> tutti i telefonini TIM!
>
>
>
>
>
> tutti i telefonini TIM!
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




Alice Messenger ;-) chatti anche con gli amici di Windows Live  
Messenger e tutti i telefonini TIM!

Vai su http://maileservizi.alice.it/alice_messenger/index.html?pmk=footer

___
stats-rosuda-devel mailing list
stats-rosuda-de...@listserv.uni-augsburg.de
http://mailman.rz.uni-augsburg.de/mailman/listinfo/stats-rosuda-devel


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


Re: [R] two questions for R beginners

2010-03-03 Thread John Sorkin
Petr,
On the other hand . . .

> mat<-matrix(1:12, 3,4)
> dat<-as.data.frame(mat)
> mat
 [,1] [,2] [,3] [,4]
[1,]147   10
[2,]258   11
[3,]369   12
> dat
  V1 V2 V3 V4
1  1  4  7 10
2  2  5  8 11
3  3  6  9 12

What you are demonstrating by your example is the manner in which the data are 
organized deep in the guts of R, not the way people, especially R beginners 
visualize objects in their mind. When I think of the integer sixty-nine, I 
visualize 69, not 1000101 despite the fact that 69, as an integer is 
represented in the computer as 1000101.
John







John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)>>> Petr 
PIKAL  3/3/2010 9:44 AM >>>
"John Sorkin"  napsal dne 01.03.2010 
15:19:10:

> If it looks like a duck and quacks like a duck, it ought to behave like 
a duck.
> 
> To the user a matrix and a dataframe look alike . . . except a dataframe 
can 

Well, matrix looks like a data.frame only on the first sight.

mat<-matrix(1:12, 3,4)
dat<-as.data.frame(mat)


str(dat)
'data.frame':   3 obs. of  4 variables:
 $ V1: int  1 2 3
 $ V2: int  4 5 6
 $ V3: int  7 8 9
 $ V4: int  10 11 12

str(mat)
 int [1:3, 1:4] 1 2 3 4 5 6 7 8 9 10 ...

seems to me a pretty different look like.

Regards
Petr


> hold non-numeric values. Thus to the users, a matrix looks like a 
special case
> of a DF, or perhaps conversely. If you can address elements of one 
structure 
> using a given syntax, you should be able to address elements of the 
other 
> structure using the same syntax. To do otherwise leads to confusion and 
is 
> counter intuitive.
> John
> 
> 
> 
> 
> John David Sorkin M.D., Ph.D.
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)>>> 
Petr 
> PIKAL  3/1/2010 8:57 AM >>>
> Hi
> 
> r-help-boun...@r-project.org napsal dne 01.03.2010 13:03:24:
> 
> < snip>
> 
> > > 
> > > I understand that 2 dimensional rectangular matrix looks quite
> > > similar to data frame however it is only a vector with dimensions.
> > > As such it can have items of only one type (numeric, character, 
...).
> > > And you can easily change dimensions of matrix.
> > > 
> > > matrix<-1:12
> > > dim(matrix) <- c(2,6)
> > > matrix
> > > dim(matrix) <- c(2,2,3)
> > > matrix
> > > dim(matrix) <-NULL
> > > matrix
> > > 
> > > So rectangular structure of printed matrix is a kind of coincidence
> > > only, whereas rectangular structure of data frame is its main 
feature.
> > > 
> > > Regards
> > > Petr
> > >> 
> > >> -- 
> > >> Karl Ove Hufthammer
> > 
> > Petr, I think that could be confusing! The way I see it is that
> > a matrix is a special case of an array, whose "dimension" attribute
> > is of length 2 (number of "rows", number of "columns"); and "row"
> > and "column" refer to the rectangular display which you see when
> > R prints to matrix. And this, of course, derives directly from
> > the historic rectangular view of a matrix when written down.
> > 
> > When you went from "dim(matrix)<-c(2,6)" to "dim(matrix)<-c(2,2,3)"
> > you stripped it of its special title of "matrix" and cast it out
> > into the motley mob of arrays (some of whom are matrices, but
> > "matrix" no longer is).
> > 
> > So the "rectangular structure of printed matrix" is not a coincidence,
> > but is its main feature!
> 
> Ok. Point taken. However I feel that possibility to manipulate 
> matrix/array dimensions by simple changing them as I  showed above 
> together with perceiving matrix as a **vector with dimensions** 
prevented 
> me especially in early days from using matrices instead of data frames 
and 
> vice versa. 
> 
> Consider cbind and rbind confusing results for vectors with unequal 
mode. 
> Far to often we can see something like that
> 
> > cbind(1:2,letters[1:2])
>  [,1] [,2]
> [1,] "1"  "a" 
> [2,] "2"  "b" 
> 
> instead of
> 
> > data.frame(1:2,letters[1:2])
>   X1.2 letters.1.2.
> 11a
> 22b
> 
> and then a question why does not the result behave as expected. Each 
type 
> of object has some features which is good for some type of 
> manipulation/analysis/plotting bud quite detrimental for others.
> 
> Regards
> Petr
> 
> 
> > 
> > To come back to Karl's query about why "$" works for a dataframe
> > but not for a matrix, note that "$" is the extractor for getting
> > a named component of a list. So, Karl, when you did
> > 
> >   d=head(iris[1:4])
> > 
> > you created a dataframe:
> > 
> >   str(d)
> >   # 'data.frame':   6 obs. of  4 variables:
> >   #  $ Sepal.Length: n

Re: [R] sem package and growth curves

2010-03-03 Thread John Fox
Dear Chuck and Daniel,

First, thanks Chuck for fielding the question, which I didn't notice in
r-help.

I can get solutions for models A, B, and C using the automatic start values
along with the argument par.size="startvalues" to sem() (as recommended in
?sem if there are convergence problems). For example, for Model A:

 snip -

> modA <- specify.model()
1: I -> ALC1, NA, 1
2: I -> ALC2, NA, 1
3: I -> ALC3, NA, 1
4: S -> ALC1, NA, 0
5: S -> ALC2, NA, 0.75
6: S -> ALC3, NA, 1.75
7: UNIT -> I, Mi, NA
8: UNIT -> S, Ms, NA
9: I <-> I, Vi, NA
10: S <-> S, Vs, NA
11: I <-> S, Cis, NA
12: ALC1 <-> ALC1, Vd1, NA
13: ALC2 <-> ALC2, Vd2, NA
14: ALC3 <-> ALC3, Vd3, NA
15: 
Read 14 records
> sem.modA <- sem(modA, alc2.modA.raw, 1122, fixed.x="UNIT",
par.size="startvalues", raw=TRUE)
> 
> summary(sem.modA)

Model fit to raw moment matrix.

 Model Chisquare =  0.048207   Df =  1 Pr(>Chisq) = 0.82621
 BIC =  -6.9747 

 Normalized Residuals
Min.  1st Qu.   Median Mean  3rd Qu. Max. 
-0.04050 -0.03790 -0.01600  0.00603  0.03200  0.09620 

 Parameter Estimates
Estimate  Std Error z value Pr(>|z|) 
Mi   0.225625 0.0106901 21.1059 0.e+00 I <--- UNIT   
Ms   0.035978 0.0073456  4.8979 9.6865e-07 S <--- UNIT   
Vi   0.087039 0.0071035 12.2530 0.e+00 I <--> I  
Vs   0.019764 0.0052178  3.7877 1.5205e-04 S <--> S  
Cis -0.012476 0.0045780 -2.7251 6.4282e-03 S <--> I  
Vd1  0.048428 0.0064146  7.5495 4.3743e-14 ALC1 <--> ALC1
Vd2  0.075702 0.0044403 17.0488 0.e+00 ALC2 <--> ALC2
Vd3  0.076698 0.0098901  7.7551 8.8818e-15 ALC3 <--> ALC3

 Iterations =  57 

 snip -

Model D converges with the default setting of par.size:

 snip -

> alc2.modD.raw <- raw.moments(subset(alc2,
+ select=c('PEER1','PEER2','PEER3','ALC1','ALC2','ALC3','UNIT')))
> 
> modD <- specify.model()
1: Ia -> ALC1, NA, 1
2: Ia -> ALC2, NA, 1
3: Ia -> ALC3, NA, 1
4: Sa -> ALC1, NA, 0
5: Sa -> ALC2, NA, 0.75
6: Sa -> ALC3, NA, 1.75
7: UNIT -> Ia, Mia, NA
8: UNIT -> Sa, Msa, NA
9: Ip -> PEER1, NA, 1
10: Ip -> PEER2, NA, 1
11: Ip -> PEER3, NA, 1
12: Sp -> PEER1, NA, 0
13: Sp -> PEER2, NA, 0.75
14: Sp -> PEER3, NA, 1.75
15: Ip -> Ia, B1, NA
16: Sp -> Ia, B2, NA
17: Ip -> Sa, B3, NA
18: Sp -> Sa, B4, NA
19: UNIT -> Ip, Mip, NA
20: UNIT -> Sp, Msp, NA
21: Ia <-> Ia, Via, NA
22: Sa <-> Sa, Vsa, NA
23: Ia <-> Sa, Cisa, NA
24: Ip <-> Ip, Vip, NA
25: Sp <-> Sp, Vsp, NA
26: Ip <-> Sp, Cisp, NA
27: ALC1 <-> ALC1, Vd1, NA
28: ALC2 <-> ALC2, Vd2, NA
29: ALC3 <-> ALC3, Vd3, NA
30: PEER1 <-> PEER1, Vd4, NA
31: PEER2 <-> PEER2, Vd5, NA
32: PEER3 <-> PEER3, Vd6, NA
33: ALC1 <-> PEER1, Cd1, NA
34: ALC2 <-> PEER2, Cd2, NA
35: ALC3 <-> PEER3, Cd3, NA
36: 
Read 35 records
> sem.modD <- sem(modD, alc2.modD.raw, 1122, fixed.x=c("UNIT"), raw=TRUE)
> summary(sem.modD)

Model fit to raw moment matrix.

 Model Chisquare =  11.557   Df =  4 Pr(>Chisq) = 0.020967
 BIC =  -16.534 

 Normalized Residuals
Min.  1st Qu.   Median Mean  3rd Qu. Max. 
-0.91500 -0.39200  0.00105  0.09760  0.39900  1.61000 

 Parameter Estimates
 Estimate   Std Error z value  Pr(>|z|)   
Mia   0.0666214 0.0156727  4.25079 2.1302e-05 Ia <--- UNIT
Msa   0.0083040 0.0147616  0.56254 5.7375e-01 Sa <--- UNIT
B10.7985829 0.1028010  7.76824 7.9936e-15 Ia <--- Ip  
B20.0804315 0.1840470  0.43702 6.6210e-01 Ia <--- Sp  
B3   -0.1433386 0.0762547 -1.87973 6.0144e-02 Sa <--- Ip  
B40.5766956 0.1938673  2.97469 2.9328e-03 Sa <--- Sp  
Mip   0.1881743 0.0119530 15.74285 0.e+00 Ip <--- UNIT
Msp   0.0961698 0.0096929  9.92167 0.e+00 Sp <--- UNIT
Via   0.0421656 0.0074640  5.64920 1.6120e-08 Ia <--> Ia  
Vsa   0.0092181 0.0054564  1.68941 9.1140e-02 Sa <--> Sa  
Cisa -0.0063651 0.0051128 -1.24492 2.1316e-01 Sa <--> Ia  
Vip   0.0696837 0.0103795  6.71357 1.8991e-11 Ip <--> Ip  
Vsp   0.0284726 0.0089274  3.18936 1.4259e-03 Sp <--> Sp  
Cisp  0.0011771 0.0071251  0.16521 8.6878e-01 Sp <--> Ip  
Vd1   0.0480379 0.0063780  7.53177 4.9960e-14 ALC1 <--> ALC1  
Vd2   0.0762156 0.0044523 17.11821 0.e+00 ALC2 <--> ALC2  
Vd3   0.0762794 0.0097763  7.80249 5.9952e-15 ALC3 <--> ALC3  
Vd4   0.1057875 0.0108526  9.74770 0.e+00 PEER1 <--> PEER1
Vd5   0.1712811 0.0087037 19.67904 0.e+00 PEER2 <--> PEER2
Vd6   0.1289592 0.0177027  7.28471 3.2241e-13 PEER3 <--> PEER3
Cd1   0.0109322 0.0061562  1.77578 7.5769e-02 PEER1 <--> ALC1 
Cd2   0.0339991 0.0046391  7.32874 2.3226e-13 PEER2 <--> ALC2 
Cd3   0.0374125 0.0101878  3.67229 2.4038e-04 PEER3 <--> ALC3 

 Iterations =  139 

 snip -

Regards,
 John 


John Fox
Senator William McMaster 
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On
> Behalf O

Re: [R] Three most useful R package

2010-03-03 Thread ivan popivanov

1) quantmod, zoo, xts, TTR in no particular order, the first requires the 
others, so I can't really separate them.

2) There are plenty of packages for my needs (using R as a hobbyist), but my 
biggest concern is that they lack active support. A package for complex testing 
of trading strategies would be nice, but it's hard to come up with a good 
design.

Regards,

> Date: Tue, 2 Mar 2010 15:13:54 -0500
> From: ralf.bie...@gmail.com
> To: r-help@r-project.org
> Subject: [R] Three most useful R package
> 
> Hi R-fans,
> 
> I would like put out a question to all R users on this list and hope
> it will create some feedback and discussion.
> 
> 1) What are your 3 most useful R package? and
> 
> 2) What R package do you still miss and why do you think it would make
> a useful addition?
> 
> Pulling answers together for these questions will serve as a guide for
> new users and help people who just want to get a hint where to look
> first. Happy replying!
> 
> Best,
> Ralf
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
  
_
Stay in touch.

[[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 using partial values

2010-03-03 Thread Newbie19_02

Thanks again for the help but what I am having trouble with is that I get:

1012  CAO0103166 01/04/1999   I200
1016  CAO0103166 03/05/2000   I200
1024  CAO0103166 20/06/1997   I209
1025  CAO0103166 25/02/1999   I209
1027  CAO0103166 27/08/1999   I200
1058  CAO0107171 11/01/2002   N411
1104  CAO0113512 14/02/2003   I209


I'm trying to avoid getting N411?

Thanks,
Natalie
-- 
View this message in context: 
http://n4.nabble.com/Subset-using-partial-values-tp1576614p1576683.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] Subset using partial values

2010-03-03 Thread Henrique Dallazuanna
Then:

subset(x, grepl('410|I25', main_condition))

On Wed, Mar 3, 2010 at 11:59 AM, Newbie19_02  wrote:
>
> Hi,
>
> That was a good suggestion but I should have been more specific,
>         PROCHI            Date_admission      main_condition
>         CAO3121534     15/08/2006           I501
> 28394 CAO3121534     18/04/1999           I251
> 28395 CAO3121534     18/10/1993           4109
> 28396 CAO3121534     19/01/1988          71946
> 28397 CAO3121534     20/04/1999           I251
> 28398 CAO3121534     21/04/1999           I251
> 28399 CAO3121534     21/05/1998           Z048
> 28400 CAO3121534     21/10/1993           4109
> 28401 CAO3121534     25/02/2002           R634
> 28402 CAO3121534     26/01/2003           B349
> 28403 CAO3121534     27/08/1998           M179
> 28404 CAO3121534     28/05/1999           I501
> 28405 CAO3121534     30/09/1997           I259
> 28406 CAO3121534     31/08/2007           H830
> 28407 CAO3121560     07/07/2000           D688
>
> So let's say that I want to subset but only by characters beginning with 410
> and I25?
> grep returns any character containing the pattern and so is not entirely
> suitable to the extended example. Though it works almost perfectly.  Is
> there a way to make it match the first three letters?
>
> THanks,
> Natalie
> --
> View this message in context: 
> http://n4.nabble.com/Subset-using-partial-values-tp1576614p1576673.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.
>



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

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

2010-03-03 Thread Amit Patel
I am attempting Anova analysis to compare results from four groups (Samp1-4) 
which are lists of intensities from the experiment. I am doing this by first 
creating a structured list of the data and then conducting the ANOVA (Script 
provided below). Im an R beginner so am not sure if I am using this correctly. 
Two major questions I have are:

1) Is using the code (zzz.aov <- aov(Intensity ~ Group + Error(Sample), data = 
zzzanova)) the correct method to calculate the variances between the four 
groups (samp 1-4). I am unsure of the inclusion of the error portion.

2) I beleive this method (aov) assumes equal variances. How can I adjust this 
to do an ANOVA with unequal variances




#SCRIPT STARTS
#Creates a structured list suitable for ANOVA analysis
# Intensity Group (1,2,3,4) Sample(1:62)
"zzzanova" <-
structure(list(Intensity = c(t(Samp1), t(Samp2), t(Samp3), t(Samp4)), 
Group = structure(c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
 3,3,3,3,3,3,3,3,3,3,3,3,3,3,
 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4), .Label = c("Group1", "Group2", 
"Group3", "Group4"), class = "factor"), 
Sample = structure(c( 1, 2, 3, 4, 5, 6, 7, 8, 9, 
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62)
))
, .Names = c("Intensity", 
"Group", "Sample"), row.names = 
c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
"31", "32", "33", "34", "35", "36", "37", "38", "39", "40",
"41", "42", "43", "44", "45", "46", "47", "48", "49", "50",
"51", "52", "53", "54", "55", "56", "57", "58", "59", "60",
"61","62"),class = "data.frame")

#Conducts the ANOVA for that PCI
zzz.aov <- aov(Intensity ~ Group + Error(Sample), data = zzzanova)

#SCRIPT ENDS


THANKS IN ADVANCE



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

2010-03-03 Thread Newbie19_02

Hi,

That was a good suggestion but I should have been more specific,
 PROCHIDate_admission  main_condition
 CAO3121534 15/08/2006   I501
28394 CAO3121534 18/04/1999   I251
28395 CAO3121534 18/10/1993   4109
28396 CAO3121534 19/01/1988  71946
28397 CAO3121534 20/04/1999   I251
28398 CAO3121534 21/04/1999   I251
28399 CAO3121534 21/05/1998   Z048
28400 CAO3121534 21/10/1993   4109
28401 CAO3121534 25/02/2002   R634
28402 CAO3121534 26/01/2003   B349
28403 CAO3121534 27/08/1998   M179
28404 CAO3121534 28/05/1999   I501
28405 CAO3121534 30/09/1997   I259
28406 CAO3121534 31/08/2007   H830
28407 CAO3121560 07/07/2000   D688

So let's say that I want to subset but only by characters beginning with 410
and I25?  
grep returns any character containing the pattern and so is not entirely
suitable to the extended example. Though it works almost perfectly.  Is
there a way to make it match the first three letters?

THanks,
Natalie
-- 
View this message in context: 
http://n4.nabble.com/Subset-using-partial-values-tp1576614p1576673.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] nu-SVM crashes in e1071

2010-03-03 Thread Steve Lianoglou
Hi,

On Wed, Mar 3, 2010 at 4:08 AM, Häring, Tim (LWF)
 wrote:
> (...)
>
>> While you're sending your bug report to David, perhaps you can try the
>> SVM from kernlab.
>>
>> It relies on code from libsvm, too, but ... you never know. It can't
>> hurt to try.
>
> Hi Steve,
>
> thanks for that hint.
> I tried ksvm()-function bet get an error message:
>
> model <- ksvm(soil_unit~., train, type="nu-svc")
> Using automatic sigma estimation (sigest) for RBF or laplace kernel
> Error in votematrix[i, ret < 0] <- votematrix[i, ret < 0] + 1 :
>  NAs are not allowed in subscripted assignments
>
> But there are no NAs in my dataset. I checked it with
> summary(is.na(train))

All the same, it seems there might be something funky with your data?

Not sure how to help debug further. If you like you send an *.rda file
of your soil_unit data offline and I can try, but otherwise I guess
you're on your own?

What if you remove some of the columns of your matrix? Will this
eventually work?
-steve

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

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


Re: [R] two questions for R beginners

2010-03-03 Thread Petr PIKAL
"John Sorkin"  napsal dne 01.03.2010 
15:19:10:

> If it looks like a duck and quacks like a duck, it ought to behave like 
a duck.
> 
> To the user a matrix and a dataframe look alike . . . except a dataframe 
can 

Well, matrix looks like a data.frame only on the first sight.

mat<-matrix(1:12, 3,4)
dat<-as.data.frame(mat)


str(dat)
'data.frame':   3 obs. of  4 variables:
 $ V1: int  1 2 3
 $ V2: int  4 5 6
 $ V3: int  7 8 9
 $ V4: int  10 11 12

str(mat)
 int [1:3, 1:4] 1 2 3 4 5 6 7 8 9 10 ...

seems to me a pretty different look like.

Regards
Petr


> hold non-numeric values. Thus to the users, a matrix looks like a 
special case
> of a DF, or perhaps conversely. If you can address elements of one 
structure 
> using a given syntax, you should be able to address elements of the 
other 
> structure using the same syntax. To do otherwise leads to confusion and 
is 
> counter intuitive.
> John
> 
> 
> 
> 
> John David Sorkin M.D., Ph.D.
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)>>> 
Petr 
> PIKAL  3/1/2010 8:57 AM >>>
> Hi
> 
> r-help-boun...@r-project.org napsal dne 01.03.2010 13:03:24:
> 
> < snip>
> 
> > > 
> > > I understand that 2 dimensional rectangular matrix looks quite
> > > similar to data frame however it is only a vector with dimensions.
> > > As such it can have items of only one type (numeric, character, 
...).
> > > And you can easily change dimensions of matrix.
> > > 
> > > matrix<-1:12
> > > dim(matrix) <- c(2,6)
> > > matrix
> > > dim(matrix) <- c(2,2,3)
> > > matrix
> > > dim(matrix) <-NULL
> > > matrix
> > > 
> > > So rectangular structure of printed matrix is a kind of coincidence
> > > only, whereas rectangular structure of data frame is its main 
feature.
> > > 
> > > Regards
> > > Petr
> > >> 
> > >> -- 
> > >> Karl Ove Hufthammer
> > 
> > Petr, I think that could be confusing! The way I see it is that
> > a matrix is a special case of an array, whose "dimension" attribute
> > is of length 2 (number of "rows", number of "columns"); and "row"
> > and "column" refer to the rectangular display which you see when
> > R prints to matrix. And this, of course, derives directly from
> > the historic rectangular view of a matrix when written down.
> > 
> > When you went from "dim(matrix)<-c(2,6)" to "dim(matrix)<-c(2,2,3)"
> > you stripped it of its special title of "matrix" and cast it out
> > into the motley mob of arrays (some of whom are matrices, but
> > "matrix" no longer is).
> > 
> > So the "rectangular structure of printed matrix" is not a coincidence,
> > but is its main feature!
> 
> Ok. Point taken. However I feel that possibility to manipulate 
> matrix/array dimensions by simple changing them as I  showed above 
> together with perceiving matrix as a **vector with dimensions** 
prevented 
> me especially in early days from using matrices instead of data frames 
and 
> vice versa. 
> 
> Consider cbind and rbind confusing results for vectors with unequal 
mode. 
> Far to often we can see something like that
> 
> > cbind(1:2,letters[1:2])
>  [,1] [,2]
> [1,] "1"  "a" 
> [2,] "2"  "b" 
> 
> instead of
> 
> > data.frame(1:2,letters[1:2])
>   X1.2 letters.1.2.
> 11a
> 22b
> 
> and then a question why does not the result behave as expected. Each 
type 
> of object has some features which is good for some type of 
> manipulation/analysis/plotting bud quite detrimental for others.
> 
> Regards
> Petr
> 
> 
> > 
> > To come back to Karl's query about why "$" works for a dataframe
> > but not for a matrix, note that "$" is the extractor for getting
> > a named component of a list. So, Karl, when you did
> > 
> >   d=head(iris[1:4])
> > 
> > you created a dataframe:
> > 
> >   str(d)
> >   # 'data.frame':   6 obs. of  4 variables:
> >   #  $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4
> >   #  $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9
> >   #  $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7
> >   #  $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4
> > 
> > (with named components "Sepal.Length", ... , "Petal.Width"),
> > and a dataframe is a special case of a general list. In a
> > general list, the separate components can each be anything.
> > In a dataframe, each component is a vector; the different
> > vectors may be of different types (logical, numeric, ... )
> > but of course the elements of any single vector must be
> > of the same type; and, in a dataframe, all the vectors must
> > have the same length (otherwise it is a general list, not
> > a dataframe).
> > 
> > So, when you print a dataframe, R chooses to display it
> > as a rectangular structure. On the other hand, when you
> > print a general list, R displays it quite differently:
> > 
> >   d
> >   #   Sepal.Length Sepal.Width Petal.Length Pe

Re: [R] Subset using partial values

2010-03-03 Thread Henrique Dallazuanna
Try this:

subset(x, grepl('411', Main_condition))

On Wed, Mar 3, 2010 at 11:33 AM, Newbie19_02  wrote:
>
> Hi everyone,
>
> I would like to subset a data.frame using partial values.
>
> For example I have the following data.frame:
>
> PROCHI  Main_condition
> 1234      411
> 1235     4110
> 1236     4111
> 1237     I20
> 1238    I201
> 1239    I202
>
> Now let's say that I use the Subset function.  Ordinarily I would use it as
> follows  Subset(x, Main_condition=="411"|Main_condition=="4110" etc to get
> all the 411s.
>
> Is there a way that you can subset by only using part of the term that you
> wish to subset by?
>
> Thanks,
> Natalie
> --
> View this message in context: 
> http://n4.nabble.com/Subset-using-partial-values-tp1576614p1576614.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.
>



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

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

2010-03-03 Thread Matthew Dowle
That in itself is a question for the maintainer, off r-help. When the 
posting guide says "contact the package maintainer first" it means it 
literally and applies even to questions about the existence of a mailing 
list for the package.  So what I'm supposed to do now is tell you how the 
posting guide works, and tell you that I'll reply off list.  Then hopefully 
the community will be happy with me too.  So I'll reply off list :-)

"Rob Forler"  wrote in message 
news:eb472fec1003030502s4996511ap8dfd329a3...@mail.gmail.com...
> Okay I appreciate the help, and I appreciate the FAQ reminder. I will read
> the r-help posting guide. I'm relatively new to using the support systems
> around R. So far everyone has been really helpful.
>
> I'm confused as to which data.table "list" I should be using.
> http://lists.r-forge.r-project.org/pipermail/datatable-commits/ doesn't
> appear to be correct. Or just directly sending an email to all of you?
>
> Thanks again,
> Rob
>
>
>
> On Wed, Mar 3, 2010 at 6:05 AM, Matthew Dowle 
> wrote:
>
>>
>> I'd go a bit further and remind that the r-help posting guide is clear :
>>
>>  " For questions about functions in standard packages distributed with R
>> (see the FAQ Add-on packages in R), ask questions on R-help.
>> If the question relates to a contributed package , e.g., one downloaded
>> from
>> CRAN, try contacting the package maintainer first. You can also use
>> find("functionname") and packageDescription("packagename") to find this
>> information. ONLY send such questions to R-help or R-devel if you get no
>> reply or need further assistance. This applies to both requests for help
>> and
>> to bug reports. "
>>
>> The "ONLY" is in bold in the posting guide. I changed the bold to 
>> capitals
>> above for people reading this in text only.
>>
>> Since Tom and I are friendly and responsive, users of data.table don't
>> usually make it to r-help. We'll follow up this one off-list.  Please 
>> note
>> that Rob's question is very good by the rest of the posting guide, so no
>> complaints there, only that it was sent to the wrong place.  Please keep
>> the
>> questions coming, but send them to us, not r-help.
>>
>> You do sometimes see messages to r-help starting something like "I have
>> contacted the authors/maintainers but didn't hear back,  does anyone know
>> ...".   To not state that they had would be an implicit request for 
>> further
>> work by the community (for free) to ask if they had. So its not enough to
>> contact the maintainer first, but you also have to say that you have as
>> well, and perhaps how long ago too would be helpful.  For r-forge 
>> projects
>> I
>> usually send any question to everyone on the project (easy to find) or if
>> they have a list then to that.
>>
>> HTH
>> Matthew
>>
>>
>> "Tom Short"  wrote in message
>> news:fd27013a1003021718w409acb32r1281dfeca5593...@mail.gmail.com...
>> On Tue, Mar 2, 2010 at 7:09 PM, Rob Forler  wrote:
>> > Hi everyone,
>> >
>> > I have the following code that works in data frames taht I would like 
>> > tow
>> > ork in data.tables . However, I'm not really sure how to go about it.
>> >
>> > I basically have the following
>> >
>> > names = c("data1", "data2")
>> > frame = data.frame(list(key1=as.integer(c(1,2,3,4,5,6)),
>> > key2=as.integer(c(1,2,3,2,5,6)),data1 = c(3,3,2,3,5,2), data2=
>> > c(3,3,2,3,5,2)))
>> >
>> > for(i in 1:length(names)){
>> > frame[, paste(names[i], "flag")] = frame[,names[i]] < 3
>> >
>> > }
>> >
>> > Now I try with data.table code:
>> > names = c("data1", "data2")
>> > frame = data.table(list(key1=as.integer(c(1,2,3,4,5,6)),
>> > key2=as.integer(c(1,2,3,2,5,6)),data1 = c(3,3,2,3,5,2), data2=
>> > c(3,3,2,3,5,2)))
>> >
>> > for(i in 1:length(names)){
>> > frame[, paste(names[i], "flag"), with=F] = as.matrix(frame[,names[i],
>> > with=F] )< 3
>> >
>> > }
>>
>> Rob, this type of question is better for the package maintainer(s)
>> directly rather than R-help. That said, one answer is to use list
>> addressing:
>>
>> for(i in 1:length(names)){
>>frame[[paste(names[i], "flag")]] = frame[[names[i]]] < 3
>> }
>>
>> Another option is to manipulate frame as a data frame and convert to
>> data.table when you need that functionality (conversion is quick).
>>
>> In the data table version, frame[,names[i], with=F] is the same as
>> frame[,names[i], drop=FALSE] (the answer is a list, not a vector).
>> Normally, it's easier to use [[]] or $ indexing to get this. Also,
>> fname[i,j] <- something assignment is still a bit buggy for
>> data.tables.
>>
>> - Tom
>>
>> Tom Short
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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://s

Re: [R] Output from test script during R CMD check

2010-03-03 Thread Dieter Menne


DarioAustralia wrote:
> 
> In the .R file I put in the tests directory, I have a number of cat("My
> text here") type statements, that explain when a certain test completed
> successfully but everything I tried so far (like putting sink(NULL) at the
> top of the .R file) hasn't worked. Does someone know what to do here ?
> 

"Hasn't worked" = "The sun is still setting"

"Does someone know what to do here ?" To achieve what?

Dieter



-- 
View this message in context: 
http://n4.nabble.com/Output-from-test-script-during-R-CMD-check-tp1576046p1576625.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] Subset using partial values

2010-03-03 Thread Newbie19_02

Hi everyone,

I would like to subset a data.frame using partial values.

For example I have the following data.frame:

PROCHI  Main_condition
1234  411
1235 4110
1236 4111
1237 I20
1238I201
1239I202

Now let's say that I use the Subset function.  Ordinarily I would use it as
follows  Subset(x, Main_condition=="411"|Main_condition=="4110" etc to get
all the 411s.

Is there a way that you can subset by only using part of the term that you
wish to subset by? 

Thanks,
Natalie
-- 
View this message in context: 
http://n4.nabble.com/Subset-using-partial-values-tp1576614p1576614.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] Three most useful R package

2010-03-03 Thread Dieter Menne


Rob Forler wrote:
> 
> And data.table because it does aggregation about 50x times faster than
> plyr
> (which I used to use a lot).
> 
> 

This is correct, from the error message its spits out one has to conclude
that is was abandoned at R-version 2.4.x

Dieter




-- 
View this message in context: 
http://n4.nabble.com/Three-most-useful-R-package-tp1575671p1576618.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Creating a timeSeries Object

2010-03-03 Thread Luis Felipe Parra
Hello I have 2000 univariate timeSeries of about 20 observations each, as
the following, I would like to store all of them in one object, sort of a
data frame or something similar. Do you know how can I do this. Thank you

Felipe Parra

GMT
 2009-10-12
2009-10-12  0.002346171
2009-10-14  0.002346171
2009-10-21  0.002346171
2009-10-28  0.002650307
2009-11-16  0.002391950
2009-11-16  0.003848032
2010-03-16  0.003848032
2010-06-17  0.008644137
2010-09-16  0.010690464
2010-12-15  0.016356718
2011-03-15  0.018496109
2011-06-16  0.023354671
2011-09-15  0.025211351
2011-12-21  0.029029900
2012-03-21  0.031173566
2012-06-21  0.033641977
2012-10-15  0.023078052
2013-04-15 -0.118415755
2013-10-15 -0.010497527
2014-04-14  0.010497527
2014-10-14 -0.010497527

[[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] sem package and growth curves

2010-03-03 Thread Chuck Cleland
On 3/2/2010 1:43 AM, Daniel Nordlund wrote:
> I have been working through the book "Applied longitudinal data analysis: 
> modeling change and event occurrence" by Judith D. Singer and John B. 
> Willett.  I have been working examples using SAS and also using it as an 
> opportunity for learning to use R for statistical analysis.
> 
> I ran into some difficulties in chapter 8 which deals with using structural 
> equation modeling.  I have tried to use the sem package to replicate the 
> problem solutions in chapter 8.  I am more familiar with RAM specifications 
> than I am with structural equations (though I am a novice at both).  The 
> solutions I have tried seem to be very sensitive to starting values 
> (especially with more complex models).  I don't know if this is just my lack 
> of knowledge in this area, or something else.
> 
> Has anyone worked out solutions to the Singer and Willett examples for 
> Chapter 8 that they would be willing to share?  I would also be interested in 
> other simple examples using sem and RAM specifications.  If anyone is 
> interested, I would also be willing to share the R code I have written for 
> other chapters in the Singer and Willett book.

Hi Dan,

  See below for my code for Models A-D in Chapter 8.  As you point out,
I find that this only works when good starting values are given.  I took
the starting values from the results given for another program (Mplus)
at the UCLA site for this text:

http://www.ats.ucla.edu/stat/examples/alda.htm

  I greatly appreciate John Fox's hard work on the sem package, but
since good starting values will generally not be available to applied
users I think the package is not as useful for these types of models as
it could be.  If anyone has approaches to specifying the models that are
less sensitive to starting values, or ways for less sophisticated users
to generate good starting values, please share.

Chuck

# Begin Code for Models A-D, Chapter 8, Singer & Willett (2003)

alc2 <-
read.table("http://www.ats.ucla.edu/stat/mplus/examples/alda/alcohol2.txt";,
sep="\t", header=FALSE)

names(alc2) <- c('ID','FEMALE','ALC1','ALC2','ALC3','PEER1','PEER2','PEER3')

alc2$UNIT <- 1

library(sem)

alc2.modA.raw <- raw.moments(subset(alc2,
select=c('ALC1','ALC2','ALC3','UNIT')))

modA <- specify.model()
I -> ALC1, NA, 1
I -> ALC2, NA, 1
I -> ALC3, NA, 1
S -> ALC1, NA, 0
S -> ALC2, NA, 0.75
S -> ALC3, NA, 1.75
UNIT -> I, Mi, 0.226
UNIT -> S, Ms, 0.036
I <-> I, Vi, NA
S <-> S, Vs, NA
I <-> S, Cis, NA
ALC1 <-> ALC1, Vd1, 0.048
ALC2 <-> ALC2, Vd2, 0.076
ALC3 <-> ALC3, Vd3, 0.077

sem.modA <- sem(modA, alc2.modA.raw, 1122, fixed.x="UNIT", raw=TRUE)

summary(sem.modA)

alc2.modB.raw <- raw.moments(subset(alc2,
select=c('FEMALE','ALC1','ALC2','ALC3','UNIT')))

modB <- specify.model()
I -> ALC1, NA, 1
I -> ALC2, NA, 1
I -> ALC3, NA, 1
S -> ALC1, NA, 0
S -> ALC2, NA, 0.75
S -> ALC3, NA, 1.75
FEMALE -> I, B1, NA
FEMALE -> S, B2, NA
UNIT -> I, Mi, 0.226
UNIT -> S, Ms, 0.036
I <-> I, Vi, NA
S <-> S, Vs, NA
I <-> S, Cis, NA
ALC1 <-> ALC1, Vd1, 0.048
ALC2 <-> ALC2, Vd2, 0.076
ALC3 <-> ALC3, Vd3, 0.077

sem.modB <- sem(modB, alc2.modB.raw, 1122, fixed.x=c("FEMALE","UNIT"),
raw=TRUE)

summary(sem.modB)

alc2.modC.raw <- raw.moments(subset(alc2,
select=c('FEMALE','ALC1','ALC2','ALC3','UNIT')))

modC <- specify.model()
I -> ALC1, NA, 1
I -> ALC2, NA, 1
I -> ALC3, NA, 1
S -> ALC1, NA, 0
S -> ALC2, NA, 0.75
S -> ALC3, NA, 1.75
FEMALE -> I, B1, NA
FEMALE -> S, NA, 0
UNIT -> I, Mi, 0.226
UNIT -> S, Ms, 0.036
I <-> I, Vi, NA
S <-> S, Vs, NA
I <-> S, Cis, NA
ALC1 <-> ALC1, Vd1, 0.048
ALC2 <-> ALC2, Vd2, 0.076
ALC3 <-> ALC3, Vd3, 0.077

sem.modC <- sem(modC, alc2.modC.raw, 1122, fixed.x=c("FEMALE","UNIT"),
raw=TRUE)

summary(sem.modC)

alc2.modD.raw <- raw.moments(subset(alc2,
select=c('PEER1','PEER2','PEER3','ALC1','ALC2','ALC3','UNIT')))

modD <- specify.model()
Ia -> ALC1, NA, 1
Ia -> ALC2, NA, 1
Ia -> ALC3, NA, 1
Sa -> ALC1, NA, 0
Sa -> ALC2, NA, 0.75
Sa -> ALC3, NA, 1.75
UNIT -> Ia, Mia, 0.226
UNIT -> Sa, Msa, 0.036
Ip -> PEER1, NA, 1
Ip -> PEER2, NA, 1
Ip -> PEER3, NA, 1
Sp -> PEER1, NA, 0
Sp -> PEER2, NA, 0.75
Sp -> PEER3, NA, 1.75
Ip -> Ia, B1, 0.799
Sp -> Ia, B2, 0.080
Ip -> Sa, B3, -0.143
Sp -> Sa, B4, 0.577
UNIT -> Ip, Mip, 0.226
UNIT -> Sp, Msp, 0.036
Ia <-> Ia, Via, 0.042
Sa <-> Sa, Vsa, 0.009
Ia <-> Sa, Cisa, -0.006
Ip <-> Ip, Vip, 0.070
Sp <-> Sp, Vsp, 0.028
Ip <-> Sp, Cisp, 0.001
ALC1 <-> ALC1, Vd1, 0.048
ALC2 <-> ALC2, Vd2, 0.076
ALC3 <-> ALC3, Vd3, 0.077
PEER1 <-> PEER1, Vd4, 0.106
PEER2 <-> PEER2, Vd5, 0.171
PEER3 <-> PEER3, Vd6, 0.129
ALC1 <-> PEER1, Cd1, 0.011
ALC2 <-> PEER2, Cd2, 0.034
ALC3 <-> PEER3, Cd3, 0.037

sem.modD <- sem(modD, alc2.modD.raw, 1122, fixed.x=c("UNIT"), raw=TRUE)

summary(sem.modD)

> Thanks,
> 
> Dan
> 
> Daniel Nordlund
> Bothell, WA USA  
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-p

Re: [R] Three most useful R package

2010-03-03 Thread Corey Sparks

3 most used packages:
1)spdep (for spatial regression/statistics)
2)car
3)survival (which is recommended, so)
3.5) survey (for analysis of complex survey samples)

Best to all,
Corey

-
Corey Sparks, PhD
Assistant Professor
Department of Demography and Organization Studies
University of Texas at San Antonio
501 West Durango Blvd
Monterey Building 2.270C
San Antonio, TX 78207
210-458-3166
corey.sparks 'at' utsa.edu
https://rowdyspace.utsa.edu/users/ozd504/www/index.htm
-- 
View this message in context: 
http://n4.nabble.com/Three-most-useful-R-package-tp1575671p1576560.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] error in R

2010-03-03 Thread Paul Hiemstra

Hi Frederik,

There is no need for the double for loop:

b[,5] <- sin(runif(5,0,2*pi))

As to your question, check the values i and k take. In the first 
iteration of the second loop k == 0, and R does not support an index 
equal to 0. The problem is in 1:n-1, this gives 0- 4, in stead do 
1:(n-1). Better is to skip the double for loop altogether and vectorization.


cheers,
Paul

frederik vanhaelst wrote:

Hi,

I want put some values in the last column of  a matrix b. But every time
again there comes the same error on the screen...

  

b <- array(0, c(5,5))
m<-matrix(runif(20,0,2*pi),5) # the sinus of this kind of values i


want put in the last column of b, m is a 5*4 matrix
  

n<-5
for(i in 1:n){


+ a2<-1
+ for(k in 1: n-1){
+ a2<-a2*sin(m[i,k])
+ }
+ b[i,n]<-a2
+ }
Error in b[i, n] <- a2 : replacement has length zero
Is there someone who see the problem?

Thanks a lot,

Frederik

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



--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~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.


  1   2   >