I don't know how to retain my row labels. I read in a table with row labels,
ie:
Price Floor Area Rooms
52. 111. 830 5
54. 128. 710 5
47.4 101 1000 4
...
but then I need to transform the data
raggedRidzeros <- function(x){
y = list(ridzeros(x[[1]]))
for(i in 2:length(x)){
y = c(y,list(ridzeros(x[[i]])))
}
y
}
(where ridzeros is a function that I call to get rid of the zeros in the
vector)
When I do this, I no longer have row labels. Is there any way to insert the
row labels from the original calling function into this function?
Anna
labels
7 messages · Anna H. Pryor, Barry Rowlingson, Peter Dalgaard +2 more
Anna H. Pryor wrote:
I don't know how to retain my row labels. I read in a table with row labels, ie: Price Floor Area Rooms 52. 111. 830 5 54. 128. 710 5 47.4 101 1000 4
I dont see any row labels. I assume you mean column labels!
but then I need to transform the data
raggedRidzeros <- function(x){
y = list(ridzeros(x[[1]]))
for(i in 2:length(x)){
y = c(y,list(ridzeros(x[[i]])))
}
y
}
This can all be done in one line! Here's some data that does have row
and column labels:
> tm
Foo Bar Baz
Mercury 1 0.6961034 0
Venus 2 0.3137058 0
Earth 3 0.7692529 1
Mars 0 0.2598111 0
Jupiter 1 0.8375288 0
Saturn 0 0.5866152 0
Now I want to sweep through columns and return a list without the
zeroes. I do this:
> nonZero <- apply(tm,2,function(x){x[x!=0]})
and I get a list:
$Foo
Mercury Venus Earth Jupiter
1 2 3 1
$Bar
Mercury Venus Earth Mars Jupiter Saturn
0.6961034 0.3137058 0.7692529 0.2598111 0.8375288 0.5866152
$Baz
Earth
1
Note this preserves column names (as the names of the list elements,
so I can do nonZero$Foo), and keeps the row names (as names of
individual elements).
> nonZero$Bar['Earth']
Earth
0.7692529
How it works:
function(x){x[x!=0]} is my 'ridzeros' function.
I use 'apply(tm,2,function(x){x[x!=0]})' to apply the ridzeros
function to columns (thats the '2') of the matrix. To do the same by
rows, use '1'.
Hardly rocket science :)
Baz
Barry Rowlingson <B.Rowlingson at lancaster.ac.uk> writes:
Now I want to sweep through columns and return a list without the zeroes. I do this:
> nonZero <- apply(tm,2,function(x){x[x!=0]})
and I get a list:
$Foo
Mercury Venus Earth Jupiter
1 2 3 1
$Bar
Mercury Venus Earth Mars Jupiter Saturn
0.6961034 0.3137058 0.7692529 0.2598111 0.8375288 0.5866152
$Baz
Earth
1
Note this preserves column names (as the names of the list elements,
so I can do nonZero$Foo), and keeps the row names (as names of
individual elements).
> nonZero$Bar['Earth']
Earth
0.7692529
How it works:
function(x){x[x!=0]} is my 'ridzeros' function.
I use 'apply(tm,2,function(x){x[x!=0]})' to apply the ridzeros
function to columns (thats the '2') of the matrix. To do the same by
rows, use '1'.
Hardly rocket science :)
...but slightly dangerous if you have a risk of ending up with all
lists elements equally long, because then you get a matrix instead of
a list. If you want to make damn sure that you get a list, I think you
need something like
do.call("c",apply(tm,2,function(x)list(x[x!=0]))
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Dear Group, I have come across with the following error while running HoltWinters(). optim(c(0.3, 0.1, 0.1), error, method = "L-BFGS-B", lower = c(0, 0, 0), upper = c(1, 1, 1)) It only happens to multiplicative seasonality but not additive. I read the program but still couldn't understand it. Thanks!
That's not an error, but a line of R code. If you could post an example which generates the error and the actual error message, we could try to investigate it.
On Tue, 29 Apr 2003, Kel wrote:
I have come across with the following error while running HoltWinters(). optim(c(0.3, 0.1, 0.1), error, method = "L-BFGS-B", lower = c(0, 0, 0), upper = c(1, 1, 1)) It only happens to multiplicative seasonality but not additive. I read the program but still couldn't understand it.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Here's the time series (Jan 1994 - Dec 1998)
test5
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1994 16.0 17.4 19.2 21.4 24.0 27.0 29.0 29.4 29.4 29.0 28.2 27.0 1995 28.0 31.8 36.0 40.6 45.6 51.0 53.0 51.0 48.6 45.8 42.6 39.0 1996 40.0 46.2 52.8 59.8 67.2 75.0 77.0 72.6 67.8 62.6 57.0 51.0 1997 52.0 60.6 69.6 79.0 88.8 99.0 101.0 94.2 87.0 79.4 71.4 63.0 1998 64.0 75.0 86.4 98.2 110.4 123.0 125.0 115.8 106.2 96.2 85.8 75.0
HoltWinters(test5,seasonal="mult")
Here's the message I get: Error in optim(c(0.3, 0.1, 0.1), error, method = "L-BFGS-B", lower = c(0, : L-BFGS-B needs finite values of fn" Thanks again.
--- Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
That's not an error, but a line of R code. If you could post an example which generates the error and the actual error message, we could try to investigate it. On Tue, 29 Apr 2003, Kel wrote:
I have come across with the following error while running HoltWinters(). optim(c(0.3, 0.1, 0.1), error, method =
"L-BFGS-B",
lower = c(0, 0, 0), upper = c(1, 1, 1)) It only happens to multiplicative seasonality but
not
additive. I read the program but still couldn't understand it.
-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
That's a very short series to expect to fit a seasonal HW model to whilst choosing the degree of smoothing. and the optimization code is failing, because the initial guesses are too far away. The following should give you a clue: HoltWinters(test5, seasonal = "additive") Smoothing parameters: alpha: 1 beta : 0.8108822 gamma: 1 and using alpha=1 will work with the multiplicative model too. You can edit the function and choose other starting values than c(0.3, 0.1, 0.1) and thereby get it to converge, but I would have little confidence in the values found.
On Wed, 30 Apr 2003, Kel wrote:
Here's the time series (Jan 1994 - Dec 1998)
test5
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1994 16.0 17.4 19.2 21.4 24.0 27.0 29.0 29.4 29.4 29.0 28.2 27.0 1995 28.0 31.8 36.0 40.6 45.6 51.0 53.0 51.0 48.6 45.8 42.6 39.0 1996 40.0 46.2 52.8 59.8 67.2 75.0 77.0 72.6 67.8 62.6 57.0 51.0 1997 52.0 60.6 69.6 79.0 88.8 99.0 101.0 94.2 87.0 79.4 71.4 63.0 1998 64.0 75.0 86.4 98.2 110.4 123.0 125.0 115.8 106.2 96.2 85.8 75.0
HoltWinters(test5,seasonal="mult")
Here's the message I get: Error in optim(c(0.3, 0.1, 0.1), error, method = "L-BFGS-B", lower = c(0, : L-BFGS-B needs finite values of fn" Thanks again. --- Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
That's not an error, but a line of R code. If you could post an example which generates the error and the actual error message, we could try to investigate it. On Tue, 29 Apr 2003, Kel wrote:
I have come across with the following error while running HoltWinters(). optim(c(0.3, 0.1, 0.1), error, method =
"L-BFGS-B",
lower = c(0, 0, 0), upper = c(1, 1, 1)) It only happens to multiplicative seasonality but
not
additive. I read the program but still couldn't understand it.
-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
__________________________________ Do you Yahoo!?
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595