Re: [R] A subject related question

2010-10-16 Thread Bill.Venables
Multivariate normal distributions with PSD variance matrices occur all the time. The most common example in practice would probably be the distribution of the vector of residuals from a normal regression. It has a degenerate distribution wrt R^n because it is subject to p linear restrictions.

Re: [R] For-loop dummy variables?

2010-10-19 Thread Bill.Venables
you might try dummy - with(cleary, cbind(B4 = as.numeric(D1 == 4), B6 = as.numeric(D1 == 6), B7 = as.numeric(D1 == 7))) and do it all in one go. ___ to fix up your apporach you need to use if(cleary$D1[i] == 4)

Re: [R] glm with linear restrictions

2010-10-19 Thread Bill.Venables
If b1+b2+b3 = 0 can't you put b3 = -b1-b2 and re-write the model in terms of b1 and b2 alone? The model is stil (g)linear. If the parameters to which you refer corresponds to the levels of a factor, then you can use the contr.sum contrast matrices. It essentailly does the above.

Re: [R] Conversion of S+ libraries

2010-10-21 Thread Bill.Venables
It would certainly not be straightforward, unless Tibco has done a lot of work to make it possible in recent years, (which is not unlikely). They have done a lot of work in the other direction, i.e. enabling R packages to be used within S-PLUS. S-PLUS has the concept of a chapter, which

Re: [R] Conversion of S+ libraries

2010-10-22 Thread Bill.Venables
Bill D. is quite right, I did have in mind conversion the other way round. I am happy to concede. The interesting thing for me is the (relatively) automatic conversion from .sgml to .Rd format. This is likely to speed things up considerably. Bill. -Original Message- From: William

Re: [R] Long model formulae

2010-10-24 Thread Bill.Venables
Here is a dodge I often use. This is a mock-up example. ___ bar - data.frame(matrix(rnorm(1001), nrow = 1)) names(bar)[1] - y ## say head(bar[,1:5]) nbar - names(bar) form - as.formula(paste(nbar[1], ~, paste(nbar[-1], collapse = +))) fitModel - substitute(tm - rpart(FORM, data =

Re: [R] Importing CSV File

2010-10-24 Thread Bill.Venables
sales - read.csv(file=C:/Program Files/R/Test Data/sales.csv, header=TRUE, row.names = Month) ^^^ -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of

Re: [R] divide column in a dataframe based on a character

2010-10-25 Thread Bill.Venables
You are nearly there. example(data.frame) zz - c(aa_bb,bb_cc,cc_dd,dd_ee,ee_ff, ff_gg,gg_hh,ii_jj,jj_kk,kk_ll) ddd - cbind(dd, group = zz) ddd - within(ddd, { group - as.character(group) tmp - do.call(rbind, strsplit(group, _)) group_b - tmp[,2]

Re: [R] cube root of a negative number

2010-10-26 Thread Bill.Venables
To take it one step further: x - as.complex(-4) cx - x^(1/3) r - complex(modulus = Mod(cx), argument = Arg(cx)*c(1,3,5)) r [1] 0.793701+1.37473i -1.587401+0.0i 0.793701-1.37473i r^3 [1] -4+0i -4+0i -4+0i So when you ask for the cube root of -4, R has a choice of three possible

Re: [R] Extracting from data.frame

2010-11-14 Thread Bill.Venables
It's because in this instance R (and S before it) behaves a bit like Microsoft and tries to guess what you really wanted rather than listen to what you asked for. If you ask for a single column from a data frame, e.g. df[,1] then by default this behaves like df[[1]] and you get a single

Re: [R] Counting

2010-11-16 Thread Bill.Venables
Your outlier has row.names 1. If this is selected in the bootstrap sample once, it will also have row.names 1. If it is selected more than once the row.names of the successive entries will begin with 1. Here is a possibility you may wish to consider. txt - textConnection( + y

Re: [R] Vectors out of lists?

2010-11-16 Thread Bill.Venables
Another approach would be Y - list(sqrt, sin, function(u) u/2) Ybar - function(u) rowMeans(sapply(Y, function(fun) fun(u))) integrate(Ybar, 0, 1) 0.4587882 with absolute error 5.6e-05 i.e. make the function vectorized directly. Note, however, that if you had Y[[4]] - function(u) 1

Re: [R] Vectors out of lists?

2010-11-17 Thread Bill.Venables
That was my thought, and if you are going to be integrating it, you do need to be concerned with efficiency to some extent, I would imagine. My experience is that Vecotrize() is theoretically interesting and it is great for getting you out of a tight spot like this, but if you can avoid it

Re: [R] Problem with nlme package

2010-11-17 Thread Bill.Venables
The function is not exported from the package. You have to get tough with it, e.g. library(nlme) summary.lme Error: object 'summary.lme' not found But if you insist: nlme:::summary.lme function (object, adjustSigma = TRUE, verbose = FALSE, ...) { fixed - fixef(object) ... You

Re: [R] a philosophy R question

2010-11-20 Thread Bill.Venables
The conventional view used to be that S is the language and that R and S-PLUS are implementations of it. R is usually described as 'a programming environment for data analysis and graphics' (as was S-PLUS before it). However as the language that R implements diverges inexorably from the

Re: [R] Can't invert matrix

2010-11-20 Thread Bill.Venables
What you show below is only a representation of the matrix to 7dp. If you look at that, though, the condition number is suspiciously large (i.e. the matrix is very ill-conditioned): txt - textConnection( + 0.99252358 0.93715047 0.7540535 0.4579895 + 0.01607797 0.09616267 0.2452471

Re: [R] density at particular values

2010-11-20 Thread Bill.Venables
It's actually not too difficult to write the density function itself as returning a function rather than a list of x and y values. Here is a no frills (well, few frills) version: ### cut here ### densityfun - local({ normd - function(value, bw) { force(value); force(bw) function(z)

Re: [R] Gap between graph and axis

2010-11-22 Thread Bill.Venables
perhaps you need something like this. par(yaxs = i) plot(runif(10), type = h, ylim = c(0, 1.1)) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sebastian Rudnick Sent: Tuesday, 23 November 2010 10:37 AM To: r-help@r-project.org

Re: [R] Two time measures

2010-11-27 Thread Bill.Venables
I think all you need is ?split -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Eduardo de Oliveira Horta Sent: Sunday, 28 November 2010 8:02 AM To: r-help@r-project.org Subject: [R] Two time measures Hello! I have a csv file

Re: [R] modifying vector elements

2010-07-13 Thread Bill.Venables
Here is one way a_clip - sub(^([0-9]+\\.[0-9]+\\.[0-9]+).*$, \\1, a) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Lorenzo Cattarino Sent: Tuesday, 13 July 2010 5:20 PM To: r-help@r-project.org Subject: [R] modifying vector

Re: [R] cca in vegan (formula instead of community matrix data)

2010-07-16 Thread Bill.Venables
As it says, (at least) one of your rows is all zeros. CCA cannot handle such sites. You might want to try something like this: m.cca - cca(WinterM_ratio ~ topo_mean + coast + prec_max + temp_min + evi_min, data = datam, subset = rowSums(WinterM_ratio) 0) ### Note. (Note that you do

Re: [R] Indexing by logical vectors

2010-07-19 Thread Bill.Venables
As far as I know the answer to your question is No, but there are things you can do to improve the readability of your code. One thing I find useful is to avoid using $ as much as possible and to favour things like with() and within(). The first thing you might do is think about choosing

Re: [R] p-VALUE calculation

2010-07-22 Thread Bill.Venables
Is this the kind of thing you mean? wData - within(wData, { + z - (weigth - mean(weigth))/sd(weigth) + p-value - 2*pnorm(-abs(z)) ## 2-sided + rm(z) }) wData employee_id weigth p-value 1 100150 0.3763641 2 101200 0.9081403 3 102300 0.1547139 4

Re: [R] Fwd: Questions about templates for R

2010-07-26 Thread Bill.Venables
Isn't there a danger that what you teach will then be driven by what templates you receive? I would have thought this was an easy thing to do yourself, once you have decided what you want to teach your students. Just write a scropt (e.g. using the inbuilt script edit in R for Windows if you

Re: [R] Add an arrow to a plot

2010-07-27 Thread Bill.Venables
It won't happen automatically unless you make it do so yourself. Fortunately this is not hard. See, ?arrows -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Trying To learn again Sent: Wednesday, 28 July 2010 7:07 AM To:

Re: [R] repeating rows in R

2010-07-27 Thread Bill.Venables
Is this the kind of thing you are looking for? dat - data.frame(x = 1:3, freq = 2:4) dat x freq 1 12 2 23 3 34 newDat - dat[rep(rownames(dat), dat$freq), ] newDat x freq 1 12 1.1 12 2 23 2.1 23 2.2 23 3 34 3.1 34 3.2 34 3.3 34

Re: [R] Variance-covariance matrix from GLM

2010-07-28 Thread Bill.Venables
?vcov ### now in the stats package You would use V - vcov(my.glm) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bojuan Zhao Sent: Thursday, 29 July 2010 9:52 AM To: r-help@r-project.org Subject: [R] Variance-covariance

Re: [R] R Equivalent of SAS Datastep Line-Hold (@@) Specifier?

2010-07-30 Thread Bill.Venables
There is a much simpler way. con - textConnection( A 1 101 M 55 5 A 1 104 F 27 0 A 1 106 M 31 35 A 1 107 F 44 21 A 1 109 M 47 15 A 1 111 F 69 70 A 1 112 F 31 10 A 1 114 F 50 0 A 1 116 M 32 20 A 1 118 F 39 25 A 1 119 F 54 0 A 1 121 M 70 38 A 1 123 F 57 55 A 1 124 M 37 18 A

Re: [R] Why do the results of paste() depend on how the argument (data.frame) is constructed?

2010-08-01 Thread Bill.Venables
Just to add to the confusion, for (nearly) all practical purposes they are the same: all.equal(df1, df2) [1] TRUE do.call(paste, df1) [1] 1 4 2 5 3 6 do.call(paste, df2) [1] 1 4 2 5 3 6 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]

Re: [R] TRUE FALSE issue

2010-08-10 Thread Bill.Venables
with(a, Samples[apply(a[,-1], 1, any)]) [1] S2 S4 Levels: S1 S2 S3 S4 S5 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Alexander Eggel Sent: Wednesday, 11 August 2010 12:05 PM To: r-help@r-project.org Subject: [R] TRUE FALSE

Re: [R] TRUE FALSE issue

2010-08-10 Thread Bill.Venables
For huge cases this might be a whiff faster with(a, Samples[rowSums(a[, -1], na.rm = TRUE) 0]) [1] S2 S4 Levels: S1 S2 S3 S4 S5 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of bill.venab...@csiro.au Sent: Wednesday, 11 August

Re: [R] problem with Bitmap

2010-08-11 Thread Bill.Venables
The types of bitmap available depend on the ghostscript you have installed. Have you checked that yours handles jpeg? What happens if you use the jpeg driver directly? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of kayj Sent:

Re: [R] Converting degree: minute: second data to decimal degree data, should be simple

2010-08-16 Thread Bill.Venables
I take it you have the data in character form. If the DMS data is already in a data frame it is probably in factor form, so you will need to coerce it to character first. Here is how you could do it with the DMS data in a data frame: m ## an example with 3 entries DMS 1 122:45:45 2

Re: [R] find most repeated item from column in dataframe

2010-08-24 Thread Bill.Venables
Do you expect this to be easy? It may be, but I can't see a particularly graceful way to do it. Here is one possible solution. dat StandID PlotNum HerbNum Woody 1 001 1 1low 2 001 2 2 medium 3 001 3 1low 4 001 4 3

Re: [R] expression() and plot title

2010-08-27 Thread Bill.Venables
Here is a suggestion you may care to develop func - function(a, b) { plot(1:10) title(main = bquote(a == .(a)*','~ b == .(b))) invisible() } try with func(1,2) func(36, 2^10) c -Original Message- From: r-help-boun...@r-project.org

Re: [R] while loop until end of file

2010-08-29 Thread Bill.Venables
Eh? ## First calculate the means: mns - with(alldata, tapply(param1, list(Pair, group), mean)) ## now put the results into a data frame res - data.frame(mns, dif = mns[, D] - mns[, R]) ## Then write it out if that's your thing. -Original Message- From: r-help-boun...@r-project.org

Re: [R] merging two maxtrices

2010-09-05 Thread Bill.Venables
Is this all you want? j - matrix(nrow=10,ncol=10) k - matrix(seq(1:50), ncol=10) row.names(k) - seq(2,10,by=2) row.names(j) - 1:10 j[row.names(k), ] - k j [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] 1NA NA NA NA NA NA NA NA NANA 2 16 11 16

Re: [R] colorRamp of image to span larger range than dataset

2010-09-05 Thread Bill.Venables
colorRampPalette returns a function, not a list of colours. You might want to try something like: ascols - colorRampPalette(c(gray, yellow, darkgoldenrod1, orange, red), interpolate=spline) x - 10*(1:nrow(volcano)) y - 10*(1:ncol(volcano)) image(x, y, volcano, col = ascols(300), axes =

Re: [R] how do I transform this to a for loop

2010-09-05 Thread Bill.Venables
sseq - c(1, seq(5, 40, by = 5)) for(i in 1:length(sseq)) assign(paste(arima, i, sep=), arima(data.ts[sseq[i]:(sseq[i]+200)], order=c(1,1,1))) ...but why would you want to do so? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On

Re: [R] mapping array

2010-09-11 Thread Bill.Venables
Is this the kind of thing you are talking about? ### 8 cut here 8 ### A - rep(NA, 100) B - sort(runif(25)) C - sort(sample(1:100, 25)) A[C] - B B C A ### 8 cut here 8 ### (The sorting is not necessary. It's only there to make checking what happened easier.) -Original Message-

Re: [R] R-equivalent Stata command: poisson or quasipoisson?

2010-09-11 Thread Bill.Venables
In R, the glm families poisson and quasipoisson will give you the same estimates. Their standard errors will (usually) be different, though, and family = quasipoisson does not give you an AIC (since it does not maximise a true likelihood; it uses quasi-likelihood estimation). I hope you are

Re: [R] for loop help

2010-09-14 Thread Bill.Venables
Most likely. If you care to be more specific, we might be able to give you a more specific answer. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of lord12 Sent: Wednesday, 15 September 2010 6:30 AM To: r-help@r-project.org

Re: [R] for loop help

2010-09-14 Thread Bill.Venables
An envorniment is a hash table. There are several packages that you might care to look at, e.g. filehasn -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of lord12 Sent: Wednesday, 15 September 2010 7:06 AM To: r-help@r-project.org

Re: [R] Splitting a matrix

2010-09-16 Thread Bill.Venables
Here is one possibility: set.seed(1) dat - matrix(rnorm(4*16), 4, 16) dim(dat) - c(4,4,4) dat , , 1 [,1] [,2] [,3][,4] [1,] -0.6264538 0.3295078 0.5757814 -0.62124058 [2,] 0.1836433 -0.8204684 -0.3053884 -2.21469989 [3,] -0.8356286 0.4874291 1.5117812

Re: [R] Was the package installed correctly

2010-09-16 Thread Bill.Venables
It means that two of the packages on which TeachingDemos depends were not installed correctly, namely rgl and tkplot. The problem could be that you do not have the system dependencies in place. For rgl these are listed as: SystemRequirements:OpenGL, GLU Library, zlib (optional),

Re: [R] convert to csv file

2010-09-16 Thread Bill.Venables
no. Your best way is to use write.csv(table_list, file = paste(file, x, .csv, sep=)) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of lord12 Sent: Friday, 17 September 2010 12:55 PM To: r-help@r-project.org Subject: Re: [R]

Re: [R] help manual on R on ESS

2010-09-17 Thread Bill.Venables
This is an ESS question, not an R one. The problem is that the argument names to the function help() have changed in recent releases of R, and htmlhelp is no longer an accepted argument. The replacement argumennt is now help_type (with default value getOption(help_type)). This may have been

Re: [R] Repeating values in a list

2010-09-18 Thread Bill.Venables
have - list(a=7,b=3,c=1) have2 - lapply(have, rep, 2) have2 $a [1] 7 7 $b [1] 3 3 $c [1] 1 1 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Derek Ogle Sent: Sunday, 19 September 2010 11:20 AM To: R (r-help@R-project.org)

Re: [R] Help!

2010-09-20 Thread Bill.Venables
You could do most of this with the function lmList in the nlme package, but since you want both plots and summaries, you might as well do it in a more flexible loop. How about something like this: Code: ## This makes a single factor to define your groups BCI - within(BCI,

Re: [R] Doing operations by grouping variable

2010-09-20 Thread Bill.Venables
That's if the variables are visible. If they are only in the data frame it's not much more difficult d - data.frame(group = rep(1:5, each=5), variable = rnorm(25)) with(d, tapply(variable, group, max)) (Tip: avoid using attach().) Bill Venables. -Original Message-

Re: [R] Estimating Weibull parameters by maximum liklihood - with censored and non censored data?

2010-09-20 Thread Bill.Venables
library(help = survival) help(survreg, package = survival) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Halabi, Anan Sent: Tuesday, 21 September 2010 3:12 PM To: r-help@r-project.org Subject: [R] Estimating Weibull parameters

Re: [R] Doing operations by grouping variable

2010-09-21 Thread Bill.Venables
You left out the subscript. Why not just do d - within(data.frame(group = rep(1:5, each = 5), variable = rnorm(25)), scaled - variable/tapply(variable, group, max)[group]) and be done with it? (Warning: if you replace the second '-' above by '=', it will not work. It is NOT true

Re: [R] How to change the xlab name's color?

2010-09-22 Thread Bill.Venables
?par See col.lab, col.main, col.sub, c. To see what colours are available you can use colours() (or colors() if you don't speak English). -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of tooblue Sent: Thursday, 23 September

[R] A little complex puzzle

2010-09-25 Thread Bill.Venables
I was looking for an example of complex variables in R. This one is trivial, but rather cute (though World War II aficionados may 'come over all funny'). See if you can guess the image before you try the function. It's not difficult. jif - function(res = 100) { z - sample(do.call(complex,

Re: [R] the function doesn´t work

2010-09-26 Thread Bill.Venables
This is worse than before and getting pretty silly. Now you are calling outer with a function that only takes one argument. R might be hard for you, but mind reading is even harder for most of us. To get help you need to explain clearly and sensibly what it is you want to do. Look at your

Re: [R] ask for a question with cch function

2010-09-28 Thread Bill.Venables
It would help if you were to tell up which package you are talking about. I take it this is the survival package and this is the proportioanl hazards fitting function for case-cohort data. You would have seen earlier in the code that method - match.arg(method) so at that stage 'method'

Re: [R] String split and concatenation

2010-09-28 Thread Bill.Venables
dump(x, file = x.R) file.show(x.R) will get you most of the way. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Steven Kang Sent: Wednesday, 29 September 2010 3:11 PM To: r-help@r-project.org Subject: [R] String split and

Re: [R] Simultaneous equation with one ordinal reponses

2010-10-04 Thread Bill.Venables
R packages do not solve modelling problems. They can be used to solve computational problems. Wouldn't it be a better plan to sort out what kind of models you want to investigate to address your research questions first? Then, and only then, can you sensibly look around for packages that

Re: [R] Plotting x-axis labels perpendicular to the axis

2010-10-05 Thread Bill.Venables
?par lood at the 'las' parameter. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of ANJAN PURKAYASTHA Sent: Wednesday, 6 October 2010 8:13 AM To: r-help@r-project.org Subject: [R] Plotting x-axis labels perpendicular to the axis

Re: [R] reorder always returns ordered

2010-10-05 Thread Bill.Venables
R-bugs is the appropriate place to report this. It may be particular to your system. Here's what happens on mine (Windows XP, R 2.11.1) f - factor(1:5) g - reorder(f, rnorm(5)) is.ordered(g) [1] FALSE g [1] 1 2 3 4 5 attr(,scores) 1 2 3 4 5

Re: [R] Using as.polynomial() over a matrix

2010-10-05 Thread Bill.Venables
I was unaware of this discussion till now, so I'm not up with what's been said already. Here is how I would go about the problem I think you are trying to solve. m - matrix(1:16, 4, 4) require(PolynomF) (lop - as.polylist(lapply(1:nrow(m), function(i) polynom(m[i,] List of polynomials:

Re: [R] Using as.polynomial() over a matrix

2010-10-05 Thread Bill.Venables
PS ... actually, now I think about it... as.polylist(apply(m, 1, polynom)) List of polynomials: [[1]] 1 + 5*x + 9*x^2 + 13*x^3 [[2]] 2 + 6*x + 10*x^2 + 14*x^3 [[3]] 3 + 7*x + 11*x^2 + 15*x^3 [[4]] 4 + 8*x + 12*x^2 + 16*x^3 This works with the PolynomF package because in that case the

Re: [R] what is the NOT IN operator

2010-10-06 Thread Bill.Venables
Try !(group %in% C(A, ...)) A slightly cuter way is to define your own operator. `%ni%` - Negate(`%in%`) letters[1:3] %ni% letters[3:5] [1] TRUE TRUE FALSE From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of Emily

Re: [R] Poisson Regression

2010-10-13 Thread Bill.Venables
One possible way to treat parameters as nuisance parameters is to model them as random. This gives allows them to have a reduced parametric load. There are many packages with funcitons to fit glmms. One you may wish to look at is lme4, which has the lmer fitting function library(lme4) fm -

Re: [R] AIC in bestglm, glm, and lm - why do they differ?

2010-10-15 Thread Bill.Venables
AIC is only defined up to an additive constant (as is log-likelihood). It should not surprise you that the values for AIC differ between packages. The real question is whether the change in AIC when going form one model to anoth is the same. If not, one is wrong (at least). -Original

Re: [R] statistics and R package for election results

2009-10-08 Thread Bill.Venables
What are you trying to find out from your analysis and what techniques do you have in mind for doing it? It might be as well to sort out this first (and tell us if you have) rather than look round for a package first and then decide on what you want to do in the analysis. Having said all

Re: [R] How do you test if a number is in a list of numbers?

2009-10-11 Thread Bill.Venables
This is pretty standard. varList - 1:4 subData - subset(dataset, var %in% varList) Should do it. W. From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of JustinNabble [justinmmcgr...@hotmail.com] Sent: 11 October 2009 16:13 To:

Re: [R] Fast optimizer

2009-10-29 Thread Bill.Venables
Dear R_Help Help, The critical questions are a) how many parameters do you have b) how pathological is the log-likelihood function c) how good are your initial values and d) how efficiently have you coded your objective function? Of these, the last is most likely the critical one, and the one

Re: [R] Logistic and Linear Regression Libraries

2009-10-31 Thread Bill.Venables
glm is not, and never was. part of the MASS package. It's in the stats package. Have you sorted out why there is a big difference between the results you get using glm and lrm? Are you confident it is due to the algorithms used and not your ability to use the software? To be helpful, if

Re: [R] How could I use a function saved in one file ?

2010-05-03 Thread Bill.Venables
Try using source(P_Value) before anything else. Also, P_Value can be written as a one-liner: P_Value - function(Table) fisher.test(Table)$p.value so you don't really need a separate function at all. Bill Venables CSIRO/CMIS Cleveland Laboratories -Original Message- From:

Re: [R] sum of certain length

2010-05-23 Thread Bill.Venables
This is one way to do it. Suppose your data is in the file rainfall.txt, as set out below. Then dat - read.table(rainfall.txt, header = TRUE) dat - within(dat, { + date - as.Date(paste(year, month, day, sep=-)) + week - factor(as.numeric(date - date[1]) %/% 7) + }) wRain - with(dat,

Re: [R] arrange data

2010-05-31 Thread Bill.Venables
Here is one way. Suppose your data frame is called 'dat'. o - with(dat, order(as.Date(paste(year, month, day, sep=- newDat - dat[o, c(year, month, day, rain)] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Roslina Zakaria

Re: [R] Faster matrix operation?

2010-06-01 Thread Bill.Venables
xyzs - matrix(rnorm(3*10,0,1),ncol=3) V - c(2,3,4) system.time(vx - apply(t(xyzs) * V, 2 ,sum)) user system elapsed 1.060.021.08 system.time(wx - as.vector(xyzs %*% V)) user system elapsed 0 0 0 all.equal(vx, wx) [1] TRUE ? -Original

Re: [R] 380x380 dataframe to list

2010-06-04 Thread Bill.Venables
Or.. unlist(data) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Nick Matzke Sent: Saturday, 5 June 2010 11:17 AM To: r-help@r-project.org Subject: Re: [R] 380x380 dataframe to list That's the answer, thanks!! Nick Peter

Re: [R] Matrix to database -- best practices/efficiency?

2010-06-07 Thread Bill.Venables
I think what you are groping for is something like this my_matrix - matrix(1:60, nrow = 6) id_a - seq(10,60,by=10) id_b - seq(100,1000,by=100) my_database - cbind( expand.grid(id_a = id_a, id_b = id_b), mat = as.vector(my_matrix) ) -Original Message- From:

Re: [R] more dates and data frames

2010-06-08 Thread Bill.Venables
Here is one way ... DF4 - cast(formula=Date~V2,data=DF3,value=X1,fill=0) d - with(DF4, seq(min(Date), max(Date), by = 1)) ### full set m - as.Date(setdiff(d, DF4$Date)) ### missing dates if(length(m) 0) { extras - cbind(data.frame(Date = m), cat = 0, dog = 0, tree = 0)

Re: [R] question about mean

2010-06-09 Thread Bill.Venables
Here is an alternative with(iris, rowsum(iris[, -5], Species)/table(Species)) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Peter Langfelder Sent: Thursday, 10 June 2010 12:27 PM To: SH.Chou Cc: r-help@r-project.org Subject:

Re: [R] Specifying formula inside a function

2010-06-09 Thread Bill.Venables
Here is one way. f - function(d) { y - names(d)[1] xs - names(d)[-1] nx - length(xs) xs - sort(sample(xs, sample(1:nx, 1))) form - as.formula(paste(y, ~, paste(xs, collapse=+))) Call - substitute(lm(FORM, data = d), list(FORM = form)) eval(Call) } d - within(data.frame(y =

Re: [R] Retrieving the 2 row of dist computations

2010-06-09 Thread Bill.Venables
This is a lazy way, and a slightly extravagant way if your memory is limited and you are dealing with large numbers of rows. NCols - 5 NRows - 7 myMat - matrix(runif(NCols*NRows), ncol=NCols) d - dist(myMat) dm - as.matrix(d) diag(dm) - Inf ij - which(dm == min(dm), arr.ind = TRUE)[1,] ij

Re: [R] how to 'average' one col wrt to another one

2010-06-16 Thread Bill.Venables
Is this the kind of thing you want? test - matrix(rep(letters[1:3],6),nrow=6,byrow=T) test[2,] - letters[5:7] test[4,] - c('e','f','i') test[1,3] - 'i' colnames(test) - c('leave','arrive','line') test - data.frame(test) tab - with(test, table(paste(leave, arrive, sep=), line)) tab -

Re: [R] how to initial a list to store data result?

2010-06-21 Thread Bill.Venables
The usual method is either lis - vector(list) or, nearly equivalently, lis - list() If you know in advance how many components the list will have, there can be a slight advantage in using lis25 - vector(list, 25) if e.g. you know the list will be of length 25. Bill Venables.

Re: [R] list operation

2010-06-23 Thread Bill.Venables
Here is an alternative: lst - list(m = c('a','b','c'), n = c('c','a'), l = c('a','bc')) set - c(a, c) (w - sapply(lst, function(x) all(set %in% x))) m n l TRUE TRUE FALSE names(w)[w] [1] m n -Original Message- From: r-help-boun...@r-project.org

Re: [R] Assigning variable value as name to cbind column

2010-06-25 Thread Bill.Venables
Why does the naming have to be done inside the cbind()? How about dataTest - data.frame(col1 = c(1,2,3)) new.data - c(1,2) name - test length(new.data) - nrow(dataTest) newDataTest - cbind(dataTest, new.data) names(newDataTest)[[ncol(newDataTest)]] - name newDataTest col1 test 11

Re: [R] predict newdata question

2010-06-25 Thread Bill.Venables
You ask: # How can I use predict here, 'newdata' crashes predict(m1,newdata=wolf$predicted);wolf # it doesn't work To use predict() you need to give a fitted model object (here m1) and a *data frame* to specify the values of the predictors for which you want predictions. Here wolf$predicted

Re: [R] integration of two normal density

2010-06-25 Thread Bill.Venables
Your intuition is wrong and R is right. Why should the product of two probability density functions be a normalized pdf also? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Carrie Li Sent: Saturday, 26 June 2010 1:28 PM To:

Re: [R] subset arg in subset(). was: converting result of substitute to 'ordidnary' expression

2010-06-26 Thread Bill.Venables
Here is another one that works: do.call(subset, list(dat, subsetexp)) x y 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Vadim Ogranovich Sent: Saturday, 26 June 2010 11:13

Re: [R] Recursive indexing failed at level 2

2010-06-26 Thread Bill.Venables
Why do you use *double* square brackets on the left side of the replacement? From the help info for [[: The most important distinction between [, [[ and $ is that the [ can select more than one element whereas the other two select a single element. You seem to be selecting 20 elements.

Re: [R] Matrix operations

2010-06-28 Thread Bill.Venables
Since X is a vector, then A - sum(X, solve(V, X)) is probably slightly better here. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Dmitrij Kudriavcev Sent: Tuesday, 29 June 2010 12:29 PM To: r-help@r-project.org Subject: [R]

Re: [R] Matrix operations

2010-06-28 Thread Bill.Venables
Oops. Try A - sum(X * solve(V, X)) (too fast!) -Original Message- From: Venables, Bill (CMIS, Cleveland) Sent: Tuesday, 29 June 2010 1:05 PM To: 'Dmitrij Kudriavcev'; 'r-help@r-project.org' Subject: RE: [R] Matrix operations Since X is a vector, then A - sum(X, solve(V, X)) is

Re: [R] how to remove numeric(0) component from a list

2010-06-28 Thread Bill.Venables
newlist - newlist[sapply(newlist, length) 0] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of song song Sent: Tuesday, 29 June 2010 2:12 PM To: r-help@r-project.org Subject: [R] how to remove numeric(0) component from a list like

Re: [R] Multiline and grouping in R

2010-06-29 Thread Bill.Venables
require(lattice) Loading required package: lattice xyplot(CASES ~ YEAR | AREA, data = t, type = b) xyplot(CASES ~ YEAR, data = t, type = b, groups = AREA) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Pablo Cerdeira Sent:

Re: [R] evaluate a string variable

2010-06-30 Thread Bill.Venables
You need to parse it before you evaluate it. eval(parse(text = avar)) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeremiah H. Savage Sent: Wednesday, 30 June 2010 3:45 PM To: r-help@r-project.org Subject: [R] evaluate a

Re: [R] lm( y ~ A/x ) ... how do I extract the coefficients by factor?

2010-07-04 Thread Bill.Venables
It's a bit like gravy. You have to make it, it doesn't just come when you cook the joint. Here is a mock-up of your situation: dat - data.frame(ByMonth = gl(6, 10, labels = paste(2010-0, 1:6, sep=)), + r1 = rnorm(60), v = rnorm(60), r = rnorm(60)) head(dat) ByMonth r1 v

Re: [R] if using ginv function, does it mean there is no need to use solve function any more?

2010-07-04 Thread Bill.Venables
ginv() is slower than solve(). This is the price you pay for more generality. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of song song Sent: Monday, 5 July 2010 10:21 AM To: r-help@r-project.org Subject: [R] if using ginv

Re: [R] data.frame: adding a column that is based on ranges of values in another column

2010-07-05 Thread Bill.Venables
Here is one way checkList - data.frame(Day = c(f.n1, f.n2), + FN = rep(c(FN1,FN2), + c(length(f.n1), length(f.n2 m - match(DF$Date, checkList$Day) DF - cbind(DF, Fortnight = checkList$FN[m]) DF XY Date Fortnight 1

Re: [R] quantiles on rows of a matrix

2010-07-07 Thread Bill.Venables
apply(matrix1, 1, quantile, probs = c(0.05, 0.9), na.rm = TRUE) may be what you are looking for. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jim Bouldin Sent: Thursday, 8 July 2010 8:52 AM To: R help Subject: [R] quantiles on

[R] Marking the tail of a distribution (was (no subject))

2010-07-11 Thread Bill.Venables
Here is a way: ### x - sort(c(seq(-4, 4, length=100), 1.96)) hx - dnorm(x) par(pty=s) plot(x, hx, type=l, xlab=z value, ylab=Density, main=density of N(0,1)) abline(v=1.96, col=red) abline(h = 0) top - x = 1.96 tail - rbind(cbind(x[top], hx[top]), c(4, 0), c(1.96, 0)) polygon(tail, col = red)

Re: [R] [ExternalEmail] Bulk Match/Replace

2010-01-26 Thread Bill.Venables
(id - with(df, id[match(v,Name)])) [1] 1 2 2 4 2 4 2 2 4 2 1 2 2 1 2 2 1 2 2 From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of Nathan S. Watson-Haigh [nathan.watson-ha...@csiro.au] Sent: 27 January 2010 10:31 To:

Re: [R] Dividing one column of form xx-yy into two columns, xx and yy

2010-02-08 Thread Bill.Venables
Here is one way. dat V1 1 43-156 2 43-43 3 1267-18 dat - within(dat, { + m - do.call(rbind, strsplit(as.character(V1), -)) + XX - as.numeric(m[,1]) + YY - as.numeric(m[,2]) + rm(m) + }) dat V1 YY XX 1 43-156 156 43 2 43-43 43 43 3 1267-18 18 1267 Bill

Re: [R] Find each time a value changes

2010-02-10 Thread Bill.Venables
something like this? c(1, which(c(0, diff(y)) != 0)) [1] 1 11 21 51 61 71 81 91 Bill Venables CSIRO/CMIS Cleveland Laboratories -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Tim Clark Sent: Thursday, 11 February 2010 11:59

  1   2   3   4   5   >