Re: [R] Script auto-detecting its own path

2010-09-29 Thread Stu Field
Hadley,
I'm not sure this will solve the issue because if I move the script, I would 
still have to go into the script and edit the "/path/to/my/script.r", or do I 
misunderstand your workaround? 

I'm looking for something like:
file.path.is.here("myscript.r") 

and which would return something like:
[1] "c:/user/Desktop/"

so that regardless of where the script is, as long as the accompanying scripts 
are in the same directory, they can be easily sourced with something like:
dirX <- file.path.is.here("MasterScript.r")
source(paste(dirX, "AuxillaryFile.r", sep=""))

Thanks,
Stu




On 29 • Sep • 2010, at  15:23, Hadley Wickham wrote:
>> 
>> Forgive me if this question has been addressed, but I was unable to find 
>> anything in the r-help list or in cyberspace. My question is this: is there 
>> a function, or set of functions, that will enable a script to detect its own 
>> path? I have tried file.path() but that was not what I was looking for. It 
>> would be nice to be able to put all the related scripts I use in the same 
>> folder with a "master" script and then source() them in that "master" 
>> script. Problem is, the "master" script must first know where it is (without 
>> me having to open it and retype the path every time I move it).
> 
> Instead of trying to work out where your script is located, when you
> source it in, just make sure the working directory is set correctly:
> 
> source("/path/to/my/script.r", chdir = T)
> 
> chdir is the very useful, but under advertised, argument to source().
> 
> Hadley
> 
> -- 
> Assistant Professor / Dobelman Family Junior Chair
> Department of Statistics / Rice University
> http://had.co.nz/

~~
Stu Field, PhD
Postdoctoral Fellow
Department of Biology
Colorado State University
1878 Campus Delivery
Fort Collins, CO 80523-1878
Office: E208 Anatomy/Zoology
Phone: (970) 491-5744
~~





[[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] Script auto-detecting its own path

2010-09-29 Thread Stu Field
Hi all,

Forgive me if this question has been addressed, but I was unable to find 
anything in the r-help list or in cyberspace. My question is this: is there a 
function, or set of functions, that will enable a script to detect its own 
path? I have tried file.path() but that was not what I was looking for. It 
would be nice to be able to put all the related scripts I use in the same 
folder with a "master" script and then source() them in that "master" script. 
Problem is, the "master" script must first know where it is (without me having 
to open it and retype the path every time I move it).

Any ideas?
Stu

ps. I found this on the internet but a) I couldn't understand it, and b) it 
didn't work:

frame_files <- lapply(sys.frames(), function(x) x$ofile)
frame_files <- Filter(Negate(is.null), frame_files)
PATH <- dirname(frame_files[[length(frame_files)]])


~~
Stu Field, PhD
Postdoctoral Fellow
Department of Biology
Colorado State University
1878 Campus Delivery
Fort Collins, CO 80523-1878
Office: E208 Anatomy/Zoology
Phone: (970) 491-5744
~~





[[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] Confusing concept of vector and matrix in R

2010-04-26 Thread Stu
Hi all,

One subtlety is that the drop argument only works if you specify 2 or
more indices e.g. [i, j, ..., drop=F]; but not for a single index e.g
[i, drop=F].

Why doesn't R complain about the unused "drop=F" argument in the
single index case?

Cheers,
- Stu

a = matrix(1:10, nrow=1)
b = matrix(10:1, ncol=1)

# a1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)
(a1 = a[2:5, drop=F])
dim(a1)

# a2 is an vector WITH dim attribute: a row matrix (drop=F works)
(a2 = a[, 2:5, drop=F])
dim(a2)

# b1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)
(b1 = b[2:5, drop=F])
dim(b1)

# b2 is an vector WITH dim attribute: a column matrix (drop=F works)
(b2 = b[2:5, , drop=F])
dim(b2)


On Mar 30, 4:08 pm, lith  wrote:
> > Reframe the problem. Rethink why you need to keep dimensions. I never ever 
> > had to use drop.
>
> The problem is that the type of the return value changes if you happen
> to forget to use drop = FALSE, which can easily turn into a nightmare:
>
> m <-matrix(1:20, ncol=4)
> for (i in seq(3, 1, -1)) {
>     print(class(m[1:i, ]))}
>
> [1] "matrix"
> [1] "matrix"
> [1] "integer"
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://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] how can one break or stop or return from a script?

2009-11-17 Thread Stu
Thanks ...
It's good to know I'm not missing the obvious.
- Stu

On Nov 16, 8:31 pm, Don MacQueen  wrote:
> I don't know how to do this in the way you describe.
>
> Easy alternatives include:
>
>   - putting the part of the script that is to be executed
> conditionally into a separate file, and then source it or not based
> on some condition.
>    - simply wrapping the different parts of the script in if, then, else 
> blocks.
>
> -Don
>
> At 1:37 PM -0800 11/16/09, Stu wrote:
>
>
>
>
>
> >Hi,
>
> >I am using a script to initialize variables in the global workspace.
>
> >Based on some condition, I would like to stop evaluation of a script
> >sourced on the command-line, without issuing an error.
>
> >My current solution is the following hack that uses a repeat { }
> >statement
>
> >--- init.R ---
> >#hack to enable setting of breakpoint
> >repeat {
>
> >...
> >if (condition) {
> >     break;
> >}
>
> >...
>
> ># remember to break !!
> >break;
> >} #end repeat
> >EOF
>
> >Thanks,
> >- Stu
>
> >__
> >r-h...@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.
>
> --
> --
> Don MacQueen
> Environmental Protection Department
> Lawrence Livermore National Laboratory
> Livermore, CA, USA
> 925-423-1062
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://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] how can one break or stop or return from a script?

2009-11-16 Thread Stu
Hi,

I am using a script to initialize variables in the global workspace.

Based on some condition, I would like to stop evaluation of a script
sourced on the command-line, without issuing an error.

My current solution is the following hack that uses a repeat { }
statement

--- init.R ---
#hack to enable setting of breakpoint
repeat {

...
if (condition) {
break;
}

...

# remember to break !!
break;
} #end repeat
EOF

Thanks,
- Stu

__
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] Curve fit a nonlinear equation with box constraints: success, many thanks!

2009-06-17 Thread Stu @ AGS
Dear R Helper Community!

 

Thank you for all your help and suggestions.  

For your reference and any future person searching the archives, here is the
solution that did what I wanted it to do.

 

As background, my goal was to find the coefficients for the following
equation form:

y ~ c1 * x1 * x2 ^ -c2 *x3 ^ c3

where y, x1, x2, and x3 are observed data, and

c1, c2 and c3 are regression coefficients subject to the following
constraints:

0.0   <= c2 <= 1.0

0.0   <= c3 <= 1.0

 

I ran the following code as a script from the R Gui on a windows machine.

The command for this was:  source("C:\\Users\\me\\R281\\work\\optimcall.R")

 

#  Script file: optimcall.R ***

# function definition

rss <- function(par) {

  y <-
c(0.111,0.0921052631578947,0.0564516129032258,0.0608108108108108
,0.0128205128205128,0.0136078431372549)

  x1 <-
c(0,0.978723404255319,0.087378640776699,0.549295774647887,0.0596026490066225
,0.61578947368421)

  x2 <- c(1,3,4,5,6,7)

  x3 <- c(3600,169200,185400,255600,271800,342000)

  par1 <- par[1]

  par2 <- par[2]

  par3 <- par[3]

  ressq <- (y - par1 * (x1 + 1) * x2^(-par2) * x3^par3)^2

  sum(ressq)

 }

 

#call to optimizer

opti <- optim(c(0.5, 0.5, 0.1), rss, gr = NULL, method = "L-BFGS-B", lower =
c(-Inf, 0, 0), upper = c(Inf, 1, 1) )

#  * End script file *

 


[[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] Specifying ui and ci such that ui %*% theta - ci >= 0

2009-06-17 Thread Stu @ AGS
Hi,

I am a bit stuck on specifying ui and ci.  

I have read Lange's book ((1999) Numerical Analysis for Statisticians) to
his approach and unfortunately his descriptions were not helpful for me.

 

Here is what I have:

ui <- rbind(c(0, -1, 0), c(0, 0, -1))

ci <- c(0, -1, -1))

theta <- c(0.5, 0.5, 0.1)

 

My goal is to feed these into constrOptim such that there is
no constraint on theta[1] and that theta[2] and theta[3] are both
constrained to fall between 0.0 and 1.0.

 

Perhaps my values for ui and ci are incorrect for these
constraints.

 

I have already solved the problem in another statistics
package so I know the actual solution to the coefficients.  But our ultimate
goal is to do additional work in R.  But so far, I have been unable  to
recreate our solution in R.

 

Thank you,

Stu

 

 


[[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] Constrained Optimization, a full example

2009-06-16 Thread Stu @ AGS
After a few days of work, I think I nearly have it.

Unfortunately, theta is unchanged after I run this (as a script from a
file).  I thought that theta would contain the fitted parameters.

 

The goal here is to find the least squares fit according to the function
defined as "rss" subject to the constraints defined as ui and ci.

I defined ui and ci to (hopefully) force par2 and par3 into the range  0.0
<= par2 <= 1.0 and 0.0 <= par3 <= 1.0.

I am not at all sure that ui and ci are defined correctly.

 

The call to constrOptim returns normally, but without a solution
(apparently).

 

Any suggestions appreciated.

Thanks

Stu

 

# data

y <-
c(0.111,0.0921052631578947,0.0564516129032258,0.0608108108108108
,0.0128205128205128,0.0136078431372549);

x1 <-
c(0,0.978723404255319,0.087378640776699,0.549295774647887,0.0596026490066225
,0.61578947368421);

x2 <- c(1,3,4,5,6,7);

x3 <- c(3600,169200,185400,255600,271800,342000);

 

observs <- data.frame(y, x1, x2, x3);

 

# function definition

rss <- function(par, y, x1, x2, x3) {

 par1 <- par[1]

 par2 <- par[2]

 par3 <- par[3]

 ressq <- (y - par1 * (x1 + 1) * x2^(-par2) * x3^par3)^2

 sum(ressq)

 }

 

#call to optimizer

opti <- constrOptim(c(0.5, 0.5, 0.1), rss, NULL, ui = rbind(c(0, 0), c(1,
0), c(0, 1)), ci = c(0, 1, 1));

 


[[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] ui and ci explanatory documentation

2009-06-16 Thread Stu @ AGS
Hi Livia and everyone,

Did you ever get a response on this question from last year (Jan 2008)?

I am also looking for more explanatory documentation on the
ui and ci parameters for the function constrOptim().

 

The examples provided in the R help and the full reference
manual are not working for me.  Goodle and Nabble searches have not resulted
in any explanation that reads like a manual.

How are ui and ci applied to the function passed into
constrOptim()?  How can ui and ci be written such that some but not all of
the parameters (the first argument of the function call) are constrained to
be between 2 values?

 

If no additional documents exist, then that would be good to
know also.

Any pointer or advice would be useful.

Thank you!

Stu

Original posting*

by  <http://www.nabble.com/user/UserProfile.jtp?user=802522> livia Jan 15,
2008; 05:58am 



Hello everyone, 

I would like to maximize the following function fqp with linear constraits
and the codes are as following: 
a= c(0.2,0.3,0.4) 
vcov=matrix(c(1,2,3,4,5,6,7,8,9),3,3) 
fqp <- function(b) {t(b)%*%a-0.5*((t(b)%*%vcov)%*%b)} 
constrOptim(c(b1,b2,b3), fqp,NULL,ui=?, ci=?, control=list(fnscale=-1)) 

The linear constrait is like abs(b1)+ abs(b2)+abs(b3) <= 1.5. How can I set
"ui" and "ci"? 

Could anyone give me some advice?

Many thanks. 

 


[[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] The R-Inferno

2009-06-16 Thread Stu @ AGS
Patrick,
Thanks for your suggestion!
The R-Inferno was especially useful!!  The first chapter had me
chuckling aloud despite the fact that I work alone.
Well worth the price!

Thanks!
Stu

> -Original Message-
> From: Patrick Burns [mailto:pbu...@pburns.seanet.com]
> Sent: Tuesday, June 16, 2009 11:31 AM
> To: Stu @ AGS
> Subject: Re: [R] The most straightfoward way to write a function that
> sums over the rows of a matrix
> 
> 'The R Inferno' may be of use to you.
> 
> 
> 
> Patrick Burns
> patr...@burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of "The R Inferno" and "A Guide for the Unwilling S User")
> 
>

__
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] Trouble with optim on a specific problem

2009-06-16 Thread Stu @ AGS
Liviu,
Thanks for your comments.
With continued study and experimentation, I have discovered the 
following:
a. I need to rewrite the function to return a 1x1 as you suggested; 
b. it seems that constrOptim() is the most appropriate routine to use 
on a nonlinear optimization problem with linear constraints on the regression 
parameters.

Thanks
Stu
> -Original Message-
> From: Liviu Andronic [mailto:landronim...@gmail.com]
> Sent: Tuesday, June 16, 2009 12:15 PM
> Cc: r-help@r-project.org
> Subject: Re: [R] Trouble with optim on a specific problem
> 
> Hello,
> 
> On 6/16/09, Stu @ AGS  wrote:
> > Thanks for your response!
> >  No, my basic equation does not use matrices at all.  It takes scalar
> values and returns a scalar.
> >
> Not quite. Taking the example above, if you run the following:
> > with(observs , {1*x1*x2^2*x3^3})
> [1] 0.000e+00 4.267e+16 8.910e+15 2.293e+17 4.308e+16 1.207e+18
> 
> you get a vector 6x1. I may be wrong, but I would expect optim() or
> any other optimiser (nlminb, etc.) to expect that the objective
> function returns a 1x1 value. In my specific example, I arbitrarily
> chose values for the parameters: c[1]=1,c[2]=2,c[3]=3.
> 
> 
> >  What I am trying to accomplish is to find the "best-fit"
> coefficients to the equation as follows:
> >  y ~ c1 * x1 * x2^c2 * x3^c3
> >  where y, x1, x2, and x3 are observed data and c1, c2, and c3 are
> regression coefficients.
> >
> Here I'm slightly confused. If it is a regression that you are trying
> to do, and it seems non-linear, perhaps ?nls could help. I tried nls
> with your data, but it ended up with an error:
> 
> > nls( y ~ c1 * x1 * x2^c2 * x3^c3, data=observs, start=list(c1=0.66,
> c2=0.999, c3 = 0.064))
> Error in numericDeriv(form[[3]], names(ind), env) :
>   Missing value or an infinity produced when evaluating the model
> 
> 
> Best,
> Liviu

__
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] The most straightfoward way to write a function that sums over the rows of a matrix

2009-06-16 Thread Stu @ AGS
Hello!

 

I am trying to write a function with vector and data.frame parameters that
uses the sum() function and values from the rows of the data.frame.

I need to pass this function as a parameter to optim().

 

My starting point is:

observs <- data.frame(y, x1, x2, x3)

 

Fn <- function(par, observs) {

sum( (y - (par[1] * (x1 + 1) * x2^(-par[2]) * x3^par[3])^2 )

}

 

y, x1, x2, x3 are all vectors.

 

I am a bit new to R and I have not been able to find a good description of
how to iterate over rows in a data.frame.

 

What is a straightforward way to do this?

What am I missing?

 

Thanks

Stu

 


[[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] Trouble with optim on a specific problem

2009-06-16 Thread Stu @ AGS
Thanks for your response!
No, my basic equation does not use matrices at all.  It takes scalar values and 
returns a scalar.
What I am trying to accomplish is to find the "best-fit" coefficients to the 
equation as follows:
y ~ c1 * x1 * x2^c2 * x3^c3
where y, x1, x2, and x3 are observed data and c1, c2, and c3 are regression 
coefficients.

I thought the correct way to use optim() to find the coefficients was to put 
the data observations into a data.frame object, then call optim()

Maybe I am not using optim() correctly?

My observed data are (as vectors where each row of observations are located at 
the same index):
y <- c(0.111, 0.0921052631578947, 0.0564516129032258, 
0.0608108108108108, 0.0128205128205128, 0.0136078431372549)
x3 <- c(3600, 169200, 185400, 255600, 271800, 342000)
x2 <- c(1, 3, 4, 5, 6, 7)
x1 <- c(0, 0.978723404255319, 0.087378640776699, 0.549295774647887, 
0.0596026490066225, 0.61578947368421)

Thank you again,
Stu

> -Original Message-
> From: Liviu Andronic [mailto:landronim...@gmail.com]
> Sent: Tuesday, June 16, 2009 2:35 AM
> To: Stu @ AGS
> Cc: r-help@r-project.org
> Subject: Re: [R] Trouble with optim on a specific problem
> 
> Hello,
> 
> On 6/16/09, Stu @ AGS  wrote:
> >  Error in optim(c(0.66, 0.999, 0.064), pe, NULL, method = "L-BFGS-B")
> :
> >
> >   objective function in optim evaluates to length 6 not 1
> >
> 
> >
> >  > pe <- function(c) c[1]*x1*x2^c[2]*x3^c[3]
> >
> I would suspect a matrix multiplication issue. In order to minimise
> your function optim expects the result of your specific function to be
> a scalar. Are you sure that after all the multiplications pe results
> in a vector of dimension 1x1?
> Liviu

__
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] Trouble with optim on a specific problem

2009-06-15 Thread Stu @ AGS
Hello!

 

I am getting the following errors when running optim() [I tried optim() with
3 different methods as you can see]:

 

Error in optim(c(0.66, 0.999, 0.064), pe, NULL, method = "L-BFGS-B") : 

  objective function in optim evaluates to length 6 not 1

> out <- optim( c(0.66, 0.999, 0.064), pe, NULL, method = "Nelder-Mead")

Error in optim(c(0.66, 0.999, 0.064), pe, NULL, method = "Nelder-Mead") : 

  objective function in optim evaluates to length 6 not 1

> out <- optim( c(0.66, 0.999, 0.064), pe, NULL, method = "CG")

Error in optim(c(0.66, 0.999, 0.064), pe, NULL, method = "CG") : 

  objective function in optim evaluates to length 6 not 1

 

I don't know what the error message should mean to me.

Particulars for the problem are listed below.

Thanks in advance for any help!!

 

Stu

 

 

> y <-
c(0.111,0.0921052631578947,0.0564516129032258,0.0608108108108108
,0.0128205128205128,0.0136078431372549)

> x3 <- c(3600,169200,185400,255600,271800,342000)

> x2 <- c(1,3,4,5,6,7)

> x1 <-
c(0,0.978723404255319,0.087378640776699,0.549295774647887,0.0596026490066225
,0.61578947368421)

> observs <- data.frame(y, x1, x2, x3)

> attach(observs)

> pe <- function(c) c[1]*x1*x2^c[2]*x3^c[3]

> out <- optim(c(0.66, 0.999, 0.064), pe, NULL, method = "L-BFGS-B")


[[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] Linear Regression with Constraints

2009-05-26 Thread Stu @ AGS
Hi!
I am a bit new to R.
I am looking for the right function to use for a multiple regression problem
of the form:

y = c1 + x1 + (c2 * x2) - (c3 * x3)

Where c1, c2, and c3 are the desired regression coefficients that are
subject to the following constraints:

0.0 < c2 < 1.0, and
0.0 < c3 < 1.0

y, x1, x2, and x3 are observed data.  
I have a total of 6 rows of data in a data set.

Is "optim" in the stats package the right function to use?
Also, I can't quite figure out how to specify the constraints.
Thank you!

-Stu

__
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] Matrix Construction; Subdiagonal

2009-03-11 Thread Stu Field
Thanks Bill,
This one will work perfectly, the others required an existing matrix  
to be modified, which isn't the case (I'm using this xyz function in a  
larger construct). Plus it's only a 12x12, so not too big on memory.
Thank you!
Stu


On 11 • Mar • 2009, at 6:34 PM,  wrote:

>
> This is horrible on memory if you are dealing with large matrices.
>
> Here is a slightly more slick version of the function I have already  
> posted:
>
>
> xyz <- function (v, k) {
>n <- length(v) + abs(k)
>x <- matrix(0, n, n)
>i <- (1 - min(0, k)):(n - max(0,k))
>j <- (1 + max(0, k)):(n + min(0,k))
>x[cbind(i,j)] <- v
>x
> }
>
> The point of this is that it does not hold three copies of the  
> matrix in memory at once (x, row(x) and col(x)).  It uses the matrix  
> index idea instead.
>
> If you were going to be doing this a lot, you would be better  
> writing a function `Diag<-`, say, which places a vector at a  
> specified diagonal position of a given matrix.  This is an easy  
> exercise for the reader!
>
>
> Bill Venables
> http://www.cmis.csiro.au/bill.venables/
>
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org 
> ] On Behalf Of Sundar Dorai-Raj
> Sent: Thursday, 12 March 2009 10:00 AM
> To: Stu Field
> Cc: r-help@r-project.org
> Subject: Re: [R] Matrix Construction; Subdiagonal
>
> You can always write your own function:
>
> myDiag <- function(x, vec, k) {
>  x[row(x) == col(x) - k] <- vec
>  x
> }
>
> myDiag(A, vec, -1)
>
> Of course, you should probably do some input checking too.
>
> --sundar
>
> On Wed, Mar 11, 2009 at 4:57 PM, Stu Field  wrote:
>> Sure, that'll work fine, thanks.
>> But I guess I was looking for something more similar to MatLab, I'm  
>> really
>> surprised R doesn't have a preset command for this (?)
>> Thanks again,
>> Stu
>> On 11 . Mar . 2009, at 5:49 PM, Sundar Dorai-Raj wrote:
>>
>> Does this help?
>>
>> A <- matrix(0, 6, 6)
>> vec <- 1:5
>> A[row(A) == col(A) + 1] <- vec
>>
>> --sundar
>>
>> On Wed, Mar 11, 2009 at 4:42 PM, Stu Field  wrote:
>>
>> I'm trying to enter a vector into the subdiagonal of a matrix but
>>
>> cannot find a command in R which corresponds to the MatLab version of
>>
>> diag(vec, k), where vec = the vector of interest, and k = the  
>> diagonal
>>
>> (k=0 for the diagonal; k=-1 for the subdiagonal; k=1 for
>>
>> superdiagonal, etc.)
>>
>> Is there an equivalent command in R?
>>
>> I'm looking for something like this:
>>
>> vec = seq(1, 5, 1)# vector of interest
>>
>> A = xyz(vec,-1)   # creates a 6x6 matrix with vec on the
>>
>> subdiagonal
>>
>> where xyz is some function similar to diag, but with differing
>>
>> arguments.
>>
>> I can't believe there is not a simple way to do this...
>>
>> Thanks for your help,
>>
>> ~~
>>
>> Stu Field, PhD
>>
>> Postdoctoral Fellow
>>
>> Department of Biology
>>
>> Colorado State University
>>
>> 1878 Campus Delivery
>>
>> Fort Collins, CO 80523-1878
>>
>> Office: E208 Anatomy/Zoology
>>
>> Phone: (970) 491-5744
>>
>> ~~
>>
>>
>>
>>
>>
>>[[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.
>>
>>
>> ~~
>> Stu Field, PhD
>> Postdoctoral Fellow
>> Department of Biology
>> Colorado State University
>> 1878 Campus Delivery
>> Fort Collins, CO 80523-1878
>> Office: E208 Anatomy/Zoology
>> Phone: (970) 491-5744
>> ~~
>>
>>
>>
>>
>
> __
> 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.

~~
Stu Field, PhD
Postdoctoral Fellow
Department of Biology
Colorado State University
1878 Campus Delivery
Fort Collins, CO 80523-1878
Office: E208 Anatomy/Zoology
Phone: (970) 491-5744
~~





[[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] Matrix Construction; Subdiagonal

2009-03-11 Thread Stu Field
Sure, that'll work fine, thanks.
But I guess I was looking for something more similar to MatLab, I'm  
really surprised R doesn't have a preset command for this (?)
Thanks again,
Stu

On 11 • Mar • 2009, at 5:49 PM, Sundar Dorai-Raj wrote:

>
> Does this help?
>
> A <- matrix(0, 6, 6)
> vec <- 1:5
> A[row(A) == col(A) + 1] <- vec
>
> --sundar
>
> On Wed, Mar 11, 2009 at 4:42 PM, Stu Field  wrote:
>> I'm trying to enter a vector into the subdiagonal of a matrix but
>> cannot find a command in R which corresponds to the MatLab version of
>> diag(vec, k), where vec = the vector of interest, and k = the  
>> diagonal
>> (k=0 for the diagonal; k=-1 for the subdiagonal; k=1 for
>> superdiagonal, etc.)
>> Is there an equivalent command in R?
>>
>> I'm looking for something like this:
>> vec = seq(1, 5, 1)# vector of interest
>>
>> A = xyz(vec,-1)   # creates a 6x6 matrix with vec on the
>> subdiagonal
>> where xyz is some function similar to diag, but with differing
>> arguments.
>>
>> I can't believe there is not a simple way to do this...
>> Thanks for your help,
>>
>> ~~
>> Stu Field, PhD
>> Postdoctoral Fellow
>> Department of Biology
>> Colorado State University
>> 1878 Campus Delivery
>> Fort Collins, CO 80523-1878
>> Office: E208 Anatomy/Zoology
>> Phone: (970) 491-5744
>> ~~
>>
>>
>>
>>
>>
>>[[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.
>>

~~
Stu Field, PhD
Postdoctoral Fellow
Department of Biology
Colorado State University
1878 Campus Delivery
Fort Collins, CO 80523-1878
Office: E208 Anatomy/Zoology
Phone: (970) 491-5744
~~





[[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] Matrix Construction; Subdiagonal

2009-03-11 Thread Stu Field
I'm trying to enter a vector into the subdiagonal of a matrix but  
cannot find a command in R which corresponds to the MatLab version of  
diag(vec, k), where vec = the vector of interest, and k = the diagonal  
(k=0 for the diagonal; k=-1 for the subdiagonal; k=1 for  
superdiagonal, etc.)
Is there an equivalent command in R?

I'm looking for something like this:
vec = seq(1, 5, 1)# vector of interest

A = xyz(vec,-1)   # creates a 6x6 matrix with vec on the  
subdiagonal
where xyz is some function similar to diag, but with differing  
arguments.

I can't believe there is not a simple way to do this...
Thanks for your help,

~~~~~~
Stu Field, PhD
Postdoctoral Fellow
Department of Biology
Colorado State University
1878 Campus Delivery
Fort Collins, CO 80523-1878
Office: E208 Anatomy/Zoology
Phone: (970) 491-5744
~~





[[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] Error running OC package - program ending

2007-11-09 Thread Stu Bioge

I am attempting to run Poole's OC package in R, using Windows NT 5.1. 
Everytime I try to estimate a two-dimensional model, the estimation begins
and then I am informed "R for Windows GUI front-end has encountered a
problem and needs to close".  There is no problem estimating a
one-dimensional model.  I have no idea why the estimation will not contine. 
I have included the error signature below.
Any help or suggestions would be appreciated.

Error Signature:
AppName: rgui.exeAppVer: 2.60.43063.0ModName: ntdll.dll
ModVer: 5.1.2600.2180Offset: 00011e58
-- 
View this message in context: 
http://www.nabble.com/Error-running-OC-package---program-ending-tf4779698.html#a13673857
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.