similar to: maximizing a function

Displaying 20 results from an estimated 3000 matches similar to: "maximizing a function"

2008 Mar 17
4
How does one do simple string concatenation?
How does one convert objects c("a","b","c") and "d" into "abcd"? > paste(c("a","b","c"), "d") of course yields [1] "a d" "b d" "c d" -- Ajay Shah http://www.mayin.org/ajayshah ajayshah at mayin.org
2008 Mar 18
3
Puzzled at generating combinations
I have two data frames. Suppose the first has rows r1 r2 r3 and the second has rows R1 R2 R3 I'd like to generate the data frame: r1 R1 r1 R2 r1 R3 r2 R1 r2 R2 r2 R3 r3 R1 r3 R2 r3 R3 How would I go about doing this? I'm sure there's a clean way to do it but I find myself thinking in loops. -- Ajay Shah
2008 Oct 15
2
"Heuristic optimisation"?
I wondered was people on this list felt about this article: http://www.voxeu.org/index.php?q=node/2363 which talks about the problems of obtaining sound answers in numerical optimisation in settings such as MLE or NLS. -- Ajay Shah http://www.mayin.org/ajayshah ajayshah at mayin.org http://ajayshahblog.blogspot.com <*(:-? -
2006 Jan 26
2
Prediction when using orthogonal polynomials in regression
Folks, I'm doing fine with using orthogonal polynomials in a regression context: # We will deal with noisy data from the d.g.p. y = sin(x) + e x <- seq(0, 3.141592654, length.out=20) y <- sin(x) + 0.1*rnorm(10) d <- lm(y ~ poly(x, 4)) plot(x, y, type="l"); lines(x, d$fitted.values, col="blue") # Fits great! all.equal(as.numeric(d$coefficients[1] + m
2008 Mar 05
1
New data source - now how do we build an R interface?
Folks, A nice new data resource has come up -- http://data.un.org/ I thought it would be wonderful to setup an R function like tseries::get.hist.quote() which would be able to pull in some or all of this data. I walked around a bit of it and I'm not able to map the resources to predictable URLs which can then be wget. There's some javascript going on that I'm not understanding.
2009 Oct 17
2
How do I access with the name of a (passed) function
How would I do something like this: f <- function(x, g) { s <- as.character(g) # THIS DOES NOT WORK sprintf("The %s of x is %.0f\n", s, g(x)) } f(c(2,3,4), "median") f(c(2,3,4), "mean") and get the results "The median of x is 3" "The mean of x is 3" -- Ajay Shah
2006 Mar 06
3
Interleaving elements of two vectors?
Suppose one has x <- c(1, 2, 7, 9, 14) y <- c(71, 72, 77) How would one write an R function which alternates between elements of one vector and the next? In other words, one wants z <- c(x[1], y[1], x[2], y[2], x[3], y[3], x[4], y[4], x[5], y[5]) I couldn't think of a clever and general way to write this. I am aware of gdata::interleave() but it deals
2007 Dec 19
1
Code for articles in R news?
I went to the article on np in R news 7/2 (October 2007). What's the general technique to get the source code associated with the article as a .R file that I can play with? -- Ajay Shah http://www.mayin.org/ajayshah ajayshah at mayin.org http://ajayshahblog.blogspot.com <*(:-? - wizard who doesn't know the answer.
2007 Aug 31
2
Bugreport on integration of Sweave and latex beamer
I think I have isolated a problem with integration between Sweave and beamer. Could you please see the file: http://www.mayin.org/ajayshah/tmp/bugdemo.Rnw Unfortunately, it uses some of my internal libraries, so you can't run it. When I put it through Sweave, I get: http://www.mayin.org/ajayshah/tmp/bugdemo.tex which is, of course, a generic latex file which you can read and
2009 Mar 15
1
cbind(NULL,zoo.object)?
Folks, I often build up R objects starting from NULL and then repeatedly using rbind() or cbind(). This yields code like: a <- NULL for () { onerow <- craft one more row a <- rbind(a, onerow) } This works because rbind() and cbind() are forgiving when presented with a NULL arg: they act like nothing happened, and you get all.equal(x,rbind(NULL,x)) or all.equal(x,cbind(NULL,x)).
2008 Mar 07
4
Reading microsoft .xls format and openoffice OpenDocument files
1. I have used gdata::read.xls() with much happiness. But every now and then it breaks. I have not, as yet, been able to construct a mental model about the class of .xls files for which it works. Does someone have a simple rule for predicting the circumstances under which it will work? 2. Just like there is a read.xls(), it'd be great if we have a read.ods() which directly
2007 May 27
0
Not able to understand the behaviour of boot
Folks, I have a time-series of 875 readings of the weekly returns of a stock market index (India's Nifty). I am interested in the AR(1) coefficient. When I do arima(r, order=c(1,0,0)) I get a statistically significant AR1 coefficient. If we apply the ordinary bootstrap to this problem, this involves sampling with replacement, which destroys the time-series structure. Hence, if we do
2008 Dec 26
1
Question about regression without an intercept
Consider this code fragment: --------------------------------------------------------------------------- set.seed(42) x <- runif(20) y <- 2 + 3*x + rnorm(20) m1 <- lm(y ~ x) m2 <- lm(y ~ -1 + x) summary(m1) summary(m2) cor(y, fitted.values(m1))^2 cor(y, fitted.values(m2))^2 --------------------------------------------------------------------------- m1 is the
2009 Mar 15
1
Stuck on building a package
Folks, I have a personal package which used to build fine. Today when I tried to build the package again, some errors popped up. Could you please help? When I paste the offending function into an R it works correctly. But the package build breaks. $ R CMD check ansecon * checking for working pdflatex ... OK * using log directory '/Users/ajayshah/L/R/packages/ansecon.Rcheck' * using R
2009 May 14
2
How to do a pretty panel plot?
The pretty picture that I saw at: http://chartsgraphs.wordpress.com/2009/02/09/r-panel-chart-beats-excel-chart/#more-1096 inspired me to try something similar. The code that I wrote is: ------snipsnip--------------------------------------------------------------------- M <- structure(list(date = structure(c(13634, 13665, 13695, 13726, 13757, 13787, 13818, 13848, 13879, 13910, 13939, 13970,
2007 Oct 09
3
How do I obtain the design matrix of an lm()?
I am using the clever formula notation of R to first do an OLS. E.g. I say m <- lm(y ~ x + f) where f is a factor, and R automatically constructs the dummy variables. Very nice. I need to then go on to do some other ML estimation using the same design matrix that's used for the OLS. I could, of course, do this manually. But it seems that lm() has done all this hard work. I wonder if
2009 Jan 03
2
R badly lags matlab on performance?
Here's a small R program: --------------------------------------------------------------------------- a <- rep(1,10000000) system.time(a <- a + 1) system.time(for (i in 1:10000000) {a[i] <- a[i] + 1}) --------------------------------------------------------------------------- and here's its matlab version:
2010 Feb 27
1
Bug in ecdf? Or what am I missing?
x <- c(6.6493705109108, 7.1348436721241, 8.76886994525624, 6.12907548096037, 6.88379118678109, 7.17841879427688, 7.90737237492867, 7.1207373264833, 7.82949407630692, 6.90411547316105) plot(ecdf(x), log="x") It does the plot fine, but complains: Warning message: In xy.coords(x, y, xlabel, ylabel, log) : 1 x value <= 0 omitted from logarithmic
2006 Jan 19
2
Tobit estimation?
Folks, Based on http://www.biostat.wustl.edu/archives/html/s-news/1999-06/msg00125.html I thought I should experiment with using survreg() to estimate tobit models. I start by simulating a data frame with 100 observations from a tobit model > x1 <- runif(100) > x2 <- runif(100)*3 > ystar <- 2 + 3*x1 - 4*x2 + rnorm(100)*2 > y <- ystar > censored <- ystar <= 0
2006 Aug 14
1
Presentation of multiple models in one table using xtable
Consider this situation: > x1 <- runif(100); x2 <- runif(100); y <- 2 + 3*x1 - 4*x2 + rnorm(100) > m1 <- summary(lm(y ~ x1)) > m2 <- summary(lm(y ~ x2)) > m3 <- summary(lm(y ~ x1 + x2)) Now you have estimated 3 different "competing" models, and suppose you want to present the set of models in one table. xtable(m1) is cool, but doing that thrice would give