Re: [R] question about non-linear least squares in R

2007-09-05 Thread apjaworski
Here is one way of getting a reasonable fit: 1. Scale your y's by dividing all values by 1e6. 2. Plot x vs. y. The plot looks like a quadratic function. 3. Fit a quadratic const. + B*x^2 - this a linear regression problem so use lm. 4. Plot the predictions. 5. Eyball the necessary shift - MA

Re: [R] integrate

2007-08-22 Thread apjaworski
As Duncan Murdoch mentioned in his reply, the problem is with the fact that your function is not really a properly defined function in the sense of "assigning a unique y to each x". The integrate function uses an adaptive quadrature routine which probably makes multiple calls to the function being

Re: [R] Moving data from one workspace to another

2007-08-01 Thread apjaworski
Walter, Here is what I do in similar situations. I am on WinXP but this should be similar on other systems (I hope). 1. I start R with the new .RData workspace (usually by double-clicking on it). 2. I go to File < Change Dir menu item. 3. I change the directory to where the old .RData is. 4.

Re: [R] beta regressions in R

2007-07-30 Thread apjaworski
Walter, There is a betareg package in CRAN. Cheers, Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 736-3122

Re: [R] Bad optimization solution

2007-05-07 Thread apjaworski
Paul, I think the problem is the starting point. I do not remember the details of the BFGS method, but I am almost sure the (.5, .5) starting point is suspect, since the abs function is not differentiable at 0. If you perturb the starting point even slightly you will have no problem. Andy

Re: [R] A problem with svIDE in Tinn-R?

2007-04-29 Thread apjaworski
Similar thing here. Happens in 2.5.0 patched and 2.6.0 (both April-25-2007) and svIDE 0.9-5 The only difference is that the warnings are: 1: '\A' is an unrecognized escape in a character string 2: unrecognized escape removed from ";for Options\AutoIndent: 0=Off, 1=follow language scoping and 2=co

Re: [R] Computing the rank of a matrix.

2007-04-06 Thread apjaworski
How about qr(A)$rank or perhaps qr(A, LAPACK=TRUE)$rank Cheers, Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 736-3122

Re: [R] Integer Optimization

2007-03-21 Thread apjaworski
Dimitri, I am assuming you mean integer linear optimization problem. Try lpSolve. I think you will find it much easier to use. Cheers, Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651)

[R] mixture of 2 normals - starting values

2007-02-22 Thread apjaworski
Hi, I have a problem of estimating a mixture of two normal distributions. I need to find the starting points automatically, since this is a part of a larger piece of image processing code. I found the mix2normal1 function in VGAM package that mentions a method of finding starting values for mu1

Re: [R] matrix - change values

2006-12-14 Thread apjaworski
Rob, Try a[a>5]<-0 Yup. It works for matrices (and for arrays). It also works with the replacement value being a vector. For example, try b <- array(1:24, dim=c(3, 4, 2)) b[(b>8) & (b<17)] <- 101:108 I think the reason it works like this is that internally array are stored as vectors. Chee

Re: [R] Gantt chart problem after upgrade to R 2.4.0

2006-11-17 Thread apjaworski
This is interesting. I am on Win2000 running R version 2.4.0 Patched (2006-11-15 r39915) and plotrix 2.1.5. I get the plot that scaled a little differently that the 2.3.1 example but the dates look fine. I ran the original code posted by John cane with no changes (copy and paste). I used the wi

Re: [R] Query about using table

2006-10-26 Thread apjaworski
Lalitha, Try something like with(data, table(cut(age, n), member_FLAG)) where data is a data frame with columns named age and member_FLAG and n is the number of age categories (bins) you want. This will give you the number of Ys and Ns in each bin, that you will need to convert to percentages.

Re: [R] compiling rgdal package on windows / macos

2006-10-04 Thread apjaworski
I just tried the Packages>Install package(s).. menu item on my fresh R-2.4.0-patched and rgdal just shows up on the list of packages to install, so I am not sure what the problem is. Alternatively, you can download the Windows *.zip file from any CRAN repository and install it from your hard driv

Re: [R] Anybody ever notice...

2006-06-12 Thread apjaworski
I am guessing you are starting Rcmdr using > library(Rcmdr). If this is the case, repeating the library command does nothing, since Rcmdr package is already attached. Try > Commander() instead. Make sure you use capital C. Cheers, Andy __ Andy Jaworski 518-1

Re: [R] find position to last number in a vector

2006-05-26 Thread apjaworski
I am sure there are several ways of doing this but how about something like this: y <- c(NA,NA,10,NA,2,NA,NA,1,NA,NA) x <- c(10,20,30,40,50,60,70,80,85,100) tail(x[!is.na(y)], 1) or rev(x[!is.na(y)])[1] Rudimentary checks indicate that the second expression is much faster than the first. Also

Re: [R] R crashes during 'eigen'

2006-03-28 Thread apjaworski
It looks like there might be a bug in the symmetry detection routine of eigen. When I do eigen(M, symmetric=FALSE) it works fine. Eigenvalues (after omitting their imaginary parts, which are essentially zeros) are the same as the ones obtained with EISPACK to within a small multiple of machine

Re: [R] bivariate normal distribution

2006-02-13 Thread apjaworski
Check out the mvtnorm package. Cheers, Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 736-3122

Re: [R] nls() fit to Kahnemann/ Tversky function

2005-10-31 Thread apjaworski
Mark, The parameter of your model (gamma) should not be a part of the dataframe. In addition, the start argument should be a named list. Something like this works nls.dataframe <- data.frame(p.kum,felt.prob.kum) nls.kurve <- nls( formula = felt.prob.kum ~ p.kum^gamma/(p.kum^gamma+(1-p.kum)^gamma

Re: [R] does column exist?

2005-05-19 Thread apjaworski
There may be a simpler way, but this is.na(match("X", names(df))) should return TRUE if the column name exists and FALSE otherwise. Cheers, Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Te

Re: [R] 'fitdistr' and two views of the same data?

2005-05-18 Thread apjaworski
Matt, There is nothing wrong here. I rerun your example and got the same parameters. Your only "problem" is that you let the density plot use the default limits on x, which are not reasonable here since your data extends to over 200. Try this: hist(dd, freq=FALSE) #dd is your original da

Re: [R] slowness of plot(x, type='l')

2005-05-09 Thread apjaworski
Thanks for the quick response and apologies for my sloppy post (nor mentioning the device) and sloppy example (the use of date()). Indeed, I was using the windows device. There is no timing problem with the postscript device. I just installed the R-devel May-9 and the problem went away. He

[R] slowness of plot(x, type='l')

2005-05-06 Thread apjaworski
A couple of days ago a few messages indicated that something changed in the basic plot routine that made plot(*, type='l') slow for large data sets. Some people even reported crashes for very large data sets. As far as I remember, this was not reported as a formal bug. I am still not sure if

Re: [R] Unbundling gregmisc (was: loading gap package)

2005-05-04 Thread apjaworski
I have one comment, although it is a little off topic. I have the gregmisc package installed (R-2.0.1 on Win2000). Whenever I use the help.search function it comes back with the following warning: Warning message: no Rd contents for package 'gregmisc' in 'C:/local/R/rw210/library' in: help.

Re: [R] multivariate Shapiro Wilks test

2005-05-03 Thread apjaworski
Anna, It looks like the mshapiro.test wants its data in the row format, that is, for a k-variate sample of size n you need the data in a k-by-n matrix. Try a <- t(mvrnorm(1000, c(1,2,3,4,5), diag(5))) mshapiro.test(a) and it should work fine. Cheers, Andy ___

Re: [R] half-normal residual plots

2005-04-07 Thread apjaworski
There is a halfnorm function in the faraway package. Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 736-3122

RE: [R] looking for a plot function

2005-04-06 Thread apjaworski
I am not sure about the scaling, but doing simply matplot(xa, t(dfr), type="b") does most of what you want. Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 7

Re: [R] plotmath question

2005-03-18 Thread apjaworski
Bert, This works fine and and seems a little simpler: x<-seq(-3,to=3,by=.01) y<-dnorm(x) plot(x,y,type='h',col='lightblue',axes=FALSE) lines(x,y,col='darkblue') axis(2) ll <- expression(mu-3*sigma, mu-2*sigma, mu-sigma, mu, mu+sigma, mu+2*sigma, mu+3*sigma) axis(1, at=-3:3, lab=ll) box()

[R] A question about r-help-bounce

2005-01-11 Thread apjaworski
Could somebody please tell me what does the r-help-bounce address do? When I try to respond to an r-help post, my mailer (Lotus Notes) generates the r-help bounce return address automatically in addition to the original sender address and the r-help address. I responded to an r-help message

Re: [R] Graphical table in R

2005-01-10 Thread apjaworski
The outer two lines could also be done more easily (?) by: library(gplots) #part of gregmisc bundle textplot(txt) Check ?textplot for additional options. Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL

Re: [R] Make a table

2004-12-22 Thread apjaworski
Muhammad, Try tapply(prevRND.dat$Z, list(X=prevRND.dat$X, Y=prevRND.dat$Y), mean) Cheers, Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 736-3122

Re: [R] switching to Linux, suggestions?

2004-12-13 Thread apjaworski
The newest "production" release of Fedora is Core 3. I would use this one if I were you. Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 736-3122

Re: [R] Non-Linear Regression on a Matrix

2004-11-16 Thread apjaworski
If your "non-linear function (A, B)" is parametric nls should do it for you. If you have R version 2 (perhaps even 1.9) do ?nls to see the help page. Older versions of R require library(nls) first. Hope this helps, Andy __ Andy Jaworski 518-1-01 Process Lab

Re: [R] xyplot and for loops

2004-05-04 Thread apjaworski
Dave, I think inside the loop you have to explicitly "print" a trellis object, i.e. say print(yplot(tmp.df$y.tmp ~ tmp.df[,i])) If you read the help page for xyplot, look under "Value". Hope this helps, Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M

Re: [R] Question on CAR appendix on NLS

2004-04-22 Thread apjaworski
Ajay, I beleve there is an error in your hand-calculated derivatives. model = function(beta1, beta2, beta3, time) { m = beta1/(1+exp(beta2+beta3*time)) term = exp(beta2 + beta3*time) gradient = cbind((1+term)^-2, < the exponent should be -1 -beta1*(1+term)^-2 * term,

Re: [R] Matrix question

2004-04-13 Thread apjaworski
Gideon, Eigenvectors are normalized to unit length. The first eigenvector calculated by R is equal (ignoring the signs of course) to your stable distribution vector divided by its length. Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Researc

Re: [R] Xeon CPU and ATLAS

2004-03-12 Thread apjaworski
First of all thanks to Peter Dalgaard, Thomas Lumley and Prof Brian Ripley for quick responses. Indeed, I will be running Windows2000 on this machine (my company's standard). I will also install the full version of cygwin on it. When I asked my original question I thought about just copying

[R] Xeon CPU and ATLAS

2004-03-12 Thread apjaworski
I am about to get a new machine at work - an IBM Intellistation with the Xeon 2.8 GB processor. It will run Windows 2000. I would like to install the proper ATLAS dll for this machine, but I am not sure if Xeon is P4? Does anybody have any experience with Xeon? Thanks in advance, Andy

Re: [R] numerical equation

2004-03-10 Thread apjaworski
Check out the uniroot function. It will solve a single equation. There is also a packge RMinpack. It implements the original Fortran Minpack library and will solve systems of nonlinear equations. It is only available in source form (search Google for it). Andy ___

[R] test

2004-03-08 Thread apjaworski
I am trying to test whether I can post to the list. I responded to a couple of messages recently and I have not seen my response posted. __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651) 73

RE: [R] Statistical Quality Control

2004-03-08 Thread apjaworski
A new package named qcc just appeared on CRAN. It has standard QC charts, OC curves and process capability stuff. It even has a Minitab-like process capability sixpack. It looks like it is pretty nicely done. Andy __ Andy Jaworski 518-1-01 Process Laborator

Re: [R] Location of polr function

2004-03-03 Thread apjaworski
Peter, These things can be a little mysterious at the beginning. Lots of things in R are arranged in groups called packages (or libraries). Some basic ones come preinstalled with R, some you have to install yourself. If you type library() at your R prompt you should get a list of all p

Re: [R] How to compute the minimal distanct between a point and curve in N-dim space

2004-02-10 Thread apjaworski
In general there will be no closed form solution. In fact, for a general curve in N dimensions one can have multiple discrete solutions or even a continuum of solutions. A trivial example of this is a problem of finding a point on a circle in 2D closest to its center. A curve in N dimensions ca

Re: [R] bug in as.POSIXct ?

2003-12-04 Thread apjaworski
Thanks very much for your response and the earlier one by Professor Ripley. The general problem is indeed a tricky one. My particular problem was much simpler. I had a bunch of data from a data acquisition system with sampling interval of 1 minute. The system used a simple compression scheme,

[R] bug in as.POSIXct ?

2003-12-04 Thread apjaworski
I think that there is a bug in the as.POSIXct function on Windows. Here is what I get on Win2000, Pentium III machine in R 1.8.1. > dd1 <- ISOdatetime(2003, 10, 26, 0, 59, 59) > dd2 <- ISOdatetime(2003, 10, 26, 1, 0, 0) > dd2 - dd1 Time difference of 1.000278 hours Now, the 26th of October was

Re: [R] Parameter estimation in nls

2003-11-25 Thread apjaworski
Your starting values for the parameters are no even in the general ballpark. Here is what I got for the final fit: Parameters: Estimate Std. Error t value Pr(>|t|) a 3.806e+07 1.732e+06 21.971 <2e-16 *** k -3.391e-02 6.903e-02 -0.4910.628 b 9.000e-01 1.240e-02 72.612 <2e-16 *

Re: [R] USA map

2003-11-03 Thread apjaworski
I believe in R you need library(maps) before using usa(). Of course, the library has to be installed first. Cheers, Andy __ Andy Jaworski Engineering Systems Technology Center 3M Center, 518-1-01 St. Paul, MN 55144-1000 - E-mail: [EMAIL PROTECTED] Tel: (6

Re: [R] Generating Data Sets -- Each with a Different Name

2003-10-23 Thread apjaworski
You need paste and assign functions. Paste will create a sequence of names and assign will give values to the variables with these names. This modification of your loop should work for(i in 1:N) { assign(paste("Random.Data.", i, sep=''), rnorm(10, 0, 1)) } Cheers, Andy __

Re: [R] upgrading R

2003-10-09 Thread apjaworski
I am not sure if this is a proper way, but here is what I did recently installing consecutive alpha and beta releases of 1.8.0 on a Win2000 machine: (1) I uninstalled previous version using the uninstall provided with R. This leaves all the additional packages in the library folder (2) I reinstall

[R] bug in stack?

2003-09-23 Thread apjaworski
I am posting it here because I am not sure if the behavior described below is actually a bug. If I do something like this: > x1 <- 1:3 > x2 <- 5:9 > x3 <- 21:27 > ll <- list(x1, x2, x3) > stack(x1,x2,x3) I get the following error: Error in rep.int(names(x), lapply(x, length)) : invalid

Re: [R] Transpose Data Frame Question

2003-09-17 Thread apjaworski
Here is a brute force way: mm <- NULL for(i in unique(ID)){ zz <- data.frame[ID==i, 3] mm <- rbind(mm, c(i, zz)) } It will work as long as you have the same number of tests for each ID. If not, you would need to pad shorter zz vectors with NAs. Cheers, Andy

Re: [R] all possible samples

2003-09-17 Thread apjaworski
I am not sure if this is the easiest way, but you can do something like this: library(gregmisc) combinations(N, n, x, repeats=TRUE) where x is an atomic vector of size N. The only restriction is that the x vector has to have N unique elements. The combinations function will return a matrix wit

Re: [R] Integer programming in R

2003-07-24 Thread apjaworski
Robin, This is not a direct answer to your question, but there exists a pretty good linear, mixted and integer programming package called lp_solve. I have used it successfully on a couple of projects. As far as I know it is in the public domain and there is source code available. There is als

Re: [R] matrix manipulations

2003-07-15 Thread apjaworski
David, I am not sure if it can be done in a vectorized form, but this should work y <- NULL for(i in 1:ncol(x)) y <- c(y, cor(x[,i],apply(x[,-i],1,sum))) Cheers, Andy __ Andy Jaworski Engineering Systems Technology Center 3M Center, 518-1-01 St. Paul, MN 55144-

Re: [R] how to rename rows/columns of a matrix?

2003-07-08 Thread apjaworski
This is what I would do: cc <- NULL for(i in 1:ncol(x)) cc <- c(cc, paste("X", i, sep='')) colnames(x) <- cc where x is your matrix. Hope this helps, Andy __ Andy Jaworski Engineering Systems Technology Center 3M Center, 518-1-01 St. Paul, MN 55144-1000 - E

Re: [R] lines and legend

2003-07-01 Thread apjaworski
Anna, I found this quite useful in positioning a legend: plot(1:10, 1:10) legend(locator(1), "A legend") Now, go to the plot window and click your left mouse where you want the upper left corner of the legend to appear. Ithink, this should work no matter what your coordinate system is. Hope t

[R] Rcmdr active data set

2003-06-24 Thread apjaworski
Hi, This seems a very basic problem, but I cannot seem to find the solution to it. I am trying to use Rcmdr on a data frame I created in my current R session. More specifically, I did x <- data.frame(matrix(0, ncol=3, nrow=5)) library(Rcmdr) Now I would like to be able to edit, view and perhap

Re: [R] Sparse Matrix

2003-05-31 Thread apjaworski
There is a contributed package called SparseM. It looks like it will do what you need. Cheers, Andy __ Andy Jaworski Engineering Systems Technology Center 3M Center, 518-1-01 St. Paul, MN 55144-1000 - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651

Re: [R] Tukey's HSD

2003-03-19 Thread apjaworski
Simint is in the multcomp package. Cheers, Andy __ Andy Jaworski Engineering Systems Technology Center 3M Center, 518-1-01 St. Paul, MN 55144-1000 - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 736-3122 |-+-

Re: [R] network connection

2003-03-18 Thread apjaworski
If you are on a Windows machine try to invoke R with the --internet2 switch. Cheers, Andy __ Andy Jaworski Engineering Systems Technology Center 3M Center, 518-1-01 St. Paul, MN 55144-1000 - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 736-3122

[R] small error in regression tests

2003-03-13 Thread apjaworski
I just r-sync'ed the r-devel version of R-1.7.0 (2003-03-11), compiled it under RH-8.0 and ran make check. The reg-tests-2 fails at the very end with the message stating that "object cement was not found". It looks like this piece of the regression test is new to version 1.7. The the piece of co

Re: [R] Regarding Installation of R

2003-01-30 Thread apjaworski
Yesterday I installed R-1.6.2 on a Win2000 laptop from a binary downloaded from the Wisconsin mirror. No problems. Andy __ Andy Jaworski Engineering Systems Technology Center 3M Center, 518-1-01 St. Paul, MN 55144-1000 - E-mail: [EMAIL PROTECTED] Tel: (651)

[R] minor bug in lattice documentation?

2003-01-08 Thread apjaworski
I have been going through Lattice documentation and I just noticed that at the bottom of the panel.functions help page there was a link called lowess.smooth pointing to .../library/modreg/html/loess.smooth.html. This file does not seem to exist in R-1.6.1 or in 1.7.0 (dev) - there are only loess.h

[R] lattice default theme

2003-01-08 Thread apjaworski
I have a feeling that this was already discussed here, but I cannot remember the outcome of the discussion. I would like to have the col.whitebg theme as a default and I cannot figure out how to do it. Functions like lset or trellis.par.set require that the device be active, so how does one set a

Re: [R] Probit Analysis

2002-12-31 Thread apjaworski
| >-| Hi Andy, Thanks! glm and dose.p can do exaclty what I want to do. Just a quick question, how can I extract the numbers in the glm.dose object created by the

Re: [R] Probit Analysis

2002-12-31 Thread apjaworski
Jacqueline, This should be a simple application of GLM. Check the help pages for glm, family and dose.p in library MASS. Look at the example at the bottom of the dose.p help page - it does almost exactly what you need. Hope this helps, Andy __ Andy Jaworski En

Re: [R] More on scan()

2002-12-19 Thread apjaworski
Here is one way of doing this. (1) read the whole file in as a vector of strings one line at a time x <- readLines("") (2) find the position of the "@DATA" string in your vector s <- which(x == "@DATA") (3) scan the file again skipping s lines scan("", skip=s, sep=",", ...) You

[R] New versions of lattice and grid

2002-12-19 Thread apjaworski
I just ran package update on my Win2000 R-1.6.1 and it installed new versions of lattice and grid (0.6-7 and 0.7-3 respectively). Then I ran demo(lattice) and noticed that the last plot, which is supposed to illustrate math expression usage, fails in the sense that all expression are shown literal