Charles C. Berry | 1 Dec 2006 01:32

Re: analog to the matlab buffer function?


See

 	?embed

It is not quite the same, but this seems to be what you want - at least 
for the example you give:

> t( embed(1:5,3) )[3:1,]
      [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    3    4
[3,]    3    4    5
>

On Fri, 1 Dec 2006, Martin Ivanov wrote:

> Hello! I am new to R. I could not find a function analogous to matlab's 
> function buffer, which is used in signal processing. Is there such a 
> function in R? What I need to do is as follows. If I apply the function 
> to the vector c(1:5) for example with a window length 3 and overlapping 
> 2, I need to get a matrix like this:
> 1 2 3
> 2 3 4
> 3 4 5
> In matlab this is achieved with the function buffer. Is there ananalogous R function?
>
> Thank you very much in advance.
> Regards,
> Martin
(Continue reading)

amit soni | 1 Dec 2006 02:00
Picon
Favicon

query on nlm() function

Does nlm() function(non linear optimization function) supports quadratic constraints?

Thanks
Amit

 
____________________________________________________________________________________

	[[alternative HTML version deleted]]

______________________________________________
R-help <at> stat.math.ethz.ch 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.

Marc Schwartz | 1 Dec 2006 02:56
Picon

Re: analog to the matlab buffer function?

Here is another possibility, though I may be missing how the Matlab
function handles incomplete rows generated at the end of the source
vector. I have not fully tested this, so it may yet require some
tweaking and certainly appropriate error checking.

I am presuming that the basic premise is that each row is of length
'window' and that it overlaps with the END of prior row by 'overlap'. 

Buffer <- function(x, window, overlap)
{
  Res <- NULL

  while (length(x) >= window)
  {
    Res <- c(Res, x[1:window])
    x <- x[(1 + window - overlap):length(x)]
  }

  matrix(Res, ncol = window, byrow = TRUE)
}

> Buffer(1:5, 3, 2)
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    3    4
[3,]    3    4    5

> Buffer(1:10, 4, 2)
     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
(Continue reading)

Spencer Graves | 1 Dec 2006 05:36

Re: help

      In case you haven't already received an adequate reply (which I 
haven't seen) or figured this out on your own, I will comment.  Consider 
the following modifications of an example in the 'lmer' documentation: 

(fm0.0 <- lmer(Reaction~(1|Subject), sleepstudy))
(fm0.1 <- lmer(Reaction~1+(1|Subject), sleepstudy))
(fm0.s <- lmer(Reaction~Subject+(1|Subject), sleepstudy))

      The first two models are equivalent, as can be seen from looking 
at the output.  In the "formula" language, something like "Reaction~X" 
means to estimate an intercept plus an X effect.  If you want a 
no-constant model, you must specify "Reaction ~ -1+X".  When X is a 
factor, "Reaction ~ -1+X" effectively fits the same model as 
"Reaction~X" using an alternative parameterization.  If X is numeric, 
"Reaction~X" means estimate b0 and b1 in Reaction = b0 + b1*X + error.  
Meanwhile, "Reaction ~ -1+X" means estimate only b1 in Reaction = b1*X + 
error.  In this latter case, the introduction of "-1" actually changes 
the model. 

      The third model "Reaction~Subject+(1+Subject) is a confusion:  The 
"~Subject" part asks lmer to estimate a separate parameter for each 
Subject.  The (1|Subject) term asks lmer to estimate the standard 
deviation for between-Subject random variability after the fixed effects 
are removed.  Since Subject is also listed as a fixed effect in this 
model, the model is overparameterized:  I'm not certain, but it appears 
to me that the software doesn't know whether to allocate 
subject-specific deviations from the overall mean to the fixed effects 
coefficients or the random effect, and it appears to do a little of both.

      It might be nice if 'lmer' included a check for factors appearing 
(Continue reading)

Gustaf Rydevik | 1 Dec 2006 07:45
Picon

Vertical line in densityplot?

Hi all,

I'm trying to get a vertical line at a specific point in a
densityplot. abline seems to be what's required, but it doesn't align
itself to the scale used in the plot.

example:

library(lattice)
x<-rnorm(100)
plot.new()
densityplot(x)
abline(v=0)
-----
The line seems to use some other coordinate system. What kind of call
do I use to make abline use the graph's coordinates?

Additionally, it would be nice to have standard xy-axis, and to have
the line stop at the x-axis, so if anyone could tell me how to do
that, I'd be grateful.

Thanks in advance,

Gustaf

PS: a minor question: Why do I have to call plot.new() for abline to work?

--

-- 
email:gustaf.rydevik <at> gmail.com
tel: +46(0)703051451
(Continue reading)

Ken Knoblauch | 1 Dec 2006 08:38
Picon
Favicon

Vertical line in densityplot?

I think that you are mixing lattice and base graphics.  This works  
for me:

library(lattice)
x<-rnorm(100)
densityplot(x, panel =
				function(x, ...) {
					panel.densityplot(x, ...)
					panel.abline(v = 0, ...)
                   }
                   )

Gustaf Rydevik a écrit

> Hi all,
>
> I'm trying to get a vertical line at a specific point in a
> densityplot. abline seems to be what's required, but it doesn't align
> itself to the scale used in the plot.
>
> example:
>
> library(lattice)
> x<-rnorm(100)
> plot.new()
> densityplot(x)
> abline(v=0)
> -----
> The line seems to use some other coordinate system. What kind of call
> do I use to make abline use the graph's coordinates?
(Continue reading)

Thomas Petzoldt | 1 Dec 2006 08:44
Picon

Re: Vertical line in densityplot?

Hi,

lattice graphics work by utilizing so called panel functions. Here is a 
working version of your example:

library(lattice)
x<-rnorm(100)
plot.new()
densityplot(x,
   panel=function(x, ...){
     panel.densityplot(x, ...)
     panel.abline(v=0)
   }
)

For mor information, please look into the examples of densityplot and 
the help file of panel.abline

Hope it helps

Thomas

Gustaf Rydevik wrote:
> Hi all,
> 
> I'm trying to get a vertical line at a specific point in a
> densityplot. abline seems to be what's required, but it doesn't align
> itself to the scale used in the plot.
> 
> example:
(Continue reading)

Christian Hoffmann | 1 Dec 2006 09:03
Picon

Question on sub(stitute) X_1 -> X\_1

Hi,

Searching the archives has brought no clue:

For a tex chunk in an Sweave text

"Oracle query results: differences \Sexpr{varname},..."

I need to change the string varname from "X_1" to "X\_1",

sub("_",??,"X_+")  -> "X\_1"

so that subsequent Latex will generate "X_1" (i.e. show the underscore) 
instead of "X subscript 1" (subscripting the "1")

Various trials with sub("_","\\_",varname) and the like have not helped.

sub("_","\\_","X_1")             -> "X_1"
sub("_","\\_","X_1",fixed=TRUE)  -> "X\\_1"
sub("_","\_","X_1",fixed=TRUE)   -> "X_1"

Latex will translate  "X\\_1" to X  (linefeed) 1  !!

Thanks for help

Christian
--

-- 
Dr. Christian W. Hoffmann,
Swiss Federal Research Institute WSL
Zuercherstrasse 111, CH-8903 Birmensdorf, Switzerland
(Continue reading)

Gustaf Rydevik | 1 Dec 2006 09:06
Picon

Re: Vertical line in densityplot?

On 12/1/06, Thomas Petzoldt <petzoldt <at> rcs.urz.tu-dresden.de> wrote:
> Hi,
>
> lattice graphics work by utilizing so called panel functions. Here is a
> working version of your example:
>
> library(lattice)
> x<-rnorm(100)
> plot.new()
> densityplot(x,
>   panel=function(x, ...){
>     panel.densityplot(x, ...)
>     panel.abline(v=0)
>   }
> )
>
>
> For mor information, please look into the examples of densityplot and
> the help file of panel.abline
>
>
> Hope it helps
>
> Thomas
>

Thank you very much! Lattice works somewhat different from "regular"
graphics step-by-step addition then.

With standard axis, I just meant a set of axis where the x and y axis
(Continue reading)

Robin Hankin | 1 Dec 2006 09:16
Picon
Favicon

Re: analog to the matlab buffer function?

 > do.call("rbind",lapply(0:4,function(i){i+(1:5)}))
      [,1] [,2] [,3] [,4] [,5]
[1,]    1    2    3    4    5
[2,]    2    3    4    5    6
[3,]    3    4    5    6    7
[4,]    4    5    6    7    8
[5,]    5    6    7    8    9
 >

On 1 Dec 2006, at 00:32, Charles C. Berry wrote:

>
> See
>
>  	?embed
>
> It is not quite the same, but this seems to be what you want - at  
> least
> for the example you give:
>
>> t( embed(1:5,3) )[3:1,]
>       [,1] [,2] [,3]
> [1,]    1    2    3
> [2,]    2    3    4
> [3,]    3    4    5
>>
>
> On Fri, 1 Dec 2006, Martin Ivanov wrote:
>
>> Hello! I am new to R. I could not find a function analogous to  
(Continue reading)


Gmane