[R] Different type of legend?

2012-01-30 Thread rkevinburton


How would I create a legend that looks like the attached image? 
Basically all of the color boxes are right next to each other and the 
text is below. This kind of arrangement allows for many more items in 
the legend. Using the legend() method seems to top out at about 14 items 
(that will fit in the horizontal plot).


Suggestions?

Thank you.

Kevin
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Different type of legend?

2012-01-30 Thread rkevinburton
Sorry. I am not sure how to post a link. Basically the legend looks 
like:


 * * * * * * * * * * *
-4 -3 -2 -1 0 1 2 3 4

Where ' * ' are colored boxes that are right next to each other. Kind of 
like a gradient.



On Mon, Jan 30, 2012 at 3:29 PM, R. Michael Weylandt wrote:


Server stripped the attachment. Can you post a link somewhere?

Michael

On Mon, Jan 30, 2012 at 4:25 PM,  rkevinbur...@charter.net wrote:


How would I create a legend that looks like the attached image? 
Basically
all of the color boxes are right next to each other and the text is 
below.
This kind of arrangement allows for many more items in the legend. 
Using the
legend() method seems to top out at about 14 items (that will fit in 
the

horizontal plot).

Suggestions?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] apply on rows and columns?

2011-11-16 Thread rkevinburton

I have the following scenario:

 m - matrix(1:4, ncol=2)
 m
  [,1] [,2]
[1,]13
[2,]24
 apply(m, 2, sum)
[1] 3 7
 apply(m, 1, sum)
[1] 4 6

So I can apply to rows *or* columns. According to the documentation 
(?apply)

MARGIN a vector giving the subscripts which the function will be applied 
over. E.g., for a matrix 1 indicates rows, 2 indicates columns, c(1, 2) 
indicates rows and columns. Where X has named dimnames, it can be a 
character vector selecting dimension names.


But I get the following results:

 apply(m, c(1,2), sum)
  [,1] [,2]
[1,]13
[2,]24

How am I to interpret this result?

Thank you.

Kevin

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] List of lists to data frame?

2011-11-16 Thread rkevinburton

I would like to make the following faster:

df - NULL
for(i in 1:length(s))
{
df - rbind(df, cbind(names(s[i]), time(s[[i]]$series), 
as.vector(s[[i]]$series), s[[i]]$category))
}
names(df) - c(name, time, value, category)
return(df)

The s object is a list of lists. It is constructed like:

s[[object]] - list(. . . . . .)

where object would be the name associated with this list s[[i]]$series 
is a 'ts' object and s[[i]]$category is a name.

Constructing this list is reasonably fast but to do some more processing 
on the data it would be easier if it were converted to a data frame. 
Right now the above code is unacceptably slow at converting this list of 
lists to a data frame. Any suggestions on how to optimize this are 
welcome.

Thank you.

Kevin

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Formula variable help

2011-11-11 Thread rkevinburton

I have an R script with the following applicable lines:

xshort - window(s, start=st, end=ed)
. . .
xshort - ts(xshort, frequency=1, start=1)
. . .
m1 - m2 - m3 - m4 - m5 - m6 - NULL
m1 - tslm(xshort ~ trend)

I get an error:

Error in get(dataname) : object 'xshort' not found

When I do traceback() I get:

3: get(dataname)
2: tslm(xshort ~ trend) at #19
1: model.cross.validation(l[[MEN]]$series)

Which points to the call to tslm above.  Since I am not supply 'data' to 
the tslm call (in the forecast package),, I am assuming that the code is 
dying here (in tslm):

 if (missing(data)) {
 dataname - as.character(formula)[2]
 x - get(dataname)
 data - data.frame(x)
 colnames(data) - dataname
 }

Any ideas what is failing?

Kevin

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] window?

2011-11-09 Thread rkevinburton

Thank you.

I am glad I asked. It wasn't giving answers that I expected and now I 
know why.


Rather than pull in another package just for this functionality, I will 
just reassign the frequency by generating a new time series like:


dswin - window(ds, start=..., end=...)
dswin - ts(dswin, frequency=1)

That should work shouldn't it?

Thanks again.

Kevin


On Tue, Nov 8, 2011 at 9:40 PM, R. Michael Weylandt wrote:


Like Denis said, you are asking ts to do things that don't make sense;
in particular, some of your statements suggest you don't fully
understand what window does or what its frequency argument does.
Specifically, when you set frequency = 1 in window, that doesn't mean
take a window and treat it as if it has frequency 1; rather take the
subseries corresponding to yearly observations. Since 53 is prime,
there is no regular subseries you can extract with window() other than
the original series and the yearly series.  ts objects are required to
have a frequency so statements like now that I am taking a subset
there is no frequency don't really make sense.

Take a look at these examples:

## Create some working data
ds.53 - ts(rnorm(53*2), frequency=53, start=c(2000,10))
ds.48 - ts(rnorm(48*2), frequency = 48, start = c(2000,10))

## These all work
window(ds.53, frequency = 1) # Returns elements 1  54 of ds.53
window(ds.53, frequency = 53) # Returns every element of ds.53

window(ds.48, frequency = 1) # Returns elements 1  54 of ds.53
window(ds.48, frequency = 12) # Returns elements seq(1, 48, by = 4) of 
ds.48

window(ds.48, frequency = 48) # Returns every element of ds.48

## These don't
window(ds.53, frequency = 7)
window(ds.48, frequency = 9)

Here's how you could do the same with xts.

library(xts)
library(forecast)
x = xts(rnorm(53*2), Sys.Date() + 365*seq(0, 2, by = 1/53))
ets(x) # Auto-conversion to ts

Michael


On Tue, Nov 8, 2011 at 8:19 PM, Kevin Burton 
rkevinbur...@charter.net wrote:
The problem is when I use the window function an try to extract a 
subset of
the time series an specify the frequency as 1 (not only will ets not 
take a
time series with a frequency greater than 24, now that I am taking a 
subset
there is no frequency so I would like to set it to 1 (which is one of 
the
arguments to the window function) but it does not produce what I 
expect.
That is the problem.  I fail to see the relationship of the 
discussion of
what frequency is and how to use the forecast package with this 
problem.


-Original Message-
From: Dennis Murphy [mailto:djmu...@gmail.com]
Sent: Tuesday, November 08, 2011 6:20 PM
To: Kevin Burton
Cc: R. Michael Weylandt; r-help@r-project.org
Subject: Re: [R] window?

The ets() function in the forecast package requires either a numeric 
vector
or a Time-Series object (produced from ts()). The frequency argument 
in ts()
refers to the time duration between observations; e.g., frequency = 7 
means
that the data are weekly; frequency = 12 means that the data are 
monthly;
frequency = 4 means that the data are quarterly. You can see this 
from the

examples on the help page of ts:
?ts at the R prompt.

The example associated with the forecast::ets() function uses the
USAccDeaths data:

data(USAccDeaths)
USAccDeaths   ## monthly data for six years
# Simulate the same structure with ts:
u - ts(rnorm(72), start = c(1973, 1), frequency = 12) u

# Evidently you want to produce a multivariate series; # here's one 
way with

monthly frequency:
v - ts(matrix(rnorm(106), ncol = 2), start = c(2001, 1), frequency = 
12) v


Is that more or less what you were after?

Dennis

On Tue, Nov 8, 2011 at 2:04 PM, Kevin Burton 
rkevinbur...@charter.net

wrote:
I expect the frequency to be set to what I set it at and the window 
to

return all of the data in the window from the original time series.
The error is not because it is prime. I can generate a time series
with just 52 values (or 10) and it still occurs. I am building these
objects for use with the 'forecast' packages and one of the methods
'ets' cannot handle a frequency above 24 so I set it (or try to) to 
1.
Will 'window' take z zoo or xts object? Can I convert from zoo or 
xts to

ts?


-Original Message-
From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com]
Sent: Tuesday, November 08, 2011 2:28 PM
To: Kevin Burton
Cc: r-help@r-project.org
Subject: Re: [R] window?

I'm not entirely sure that your request makes sense: what do you
expect the frequency to be? It makes sense to me as is...Might your
troubles be because
53 is prime?

More generally, most people don't like working with the raw ts class
and prefer the zoo or xts packages because they are much more 
pleasant

for most time series work. You might want to take a look into those.

Michael

On Tue, Nov 8, 2011 at 3:18 PM, Kevin Burton
rkevinbur...@charter.net
wrote:

This doesn't seem to work:




d - rnorm(2*53)



ds - ts(d, frequency=53, start=c(2000,10))



dswin - window(ds, start=c(2001,1), end=c(2001,10), frequency=1)



dswin



[R] Stack trace?

2011-11-09 Thread rkevinburton

Currently I have a for loop executing functions and at the end I get a 
message like:

There were 50 or more warnings (use warnings() to see the first 50)

If I do what it says and type warnings(), I get 50 messages like:

2: In !is.na(x)  !is.na(rowSums(xreg)) :
   longer object length is not a multiple of shorter object length

I am not sure what function these errors are originating from. I don't 
think it is from any of the 'R' script that I wrote. I would like to see 
which function is being called when this error is thrown and which 
called that . . . and so on.

I have the same problem with error messages. An error is thrown but I 
don't have a call stack to help trace down the problem. Is there some 
function or technique that I could use to help get a call stack?

Thank you.

Kevin

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Serialization help.

2011-10-21 Thread rkevinburton

I have the following code:

c - file(c:/temp/r/SkuSalesModel.br, rb)
s - unserialize(c)
close(c)
rm(c)

And it worked as late as yesterday. Today when I came in I get the 
following error:

Error in .Call(R_unserialize, connection, refhook, PACKAGE = base) :
   negative length vectors are not allowed

I have not upgraded or changed any installation and the file has not 
changed. Any ideas on how I can get more info or solve this error?

Thank you.

Kevin

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Plotting text?

2011-10-21 Thread rkevinburton

I noticed that the text() command adds text to a plot. Is there a way to 
either make the plot blank or add text to a blank sheet. I would like 
to plot a page that contains just text, no plot lines, labels, etc.

Suggestions?

Kevin

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] F# vs. R

2010-07-08 Thread rkevinburton
True, porting old C and Fortran code to C# or F# would be a pain and probably 
riddled with errors but it is not too soon to start looking to see if there is 
a better way. There have been numerous ports of LAPACK, BLAS, etc. to C#. Maybe 
they could be leveraged.

Maybe just allowing packages to be wrtten in C# or F# would be helpful. And 
remember there is Mono.

Just my 2 cents.

 Patrick Burns pbu...@pburns.seanet.com wrote: 
 I'd like to hear answers to this as well.
 A language doesn't have to be a complete
 replacement to be useful.
 
 F# seems to have some nice features.
 
 Pat
 
 On 07/07/2010 17:54, Sergey Goriatchev wrote:
  Hello, Marc
 
  No, I do not want to validate Cox PH. :-)
  I do use R daily, though right now I do not use the statistical part that 
  much.
 
  I just generally wonder if any R-user tried F# and his/her opinions.
 
  Regards,
  Sergey
 
 
  On Wed, Jul 7, 2010 at 17:56, Marc Schwartzmarc_schwa...@me.com  wrote:
  On Jul 7, 2010, at 10:31 AM, Sergey Goriatchev wrote:
 
  Hello, everyone
 
  F# is now public. Compiled code should run  faster than R.
 
  Anyone has opinion on F# vs. R? Just curious
 
  Best,
  S
 
 
  The key time critical parts of R are written in compiled C and FORTRAN.
 
  Of course, if you want to take the time to code and validate a Cox PH or 
  mixed effects model in F# and then run them against R's coxph() or 
  lme()/lmer() functions to test the timing, feel free...  :-)
 
  So unless there is a pre-existing library of statistical and related 
  functionality for F#, perhaps you need to reconsider your query.
 
  Regards,
 
  Marc Schwartz
 
 
 
 
 
 
 -- 
 Patrick Burns
 pbu...@pburns.seanet.com
 http://www.burns-stat.com
 (home of 'Some hints for the R beginner'
 and 'The R Inferno')
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Forcing scalar multiplication.

2010-06-25 Thread rkevinburton
I am trying to check the results from an Eigen decomposition and I need to 
force a scalar multiplication. The fundamental equation is: Ax = lx. Where 'l' 
is the eigen value and x is the eigen vector corresponding to the eigenvalue. 
'R' returns the eigenvalues as a vector (e - eigen(A); e$values). So in order 
to 'check' the result I would multiply the eigenvalues ('l') by the 
eigenvectors. But unless I do it one by one (say e$values[1] * e$vectors[,1]) 
'R' tries a matrix multiplication and that is not what I want.  I would like a 
matrix that is formed by the SCALAR multiplication of each of the values by the 
corresponding eigenvector. How can I force such a multiplication?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Forcing scalar multiplication.

2010-06-25 Thread rkevinburton
I am trying to check the results from an Eigen decomposition and I need to 
force a scalar multiplication. The fundamental equation is: Ax = lx. Where 'l' 
is the eigen value and x is the eigen vector corresponding to the eigenvalue. 
'R' returns the eigenvalues as a vector (e - eigen(A); e$values). So in order 
to 'check' the result I would multiply the eigenvalues ('l') by the 
eigenvectors. But unless I do it one by one (say e$values[1] * e$vectors[,1]) 
'R' tries a matrix multiplication and that is not what I want.  I would like a 
matrix that is formed by the SCALAR multiplication of each of the values by the 
corresponding eigenvector. How can I force such a multiplication?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Beginning Eigen System question.

2010-06-23 Thread rkevinburton
Forgive me if I missunderstand a basic Eigensystem but when I present the 
following matrix to most any other LinearAlgebra system:

 1  3  1
 1  2  2
 1  1  3

I get an answer like:

//$values
//[1]  5.00e+00  1.00e+00 -5.536207e-16

//$vectors
//   [,1]   [,2]   [,3]
//[1,] 0.5773503 -0.8451543 -0.9428090
//[2,] 0.5773503 -0.1690309  0.2357023
//[3,] 0.5773503  0.5070926  0.2357023

But R gives me:

//$values
//[1]  5.00e+00  1.00e+00 -5.536207e-16

//$vectors
//   [,1]   [,2]   [,3]
//[1,] -0.5773503 -0.8451543 -0.9428090
//[2,] -0.5773503 -0.1690309  0.2357023
//[3,] -0.5773503  0.5070926  0.2357023

The only difference seems to be the sign on the first eigen vector. What am I 
missing?

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Building Hmisc

2010-04-29 Thread rkevinburton
From the notes I see that for 2.11 Hmisc is not supported and the suggestion 
is made to build from source. I am on a Windows 7 platform and I got all of 
the tools and successfully built 'R' from source. I changed to gnuwin32 and 
entered make all recommended. Even though the tar.gz (source) version of Hmisc 
has been downloaded and placed in library/recommended folder the build process 
doesn't seem to pick it up. What do I need to do to build this from source? 
Right now whenever I start R I get the error:

Error: package 'Hmisc' could not be loaded
In addition: Warning message:
In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = 
lib.loc) :
  there is no package called 'Hmisc'

And I cannot run anything.

Thank you for the suggestions.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Type-I v/s Type-III Sum-Of-Squares in ANOVA

2010-04-19 Thread rkevinburton
i believe John Fox offers another solution in his book.

Kevin

 Daniel Wollschlaeger dw...@psychologie.uni-kiel.de wrote: 
 * On Mo, 1. Mar 2010, Ista Zahn wrote:
 
  I've posted a short explanation about this at
  http://yourpsyche.org/miscellaneous that you might find helpful. I'm a
 
 As someone who's also struggled with the type X sum of squares topic, I
 like the idea to completely walk through a numerical example and see what
 happens. I'd like to extend this a bit, and cover the following aspects:
 
 - how are the model comparisons underlying the SS types calculated?
 - do the compared models obey the marginality principle?
 - what are the orthogonal projections defining the model comparisons?
 - are the projections invariant to the type of contrast codes?
 - are the hypotheses formulated using empirical cell sizes?
   (are the effect estimates using weighted or unweighted marginal means)?
 - how can (some of) the SS be calculated without matrix math?
 
 Below you'll find the code for SS type III using the 2x2 example from
 Maxwell and Delaney. For SS type I, II, and III using the 3x3 example in
 MD, please see http://www.uni-kiel.de/psychologie/dwoll/r/doc/ssTypes.r
 
 The model projections for SS type III corresponding to models that violate
 the marginality principle are not invariant to the coding scheme. If,
 e.g., Pai is the projection for the model including main effect A and
 interaction A:B, Pai will be different for non sum-to-zero and sum-to-zero
 codes. This seems to mean that SS type III for main effects compare
 different models when using different contrasts codes. Which leads to the
 question what hypotheses these models actually imply. I'd be grateful if
 someone could provide any pointers on where to read up on that.
 
 I hope this post is not too long! Best, Daniel
 
 -
 # 2x2 unbalanced design: data from Maxwell  Delaney 2004 p322
 P   - 2  # two groups in factor A (female / male)
 Q   - 2  # two groups in factor B (college degree / no degree)
 g11 - c(24, 26, 25, 24, 27, 24, 27, 23)
 g12 - c(15, 17, 20, 16)
 g21 - c(25, 29, 27)
 g22 - c(19, 18, 21, 20, 21, 22, 19)
 Y   - c(g11, g12, g21, g22)  # salary in 100$
 A   - factor(rep(1:P, c(8+4, 3+7)), labels=c(f, m))
 B   - factor(rep(rep(1:Q, P), c(8,4, 3,7)), labels=c(deg, noDeg))
 
 -
 # utility function getInf2x2 (run with different contrasts settings)
 # fit all relevant regression models for 2x2 between-subjects design
 # output: * residual sum of squares for each model and their df
 # * orthogonal projection on subspace as defined
 #   by the design matrix of each model
 getInf2x2 - function() {
   X - model.matrix(lm(Y ~ A + B + A:B))  # ANOVA design matrix
 
   # indicator variables for factors from design matrix
   idA - X[ , 2]   # factor A
   idB - X[ , 3]   # factor B
   idI - X[ , 4]   # interaction A:B
 
   # fit each relevant regression model
   mod1   - lm(Y ~ 1) # no effect
   modA   - lm(Y ~ idA)   # factor A
   modB   - lm(Y ~   idB) # factor B
   modAB  - lm(Y ~ idA + idB) # factors A, B
   modAI  - lm(Y ~ idA   + idI)   # factor A, interaction A:B
   modBI  - lm(Y ~   idB + idI)   # factor B, interaction A:B
   modABI - lm(Y ~ idA + idB + idI)   # full model A, B, A:B
 
   # RSS for each regression model from lm()
   rss1   - sum(residuals(mod1)^2)# no effect, i.e., total SS
   rssA   - sum(residuals(modA)^2)# factor A
   rssB   - sum(residuals(modB)^2)# factor B
   rssAB  - sum(residuals(modAB)^2)   # factors A, B
   rssAI  - sum(residuals(modAI)^2)   # factor A, A:B
   rssBI  - sum(residuals(modBI)^2)   # factor B, A:B
   rssABI - sum(residuals(modABI)^2)  # full model A, B, A:B
 
   # degrees of freedom for RSS for each model
   N - length(Y)  # total N
   df1   - N - (0+1)  # no effect:0 predictors + mean
   dfA   - N - (1+1)  # factor A: 1 predictor  + mean
   dfB   - N - (1+1)  # factor B: 1 predictor  + mean
   dfAB  - N - (2+1)  # factors A, B: 2 predictors + mean
   dfAI  - N - (2+1)  # factor A, A:B:2 predictors + mean
   dfBI  - N - (2+1)  # factor B, A:B:2 predictors + mean
   dfABI - N - (3+1)  # full model A, B, A:B: 3 predictors + mean
 
   ---
   # alternatively: get RSS for each model and their df manually
   # based on geometric interpretation
   # design matrix for each model
   one  - rep(1, nrow(X))# column of 1s
   X1   - cbind(one) # no effect
   Xa   - cbind(one, idA)# factor A
   Xb   - cbind(one,  idB)   # factor B
   Xab  - cbind(one, idA, idB)   # factors A, B
   Xai  - cbind(one, idA,  idI)  # factor A, interaction A:B
   Xbi  - cbind(one,  idB, idI)  # factor B, 

[R] Factors attribute?

2010-03-22 Thread rkevinburton
I noticed that when I fit a linear model using 'lm' there is an attribute 
called factors that is added to the term. It doesn't seem to appear for 
'model.matrix', just 'lm'. I have been unable to find where it gets constructed 
or what it means? It looks like a two dimensional array that I may be able to 
use so I would just like to get some 'official' statement regarding what it is 
and how it is constructed. I would rather not go on my assumptions. An example 
would be like:

 l - lm(prestige ~ income + education, data=Duncan)
 attr(l$terms,factors)
  income education
prestige   0 0
income 1 0
education  0 1

Thank you.

Kevin Burton
rkevinbur...@charter.net

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Factors attribute?

2010-03-22 Thread rkevinburton

I am sorry but I didn't see factors mentioned in this documentation.

Kevin

 Henrique Dallazuanna www...@gmail.com wrote: 
 See ?terms
 
 On Mon, Mar 22, 2010 at 2:08 PM,  rkevinbur...@charter.net wrote:
  I noticed that when I fit a linear model using 'lm' there is an attribute 
  called factors that is added to the term. It doesn't seem to appear for 
  'model.matrix', just 'lm'. I have been unable to find where it gets 
  constructed or what it means? It looks like a two dimensional array that I 
  may be able to use so I would just like to get some 'official' statement 
  regarding what it is and how it is constructed. I would rather not go on my 
  assumptions. An example would be like:
 
  l - lm(prestige ~ income + education, data=Duncan)
  attr(l$terms,factors)
           income education
  prestige       0         0
  income         1         0
  education      0         1
 
  Thank you.
 
  Kevin Burton
  rkevinbur...@charter.net
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 
 -- 
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Factors attribute?

2010-03-22 Thread rkevinburton

I am sorry but I didn't see factors mentioned in this documentation.

Kevin

 Henrique Dallazuanna www...@gmail.com wrote: 
 See ?terms
 
 On Mon, Mar 22, 2010 at 2:08 PM,  rkevinbur...@charter.net wrote:
  I noticed that when I fit a linear model using 'lm' there is an attribute 
  called factors that is added to the term. It doesn't seem to appear for 
  'model.matrix', just 'lm'. I have been unable to find where it gets 
  constructed or what it means? It looks like a two dimensional array that I 
  may be able to use so I would just like to get some 'official' statement 
  regarding what it is and how it is constructed. I would rather not go on my 
  assumptions. An example would be like:
 
  l - lm(prestige ~ income + education, data=Duncan)
  attr(l$terms,factors)
           income education
  prestige       0         0
  income         1         0
  education      0         1
 
  Thank you.
 
  Kevin Burton
  rkevinbur...@charter.net
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 
 -- 
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Factors attribute format

2010-03-22 Thread rkevinburton
Thanks to Marc Schultz I found the documentation on the factors attribute 
under ?term.object. It stats:

factors: A matrix of variables by terms showing which variables appear
  in which terms.  The entries are 0 if the variable does not
  occur in the term, 1 if it does occur and should be coded by
  contrasts, and 2 if it occurs and should be coded via dummy
  variables for all levels (as when an intercept or lower-order
  term is missing).  If there are no terms other than an
  intercept and offsets, this is ‘numeric(0)’.

So now this brings up another question. It seems that the attriute is a two 
dimentional array. When I print it out in 'R' 

Fitting the formula prestige ~ income + education I get:

  income education
prestige   0 0
income 1 0
education  0 1

This matrix says to me that 'income' occurs in the term 'income' etc. So it 
seems that this matrix will always be a diagonal matrix with an added row of 
zeros containing the response term. If the formula is such that the response is 
a function of one or more of the dependent variables then of course it will be 
something other that a row of zeros. So far OK?

My problem in understanding comes with using a formula that contains R factors. 
I am using the following (from the TSA package)  for an example:

l - lm(tempdub ~ season(tempdub))
attr(l$terms, factors)

season(tempdub)
tempdub   0
season(tempdub)   1

The function 'season' produces a factor (in this case with 12 levels, one for 
each month). But the factor attribute still has a '1' and not a '2' indicating 
that the variable should be coded as a dummy variable (factor).

Please help my misunderstanding.

Thank you.

Kevin Burton

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Possible error in anova.lm?

2010-03-09 Thread rkevinburton
Perhaps those more in the know than I could clarify some confusion. In the 
ANOVA 'R' code I see:

mss - sum(if (is.null(w)) object$fitted.values^2 else w * 
object$fitted.values^2)
if (ssr  1e-10 * mss) 
warning(ANOVA F-tests on an essentially perfect fit are unreliable)

But in the summary.lm I see:

mss - if (attr(z$terms, intercept)) 
sum((f - mean(f))^2)
else sum(f^2)

or

mss - if (attr(z$terms, intercept)) {
m - sum(w * f/sum(w))
sum(w * (f - m)^2)
}

At the very least the ANOVA code seems to be inefficient to calculate mss then 
only use it for a warning. But it seems that it is being calculated 
incorrectly. It is hard to tell since it is only used to issue the warning. But 
it may be that the warning is incorrect in some cases if mss is not calculated 
correctly. Ideas?

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Interpretation of 'swtich'

2010-03-07 Thread rkevinburton
Thatnk you.

The documentation indicates as you indicated that if there is not an exact 
match then the next element is chosen. But it does not indicate the case that 
contains an exact match but there is not value to be returned (=, case). From 
what you indicate this is treated as if it was not a match.

Kevin

 Uwe Ligges lig...@statistik.tu-dortmund.de wrote: 
 
 
 On 06.03.2010 21:49, rkevinbur...@charter.net wrote:
  In browsing the source I see the following construct:
 
   res- switch(type, working = , response = r, deviance = ,
   pearson = if (is.null(object$weights))
   r
   else r * sqrt(object$weights), partial = r)
 
  I understand that 'switch' will execute the code that is matched by its 
  corresponding string value (in this case 'type'). What I don't understand 
  is the empty code. Is this code saying that if the type is deviance then 
  fill the 'res' variable with an empty value? From my naive point of view it 
  seems that 'res' will only get a value(s) if 'type' is 'response', 
  'pearson', or 'partial'. Please help with my understanding.
 
 Please do read the help pages!
 
  From ?switch:
 
 If there is an exact match then that element is evaluated and returned 
 if there is one, otherwise the next element is chosen, [...]
 
 Example:
 
 switch(A, A=1, B=, C=2) # 1
 switch(B, A=1, B=, C=2) # 2
 
 Uwe Ligges
 
 
 
  Kevin Burton
  rkevinbur...@charter.net
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Interpretation of 'swtich'

2010-03-06 Thread rkevinburton
In browsing the source I see the following construct:

res - switch(type, working = , response = r, deviance = , 
pearson = if (is.null(object$weights)) 
r
else r * sqrt(object$weights), partial = r)

I understand that 'switch' will execute the code that is matched by its 
corresponding string value (in this case 'type'). What I don't understand is 
the empty code. Is this code saying that if the type is deviance then fill 
the 'res' variable with an empty value? From my naive point of view it seems 
that 'res' will only get a value(s) if 'type' is 'response', 'pearson', or 
'partial'. Please help with my understanding.

Kevin Burton
rkevinbur...@charter.net

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] What is assign attribute?

2010-03-04 Thread rkevinburton

I am sorry I still don't understand.

In the example you give the 'assign' vecotr is a vector of length 6 and there 
are indeed 6 columns in the data frame. But the formula only has two variables 
namely 'Month' and 'Wind'. Where do the values if the 'assign' vector come 
from? I see '0 1 1 1 1 2'. What is '1' an index to? '2'? Maybe I am get 
confused with what the term 'factors' does to the formula.

Thanks agiain for your help.

Kevin

 Peter Dalgaard p.dalga...@biostat.ku.dk wrote: 
 rkevinbur...@charter.net wrote:
  I am just curious. Every once and a while I see an attribute attached to an 
  object called assign. What meaning does this have? For example:
  
  dist ~ speed, data=cars
  
  forms a matrix like:
  
   num [1:50, 1:2] 1 1 1 1 1 1 1 1 1 1 ...
   - attr(*, dimnames)=List of 2
..$ : chr [1:50] 1 2 3 4 ...
..$ : chr [1:2] (Intercept) speed
   - attr(*, assign)= int [1:2] 0 1
  
  The dimnames attribute is fairly self-explanatory. I just am not sure 
  what the assign attribute means.
 
 It has to do with the mapping between terms of the formula and columns 
 of the design matrix:
 
   str(model.matrix(Ozone~factor(Month)+Wind,data=airquality))
   num [1:116, 1:6] 1 1 1 1 1 1 1 1 1 1 ...
   - attr(*, dimnames)=List of 2
..$ : chr [1:116] 1 2 3 4 ...
..$ : chr [1:6] (Intercept) factor(Month)6 factor(Month)7 
 factor(Month)8 ...
   - attr(*, assign)= int [1:6] 0 1 1 1 1 2
   - attr(*, contrasts)=List of 1
..$ factor(Month): chr contr.treatment
 
 I.e. columns 2:5 belong to the first non-intercept term, factor(Month). 
 (Notice that it is implicitly assumed that you have the corresponding 
 terms() output to hand, likewise for the contrasts attribute.)
 -- 
 O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
   (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
 ~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Newbie help with ANOVA and lm.

2010-02-27 Thread rkevinburton
Would someone be so kind as to explain in English what the ANOVA code 
(anova.lm) is doing? I am having a hard time reconciling what the text books 
have as a brute force regression and the formula algorithm in 'R'. Specifically 
I see:

p - object$rank
if (p  0L) {
p1 - 1L:p
comp - object$effects[p1]
asgn - object$assign[object$qr$pivot][p1]
nmeffects - c((Intercept), attr(object$terms, term.labels))
tlabels - nmeffects[1 + unique(asgn)]
ss - c(unlist(lapply(split(comp^2, asgn), sum)), ssr)
df - c(unlist(lapply(split(asgn, asgn), length)), dfr)
}
else {
ss - ssr
df - dfr
tlabels - character(0L)
}
ms - ss/df
f - ms/(ssr/dfr)
P - pf(f, df, dfr, lower.tail = FALSE)
 

I think I understand the check for 'p' being non-zero. 'p' is essentially the 
number of terms in the model matrix (including the intercept term if it 
exists). So in a mathematical description of a regression that included the 
intercept and one term (like dist ~ speed) you would have a model matrix of a 
column of '1's and then a column of data. The 'assign' would be a vector 
containing [0,1]. So then in finding the degrees of freedom you split the 
asssign matrix with itself. I am having a hard time seeing that this ever 
produces degrees of freedom that are different. So I get that the vector 'df' 
would always be something like [2,2,dfr]. But that is obviously wrong. Would 
someone care to elighten me on what the code above is doing?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] What is assign attribute?

2010-02-25 Thread rkevinburton

I am just curious. Every once and a while I see an attribute attached to an 
object called assign. What meaning does this have? For example:

dist ~ speed, data=cars

forms a matrix like:

 num [1:50, 1:2] 1 1 1 1 1 1 1 1 1 1 ...
 - attr(*, dimnames)=List of 2
  ..$ : chr [1:50] 1 2 3 4 ...
  ..$ : chr [1:2] (Intercept) speed
 - attr(*, assign)= int [1:2] 0 1

The dimnames attribute is fairly self-explanatory. I just am not sure what 
the assign attribute means.

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] What is assign attribute?

2010-02-25 Thread rkevinburton

I am just curious. Every once and a while I see an attribute attached to an 
object called assign. What meaning does this have? For example:

dist ~ speed, data=cars

forms a matrix like:

 num [1:50, 1:2] 1 1 1 1 1 1 1 1 1 1 ...
 - attr(*, dimnames)=List of 2
  ..$ : chr [1:50] 1 2 3 4 ...
  ..$ : chr [1:2] (Intercept) speed
 - attr(*, assign)= int [1:2] 0 1

The dimnames attribute is fairly self-explanatory. I just am not sure what 
the assign attribute means.

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Help with split.

2010-02-25 Thread rkevinburton
I read in the documentation for split:

‘split’ divides the data in the vector ‘x’ into the groups defined by ‘f’. 

But I am still unclear as to its function. Take for example:

x - 1:4
split(x, c(0,1))
$`0`
[1] 1 3

$`1`
[1] 2 4

I am not clear on how this result is reached.

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Building R from source

2010-02-17 Thread rkevinburton
Thank you for the tip. I was used to inserting write statements and was 
surpised when it didn't work and reading this section I see that I shouldn't 
have been doing this anyway.

One more question. Is there another call that I can use to print out a 
2-dimensional array? Since FORTRAN stores as column major it is hard to print 
out an array by row as 'R' does. Also it doesn't mention how to not specify the 
data to be printed out so that just the label is printed. It (the manual) just 
says it is possible.

Thanks again.

Kevin

 Uwe Ligges lig...@statistik.tu-dortmund.de wrote: 
 Since no more information is given:
 See Writing R Extensions, currently section 6.5: Printing and 6.5.1 
 Printing from FORTRAN
 
 
 Uwe Ligges
 
 
 
 On 17.02.2010 03:50, rkevinbur...@charter.net wrote:
  I found the problem but not a solution. It turns out if I add the following 
  lines to dqrdc2.f I get the error:
 
 write(*,300) ldx,n,p
 300 format(3i4)
 
  I don't get a compile error but I get the seemingly unrelated error in 
  linking R.DLL
  I guess the question now is, How do I add a simple print statement?. Or, 
  what is wrong with the above print statement?
 
  Thank you.
 
  Kevin
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] qr test?

2010-02-17 Thread rkevinburton
I am testing 'qr' with an admittedly contrived matrix and I am getting 
different results than I am from another package. The matrix that I am using is:

x - matrix(seq(.1, by=.1, length.out=12), 4)

So the whole test is:

x - matrix(seq(.1, by=.1, length.out=12), 4)
qr(x)

And the output from 'R' is:

$qr
   [,1]   [,2]  [,3]
[1,] -0.5477226 -1.2780193 -2.008316e+00
[2,]  0.3651484 -0.3265986 -6.531973e-01
[3,]  0.5477226 -0.3781696 -1.650163e-16
[4,]  0.7302967 -0.9124744  8.078153e-01

$rank
[1] 2

$qraux
[1] 1.182574 1.156135 1.589436

$pivot
[1] 1 2 3

attr(,class)
[1] qr


The differences that I see is in the last value of qraux. I was expecting  
1.83205 not 1.589436. Also the last row of the decomposition shows:

[4,]  0.7302967 -0.9124744  8.078153e-01

I was expecting

 0.73030-0.91247-0.55470

So again it is the last element of the array. For the linear algebra gurus out 
there is this to be expected from the contrived matrix? Is there a better 
matrix that I can use to test that will more or less give consistent agreed 
upon results for a QR decomposition?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Problems building from sources

2010-02-16 Thread rkevinburton
I am trying to build R-2.9.2 from source on a Windows 7 machine. I have 
installed all of the requisite software and followed the instructions. I also 
could have sworn that I had a successful build. But now I get the following 
error.

gcc -std=gnu99 -shared -s -mwindows -o R.dll R.def console.o dataentry.o dynload
.o edit.o editor.o embeddedR.o extra.o opt.o pager.o preferences.o psignal.o rho
me.o rt_complete.o rui.o run.o shext.o sys-win32.o system.o dos_wglob.o e_pow.o
malloc.o ../main/libmain.a ../appl/libappl.a ../nmath/libnmath.a getline/gl.a ..
/extra/xdr/libxdr.a ../extra/pcre/libpcre.a ../extra/bzip2/libbz2.a ../extra/int
l/libintl.a ../extra/trio/libtrio.a ../extra/tzone/libtz.a dllversion.o -L. -lgf
ortran -lRblas -L../../bin -lRzlib -lRgraphapp -lRiconv -lcomctl32 -lversion
c:/rtools/mingw/bin/../lib/gcc/mingw32/4.2.1-sjlj/../../../libmingwex.a(mingw_sn
printf.o):mingw_snprintf.c:(.text+0x1970): multiple definition of `snprintf'
../extra/trio/libtrio.a(compat.o):compat.c:(.text+0x30): first defined here
c:/rtools/mingw/bin/../lib/gcc/mingw32/4.2.1-sjlj/../../../libmingwex.a(mingw_sn
printf.o):mingw_snprintf.c:(.text+0x170): multiple definition of `vsnprintf'
../extra/trio/libtrio.a(compat.o):compat.c:(.text+0x20): first defined here
collect2: ld returned 1 exit status
make[3]: *** [R.dll] Error 1
make[2]: *** [../../bin/R.dll] Error 2
make[1]: *** [rbuild] Error 2
make: *** [all] Error 2

It seems like vsnprint and snprintf are multiply defined. Any ideas?

Kevin

 Dimitri Shvorob dimitri.shvo...@gmail.com wrote: 
 
 Now that we have a reproducible example... ;)
 -- 
 View this message in context: 
 http://n4.nabble.com/Problems-with-boxplot-in-ggplot2-qplot-tp1555338p1557994.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Building R from source

2010-02-16 Thread rkevinburton
I found the problem but not a solution. It turns out if I add the following 
lines to dqrdc2.f I get the error:

  write(*,300) ldx,n,p
  300 format(3i4)

I don't get a compile error but I get the seemingly unrelated error in linking 
R.DLL
I guess the question now is, How do I add a simple print statement?. Or, what 
is wrong with the above print statement?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] F77_CALL, F77_NAME definition

2010-01-03 Thread rkevinburton
I give up. Maybe it is my search (Windows) but I cannot seem to find the 
definition of the F77_CALL or F77_NAME macros. Either there are too many 
matches or the search just doesn't find it. For example where is the source for:

F77_CALL(dpotri)

?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] write.csv and header

2009-12-16 Thread rkevinburton
I have a small request regarding this append feature. As it is now if the 
data is appended to the file so is the header. I would like to have the header 
only entered once and appends just append the data.

Doable?

Kevin

 Patrick Connolly p_conno...@slingshot.co.nz wrote: 
 On Tue, 15-Dec-2009 at 01:55PM +0100, Gustaf Rydevik wrote:
 
 
 | Hi,
 | 
 | ?write.table and the argument append should be of help.
 | example:
 | 
 |  sink(test.csv)
 |  cat(-)
 |  cat(\n)
 |  cat(This is \n a test of header)
 |  cat(\n)
 |  cat(-)
 |  cat(\n)
 |  sink()
 | 
 
 Or, instead of the use of sink() and cat(), one could use the write()
 function, also using the append = TRUE argument.
 
 
 | write.table(matrix(rnorm(100),nrow=10),file=test.csv,append=TRUE,sep=,)
 | 
 | 
 | regards,
 | Gustaf
 | 
 | 
 | -- 
 | Gustaf Rydevik, M.Sci.
 | tel: +46(0)703 051 451
 | address:Essingetorget 40,112 66 Stockholm, SE
 | skype:gustaf_rydevik
 | 
 |[[alternative HTML version deleted]]
 | 
 | __
 | R-help@r-project.org mailing list
 | https://stat.ethz.ch/mailman/listinfo/r-help
 | PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 | and provide commented, minimal, self-contained, reproducible code.
 
 -- 
 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
___Patrick Connolly   
  {~._.~}   Great minds discuss ideas
  _( Y )_   Average minds discuss events 
 (:_~*~_:)  Small minds discuss people  
  (_)-(_). Eleanor Roosevelt
 
 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] write.csv and header

2009-12-16 Thread rkevinburton
I have a small request regarding this append feature. As it is now if the 
data is appended to the file so is the header. I would like to have the header 
only entered once and appends just append the data.

Doable?

Kevin

 Patrick Connolly p_conno...@slingshot.co.nz wrote: 
 On Tue, 15-Dec-2009 at 01:55PM +0100, Gustaf Rydevik wrote:
 
 
 | Hi,
 | 
 | ?write.table and the argument append should be of help.
 | example:
 | 
 |  sink(test.csv)
 |  cat(-)
 |  cat(\n)
 |  cat(This is \n a test of header)
 |  cat(\n)
 |  cat(-)
 |  cat(\n)
 |  sink()
 | 
 
 Or, instead of the use of sink() and cat(), one could use the write()
 function, also using the append = TRUE argument.
 
 
 | write.table(matrix(rnorm(100),nrow=10),file=test.csv,append=TRUE,sep=,)
 | 
 | 
 | regards,
 | Gustaf
 | 
 | 
 | -- 
 | Gustaf Rydevik, M.Sci.
 | tel: +46(0)703 051 451
 | address:Essingetorget 40,112 66 Stockholm, SE
 | skype:gustaf_rydevik
 | 
 |[[alternative HTML version deleted]]
 | 
 | __
 | R-help@r-project.org mailing list
 | https://stat.ethz.ch/mailman/listinfo/r-help
 | PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 | and provide commented, minimal, self-contained, reproducible code.
 
 -- 
 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
___Patrick Connolly   
  {~._.~}   Great minds discuss ideas
  _( Y )_   Average minds discuss events 
 (:_~*~_:)  Small minds discuss people  
  (_)-(_). Eleanor Roosevelt
 
 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Normal tests disagree?

2009-12-01 Thread rkevinburton
If I have data that I feed into shapio.test and jarque.bera.test yet they seem 
to disagree. What do I use for a decision?

For my data set I have p.value of 0.05496421 returned from the shapiro.test and 
0.882027 returned from the jarque.bera.test. I have included the data set below.

Thank you.

Kevin


Category,Period,Residual
CHILD HATS, WIGS  MASKS,1/1/2005,-0.449735723758323
CHILD HATS, WIGS  MASKS,2/1/2005,0.281461045050074
CHILD HATS, WIGS  MASKS,3/1/2005,0.591383050911335
CHILD HATS, WIGS  MASKS,4/1/2005,0.239998659520616
CHILD HATS, WIGS  MASKS,5/1/2005,0.00343879474063987
CHILD HATS, WIGS  MASKS,6/1/2005,-2.64372061292663
CHILD HATS, WIGS  MASKS,7/1/2005,0.381630655290173
CHILD HATS, WIGS  MASKS,8/1/2005,-1.79543281552347
CHILD HATS, WIGS  MASKS,9/1/2005,1.90631012440313
CHILD HATS, WIGS  MASKS,10/1/2005,-0.256232543929779
CHILD HATS, WIGS  MASKS,11/1/2005,1.83452602676812
CHILD HATS, WIGS  MASKS,12/1/2005,-1.06869719416837
CHILD HATS, WIGS  MASKS,1/1/2006,1.04378655286183
CHILD HATS, WIGS  MASKS,2/1/2006,0.232655831328322
CHILD HATS, WIGS  MASKS,3/1/2006,-0.939084802643773
CHILD HATS, WIGS  MASKS,4/1/2006,0.854132879285335
CHILD HATS, WIGS  MASKS,5/1/2006,-1.71217066877156
CHILD HATS, WIGS  MASKS,6/1/2006,1.28040273099582
CHILD HATS, WIGS  MASKS,7/1/2006,-0.386415431325857
CHILD HATS, WIGS  MASKS,8/1/2006,-0.769127669783483
CHILD HATS, WIGS  MASKS,9/1/2006,-0.810996835089867
CHILD HATS, WIGS  MASKS,10/1/2006,0.0477292147635991
CHILD HATS, WIGS  MASKS,11/1/2006,0.294672848750557
CHILD HATS, WIGS  MASKS,12/1/2006,-0.0841330473924862
CHILD HATS, WIGS  MASKS,1/1/2007,0.231663729192233
CHILD HATS, WIGS  MASKS,2/1/2007,-0.601790650547443
CHILD HATS, WIGS  MASKS,3/1/2007,0.285635768516625
CHILD HATS, WIGS  MASKS,4/1/2007,-0.963154959558619
CHILD HATS, WIGS  MASKS,5/1/2007,1.52188112949994
CHILD HATS, WIGS  MASKS,6/1/2007,-0.826092842933196
CHILD HATS, WIGS  MASKS,7/1/2007,1.91937201229077
CHILD HATS, WIGS  MASKS,8/1/2007,-0.317789483136924
CHILD HATS, WIGS  MASKS,9/1/2007,-0.865011007394312
CHILD HATS, WIGS  MASKS,10/1/2007,-0.0281604973711276
CHILD HATS, WIGS  MASKS,11/1/2007,-0.123887049811822
CHILD HATS, WIGS  MASKS,12/1/2007,-0.0327727730592468
CHILD HATS, WIGS  MASKS,1/1/2008,-0.0654939600771254
CHILD HATS, WIGS  MASKS,2/1/2008,0.279247739913908
CHILD HATS, WIGS  MASKS,3/1/2008,0.167606602923418
CHILD HATS, WIGS  MASKS,4/1/2008,0.189533097427477
CHILD HATS, WIGS  MASKS,5/1/2008,0.402062194225847
CHILD HATS, WIGS  MASKS,6/1/2008,1.97150984262995
CHILD HATS, WIGS  MASKS,7/1/2008,-2.27538477532968
CHILD HATS, WIGS  MASKS,8/1/2008,1.89091792097945
CHILD HATS, WIGS  MASKS,9/1/2008,0.0251732151287081
CHILD HATS, WIGS  MASKS,10/1/2008,-0.2349741808124
CHILD HATS, WIGS  MASKS,11/1/2008,-0.659332058368173
CHILD HATS, WIGS  MASKS,12/1/2008,0.127284768034285
CHILD HATS, WIGS  MASKS,1/1/2009,-1.42838560676513
CHILD HATS, WIGS  MASKS,2/1/2009,0.617689775286461
CHILD HATS, WIGS  MASKS,3/1/2009,-0.034243005247084
CHILD HATS, WIGS  MASKS,4/1/2009,-0.304574261133836
CHILD HATS, WIGS  MASKS,5/1/2009,0.128679369916751
CHILD HATS, WIGS  MASKS,6/1/2009,-0.657479389968652
CHILD HATS, WIGS  MASKS,7/1/2009,0.608766068692517
CHILD HATS, WIGS  MASKS,8/1/2009,1.92814770869400
CHILD HATS, WIGS  MASKS,9/1/2009,-0.172644961366165
CHILD HATS, WIGS  MASKS,10/1/2009,-0.453255508263169
CHILD HATS, WIGS  MASKS,11/1/2009,-1.09903330959344

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Normal tests disagree?

2009-12-01 Thread rkevinburton
If I have data that I feed into shapio.test and jarque.bera.test yet they seem 
to disagree. What do I use for a decision?

For my data set I have p.value of 0.05496421 returned from the shapiro.test and 
0.882027 returned from the jarque.bera.test. I have included the data set below.

Thank you.

Kevin


Category,Period,Residual
CHILD HATS, WIGS  MASKS,1/1/2005,-0.449735723758323
CHILD HATS, WIGS  MASKS,2/1/2005,0.281461045050074
CHILD HATS, WIGS  MASKS,3/1/2005,0.591383050911335
CHILD HATS, WIGS  MASKS,4/1/2005,0.239998659520616
CHILD HATS, WIGS  MASKS,5/1/2005,0.00343879474063987
CHILD HATS, WIGS  MASKS,6/1/2005,-2.64372061292663
CHILD HATS, WIGS  MASKS,7/1/2005,0.381630655290173
CHILD HATS, WIGS  MASKS,8/1/2005,-1.79543281552347
CHILD HATS, WIGS  MASKS,9/1/2005,1.90631012440313
CHILD HATS, WIGS  MASKS,10/1/2005,-0.256232543929779
CHILD HATS, WIGS  MASKS,11/1/2005,1.83452602676812
CHILD HATS, WIGS  MASKS,12/1/2005,-1.06869719416837
CHILD HATS, WIGS  MASKS,1/1/2006,1.04378655286183
CHILD HATS, WIGS  MASKS,2/1/2006,0.232655831328322
CHILD HATS, WIGS  MASKS,3/1/2006,-0.939084802643773
CHILD HATS, WIGS  MASKS,4/1/2006,0.854132879285335
CHILD HATS, WIGS  MASKS,5/1/2006,-1.71217066877156
CHILD HATS, WIGS  MASKS,6/1/2006,1.28040273099582
CHILD HATS, WIGS  MASKS,7/1/2006,-0.386415431325857
CHILD HATS, WIGS  MASKS,8/1/2006,-0.769127669783483
CHILD HATS, WIGS  MASKS,9/1/2006,-0.810996835089867
CHILD HATS, WIGS  MASKS,10/1/2006,0.0477292147635991
CHILD HATS, WIGS  MASKS,11/1/2006,0.294672848750557
CHILD HATS, WIGS  MASKS,12/1/2006,-0.0841330473924862
CHILD HATS, WIGS  MASKS,1/1/2007,0.231663729192233
CHILD HATS, WIGS  MASKS,2/1/2007,-0.601790650547443
CHILD HATS, WIGS  MASKS,3/1/2007,0.285635768516625
CHILD HATS, WIGS  MASKS,4/1/2007,-0.963154959558619
CHILD HATS, WIGS  MASKS,5/1/2007,1.52188112949994
CHILD HATS, WIGS  MASKS,6/1/2007,-0.826092842933196
CHILD HATS, WIGS  MASKS,7/1/2007,1.91937201229077
CHILD HATS, WIGS  MASKS,8/1/2007,-0.317789483136924
CHILD HATS, WIGS  MASKS,9/1/2007,-0.865011007394312
CHILD HATS, WIGS  MASKS,10/1/2007,-0.0281604973711276
CHILD HATS, WIGS  MASKS,11/1/2007,-0.123887049811822
CHILD HATS, WIGS  MASKS,12/1/2007,-0.0327727730592468
CHILD HATS, WIGS  MASKS,1/1/2008,-0.0654939600771254
CHILD HATS, WIGS  MASKS,2/1/2008,0.279247739913908
CHILD HATS, WIGS  MASKS,3/1/2008,0.167606602923418
CHILD HATS, WIGS  MASKS,4/1/2008,0.189533097427477
CHILD HATS, WIGS  MASKS,5/1/2008,0.402062194225847
CHILD HATS, WIGS  MASKS,6/1/2008,1.97150984262995
CHILD HATS, WIGS  MASKS,7/1/2008,-2.27538477532968
CHILD HATS, WIGS  MASKS,8/1/2008,1.89091792097945
CHILD HATS, WIGS  MASKS,9/1/2008,0.0251732151287081
CHILD HATS, WIGS  MASKS,10/1/2008,-0.2349741808124
CHILD HATS, WIGS  MASKS,11/1/2008,-0.659332058368173
CHILD HATS, WIGS  MASKS,12/1/2008,0.127284768034285
CHILD HATS, WIGS  MASKS,1/1/2009,-1.42838560676513
CHILD HATS, WIGS  MASKS,2/1/2009,0.617689775286461
CHILD HATS, WIGS  MASKS,3/1/2009,-0.034243005247084
CHILD HATS, WIGS  MASKS,4/1/2009,-0.304574261133836
CHILD HATS, WIGS  MASKS,5/1/2009,0.128679369916751
CHILD HATS, WIGS  MASKS,6/1/2009,-0.657479389968652
CHILD HATS, WIGS  MASKS,7/1/2009,0.608766068692517
CHILD HATS, WIGS  MASKS,8/1/2009,1.92814770869400
CHILD HATS, WIGS  MASKS,9/1/2009,-0.172644961366165
CHILD HATS, WIGS  MASKS,10/1/2009,-0.453255508263169
CHILD HATS, WIGS  MASKS,11/1/2009,-1.09903330959344

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] loess smoothing

2009-11-19 Thread rkevinburton
Hello,

In reading the loess description I see:

 span: the parameter alpha which controls the degree of smoothing.

The default seems to be 0.75. Would it be possible to expand on this decription 
so I can avoid trail and error? Can I increase this pass 'span'  1? 
Qualitatively to what degree changing this value affects the smoothing of the 
data?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] uniroot vs.optimize

2009-11-19 Thread rkevinburton
I looked at the descriptions for uniroot and optimize and they are somewhat 
different but the book reference is the same and I am wondering if there are 
reasons to pick one over the other?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Normal distribution test

2009-11-17 Thread rkevinburton
This is probably an even more basic question but shapiro.test return both the 
statistic (w) and the significance (pw) of the statistic. For this test the 
null-hypothesis is that the distirbution is not normal so very small values of 
pw would mean that there is very little chance that the distiribution is not 
normal. Correct?

Thank you.

Kevin

 Johannes Graumann johannes_graum...@web.de wrote: 
 Markus Mehrwald wrote:
 
  Hi all,
  
  I am completely new to R and my knowledge of statistics is quite small
  so I hope you can help my.
  I have three dimensional point data which represents (and this is what I
  do not know for sure) a normal distribution. Now I want to test if this
  is true or not and as I can remember from statistics lessons I can use
  Chi-Square test for distribution test. BUT: I have realy no idea how to
  do this with R and additionally if my assumptions are correct and if
  this is possible with R at all.
  
  Thank you very much in advance for any answer.
  Markus
 
 See
 ?shapiro.test
 or
 ?ks.test
 
 HTH, Joh
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Relase positive with log and zero of negative with 0

2009-11-15 Thread rkevinburton
This is a very simple question but I couldn't form a site search quesry that 
would return a reasonable result set.

Say I have a vector:

x - c(0,2,3,4,5,-1,-2)

I want to replace all of the values in 'x' with the log of x. Naturally this 
runs into problems since some of the values are negative or zero. So how can I 
replace all of the positive elements of x with the log(x) and the rest with 
zero?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Building from source under Windows 7

2009-11-04 Thread rkevinburton
I have downloaded all of the tools and read the readme's that I know about but 
I am still getting the following error when I try to build from source:

C:\Program Files (x86)\R\R-2.9.2\src\gnuwin32make all recommended
make[1]: `Rpwd.exe' is up to date.
cp -p etc/Makeconf etc/Rcmd_environ etc/Rconsole etc/Rdevga etc/Rprofile.site et
c/rgb.txt ../../../etc
cp: preserving permissions for `../../../etc/Makeconf': Permission denied
cp: preserving permissions for `../../../etc/Rcmd_environ': Permission denied
cp: preserving permissions for `../../../etc/Rconsole': Permission denied
cp: preserving permissions for `../../../etc/Rdevga': Permission denied
cp: preserving permissions for `../../../etc/Rprofile.site': Permission denied
cp: preserving permissions for `../../../etc/rgb.txt': Permission denied
make[3]: *** [fixetc] Error 1
make[2]: *** [fixfiles] Error 2
make[1]: *** [rbuild] Error 2
make: *** [all] Error 2

C:\Program Files (x86)\R\R-2.9.2\src\gnuwin32

I have given myself full control on all of the directories and files yet I am 
unable to get rid of this 'Permission denied' error. Anybody out there that has 
similar problem building 2.9.2 under Windows 7 x64?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Formula with in memory data.frame

2009-10-30 Thread rkevinburton
I have an array of data.frame(s) that I would like to smooth with loess one at 
a time. the array is master and the two variable that I am interested in is 
Period and Quantity. So my first attempt at calling loess is:

loess(Quantity ~ Period, master[[i]])

But I get the following error:

Error: NA/NaN/Inf in foreign function call (arg 2)
In addition: Warning message:
NAs introduced by coercion 

I did a str on the array element str(master[[j]]):

'data.frame':   58 obs. of  3 variables:
 Factor w/ 41 levels 10\ Plates,..: 1 1 1 1 1 1 1 1 1 1 ...
 $ Period  : POSIXct, format: 0001-01-20 0002-01-20 ...
 $ Quantity: int  0 0 0 0 0 0 0 0 0 0 ...

So am I doing something wrong?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Non-normal residuals.

2009-10-27 Thread rkevinburton
Hello,

I asked a question about what the most likely process to follow if after a 
time-series fit is performed the residuals are found to be non-normal. One 
peron responded and offered to help if I supplied a sample data set. 
Unfortunately now that I have a sample I have lost the emai addressl. If you 
are that person or have some ideas please email me back at 
rkevinbur...@charter.net.

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Year and Month extraction from Date object.

2009-10-27 Thread rkevinburton
Hello,

I have seen much discussion on Date. But I can't seem to do this simple 
operation. I can convert a string to a date:

d - as.Date(DATE, format=%m/%d/%Y)

But what I want to do is extract the year and month so I can construct an 
element in a ts object. Ideally I would like to see d$year but that doesn't 
seem to be available. Once I have a Date object how can I get an integer year?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] PDF Corrupted?

2009-10-27 Thread rkevinburton
I am running R 2.9.2 and creating a PDF that I am trying to open with Adobe 
Reader 9.2 but when I try to open it the reader responds with 

There was an error opening this document. The file is damaged and cannot be 
repaired.:

I am using the R command(s):

pdf(file=cat.pdf, title=Historical Sales By Category)
for(j in 1:length(master))
{
d - as.Date(master[[j]]$Period[1], format=%m/%d/%Y)
fit - ets(ts(master[[j]]$Quantity, start=c(1900 + as.POSIXlt(d)$year, 1 + 
as.POSIXlt(d)$mon), frequency=12))
plot(fit, col.axis = sky blue, col.lab = thistle)
title(master[[j]]$Category,
  cex.main = 2,   font.main= 4, col.main= blue)
}

Any idea what I am doing wrong?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Time forecasting next step.

2009-10-19 Thread rkevinburton
This is kind of a general question about methodology more than anything. But I 
was looking for fome advice. I have fit a time-series model and feel pretty 
confident that I have taken this model (exponential smoothing) as far as it 
will go. In other words looking at the data and the fitted curves I think it is 
as close as I can get. But when I plot the residuals and form a qqplot it seems 
that the residuals are not normal. From the QQ-plot there is some factor that 
is influencing the series that cannot be attributed to noramal random 
fluxuation. I can run 'tsdiag' to determine basically whether the residuals are 
normall and random, but what if they are not? What would be the next set of 'R' 
commands that I might run to find this influence?

Any suggestions?

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Tinn-R setup

2009-09-07 Thread rkevinburton
I recently installed R 2.9.2 on a new Windows platform. Everything seemed to 
installed OK. I then downloaded the latest Tinn-R (2.3.2.3 I think) and as I 
have always done I selected R - Configure - Permanent. I was greeted with a 
dialog box asking me for a mirror site. I don't remember this prompt before but 
I decided to play along and I select a mrror site. Then the process takes off 
installing what appears to be every package that has ever been conceived for R 
(translate - alot of packages). Is this normal? I repeated this about three 
times because at the end it gave me an error indicating sus-and-such library 
was not found. Each time it was a different library that couldn't be found. 
Finally on the third try it seemed to complete without error. Again I have 
never had to go through so many steps to get Tinn-R installed and configured. 
Did I do something wrong? Is there a bug in this package or a problem with the 
integration between R 2.9.2 and Tin-R 2.3.2.3?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Tinn-R setup

2009-09-07 Thread rkevinburton
I recently installed R 2.9.2 on a new Windows platform. Everything seemed to 
installed OK. I then downloaded the latest Tinn-R (2.3.2.3 I think) and as I 
have always done I selected R - Configure - Permanent. I was greeted with a 
dialog box asking me for a mirror site. I don't remember this prompt before but 
I decided to play along and I select a mrror site. Then the process takes off 
installing what appears to be every package that has ever been conceived for R 
(translate - alot of packages). Is this normal? I repeated this about three 
times because at the end it gave me an error indicating sus-and-such library 
was not found. Each time it was a different library that couldn't be found. 
Finally on the third try it seemed to complete without error. Again I have 
never had to go through so many steps to get Tinn-R installed and configured. 
Did I do something wrong? Is there a bug in this package or a problem with the 
integration between R 2.9.2 and Tin-R 2.3.2.3?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Help with residuals function.

2009-08-21 Thread rkevinburton
I have a misunderstanding on the residuals function in 'R'. In the stats 
package the residuals for the output of a HoltWinters fit is 
residuals.HoltWinters and the source looks like:

 stats:::residuals.HoltWinters
function (object, ...) 
object$x - object$fitted[, 1]
environment: namespace:stats
 

If I execute the following code (I only include the forecast package for the 
data set):

library(forecast)
library(expsmooth)
library(fma)
f - HoltWinters(wineind)

This results in a HoltWinters fit to the data in the variable 'f'. If I look at 
the first few data points:

 f$x[1:10]
 [1] 15136 16733 20016 17708 18019 19227 22893 23739 21133 22591

And at the fitted values:

 f$fitted[1:10,1]
 [1] 14043.33 16849.90 18885.04 20474.27 18836.84 21665.11 24118.32 25198.27
 [9] 22901.40 24450.89

Then at the residuals:

 residuals(f)[1:10]
 [1]   984.6741  1127.0982  1122.9566   879.7321   661.1564   459.8873
 [7]  1698.6798  3580.7276 -1941.4028 -2196.8865

Take the first element. It is clearly not simply f$x[1] - f$fitted[1,1] (which 
is 1092.674 not 984.6741). So my question is, What is actually being 
subtracted to get the residuals?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] predict.HoltWinters source misunderstanding.

2009-08-20 Thread rkevinburton
If I look in the stats package for the 'R' source code for predict.HoltWinters 
I see the following lines:

vars - function(h) {
psi - function(j) object$alpha * (1 + j * object$beta) + 
(j%%f == 0) * object$gamma * (1 - object$alpha)
var(residuals(object)) * if (object$seasonal == additive) 
sum(1, (h  1) * sapply(1L:(h - 1), function(j) crossprod(psi(j

There is more source code but my question is on the call to crossprod(psi(j)). 
Looking at the psi function I could see no elements that are vectors (or 
matrices) or that result in such. In fact if I replace the call to crossprod 
with:

sum(1, (h  1) * sapply(1L:(h - 1), function(j) {
  r - psi(j)
  r*r
} ))

I get the same results. If I further augment my test by printing out the length 
of the return value from 'psi' I can see no case where 'psi' would return 
anything but a single number. So my question is, why the call to crossprod when 
simply squaring the number will do. Am I missing a case when the members of the 
HoltWinters fit would be vectors and then crossprod would be appropriate or is 
this just an oversight?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Building 'R' from source for Windows.

2009-08-15 Thread rkevinburton
Thank you for looking into this. It turns out the problem was You are 
misinterpreting R_HOME.  . .  I thought R_HOME was were I installed R not the 
directory where I was trying to compile the source. Once I moved the extra 
stuff that RTools.exe installed in what I thought was the R installation 
directory to where I was trying to cimpile the R source it became apparent what 
I had done wrong. Thanks again.

But unfortunately this brings up two more questions. One the function or 
project that I would like to start debugging is in appl (I would like to step 
into the L-LBFGSB lbfgsb.c code). The documentation that was with the RTools 
code mentioned that if I built a package like 'make DEBUG=T package' it would 
insert -gdwarf-2 in the compiler swtiches and that would allow be to set a 
breakpoint. Well I am not sure if the fact that this is not a package if that 
is why it didn't work but if I go to the appl directory and enter 'make 
DEBUG=T', I don't see gcc called with -gdwarf-2. If I go to the gnuwin32 
directory and try to build all of 'R' like 'make DEBUG=T all recommended' I see 
the -gdwarf=2 flag added to compilation of each file. But I would rather not 
add debugging information to all the source in R. Any suggestions?

The second question is kind of like 'Where do I go from here?'. From the 
instructions I get that I probably need to use 'Inno' to build an installation. 
Hopefully once the first problem is solved this installation will have 
debugging symbols where I need them. If I run the resultant self-extracting 
installer will that just overwrite my R installation and now I debug with that?

Again, thanks for the additional tips. It has been a long time since I last 
debugged with anything other than Windows Visual Studio and this will take some 
getting used to.

Kevin

 Peter Dalgaard p.dalga...@biostat.ku.dk wrote: 
 rkevinbur...@charter.net wrote:
  I know I am going to catch alot of comments for this question but I am 
  really stuck. If there is some written documentation that I have missed 
  please redirect me.
  
  I want to build 'R' from source on a Windows Platform. The main reasons are 
  that I want to check out a debugging some existing packages so I need to 
  build with debug symbols and I want to check out a 64-bit version of 'R'. 
  So I read the instuructions and downloaded and installed 'rtools' and 
  extracted the source. Then I ran into this statement in R-admin.pdf:
  
  Open a command window at ‘R_HOME/src/gnuwin32’. Edit ‘MkRules’ to set the 
  appropriate paths as needed and to set the type(s) of help that you want 
  built. Beware: ‘MkRules’ contains tabs and some editors (e.g., WinEdt) 
  silently remove them. Then run make all recommended and sit back and wait 
  while the basic compile takes place.
  
  But when I go to this directory I don't see MkRules. In fact I don't see 
  any files, just folders (bitmap and unicode). Are the instructions wrong ? 
  Have I missed a step? Or is there somewhere I can retrieve the missing file 
  (MkRules)?
  
  Thank you. 
  
  Kevin
 
 It should be there. Three possibilities:
 
 - Your editor is not showing it because of extension issues (look for 
 All files)
 
 - You are misinterpreting R_HOME as something other than the source 
 directory. (Could this be a typo? R_HOME is usually the destination dir, 
 but source is what makes sense here. Or are the instructions assuming 
 builddir=srcdir=destdir?)
 
 - You unpacked it incorrectly or got the wrong source file. I checked 
 http://cran.r-project.org/src/base/R-2/R-2.9.1.tar.gz and it does have 
 the file in the right place.
 
 
 -- 
 O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
   (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
 ~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Building 'R' from source for Windows.

2009-08-14 Thread rkevinburton
I know I am going to catch alot of comments for this question but I am really 
stuck. If there is some written documentation that I have missed please 
redirect me.

I want to build 'R' from source on a Windows Platform. The main reasons are 
that I want to check out a debugging some existing packages so I need to build 
with debug symbols and I want to check out a 64-bit version of 'R'. So I read 
the instuructions and downloaded and installed 'rtools' and extracted the 
source. Then I ran into this statement in R-admin.pdf:

Open a command window at ‘R_HOME/src/gnuwin32’. Edit ‘MkRules’ to set the 
appropriate paths as needed and to set the type(s) of help that you want 
built. Beware: ‘MkRules’ contains tabs and some editors (e.g., WinEdt) 
silently remove them. Then run make all recommended and sit back and wait 
while the basic compile takes place.

But when I go to this directory I don't see MkRules. In fact I don't see any 
files, just folders (bitmap and unicode). Are the instructions wrong ? Have I 
missed a step? Or is there somewhere I can retrieve the missing file (MkRules)?

Thank you. 

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Browser and Debug?

2009-08-13 Thread rkevinburton
If I am on Windows and don't have GDB it does'nt look like it is possible. Any 
tips?

Kevin
 roger koenker rkoen...@uiuc.edu wrote: 
 At points of total desperation you can always consider
 the time-honored, avuncular advice  --  RTFM,
 in this case Section 4.4 of Writing R Extensions.
 
 
 url:www.econ.uiuc.edu/~rogerRoger Koenker
 emailrkoen...@uiuc.eduDepartment of Economics
 vox: 217-333-4558University of Illinois
 fax:   217-244-6678Urbana, IL 61801
 
 
 
 On Aug 13, 2009, at 10:20 AM, rkevinbur...@charter.net wrote:
 
  This may be asking more than can be reasonably expected. But, any  
  tips on debugging the 'C' and Fortran code without trying to put  
  together all the tools to compile from source?
 
  Kevin
 
   Erik Iverson eiver...@nmdp.org wrote:
  This article might help:
 
  http://www.biostat.jhsph.edu/~rpeng/docs/R-debug-tools.pdf
 
  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org 
  ] On Behalf Of Inchallah Yarab
  Sent: Thursday, August 13, 2009 9:40 AM
  To: r-help@r-project.org
  Subject: [R] Browser and Debug?
 
  Hi,
 
  Someone can explain to me how use Browser and Debug ?
  thank you
 
 
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] if confusion

2009-08-03 Thread rkevinburton
Simple question:

Why doesn't the following work? Or what 'R' rule am I missing?

tclass -  Testing 1 2 3
if(tclass == Testing 1 2 3)
{
cat(Testing, tclass, \n)
}
else
{
cat(tclass, \n)
}

I get an error 'else' is unexpected.

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Simple cat statement - output truncated

2009-07-16 Thread rkevinburton
So then I am to assume that the output of 'cat' can be truncated by passing it 
bad arrays. That is the only difference between the reproducible code you 
show and mine. It is just a theory but say that the components array is not 
dimmensioned for 4 elements. It seems a little strange if that is the case that 
a reference error is not thrown and just the output of the cat call is affected.

Kevin

 Duncan Murdoch murd...@stats.uwo.ca wrote: 
 On 7/15/2009 9:53 AM, rkevinbur...@charter.net wrote:
  I have a statement:
  
  cat(myforecast ETS(, paste(object$components[1], 
  object$components[2], object$components[3], object$components[4], sep = 
  ,), ) , n, \n)
  
  That generates:
  
  cast ETS( A,N,N,FALSE )  3 
  
  Anyone guess as to why the first 5 letters are truncated/missing?
 
 You are probably being punished for posting non-reproducible code*.
 
 When I try a reproducible version of the line above, things look fine:
 
   cat(myforecast ETS(, paste(A,N,N,FALSE, sep = ,), ) , 3, 
 \n)
 myforecast ETS( A,N,N,FALSE )  3
 
 
 Duncan Murdoch
 
 * R has a new predictive punishment module.  It punishes you for things 
 it knows you will do later.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Simple cat statement - output truncated

2009-07-16 Thread rkevinburton
It has to be related to 'cat' because the output of 'cat' is truncated. I am 
just tyring to find out some possible reasons as to why it is truncated. I have 
been unable to form an array like is in the test program. Do you think there is 
something else that is gobbling up the output from cat that would make it 
appear to be truncated?

Kevin 

 Duncan Murdoch murd...@stats.uwo.ca wrote: 
 On 7/16/2009 10:21 AM, rkevinbur...@charter.net wrote:
  So then I am to assume that the output of 'cat' can be truncated by passing 
  it bad arrays. 
 
 I certainly wouldn't draw that conclusion.  Without a reproducible 
 example, my assumption would be that it is unrelated to cat().
 
 Duncan Murdoch
 
  That is the only difference between the reproducible code you show and 
  mine. It is just a theory but say that the components array is not 
  dimmensioned for 4 elements. It seems a little strange if that is the case 
  that a reference error is not thrown and just the output of the cat call is 
  affected.
  
  Kevin
  
   Duncan Murdoch murd...@stats.uwo.ca wrote: 
  On 7/15/2009 9:53 AM, rkevinbur...@charter.net wrote:
   I have a statement:
   
   cat(myforecast ETS(, paste(object$components[1], 
   object$components[2], object$components[3], object$components[4], sep = 
   ,), ) , n, \n)
   
   That generates:
   
   cast ETS( A,N,N,FALSE )  3 
   
   Anyone guess as to why the first 5 letters are truncated/missing?
  
  You are probably being punished for posting non-reproducible code*.
  
  When I try a reproducible version of the line above, things look fine:
  
cat(myforecast ETS(, paste(A,N,N,FALSE, sep = ,), ) , 3, 
  \n)
  myforecast ETS( A,N,N,FALSE )  3
  
  
  Duncan Murdoch
  
  * R has a new predictive punishment module.  It punishes you for things 
  it knows you will do later.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Simple cat statement - output truncated

2009-07-15 Thread rkevinburton
I have a statement:

cat(myforecast ETS(, paste(object$components[1], object$components[2], 
object$components[3], object$components[4], sep = ,), ) , n, \n)

That generates:

cast ETS( A,N,N,FALSE )  3 

Anyone guess as to why the first 5 letters are truncated/missing?

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Repeated SANN values.

2009-04-07 Thread rkevinburton
I tried optim using the SANN algoithm. To start things out I tried the example 
of solving the traveling salesman problem as given in the documentation. The 
example works just fine. But if I comment out the line:

set.seed(123) # chosen to get a good soln relatively quickly

More often than not it doesn't converge to the optimum solution as shown in the 
example. Alos with trace on it seems that the algoritm is easily fooled by a 
local mimimum as once it gets close to the solution it seems to get stuck and 
repeatedly returns the same value: A sample run:

sann objective function values
initial   value 29625.00
iter 5000 value 13972.00
iter1 value 13501.00
iter15000 value 13501.00
iter2 value 13501.00
iter25000 value 13487.00
iter2 value 13487.00
final value 13487.00
sann stopped after 2 iterations

Not that familiiar with the algoritmn Is that just a drawback of the algorithm 
or can I adjust the anealling temperature (temp) or the maximum temperature 
(tmax) or even the mximum number of iterations to kick it out of what appears 
to be a local minimum? I am willing to sacrifice extra compute time for better 
accuracy.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Need help in calculating studentized residuals/leverage values of non-linear model [nls()]

2009-04-06 Thread rkevinburton
Is the output of residuals() the studentized residuals or just the residuals?

 Dieter Menne dieter.me...@menne-biomed.de wrote: 
 Giam Xingli giam at nus.edu.sg writes:
 
 I hope I can get advice regarding the calculation of leverage values or
 studentized residual values of a non-linear regression model. It seems 
  like
 rstudent() does not work on a nls object.
 
 residuals() should work for nls.
 
 Dieter
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Souce macros help

2009-04-05 Thread rkevinburton

I was trying to understand some of the source in optimi.c and in the SANN 
source I see:

SETCADR(OS-R_gcall, x);
PROTECT_WITH_INDEX(s = eval(OS-R_gcall, OS-R_env), ipx);
REPROTECT(s = coerceVector(s, REALSXP), ipx);
if(LENGTH(s) != n)
error(_(candidate point in optim evaluated to length %d not %d),
  LENGTH(s), n);

I think I need a little help it it is not too much to ask. Admitedly I could 
search for the definition of each of these macros and after some time decipher 
their meaning. But in an effort to save some time I am appealing to this group.

First, 

SETCADR(OS-R_gcall, x);

I was unable to find thie function call in the sources it seems to be called 
everywhere so searches turn up many hits.

Second,

PROTECT_WITH_INDEX(s = eval(OS-R_gcall, OS-R_env), ipx);

I am assuming that this acutall calls the function pointed to by R_gcall. But, 
I am not sure where ipx fits in and what PROTECT_WITH_INDEX does. I read the 
wirting exstensions documentation and this specific macro is dealt with in 
section 5.9.1 but I still am having a hard time understanding what is 
happening. Perhaps the added call to eval is confiusing me. I am assuing that 
this makes the function call.


Third,

REPROTECT(s = coerceVector(s, REALSXP), ipx);

Again the vector ipx shows up. Would someone please help me to understand what 
this statement is doing?

Thank you for your time and patience.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] embed?

2009-04-03 Thread rkevinburton
I have a question on the function 'embed'. I ran the example

x - 1:10
embed(x, dimension=3)

This gives the output:

 [,1] [,2] [,3]
[1,]321
[2,]432
[3,]543
[4,]654
[5,]765
[6,]876
[7,]987
[8,]   1098

I don't quite understand the output and why it is useful. First, there are only 
8 rows down from 10 and the first element starts with 3. Of course I can think 
of explanations as to what is occuring but I cannot see how this is useful. I 
am sure it has application as i see this command used in much of the source but 
I just cannot see it now.

The documentation states:

Each row of the resulting matrix consists of sequences x[t], x[t-1], ..., 
x[t-dimension+1], where t is the original index of x. If x is a matrix, i.e., x 
contains more than one variable, then x[t] consists of the tth observation on 
each variable. 

This explanation doesn't seem to account for the dimension argument.

Thank you for your comments.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Constrined dependent optimization.

2009-04-03 Thread rkevinburton
I have decided to use this SANN approach to my problem but to keep the run time 
reasonable instead of 20,000 variables I will randomly sample this space to get 
the number of variables under 100. But I want to do this a number of times. Is 
there someone who could help me set up WINBUGS to repeat this optimization N 
times each time randomly picking 100 of the possible 20,000.

Comments?

Kevin

 Paul Smith phh...@gmail.com wrote: 
 Apparently, the convergence is faster if one uses this new swap function:
 
 swapfun - function(x,N=100) {
  loc - c(sample(1:(N/2),size=1,replace=FALSE),sample((N/2):100,1))
  tmp - x[loc[1]]
  x[loc[1]] - x[loc[2]]
  x[loc[2]] - tmp
  x
 }
 
 It seems that within 20 millions of iterations, one gets the exact
 optimal solution, which does not take too long.
 
 Paul
 
 
 On Mon, Mar 30, 2009 at 5:11 PM, Paul Smith phh...@gmail.com wrote:
  Optim with SANN also solves your example:
 
  ---
 
  f - function(x) sum(c(1:50,50:1)*x)
 
  swapfun - function(x,N=100) {
   loc - sample(N,size=2,replace=FALSE)
   tmp - x[loc[1]]
   x[loc[1]] - x[loc[2]]
   x[loc[2]] - tmp
   x
  }
 
  N - 100
 
  opt1 - 
  optim(fn=f,par=sample(1:N,N),gr=swapfun,method=SANN,control=list(maxit=5,fnscale=-1,trace=10))
  opt1$par
  opt1$value
 
  ---
 
  We need to specify a large number of iterations to get the optimal
  solution. The objective function at the optimum is 170425, and one
  gets a close value with optim and SANN.
 
  Paul
 
 
  On Mon, Mar 30, 2009 at 2:22 PM, Hans W. Borchers
  hwborch...@googlemail.com wrote:
 
  Image you want to minimize the following linear function
 
     f - function(x) sum( c(1:50, 50:1) * x / (50*51) )
 
  on the set of all permutations of the numbers 1,..., 100.
 
  I wonder how will you do that with lpSolve? I would simply order
  the coefficients and then sort the numbers 1,...,100 accordingly.
 
  I am also wondering how optim with SANN could be applied here.
 
  As this is a problem in the area of discrete optimization resp.
  constraint programming, I propose to use an appropriate program
  here such as the free software Bprolog. I would be interested to
  learn what others propose.
 
  Of course, if we don't know anything about the function f then
  it amounts to an exhaustive search on the 100! permutations --
  probably not a feasible job.
 
  Regards,  Hans Werner
 
 
 
  Paul Smith wrote:
 
  On Sun, Mar 29, 2009 at 9:45 PM,  rkevinbur...@charter.net wrote:
  I have an optimization question that I was hoping to get some suggestions
  on how best to go about sovling it. I would think there is probably a
  package that addresses this problem.
 
  This is an ordering optimzation problem. Best to describe it with a
  simple example. Say I have 100 bins each with a ball in it numbered
  from 1 to 100. Each bin can only hold one ball. This optimization is that
  I have a function 'f' that this array of bins and returns a number. The
  number returned from f(1,2,3,4) would return a different number from
  that of f(2,1,3,4). The optimization is finding the optimum order of
  these balls so as to produce a minimum value from 'f'.I cannot use the
  regular 'optim' algorithms because a) the values are discrete, and b) the
  values are dependent ie. when the variable representing the bin
  location is changed (in this example a new ball is put there) the
  existing ball will need to be moved to another bin (probably swapping
  positions), and c) each variable is constrained, in the example above
  the only allowable values are integers from 1-100. So the problem becomes
  finding the optimum order of the balls.
 
  Any suggestions?
 
  If your function f is linear, then you can use lpSolve.
 
  Paul
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
  --
  View this message in context: 
  http://www.nabble.com/Constrined-dependent-optimization.-tp22772520p22782922.html
  Sent from the R help mailing list archive at Nabble.com.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting 

[R] data.frame to array?

2009-04-03 Thread rkevinburton
I have a list of data.frames

 str(bins)

List of 19217
 $ 100026:'data.frame': 1 obs. of  6 variables:
  ..$ Sku  : chr 100026
  ..$ Bin  : chr T149C
  ..$ Count: int 108
  ..$ X: int 20
  ..$ Y: int 149
  ..$ Z: chr 3
 $ 100030:'data.frame': 1 obs. of  6 variables:
...
As you can see one 'column' is Count. This list seems to contain 19217 
data.frames. I would like to create an array of 19217 integers which hold the 
values of the Count column. I have tried the obvious (to me):

bins[[1:3]]$Count

But that returns NULL instead of an array of length 3 that I was expecting. 
Interestingly bins[[1]]$Count returns the first Count in the list of data 
frames. How do I get all of the Counts?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Constrined dependent optimization.

2009-04-02 Thread rkevinburton
Sorry I sent a description of the function I was trying to minimize but I must 
not have sent it to this group (and you). Hopefully with this clearer 
description of my problem you might have some suggestions. 

It is basically a warehouse placement problem. You have a warehouse that has 
many items each placed in a certain bin (the real warehouse has about 20,000 
of these bins, hence the large number of variables that I want to input to 
optimize). Now assume that an order comes in for three items A, B, and C. In 
the worst case A will be on one end of the warehouse, B in the middle and C on 
the other end of the warehouse. The work involved in getting these items to 
fulfill this order is roughly proportional to the distance from A to B plus the 
distance from B to C (assuming the absolute positions are sorted). So the cost 
for fulfilling this order is this distance. In the ideal world A, B, and C 
would be right next to each other and the cost/distance would be minimized. So 
the function I want to minimize would be placing these 20,000 items in such a 
way so that the minimum work is involved in fulfilling the orders for the 
past month or two. Clearer? 

I can see that I may need to cut back on the variables 20,000 is probably too 
many. Maybe I can take the top 1,000 or so. I just am not sure of the packages 
available what to reasonably expect. I would like this optimization to complete 
in a reasonable amount of time (less than a few days). I have heard that SANN 
is slower than other optimization methods but it does have the feature of 
supplying a gradient as you pointed out. Are there other packages out there 
that might be better suited to such a large scale optimizaiton?

Thanks again.

Kevin
 Paul Smith phh...@gmail.com wrote: 
 As I told you before, without knowing the definition of your function
 f, one cannot help much.
 
 Paul
 
 
 On Wed, Apr 1, 2009 at 3:15 PM,  rkevinbur...@charter.net wrote:
  Thank you I had not considered using gradient in this fashion. Now as an 
  add on question. You (an others) have suggested using SANN. Does your 
  answer change if instead of 100 variables or bins there are 20,000? From 
  the documentation L-BFGS-B is designed for a large number of variables. But 
  maybe SANN can handle this as well.
 
  Kevin
 
   Paul Smith phh...@gmail.com wrote:
  Apparently, the convergence is faster if one uses this new swap function:
 
  swapfun - function(x,N=100) {
   loc - c(sample(1:(N/2),size=1,replace=FALSE),sample((N/2):100,1))
   tmp - x[loc[1]]
   x[loc[1]] - x[loc[2]]
   x[loc[2]] - tmp
   x
  }
 
  It seems that within 20 millions of iterations, one gets the exact
  optimal solution, which does not take too long.
 
  Paul
 
 
  On Mon, Mar 30, 2009 at 5:11 PM, Paul Smith phh...@gmail.com wrote:
   Optim with SANN also solves your example:
  
   ---
  
   f - function(x) sum(c(1:50,50:1)*x)
  
   swapfun - function(x,N=100) {
    loc - sample(N,size=2,replace=FALSE)
    tmp - x[loc[1]]
    x[loc[1]] - x[loc[2]]
    x[loc[2]] - tmp
    x
   }
  
   N - 100
  
   opt1 - 
   optim(fn=f,par=sample(1:N,N),gr=swapfun,method=SANN,control=list(maxit=5,fnscale=-1,trace=10))
   opt1$par
   opt1$value
  
   ---
  
   We need to specify a large number of iterations to get the optimal
   solution. The objective function at the optimum is 170425, and one
   gets a close value with optim and SANN.
  
   Paul
  
  
   On Mon, Mar 30, 2009 at 2:22 PM, Hans W. Borchers
   hwborch...@googlemail.com wrote:
  
   Image you want to minimize the following linear function
  
      f - function(x) sum( c(1:50, 50:1) * x / (50*51) )
  
   on the set of all permutations of the numbers 1,..., 100.
  
   I wonder how will you do that with lpSolve? I would simply order
   the coefficients and then sort the numbers 1,...,100 accordingly.
  
   I am also wondering how optim with SANN could be applied here.
  
   As this is a problem in the area of discrete optimization resp.
   constraint programming, I propose to use an appropriate program
   here such as the free software Bprolog. I would be interested to
   learn what others propose.
  
   Of course, if we don't know anything about the function f then
   it amounts to an exhaustive search on the 100! permutations --
   probably not a feasible job.
  
   Regards,  Hans Werner
  
  
  
   Paul Smith wrote:
  
   On Sun, Mar 29, 2009 at 9:45 PM,  rkevinbur...@charter.net wrote:
   I have an optimization question that I was hoping to get some 
   suggestions
   on how best to go about sovling it. I would think there is probably a
   package that addresses this problem.
  
   This is an ordering optimzation problem. Best to describe it with a
   simple example. Say I have 100 bins each with a ball in it numbered
   from 1 to 100. Each bin can only hold one ball. This optimization is 
   that
   I have a function 'f' that this array of bins and 

Re: [R] Constrined dependent optimization.

2009-04-01 Thread rkevinburton
Thank you I had not considered using gradient in this fashion. Now as an add 
on question. You (an others) have suggested using SANN. Does your answer change 
if instead of 100 variables or bins there are 20,000? From the documentation 
L-BFGS-B is designed for a large number of variables. But maybe SANN can handle 
this as well.

Kevin

 Paul Smith phh...@gmail.com wrote: 
 Apparently, the convergence is faster if one uses this new swap function:
 
 swapfun - function(x,N=100) {
  loc - c(sample(1:(N/2),size=1,replace=FALSE),sample((N/2):100,1))
  tmp - x[loc[1]]
  x[loc[1]] - x[loc[2]]
  x[loc[2]] - tmp
  x
 }
 
 It seems that within 20 millions of iterations, one gets the exact
 optimal solution, which does not take too long.
 
 Paul
 
 
 On Mon, Mar 30, 2009 at 5:11 PM, Paul Smith phh...@gmail.com wrote:
  Optim with SANN also solves your example:
 
  ---
 
  f - function(x) sum(c(1:50,50:1)*x)
 
  swapfun - function(x,N=100) {
   loc - sample(N,size=2,replace=FALSE)
   tmp - x[loc[1]]
   x[loc[1]] - x[loc[2]]
   x[loc[2]] - tmp
   x
  }
 
  N - 100
 
  opt1 - 
  optim(fn=f,par=sample(1:N,N),gr=swapfun,method=SANN,control=list(maxit=5,fnscale=-1,trace=10))
  opt1$par
  opt1$value
 
  ---
 
  We need to specify a large number of iterations to get the optimal
  solution. The objective function at the optimum is 170425, and one
  gets a close value with optim and SANN.
 
  Paul
 
 
  On Mon, Mar 30, 2009 at 2:22 PM, Hans W. Borchers
  hwborch...@googlemail.com wrote:
 
  Image you want to minimize the following linear function
 
     f - function(x) sum( c(1:50, 50:1) * x / (50*51) )
 
  on the set of all permutations of the numbers 1,..., 100.
 
  I wonder how will you do that with lpSolve? I would simply order
  the coefficients and then sort the numbers 1,...,100 accordingly.
 
  I am also wondering how optim with SANN could be applied here.
 
  As this is a problem in the area of discrete optimization resp.
  constraint programming, I propose to use an appropriate program
  here such as the free software Bprolog. I would be interested to
  learn what others propose.
 
  Of course, if we don't know anything about the function f then
  it amounts to an exhaustive search on the 100! permutations --
  probably not a feasible job.
 
  Regards,  Hans Werner
 
 
 
  Paul Smith wrote:
 
  On Sun, Mar 29, 2009 at 9:45 PM,  rkevinbur...@charter.net wrote:
  I have an optimization question that I was hoping to get some suggestions
  on how best to go about sovling it. I would think there is probably a
  package that addresses this problem.
 
  This is an ordering optimzation problem. Best to describe it with a
  simple example. Say I have 100 bins each with a ball in it numbered
  from 1 to 100. Each bin can only hold one ball. This optimization is that
  I have a function 'f' that this array of bins and returns a number. The
  number returned from f(1,2,3,4) would return a different number from
  that of f(2,1,3,4). The optimization is finding the optimum order of
  these balls so as to produce a minimum value from 'f'.I cannot use the
  regular 'optim' algorithms because a) the values are discrete, and b) the
  values are dependent ie. when the variable representing the bin
  location is changed (in this example a new ball is put there) the
  existing ball will need to be moved to another bin (probably swapping
  positions), and c) each variable is constrained, in the example above
  the only allowable values are integers from 1-100. So the problem becomes
  finding the optimum order of the balls.
 
  Any suggestions?
 
  If your function f is linear, then you can use lpSolve.
 
  Paul
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
  --
  View this message in context: 
  http://www.nabble.com/Constrined-dependent-optimization.-tp22772520p22782922.html
  Sent from the R help mailing list archive at Nabble.com.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide 

Re: [R] Constrined dependent optimization.

2009-03-30 Thread rkevinburton
It would in the stictess sense be non-linear since it is only defined for 
descrete interface values for each variable. And in general it would be 
non-linear anyway. If I only have three variables which can take on values 
1,2,3 then f(1,2,3) could equal 0 and f(2,1,3) could equal 10.

Thank you for the suggestions.

Kevin

 Paul Smith phh...@gmail.com wrote: 
 On Sun, Mar 29, 2009 at 9:45 PM,  rkevinbur...@charter.net wrote:
  I have an optimization question that I was hoping to get some suggestions 
  on how best to go about sovling it. I would think there is probably a 
  package that addresses this problem.
 
  This is an ordering optimzation problem. Best to describe it with a simple 
  example. Say I have 100 bins each with a ball in it numbered from 1 to 
  100. Each bin can only hold one ball. This optimization is that I have a 
  function 'f' that this array of bins and returns a number. The number 
  returned from f(1,2,3,4) would return a different number from that of 
  f(2,1,3,4). The optimization is finding the optimum order of these 
  balls so as to produce a minimum value from 'f'.I cannot use the regular 
  'optim' algorithms because a) the values are discrete, and b) the values 
  are dependent ie. when the variable representing the bin location is 
  changed (in this example a new ball is put there) the existing ball will 
  need to be moved to another bin (probably swapping positions), and c) each 
  variable is constrained, in the example above the only allowable values 
  are integers from 1-100. So the problem becomes finding the optimum order 
  of the balls.
 
  Any suggestions?
 
 If your function f is linear, then you can use lpSolve.
 
 Paul
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Constrined dependent optimization.

2009-03-29 Thread rkevinburton
I have an optimization question that I was hoping to get some suggestions on 
how best to go about sovling it. I would think there is probably a package that 
addresses this problem.

This is an ordering optimzation problem. Best to describe it with a simple 
example. Say I have 100 bins each with a ball in it numbered from 1 to 100. 
Each bin can only hold one ball. This optimization is that I have a function 
'f' that this array of bins and returns a number. The number returned from 
f(1,2,3,4) would return a different number from that of f(2,1,3,4). The 
optimization is finding the optimum order of these balls so as to produce a 
minimum value from 'f'.I cannot use the regular 'optim' algorithms because a) 
the values are discrete, and b) the values are dependent ie. when the 
variable representing the bin location is changed (in this example a new ball 
is put there) the existing ball will need to be moved to another bin (probably 
swapping positions), and c) each variable is constrained, in the example 
above the only allowable values are integers from 1-100. So the problem becomes 
finding the optimum order of the balls.

Any suggestions?

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Bug? FORTTRAN help

2009-03-26 Thread rkevinburton
I was feeling masochistic the other day and we have been having some wierd 
memory problems so I started digging into the source for L-BFGS-B. In the 
lbgfsb.c file I see the following code:

/* Cholesky factorization of (2,2) block of wn. */
F77_CALL(dpofa)(wn[*col + 1 + (*col + 1) * wn_dim1], m2, col, info);
if (*info != 0) {
*info = -2;
return;
}

If I am not mistaken this says that there is a m2 * col matrix that starts at 
'col + 1 + (col + 1) * wn_dm1. Where wn_dm1 is 2 * m. My first question is to 
verify that statement. 
Say I am trying to optimize the banana function as given in the 
documentation. In that case n = 2 and the default m = 5. So m2 is 10 and 
wn_dim1 is 20 and the dimension of wn is 100 (this is all by deduction. So if 
col is 5 then the offset into the array is 55 and there is not room in the 
vector for a 10 x 5 array. I am worried that the optimizer will silently write 
info memory that it shouldn't but more than likely it is something that I don't 
understand. So please vefify my first statement.

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] .Internal

2009-03-23 Thread rkevinburton
Sorry to be so dense but the article that you suggest does not give any 
information on how the arguments are packed up. I look at the call:

val - .Internal(fmin(function(arg) -f(arg, ...), lower, upper, tol))

and then with the help of this article I find do_fmin in optimize.c:

SEXP attribute_hidden do_fmin(SEXP call, SEXP op, SEXP args, SEXP rho)

Again there doesn't seem to be any coorespondance between lower, upper, tol and 
the arguments to do_fmin. So I am missing a step.

Thank you.

Kevin


 Berwin A Turlach ber...@maths.uwa.edu.au wrote: 
 G'day Kevin,
 
 On Wed, 18 Mar 2009 21:46:51 -0700
 rkevinbur...@charter.net wrote:
 
  I was trying to find source for optimize and I ran across
  
  function (f, interval, ..., lower = min(interval), upper =
  max(interval), maximum = FALSE, tol = .Machine$double.eps^0.25) 
  {
  if (maximum) {
  val - .Internal(fmin(function(arg) -f(arg, ...), lower, 
  upper, tol))
  list(maximum = val, objective = f(val, ...))
  }
  else {
  val - .Internal(fmin(function(arg) f(arg, ...), lower, 
  upper, tol))
  list(minimum = val, objective = f(val, ...))
  }
  }
  
  Then I did a search for fmin and i came up with:
  
  /* fmin(f, xmin, xmax tol) */
  SEXP attribute_hidden do_fmin(SEXP call, SEXP op, SEXP args, SEXP rho)
  
  
  So my question is where do I find the intermediary step between 
  
  .Internal(fmin(function(arg) f(arg, ...), lower,  upper, tol))
  
  and
  
  SEXP attribute_hidden do_fmin(SEXP call, SEXP op, SEXP args, SEXP rho)
 
 @Article{Rnews:Ligges:2006,
   author   = {Uwe Ligges},
   title= {{R} {H}elp {D}esk: {Accessing} the Sources},
   journal  = {R News},
   year = 2006,
   volume   = 6,
   number   = 4,
   pages= {43--45},
   month= {October},
   url  = http,
   pdf= Rnews2006-4
 }
 
 http://CRAN.R-project.org/doc/Rnews/Rnews_2006-4.pdf
 
  The number of arguments doesn't match up. I am guessing that lower
  and upper somehow get merged into the args. And rho is 'tol'. Right?
 
 Unlikely.  In Writing R Extensions (and the functions I looked up),
 'rho' usually denotes an environment that is used to evaluate
 expressions in.  Typically (i.e. in cases that I had need to look at),
 all arguments are rolled into the SEXP arg for internal functions.
 
 HTH.
 
 Cheers,
 
   Berwin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] variance/mean

2009-03-22 Thread rkevinburton
At the risk of appearing ignorant why is the folowing true?

o - cbind(rep(1,3),rep(2,3),rep(3,3))
var(o)
 [,1] [,2] [,3]
[1,]000
[2,]000
[3,]000

and

mean(o)
[1] 2

How do I get mean to return an array similar to var? I would expect in the 
above example a vector of length 3 {1,2,3}.

Thank you for your help.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] .Internal

2009-03-18 Thread rkevinburton
I was trying to find source for optimize and I ran across

function (f, interval, ..., lower = min(interval), upper = max(interval), 
maximum = FALSE, tol = .Machine$double.eps^0.25) 
{
if (maximum) {
val - .Internal(fmin(function(arg) -f(arg, ...), lower, 
upper, tol))
list(maximum = val, objective = f(val, ...))
}
else {
val - .Internal(fmin(function(arg) f(arg, ...), lower, 
upper, tol))
list(minimum = val, objective = f(val, ...))
}
}

Then I did a search for fmin and i came up with:

/* fmin(f, xmin, xmax tol) */
SEXP attribute_hidden do_fmin(SEXP call, SEXP op, SEXP args, SEXP rho)


So my question is where do I find the intermediary step between 

.Internal(fmin(function(arg) f(arg, ...), lower,  upper, tol))

and

SEXP attribute_hidden do_fmin(SEXP call, SEXP op, SEXP args, SEXP rho)

The number of arguments doesn't match up. I am guessing that lower and upper 
somehow get merged into the args. And rho is 'tol'. Right?

Thank you for your comments.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] sweep?

2009-03-16 Thread rkevinburton
I am having a hard time understanding just what 'sweep' does. The documentation 
states:

Return an array obtained from an input array by sweeping out a summary 
statistic. 

So what does it mean weeping out a summary statistic?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Yet another large file question.

2009-03-15 Thread rkevinburton
I am using the XML package to form a rather large XML file. 

It seems to go OK untill the file length gets larger than about 30Mb then it 
seems that the last tokens of the xml file are unmatched. It is almost like the 
file hasn't been flushed because the file is OK with the exception of the last 
lines. I was wondering two things 1) Has anyone else run into similar 
limitations with saveXML in the XML package and if there is a work-around? 2) 
Am I better off using more pimitive write methods to get the data to a file? If 
so any suggestions?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] updating packages?

2009-03-13 Thread rkevinburton
I am trying to update the packages that I have installed but I get the 
following warning messages:

package 'tseries' successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package 'tseries'
bundle 'forecasting' successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package 'forecast'

What does that mean? How can I update these packages?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Reshape question.

2009-03-11 Thread rkevinburton
This hopefully is trivial. I am trying to reshape the data using the reshape 
package.

First I read in the data:

a2009 - read.csv(Total2009.dat, header = TRUE)

Then I trim it so that it only contains the columns that I have interested in:

m2009 - melt(a2009, id.var=c(DayOfYear,Category,SubCategory,Sku), 
measure.var=c(Quantity), na.rm=TRUE)

Then I start to formulate the data that I will process:

c2009 - cast(m2009, DayOfYear ~ variable | Category, sum)

Finally I aggregate the data:

t2009 - cast(m2009, DayOfYear ~ variable, sum)

My question is on the third step above (repeated here)

c2009 - cast(m2009, DayOfYear ~ variable | Category, sum)

This gets the data assocated with a unique 'Category' name. I want to get the 
data grouped by 'Category' and 'SubCategory'. The 'SubCategory' is not unique 
but the combination 'Category' and 'SubCategory' form a unique pair. What would 
be the formula that would give me the data grouped by Category AND SubCategory? 
Would it be as simple as:

c2009 - cast(m2009, DayOfYear ~ variable | Category  SubCategory, sum)

?

Thank you for your suggestions.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reshape question.

2009-03-11 Thread rkevinburton
Thank you for you reply. I will try this. The inital few rows in the .dat file 
look like:

Year,DayOfYear,Sku,Quantity,CatId,Category,SubCategory
2009,1,100051,1,10113,MEN,Historical men's
2009,1,100130,1,10638,ACCESSORIES  MAKEUP,ALL Kids Accessories
2009,1,100916,1,10222,WOMEN,TV  Movies Women
2009,1,101241,1,10897,HOLIDAY,Colonial (Presidents)
2009,1,101252,1,10640,ACCESSORIES  MAKEUP,Finishing Touches
2009,1,101298,1,10865,HOLIDAY,Easter
2009,1,101613,1,10410,GIRLS,Classic Girls
2009,1,101645,1,10320,BOYS,Superheroes Boys
2009,1,101648,1,10320,BOYS,Superheroes Boys
2009,1,101718,1,10897,HOLIDAY,Colonial (Presidents)
2009,1,101719,1,10897,HOLIDAY,Colonial (Presidents)
2009,1,101751,1,10420,GIRLS,Superheroes Girls
2009,1,102125,1,10638,ACCESSORIES  MAKEUP,ALL Kids Accessories
2009,1,102174,1,10897,HOLIDAY,Colonial (Presidents)
2009,1,102558,1,10636,ACCESSORIES  MAKEUP,Armor/Weapons/Guns
2009,1,102582,1,10636,ACCESSORIES  MAKEUP,Armor/Weapons/Guns
2009,1,102717,1,10862,HOLIDAY,Christmas
2009,1,104705,1,10518,PLUS,Plus Women
2009,1,104745,6,10748,HATS, WIGS  MASKS,Wigs - Men's
2009,1,104745,1,10748,HATS, WIGS  MASKS,Wigs - Men's
2009,1,104751,1,10310,BOYS,Classic Boys
2009,1,105238,1,10742,HATS, WIGS  MASKS,Hats-Miscellaneous
2009,1,105352,10,10742,HATS, WIGS  MASKS,Hats-Miscellaneous
2009,1,107420,10,10744,HATS, WIGS  MASKS,Masks - Miscellaneous
2009,1,107420,1,10744,HATS, WIGS  MASKS,Masks - Miscellaneous
2009,1,107479,1,10743,HATS, WIGS  MASKS,Masks - Famous
2009,1,107479,1,10743,HATS, WIGS  MASKS,Masks - Famous

If your propose solution works I am confused as to why during the original I 
was able to specify:

c2009 - cast(m2009, DayOfYear ~ variable | Category, sum)
t2009 - cast(m2009, DayOfYear ~ variable, sum)

By combining this into one 'cast' is it better (as in faster)?

Thanks again.

Kevin

 Tal Galili tal.gal...@gmail.com wrote: 
 how about:
 c2009 - cast(m2009, Category + SubCategory +DayOfYear ~ variable , sum)
 ?
 
 
 p.s: toy data would be nice to have :)
 
 
 
 
 
 
 On Wed, Mar 11, 2009 at 9:47 PM, rkevinbur...@charter.net wrote:
 
  This hopefully is trivial. I am trying to reshape the data using the
  reshape package.
 
  First I read in the data:
 
  a2009 - read.csv(Total2009.dat, header = TRUE)
 
  Then I trim it so that it only contains the columns that I have interested
  in:
 
  m2009 - melt(a2009, id.var=c(DayOfYear,Category,SubCategory,Sku),
  measure.var=c(Quantity), na.rm=TRUE)
 
  Then I start to formulate the data that I will process:
 
  c2009 - cast(m2009, DayOfYear ~ variable | Category, sum)
 
  Finally I aggregate the data:
 
  t2009 - cast(m2009, DayOfYear ~ variable, sum)
 
  My question is on the third step above (repeated here)
 
  c2009 - cast(m2009, DayOfYear ~ variable | Category, sum)
 
  This gets the data assocated with a unique 'Category' name. I want to get
  the data grouped by 'Category' and 'SubCategory'. The 'SubCategory' is not
  unique but the combination 'Category' and 'SubCategory' form a unique pair.
  What would be the formula that would give me the data grouped by Category
  AND SubCategory? Would it be as simple as:
 
  c2009 - cast(m2009, DayOfYear ~ variable | Category  SubCategory, sum)
 
  ?
 
  Thank you for your suggestions.
 
  Kevin
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 
 -- 
 --
 
 
 My contact information:
 Tal Galili
 Phone number: 972-50-3373767
 FaceBook: Tal Galili
 My Blogs:
 www.talgalili.com
 www.biostatistics.co.il

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] hatvalues?

2009-03-05 Thread rkevinburton
I am struiggling a bit with this function 'hatvalues'.  I would like a little 
more undrestanding than taking the black-box and using the values. I looked at 
the Fortran source and it is quite opaque to me. So I am asking for some help 
in understanding the theory. First, I take the simplest case of a single 
variant. For this I turn o John Fox's book, Applied Regression Analysis and 
Generalized Linear Models, p 245 and generate this 'R' code:

 library(car)
 attach(Davis)
# remove the NA's
 narepwt - repwt[!is.na(repwt)]
 meanrw - mean(narepwt)
 drw - narepwt - meanrw
 ssrw - sum(drw * drw)
 h - 1/length(narepwt) + (drw * drw)/ssrw
 h

This gives me a array of values the largest of which is

 order(h, decreasing=TRUE)
  [1]  21  52  17  93  30  62 158 113 175 131 182  29 106 125 123 146  91  99

So the largest hatvalue is 

 h[21]
[1] 0.1041207

Which doesn't match the 0.714 value that is reported in the book but I will 
probably take that up with the author later.

Then I use more of 'R' and I get

fit - lm(weight ~ repwt)
hr - hatvalues(fit)
hr[21]
   21 
0.1041207 

So this matches which is reasusing. My question is this, given the QR 
transformation and the residuals derived from that transformation what is a 
simple matrix formula for the hatvalues?

From http://en.wikipedia.org/wiki/Linear_regression I get

residuals = y - Hy = y(I - H)
or
H = -(residuals/y - I)

 fit - lm(weight ~ repwt)
 h - -(residuals(fit)/weight[as.numeric(names(residuals(fit)))] - 
 diag(1,length(residuals(fit)), length(residuals(fit

This generates a matrix but I cannot see any coerrelation between this 
hat-matrix and the return from hatvalues.

Comments?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] RES: object .trPaths not found

2009-03-02 Thread rkevinburton
Yes. But I found out I the files permissions were set so that the configuration 
had a null effect and the configuration silently ignored the fact that the file 
could not be written to.

Thank you.

Kevin

 Leandro Marino lean...@cesgranrio.org.br wrote: 
 Did you do the configuration of Tinn-R after the installation?
 
 Atenciosamente,
 Leandro Lins Marino
 Centro de Avaliação
 Fundação CESGRANRIO
 Rua Santa Alexandrina, 1011 - 2º andar
 Rio de Janeiro, RJ - CEP: 20261-903
 R (21) 2103-9600 R.:236 
 ( (21) 8777-7907
 ( lean...@cesgranrio.org.br
 
 Aquele que suporta o peso da sociedade
 é precisamente aquele que obtém
  as menores vantagens. (SMITH, Adam)
 
   Antes de imprimir pense em sua responsabilidade e compromisso com o MEIO 
 AMBIENTE 
 
 -Mensagem original-
 De: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Em 
 nome de Uwe Ligges
 Enviada em: sábado, 28 de fevereiro de 2009 16:34
 Para: rkevinbur...@charter.net
 Cc: R help
 Assunto: Re: [R] object .trPaths not found
 
 
 
 rkevinbur...@charter.net wrote:
  I am running an R script with Tinn-R (2.2.0.1) and I get the error message
  
  Error in source(.trPaths[4], echo = TRUE, max.deparse.length = 150) : 
object .trPaths not found
  
  Any solutions?
 
 
 Maybe, but the may depend on your script, your OS, your R version, 
 used packages and so on.
 
 Hence please read and follow the posting guide and provide commented, 
 minimal, self-contained, reproducible code.
 
 Uwe Ligges
 
 
 
 
  Thank you.
  
  Kevin
  
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] RES: object .trPaths not found

2009-03-02 Thread rkevinburton
Yes. But I found out I the files permissions were set so that the configuration 
had a null effect and the configuration silently ignored the fact that the file 
could not be written to.

Thank you.

Kevin

 Leandro Marino lean...@cesgranrio.org.br wrote: 
 Did you do the configuration of Tinn-R after the installation?
 
 Atenciosamente,
 Leandro Lins Marino
 Centro de Avaliação
 Fundação CESGRANRIO
 Rua Santa Alexandrina, 1011 - 2º andar
 Rio de Janeiro, RJ - CEP: 20261-903
 R (21) 2103-9600 R.:236 
 ( (21) 8777-7907
 ( lean...@cesgranrio.org.br
 
 Aquele que suporta o peso da sociedade
 é precisamente aquele que obtém
  as menores vantagens. (SMITH, Adam)
 
   Antes de imprimir pense em sua responsabilidade e compromisso com o MEIO 
 AMBIENTE 
 
 -Mensagem original-
 De: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Em 
 nome de Uwe Ligges
 Enviada em: sábado, 28 de fevereiro de 2009 16:34
 Para: rkevinbur...@charter.net
 Cc: R help
 Assunto: Re: [R] object .trPaths not found
 
 
 
 rkevinbur...@charter.net wrote:
  I am running an R script with Tinn-R (2.2.0.1) and I get the error message
  
  Error in source(.trPaths[4], echo = TRUE, max.deparse.length = 150) : 
object .trPaths not found
  
  Any solutions?
 
 
 Maybe, but the may depend on your script, your OS, your R version, 
 used packages and so on.
 
 Hence please read and follow the posting guide and provide commented, 
 minimal, self-contained, reproducible code.
 
 Uwe Ligges
 
 
 
 
  Thank you.
  
  Kevin
  
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Gradient function for optim.

2009-03-02 Thread rkevinburton
Thank you. I saw the source. But I am not sure how to get from 
.Internal(optim(...)) to fmingr.

Kevin

 Katharine Mullen k...@few.vu.nl wrote: 
 see the fmingr function in src/main/optim.c
 (https://svn.r-project.org/R/trunk/src/main/optim.c)
 
 On Wed, 25 Feb 2009 rkevinbur...@charter.net wrote:
 
  I have read that when the gradient function is not supplied (is null)
  then first order differencing is used to find the differential. I was
  trying to track down this for my own information but I run into
  .Internal(optim.). I was not sure where to look next to see the
  function that is automatically supplied for the gradient.
 
  Thank you.
 
  Kevin
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Optim parscale?

2009-03-02 Thread rkevinburton
I am not clear on what is happening with parscale in optim It seems that 
scaling the parameters will produce unpredictable results in a non-linear 
function (which is the purpose of optim right?)

The documentation states:

parscale
A vector of scaling values for the parameters. Optimization is performed on 
par/parscale and these should be comparable in the sense that a unit change in 
any element produces about a unit change in the scaled value. 

I am not sure how it can be guaranteed that this will be case. I first saw a 
non-unity parscale in the ARIMA code where I see code like:

ses - summary(fit)$coefficients[, 2]
parscale - c(parscale, 10 * ses)

Comments?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] object .trPaths not found

2009-02-28 Thread rkevinburton
FYI. I found the solution. My RProfile.site file could not be written to 
because of permissions. Whan I selected the Configure/Permanent option in 
Tinn-R it was silently ignoring the fact that the file could not be written to. 
When I adjusted the permissions, all was well. 

Thank you.

Kevin

 Kingsford Jones kingsfordjo...@gmail.com wrote: 
 RSiteSearch('trpaths')
 
 will lead you to potential solutions...
 
 
 
 On Fri, Feb 27, 2009 at 7:18 PM,  rkevinbur...@charter.net wrote:
  I am running an R script with Tinn-R (2.2.0.1) and I get the error message
 
  Error in source(.trPaths[4], echo = TRUE, max.deparse.length = 150) :
   object .trPaths not found
 
  Any solutions?
 
  Thank you.
 
  Kevin
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Variable scope.

2009-02-28 Thread rkevinburton
I have a question on scope/reference/value type of variables with 'R'.

The issue cam up first when I look at the arima code.

I see code like:

myupARIMA - function(mod, phi, theta) {
. . . .
   mod
}

Then 

armafn - function(p, trans) {
. . . .
Z - upARIMA(mod, trarma[[1]], trarma[[2]])
. . . .
res - .Call(R_ARIMA_Like, x, Z$phi, Z$theta, Z$Delta, 
Z$a, Z$P, Z$Pn, as.integer(0), FALSE)
. . . . 
}

The question is that ARIMA_Like will make changes to the arrays Z$P etc. Since 
upARIMA essentially returns 'mod' are changes to the arrays passed as Z$... to 
ARUINA_Like refkected in the original 'mod'? Or another way of phrasing the 
question is 'Z' a reference variable? Are the members such as Z$a also passed 
as reference hence changes to Z$a should also be seen in mod$a? In the arima 
code the references to x and mod seem to be essentially global variables as 
armafn is 'nested' in arima. Will changes to x also be reflected in the 
original x? (Like x - x - (xreg %*% par[narma + (1:ncxreg)))

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] object .trPaths not found

2009-02-27 Thread rkevinburton
I am running an R script with Tinn-R (2.2.0.1) and I get the error message

Error in source(.trPaths[4], echo = TRUE, max.deparse.length = 150) : 
  object .trPaths not found

Any solutions?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Gradient function for optim.

2009-02-25 Thread rkevinburton
I have read that when the gradient function is not supplied (is null) then 
first order differencing is used to find the differential. I was trying to 
track down this for my own information but I run into .Internal(optim.). I 
was not sure where to look next to see the function that is automatically 
supplied for the gradient.

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Arima bug?

2009-02-19 Thread rkevinburton
I was looking at the 'R' code associated with arima. I see the following:

upARIMA - function(mod, phi, theta) {
p - length(phi)
q - length(theta)
mod$phi - phi
mod$theta - theta
r - max(p, q + 1)
if (p  0) 
mod$T[1:p, 1] - phi
if (r  1) 
mod$Pn[1:r, 1:r] - .Call(R_getQ0, phi, theta)
else if (p  0) 
mod$Pn[1, 1] - 1/(1 - phi^2)
else mod$Pn[1, 1] - 1
mod$a[] - 0
mod
}
 

In particular the statement:

   else if (p  0) 
mod$Pn[1, 1] - 1/(1 - phi^2)

If p (the length of the phi vector) is greater than one then it looks like the 
code is trying to assign a vector to a single element which will generate an 
error in 'R'. Much like

x - 1:3
x[1] - 1:3

So I was wondering if there is something that I am missing that will 
guarantee that the length of the phi vector in this case is always 1. If this 
is not the case then it seems that this is a bug in the arima code.

Comments?

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Sign differences amoung QR solutions.

2009-02-12 Thread rkevinburton

I was noticing mainly sign differences amoung the solutions to QR 
decomposition. For example R:

 x - matrix(c(12,-51,4,6,167,-68,-4,24,-41),nrow=3,byrow=T)
 x
 [,1] [,2] [,3]
[1,]   12  -514
[2,]6  167  -68
[3,]   -4   24  -41
 r - qr(x)
 r$qr
[,1] [,2] [,3]
[1,] -14.000  -21.000   14
[2,]   0.4285714 -175.000   70
[3,]  -0.28571430.1107692  -35

 qr.Q(r)
   [,1]   [,2][,3]
[1,] -0.8571429  0.3942857  0.33142857
[2,] -0.4285714 -0.9028571 -0.03428571
[3,]  0.2857143 -0.1714286  0.94285714


When I feed this matrix into 
http://www.bluebit.gr/matrix-calculator/calculate.aspx I get:

R
-14.000  -21.000   14.000
   0.000 -175.000   70.000
   0.0000.000  -35.000

Q
-0.857  0.394  0.331
-0.429 -0.903 -0.034
 0.286 -0.171  0.943

Which seems to agree with the results of 'R'

This same matrix on http://en.wikipedia.org/wiki/QR_decomposition

R
14 -21 14
0 175 -70
0 0 35

Q
6/7 -69/175 -58/175
3/7 158/175 6/175
-2/7 6/36 -33/35

I have yet another algoithm that puts the R matrix as:
-14 -21 14 
0 -175 70 
0 0 35 

And Q as:
Q: 
-0.8571 0.3943 -0.3314 
-0.4286 -0.9029 0.0343 
0.2857 -0.1714 -0.9429 

So Wikipedia shows different signs but the property X = QR holds in all cases. 
My question is are there any gotchas (similar to the sign for tan) that I need 
to be aware of when using the results of a QR decomposition? With the sign 
differences it seems that there could be many possible decompositions for one 
matrix depending on the algoithem.

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Hessian?

2009-02-07 Thread rkevinburton
I am new to 'R' and also new to the concept of a 'Hessian' with non-linear 
optimization. I would like to avoid going through all of the reference articles 
given with ?optim as access to a library is not handy. Would someone be able to 
elighten me on what is in the Hessian matrix if 'hessian = TRUE' with optim? 
The documentation indicates that this is a numerically differentiated Hessian. 
So I am assuming that some small delta is chosen. How is the delta chosen ?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Foreign function call

2009-02-04 Thread rkevinburton
Let me get more specific. I think it this can be answered then I can translate 
the information to other calls. In the arima 'R' code there is a reference to

.Call(R_TSconv, a, b)

If from the console I type:

 .Call(R_TSConv, c(1,-1), c(1,-1))

I get:

Error: object R_TSConv not found

If I do 

 getNativeSymbolInfo(R_TSConv)

I get:

Error in FUN(R_TSConv[[1L]], ...) : no such symbol R_TSConv

What am I missing?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Foreign function call

2009-02-04 Thread rkevinburton
Thank you that helps alot. Now the question is how do I know that it is in the 
'stats' package? getNativeSymbolInfo doesn't seem to find 'RTSconv'.

Kevin

 Sundar Dorai-Raj sdorai...@gmail.com wrote: 
 You're missing that R_TSConv is an R object. You can use
 stats:::R_TSConv to see the value. Not sure how this helps you though.
 
 On Wed, Feb 4, 2009 at 10:08 AM,  rkevinbur...@charter.net wrote:
  Let me get more specific. I think it this can be answered then I can 
  translate the information to other calls. In the arima 'R' code there is a 
  reference to
 
  .Call(R_TSconv, a, b)
 
  If from the console I type:
 
  .Call(R_TSConv, c(1,-1), c(1,-1))
 
  I get:
 
  Error: object R_TSConv not found
 
  If I do
 
  getNativeSymbolInfo(R_TSConv)
 
  I get:
 
  Error in FUN(R_TSConv[[1L]], ...) : no such symbol R_TSConv
 
  What am I missing?
 
  Thank you.
 
  Kevin
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Calling compiled functions

2009-02-03 Thread rkevinburton
In the scripts I see lots of calls like .Call(.). But if I replace this 
exact string in my own R script I get  not found. I was wondering what the 
scopting rules are for these functions. How just for testing (I don't want to 
build a full blown package) to I use .Call and .C or .Fortran foreign function 
calls?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help

2009-01-29 Thread rkevinburton
You could look into ' try' and set it up to catch errors and do the appropriate 
thing in your error handler. I don't have the exact syntax at hand right now 
but looking at ?try or ?tryCatch I think will do what you want.

Kevin

 Alexandra Almeida alexandra...@gmail.com wrote: 
 Hi everybody!
 
 I´m with a problem that probably is easy for you, but I really don´t know
 how to solve.
 On the following script:
 
 for(j in 1:length(limiares))
 {
excessos-limiares[j]-estacao[estacaolimiares[j]]
par.ests-gpd(-(estacao),threshold=-limiares[j],method=c(pwm))$par.est
 
 GOF.test-ks.test(excessos,pgpd,xi=par.ests[1],beta=par.ests[2])$p.value
 
 tabs[j,]-c(par.ests,gpd(-(estacao),threshold=-limiares[j],method=c(pwm))$par.ses,GOF.test,length(excessos))
 }
 
 I´ve found the error for some values of i: Erro em ks.test(excessos, pgpd,
 xi = par.ests[1], beta = par.ests[2]) : NA/NaN/Inf em chamada de função
 externa (argumento 1)
 
 *My question is: This warning stop the for and I don´t want it, is there
 some way to continue the for, and for the cases where the function cannot
 calculate the ks.test for the i just leave a NA as answer???*
 
 Thank you *very much*!!!
 
 Alexandra Almeida
 
 
 
 -- 
 Alexandra R M de Almeida
 
   [[alternative HTML version deleted]]
 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] ifelse help?

2009-01-19 Thread rkevinburton
I am having a hard time understanding what is happening with ifelse.

Let me illustrate:

h - numeric(5)
p - 1:5
j - floor(j)
x - 1:1000
 ifelse(h == 0, x[j+2], 1:5)
[1] 2 3 4 5 6

My question is, shouldn't this be retruning 25 numbers? It seems that the 
ifelse should check 5 values of h for zero. For each of the 5 values I am 
thinking it should return an array of 5 (x[j+2] if h[index] == 0). Since the 
dimension of h is 5 that would mean 25 values. But that isn't what is being 
returned.Something about this that I don't understand. Please help my ignorance.

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] ifelse help?

2009-01-19 Thread rkevinburton
Sorry I didn't give the proper initialization of j. But you are right j should 
also be an array of 5. So x[j + 5] would return 5 values. 

So if the array returned from 'ifelse' is the same dimention as test (h), then 
are all the values of h being tested? So since h as you say has no dimensions 
is the test only testing h[1]? Again it seems that if all of the elements of h 
are tested (there are 5 elements) and each element produces an array of 5 the 
resulting array should be 25. 

Kevin

 Charles C. Berry cbe...@tajo.ucsd.edu wrote: 
 On Mon, 19 Jan 2009, rkevinbur...@charter.net wrote:
 
  I am having a hard time understanding what is happening with ifelse.
 
  Let me illustrate:
 
  h - numeric(5)
  p - 1:5
  j - floor(j)
 
 And j is 0:4 + epsilon , where 0 = epsilon  1, evidently.
 
  x - 1:1000
  ifelse(h == 0, x[j+2], 1:5)
  [1] 2 3 4 5 6
 
  My question is, shouldn't this be retruning 25 numbers?
 
 
 No. It should be
 
   A vector of the same length and attributes (including class) as
   test and data values from the values of yes or no
 
 according to ?ifelse, and 'test' is what you have as 'h'
 
 Consider
 
  z - as.data.frame( diag(2 ) )
   ifelse(z == 0, letters , 1:5)
   V1  V2
 [1,] 1 c
 [2,] b 4
 
 
 all args have different lengths and classes. But the result has those of 
 the 'test' arg.
 
 
  It seems that the ifelse should check 5 values of h for zero. For each 
  of the 5 values I am thinking it should return an array of 5 (x[j+2] if 
  h[index] == 0). Since the dimension of h is 5 that would mean 25 values.
 
 h has no attributes, therefore no 'dimension'
 
 HTH,
 
 Chuck
 
  But that isn't what is being returned.Something about this that I don't 
  understand. Please help my ignorance.
 
  Thank you.
 
  Kevin
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 Charles C. Berry(858) 534-2098
  Dept of Family/Preventive 
 Medicine
 E mailto:cbe...@tajo.ucsd.edu UC San Diego
 http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901
 


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Warning on assignment.

2009-01-15 Thread rkevinburton
I have a question on whether a warning message is valid or if I just don't 
understand the process. Let me illustrate via some R code:

x - 1:20
i - x %% 2  0
y - rep(1,20)

x[i] - y
Warning message:
In x[i] - y :
  number of items to replace is not a multiple of replacement length

But it still does what I would expect for the assignment:

 x
 [1]  1  2  1  4  1  6  1  8  1 10  1 12  1 14  1 16  1 18  1 20
 

What don't I understand?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Warning on assignment.

2009-01-15 Thread rkevinburton
This was just an illustration. It is the warning message that I don't 
understand. The warning says number of items to replace is not a multiple of 
replacement length. The way I look at it 10 is a multiple of 20.

Kevin

 Sarah Goslee sarah.gos...@gmail.com wrote: 
 The lengths are different, particularly the length of subsetted x[i]
 
  x - 1:20
  i - x %% 2  0
  y - rep(1,20)
 
  length(x)
 [1] 20
  length(i)
 [1] 20
  length(x[i])
 [1] 10
  length(y)
 [1] 20
 
 You happened to be lucky and got what you wanted, but a more reliable
 approach is:
 
  x[i] - y[i]
 
 Sarah
 
 On Thu, Jan 15, 2009 at 1:08 PM,  rkevinbur...@charter.net wrote:
  I have a question on whether a warning message is valid or if I just don't 
  understand the process. Let me illustrate via some R code:
 
  x - 1:20
  i - x %% 2  0
  y - rep(1,20)
 
  x[i] - y
  Warning message:
  In x[i] - y :
   number of items to replace is not a multiple of replacement length
 
  But it still does what I would expect for the assignment:
 
  x
   [1]  1  2  1  4  1  6  1  8  1 10  1 12  1 14  1 16  1 18  1 20
 
 
  What don't I understand?
 
  Thank you.
 
  Kevin
 
 
 -- 
 Sarah Goslee
 http://www.functionaldiversity.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Partial sort?

2009-01-14 Thread rkevinburton
This is definitely a newbie question but from the documentation I have not been 
able to figure out what the partial sort option on the sort method does. I have 
read and re-read the documentation and looked at the examples but for some 
reason it doesn't register. Would someone attempt to explain what sort with a 
non-null partial array of indices does?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] pmax and sort?

2009-01-12 Thread rkevinburton
I am having a hard time understanding the documentation and I was wondering if 
there would be someone to help clear the cobwebs. 

The documentation for pmax states:

pmax and pmin take one or more vectors (or matrices) as arguments and return a 
single vector giving the ‘parallel’ maxima (or minima) of the vectors. The 
first element of the result is the maximum (minimum) of the first elements of 
all the arguments, the second element of the result is the maximum (minimum) of 
the second elements of all the arguments and so on. Shorter inputs are recycled 
if necessary. attributes (such as names or dim) are transferred from the first 
argument (if applicable). 

This descirption seems to me like what sort would return. Would someone please 
help me understand the differenece between pmax and sort?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] pmax and sort?

2009-01-12 Thread rkevinburton
I am having a hard time understanding the documentation and I was wondering if 
there would be someone to help clear the cobwebs. 

The documentation for pmax states:

pmax and pmin take one or more vectors (or matrices) as arguments and return a 
single vector giving the ‘parallel’ maxima (or minima) of the vectors. The 
first element of the result is the maximum (minimum) of the first elements of 
all the arguments, the second element of the result is the maximum (minimum) of 
the second elements of all the arguments and so on. Shorter inputs are recycled 
if necessary. attributes (such as names or dim) are transferred from the first 
argument (if applicable). 

This descirption seems to me like what sort would return. Would someone please 
help me understand the differenece between pmax and sort?

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Power functions?

2009-01-03 Thread rkevinburton
I had a question about the basic power functions in R.

For example from the R console I enter:

-1 ^ 2
[1] -1

but also

-1^3
[1] -1

-0.1^2
[1]  -0.01

Normally pow(-1, 2) return either -Infinity or NaN. Has R taken over the math 
functions? If so I would think that -1^2 is 1 not -1 and -0.1^2 is 0.01 not 
-0.01.

Thank you.

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


  1   2   3   >