[R] filled.contour colorbar without black color separators?

2010-11-05 Thread Gregor Volberg

Dear list members, 

I have been using filled.contour in order to plot EEG data. For the colors, I 
used a conventional ramp from blue to red (blue - green - yellow - red), and 
100 color levels to make the plot looking smooth: 

(...) color.palette = colorRampPalette(c('blue','green',  'yellow','red'), 
space='rgb'), nlevels = 100 (...) 

 My problem ist that filled.contour draws a black bar as a separation between 
each color of the color bar (color key) so that color bar becomes essentially 
black if I use many color levels. Is there a way to  turn of this behavior? Any 
advice would be greatly appreciated, 
Gregor 



-- 
Dr. rer. nat. Gregor Volberg gregor.volb...@psychologie.uni-regensburg.de ( 
mailto:gregor.volb...@psychologie.uni-regensburg.de )
University of Regensburg
Institute for Experimental Psychology
93040 Regensburg, Germany
Tel: +49 941 943 3862 
Fax: +49 941 943 3233
http://www.psychologie.uni-regensburg.de/Greenlee/team/volberg/volberg.html



[[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] Generate variable with Bivariate Normal Distribution

2010-10-20 Thread Gregor
You could e.g. use the package mvtnorm (not horribly fast, but handy):

(assuming that rho is the correlation)

library(mvtnorm)
m - c(mean1, mean2) #mean vector
cov - rho*sqrt(variance1*variance2)
sig - matrix(c(variance1, cov, cov, variance2), nrow=2) #covariance matrix
rmvnorm(100, mean=m, sigma=sig)

alternatively, you can transform manually via sigma^(1/2) (faster). This is 
covered
in almost any (multivariate) statistics book.

Gregor


On Wed, 20 Oct 2010 12:29:53 +0700
สถาบันวิจัยและพัฒนา มหาวิทยาลัยราชภัฏอุบลราชธานี ird_u...@hotmail.com wrote:

 
 Dear All
 
 I want to generate variable with Bivariate Normal Distribution by 
 use mean1 = a, variance1 = b, mean2 = c, variance2 = d, rho = e.
 
  How I can do this.
 
 Many Thanks.
 
 IRD 
   [[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] fast rowCumsums wanted for calculating the cdf

2010-10-15 Thread Gregor
Dear all,

Maybe the easiest solution: Is there anything that speaks against generalizing
cumsum from base to cope with matrices (as is done in matlab)? E.g.:

cumsum(Matrix, 1)
equivalent to
apply(Matrix, 1, cumsum)

The main advantage could be optimized code if the Matrix is extreme nonsquare
(e.g. 100,000x10), but the summation is done over the short side (in this case 
10).
apply would practically yield a loop over 100,000 elements, and vectorization 
w.r.t.
the long side (loop over 10 elements) provides considerable efficiency gains.

Many regards,
Gregor




On Tue, 12 Oct 2010 10:24:53 +0200
Gregor mailingl...@gmx.at wrote:

 Dear all,
 
 I am struggling with a (currently) cost-intensive problem: calculating the
 (non-normalized) cumulative distribution function, given the (non-normalized)
 probabilities. something like:
 
 probs - t(matrix(rep(1:100),nrow=10)) # matrix with row-wise probabilites
 F - t(apply(probs, 1, cumsum)) #SLOOOW!
 
 One (already faster, but for sure not ideal) solution - thanks to Henrik 
 Bengtsson:
 
 F - matrix(0, nrow=nrow(probs), ncol=ncol(probs));
 F[,1] - probs[,1,drop=TRUE];
 for (cc in 2:ncol(F)) {
   F[,cc] - F[,cc-1,drop=TRUE] + probs[,cc,drop=TRUE];
 }
 
 In my case, probs is a (30,000 x 10) matrix, and i need to iterate this step 
 around
 200,000 times, so speed is crucial. I currently can make sure to have no NAs, 
 but
 in order to extend matrixStats, this could be a nontrivial issue.
 
 Any ideas for speeding up this - probably routine - task?
 
 Thanks in advance,
 Gregor
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] fast rowCumsums wanted for calculating the cdf

2010-10-12 Thread Gregor
Dear all,

I am struggling with a (currently) cost-intensive problem: calculating the
(non-normalized) cumulative distribution function, given the (non-normalized)
probabilities. something like:

probs - t(matrix(rep(1:100),nrow=10)) # matrix with row-wise probabilites
F - t(apply(probs, 1, cumsum)) #SLOOOW!

One (already faster, but for sure not ideal) solution - thanks to Henrik 
Bengtsson:

F - matrix(0, nrow=nrow(probs), ncol=ncol(probs));
F[,1] - probs[,1,drop=TRUE];
for (cc in 2:ncol(F)) {
  F[,cc] - F[,cc-1,drop=TRUE] + probs[,cc,drop=TRUE];
}

In my case, probs is a (30,000 x 10) matrix, and i need to iterate this step 
around
200,000 times, so speed is crucial. I currently can make sure to have no NAs, 
but in
order to extend matrixStats, this could be a nontrivial issue.

Any ideas for speeding up this - probably routine - task?

Thanks in advance,
Gregor

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

2010-09-01 Thread Waller Gregor (wall)

hi there.. i got a problem with ggplot2.

here my example:

library (ggplot2)

v1  - c(1,2,3,3,4)
v2  - c(4,3,1,1,9)
v3  - c(3,5,7,2,9)
gender - c(m,f,m,f,f)

d.data  - data.frame (v1, v2, v3, gender)
d.data

x  - names (d.data[1:3])
y  -  mean (d.data[1:3])


pl  - ggplot (data=d.data, aes (x=x,y=y))
pl  - pl + geom_bar()
pl  - pl + coord_flip()
pl  - pl + geom_text (aes(label=round(y,1)),vjust=0.5,
hjust=4,colour=white, size=7)
pl

this gives me a nice barchart to compare the means of my variables
v1,v2 and v3.
my question: how do i have to proceed if i want this barchart splittet
by the variable gender.
so i get two small bars for v1, one for female and one for male, two
bars for v2 etc. 
i need them all in one chart. 

fill=gender, position=dodge do not work... 

any ideas?

thanks a lot

greg

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Function for Estimating Fractional Multinomial Logit Model?

2009-07-21 Thread GREGOR Brian J
I need to estimate a model that predicts the proportional split of
travel among the vehicles of a household based on vehicle
characteristics such as age, fuel economy, and travel cost per mile. The
model estimation dataset has a record for each household vehicle with
information about the vehicle, the household, and the proportion of the
total household vehicle travel using that vehicle. I have not been able
to figure out how use multinomial logit estimation functions in R to
predict proportions rather than categorical probabilities. I have found
from searching the web that there is a Stata function, FMLOGIT, that
will do what I want. Does anyone know how this can be done in R? All of
my model estimation scripts for the large model I'm building are in R
and I would like to keep it that way to create a nice replicable set of
scripts and data to document the model. Thanks much.
 
Brian Gregor 
Senior Transportation Analyst 
Oregon Department of Transportation 
Transportation Planning Analysis Unit 
555 13th Street NE 
Salem, OR 97301 
503-986-4120 


[[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] transforming character categories

2009-06-28 Thread Gregor Povh



Dear R users,

apologies for this quite simple question.  I've tried serverall 
approaches, however, could not generate the desired result.


I have a large data frame, which has several cathegories encoded as 
character strings, for example.


Name, income, gender, ...
...  from 1000$ to 2000$  ...
...  from 2000$  to 3000$ ...
...  more than 3000$...
...  from 1000$ to 2000$  ...
...  from 1000$ to 2000$  ...


How can I transform this column into numeric values for the categories, 
for example in somethins like this:

... 1000 ...
... 2000 ...
... 3000 ...
... 1000 ...
... 1000 ...

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

2009-06-28 Thread Gregor Povh
Thanks Gabor, but in my case not every value ist actually encoded within 
the character string.  Vor example, I have an answer category, which is 
more than one Mio. $.  (not in the column income...). 

I have the feeling, that there must be an another, straightforward way 
or function for transformation of levels / categories, but I just cannot 
make it work.

- greg

 Try this.  It matches the first numeric string on
 each line applying as.numeric to it and then using
 c to simplify the resulting list to a numeric vector.

   
 x - c(from 1000$ to 2000$, from 2000$  to 3000$, more than 3000$,
 
 + from 1000$ to 2000$, from 1000$ to 2000$)

   
 library(gsubfn)
 strapply(x, ([0-9]+).*, as.numeric, simplify = c)
 
 [1] 1000 2000 3000 1000 1000

 See the gsubfn home page for more:
 http://gsubfn.googlecode.com

 On Sun, Jun 28, 2009 at 4:25 AM, Gregor Povhgregorp...@yahoo.de wrote:
   
 Dear R users,

 apologies for this quite simple question.  I've tried serverall approaches,
 however, could not generate the desired result.

 I have a large data frame, which has several cathegories encoded as
 character strings, for example.

 Name, income, gender, ...
 ...  from 1000$ to 2000$  ...
 ...  from 2000$  to 3000$ ...
 ...  more than 3000$...
 ...  from 1000$ to 2000$  ...
 ...  from 1000$ to 2000$  ...


 How can I transform this column into numeric values for the categories, for
 example in somethins like this:
 ... 1000 ...
 ... 2000 ...
 ... 3000 ...
 ... 1000 ...
 ... 1000 ...

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] graphically representing frequency of words in a speech?

2009-06-07 Thread Gorjanc Gregor
 The only thing that I found for R is by Gregor Gorjanc, but the
 information seems to be dated:

http://www.bfro.uni-lj.si/MR/ggorjan/software/R/index.html#tagCloud

Hi,

Yes, I have tried to create a tag cloud plot in R, but I abandoned the project
due to other things. The main obstacle was that in R we need to take
care of the fontsizes and placement of words, while this is very easy with
say browsers, who do all the renderind. I tracked the last version of the R file
which is pasted bellow. I must say that I do not remember the status of the
code so use it as you wish. If anyone wishes to take this project further, 
please
do so!

gg

### tagCloud.R
###
### What: Tag cloud plot functions
### Time-stamp: 2006-09-10 02:53:29 ggorjan
###

tagCloud - function(x, n=100, decreasing=TRUE,
 threshold=NULL, fontsize=c(12, 36),
 align=TRUE, expandRow=TRUE,
 justRow=bottom, title,
 textGpar=gpar(col=navy),
 rectGpar=gpar(col=white),
 titleGpar=gpar(), viewGpar=gpar(),
 mar=c(1, 1, 1, 1))
{
  UseMethod(tagCloud)
}

tagCloud.default - function(x, n=100, decreasing=TRUE,
 threshold=NULL, fontsize=c(12, 36),
 align=TRUE, expandRow=TRUE,
 justRow=bottom, title,
 textGpar=gpar(col=navy),
 rectGpar=gpar(col=white),
 titleGpar=gpar(), viewGpar=gpar(),
 mar=c(1, 1, 1, 1))
{
  if(!is.null(dim(x))) stop('x' must be a vector)

  tagCloud.table(table(x), n=n, decreasing=decreasing, fontsize=fontsize,
 threshold=threshold, align=align, expandRow=expandRow,
 justRow=justRow, title=title, textGpar=textGpar,
 rectGpar=rectGpar, titleGpar=titleGpar, viewGpar=viewGpar,
 mar=mar)
}

tagCloud.table - function(x, n=100, decreasing=TRUE,
   threshold=NULL, fontsize=c(12, 36),
   align=TRUE, expandRow=TRUE,
   justRow=bottom, title,
   textGpar=gpar(col=navy),
   rectGpar=gpar(col=white),
   titleGpar=gpar(), viewGpar=gpar(),
   mar=c(1, 1, 1, 1))
{
  ## --- Check ---

  if(length(dim(x)) != 1)
stop('x' must be one dimensional table)

  ## --- Threshold ---

  if(!is.null(threshold)) x - x[x = threshold]

  ## --- Number of units ---

  N - length(x)## length of table
  if(is.null(n)) {  ## if n=NULL, plot all units
n - N
  } else {
if(n  N) n - N## if n is to big, decrease it
if(n  1) n - round(N * n) ## if n is percentage of units
  }

  fontsizeLength - length(fontsize)
  if(fontsizeLength != 2)
stop('fontsize' must be of length two)

  ## --- Sort and subset ---

  if(n  N) { ## only if we want to plot subset of units
tmp - sort(x, decreasing=decreasing)
x - x[names(x) %in% names(tmp[1:n])]
  }

  ## --- Get relative freq ---

  x - prop.table(x)

  ## --- Fontsize ---

  fontsizeDiff - diff(fontsize)
  xDiff - max(x) - min(x)
  if(xDiff != 0) {
off - ifelse(fontsizeDiff  0, min(x), max(x))
fontsize - (x - off) / xDiff * fontsizeDiff + min(fontsize)
  } else { ## all units have the same frequency
fontsize - rep(min(fontsize), times=n)
  }

  ## --- Viewport and rectangle ---

  grid.newpage()
  width - unit(1, npc)
  height - unit(1, npc)
  vp - viewport(y=unit(mar[1], lines), x=unit(mar[2], lines), ,
 width=width - unit(mar[2] + mar[4], lines),
 height=height - unit(mar[1] + mar[3], lines),
 just=c(left, bottom), gp=viewGpar, name=main)
  pushViewport(vp)

  if(!missing(title))
grid.text(title, y=height, gp=titleGpar, name=title)

  grid.rect(gp=rectGpar, name=cloud)

  ## --- Grobs ---

  tag - vector(mode=list, length=4)
  names(tag) - c(fontsize, grob, width, height)
  tag[[1]] - tag[[2]] - tag[[3]] - tag[[4]] - vector(mode=list, length=n)
  for(i in 1:n) {
tag$fontsize[[i]] - fontsize[i]
tag$grob[[i]] - textGrob(names(x[i]), gp=gpar(fontsize=fontsize[i]))
tag$width[[i]] - convertWidth(grobWidth(tag$grob[[i]]), unitTo=npc,
   valueOnly=TRUE)
tag$height[[i]] - convertHeight(grobHeight(tag$grob[[i]]), unitTo=npc,
 valueOnly=TRUE)
  }

  ## --- Split lines ---

  row - colWidth - vector(length=n)
  row[1] - 1
  colWidth[1] - 0
  lineWidth - tag$width[[1]]
  j - 1
  gapWidth - convertWidth(stringWidth( ), unitTo=npc, valueOnly=TRUE)
  maxWidth - convertWidth(width, unitTo=npc, valueOnly=TRUE)

  for(i in 2:length(tag

[R] Using spdep example data and R code : bbox should never contain infinite values

2009-04-17 Thread Dejan Gregor
Hi,

I am facing with a problem when running a code against the sample data from
spdep. I am getting

SpatialPoints object : bbox should never contain infinite values
In additionl Warning Messages:
1. In min(x): no non-missing arguments to min; returning Inf
2. In max(x): no non-missing arg...


The code I am trying to execute:

sidgams-opgamdata=as(nc, data.frame), radius=30, step=10, alpha=.002)
gampoints-SpatialPoints(sidsgam[,c(x,y)]*1000,
  CRS(+proj=utm +zone=18 +datum=WGS84))

The input dataset is a modified polygon (in WGS datum) of North Carolina
that comes with spdep, but using some other additional fields for
calculation.

I would be very happy to receive a suggestion on corecting this.

Thanks!

Dejan

[[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] density plot probabilities

2009-02-01 Thread gregor rolshausen

hello !
I have question concerning *kernel density plots*:

how to plot density vs. the probability of a vector, when that vector 
is very short (5-10 values)?

I tried:

 plot(density(x))

or

 hist(x,probability=T,border=white)
 lines(density(x))

for small length of vectors, the ylab is not 0ylab1 but fro example 
from 0 to 3. thats confusing for a density... why is that?


thanks for your time.
cheers,
gregor

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

2009-02-01 Thread gregor rolshausen

sorry!

I ment to plot the probability vs. the values of course. not the 
probability vs. the density...


cheers,gregor

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


[R] R and Xcode Editor

2009-01-21 Thread Gregor Reich

Hi

From the R for OS X FAQ page: (http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html 
)


4.4.6 Editor (internal and external): Using AppleScript it is easy to  
implement Command-E and Command-Return like functionality.


How?

Regards, Gregor.

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


[R] logistic regression - exp(estimates)?

2009-01-15 Thread gregor rolshausen

hello.

I have a question on the interpretation of a logistic model.

is it helpful to exponentiate the coefficients (estimates)? I think I 
once read something about that, but I cannot remember where.

if so, how would be the interpretation of the exp(estimate) ?

would there be a change of the interpretation of the ANOVA table (or is 
the ANOVA table not really helpful at all?).



thanks for your time.

cheers,
gregor rolshausen

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


Re: [R] How to compute p-Values

2009-01-14 Thread gregor rolshausen

Andreas Klein wrote:

Hello.


How can I compute the Bootstrap p-Value for a one- and two sided test, when I 
have a bootstrap sample of a statistic of 1000 for example?

My hypothesis are for example:

1. Two-Sided: H0: mean=0 vs. H1: mean!=0
2. One Sided: H0: mean=0 vs. H1: mean0

  

hi,
do you want to test your original t.test against t.tests of bootstrapped 
samples from you data?


if so, you can just write a function creating a vector with the 
statistics (t) of the single t.tests (in your case 1000 t.tests each 
with a bootstrapped sample of your original data - 1000 simulated 
t-values).

you extract them by:

 tvalue=t.test(a~factor)$statistic

then just calculate the proportion of t-values from you bootstrapped 
tests that are bigger than your original t-value.


p=sum(simualted_tvalueoriginal_tvalue)/1000


(or did I get the question wrong?)

cheers,
gregor

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

2009-01-13 Thread gregor rolshausen

hello,
I want to fit a curve to a simple x,y dataset - my problem is, that I 
want to fit it for the following term:


n(1-e^x/y) - so I get the n constant for my data...

can anyone help/comment on that?

cheers,
gregor

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

2009-01-13 Thread gregor rolshausen

ok. sorry for being blurry.

I have x,y data, that probably fits a asymptotic curve (asymptote at N). 
now I want to fit a curve onto the data, that gives me the N. therefore 
I thought to fit an e-function, namely N(1-e^(y/x)) onto the data and 
get the N from the fitted curves' equation.
in the course of this, I was looking for a R-function to fit a given 
function to data.
(I believe there is some implementation in MatLab for this kind of 
question, anyhow, I wanted to look in R as well...)


I am not an expert, so excuse my misuse of terms. I hope my problem 
graspable...?


cheers,
gregor




Uwe Ligges wrote:



gregor rolshausen wrote:

hello,
I want to fit a curve to a simple x,y dataset - my problem is, that I 
want to fit it for the following term:


n(1-e^x/y) - so I get the n constant for my data...


Not an R problem in the first place, but the question arises what 
n(1-e^x/y) means, its is just some scalar value so far. I am looking 
for some equation ...


Uwe Ligges




can anyone help/comment on that?

cheers,
gregor

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] PCA loadings differ vastly!

2009-01-13 Thread gregor rolshausen

hi, I have two questions:

#first (SPSS vs. R):

I just compared the output of different PCA routines in R (pca, prcomp, 
princomp) with results from SPSS. the loadings of the variables differ 
vastly! in SPSS the variables load constantly higher than in R.
I made sure that both progr. use the correlation matrix as basis. I 
found the same problem with rotated values (varimax rotation and rtex=T 
rotation).


can anyone comment ?

second:

princomp(data, cor=T, rtex=T)$loadings  vs.  princomp(data, cor=T, 
rtex=F)$loadings


gives me different loadings (expected because of rotation) with one 
dataset (11 variables)

but returns the SAME values with another dataset (3 variables).

comments ??

thanks for your time!

cheers,
gregor

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

2009-01-13 Thread Gregor Gorjanc
 Richard.Cotton at hsl.gov.uk writes:
 I'm running OpenBUGS model via the R2WinBUGS package interface, under 
 Windows.  Is it possible to terminate running models, short of using the 
 Windows Task Manager to forcibly exit the program?

If you use OpenBUGS, then I guess you can not since R2WinBUGS just passes a call
to BRugs and there is no way to stop that process or maybe it is - take a look
in the list of processes. If you use WinBUGS, then you can safely kill it and
R will not terminate.

gg

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

2009-01-01 Thread Gregor Gorjanc
Anny Huang annylhuang at gmail.com writes:
 I did some analysis using package R2WinBUGS to call WinBUGS. I set the
 iterations to 5 (fairly a large number, I think), but after the program
 was done,  the effective posterior samples contained only 7 draws.  I don't
 know why.

This indicates that you have a mixing problem! I guess that you do not have 
enough information to retrieve the post. dist. of that parameter. You might
try to reconsider your model or reparametrize it.

gg

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] [Solved] Re: Sweave from Kile

2008-10-14 Thread Gorjanc Gregor
Hi Matthieu!

I am glad you solved your problem.

 Now I can compile direct from Kile! The only problem is that the command
 -ld only create the pdf, does not open it. Maybe are there other options
 from Script File of Gregor Gorjanc to compile with pdflatex (texi2dvi
 did not work) and open but I just made it from Kile: Settings-Configure
 Kile-Tools-Build-New Tool, configure it based on Archive for example,
 put the new command sweave  and then add any command to open (viewpdf in
 my case).

There are several arguments one can use with Sweave.sh. Try

Sweave.sh --help and you will get the help informtion.

Here is the relevant part about ways of compiling LaTeX and about direct
opening with Acrobat Reader or similar applications.

There are now the following ways of LaTeX processing:

  Command and path Script option Used tools
   - texi2dvi
  - PS  -tp, --texi2dvi2ps   texi2dvi and dvips
  - PS to PDF   -tld, --texi2dvi2ps2pdf  texi2dvi, dvips and ps2pdf
  - PDF -td, --texi2dvi2pdf  texi2dvi with pdf option

   - latex
  - PS  -lp, --latex2dvi2ps  hardcoded set of 'latex and 
friends' and dvips
  - PS to PDF   -lld, --latex2dvi2ps2pdf hardcoded set of 'latex and 
friends', dvips and ps2pdf

   - pdflatex
  - PDF -ld, --latex2pdf hardcoded set of 'pdflatex and 
friends'

Open produced files (PDF or Postscript) via options bellow, which are
one step further of options above and always imply them:

-otp=gv, --opentexi2dvi2ps=gv
-otld=acroread, --opentexi2dvi2ps2pdf=acroread
-otd=acroread, --opentexi2dvi2pdf=acroread
-olp=gv, --openlatex2dvi2ps=gv
-olld=acroread, --openlatex2dvi2ps2pdf=acroread
-old=acroread, --openlatex2pdf=acroread
  Files are opened with given application. Defaults are values taken
  from environmental variables PDFAPP and PSAPP. If these are not
  defined 'acroread' is taken for PDF and 'gv' for Postscript. Quotes
  are necessary in case of bad filenames.

gg

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

2008-10-13 Thread Gorjanc Gregor
Hi Matthieu,

 Does anybody have experience with Sweave run from Kile? I'm trying to
 make it run but have problems and don't know if the instructions are
 false or I do something wrong (my knowledge in bash and shell is too low
 to understand it)...
...

It would help if you stated that you use mine Sweave.sh i.e. the one from
http://cran.r-project.org/contrib/extra/scripts/Sweave.sh. I will assume you
do.

I will start with the second problem

 2: If I run kile with sudo (sudo Kile), the problem disappears but a new
one comes
 SweaveOnly output:
 * cd '/media/Partition_Commune/Mes documents/Ordi/LaTex/Sweave'
 * Sweave.sh −ld '\example1Leisch.Rnw'
 *
 Run Sweave and postprocess with LaTeX directly from command line
 −ld is not a supported file type!
 It should be one of: .lyx, .Rnw, .Snw., .nw or .tex
 Is the instructions false? Or do I do something wrong?

Is there a single - or double - i.e. --. If I issue the following

$ Sweave.sh --ld test.Rnw

Run Sweave and postprocess with LaTeX directly from command line

--ld is not a supported file type!
It should be one of: .lyx, .Rnw, .Snw., .nw or .tex

I get the same error.

 1: finished with exit status 126
 SweaveOnly output:
 * cd '/media/Partition_Commune/Mes documents/Ordi/LaTex/Sweave'
 * Sweave.sh −ld '\example1Leisch.Rnw'
 *
 /bin/bash: /usr/local/bin/Sweave.sh: Permission non accordée
 in english: permission not given

It seems that chmod did not behave as you expected. First check file
permissions with

ls -l /usr/local/bin/Sweave.sh

On my computer I get

-rwxr-xr-x 1 root root 30K 2008-04-30 11:17 /usr/local/bin/Sweave.sh*

Note that x is there three times i.e. anyone can run this script, the user, the
group and others.

Try with

sudo chmod a+x /usr/local/bin/Sweave.sh

and check the file permissions.

gg
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Version 2.7.2 GUI acts awkward?

2008-09-30 Thread Gregor Rolshausen

hi,
I am running R 2.7.2 Windows - recently the GUI-windows (for example to 
change directory or read in R-scripts) do not open - well, they 
open, but close down directly afterwards. I can't select a directory or 
file ...


I tried re-installing R - same problem again.

does anybody have an idea?

thanks
gregor

--
Gregor Rolshausen

PhD Student; University of Freiburg, Germany

e-mail: [EMAIL PROTECTED]   
tel.  : ++49 761 2032559

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


Re: [R] ANOVA between within variance

2008-09-27 Thread Gregor Rolshausen
dear Dr. Kubovy,

I am sorry. but the Variance table is not exactly what I want. I want  
the partitioned VARIANCE for between and within the groups. the anova 
()-table just gives me the SumSq and the mean Sq... I know how to run  
t.test and ANOVA!
in the nlme-package there is the VarCorr function, which extracts the  
between and within variances, but only for nested ANOVAs. so my  
question was, if there is a function like that for not-nested ANOVAS ?

sorry. maybe I should reformulate the question.

cheers ,
gregor






Am Sep 27, 2008 um 7:19 AM schrieb Michael Kubovy:

 Than all you need is to run a t-test, no?  More generally (from ?lm):

 ctl - c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
 trt - c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
 group - gl(2,10,20, labels=c(Ctl,Trt))
 weight - c(ctl, trt)
 anova(lm.D9 - lm(weight ~ group))
 This gives you what you need:
 Analysis of Variance Table

 Response: weight
   Df Sum Sq Mean Sq F value Pr(F)
 group  1   0.690.691.42   0.25
 Residuals 18   8.730.48
 I am concerned that you have not spent enough time either studying  
 stats or reading up on R. There are many good introductions to  
 stats using R.
 _
 Professor Michael Kubovy
 University of Virginia
 Department of Psychology
 USPS: P.O.Box 400400Charlottesville, VA 22904-4400
 Parcels:Room 102Gilmer Hall
 McCormick RoadCharlottesville, VA 22903
 Office:B011+1-434-982-4729
 Lab:B019+1-434-982-4751
 Fax:+1-434-982-4766
 WWW:http://www.people.virginia.edu/~mk9y/


Gregor Rolshausen
PhD Student
Department of Evolutionary Ecology
University of Freiburg im Breisgau; Hauptstrasse 1, 79108 Freiburg
phone - +49.761.2559
email - [EMAIL PROTECTED]




[[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] ANOVA between within variance

2008-09-26 Thread Gregor Rolshausen

hi,
is there an option to calculate the 'within'  'between' group variances 
for a simple ANOVA (aov) model (2 groups, 1 trait, normally distr.) ?

or do I have to calculate them from the Sum Sq ?

thanks for your time and greetings,

gregor


--
Gregor Rolshausen

PhD Student; University of Freiburg, Germany

e-mail: [EMAIL PROTECTED]   
tel.  : ++49 761 2032559

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

2008-07-08 Thread Gregor Gorjanc
 tolga.i.uzuner at jpmorgan.com writes:

 I am looking for a way to get legends placed automagically in an empty 
 spot on a graph. Additional complication comes through my useage of 
 multiple graphs on the same plot through mfrow. 

Take a look in Hmisc package. There is function for this task.

Gregor

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

2008-05-23 Thread GREGOR Brian J
Monica, here are some other Pros to consider about R:

1) IMHO, the most important reason for using R is that expressed by John
Chambers as the aim of the S language: to turn ideas into software,
quickly and faithfully. The broad capabilities of R facilitate the
integration of data maintenance and cleaning, exploratory data analysis,
model estimation, model implementation, model calibration, model
application, and the reporting and display of model outputs. This has
tremendous productivity advantages. For example, I was able to meet a
tight timeline for developing a regional land use model because R
allowed me to easily move through the steps of model development from
data analysis to implementation. I even found that I could do some
geographical operations that could not be done using our GIS software.
In addition, all of the model outputs (including a very many maps) were
produced with R. Once you learn how to use R in this way, you will find
it takes less time to program the outputs in R than to produce them in
GIS. R yields productivity advantages in smaller ways too. We've
developed a number of small applications to solve GIS or other problems
that could not be solved as easily using other tools. Moreover, once
they have been solved using R, the solutions are easily automated or
recycled in other contexts.

2) R facilitates documentation and replication. Previous to using R, we
did our data analysis and implemented our models in a variety of
platforms. For example, Access, Excel, SPSS and Stata were all
previously used in household survey data processing and analysis. This
was a documentation nightmare. All the steps can be done using R instead
and documentation can be easily included in the scripts. If care is
taken to use good naming conventions that emphasize readability, the
scripts can be largely self documenting. This also facilitates group
work. 

Since we started using R in our work, we have been able to greatly
increase our modeling capabilities and output with no increase in
staffing.

Brian Gregor, P.E.
Senior Transportation Analyst
Oregon Department of Transportation
Transportation Planning Analysis Unit
555 13th Street NE
Salem, OR 97301
503-986-4120



Message: 22
Date: Thu, 22 May 2008 16:00:10 +
From: Monica Pisica [EMAIL PROTECTED]
Subject: [R] Pros and Cons of R
To: r-help@r-project.org
Message-ID: [EMAIL PROTECTED]
Content-Type: text/plain; charset=Windows-1252


Hi,

I am doing a very informal presentation for my office about R
capabilities to deal with and analyze spatial data, display data and
maps, and connections with GIS. I've used in my presentation info from
the CRAN, the spatial Task view, and the more striking graphics examples
from http://addictedtor.free.fr/graphiques/thumbs.php and NCEAS
http://www.nceas.ucsb.edu/scicomp/GISSeminar/UseCases/MapProdWithRGraphi
cs/OneMapProdWithRGraphics.html together with examples of my own work.

I am finishing with pros and cons about R and I am wondering if you can
come up with other examples, or comments. Here they are:

Pros:

- R is a programming environment well suited for statistical analysis.
- R is open source and cross platforms (Windows, Mac, Linux).
- Fortran, C (C++), and Python wrappers are in place.
- Deals well with spatial data, has a robust graphical interface and
has an active user group list / forum.
- External packages for R are almost daily increasing, most of them
based on published up-to-date books and peer-reviewed articles.
- R related books ? quite a few ?.

Cons:

- R has a very steep learning curve.
- There is no perfect ?beginner? book.
- Experience with other programming languages is a plus / minus.
- You can save scripts, but not *.exe.
- It is updated several times a year (good) but there are no up-grades.
- It seems that it is hard to install correctly under Linux.
- Everything you want to do is a command line, minimal GUI.
- Memory management problems (depends on your OS), especially when
displaying big images at high resolution or working with huge matrices
(hundreds of Mb).

Also i am wondering if R works under 64 bit computers and if it takes
advantage of it.

Thanks,

Monica 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Left censored responses in mixed effects models

2008-05-12 Thread Gregor Gorjanc
Bert Gunter gunter.berton at gene.com writes:
 Dear R Fellow-Travellers:
 
 What is your recommended way of dealing with a left-censored response
 (non-detects) in (linear Gaussian) mixed effects models?

Your description of the data calls for a tobit model

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

I think you need to take a look in the survival package.

Regards, Gregor

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] rbugs on linux and wine

2008-04-22 Thread Gorjanc Gregor
 Gregor Gorjanc wrote:
 Hi Alexander!

 You are mixing WinBUGS and OpenBUGS. R package Rbugs works with OpenBUGS, but
 the later does not work with Rbugs under Linux!

 Are you talking about rbugs or BRugs, Gregor?

Ouch. Thank you Uwe! You are right, there are two R packages: rbugs and BRugs. 
Unfortunatelly,
I do not have eany xperience with rbugs.

Sorry.

g

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] rbugs on linux and wine

2008-04-21 Thread Gregor Gorjanc
Hi Alexander!

You are mixing WinBUGS and OpenBUGS. R package Rbugs works with OpenBUGS, but
the later does not work with Rbugs under Linux!

Gregor

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

2008-03-06 Thread GREGOR Brian J
Chandra,

While I can't advise on how to use the ipf function in the cat package,
I can offer the following function that we use here to balance rebalance
arrays with new marginal totals.

#ipf.R
#Function to iteratively proportionally fit a multidimensional array
#IPF also known as Fratar method, Furness method, raking and two/three
dimensional balancing.
#This method of matrix balancing is multiplicative since the margin
factors (coefficients)
#are multiplied by the seed array to yield the balanced array. 
#Ben Stabler, [EMAIL PROTECTED], 9.30.2003
#Brian Gregor, [EMAIL PROTECTED], 2002

#inputs:
#1) margins_ - a list of margin values with each component equal to a
margin
#Example: row margins of 210 and 300, column margins of 140 and 370
#and third dimension margins of 170 and 340.  
#[[1]] [,1] [,2] [,3]
#210, 300
#[[2]]
#140, 370
#[[3]]
#170, 340
#2) seedAry - a multi-dimensional array used as the seed for the IPF
#3) iteration counter (default to 100)
#4) closure criteria (default to 0.001)

#For more info on IPF see:
#Beckmann, R., Baggerly, K. and McKay, M. (1996). Creating Synthetic
Baseline Populations.
#   Transportation Research 30A(6), 415-435.
#Inro. (1996). Algorithms. EMME/2 User's Manual. Section 6.
#~~~
~~~

ipf - function(Margins_, seedAry, maxiter=100, closure=0.001) {
#Check to see if the sum of each margin is equal
MarginSums. - unlist(lapply(Margins_, sum))
if(any(MarginSums. != MarginSums.[1])) warning(sum of each margin
not equal)

#Replace margin values of zero with 0.001
Margins_ - lapply(Margins_, function(x) {
  if(any(x == 0)) warning(zeros in marginsMtx replaced with
0.001) 
  x[x == 0] - 0.001
  x
  })

#Check to see if number of dimensions in seed array equals the
number of
#margins specified in the marginsMtx
numMargins - length(dim(seedAry))
if(length(Margins_) != numMargins) {
stop(number of margins in marginsMtx not equal to number of
margins in seedAry)
}

#Set initial values
resultAry - seedAry
iter - 0
marginChecks - rep(1, numMargins)
margins - seq(1, numMargins)

#Iteratively proportion margins until closure or iteration criteria
are met
while((any(marginChecks  closure))  (iter  maxiter)) {
for(margin in margins) {
marginTotal - apply(resultAry, margin, sum)
marginCoeff - Margins_[[margin]]/marginTotal
marginCoeff[is.infinite(marginCoeff)] - 0
resultAry - sweep(resultAry, margin, marginCoeff, *)
marginChecks[margin] - sum(abs(1 - marginCoeff))
}
iter - iter + 1
}

#If IPF stopped due to number of iterations then output info
if(iter == maxiter) cat(IPF stopped due to number of iterations\n)

#Return balanced array
resultAry
}


Brian Gregor, P.E.
Transportation Planning Analysis Unit
Oregon Department of Transportation
[EMAIL PROTECTED]
(503) 986-4120

 
 Message: 143
 Date: Wed, 05 Mar 2008 18:14:28 +1100
 From: Chandra Shah [EMAIL PROTECTED]
 Subject: [R] ipf function in R
 To: r-help@r-project.org
 Message-ID: [EMAIL PROTECTED]
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 
 Hi
 I have a 3 x 2 contingency table:
 10 20
 30 40
 50 60
 I want to update the frequencies to new marginal totals:
 100 130
 40 80 110
 I want to use  the ipf (iterative proportional fitting) 
 function which 
 is apparently in the cat package.
 Can somebody please advice me how to input this data and 
 invoke ipf in R 
 to obtain an updated contingency table?
 Thanks.
 By the way I am quite new to R.
 
 -- 
  
 
 Dr Chandra Shah
 Senior Research Fellow
 Monash University-ACER Centre for the Economics of Education 
 and Training
 Faculty of Education, Building 6,
 Monash University
 Victoria
 Australia 3800
 Tel. +61 3 9905 2787
 Fax +61 3 9905 9184
 
 www.education.monash.edu.au/centres/ceet
 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] R2WinBUGS sending variables as factors

2008-01-05 Thread Gregor Gorjanc
 James.Dell at csiro.au writes:
...
 1) I can't seem to send variables classed as factors (Month), is there a
 way do this?

You can not use factors per se in BUGS. You have to convert them to numeric
(integer) variables before.

 2) Checking the Log in WinBUGS I can see that the model is Syntactically
 correct, but Bugs is not able to recognise the the initial values for
 each of the chains.
...
 model
 {
 #Centre variables
  mSeaW - mean(SeaW[])
  s_dSeaW - sd(SeaW[])
 
  #normalise Variables 
nSeaWiFS - mSeaW/s_dSeaW
 
  for(i in 1:N) {
   log(lambda[i]) - delta0 + alpha1 * Month[i] + alpha2 * Lat[i]  +
 beta1 * (SeaW[i] - nSeaW) 

I guess you want to use mSeaW here instead of nSeaW!
^ ^
  # recalculate the original intercept term
  Intercept - delta0 - beta1 * nSeaW 

I guess you want to use nSeaWiFS here instead of nSeaW!
...
 
 ##And the Error Message from WinBUGS
 
 model is syntactically correct
 
 data(C:/Program Files/R/R-2.6.0/data.txt)
 
 data loaded
 
 compile(3)
 
 made use of undefined node nSeaW

This warned you that the model is not OK!

Gregor

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

2007-12-23 Thread Gregor Gorjanc
Dietrich Trenkler Dietrich.Trenkler at uni-osnabrueck.de writes:
 Dear HelpeRs,
 
 a colleague of mine uses Scientific Workplace to write his LaTeX documents.
 I made his mouth water mentioning the advantages of using Sweave.
 
 Not using SW myself I wonder if anyone out there has gathered some 
 experiences
 in using the combination of both.

I can not say anything about SW, but LyX can do the same. I have a paper, that
will probably appear in next issues of Rnews about using Sweave in LyX.

Gregor

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Dealing with NA's in a data matrix

2007-12-05 Thread Gregor Gorjanc
Henrique Dallazuanna wwwhsd at gmail.com writes:
  x[is.na(x)] - 0
 
 On 05/12/2007, Amit Patel amitpatel_ak at yahoo.co.uk wrote:
  Hi I have a matrix with NA value that I would like to convert these to a
value of 0.
  any suggestions

also

library(gdata)
x - matrix(rnorm(16), nrow=4, ncol=4)
x[1, 1] - NA
NAToUnknown(x, unknown=0)

Gregor

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Summary: Process multiple columns of data.frame

2007-11-23 Thread Gregor Gorjanc
Thompson, David (MNR David.John.Thompson at ontario.ca writes:
 Thank you Jim Holtman and Mark Leeds for your help.
 
 Original question:
 How do I do the following more concisely?
  Bout[is.na(Bout$bd.n), 'bd.n'] - 0
  Bout[is.na(Bout$ht.n), 'ht.n'] - 0
  Bout[is.na(Bout$dbh.n), 'dbh.n'] - 0
 . . . 
 
 Solution:
 for (i in c('bd.n', 'ht.n', 'dbh.n')) Bout[is.na(Bout[[i]]), i] - 0

ABove solution is completely OK, but can be cumbersome. I wrote functions
NAToUnknown() and unknownToNA() with exactly the same problem in mind. 
Take a look in gdata package. I also described the function in RNews

G. Gorjanc. Working with unknown values: the
gdata package. R News, 7(1):24–26, 2007.
http://CRAN.R-project.org/doc/Rnews/Rnews_2007-1.pdf.

For your example try the following:

library(gdata)

df.0 - as.data.frame( cbind( 
c1=c(NA, NA, 10, NA, 15, 11, 12, 14, 14, 11), 
c2=c(13, NA, 16, 16, NA, 12, 14, 19, 18, NA), 
c3=c(NA, NA, 11, 19, 17, NA, 11, 16, 20, 13), 
c4=c(20, NA, 15, 11, NA, 15, NA, 13, 14, 15), 
c5=c(14, NA, 13, 16, 17, 17, 16, NA, 15, NA), 
c6=c(NA, NA, 13, 11, NA, 16, 15, 12, NA, 20)) )

df.0
   c1 c2 c3 c4 c5 c6
1  NA 13 NA 20 14 NA
2  NA NA NA NA NA NA
3  10 16 11 15 13 13
4  NA 16 19 11 16 11
5  15 NA 17 NA 17 NA
6  11 12 NA 15 17 16
7  12 14 11 NA 16 15
8  14 19 16 13 NA 12
9  14 18 20 14 15 NA
10 11 NA 13 15 NA 20

NAToUnknown(df.0, unknown=0)
   c1 c2 c3 c4 c5 c6
1   0 13  0 20 14  0
2   0  0  0  0  0  0
3  10 16 11 15 13 13
4   0 16 19 11 16 11
5  15  0 17  0 17  0
6  11 12  0 15 17 16
7  12 14 11  0 16 15
8  14 19 16 13  0 12
9  14 18 20 14 15  0
10 11  0 13 15  0 20

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Confidence Intervals for Random Effect BLUP's

2007-11-10 Thread Gregor Gorjanc
Rick Bilonick rab at nauticom.net writes:
...
 I think prediction interval is what is usually used. Regardless, I'm not
 sure how predict.lm will be of much help because I asked specifically
 about BLUP's for random effects and the last time I checked lm did not
 handle mixed effects models. Neither predict.lme and predict.lmer
 provide intervals. Here is the code that I included in my original
 e-mail. My simple question is, will this code correctly compute a
 prediction interval for each subjects random effect? In particular, will
 the code handle the bVar slot correctly? Some postings warned about
 inappropriate access to slots. Here is the code that I asked about in my
 original e-mail:

Rick, 

I can not help you with your code as I am not familiar with slots in lmer 
outputs. Maybe lmer authors can help you - try on r-sig-mixed list.

But you can check your results with running MCMC for the same model and
you will get the whole posterior density of all your parameters that
you put on prior with unknown variance i.e. random effects or sometimes also
called BLUPs. There is a function in lme4 package that can do that!

Gregor

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

2007-10-27 Thread Gregor Gorjanc
Diane Srivastava srivast at zoology.ubc.ca writes:
 I have a meta-analysis dataset which I would like to analyze as a mixed
 model, where the y-variable is a measure of effect size, the random effect
 is the study from which the effect size was extracted, and the fixed
 effect is a categorical explanatory variable. The complication is that we
 often have multiple estimates of effect size from a single study (e.g. the
 experiment was repeated in different years, or under different
 conditions). Being a meta-analysis, I need to weight the effect sizes by
 the inverse of the effect SE. Thus my dataset includes: study, effect
 size, SE, explanatory variables.

Andrew Gelman shows in several places (his books, R2WinBUGS package) how
to use data (your effect size estimates) from previous analyses. He has
mean and variance of the estimate (the data) and models them. The key is
that you will have to swicth to BUGS. It has very flexible model language!

Regards, Gregor

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