Re: [R] Longitudinal categorical response data

2011-03-26 Thread Rune Haubo
lmer is not designed for ordered categorical data as yours are. You could
take a look at the ordinal package which is designed for this type of data
including mixed models (function clmm) which you probably want to use.

Best,
Rune

Den 24/03/2011 21.03 skrev Rasanga Ruwanthi ruwanthi_...@yahoo.com:

 Dear List,

 I have some longitudinal data, each patient was followed at times 0, 12,
16, 24 weeks and measure severity of a illness (0-worse, 1-same, 2-better).
So, longitudinal response is categorical.  I was wondering whether lmer in R
can fit a model for this type of data. If so, how we code? Or any
other function in R that can fit this type of longitudinal data? Any
suggestion would be greatly appreciated.


 Thanks
 Ruwanthi




[[alternative HTML version deleted]]


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


[[alternative HTML version deleted]]

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


Re: [R] Matching package - Match function

2011-03-26 Thread sunny
I have figured out the solution to this. It appears that distance isn't
defined as the difference in propensity scores. Instead, this difference is
then scaled by the standard deviation of the predicted dependent-variable
values of the corresponding logistic regression, and then squared. 

Therefore, instead of checking for:

 summary(abs(logit.reg$fitted[match$index.treated]-logit.reg$fitted[match$index.control]))
  
 Min.   1st Qu.Median  Mean   3rd Qu.  Max. 
7.453e-13 2.959e-07 5.849e-07 5.842e-07 8.741e-07 1.167e-06 

the correct form is:

 summary(((logit.reg$fitted[match$index.treated]-logit.reg$fitted[match$index.control])/sd(logit.reg$fitted))^2)
 Min.   1st Qu.Median  Mean   3rd Qu.  Max. 
4.078e-18 6.426e-07 2.512e-06 3.337e-06 5.609e-06 1.000e-05 

which then gives the expected maximum value of 1e-5, as set in the
distance.tolerance option.


sunny wrote:
 
 Hi.
 
 I am using the Matching package for propensity score matching. For each
 treated unit, I want to find all control units whose propensity scores lie
 within a certain distance from the treated unit. The sample code is as
 follows:
 
 library(Matching)
 
 x - rnorm(10)
 y - rnorm(10)
 z - rbinom(10,1,0.002)
 
 logit.reg - glm(z~x+y,family=binomial(link='logit'))
 
 match -
 Match(Y=NULL,Tr=z,X=logit.reg$fitted,version='fast',ties=TRUE,M=1,distance.tolerance=1e-5)
 
 According to the function definition
 (http://sekhon.berkeley.edu/matching/Match.html):
 
 distance.tolerance: This is a scalar which is used to determine if
 distances between two observations are different from zero. Values less
 than distance.tolerance are deemed to be equal to zero. This option can be
 used to perform a type of optimal matching
 
 Thus, for each treated unit I should get all control units whose
 difference in propensity scores from the treated unit is less than 1e-5.
 However, the actual difference between the treated unit's and the control
 units' propensity is distributed as follows:
 
 summary(abs(logit.reg$fitted[match$index.treated]-logit.reg$fitted[match$index.control]))
  Min.   1st Qu.Median  Mean   3rd Qu.  Max. 
 7.453e-13 2.959e-07 5.849e-07 5.842e-07 8.741e-07 1.167e-06 
 
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Matching-package-Match-function-tp3406144p3406919.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] bwplot [lattice]: how to get different y-axis scales for each row?

2011-03-26 Thread Marius Hofert
Dear expeRts,

How can I get ...
(1) different y-axis scales for each row 
(2) while having the same y-axis scales for different columns?

I coulnd't manage to do this with relation=free [which gives (1) but not (2)].
I also tried relation=sliced, but it did not give the same y-axis scales 
within each row (see the fourth row). Further, it separates the panels.

Cheers,

Marius

## minimal example:

library(lattice)

## build example data set
dim - c(100, 6, 2, 3) # n, groups, methods, attributes
dimnames - list(n=paste(n=, seq_len(100), sep=),
 groups=paste(group=, seq_len(6), sep=),
 methods=paste(method=, seq_len(2), sep=),
 attr=paste(attribute=, seq_len(3), sep=))
set.seed(1) 
data - rexp(prod(dim))
arr - array(data=data, dim=dim, dimnames=dimnames)
arr[,2,,] - arr[,2,,]*10
arr[,4,2,2] - arr[,4,2,2]*10
z - abs(sweep(arr, 3, 1))
df - as.data.frame.table(z, responseName=error)

## box plot
bwplot(error ~ methods | attr * groups, data=df, 
   as.table=TRUE, notch=TRUE,
   scales=list(alternating=c(1,1), tck=c(1,0)))

## with relation=sliced
bwplot(error ~ methods | attr * groups, data=df, 
   as.table=TRUE, notch=TRUE,
   scales=list(alternating=c(1,1), tck=c(1,0), relation=sliced))

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] bwplot: how to get plotmath labels?

2011-03-26 Thread Marius Hofert
Dear expeRts,

How can I get plotmath-labels in the bwplot below?
As you can see, I couldn't manage to pass the expressions through the dimnames 
argument.

Cheers,

Marius


library(lattice)

## data
dim - c(100, 6, 2, 3)
dimnames - list(n=paste(n=, seq_len(100), sep=),
 groups=paste(group=, seq_len(6), sep=),
 methods=c(expression(method==1), expression(alpha=1)),
 attr=paste(attribute=, seq_len(3), sep=))
data - rexp(prod(dim))
arr - array(data=data, dim=dim, dimnames=dimnames)
z - abs(sweep(arr, 3, 1))
df - as.data.frame.table(z, responseName=error)

## box plot
bwplot(error ~ methods | attr * groups, data=df, 
   as.table=TRUE, outer=FALSE, strip=TRUE, notch=TRUE,
   scales=list(alternating=c(1,1), tck=c(1,0)))
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Error: cannot allocate vector of size

2011-03-26 Thread Paul Hiemstra
Without more detailed information I would say that R runs out of 
memory...and furthermore:


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

cheers,
Paul

On 03/25/2011 11:32 PM, mipplor wrote:

i run a model ,but i turn out to be like this. but i have run this model days
ago and it works well

whats going on here? any suggestion.


   

model1‐siarmcmcdirichletv4(data,sources,tef,concdep=0,50,5)
 

Error: cannot allocate vector of size 2.2 Gb
In addition: Warning messages:
1: In matrix(1, ncol = (numsources + numiso) * numgroups, nrow =
(siardata$iterations -  :
   Reached total allocation of 895Mb: see help(memory.size)
2: In matrix(1, ncol = (numsources + numiso) * numgroups, nrow =
(siardata$iterations -  :
   Reached total allocation of 895Mb: see help(memory.size)
3: In matrix(1, ncol = (numsources + numiso) * numgroups, nrow =
(siardata$iterations -  :
   Reached total allocation of 895Mb: see help(memory.size)
4: In matrix(1, ncol = (numsources + numiso) * numgroups, nrow =
(siardata$iterations -  :
   Reached total allocation of 895Mb: see help(memory.size)

--
View this message in context: 
http://r.789695.n4.nabble.com/Error-cannot-allocate-vector-of-size-tp3406597p3406597.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.
   



--
Paul Hiemstra, MSc
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 253 5773
http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770

currently @ KNMI
paul.hiemstra_AT_knmi.nl

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


Re: [R] linear constrained optimization in R

2011-03-26 Thread Hans W Borchers
sammyny sjain at caa.columbia.edu writes:
 
 I am trying to use
 http://rss.acs.unt.edu/Rdoc/library/stats/html/constrOptim.html in R to do
 optimization in R with some given linear constraints but not able to figure
 out how to set up the problem.
 
 For example, I need to maximize $f(x,y) = log(x) + \frac{x^2}{y^2}$ subject
 to constraints $g_1(x,y) = x+y  1$, $g_2(x,y) = x  0$ and $g_3(x,y) = y 
 0$. How do I do this in R? This is just a hypothetical example. Do not worry
 about its structure, instead I am interested to know how to set this up in
 R.
 
 thanks!
 

To get a reasonable solution, avoid coming near to x=0 and y=0. With
x = 0.0001 and y = 0.0001 constrOptim() can be called as follows:

constrOptim(c(0.25, 0.25), function(x) -log(x[1])-x[1]^2/x[2]^2, NULL, 
matrix(c(-1,1,0, -1,0,1), 3, 2), c(-1, 0.0001, 0.0001))

--Hans Werner

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

2011-03-26 Thread Michael Haenlein
Dear all,

is there a convenient way to determine the effect size for a regression
coefficient in a multiple regression model?
I have a model of the form lm(y ~ A*B*C*D) and would like to determine
Cohen's f2 (http://en.wikipedia.org/wiki/Effect_size) for each predictor
without having to do it manually.

Thanks,

Michael



Michael Haenlein
Associate Professor of Marketing
ESCP Europe
Paris, France

[[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] Effect size in multiple regression

2011-03-26 Thread Joshua Wiley
Hi Michael,

You can just fit your model, and then use anova() to get the Sum of Squares.

## fit and store model
m - lm(mpg ~ hp * wt * vs, data = mtcars)
## store ANOVA from model
msum - anova(m)
## divide all Sums of Squares by the sum() of the Sums of Squares
msum[[Sum Sq]]/sum(msum[[Sum Sq]])

do note that this will be order dependent.

HTH,

Josh


On Sat, Mar 26, 2011 at 4:03 AM, Michael Haenlein
haenl...@escpeurope.eu wrote:
 Dear all,

 is there a convenient way to determine the effect size for a regression
 coefficient in a multiple regression model?
 I have a model of the form lm(y ~ A*B*C*D) and would like to determine
 Cohen's f2 (http://en.wikipedia.org/wiki/Effect_size) for each predictor
 without having to do it manually.

 Thanks,

 Michael



 Michael Haenlein
 Associate Professor of Marketing
 ESCP Europe
 Paris, France

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



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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] NetCDF - rolling means and StdDev

2011-03-26 Thread Steve Friedman
Hello,

I am trying to come up with a routine to calculate a rolling mean and
standard deviation for three parameters stored in a NetCDF file.  The NetCDF
file contains 10 years of daily records for each of the three parameters,
and I need the statistics for each of the three parameters.

Below I include some code illustrating what I've done so far. Obviously this
approach does not get at the problem. It loops thru the data, to get to the
daily data, but stops short of trying to get the running mean/standard
deviation, an assignment that came after I developed the approach shown
here.

Where should the rolling mean and standard deviation functions be integrated
in the script, and what recommendations - approach can you offer to
accomplish this task.

I am running this on a Windows 7 machine with R 2.12.2
Thanks for taking the time to help.

Steve


setwd(C:\\Woodstorks)
getwd()


library(tis) #  includes function for leap year
library(ncdf)

 woodstorks - open.ncdf(WoodStork_Eden_2000_2009.nc)

 print(woodstorks)

  print(v2)

# next two lines create index values for temporal sequences.
 DaysToMonth365 - c(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
365)
 DaysToMonth366 - c(0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335,
366)

Lyear - isLeapYear(2000:2009) #  returns boolean TRUE FALSE vector for
years in sequence


#  next function is used latter in script see line 50
  processMonth-function(x){
print(x)
  }

 start_year- 1999

# initiates 1 year before to capture December of correct year, next line
uses the for loop to run thru
# the number of years. Here 3 is used to limit the number used in a testing
mode.

   for(t in 1:3) {
   currentYear = start_year + t
   leapYear - isLeapYear(currentYear:currentYear) #  returns boolean vector
TRUE FALSE for years in sequence
   #print(leapYear)
Days-DaysToMonth365
  if(leapYear){
 Days-DaysToMonth366
   }
  print(Days)
  data - array(data, dim = c(Days[1], 405, 265))
 for(d in 1: 226) {
   for(y in 1: 405) {
 for(x in 1:287) {
  Day = 1
  counter - 2  # first element in array
#print(paste(Day = , d))
   if(d = Days[counter]) {
   counter - counter + 1
   #print(paste(here = , t))
   processMonth(data)
   data - array(data, dim = c(Days[1], 405, 265))
Day = 1
print(Day)
 }
   else
   {
   index-c(x,y,d,t)
   count-c(1,1,1,1)
   temp-  get.var.ncdf(woodstorks, v2, start=index, count =
count)
   i - (d*405*287) + (y*287) + x #map 3d to 1dimension
   data[i] = temp[1]
   #print(data[i])
   Day - Day + 1
   print(Day)
  }
   }
   }
 }
  }

[[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] A question on glmnet analysis

2011-03-26 Thread 細田弘吉
Hi Nick,
Thanks a lot for your quick response.
Sorry for delayed response becasue of time difference between us.

(11/03/25 22:40), Nick Sabbe wrote:
  I haven't read all of your code, but at first read, it seems right.
 
  With regard to your questions:
  1. Am I doing it correctly or not?
  Seems OK, as I said. You could use some more standard code to
convert your
  data to a matrix, but essentially the results should be the same.
  Also, lambda.min may be a tad to optimistic: to correct for the reuse of
  data in crossvalidation, one normally uses the minus one se trick (I
think
  this is described in the helpfile for glmnet.cv, and that is also
present in
  the glmnet.cv return value (lambda.1se if I'm not mistaken))
Actually,

fit.1cv$lambda.min
[1] 0.036

fit.1$lambda.1se
[1] 0.121

coef(fit.1cv, s=fit.1cv$lambda.1se)
16 x 1 sparse Matrix of class dgCMatrix
 1
(Intercept) -1.1707519
V1   0.000
V2   0.000
V3   0.000
V4   0.000
V5   0.000
V6   0.000
V7   0.000
V8   0.2865651
V9   0.000
V10  0.000
V11  0.000
V12  0.000
V13  0.000
V14  0.000
V15  0.000

Do you mean that I should select one parameter model (only V8 included)
described above?

  2. Which model, I mean lasso or elastic net, should be selected? and
  why? Both models chose the same variables but different coefficient
values.
  You may want to read 'the elements of statistical learning' to find some
  info on the advantages of ridge/lasso/elnet compared. Lasso should
work fine
  in this relatively low-dimensional setting, although it depends on the
  correlation structure of your covariates.
  Depending on your goals, you may want to refit a standard logistic
  regression with only the variables selected by the lasso: this
avoids the
  downward bias that is in (just about) every penalized regression.
fit1.glm - glm(outcome ~ x1+x2+x3+x4, family=binomial, data=MyData)

summary(fit1.glm)

Call:
glm(formula = outcome ~ x1+x2+x3+x4, family = binomial, data = MyData)

Deviance Residuals:
   Min  1Q  Median  3Q Max
-1.806  -0.626  -0.438  -0.191   2.304

Coefficients:
   Estimate Std. Error z value Pr(|z|)
(Intercept)  -1.855  0.393   -4.72  2.3e-06 ***
x11.037  0.5581.86   0.0630 .
x21.031  0.3263.16   0.0016 **
x3   -0.591  0.323   -1.83   0.0678 .
x40.347  0.2931.18   0.2368
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 114.717  on 103  degrees of freedom
Residual deviance:  87.178  on  99  degrees of freedom
AIC: 97.18

Number of Fisher Scoring iterations: 5

library(epicalc)
logistic.display(fit1.glm)

Logistic regression predicting postopDWI_HI2

crude OR(95%CI)   adj. OR(95%CI)P(Wald's test)
P(LR-test)
x1 1 vs 0   2.45 (0.98,6.13)  2.82 (0.95,8.42)  0.063
0.059


x2  2.76 (1.6,4.77)   2.8 (1.48,5.31)   0.002  
0.001


x3  0.64 (0.36,1.14)  0.55 (0.29,1.04)  0.068
0.051


x4  2.07 (1.28,3.34)  1.41 (0.8,2.51)   0.237
0.234


Log-likelihood = -43.5889
No. of observations = 104
AIC value = 97.1777

The AUC of this glm model is 0.81, which means good predictive ability.
My next question, however, is which coefficients value should I select,
glmnet model or glm model for presentation?  Is it O.K. to select
variables by glmnet and present coefficients (odds ratio) by glm?

 
  3. Is it O.K. to calculate odds ratio by exp(coefficients)? And how can
  you calculate 95% confidence interval of odds ratio?
  Or 95%CI is meaningless in this kind of analysis?
  At this time, confidence intervals for lasso/elnet in GLM settings is an
  open problem (the reason being that the L1 penalty is not
differentiable).
  Some 'solutions' exist (bootstrap, for one), but they have all been
shown to
  have (statistical) properties that make them - at the least -
doubtful. I
  know, because I'm working on this. Short answer: there is no way to
do this
  (at this time).
Well, thank you for a clear-cut answer. :-)

 
  HTH (and hang on there in Japan),
  Nick Sabbe
Your answers helped me very much.
Actually, I live in the west part of Japan and fortunately had no damage
around neighborhodd by the earthquake. Now we are worried about the
nuclear power plant...

Best regards,
KH

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


Re: [R] A question on glmnet analysis

2011-03-26 Thread 細田弘吉

(11/03/26 0:12), Mike Marchywka wrote:


Would you post your data or if you did I missed it?


Sorry, I did not. This is patients' data and I have to obtain some 
permission from my office to send it, so ...



I don't have an answer for you but curious as I was
interested in similar analyses with mostly continuous prognostic
factors and continuous outcome ( survival). My interest
was making a blind test to see if analysis could separate drug
and treatment patients in a triple blind test.
The end result would create preidctions ( drug or treeatment for
each patient) and that would need to be compared to
real assignments and checked for significance.


I want to divide my data into training and test data. But I only have 
104 observations. That's a problem.


Best regards,
KH

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

2011-03-26 Thread kitty
Does anyone know if it is possible to get the length of the log phase (the
main growth phase) from a grofit logistic model?

I can get the lag phase length, maximum growth and max rate of growth, but I
also want to know the length of the log phase (ie, for how long do the
bacteria grow exponentially?)

Thank you for any help in advance

[[alternative HTML version deleted]]

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


Re: [R] Error: cannot allocate vector of size

2011-03-26 Thread Uwe Ligges



On 25.03.2011 23:32, mipplor wrote:

i run a model ,but i turn out to be like this. but i have run this model days
ago and it works well

whats going on here? any suggestion.



If it worked exactly the way before on the same machine, you probably 
have too huge objects in your workspace.


Uwe Ligges





model1‐siarmcmcdirichletv4(data,sources,tef,concdep=0,50,5)

Error: cannot allocate vector of size 2.2 Gb
In addition: Warning messages:
1: In matrix(1, ncol = (numsources + numiso) * numgroups, nrow =
(siardata$iterations -  :
   Reached total allocation of 895Mb: see help(memory.size)
2: In matrix(1, ncol = (numsources + numiso) * numgroups, nrow =
(siardata$iterations -  :
   Reached total allocation of 895Mb: see help(memory.size)
3: In matrix(1, ncol = (numsources + numiso) * numgroups, nrow =
(siardata$iterations -  :
   Reached total allocation of 895Mb: see help(memory.size)
4: In matrix(1, ncol = (numsources + numiso) * numgroups, nrow =
(siardata$iterations -  :
   Reached total allocation of 895Mb: see help(memory.size)

--
View this message in context: 
http://r.789695.n4.nabble.com/Error-cannot-allocate-vector-of-size-tp3406597p3406597.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] bwplot: how to get plotmath labels?

2011-03-26 Thread David Winsemius


On Mar 26, 2011, at 4:47 AM, Marius Hofert wrote:


Dear expeRts,

How can I get plotmath-labels in the bwplot below?
As you can see, I couldn't manage to pass the expressions through  
the dimnames

argument.


It would have been helpful, and may still be necessary, for you to  
explain more fully what you were attempting to do. See if this effort  
was informative.



Marius

library(lattice)

## data
dim - c(100, 6, 2, 3)


# did not find the dimnames object useful
# at least to the extent I understood the question


data - rexp(prod(dim))
arr - array(data=data, dim=dim, dimnames=dimnames)
z - abs(sweep(arr, 3, 1))
df - as.data.frame.table(z, responseName=error)

## box plot
bwplot(error ~ methods | attr * groups, data=df,
  as.table=TRUE, outer=FALSE, strip=TRUE, notch=TRUE,
  scales=list(alternating=c(1,1), tck=c(1,0)))


 bwplot(error ~ methods | attr * groups, data=df,
  as.table=TRUE, outer=FALSE, strip=TRUE, notch=TRUE,
  scales=list(y=list(alternating=TRUE,
  tck=c(1,0)),
  x=list(labels=c( expression(method == 1),  
expression(alpha == 1)) )

) )



David Winsemius, MD
West Hartford, CT

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


[R] Free license for xlsReadWritePro

2011-03-26 Thread Hans-Peter Suter
Some years ago I travelled through Libya and it's with much emotion
that I follow the news.

The license below is dedicated to Mohammed Nabbous and will let you
run xlsReadWritePro for free (Windows, R 32-bit):

library( xlsReadWritePro )
xls.lic( action = register,
 miscData = list(
User = R.I.P. Mohammed Nabbous,
Company = Let's hope that Libya will become free,
Product = xlsReadWritePro,
Date = 2011-03-19,
LicenseType = SingleUser,
Count = 1,
Key = 76991137f5f554a288e8cee343a24722,
WhereToStore = ProgramFolder ) )

Info/download at http://swissr.org. Direct download links at
http://dl.dropbox.com/u/2602516/swissrpkg/index.html. Support
(tracker) at http://dev.swissr.org/.

Let's hope that Libya will become free,

Hans-Peter

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


Re: [R] bwplot: how to get plotmath labels?

2011-03-26 Thread Marius Hofert
Dear David,

many thanks, that was it.

Cheers,

Marius

On 2011-03-26, at 18:04 , David Winsemius wrote:

 
 On Mar 26, 2011, at 4:47 AM, Marius Hofert wrote:
 
 Dear expeRts,
 
 How can I get plotmath-labels in the bwplot below?
 As you can see, I couldn't manage to pass the expressions through the 
 dimnames
 argument.
 
 It would have been helpful, and may still be necessary, for you to explain 
 more fully what you were attempting to do. See if this effort was informative.
 
 Marius
 
 library(lattice)
 
 ## data
 dim - c(100, 6, 2, 3)
 
 # did not find the dimnames object useful
 # at least to the extent I understood the question
 
 data - rexp(prod(dim))
 arr - array(data=data, dim=dim, dimnames=dimnames)
 z - abs(sweep(arr, 3, 1))
 df - as.data.frame.table(z, responseName=error)
 
 ## box plot
 bwplot(error ~ methods | attr * groups, data=df,
  as.table=TRUE, outer=FALSE, strip=TRUE, notch=TRUE,
  scales=list(alternating=c(1,1), tck=c(1,0)))
 
 bwplot(error ~ methods | attr * groups, data=df,
  as.table=TRUE, outer=FALSE, strip=TRUE, notch=TRUE,
  scales=list(y=list(alternating=TRUE,
  tck=c(1,0)),
  x=list(labels=c( expression(method == 1), expression(alpha 
 == 1)) )
) )
 
 
 
 David Winsemius, MD
 West Hartford, CT
 

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


[R] Building a matrix so that matrix(r, c)-matrix(c, r) with No For Loops

2011-03-26 Thread Brian Pellerin
Hello,

I would like to take advantage of the upper.tri() function here but I don't
know exactly. Here is some working code...
i-5
fi-matrix(0,nrow=i,ncol=i)
for(r in 1:i){
for(c in 1:i){
if(r==c){
 fi[r,c]-1
}else if(rc){
fi[r,c]-1-runif(1)^.5
 }else{
fi[r,c]-fi[c,r]
}
 }
}

So far I know I can simplify this code to 5 lines (no for loops):
i-5
fi-matrix(nrow=i,ncol=i)
fi[upper.tri(fi)]-1-runif(length(fi[upper.tri(fi)]))^.5
diag(fi)-1
fi[lower.tri(fi)]-fi[upper.tri(fi)]#This entry is not correct. fi[r,c] ! ==
fi[c,r]

Any suggestions?

Sincerely,
Brian

[[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] Tinn-R looses connection to R (Windows Vista)

2011-03-26 Thread Felipe Carrillo
Nutter, Benjamin NutterB at ccf.org writes:

 
 I've noticed it, but I haven't looked into it much since I rarely work
 on Vista.  I have found that opening R before I open Tinn-R tends to
 work better than using Tinn-R to open the preferred GUI.
 
 Benjamin 
 
 -Original Message-
 From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
project.org]
 On Behalf Of Agi Richard
 Sent: Wednesday, November 17, 2010 4:43 AM
 To: R-help at r-project.org
 Subject: [R] Tinn-R looses connection to R (Windows Vista)
 
 Hi everyone,
 I wonder, if anyone can help me with this annoying issue, although it is
 related to Tinn-R and Windows Vista...
 I am running R 2.11.1 and Tinn-R 2.3.5.2 together. I saved 2 R-hotkeys:
 ALT+A for sending the whole content of one file and ALT+S for a 
 ALT+selection
 from one file from Tinn-R to R. Everything works fine with other windows
 versions, also with Vista at the beginning of every session, but after a
 certain time (not always the same, neither the number of times, that I
 used the hotkeys is the same, so it occurs randomly, but quite fast,
 lets say on average within half an hour - 2hs) ALT+S does not work
 anymore, but instead this hotkey opens the start menue of Vista!! (The
 same function the windows key has!) I would be very happy, if anyone has
 an idea why this could be!! Is it related to R, to Tinn-R or to Vista?
 Thank you very very much in advance!
 Carol
 
 Hi:
Did you fix the problem? I just recently started experiencing the same thing 
with my laptop(windows vista). I don't have that problem with my desktop which 
it still has windows XP.
Thanks

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Sampling Weights in HB Choice Modelling (e.g., rhierMnlRwMixture)

2011-03-26 Thread Klaus
Is anyone familiar with a way to account for sampling weights (e.g., in order
to cope with selection bias) for individual respondents using the bayesm
package (e.g., rhierMnlRwMixture)?

In the regular MNL this can easily be done in STATA using the mlogit
function with pweights option. However, I am unfamiliar with a way to do it
in HB estimation. 

Any help or hints are appreciated. 

Best, Klaus

--
View this message in context: 
http://r.789695.n4.nabble.com/Sampling-Weights-in-HB-Choice-Modelling-e-g-rhierMnlRwMixture-tp3407486p3407486.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] Sweave and Textwrangler

2011-03-26 Thread Christopher Desjardins
Hi,
I am trying to get TextWrangler to work with LaTeX and Sweave. Ideally
I would call a script from TextWrangler that would run Sweave on a
document, then LaTeX (using SyncTeX), and finally
open the corresponding pdf in Skim. Of course I don't always need to
run Sweave and would be looking for the option of LaTeX - Open.  I
found this http://www.xs4all.nl/~msneep/latex/ but it doesn't work for
me as it gives me an error. Something similar to do that would be
ideal. Additionally the option to use BibTeX would be great too.

Additionally, I tried this
http://www.stat.umn.edu/~arendahl/computing/index.html
and Sweave.sh script and trying to alter that (and the *.engine files) to
work with TextWrangler but to no avail.

Does anyone do this and have a tip they could give me? Sorry if this is
off-topic (if so please reply to me off the list).

Thanks!
Chris

[[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] Building a matrix so that matrix(r, c)-matrix(c, r) with No For Loops

2011-03-26 Thread David Winsemius


On Mar 26, 2011, at 9:44 AM, Brian Pellerin wrote:


Hello,

I would like to take advantage of the upper.tri() function here but  
I don't

know exactly. Here is some working code...
i-5
fi-matrix(0,nrow=i,ncol=i)
for(r in 1:i){
for(c in 1:i){
if(r==c){
fi[r,c]-1
}else if(rc){
fi[r,c]-1-runif(1)^.5
}else{
fi[r,c]-fi[c,r]
}
}
}

So far I know I can simplify this code to 5 lines (no for loops):
i-5
fi-matrix(nrow=i,ncol=i)
fi[upper.tri(fi)]-1-runif(length(fi[upper.tri(fi)]))^.5
diag(fi)-1
fi[lower.tri(fi)]-fi[upper.tri(fi)]#This entry is not correct.  
fi[r,c] ! ==

fi[c,r]


I've always found using the upper.tri and lower.tri functions error  
prone in my hands, because they are really logical matrices for  
selection rather than returning values as I naively expect. Try this:


i-5
fi-diag(1,i,i)
fi[upper.tri(fi)]-1-runif(length(fi[upper.tri(fi)]))^.5
fi[lower.tri(fi)]-t(fi)[lower.tri(fi)]
fi

It may seem odd to use lower.tri(fi) inside `[ ]` since the values of  
`fi` in the lower triangle are all zero, but you are really just using  
it to extract from `t(fi)`.


--
David.



Any suggestions?

Sincerely,
Brian

[[alternative HTML version deleted]]

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] Sweave and Textwrangler

2011-03-26 Thread Duncan Murdoch

On 11-03-26 10:58 AM, Christopher Desjardins wrote:

Hi,
I am trying to get TextWrangler to work with LaTeX and Sweave. Ideally
I would call a script from TextWrangler that would run Sweave on a
document, then LaTeX (using SyncTeX), and finally
open the corresponding pdf in Skim. Of course I don't always need to
run Sweave and would be looking for the option of LaTeX -  Open.  I
found this http://www.xs4all.nl/~msneep/latex/ but it doesn't work for
me as it gives me an error. Something similar to do that would be
ideal. Additionally the option to use BibTeX would be great too.

Additionally, I tried this
http://www.stat.umn.edu/~arendahl/computing/index.html
and Sweave.sh script and trying to alter that (and the *.engine files) to
work with TextWrangler but to no avail.

Does anyone do this and have a tip they could give me? Sorry if this is
off-topic (if so please reply to me off the list).


I don't use TextWrangler, but I got TeXShop working pretty nicely with 
Sweave.  The engine file simply does this:


Rscript -e patchDVI::SweavePDF(  '$1' )

The patchDVI package is on R-forge here:

https://r-forge.r-project.org/R/?group_id=233

This needs a very recent version of Sweave.sty if you have a recent 
pdflatex.


You say you don't want to run Sweave every time, and want to sometimes 
run only Latex.  I don't see how this would be desirable, because your 
edits to the .tex file are lost the next time you run Sweave, but the 
above engine skips Sweave if it is given a .tex file instead of 
something it recognizes as Sweave input.


I gave a little tutorial on this recently; it's online here:

http://www.umanitoba.ca/statistics/seminars/2011/3/4/duncan-murdoch-using-sweave-R/

The last section of the sample document shows how to set up TeXShop.  I 
suspect setting up TextWrangler would be somewhat similar.


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] 2 questions about probplot in package e1071

2011-03-26 Thread Thomas Adams
 The contributed package e1071 does exactly what I want except that I 
need to have (1) the abscissa and ordinate axes swapped, with the 
probability scale on the bottom and the quantiles scale on the LHS. 
Using the following example:


library(e1071)
x - rnorm(100, mean=5)
probplot(x, line=FALSE)

and (2) I need to have lines connecting the plotted symbols, as you get 
with:


x-log(seq(1:20))
plot(x,type='b')

How can I do these two things; I've done a bunch of searching, but have 
not come across anything yet.


Regards,
Tom

--
Thomas E Adams
National Weather Service
Ohio River Forecast Center
1901 South State Route 134
Wilmington, OH 45177

EMAIL:  thomas.ad...@noaa.gov

VOICE:  937-383-0528
FAX:937-383-0033

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

2011-03-26 Thread Quan Zhou
Hi
How can I return the index of sort, when I use R function sort?
or any other sorting functions in R
For example, I sorted a vector, but R just return the sorted value without
giving me the original index of these data.

Thanks a lot.

[[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] round number

2011-03-26 Thread Alfredo Alessandrini
Hi,

 a - 4

 a*0.2
[1] 0.8

ok!!

Is there a method to obtain this:

 a*0.2
[1] 0.80

I need to round the number also with the zero.



Thanks in advance,

Alfredo

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


Re: [R] 2 questions about probplot in package e1071

2011-03-26 Thread David Winsemius


On Mar 26, 2011, at 4:06 PM, Thomas Adams wrote:

The contributed package e1071 does exactly what I want except that I  
need to have (1) the abscissa and ordinate axes swapped, with the  
probability scale on the bottom and the quantiles scale on the LHS.  
Using the following example:


library(e1071)
x - rnorm(100, mean=5)
probplot(x, line=FALSE)

and (2) I need to have lines connecting the plotted symbols, as you  
get with:


x-log(seq(1:20))
plot(x,type='b')

How can I do these two things; I've done a bunch of searching, but  
have not come across anything yet.


The code is all there. Just rework it. Type:

probplot

then...

probplot2 - function(

and paste in your re-worked code that swaps labels,  the x and y  
vectors,  and change axis(1) to axis 2 and axis(2, ...) to  
axis(1,  ...)  a few other swaps like abline(h=...)  to abline(v=...)


--

David Winsemius, MD
West Hartford, CT

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


Re: [R] index of sort

2011-03-26 Thread David Winsemius


On Mar 26, 2011, at 2:03 PM, Quan Zhou wrote:


Hi
How can I return the index of sort, when I use R function sort?
or any other sorting functions in R
For example, I sorted a vector, but R just return the sorted value  
without

giving me the original index of these data.


You seem to be looking for:

?order

--

David Winsemius, MD
West Hartford, CT

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


Re: [R] 2 questions about probplot in package e1071

2011-03-26 Thread Thomas Adams

 David,

Thanks! This is very helpful! I'm still very much a novice…

Tom

On 3/26/11 4:11 PM, David Winsemius wrote:


On Mar 26, 2011, at 4:06 PM, Thomas Adams wrote:

The contributed package e1071 does exactly what I want except that I 
need to have (1) the abscissa and ordinate axes swapped, with the 
probability scale on the bottom and the quantiles scale on the LHS. 
Using the following example:


library(e1071)
x - rnorm(100, mean=5)
probplot(x, line=FALSE)

and (2) I need to have lines connecting the plotted symbols, as you 
get with:


x-log(seq(1:20))
plot(x,type='b')

How can I do these two things; I've done a bunch of searching, but 
have not come across anything yet.


The code is all there. Just rework it. Type:

probplot

then...

probplot2 - function(

and paste in your re-worked code that swaps labels, the x and y 
vectors, and change axis(1) to axis 2 and axis(2, ...) to axis(1, ...) 
a few other swaps like abline(h=...) to abline(v=...)





--
Thomas E Adams
National Weather Service
Ohio River Forecast Center
1901 South State Route 134
Wilmington, OH 45177

EMAIL:  thomas.ad...@noaa.gov

VOICE:  937-383-0528
FAX:937-383-0033

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


Re: [R] round number

2011-03-26 Thread Duncan Murdoch

On 11-03-26 2:05 PM, Alfredo Alessandrini wrote:

Hi,


a- 4



a*0.2

[1] 0.8

ok!!

Is there a method to obtain this:


a*0.2

[1] 0.80


It is easy to print values with trailing zeros, but I think it's hard to 
make it the default.  The sprintf() function is the one I'd use for the 
formatting:


sprintf(%.2f, a*0.2)

(or put noquote() around it if you don't like the quoted result).

Duncan Murdoch



I need to round the number also with the zero.



Thanks in advance,

Alfredo

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

2011-03-26 Thread Jorge Ivan Velez
Hi Alfredo,

Try

noquote(sprintf(%.2f, a*.2))

HTH,
Jorge


On Sat, Mar 26, 2011 at 2:05 PM, Alfredo Alessandrini  wrote:

 Hi,

  a - 4

  a*0.2
 [1] 0.8

 ok!!

 Is there a method to obtain this:

  a*0.2
 [1] 0.80

 I need to round the number also with the zero.



 Thanks in advance,

 Alfredo

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

2011-03-26 Thread Petr Savicky
On Sat, Mar 26, 2011 at 07:05:40PM +0100, Alfredo Alessandrini wrote:
 Hi,
 
  a - 4
 
  a*0.2
 [1] 0.8
 
 ok!!
 
 Is there a method to obtain this:
 
  a*0.2
 [1] 0.80
 
 I need to round the number also with the zero.

Hi.

Try the following

  formatC(a*0.2, digits=2, format=f)
  [1] 0.80

  noquote(formatC(a*0.2, digits=2, format=f))
  [1] 0.80

The two-digit form 0.80 is used also if a vector is printed
and some other component requires 2 digits. For example

  c(a*0.2, 0.01)
  [1] 0.80 0.01

Hope this helps.

Petr Savicky.

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

2011-03-26 Thread Bulent Arikan
Hi,
I am working on some line charts and although I have a lot of resources, I
cannot seem to find an answer to this question: how can I set the
incrementation of values on the x-axis values so that I can see all the
groups on this axis. Right now, R puts them at increments of 2 (i.e., 2, 4,
6, 8, 10, 12). I need to see all, from 1 to 12.

Thank you!

-- 
BÜLENT

[[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] line graph question

2011-03-26 Thread Jim Lemon

On 03/27/2011 09:21 AM, Bulent Arikan wrote:

Hi,
I am working on some line charts and although I have a lot of resources, I
cannot seem to find an answer to this question: how can I set the
incrementation of values on the x-axis values so that I can see all the
groups on this axis. Right now, R puts them at increments of 2 (i.e., 2, 4,
6, 8, 10, 12). I need to see all, from 1 to 12.


Hi Bulent,
First try:

plot(...,xaxt=n,...)
axis(1,at=1:12,labels=1:12)

and if they are still not there, look at staxlab in the plotrix package.

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] line graph question

2011-03-26 Thread Phil Spector

Bulent -
   Many characteristics of plots are determined by the graphical
parameters documented in the help file for the par function.
In this case, the xaxp parameter should be useful.  Compare

plot(1:12,1:12)

with

plot(1:12,1:12,xaxp=c(0,12,12))

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


On Sat, 26 Mar 2011, Bulent Arikan wrote:


Hi,
I am working on some line charts and although I have a lot of resources, I
cannot seem to find an answer to this question: how can I set the
incrementation of values on the x-axis values so that I can see all the
groups on this axis. Right now, R puts them at increments of 2 (i.e., 2, 4,
6, 8, 10, 12). I need to see all, from 1 to 12.

Thank you!

--
B?LENT

[[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] simple if question

2011-03-26 Thread Sebastián Daza

Hi everyone,
I have just got different samples from a dataframe (independent and 
exclusive, there aren't common elements among them). I want to create a 
variable that indicate the sampling selection of the elements in the 
original dataframe (for example, 0 = no selected, 1= sample 1, 2=sample 
2, etc.).


I have tried to do it with ifelse command, but the problem is that the 
second line replaces the values of the first line, and I haven't been 
able to do it with the if command (I got this error: In if (data$school 
%in% sample1) { :

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

data$selection - ifelse(data$school %in% sample1, 1, 0)
data$selection - ifelse(data$school %in% sample2, 2, 0)

Any ideas?
Thank you in advance.

--
Sebastián Daza
sebastian.d...@gmail.com

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


Re: [R] Two matrix loop

2011-03-26 Thread Thomas Levine
This way uses a three-dimensional array instead of the nested apply.
It seems to take the same amount of time, even on larger datasets, but
it may give you ideas.

distance=function(x) daisy(x, metric = 'gower')

persons=array(dim=c(2,nrow(donor)*nrow(receiver),ncol(receiver)))
persons[1,,]=donor[rep(1:nrow(donor),each=nrow(receiver)),]
persons[2,,]=receiver[rep(1:nrow(receiver),nrow(donor)),]

matrix(apply(persons,2,distance),,nrow(donor))

Tom

On Thu, Mar 24, 2011 at 8:23 AM, Stefan Petersson
stefan.peters...@inizio.se wrote:

 Hi,

 I'm trying to create a distance matrix. And it works out somewhat ok. 
 However, I suspect that there are
 some efficiency issues with my efforts. Plz have a look at this:

 donor - matrix(c(3,1,2,3,3,1,4,3,5,1,3,2), ncol=4)
 receiver -
 matrix(c(1,4,3,2,4,3,1,5,1,3,2,1,4,5,3,5,1,3,2,4,5,1,2,3,1,4,5,5,1,2,1,3,4,3,2,5,5,1,4,2,5,4,3,2),
  ncol=4)

 The above creates my two matrices. I have three donors, and eleven receivers 
 (rows), with four
 measures (columns) in each matrix.

 And now, I want to apply the daisy() function from the cluster library, to 
 calculate distances between my
 three donors, and eleven receivers. The end result should be a 11x3 matrix 
 with distances between the
 units from the two matrices. I can calculate one distance measure (ie donor 1 
 and receiver 1). Like this:

 library(cluster)
 daisy(rbind(donor[1,], receiver[1,]), metric = 'gower')

 My first attempt was a simple nested for-loop. But that one was discarded 
 after reading up on efficiency
 issues with for-looping. So I turned to 'apply' with this result:

 apply(donor, 1, function(b) apply(receiver, 1, function(a) daisy(rbind(b, a), 
 metric = 'gower')))

      [,1] [,2] [,3]
  [1,] 1.00 0.50 0.75
  [2,] 1.00 0.75 0.75
  [3,] 0.75 1.00 1.00
  [4,] 0.50 0.75 0.75
  [5,] 0.75 1.00 0.75
  [6,] 0.75 1.00 0.50
  [7,] 0.75 0.50 0.75
  [8,] 1.00 1.00 1.00
  [9,] 1.00 0.75 1.00
 [10,] 0.75 0.50 1.00
 [11,] 0.75 1.00 0.25

 However, something tells me that there is a simpler (more efficient) way of 
 doing this. I've been reading
 up on the Matrix library, but I'm having trouble understanding the 
 functions...

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

2011-03-26 Thread David Winsemius


On Mar 26, 2011, at 7:05 PM, Sebastián Daza wrote:


Hi everyone,
I have just got different samples from a dataframe (independent and  
exclusive, there aren't common elements among them). I want to  
create a variable that indicate the sampling selection of the  
elements in the original dataframe (for example, 0 = no selected, 1=  
sample 1, 2=sample 2, etc.).


I have tried to do it with ifelse command, but the problem is that  
the second line replaces the values of the first line, and I haven't  
been able to do it with the if command (I got this error: In if (data 
$school %in% sample1) { :

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



Nested ifelse's should work. There may be a limit to nested depth.

data$selection - ifelse(data$school %in% sample1, 1,   # else
 ifelse(data$school %in% sample2, 2, #else
  0) )



Any ideas?
Thank you in advance.

--
Sebastián Daza
sebastian.d...@gmail.com

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


David Winsemius, MD
West Hartford, CT

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


[R] Multiple plots with one legend

2011-03-26 Thread mavkoup
Hi,

I've created 3 plots one under the other, and want to include a legend on
the right that spans the height of all 3 plots.

How can I do this?

Thanks!

--
View this message in context: 
http://r.789695.n4.nabble.com/Multiple-plots-with-one-legend-tp3408537p3408537.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] simple if question

2011-03-26 Thread Thomas Levine
Posting some sample data would help, but I think something like this
is what you want

data[data$school=='Cornell University',]

For example

CO2[CO2$Type=='Quebec',]

Tom

2011/3/26 Sebastián Daza sebastian.d...@gmail.com:
 Hi everyone,
 I have just got different samples from a dataframe (independent and
 exclusive, there aren't common elements among them). I want to create a
 variable that indicate the sampling selection of the elements in the
 original dataframe (for example, 0 = no selected, 1= sample 1, 2=sample 2,
 etc.).

 I have tried to do it with ifelse command, but the problem is that the
 second line replaces the values of the first line, and I haven't been able
 to do it with the if command (I got this error: In if (data$school %in%
 sample1) { :
  the condition has length  1 and only the first element will be used)

 data$selection - ifelse(data$school %in% sample1, 1, 0)
 data$selection - ifelse(data$school %in% sample2, 2, 0)

 Any ideas?
 Thank you in advance.

 --
 Sebastián Daza
 sebastian.d...@gmail.com

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


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


Re: [R] Multiple plots with one legend

2011-03-26 Thread David Winsemius


On Mar 26, 2011, at 7:06 PM, mavkoup wrote:


Hi,

I've created 3 plots one under the other, and want to include a  
legend on

the right that spans the height of all 3 plots.


?mtext
# with the `las` parameter for rotation

Or you can use:

text(x,y,  some text, srt=-90,xpd=NA )





--

David Winsemius, MD
West Hartford, CT

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


Re: [R] Multiple plots with one legend

2011-03-26 Thread mavkoup
Ok I think I can figure that out. Which leads me to a further question. My 3
plots contain 10 time series, each with a different name and color. Can I
create the legend such that it has a line of the correct color follow by the
name of the series? I.e.

line(with color1) NAME 1
line(with color2) NAME 2
...

I have a vector of colors I'm using and a vector of names.

Thanks

--
View this message in context: 
http://r.789695.n4.nabble.com/Multiple-plots-with-one-legend-tp3408537p3408646.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] Coordinates of the text region

2011-03-26 Thread Francois Rousseu

Hello R people
 
Is there a way to get the coordinates of the text region (coordinates of the 
four corners for example) when using the text function? I'm looking for a way 
that does not make use of interactive function like locator. My goal is to 
determine the position of other structures in a graphic so that they don't 
overlap with the text.
 
Thanks
Francois Rousseu
  
[[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] Multiple plots with one legend

2011-03-26 Thread David Winsemius


On Mar 26, 2011, at 8:27 PM, mavkoup wrote:

Ok I think I can figure that out. Which leads me to a further  
question. My 3
plots contain 10 time series, each with a different name and color.  
Can I
create the legend such that it has a line of the correct color  
follow by the

name of the series? I.e.


plots and therefore legends in R can take many forms. Have your  
read the Posting Guide's recommendations on how to submit a  
reproducible example yet? That would be particularly important if you  
have three different plots on the same page.




line(with color1) NAME 1
line(with color2) NAME 2
...

I have a vector of colors I'm using and a vector of names.


--

David Winsemius, MD
West Hartford, CT

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


Re: [R] Coordinates of the text region

2011-03-26 Thread David Winsemius


On Mar 26, 2011, at 8:39 PM, Francois Rousseu wrote:



Hello R people

Is there a way to get the coordinates of the text region  
(coordinates of the four corners for example)


What text region are you talking about?

when using the text function? I'm looking for a way that does not  
make use of interactive function like locator. My goal is to  
determine the position of other structures in a graphic so that they  
don't overlap with the text.


The plotrix package and the rms package have functions for avoiding  
plotted points but you seem to be looking for something else.


--

David Winsemius, MD
West Hartford, CT

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


Re: [R] Coordinates of the text region

2011-03-26 Thread Francois Rousseu

Let's say I do the following:
 
plot(0,0,type=n,xlim=c(0,10),ylim=c(0,10))
rect(4,5,5,6,border=black,col=white)
text(4.5,5.5,species,cex=2)
 
I would like to be able to determine a rectangle size that will be able to 
contain the text species. I'm working on a function using multiple lines and 
boxes where text of varying length has to be written.
 
Francois
 

 
 
 On Mar 26, 2011, at 8:39 PM, Francois Rousseu wrote:
 
 
  Hello R people
 
  Is there a way to get the coordinates of the text region 
  (coordinates of the four corners for example)
 
 What text region are you talking about?
 
  when using the text function? I'm looking for a way that does not 
  make use of interactive function like locator. My goal is to 
  determine the position of other structures in a graphic so that they 
  don't overlap with the text.
 
 The plotrix package and the rms package have functions for avoiding 
 plotted points but you seem to be looking for something else.
 
 -- 
 
 David Winsemius, MD
 West Hartford, CT
 
  
[[alternative HTML version deleted]]

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


Re: [R] Coordinates of the text region

2011-03-26 Thread jim holtman
take a look at 'textbox' in plotrix.

On Sat, Mar 26, 2011 at 9:05 PM, Francois Rousseu
francoisrous...@hotmail.com wrote:

 Let's say I do the following:

 plot(0,0,type=n,xlim=c(0,10),ylim=c(0,10))
 rect(4,5,5,6,border=black,col=white)
 text(4.5,5.5,species,cex=2)

 I would like to be able to determine a rectangle size that will be able to 
 contain the text species. I'm working on a function using multiple lines and 
 boxes where text of varying length has to be written.

 Francois




 On Mar 26, 2011, at 8:39 PM, Francois Rousseu wrote:

 
  Hello R people
 
  Is there a way to get the coordinates of the text region
  (coordinates of the four corners for example)

 What text region are you talking about?

  when using the text function? I'm looking for a way that does not
  make use of interactive function like locator. My goal is to
  determine the position of other structures in a graphic so that they
  don't overlap with the text.

 The plotrix package and the rms package have functions for avoiding
 plotted points but you seem to be looking for something else.

 --

 David Winsemius, MD
 West Hartford, CT


        [[alternative HTML version deleted]]

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




-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

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


Re: [R] Multiple plots with one legend

2011-03-26 Thread jim holtman
You can use 'layout' to create 4 plot areas: the 3 plot you currently
have, and one for the legend.  Try this to see what happens:

 x - cbind(rbind(1,2,3), 4)
 layout(x, width = c(5,1))
 layout.show(4)


On Sat, Mar 26, 2011 at 7:06 PM, mavkoup mavk...@hotmail.com wrote:
 Hi,

 I've created 3 plots one under the other, and want to include a legend on
 the right that spans the height of all 3 plots.

 How can I do this?

 Thanks!

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Multiple-plots-with-one-legend-tp3408537p3408537.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.




-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

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


Re: [R] library(foreign) read.spss warning

2011-03-26 Thread Matt Shotwell
There is some information about this subtype in the PSPP source code,
and for other subtypes not yet implemented by read.spss. The PSPP source
code indicates that this subtype consists of Value labels for long
strings, which isn't very illuminating to me (probably because I don't
use PSPP, or SPSS, though I increasingly have need to import SPSS data
files). Copied below are the relevant bits.

-Matt

From (the PSPP source file) src/data/sys-file-reader.c:

enum
  {
/* subtypes 0-2 unknown */
EXT_INTEGER   = 3,  /* Machine integer info. */
EXT_FLOAT = 4,  /* Machine floating-point info. */
EXT_VAR_SETS  = 5,  /* Variable sets. */
EXT_DATE  = 6,  /* DATE. */
EXT_MRSETS= 7,  /* Multiple response sets. */
EXT_DATA_ENTRY= 8,  /* SPSS Data Entry. */
/* subtypes 9-10 unknown */
EXT_DISPLAY   = 11, /* Variable display parameters. */
/* subtype 12 unknown */
EXT_LONG_NAMES= 13, /* Long variable names. */
EXT_LONG_STRINGS  = 14, /* Long strings. */
/* subtype 15 unknown */
EXT_NCASES= 16, /* Extended number of cases. */
EXT_FILE_ATTRS= 17, /* Data file attributes. */
EXT_VAR_ATTRS = 18, /* Variable attributes. */
EXT_MRSETS2   = 19, /* Multiple response sets (extended). */
EXT_ENCODING  = 20, /* Character encoding. */
EXT_LONG_LABELS   = 21  /* Value labels for long strings. */
  };

and

  static const struct extension_record_type types[] =
{   
  /* Implemented record types. */
  { EXT_INTEGER,  4, 8 },
  { EXT_FLOAT,8, 3 },
  { EXT_MRSETS,   1, 0 }, 
  { EXT_DISPLAY,  4, 0 },
  { EXT_LONG_NAMES,   1, 0 },
  { EXT_LONG_STRINGS, 1, 0 },
  { EXT_NCASES,   8, 2 },
  { EXT_FILE_ATTRS,   1, 0 },
  { EXT_VAR_ATTRS,1, 0 },
  { EXT_MRSETS2,  1, 0 },
  { EXT_ENCODING, 1, 0 },
  { EXT_LONG_LABELS,  1, 0 },

  /* Ignored record types. */
  { EXT_VAR_SETS, 0, 0 },
  { EXT_DATE, 0, 0 },
  { EXT_DATA_ENTRY,   0, 0 },
};


On Fri, 2011-03-25 at 18:39 -0500, Robert Baer wrote:
 I got the following:
  library(foreign)
  swal = read.spss(swallowing.sav, to.data.frame =TRUE)
 Warning message:
 In read.spss(swallowing.sav, to.data.frame = TRUE) :
   swallowing.sav: Unrecognized record type 7, subtype 21 encountered in 
 system file
  
 
 The bulk of the data seems to read in  a usable form, but I'm curious about 
 what might be getting lost because I don't know how to translate type 7, 
 subtype 21.  I did not generate the SPSS data so I'm not certain of the 
 version, but I'm assuming version 18 or 19.  I did a quick Find on the PSPP 
 manual for Type 7 and subtype 21 and came up dry.
 
 Any insights or clues how I might learn more?  
 
 Thanks,
 Rob
 
 
  R.Version()
 $platform
 [1] i386-pc-mingw32
 
 $arch
 [1] i386
 
 $os
 [1] mingw32
 
 $system
 [1] i386, mingw32
 
 $status
 [1] 
 
 $major
 [1] 2
 
 $minor
 [1] 12.2
 
 $year
 [1] 2011
 
 $month
 [1] 02
 
 $day
 [1] 25
 
 $`svn rev`
 [1] 54585
 
 $language
 [1] R
 
 $version.string
 [1] R version 2.12.2 (2011-02-25)
 
 
 
 --
 Robert W. Baer, Ph.D.
 Professor of Physiology
 Kirksville College of Osteopathic Medicine
 A. T. Still University of Health Sciences
 Kirksville, MO 63501
 660-626-232
 FAX 660-626-2965
 
   [[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] Building a matrix so that matrix(r, c)-matrix(c, r) with No For Loops

2011-03-26 Thread Brian Pellerin
Thanks, David. This works splendidly. Thanks for your help.

Sincerely,
Brian

 David Winsemius dwinsem...@comcast.net 03/26/11 3:06 PM 

On Mar 26, 2011, at 9:44 AM, Brian Pellerin wrote:

 Hello,

 I would like to take advantage of the upper.tri() function here but  
 I don't
 know exactly. Here is some working code...
 i-5
 fi-matrix(0,nrow=i,ncol=i)
 for(r in 1:i){
 for(c in 1:i){
 if(r==c){
 fi[r,c]-1
 }else if(rc){
 fi[r,c]-1-runif(1)^.5
 }else{
 fi[r,c]-fi[c,r]
 }
 }
 }

 So far I know I can simplify this code to 5 lines (no for loops):
 i-5
 fi-matrix(nrow=i,ncol=i)
 fi[upper.tri(fi)]-1-runif(length(fi[upper.tri(fi)]))^.5
 diag(fi)-1
 fi[lower.tri(fi)]-fi[upper.tri(fi)]#This entry is not correct.  
 fi[r,c] ! ==
 fi[c,r]

I've always found using the upper.tri and lower.tri functions error  
prone in my hands, because they are really logical matrices for  
selection rather than returning values as I naively expect. Try this:

i-5
fi-diag(1,i,i)
fi[upper.tri(fi)]-1-runif(length(fi[upper.tri(fi)]))^.5
fi[lower.tri(fi)]-t(fi)[lower.tri(fi)]
fi

It may seem odd to use lower.tri(fi) inside `[ ]` since the values of  
`fi` in the lower triangle are all zero, but you are really just using  
it to extract from `t(fi)`.

-- 
David.


 Any suggestions?

 Sincerely,
 Brian

   [[alternative HTML version deleted]]

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

David Winsemius, MD
West Hartford, CT

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


Re: [R] Coordinates of the text region

2011-03-26 Thread Greg Snow
Look at the strwidth and strheight functions.  Also note the adj parameter (see 
?par for details).

-- 
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-bounces@r-
 project.org] On Behalf Of Francois Rousseu
 Sent: Saturday, March 26, 2011 6:40 PM
 To: r-help@r-project.org
 Subject: [R] Coordinates of the text region
 
 
 Hello R people
 
 Is there a way to get the coordinates of the text region (coordinates
 of the four corners for example) when using the text function? I'm
 looking for a way that does not make use of interactive function like
 locator. My goal is to determine the position of other structures in a
 graphic so that they don't overlap with the text.
 
 Thanks
 Francois Rousseu
 
   [[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.