Re: [R] Frequencies from a matrix - spider from frequencies

2010-03-21 Thread Uwe Dippel

Jim Lemon wrote:

Yes, I realized that I had forgotten to require(plotrix) after I sent
the message. From your example, you might also want to look at the 
diamondplot function, also in plotrix.
  


Jim,

thanks for the hint to diamondplot. It is much closer natively to what I 
wanted to do, and simple to use. Hats off!: Just entering the data frame 
produces a quick print.

However, it fails to make sense w.r.t. units and values here.
I use the example data and code given in ?diamondplot:
data(mtcars)
 
mysubset-mtcars[substr(dimnames(mtcars)[[1]],1,1)==M,c(mpg,hp,wt,disp)]

 diamondplot(mysubset)
and get a plot (I think I can't attach it here?), with, e.g.
hp and disp crossing the Maserati radial axis at 17, wt at 15 and mpg at 10.
The actual data row, though, is
 mpg  hpwt  disp
Maserati Bora 15.0 335 3.570 301.0

Looking closer, the plot seems to arbitrarily scale all values (columns) 
to a(n arbitrary?) maximum of '17'.
And when I print my data (submitted earlier), the same happens: all 
responses are scaled to 17 as the highest in each category. From that 
point of view, diamondplot is not that useful. How can I force it not to 
scale arbitrarily, but print the actual numbers?


Uwe

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


Re: [R] different forms of nls recommendations

2010-03-21 Thread Dieter Menne


emorway wrote:
 
 
 So I wanted to try a different equation of the general form a/(b+c*x^d)
 
 US.nls.2-nls(US.final.values$ECe~(a/(b+c*US.final.values$WTD^d)),data=US.final.values,start=list(a=100.81,b=73.7299,c=0.0565,d=-6.043),trace=TRUE,algorithm=port)
 
 but that ended with Convergence failure: false convergence (8).  I tried
 relaxing the convergence 
 
 

You want 4 parameters from a set of data that has a very large variance. Try
to fix d and c to a reasonable constant; it probably will converge.

From looking at your data and the variances, I would suggest to
log-transform first. If you feel bad about it, you can always fit the
original data later after you have found a good model.

Dieter


-- 
View this message in context: 
http://n4.nabble.com/different-forms-of-nls-recommendations-tp1676330p1676547.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] Converting a character string into a data frame name and performing assignments to that data frame

2010-03-21 Thread Dieter Menne


Kavitha Venkatesan-2 wrote:
 
 variable.df is a character string that contains the name of the data
 frame that I want to do the following operations on:
 
 variable.df - data.frame();
 # I can do the above command using
 assign( variable.df, data.frame() )
 
 How can I perform the assignment statements below ?
 
 colnames(variable.df) = colnames(some.other.df)
 

Try to avoid assign and eval when you are not fiRm; the first is rarely
used, and the second is a bit to powerful for safeR.

data(iris)
head(iris)
names(iris) = c(A,B,C,D,Spec)
head(iris)

Dieter







-- 
View this message in context: 
http://n4.nabble.com/Converting-a-character-string-into-a-data-frame-name-and-performing-assignments-to-that-data-frame-tp1676236p1676552.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] using a condition given as string in subset function - how?

2010-03-21 Thread Albert-Jan Roskam
Hi,

Is eval always used in conjunction with parse? Based on other languages, I'd 
expect the expression already to work without the use of parse(), but indeed it 
doesn't, or at least not as intended. Just a newbie question..

Cheers!!

Albert-Jan



~~

In the face of ambiguity, refuse the temptation to guess.

~~

--- On Sun, 3/21/10, jim holtman jholt...@gmail.com wrote:

From: jim holtman jholt...@gmail.com
Subject: Re: [R] using a condition given as string in subset function - how?
To: Mark Heckmann mark.heckm...@gmx.de
Cc: r-help@r-project.org
Date: Sunday, March 21, 2010, 2:33 AM

I know that if you have to resort to 'parse(text=...)', you should look for
another way (it is a 'fortune'), but it is getting late, and at least it
works:

 eval(parse(text=subset(df, A==1  B==1)))
  A B
1 1 1


On Sat, Mar 20, 2010 at 9:09 PM, Mark Heckmann mark.heckm...@gmx.de wrote:

 df - data.frame(A=c(1,2), B=c(1,1))

 I have a string containing a condition for a subset function, like:
 conditionAsString - paste(names(df), df[1,], sep===, collapse=  )
   conditionAsString
   A==1  B==1

 Now I want to use this string in the subset call, like

 subset(df, conditionAsString)

 I do not exactly now how to combine substitute, expression, parse and
 so on to get what I want, which would be:

 subset(df, A==1  B==1)

 but using the string conditionAsString.

 Thanks,
 Mark
 –––––––––––––––––––––––––––––––––––––––
 Mark Heckmann
 Blog: www.markheckmann.de
 R-Blog: http://ryouready.wordpress.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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




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

What is the problem that you are trying to solve?

    [[alternative HTML version deleted]]


-Inline Attachment Follows-

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



  
[[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] Find a rectangle of maximal area

2010-03-21 Thread Hans W Borchers
For an application in image processing -- using R for statistical purposes -- I
need to solve the following task:

Given n (e.g. n = 100 or 200) points in the unit square, more or less randomly
distributed. Find a rectangle of maximal area within the square that does not
contain any of these points in its interior.

If a, b are height and width of the rectangel, other constraints may have to be
imposed such as  a, b = 0.5  and/or  0.5 = a/b = 2.0 . The rectangle is
allowed to touch the border of the square.

For each new image the points will be identified by the application, like all
stars of a certain brightness on an astronomical picture. So the task will have
to be performed several times.

I assume this problem is computationally hard. I would like to find a solution
that is reasonably fast for  n = 100..200  points. Exhaustive search along the
x, y coordinates of the points will not be fast enough.

I know this request is not about R syntax and does not contain 'repro-code'. But
perhaps a somehow similar problem has been solved before.

Thanks in advance for any suggestions,
Hans Werner

P.S.: Example Is this rectangle of maximal area?

n - 100; set.seed(832)
x - runif(n); y - runif(n)
plot(c(0,1), c(0,1), type=n, axes=FALSE, asp=1,
 xlab=, ylab=, main=Rectangle Problem, sub=)
rect(0,0,1,1, col=darkblue)
xl-100; yu-43; xr-40; yo-3
area - (x[xr]-x[xl])*(y[yo]-y[yu])
rect(x[xl], y[yu], x[xr], y[yo],
 lty=2, col=darkblue, border=red)
text((x[xl]+x[xr])/2, (y[yu]+y[yo])/2,
 paste(area =, round(area, 4)), cex=0.75, col=red)
points(x, y, pch=20, col=white)


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Levene's Test for Homogeneity of Variance

2010-03-21 Thread Iurie Malai
Hi, All!

To calculate Levene's Test for Homogeneity of Variance I use R Commander,
and this is the output:

 levene.test(Dataset$age, Dataset$sex)
Levene's Test for Homogeneity of Variance
  Df F value Pr(F)
group  1  0.8739 0.3567
  33

I am not sure what means Pr(F)? Can anyone explain/translate this?


Regards,
Iurie Malai
Department of Psychology and Special Education
Moldova Pedagogical State University

iurie.ma...@gmail.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] Levene's Test for Homogeneity of Variance

2010-03-21 Thread Philippe Glaziou
On 21 March 2010 13:13, Iurie Malai iurie.ma...@gmail.com wrote:
 To calculate Levene's Test for Homogeneity of Variance I use R Commander,
 and this is the output:

 levene.test(Dataset$age, Dataset$sex)
 Levene's Test for Homogeneity of Variance
      Df F value Pr(F)
 group  1  0.8739 0.3567
      33

 I am not sure what means Pr(F)? Can anyone explain/translate this?


this is shorthand for:
 1 - pf(0.8739, 1 ,33)
[1] 0.3567

see:
?pf

Philippe

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


Re: [R] Levene's Test for Homogeneity of Variance

2010-03-21 Thread John Fox
Dear Iurie,

Pr(F) is the p-value for the test of the null hypotheses that the
population variances are equal. This is the typical format for labelling a
p-value in R output.

I hope this helps,
 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 Of Iurie Malai
 Sent: March-21-10 8:14 AM
 To: r-help@r-project.org
 Subject: [R] Levene's Test for Homogeneity of Variance
 
 Hi, All!
 
 To calculate Levene's Test for Homogeneity of Variance I use R Commander,
 and this is the output:
 
  levene.test(Dataset$age, Dataset$sex)
 Levene's Test for Homogeneity of Variance
   Df F value Pr(F)
 group  1  0.8739 0.3567
   33
 
 I am not sure what means Pr(F)? Can anyone explain/translate this?
 
 
 Regards,
 Iurie Malai
 Department of Psychology and Special Education
 Moldova Pedagogical State University
 
 iurie.ma...@gmail.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.

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


Re: [R] Problem specifying Gamma distribution in lme4/glmer

2010-03-21 Thread Ben Bolker
Matthew Giovanni matthewgiovanni at gmail.com writes:

 
 Dear R and lme4 users-
 
 I am trying to fit a mixed-effects model, with the glmer function in
 lme4, to right-skewed, zero-inflated, non-normal data representing
 understory grass and forb biomass (continuous) as a function of tree
 density (indicated by leaf-area).  Thus, I have tried to specify a
 Gamma distribution with a log-link function but consistently receive
 an error as follows:
 
 total=glmer(total~gla4+(1|plot)+
(1|year/month),data=veg,family=Gamma(link=log))
 summary(total)
 Error in asMethod(object) : matrix is not symmetric [1,2]
 
 I have also tried fitting glmm's with lme4 and glmer to other
 Gamma-distributed data but receive the same error.  Has anyone had
 similar problems and found any solutions?

 1. probably best to post questions like this to 
r-sig-mixed-mod...@r-project.org

 2. haven't seen this particular problem.  Can you please
provide a reproducible example (post your data, or a small
subset of your data, or a simulated example that displays
the same problem), and give the results of
the sessionInfo() function?

f - factor(rep(1:10,each=10))
x - runif(100)
dat - data.frame(x,f)
library(lme4)
 [snip messages]
g1 - glmer(x~1+(1|f),data=dat,family=Gamma(link=log))
  Generalized linear mixed model fit by the Laplace approximation 
  [...]
summary(g1)
  [ works fine]

sessionInfo()
  R version 2.10.1 (2009-12-14) 
  i486-pc-linux-gnu 

  [snip]

  other attached packages:
  [1] lme4_0.999375-32-2 Matrix_0.999375-38 lattice_0.18-3

 3. zero-inflated data may not be particularly well-represented
by a Gamma distribution: if you actually have a significant number
of exactly-zero values, you may want to analyze your data in two
stages, first as a presence-absence problem and then as a conditional
density (i.e., what is the distribution of the non-zero values)?

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


Re: [R] Problem specifying Gamma distribution in lme4/glmer

2010-03-21 Thread Dieter Menne


Ben Bolker wrote:
 
 
  3. zero-inflated data may not be particularly well-represented
 by a Gamma distribution: if you actually have a significant number
 of exactly-zero values, you may want to analyze your data in two
 stages, first as a presence-absence problem and then as a conditional
 density (i.e., what is the distribution of the non-zero values)?
 
 

Interesting idea. Do you know of a example where this was done (independent
of lmer)? We have similar data, were people are either symptom free (50%
with score 0), and the rest is smoothly distributed.

Dieter


-- 
View this message in context: 
http://n4.nabble.com/Problem-specifying-Gamma-distribution-in-lme4-glmer-tp1676344p1676746.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] EM algorithm in R

2010-03-21 Thread Daniel Nordlund
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of tj
 Sent: Saturday, March 20, 2010 10:35 AM
 To: r-help@r-project.org
 Subject: Re: [R] EM algorithm in R
 
 
 here is my program... Im trying to fit 1 component to 6 components in each
 of
 the 300 generated samples. Each sample has size=200. For each of the 300
 generated samples and for each modeled component (v=1,2,3,4,5,6), I will
 get
 estimates of the parameters that will maximize the likelihood, AND then I
 will determine when AIC obtained its minimum value - - is it in the 1
 component or 2 components or .. 6 components? Then I will count the
 times that AIC has its minimum at component=2.  I will do the same for BIC
 and AIC.
 
 MY program right now:
 
 h=5
 tol=0.0001
 size=200
 B=300
 mean1=-0.8
 mean2=0.8
 q=c(0.25,0.75,0,0,0,0) #i will use this later for the qth
 quantile
 mu=0
 a1=0; a2=0; a3=0; a4=0; a5=0; a6=0
 mu1s=0 ; mu2s=0 ; mu3s=0 ; mu4s=0 ; mu5s=0 ; mu6s=0
 as1=rep(NA,B) ; as2=rep(NA,B); as3=rep(NA,B); as4=rep(NA,B);
 as5=rep(NA,B);
 as6=rep(NA,B)
 vs=0
 itrs=0
 AIC=0
 BIC=0
 CAIC=0
 Aicno=0
 Bicno=0
 Caicno=0
 
 mylog=function(y,mu1,mu2,mu3,mu4,mu5,mu6,var,a1,a2,a3,a4,a5,a6){
 sum(log(
 (a1/sqrt(2*pi*var))*(exp(-((y-mu1)^2)/(2*var))) +
 (a2/sqrt(2*pi*var))*(exp(-((y-mu2)^2)/(2*var))) +
 (a3/sqrt(2*pi*var))*(exp(-((y-mu3)^2)/(2*var))) +
 (a4/sqrt(2*pi*var))*(exp(-((y-mu4)^2)/(2*var))) +
 (a5/sqrt(2*pi*var))*(exp(-((y-mu5)^2)/(2*var))) +
 (a6/sqrt(2*pi*var))*(exp(-((y-mu6)^2)/(2*var)))
 ),na.rm=TRUE)
 }
 
 set.seed(h)
 
 for (j in 1:B){#generating my sample
 
 t=rbinom(1,200,0.5)
 
 y1=rnorm(mean=mean1,sd=1,n=t)
 
 y2=rnorm(mean=mean2,sd=1,n=200-t)
 
 y=c(y1,y2)
 
 var=var(y)
 mu1=as.numeric(quantile(y,q[1]))   # setting my starting values for the
 means
 mu2=as.numeric(quantile(y,q[2]))
 mu3=as.numeric(quantile(y,q[3]))
 mu4=as.numeric(quantile(y,q[4]))
 mu5=as.numeric(quantile(y,q[5]))
 mu6=as.numeric(quantile(y,q[6]))
 
 for (v in 1:6)
 {
 
 for (i in 2:600){#my maximum number of
 iteration
 to get the maximum likelihood estimates for my parameters is 600
 
 a1[v]=ifelse(1v,NA,1/v)#here, i set my starting values
 for
 proportions as 1/v, where v is the  number of components. Example, When
 the
 number
 a2[v]=ifelse(2v,NA,1/v) #of components is 2, the program
 will only give two starting values for proportions. I'm having a problem
 when the
 a3[v]=ifelse(3v,NA,1/v) #program gives NA... there are
 problems encountered in the preceding procedures.
 a4[v]=ifelse(4v,NA,1/v)
 a5[v]=ifelse(5v,NA,1/v)
 a6[v]=ifelse(6v,NA,1/v)
 
 ms=
 c(a1[i-1]*dnorm(y,mu1[i-1],sqrt(var[i-1])),a2[i-1]*dnorm(y,mu2[i-
 1],sqrt(var[i-1])),
 a3[i-1]*dnorm(y,mu3[i-1],sqrt(var[i-1])),
 a4[i-1]*dnorm(y,mu4[i-1],sqrt(var[i-1])),
 a5[i-1]*dnorm(y,mu5[i-1],sqrt(var[i-1])),
 a6[i-1]*dnorm(y,mu6[i-1],sqrt(var[i-1])))
 m=as.numeric(na.omit(ms))
 
 B = m/sum(m)
 B1 = B[1:size]
 B2 = B[size+1:size*2]
 B3 = B[size*2+1:size*3]
 B4 = B[size*3+1:size*4]
 B5 = B[size*4+1:size*5]
 B6 = B[size*5+1:size*6]
 
 mu1[i]=sum(B1*y)/sum(B1)
 mu2[i]=sum(B2*y)/sum(B2)
 mu3[i]=sum(B3*y)/sum(B3)
 mu4[i]=sum(B4*y)/sum(B4)
 mu5[i]=sum(B5*y)/sum(B5)
 mu6[i]=sum(B6*y)/sum(B6)
 
 a1[i]=sum(B1)/size
 a2[i]=sum(B2)/size
 a3[i]=sum(B3)/size
 a4[i]=sum(B4)/size
 a5[i]=sum(B5)/size
 a6[i]=sum(B6)/size
 
 var[i]=sum((B1*(y-mu1[i])^2+ B2*(y-mu2[i])^2 + B3*(y-mu3[i])^2+
  B4*(y-mu4[i])^2 + B5*(y-mu5[i])^2 + B6*(y-mu6[i])^2),na.rm=TRUE)/size
 
 if(abs(mylog(y,mu1[i],mu2[i],mu3[i],mu4[i],mu5[i],mu6[i],var[i],
a1[i],a2[i],a3[i],a4[i],a5[i],a6[i])-
 
 mylog(y,mu1[i-1],mu2[i-1],mu3[i-1],mu4[i-1],mu5[i-1],mu6[i-1],var[i-1],
a1[i-1],a2[i-1],a3[i-1],a4[i-1],a5[i-1],a6[i-1]))
 =tol)
 break()
 
 }
 f[j]=mylog(y,mu1s[j],mu2s[j],mu3s[j],mu4s[j],mu5s[j],mu6s[j],vs[j],
as1[j],as2[j],as3[j],as4[j],as5[j],as6[j])
 AIC[v]=f[j]-v
 BIC[v]=f[j]-(v/2)*log(size)
 CAIC[v]=f[j]-(v/2)*log(size)-(v/2)
 if (AIC[v] AIC[v+1])  # i need to record the value of v with minimum AIC
 if (BIC[v] BIC[v+1])  # i need to record the value of v with minimum AIC
 if (CAIC[v] CAIC[v+1]) #i need to record the value of v with minimum AIC
 
 }
 
 Aicno[j]=v#storage for the value of v when minimum AIC was obtained
 Bicno[j]=v#storage for the value of v when minimum AIC was obtained
 Caicno[j]=v   #storage for the value of v when minimum AIC was obtained
 as1[j]=a1[i]
 as2[j]=a2[i]
 as3[j]=a3[i]
 as4[j]=a4[i]
 as5[j]=a5[i]
 as6[j]=a6[i]
 mu1s[j]=mu1[i]
 mu2s[j]=mu2[i]
 mu3s[j]=mu3[i]
 mu4s[j]=mu4[i]
 mu5s[j]=mu5[i]
 mu6s[j]=mu6[i]
 vs[j]=var[i]
 
 }
 
 Aicno# so for this, I wish to obtain 300 values of k, where k can
 be
 equal to 1,2,3,4,5,6, corresponding to the component with lowest AIC
 Bicno# so for this, I wish to obtain 300 values of k, where k can
 be
 equal to 1,2,3,4,5,6, corresponding to the 

[R] calculus using R

2010-03-21 Thread ATANU

can anyone suggest how can i do calculus
(e.g.limit,differentiation,integrate,mean value theorem,definite
integral,convergence,maxima minima of functions,checking continuity) using
R??
-- 
View this message in context: 
http://n4.nabble.com/calculus-using-R-tp1676727p1676727.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] Applying SVM model to a new data

2010-03-21 Thread m_r_nour

Hi

I'm using Libsvm, I made a function to save models, confusion matrix of
different models

but when I want to use saved model, I can't


let suppose output of function is :

models=list(model1,model2,)

but how can I use these models? using predict(models[[1]],y) causes error
message:

Error in UseMethod(predict) : 
  no applicable method for 'predict' applied to an object of class list



thanks

Regards

-- 
View this message in context: 
http://n4.nabble.com/Applying-SVM-model-to-a-new-data-tp1676864p1676864.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] sapply, lattice functions

2010-03-21 Thread Santosh
Dear R-gurus..

How do I implement the following:
a) Overlay frequency(instead of density) with line of density plot, vertical
lines of confidence intervals and reference levels?
b) Control the breaks (using nint?), order of the panel, and the layout,
place units for each conditioning variable?

Is there more efficient way than lines provided below? Please feel free to
suggest other ways of displaying the above information.

library(reshape)
# The data frame below is an example of a subset of results from bootstrap
runs. From the results of bootstrap, I would like to  # display
frequency histogram with overlay of density,confidence intervals, and point
estimates.

aa - data.frame(id=seq(20),a1=rnorm(20),b1=rnorm(20,0.8),c1=rnorm(20,0.5))
aa1 - rbind(aa,c( -99, -0.02,1.09,  0.23)) # record of reference values for
each distribution, set id = -99
ab - melt(aa1,measure=names(aa1)[-match(id,names(aa1)])
uns - unlist(list(id=,a1=mL/h,b1=L,c1=L))
uns1 - data.frame(var=names(uns),uni=(uns))
ab1 - merge(ab,uns1,by=variable,all.x=T)
 ab2 - ab1[order(ab1$variable,ab1$id),]

histogram(~value|paste(as.character(variable),
(,uni,),sep=),breaks=NULL,nint=10,ab2,layout=c(2,2),as.table=T,type=density,scales=list(relation='free'),
panel=function(x,lqp=c(0.025,0.975),...) { # lqp indicate
confidence intervals
x1 - x[-1]
 vs - x[1]
panel.histogram(x1,col='light blue',...)
panel.densityplot(x1,col.line='blue',lwd=1.75,...)
panel.abline(v=c(quantile(as.vector(x1),prob=lqp,na.rm = T),vs),
col=c(blue,blue,dark green),lwd=2,lty=c(2,2,1))},
strip=strip.custom( strip.names=F, strip.levels=T)
)

Thanks so much for your help!
Santosh

On Sat, Mar 20, 2010 at 10:56 AM, Sundar Dorai-Raj sdorai...@gmail.comwrote:

 You're right. It's necessary for xyplot though to prevent grouping.

 On Mar 20, 2010 10:43 AM, Dieter Menne dieter.me...@menne-biomed.de
 wrote:



 Sundar Dorai-Raj-2 wrote:
 
  Or perhaps more clearly,
 
  histogram(~a1 + b1 + c1, data = aa, o...
 Why outer=TRUE? Looks same for me without:
 Dieter

 library(lattice)

 aa - data.frame(a1=rnorm(20),b1=rnorm(20,0.8),c1=rnorm(20,0.5))
 histogram(~a1 + b1 + c1, data = aa)


 --
 View this message in context:
 http://n4.nabble.com/sapply-lattice-functions-tp1618134p1676043.html
 Sent from the R help mailing list archive at Nabble.com.


 __
 R-help@r-project.org mailing list
 https://stat.ethz

[[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] calculus using R

2010-03-21 Thread David Winsemius


On Mar 21, 2010, at 11:26 AM, ATANU wrote:



can anyone suggest how can i do calculus
(e.g.limit,differentiation,integrate,mean value theorem,definite
integral,convergence,maxima minima of functions,checking continuity)  
using

R??


?D
?integrate
?pmax
?pmin
package:RYacas

Continuity? Limits? R is of necessity being run on discrete machines  
and R is not a symbolic algebra machine.


--
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] using a condition given as string in subset function - how?

2010-03-21 Thread Thomas Lumley

On Sun, 21 Mar 2010, Albert-Jan Roskam wrote:


Hi,

Is eval always used in conjunction with parse? Based on other languages, I'd 
expect the expression already to work without the use of parse(), but indeed it 
doesn't, or at least not as intended. Just a newbie question..


parse() turns a character string into R code, and eval() evaluates R code.

parse() usually requires eval(), because there's rarely much point parsing a 
string if you aren't going to evaluate it, but eval() usually doesn't require 
parse().  That is, most uses of eval() are not on strings but on expressions.

In your case it is not clear whether someone else hands you a condition in 
string form, in which care parse() is necessary, or whether you build it up 
your self, in which case parse() is not necessary, and eval() may not be 
necessary.

-thomas



Cheers!!

Albert-Jan



~~

In the face of ambiguity, refuse the temptation to guess.

~~

--- On Sun, 3/21/10, jim holtman jholt...@gmail.com wrote:

From: jim holtman jholt...@gmail.com
Subject: Re: [R] using a condition given as string in subset function - how?
To: Mark Heckmann mark.heckm...@gmx.de
Cc: r-help@r-project.org
Date: Sunday, March 21, 2010, 2:33 AM

I know that if you have to resort to 'parse(text=...)', you should look for
another way (it is a 'fortune'), but it is getting late, and at least it
works:


eval(parse(text=subset(df, A==1  B==1)))

?? A B
1 1 1


On Sat, Mar 20, 2010 at 9:09 PM, Mark Heckmann mark.heckm...@gmx.de wrote:


df - data.frame(A=c(1,2), B=c(1,1))

I have a string containing a condition for a subset function, like:
conditionAsString - paste(names(df), df[1,], sep===, collapse=  )
??  conditionAsString
??  A==1  B==1

Now I want to use this string in the subset call, like

subset(df, conditionAsString)

I do not exactly now how to combine substitute, expression, parse and
so on to get what I want, which would be:

subset(df, A==1  B==1)

but using the string conditionAsString.

Thanks,
Mark
?
Mark Heckmann
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.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.htmlhttp://www.r-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





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

What is the problem that you are trying to solve?

?? [[alternative HTML version deleted]]


-Inline Attachment Follows-

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




[[alternative HTML version deleted]]




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

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


Re: [R] calculus using R

2010-03-21 Thread Gabor Grothendieck
Try this:

 library(Ryacas) # http://ryacas.googlecode.com
Loading required package: XML

 x - Sym(x)
 h - Sym(h)

 # limit
 Limit(1/(1-x), x, Infinity)
[1] Starting Yacas!
expression(0)

 # differentiation
 deriv(x^3, x)
expression(3 * x^2)

 # integration: indefinite and definite
 Integrate(x^3, x)
expression(x^4/4)
 Integrate(x^3, x, 0, 1)
expression(1/4)

 # mean value
 Limit((cos(x+h)-cos(x))/h, h, 0)
expression(-sin(x))

 # min/max
 Solve(deriv(x^2-x, x) == 0, x)
expression(list(x == 1/2))

 # continuity
 Limit(sin(x+h^2) - sin(x-h^2), h, 0)
expression(0)

On Sun, Mar 21, 2010 at 11:26 AM, ATANU ata.s...@gmail.com wrote:

 can anyone suggest how can i do calculus
 (e.g.limit,differentiation,integrate,mean value theorem,definite
 integral,convergence,maxima minima of functions,checking continuity) using
 R??
 --
 View this message in context: 
 http://n4.nabble.com/calculus-using-R-tp1676727p1676727.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] multiple logical comparisons

2010-03-21 Thread Martin Batholdy
Hi,

I would like to compare a column of data with a vector.

I have this data.frame for example;

x - data.frame(A = c(1:5), B = c(1,1,2,2,2))

Now I have a search vector:

search - c(1,3,5)


when I now try to get all the data-rows which have a 1, a 3, or a 5 in column A 
and a 2 in column B, 
I tried this:

x[x$B == 2  x$A == search,]


I hoped to get 
3 2
5 2
as output.


But I get an empty set.


Can someone help me on that?


_

search - c(1,3,5)
x - data.frame(A = c(1:5), B = c(1,1,2,2,2))

x[x$B == 2  x$A == search,]

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


Re: [R] Problem specifying Gamma distribution in lme4/glmer

2010-03-21 Thread Ben Bolker
Dieter Menne dieter.menne at menne-biomed.de writes:
 
 Ben Bolker wrote:

   3. zero-inflated data may not be particularly well-represented
  by a Gamma distribution: if you actually have a significant number
  of exactly-zero values, you may want to analyze your data in two
  stages, first as a presence-absence problem and then as a conditional
  density (i.e., what is the distribution of the non-zero values)?

 [...] Do you know of a example where this was done (independent
 of lmer)?  [...]

  Nothing springs to mind, but it seems sensible.

  Ben Bolker

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


Re: [R] using a condition given as string in subset function - how?

2010-03-21 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Albert-Jan Roskam
 Sent: Sunday, March 21, 2010 2:25 AM
 To: Mark Heckmann; jim holtman
 Cc: r-help@r-project.org
 Subject: Re: [R] using a condition given as string in subset 
 function - how?
 
 Hi,
 
 Is eval always used in conjunction with parse? Based on other 
 languages, I'd expect the expression already to work without 
 the use of parse(), but indeed it doesn't, or at least not as 
 intended. Just a newbie question..

When eval is given a parse tree (e.g., the output of
parse() or call()) it recursively ascends the tree,
effectively calling eval() on the subtrees.  E.g.,
parse(text='paste(No, 1)')[[1]] returns a call object
of length 3, the elements being the name object `paste`,
the character object No, and the numeric object 1.
Evaluating a name object returns its value and evaluating
a character or numeric object returns the object (unchanged).
I.e., in this case
   eval(`paste`) - function(..., sep= , collapse=NULL)
   eval(No) - No
   eval(1) - 1
The root of the parse tree is the call object and evaluating
that means applying the function given by the first argument
to the rest of the argumeents.

If eval(No) meant the same as eval(parse(text=No))
then this scheme would break down, since you wouldn't be able
to distinguish between character objects and name objects,
so it would not be possible to say you wanted the string No
or the value of the object called No.
 
You might say that eval(String) should do one thing when
called directly, whatever that means, and another when called
by a recursive call to eval(), but I think functions should
act the same no matter who calls them.

There are also times when you want the raw parse tree, as when
processing model formulae like log(response)~groupId/predictor
or trellis/lattice formulae like log(y)~predictor|groupId.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

 
 Cheers!!
 
 Albert-Jan
 
 
 
 ~~
 
 In the face of ambiguity, refuse the temptation to guess.
 
 ~~
 
 --- On Sun, 3/21/10, jim holtman jholt...@gmail.com wrote:
 
 From: jim holtman jholt...@gmail.com
 Subject: Re: [R] using a condition given as string in subset 
 function - how?
 To: Mark Heckmann mark.heckm...@gmx.de
 Cc: r-help@r-project.org
 Date: Sunday, March 21, 2010, 2:33 AM
 
 I know that if you have to resort to 'parse(text=...)', you 
 should look for
 another way (it is a 'fortune'), but it is getting late, and 
 at least it
 works:
 
  eval(parse(text=subset(df, A==1  B==1)))
   A B
 1 1 1
 
 
 On Sat, Mar 20, 2010 at 9:09 PM, Mark Heckmann 
 mark.heckm...@gmx.de wrote:
 
  df - data.frame(A=c(1,2), B=c(1,1))
 
  I have a string containing a condition for a subset function, like:
  conditionAsString - paste(names(df), df[1,], sep===, 
 collapse=  )
    conditionAsString
    A==1  B==1
 
  Now I want to use this string in the subset call, like
 
  subset(df, conditionAsString)
 
  I do not exactly now how to combine substitute, expression, 
 parse and
  so on to get what I want, which would be:
 
  subset(df, A==1  B==1)
 
  but using the string conditionAsString.
 
  Thanks,
  Mark
  
 ––––––––––––––––––––â€
“––––––––––––––––––
  Mark Heckmann
  Blog: www.markheckmann.de
  R-Blog: http://ryouready.wordpress.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.htmlhttp://www.r-proje
ct.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 
 -- 
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390
 
 What is the problem that you are trying to solve?
 
     [[alternative HTML version deleted]]
 
 
 -Inline Attachment Follows-
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 
   
   [[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 logical comparisons

2010-03-21 Thread Erik Iverson

Martin Batholdy wrote:

Hi,

I would like to compare a column of data with a vector.

I have this data.frame for example;

x - data.frame(A = c(1:5), B = c(1,1,2,2,2))

Now I have a search vector:

search - c(1,3,5)


when I now try to get all the data-rows which have a 1, a 3, or a 5 in column A and a 2 in column B, 
I tried this:


x[x$B == 2  x$A == search,]


I hoped to get 
3 2

5 2
as output.


See ?%in%

x[x$B == 2  x$A %in% search, ]

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


Re: [R] Problem specifying Gamma distribution in lme4/glmer

2010-03-21 Thread David Winsemius


On Mar 21, 2010, at 5:16 PM, Ben Bolker wrote:


Dieter Menne dieter.menne at menne-biomed.de writes:


Ben Bolker wrote:



3. zero-inflated data may not be particularly well-represented
by a Gamma distribution: if you actually have a significant number
of exactly-zero values, you may want to analyze your data in two
stages, first as a presence-absence problem and then as a  
conditional

density (i.e., what is the distribution of the non-zero values)?



[...] Do you know of a example where this was done (independent
of lmer)?  [...]


 Nothing springs to mind, but it seems sensible.


I thought this was what hurdle and ZIF models were supposed to handle  
gracefully?


--
David.


 Ben Bolker


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


Re: [R] different forms of nls recommendations

2010-03-21 Thread Bernardo Rangel Tura
On Sat, 2010-03-20 at 14:55 -0800, emorway wrote:
 Hello, 
 
 Using this data:
 http://n4.nabble.com/file/n1676330/US_Final_Values.txt US_Final_Values.txt 
 
 and the following code i got the image at the end of this message:
 
 US.final.values-read.table(c:/tmp/US_Final_Values.txt,header=T,sep= )
 US.nls.1-nls(US.final.values$ECe~a*US.final.values$WTD^b+c,data=US.final.values,start=list(a=2.75,b=-0.95,c=0.731),trace=TRUE)
 f.US1-function(x){coef(US.nls.1)[a]*x^coef(US.nls.1)[b]+coef(US.nls.1)[c]}
 xvals.US1-seq(min(US.final.values$WTD),max(US.final.values$WTD),length.out=75)
 yvals.US1-f.US1(xvals.US1)
 Rsq.nls.1-sum((predict(US.nls.1)-mean(US.final.values$ECe))^2/sum((US.final.values$ECe-mean(US.final.values$ECe))^2))
 plot(US.final.values$WTD,US.final.values$ECe,col=red,pch=19,cex=.75)
 lines(xvals.US1,yvals.US1,col=blue)
 
 but the r^2 wasn't so hot.  
 Rsq.nls.1
 [1] 0.2377306
 
 So I wanted to try a different equation of the general form a/(b+c*x^d)
 
 US.nls.2-nls(US.final.values$ECe~(a/(b+c*US.final.values$WTD^d)),data=US.final.values,start=list(a=100.81,b=73.7299,c=0.0565,d=-6.043),trace=TRUE,algorithm=port)
 
 but that ended with Convergence failure: false convergence (8).  I tried


Hi emorway,

Do you have 657 obs and 4 parameters to fit.
In my opinion you have few obs...
I think do you  fit in steps:

US.nls.2-nls(ECe~(a/(b + c *
WTD^d)),data=US.final.values,start=list(a=100.81,b=73.7299,c=0.0565,d=-6.043),trace=TRUE,algorithm=port)
temp_nls1 - nls(ECe~(100/(73 + .05 *
WTD^d)),data=US.final.values,start=list(d=-6.043),trace=TRUE,algorithm=port)
temp_nls2 - nls(ECe~(100/(73 + .05 *
WTD^d)),data=US.final.values,start=list(d=-1.01613),trace=TRUE,algorithm=port)
temp_nls3 - nls(ECe~(100/(73 + c *
WTD^(-1.01613))),data=US.final.values,start=list(c=0.05),trace=TRUE,algorithm=port)
temp_nls4 - nls(ECe~(100/(73 + c *
WTD^(-1.01613))),data=US.final.values,start=list(c=-14.7127),trace=TRUE,algorithm=port)
temp_nls5 - nls(ECe~(100/(b-14.7127 *
WTD^(-1.01613))),data=US.final.values,start=list(b=73),trace=TRUE,algorithm=port)
temp_nls6 - nls(ECe~(100/(b-14.7127 *
WTD^(-1.01613))),data=US.final.values,start=list(b=70.4936),trace=TRUE,algorithm=port)
temp_nls7 - nls(ECe~(a/(70.4936-14.7127 *
WTD^(-1.01613))),data=US.final.values,start=list(a=100),trace=TRUE,algorithm=port)
  0: 2243.9898:  100.000
  1: 2122.8218:  106.219
  2: 1359.8819:  187.530
  3: 1359.8819:  187.530



-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil

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

2010-03-21 Thread Martin Batholdy
thanks!



Now I have one more question;

How can I do the reverse?
when %in% is == (for two vectors of different lengths); what is the equivalent 
to !=  ?



On 21.03.2010, at 22:33, Erik Iverson wrote:

 Martin Batholdy wrote:
 Hi,
 I would like to compare a column of data with a vector.
 I have this data.frame for example;
 x - data.frame(A = c(1:5), B = c(1,1,2,2,2))
 Now I have a search vector:
 search - c(1,3,5)
 when I now try to get all the data-rows which have a 1, a 3, or a 5 in 
 column A and a 2 in column B, I tried this:
 x[x$B == 2  x$A == search,]
 I hoped to get 3 2
 5 2
 as output.
 
 See ?%in%
 
 x[x$B == 2  x$A %in% search, ]
 
 

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

2010-03-21 Thread Erik Iverson

Martin Batholdy wrote:

thanks!



Now I have one more question;

How can I do the reverse?
when %in% is == (for two vectors of different lengths); what is the equivalent 
to !=  ?



a %in% b returns a logical vector, so

!a %in% b

returns its negation.  See order of precedence in ?Syntax.

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


Re: [R] lattice grob

2010-03-21 Thread Felix Andrews
What's wrong with using grid.grabExpr?

p1 - xyplot(1:10 ~ 1:10)
g1 - grid.grabExpr(print(p1))

I can imagine there would be potential problems to do with the
plot-time aspect and layout calculations...



On 19 March 2010 21:51, baptiste auguie baptiste.aug...@googlemail.com wrote:
 Dear list,

 I'm trying to arrange various grid objects on a page using a
 frameGrob. It works fine with basic grobs (textGrob, gTree, etc.), and
 also with ggplot2 objects using the ggplotGrob() function. I am
 however stuck with lattice. As far as I understand, lattice produces a
 list of class trellis, which is eventually displayed using the
 plot.trellis method. I am not sure if/how one can convert this list
 into a high-level grob. I tried the following,

 latticeGrob - function(p, ...){
  grob(p=p, ..., cl=lattice)
 }

 drawDetails.lattice - function(x, recording=FALSE){
  lattice:::plot.trellis(x$p)
 }

 p1 - xyplot(1:10 ~ 1:10)
 g1 - latticeGrob(p1)

 grid.draw(g1) # works fine

 but,

 fg - frameGrob(layout = grid.layout(1,1))
 fg - placeGrob(fg, g1, row = 1, col = 1)
 grid.draw(fg)

 Error in UseMethod(depth) :
  no applicable method for 'depth' applied to an object of class NULL

 Ideas are most welcome,

 Best regards,

 baptiste

 sessionInfo()
 R version 2.10.1 RC (2009-12-06 r50690)
 i386-apple-darwin9.8.0

 locale:
 [1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

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

 other attached packages:
 [1] ggplot2_0.8.7   digest_0.4.1    reshape_0.8.3   plyr_0.1.9
 proto_0.3-8     gridExtra_0.5   lattice_0.17-26 gtools_2.6.1

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




-- 
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 4670
E: felix.andr...@anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 lmer weights argument to represent heteroskedasticity

2010-03-21 Thread J
Hi-

I want to fit a model with crossed random effects and heteroskedastic
level-1 errors where inferences about fixed effects are of primary
interest.  The dimension of the random effects is making the model
computationally prohibitive using lme() where I could model the
heteroskedasticity with the weights argument.  I am aware that the weights
argument to lmer() cannot be used to estimate a heteroskedastic variance
function with unknown parameters.  However my data situation is such that I
am able to assign each unit uniquely to one of four groups and I am willing
to treat the relative error variances of the groups as known.  I.e. I would
be able to specify the model I want to fit in lme() using a weights
statement of the form weights = varIdent(form = ~1 | group, fixed =
knownSDratios).  I am trying to figure out how I can concoct a weights
argument for lmer() that will fit this same model.  In particular, since the
reported inferences about fixed effects parameters are not invariant to how
the weights passed to lmer() are scaled, I am trying to understand how to
construct a weights argument that not only contains the information about
the relative precisions of the errors in the different groups, but also
provides valid inferences about the fixed effects.  In a simple example
below with balanced, nested data, scaling the weights to sum to the number
of cases in the data makes lmer() and lme() agree on the inferences about
the fixed effects.  However, at the end of the example, it is also clear
that this correspondence does not hold when the data are not balanced.  My
question boils down to this:  is there a general way to scale lmer()'s
weights argument that will cause it to always correspond to what lme()
would report about fixed effects inferences when passed the same fixed
relative precision information?

Thanks for any advice.

J.R.

###

## EXAMPLE: generate balanced nested data with heteroskedastic errors of
## variance 0.5, 1, 2, or 4
###
ngroup- 50
npergroup - 20
n - ngroup*npergroup

set.seed(5046)

d - data.frame(unitid = 1:n, groupid = rep(1:ngroup,
each=npergroup), verror = sample(c(0.5, 1, 2, 4), size=n, replace=T),
x = 0.1*rnorm(n))
groupeffx - data.frame(groupid = 1:ngroup, theta = rnorm(ngroup, sd = 0.25))
d - merge(d, groupeffx)
d$etrue   - rnorm(n, sd = sqrt(d$verror))
d$y   - 5 + d$x + d$theta + d$etrue
d$verrorf - factor(paste(v,d$verror,sep=))

print(tapply(d$etrue, d$verrorf, var))

## function to collect pieces from lme() output
sumLME - function(o){
  tab   - summary(o)$tTable
  r - c(tab[1,1:2], tab[2,1:2], as.numeric(VarCorr(o))[3:4])
  names(r) - c(b0,b0sd,b1,b1sd,sdgroup,sdresid)
  return(r)
}

## function to collect pieces from lmer() output
sumLMER - function(o){
  tab- summary(o)@coefs
  r - c(tab[1,1:2], tab[2,1:2],
as.numeric(attributes(VarCorr(o)$groupid)$stddev),
as.numeric(attr(VarCorr(o), sc)))
  names(r) - c(b0,b0sd,b1,b1sd,sdgroup,sdresid)
  return(r)
}

res - vector(0, mode=list)

library(nlme)
## lme, ignoring heteroskedasticity
res[[lme.nohet]] - sumLME( lme(fixed = y ~ x, data = d, random = ~1
| groupid) )

## lme, heteroskedastic model with variance weights estimated
res[[lme.esthet]] - sumLME( lme(fixed = y ~ x, data = d, random =
~1 | groupid, weights = varIdent(form = ~1|verrorf)) )

## lme, heteroskedastic model with true fixed weights
v - c(v0.5 = 0.5, v1 = 1, v2 = 2, v4 = 4)
sdrats - sqrt(v / v[1])[-1]
res[[lme.fixedhet]] - sumLME( lme(fixed = y ~ x, data = d, random =
~1 | groupid, weights = varIdent(form = ~1|verrorf, fixed = sdrats)) )

detach(package:nlme)
library(lme4)

## lmer, ignoring heteroskedasticity
res[[lmer.nohet]] - sumLMER( lmer(y ~ x + (1|groupid), data = d) )
## essentially matches res[[lme.nohet]], makes sense

## lmer, with fixed weights equal to known precisions
d$w1 - 1 / d$verror
res[[lmer.w1]] - sumLMER( lmer(y ~ x + (1|groupid), data = d, weights = w1) )
## only b0 and b1 matches res[[lme.fixedhet]]

## lmer, with fixed weights proportional to known precisions but weights sum to
## number of records as they would with the unweighted case.
d$w2 - nrow(d) * d$w1 / sum(d$w1)
res[[lmer.w2]] - sumLMER( lmer(y ~ x + (1|groupid), data = d, weights = w2) )
## this is extremely close to res[[lme.fixedhet]] except for sdresid

do.call(rbind, res)


## is the case that matched only because of balance?
dsub - d[sample(1:nrow(d), size= nrow(d)/2, replace=F),]
dsub$w2 - nrow(dsub) * dsub$w1 / sum(dsub$w1)

sumLMER( lmer(y ~ x + (1|groupid), data = dsub, weights = w2) )
detach(package:lme4)
library(nlme)
sumLME( lme(fixed = y ~ x, data = dsub, random = ~1 | groupid, weights
= varIdent(form = ~1|verrorf, fixed = sdrats)) )
## these no longer match

[[alternative HTML version deleted]]

__
R-help@r-project.org 

[R] add euro sign to a plot

2010-03-21 Thread Martin Batholdy
hi,

Is it possible to add special characters like the euro sign to a plot?

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.


Re: [R] add euro sign to a plot

2010-03-21 Thread Rodrigo Aluizio
Hi Martin, here as example code that may help you to get what you want (once
you didn't specified were in the plot you want the symbol).

plot(1:10)
title(main= \u20ac, font = 5)

Ps.: This coding may differ between operational system, this one worked in a
Windows Vista 32 bits.
This works for all (I guess) the special character present in the windows
Character Map, just copy the code and use as \SymbolCode.

Hope it helps.

Rodrigo.

2010/3/21 Martin Batholdy batho...@googlemail.com

 hi,

 Is it possible to add special characters like the euro sign to a plot?

 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.


[[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] calling external .EXE file in R macOSX

2010-03-21 Thread Alex Anderson

Hi All,
I am currently working on an analysis which requires a call to an 
external FORTRAN routine contained within a file called MCDS.EXE.  This 
file is usually called from within a WINDOWS program called DISTANCE.  I 
have some R script from the developers of the original software which 
apparently makes a call to this  .EXE file which i need to re-engineer 
slightly,  but i am having difficulty interpreting how the script makes 
this call and passes to the EXE file the relevant input command file and 
data file for processing.  I am also unsure if making such a call will 
work within the OSX environment for a (windows?) executable file.  Below 
is an example from the script which is supposed to make the call. Any 
suggestions would be much appreciated.

Cheers
A

cds - function (key, adj, L, w, A=NA, xi, zi, 
file.base,ext.files=F,bootstrap=F) {

#Purpose: Driver function to run the mcds.exe engine from R
#Updated by Tiago on 19/12/2004 so that it can take an external data and 
command input files
#Usefull if you want to do a non-standard bootstrap analysis of some 
data analised in distance

#and for wich distance is not capable of producing variance estimates
#This way, you can call this function inside a bootstrap procedure, as 
long as you update the

#data file at each resample
#Inputs:
#  key- vector string containing key functions
#  adj- vector string containing adjustment terms
#  L - total survey effort
#  A - survey area
#  xi - vector of perpendicular distances
#  zi - vector of cluster sizes
#  file.base - if specified and engine is cds, then the cds input and
#  output files are written into the current directory, with the
#  cds.file.base as a prefix and '.txt' as a suffix.  E.g., setting
#  cds.file.base to 'cds' produces 'cds.cmd.txt', 'cds.data.txt',
#  'cds.log.txt','cds.stat.txt','cds.plot.txt' and 'cds.boot.txt'
#  If not specified, these files are created in a temp location and
#  are deleted at the end.
#  ext.files - If true, then the funtion uses the external files 
'file.base'+'.cms.'+txt' as command file
#  and 'file.base'+'.data.'+.txt' as data file. Typicaly these 
files would be the result of
#  runing Distance in debug mode, and should be placed in the 
working directory for R.
#  By default ext.files is false, so the function looks for the 
files produced  by functions

#  'create.data.file' and  'create.command.file'
#  You need to change the input comand file in order for the 
mcds engine to produce the files
#  that the function 'read.stats.file' expects, and that means 
that inside the command file you should define

#  file names with prefix = file.base
#  bootstrap - If true, procedure is being called inside a bootstrap 
routine, and intermediate files

#   are deleted at each loop step, except the command file
#Outputs: list, containing
# Nhat.grp, Nhat.ind, mu, nL, Es, LnL, AIC, status
# Note - status is an integer:
#  1=OK, 2=warnings, 3=errors, 4=file errors, 5=some other problem 
(e.g., program crash)


run.cds-function(cmd.file.name) {
#Purpose: runs the MCDS.exe engine and waits for it to finish
#  *Note* that mcds.exe needs to be in the working directory, or in the
#  PATH windows environment
#  variable for this to work, as it makes no attempt to find the
#  location of the file
#Inputs:
#  cmd.file.name - name of the command file to run
#Returns:
#  A status integer - 1=OK, 2=warnings, 3=errors, 4=file errors, 5=some 
other problem (e.g., program crash)


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

2010-03-21 Thread Roy Lowrance
Hi All:

I am trying to move a model from Stata to R.

It is a linear regression model with about 90,000 indicator variables.

What is the best approach to follow in R?

- Roy

[[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] Find a rectangle of maximal area

2010-03-21 Thread Jim Lemon

On 03/21/2010 10:12 PM, Hans W Borchers wrote:

For an application in image processing -- using R for statistical purposes -- I
need to solve the following task:

Given n (e.g. n = 100 or 200) points in the unit square, more or less randomly
distributed. Find a rectangle of maximal area within the square that does not
contain any of these points in its interior.

If a, b are height and width of the rectangel, other constraints may have to be
imposed such as  a, b= 0.5  and/or  0.5= a/b= 2.0 . The rectangle is
allowed to touch the border of the square.

For each new image the points will be identified by the application, like all
stars of a certain brightness on an astronomical picture. So the task will have
to be performed several times.

I assume this problem is computationally hard. I would like to find a solution
that is reasonably fast for  n = 100..200  points. Exhaustive search along the
x, y coordinates of the points will not be fast enough.

I know this request is not about R syntax and does not contain 'repro-code'. But
perhaps a somehow similar problem has been solved before.


Hi Hans,
The emptyspace function in the plotrix package is a fairly crude 
implementation of this, but the code might give you some ideas.


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] calling external .EXE file in R macOSX

2010-03-21 Thread Sharpie


Alex Anderson wrote:
 
 Hi All,
 I am currently working on an analysis which requires a call to an 
 external FORTRAN routine contained within a file called MCDS.EXE.  This 
 file is usually called from within a WINDOWS program called DISTANCE.  I 
 have some R script from the developers of the original software which 
 apparently makes a call to this  .EXE file which i need to re-engineer 
 slightly,  but i am having difficulty interpreting how the script makes 
 this call and passes to the EXE file the relevant input command file and 
 data file for processing.  I am also unsure if making such a call will 
 work within the OSX environment for a (windows?) executable file.  Below 
 is an example from the script which is supposed to make the call. Any 
 suggestions would be much appreciated.
 Cheers
 A
 
 {snip}
 
 


Hrm, I really can't tell what that function you posted does-- it seems to be
mostly comments.  But I would imagine MCDS.EXE is being run using something
like a call to the system() function.

The problem with running the program on OS X is that MCDS.EXE is a Windows
binary.  You can't just run a binary compiled for Winows on OS X or Linux
more than you could run a binary compiled for OS X or Linux on Windows.

Your options include:

  1. Get the Fortran source code, recompile MCDS on OS X , and run the
program using something like system('mcds')

  2. Get the Fortran source code, refactor and recompile MCDS as a shared
library, load directly into R, and run the routines using .Fortran()

  3. Try using an emulator, such as Wine (www.winehq.ort), and run the
program using something like system('wine MCDS.EXE')

Number three would require the least amount of hassle, but is not guaranteed
to work.  Other people may have better suggestions and you might try asking
on the mac-specific R mailing list:

  https://stat.ethz.ch/mailman/listinfo/r-sig-mac

The people there may be able to give you better answers concerning R and OS
X

Good Luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://n4.nabble.com/calling-external-EXE-file-in-R-macOSX-tp1677148p1677162.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] multiple logical comparisons

2010-03-21 Thread David Winsemius

Just read the help page:

?%in%

%w/o% - function(x,y) x[!x %in% y] #-- x without y
(1:10) %w/o% c(3,7,12)
--  
David.

On Mar 21, 2010, at 5:57 PM, Martin Batholdy wrote:


thanks!



Now I have one more question;

How can I do the reverse?
when %in% is == (for two vectors of different lengths); what is the  
equivalent to !=  ?




On 21.03.2010, at 22:33, Erik Iverson wrote:


Martin Batholdy wrote:

Hi,
I would like to compare a column of data with a vector.
I have this data.frame for example;
x - data.frame(A = c(1:5), B = c(1,1,2,2,2))
Now I have a search vector:
search - c(1,3,5)
when I now try to get all the data-rows which have a 1, a 3, or a  
5 in column A and a 2 in column B, I tried this:

x[x$B == 2  x$A == search,]
I hoped to get 3 2
5 2
as output.


See ?%in%

x[x$B == 2  x$A %in% search, ]




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Problem using ESS. Error message: cannot change working directory

2010-03-21 Thread Nicolas Leveroni
Greetings R wizards.
I have the following problem using Emacs Speaks Statistics:

When trying to set a working directory, or when trying to read a file
that is in a directory that has the character á (note that it has a
spanish accent symbol: ´ )  R being ran from emacs tells me that the
directory doesn't exist, or that it can't be found, or:

 setwd(c:/Documents and Settings/Nicolás)
Error in setwd(c:/Documents and Settings/Nicolás) :
  cannot change working directory

I do NOT have the same problem if I try to do this directly with R
GUI. In my opinion, emacs is telling R Nicolás when it should
tell it Nicolás.

Any thoughts??

Thanks for your help. Thanks for R, and greetings to the hole
community of users, developers, etc.,

Nicolás Leveroni

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


Re: [R] Problem specifying Gamma distribution in lme4/glmer

2010-03-21 Thread David Winsemius


On Mar 21, 2010, at 5:16 PM, Ben Bolker wrote:


Dieter Menne dieter.menne at menne-biomed.de writes:


Ben Bolker wrote:



3. zero-inflated data may not be particularly well-represented
by a Gamma distribution: if you actually have a significant number
of exactly-zero values, you may want to analyze your data in two
stages, first as a presence-absence problem and then as a  
conditional

density (i.e., what is the distribution of the non-zero values)?



[...] Do you know of a example where this was done (independent
of lmer)?  [...]


Nothing springs to mind, but it seems sensible.


I thought this was what hurdle and ZIF models were supposed to handle  
gracefully?


--
David.


Ben Bolker


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


Re: [R] lattice grob

2010-03-21 Thread Paul Murrell

Hi

baptiste auguie wrote:

Dear list,

I'm trying to arrange various grid objects on a page using a
frameGrob. It works fine with basic grobs (textGrob, gTree, etc.), and
also with ggplot2 objects using the ggplotGrob() function. I am
however stuck with lattice. As far as I understand, lattice produces a
list of class trellis, which is eventually displayed using the
plot.trellis method. I am not sure if/how one can convert this list
into a high-level grob. I tried the following,

latticeGrob - function(p, ...){
  grob(p=p, ..., cl=lattice)
}

drawDetails.lattice - function(x, recording=FALSE){
  lattice:::plot.trellis(x$p)


Try ...

lattice:::plot.trellis(x$p, newpage=FALSE)

Paul



}

p1 - xyplot(1:10 ~ 1:10)
g1 - latticeGrob(p1)

grid.draw(g1) # works fine

but,

fg - frameGrob(layout = grid.layout(1,1))
fg - placeGrob(fg, g1, row = 1, col = 1)
grid.draw(fg)

Error in UseMethod(depth) :
  no applicable method for 'depth' applied to an object of class NULL

Ideas are most welcome,

Best regards,

baptiste


sessionInfo()

R version 2.10.1 RC (2009-12-06 r50690)
i386-apple-darwin9.8.0

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

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

other attached packages:
[1] ggplot2_0.8.7   digest_0.4.1reshape_0.8.3   plyr_0.1.9
proto_0.3-8 gridExtra_0.5   lattice_0.17-26 gtools_2.6.1

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


--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~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.


Re: [R] Find a rectangle of maximal area

2010-03-21 Thread Erwin Kalvelagen
Hans W Borchers hwborchers at googlemail.com writes:

 
 For an application in image processing -- using R for statistical purposes -- 
I
 need to solve the following task:
 
 Given n (e.g. n = 100 or 200) points in the unit square, more or less randomly
 distributed. Find a rectangle of maximal area within the square that does not
 contain any of these points in its interior.
 
 If a, b are height and width of the rectangel, other constraints may have to 
be
 imposed such as  a, b = 0.5  and/or  0.5 = a/b = 2.0 . The rectangle is
 allowed to touch the border of the square.
 
 For each new image the points will be identified by the application, like all
 stars of a certain brightness on an astronomical picture. So the task will 
have
 to be performed several times.
 
 I assume this problem is computationally hard. I would like to find a solution
 that is reasonably fast for  n = 100..200  points. Exhaustive search along the
 x, y coordinates of the points will not be fast enough.
 
 I know this request is not about R syntax and does not contain 'repro-code'. 
But
 perhaps a somehow similar problem has been solved before.
 
 Thanks in advance for any suggestions,
 Hans Werner
 


I solved this with a simple minded MINLP formulation using BARON (a global 
solver). 
This seems to produce solutions relatively quickly (somewhat slower for n=200). 
Actually this solved easier than I expected. See:

http://yetanothermathprogrammingconsultant.blogspot.com/2010/03/looks-difficult-
to-me-2.html


Erwin Kalvelagen
Amsterdam Optimization Modeling Group
er...@amsterdamoptimization.com
http://amsterdamoptimization.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.