similar to: Need a factor level even though there are no observations

Displaying 20 results from an estimated 2000 matches similar to: "Need a factor level even though there are no observations"

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
2006 Jan 22
6
Making a markov transition matrix
Folks, I am holding a dataset where firms are observed for a fixed (and small) set of years. The data is in "long" format - one record for one firm for one point in time. A state variable is observed (a factor). I wish to make a markov transition matrix about the time-series evolution of that state variable. The code below does this. But it's hardcoded to the specific years that I
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
2005 Aug 19
1
Problem with get.hist.quote() in tseries
When using get.hist.quote(), I find the dates are broken. This is with R 2.1.1 on Mac OS X `panther'. > library(tseries) Loading required package: quadprog 'tseries' version: 0.9-27 'tseries' is a package for time series analysis and computational finance. See 'library(help="tseries")' for details. > x <-
2004 Dec 29
1
Discrepancy between intervals.lme and coef.lme
I'm using R on Windows v2.0.1 with the nlme package (v3.1-53) and am finding some unexpected discrepancies in the output of intervals.lme and coef.lme. I've included a toy dataset at the end, but briefly, the data are longitudinal data from couples in marital therapy. Each spouse's relationship satisfaction is measured 4 times; I've fit both linear and quadratic models to the
2005 May 27
1
R commandline editor question
I am using R 2.1 on Apple OS X. When I get the ">" prompt, I find it works well with emacs commandline editing. Keys like M-f C-k etc. work fine. The one thing that I really yearn for, which is missing, is bracket matching When I am doing something which ends in )))) it is really useful to have emacs or vi-style bracket matching, so as to be able to visually keep track of whether I
2005 Sep 25
1
Question on lm(): When does R-squared come out as NA?
I have a situation with a large dataset (3000+ observations), where I'm doing lags as regressors, where I get: Call: lm(formula = rj ~ rM + rM.1 + rM.2 + rM.3 + rM.4) Residuals: 1990-06-04 1994-11-14 1998-08-21 2002-03-13 2005-09-15 -5.64672 -0.59596 -0.04143 0.55412 8.18229 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.003297 0.017603
2004 Mar 01
6
Find out the day of week for a chron object?
I know that this is correct: library(chron) x = dates("01-03-04", format="d-m-y", out.format="day mon year") print(x) It gives me the string "01 Mar 2004" which is correct. I also know that I can say: print(day.of.week(3,1,2004)) in which case he says 1, for today is monday. My question is: How do I combine these two!? :-) I have a
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
2005 Oct 01
1
Placing axes label strings closer to the graph?
Folks, I have placed an example of a self-contained R program later in this mail. It generates a file inflation.pdf. When I stare at the picture, I see the "X label string" and "Y label string" sitting lonely and far away from the axes. How can these distances be adjusted? I read ?par and didn't find this directly. I want to hang on to 2.8 x 2.8 inches as the overall size
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
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
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
2004 Apr 08
2
Clever R syntax for extracting a subset of observations
I know that if: x = seq(1,10) d = c(7,3,2) and if I say y = x[d] then I get the vector y as (7,3,2). Very clever! This idea is used intensively with the boot library. Now consider the following code (which works): --------------------------------------------------------------------------- library(boot) sdratio <- function(D, d) { return(sd(D$x[d])/sd(D$y[d])) } x =
2004 Feb 19
6
R for economists (was: Almost Ideal Demand System)
Hi, I did not find any web page about using R in economics and econometrics so far. However, this does not mean that there is none (searching with google for "R" and "economics" gives many pages about economics and a name like Firstname R. Lastname on it ;-)). Does anybody in the list does know such a web page? If not, I will be happy if you, Ajay, could build and
2005 Jun 07
1
R and MLE
I learned R & MLE in the last few days. It is great! I wrote up my explorations as http://www.mayin.org/ajayshah/KB/R/mle/mle.html I will be most happy if R gurus will look at this and comment on how it can be improved. I have a few specific questions: * Should one use optim() or should one use stats4::mle()? I felt that mle() wasn't adding much value compared with optim, and
2004 May 27
3
Date parsing question
How do I parse a date "yyyymmdd"? I tried asking chron(s, "ymd") but that didn't work. Would the date parsing routines of the Date class of 1.9 grok this? -- Ajay Shah Consultant ajayshah at mayin.org Department of Economic Affairs http://www.mayin.org/ajayshah Ministry of Finance, New Delhi
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 <*(:-? -
2004 Jun 21
2
Elementary sapply question
I am discovering sapply! :-) Could you please help me with a very elementary question? Here is what I know. The following two programs generate the same answer. --------------------------------+---------------------------------------- Loops version | sapply version --------------------------------+----------------------------------------
2005 May 24
1
Catching an error with lm()
Folks, I'm in a situation where I do a few thousand regressions, and some of them are bad data. How do I get back an error value (return code such as NULL) from lm(), instead of an error _message_? Here's an example: > x <- c(NA, 3, 4) > y <- c(2, NA, NA) > d <- lm(y ~ x) Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases