[R] Plotting numeric values against non numeric items

2010-01-08 Thread lse1986

Hi i want do a line graph.

My y axis contains numeric values. My x axis contains non numeric
statements.

This is what i want the graph to look like.

When i try to plot this graph on R it comes up with the following error
message:

"Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf"

Any help would be much appreciated. Thanks in advance.

-- 
View this message in context: 
http://n4.nabble.com/Plotting-numeric-values-against-non-numeric-items-tp1010129p1010129.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.


Re: [R] lattice, add text to xyplot

2010-01-08 Thread Ivan Gregoretti
Thank you. It works.

Ivan

Ivan Gregoretti, PhD
National Institute of Diabetes and Digestive and Kidney Diseases
National Institutes of Health
5 Memorial Dr, Building 5, Room 205.
Bethesda, MD 20892. USA.



On Fri, Jan 8, 2010 at 8:13 PM, David Winsemius  wrote:
>
> On Jan 8, 2010, at 8:10 PM, Jason Morgan wrote:
>
>> On 2010.01.08 19:44:39, Ivan Gregoretti wrote:
>>>
>>> Hello listers,
>>>
>>> Does anybody know how to add text to an xyplot without whipping out
>>> the existing curve?
>>> That's all.
>>>
>>> For instance,
>>>
>>> Lets say you generate a graph like this
>>>
>>> A <- data.frame(x = rnorm(100), y = rnorm(100))
>>> xyplot(y ~ x, data = A)
>>>
>>> How would you add 'Hello world'?
>>>
>>> I tried 6.02E23 different partial solutions found on the web and
>>> failed. I just need one EXAMPLE that WORKS.
>>>
>>> Unfortunately,
>>>
>>> library(lattice)
>>> ?panel.text
>>>
>>> shows no examples.
>>>
>>> As you see, I bring you a formidable challenge.
>>
>> A <- data.frame(x = rnorm(100), y = rnorm(100))
>> xyplot(y ~ x, data = A,
>>      panel = function(...) {
>>        panel.text(0, 0, "Hello world!")
>>        panel.xyplot(...)
>>      })
>
> Or, following a Sarkar r-helpful example on how to add to an existing plot:
>
>  library(lattice)
>  A <- data.frame(x = rnorm(100), y = rnorm(100))
>  xyplot(y ~ x, data = A)
>  trellis.focus("toplevel") ## has coordinate system [0,1] x [0,1]
>  panel.text(0.5, 0.2, "Hello, world", cex = 1.2, font = 2)
>  trellis.unfocus()
>
> --
> David
>>
>> A whole lot of examples lattice are available here:
>>
>> http://lmdvr.r-forge.r-project.org/figures/figures.html
>>
>> If you plan on using lattice often, I highly recommend Deepayan Sarkar's
>> book.
>>
>> Hope that helps,
>> ~Jason
>>
>>>
>>> Thank you,
>>>
>>> Ivan
>>>
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>

__
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] Variable Combinations in Regression

2010-01-08 Thread Jim Lemon

On 01/09/2010 07:49 AM, Richardson, Patrick wrote:


 Let's say I have 8 variables and I want to generate all combinations
 of those variables (In pairs, threes fours, etc) to run in multiple linear
 regression. Is there a built-in function to do that in R?

 Or at a minimum, how could I take those variables and generate all possible
 combinations.



Hi Patrick,
Maybe what you want is this:

allComb<-function(x) {
 nx<-length(x)
 combs<-as.list(x)
 for(i in 2:length(x)) {
  indices<-combn(1:nx,i)
  for(j in 1:dim(indices)[2]) {
   xlist<-list(x[indices[,j]])
   combs<-c(combs,xlist)
  }
 }
 return(combs)
}

that returns a list of all combinations of all sizes. As David pointed 
out, there are going to be a lot of combinations with eight elements.


Jim

__
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] lattice, add text to xyplot

2010-01-08 Thread David Winsemius


On Jan 8, 2010, at 8:10 PM, Jason Morgan wrote:


On 2010.01.08 19:44:39, Ivan Gregoretti wrote:

Hello listers,

Does anybody know how to add text to an xyplot without whipping out
the existing curve?
That's all.

For instance,

Lets say you generate a graph like this

A <- data.frame(x = rnorm(100), y = rnorm(100))
xyplot(y ~ x, data = A)

How would you add 'Hello world'?

I tried 6.02E23 different partial solutions found on the web and
failed. I just need one EXAMPLE that WORKS.

Unfortunately,

library(lattice)
?panel.text

shows no examples.

As you see, I bring you a formidable challenge.


A <- data.frame(x = rnorm(100), y = rnorm(100))
xyplot(y ~ x, data = A,
  panel = function(...) {
panel.text(0, 0, "Hello world!")
panel.xyplot(...)
  })


Or, following a Sarkar r-helpful example on how to add to an existing  
plot:


 library(lattice)
 A <- data.frame(x = rnorm(100), y = rnorm(100))
 xyplot(y ~ x, data = A)
 trellis.focus("toplevel") ## has coordinate system [0,1] x [0,1]
 panel.text(0.5, 0.2, "Hello, world", cex = 1.2, font = 2)
 trellis.unfocus()

--
David


A whole lot of examples lattice are available here:

http://lmdvr.r-forge.r-project.org/figures/figures.html

If you plan on using lattice often, I highly recommend Deepayan  
Sarkar's

book.

Hope that helps,
~Jason



Thank you,

Ivan



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] lattice, add text to xyplot

2010-01-08 Thread Jason Morgan
On 2010.01.08 19:44:39, Ivan Gregoretti wrote:
> Hello listers,
> 
> Does anybody know how to add text to an xyplot without whipping out
> the existing curve?
> That's all.
> 
> For instance,
> 
> Lets say you generate a graph like this
> 
> A <- data.frame(x = rnorm(100), y = rnorm(100))
> xyplot(y ~ x, data = A)
> 
> How would you add 'Hello world'?
> 
> I tried 6.02E23 different partial solutions found on the web and
> failed. I just need one EXAMPLE that WORKS.
> 
> Unfortunately,
> 
> library(lattice)
> ?panel.text
> 
> shows no examples.
> 
> As you see, I bring you a formidable challenge.

A <- data.frame(x = rnorm(100), y = rnorm(100))
xyplot(y ~ x, data = A,
   panel = function(...) {
 panel.text(0, 0, "Hello world!")
 panel.xyplot(...)
   })

A whole lot of examples lattice are available here:

http://lmdvr.r-forge.r-project.org/figures/figures.html

If you plan on using lattice often, I highly recommend Deepayan Sarkar's
book.

Hope that helps,
~Jason

> 
> Thank you,
> 
> Ivan
> 
> Ivan Gregoretti, PhD
> National Institute of Diabetes and Digestive and Kidney Diseases
> National Institutes of Health
> 5 Memorial Dr, Building 5, Room 205.
> Bethesda, MD 20892. USA.

-- 
Jason W. Morgan
Graduate Student
Department of Political Science
*The Ohio State University*
154 North Oval Mall
Columbus, Ohio 43210

__
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 to organize a lot of R source files

2010-01-08 Thread Henrik Bengtsson
library("R.utils");
sourceDirectory("myRFiles/", modifiedOnly=TRUE);

See ?sourceDirectory (regardless what the Rd help say, any '...'
argument is passed to sourceTo()).

/Henrik

On Fri, Jan 8, 2010 at 7:38 AM, Hao Cen  wrote:
> Hi,
>
> I wonder what is a better way to organize a lot of R source files. I have
> a lot of utility functions written and store them in several source files
> (e.g util1.R, util2.R,..utilN.R). I also have a master file in which the
> source command is used to load all the util.R files. When I need to use
> the utility functions in a new project, I create a new R file (e.g main.R)
> in which I "source" the master file.
>
> The problem with this approach is that anytime a single utility function
> is modified, I need to rerun the source command in main.R to load the
> master file, which loads all the utility R files via a loop over each
> file. Sometimes I have to wait for 10 seconds to get them all loaded.
> Sometimes I forget to run the source command. Is there a way in R to 1)
> only reload the file changed (like a make utility) when I run source on
> all utility files and/or even better 2)  reload the changed utility files,
> when I run a command that use one of those utility functions, without the
> need for me to source those files.
>
> Not sure if packaging solves this issue because the library command has be
> used every time a utility function is modified and in addition the package
> has to be rebuilt. I don't worry about sharing the source files at this
> moment as I am the only user of those utility files.
>
> This may be a common issue many R users face. I wonder how other R users
> solve this issue.
>
> thanks
>
> Jeff
>
> __
> 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] Arguments of a function

2010-01-08 Thread Jim Lemon

On 01/09/2010 05:15 AM, Lisa wrote:

Dear all,

I have a question about how to set arguments in my own function. For
example, I have a function that looks like this:

my.f<- function(a = x1, b = x2)
{
x1 = equation 1
x2 = equation 2
x3 = equation 3
y = a + b
}

x1, x2, and x3 are temporary variables (intermediate results) calculated
from other variables within the funciton. I want to use two of these three
variables to calculate y, and write R script as below:

my.f(a = x1, b = x2)

or

my.f(a = x2, b = x3)

The error information shows that: “objects 'x1', 'x2', or 'x3' not found”.

   

Hi Lisa,
Although you indicated that Henrique's solution worked, it looks to me 
as though you are confusing arguments with local variables. As you say, 
you are assigning the value of the sum of x1 and x2 to y. Since x1 and 
x2 only exist within the function, it would seem that you want:


my.f<-function(...) {
 x1<-(equation 1)
 x2<-(equation 2)
 x3<-(equation 3)
 y<-x1+x2
 return(y)
}

I suspect that you want to pass some values that will be used in the 
calculation of x1, x2 and x3 as arguments to the function (a and b?) 
thus the ellipsis in the function definition. Maybe what you are looking 
for is:


my.f<-function(a,b) {
 x1<-2 * a + 3
 x2<-b / 2
 x3<-(a + b) ^ 2
 y<-x1+x2
 return(y)
}

I hope this guess will be helpful to you.

Jim

__
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] lattice, add text to xyplot

2010-01-08 Thread Ivan Gregoretti
Hello listers,

Does anybody know how to add text to an xyplot without whipping out
the existing curve?
That's all.


For instance,

Lets say you generate a graph like this

A <- data.frame(x = rnorm(100), y = rnorm(100))
xyplot(y ~ x, data = A)

How would you add 'Hello world'?

I tried 6.02E23 different partial solutions found on the web and
failed. I just need one EXAMPLE that WORKS.

Unfortunately,

library(lattice)
?panel.text

shows no examples.

As you see, I bring you a formidable challenge.

Thank you,

Ivan

Ivan Gregoretti, PhD
National Institute of Diabetes and Digestive and Kidney Diseases
National Institutes of Health
5 Memorial Dr, Building 5, Room 205.
Bethesda, MD 20892. USA.

__
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] Online R documentation

2010-01-08 Thread Liviu Andronic
On Fri, Jan 8, 2010 at 10:06 PM, Jim Lemon  wrote:
> It's not the first time I've said it, but Jonathan Baron's search engine has
> always provided answers when my local R help can't. The only change I would
> make is to default to searching R functions only.
>
Another interface to this search engine is the sos package. Its main
function, findFn(), defaults to searching R functions only, and there
is also an Rcmdr plug-in.

Regards
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.


Re: [R] how to organize a lot of R source files

2010-01-08 Thread Jim Lemon

Hi Jeff,
Your request makes a lot of sense. I often modify files in the packages 
I maintain, typically by loading the package, then working on a copy of 
the function, continually "sourcing" the new code until it works 
correctly, and then checking and building the package. Apart from the 
official packages I maintain, I keep a few local packages with odd 
functions that I don't think are worth uploading to an already loaded 
CRAN. This shell script can be used to automate the building of a package.


#!/bin/sh
cp $1 $2/R
if R CMD check $2; then
 R CMD build $2;
 R CMD INSTALL $3;
else
 echo "Problem with R check of $2"
fi

If I had modified the "clinsig.R" file in the clinsig package, I could 
call this script like this:


Rpackage /home/jim/R/clinsig.R /home/jim/R/clinsig clinsig_1.0-1.tar.gz

and it would rebuild the package with the new function. Because I 
usually keep the files I am modifying in /home/jim/R I could simplify 
the command line a bit. This may seem like a lot of work, but when I 
worked out a way to get a function to check the timestamp of its source 
file and compare it against the timestamp of the latest package:


if(max(file.info(system("find /home/jim/R -name 'clinsig.R'
 -type f",intern=TRUE))$mtime) >
 max(file.info(system("find /home/jim/R -name 'clinsig_*'
 -type f",intern=TRUE))$mtime))
 source("/home/jim/R/clinsig.R")

a lot of hard coding of file locations ends up in your function file.

Jim

__
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] Functions for QUAIDS and nonlinear SUR?

2010-01-08 Thread Werner W.
Hi,

I would like to estimate a quadratic almost ideal demand system in R which is 
estimated usually by nonlinear seemingly unrelated regression. But there is no 
such function in R yet but it is readily available in STATA (nlsur), see B. Poi 
(2008): Demand-system estimation: Update, Stata Journal 8(4). 
Now I am thinking, what is quicker learning to "program" STATA which seems not 
really comfortable for programming or implement the method in R which might be 
above my head in terms of econometrics. May be it works with nlsystemfit?

Has anyone recommendations how to proceed or any pointers to a somewhat sure 
way to go in R? 

Thanks so much,
  Werner

__
Do You Yahoo!?
hutz gegen Massenmails. 
http://mail.yahoo.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.


Re: [R] strange behavior of R

2010-01-08 Thread David Winsemius


On Jan 8, 2010, at 5:57 PM, Fahim wrote:



Hi
I observed an interesting behavior of R. Can you find where is the  
bug, or

it is not a bug but made deliberately.
- Hide quoted text -



arr = c();#defined the empty array
a= c("x1", "x2");
b = c("y1", "y2");
arr = rbind(arr,a);#row bind the first character array -a
arr = rbind(arr,b);# row bind the second character  
array-b


Everything ok upto this point, arr content is displayed as follows

arr

 [,1] [,2]
a "x1" "x2"
b "y1" "y2"

Now I delete any row:
arr = arr[-1,];

The value of arr is :

arr

[1] "y1" "y2"

Problem: I want to access the first row now using:

arr[1, ]

Error in arr[1, 1] : incorrect number of dimensions


use arr[ , -1, drop=FALSE] to avoid loosing dimensions.

?"["

--
David.


Though it is showing the value  as under:

arr[1]

[1] "y1"


arr[2]

[1] "y2"


I think, when there is single row, R is considering it as an array  
and not

as matrix. But why it is so?/




Because you didn't red the manual.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] strange behavior of R

2010-01-08 Thread Sarah Goslee
You need to reread the help for [, specifically the drop argument.

?"["

Sarah

On Fri, Jan 8, 2010 at 5:57 PM, Fahim  wrote:
>
> Hi
> I observed an interesting behavior of R. Can you find where is the bug, or
> it is not a bug but made deliberately.
> - Hide quoted text -
>
>
>> arr = c();                        #defined the empty array
>> a= c("x1", "x2");
>> b = c("y1", "y2");
>> arr = rbind(arr,a);            #row bind the first character array -a
>> arr = rbind(arr,b);            # row bind the second character array-b
>
> Everything ok upto this point, arr content is displayed as follows
>> arr
>  [,1] [,2]
> a "x1" "x2"
> b "y1" "y2"
>
> Now I delete any row:
> arr = arr[-1,];
>
> The value of arr is :
>> arr
> [1] "y1" "y2"
>
> Problem: I want to access the first row now using:
>>arr[1, ]
> Error in arr[1, 1] : incorrect number of dimensions
>
> Though it is showing the value  as under:
>> arr[1]
> [1] "y1"
>
>> arr[2]
> [1] "y2"
>
>
> I think, when there is single row, R is considering it as an array and not
> as matrix. But why it is so?/
>
>

-- 
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] strange behavior of R

2010-01-08 Thread Fahim

Hi 
I observed an interesting behavior of R. Can you find where is the bug, or
it is not a bug but made deliberately.
- Hide quoted text -


> arr = c();#defined the empty array
> a= c("x1", "x2");
> b = c("y1", "y2");
> arr = rbind(arr,a);#row bind the first character array -a
> arr = rbind(arr,b);# row bind the second character array-b

Everything ok upto this point, arr content is displayed as follows
> arr
  [,1] [,2]
a "x1" "x2"
b "y1" "y2"

Now I delete any row:
arr = arr[-1,];

The value of arr is :
> arr
[1] "y1" "y2"

Problem: I want to access the first row now using:
>arr[1, ]
Error in arr[1, 1] : incorrect number of dimensions

Though it is showing the value  as under:
> arr[1]
[1] "y1"

> arr[2]
[1] "y2"


I think, when there is single row, R is considering it as an array and not
as matrix. But why it is so?/
 

-Fahim
-- 
View this message in context: 
http://n4.nabble.com/strange-behavior-of-R-tp1010047p1010047.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.


Re: [R] Singularity problem

2010-01-08 Thread David Winsemius


On Jan 8, 2010, at 4:50 PM, Moohwan Kim wrote:


Dear R family

I have a problem with invertibility in a matrix.

m1 <- ar(x, method='mle')

Error in solve.default(res$hessian * length(x)) :
 Lapack routine dgesv: system is exactly singular

How could I avoid this problem?



Take out the collinear terms.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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 to Merge based on Rows

2010-01-08 Thread Gabor Grothendieck
Try this.  (The second line removes the suffixes in the column names.)

> out <- merge(x1, x2, by = 0, all = TRUE)[-1]
> names(out) <- sub("\\..*", "", names(out))
> out
  Apples Oranges Pears Apples Oranges Pears
1  5   6 7  5   3 9
2  5   3 4  3   2 1
3  8   910  3   4 5
4 11  1314 NA  NANA
5 15   3 8  8   1 4
6  1   4 5 NA  NANA
7 NA  NANA  3   2 1



On Fri, Jan 8, 2010 at 4:21 PM, MRKidd  wrote:
>
>  Let's say that I have a bunch of matrices.
>
> They look like this (pardon using fruit for examples, my actual data tables
> are far too enormous):
>
> Matrix1
>
>      Apples   Oranges   Pears
> A       5           6           7
> B       5           3           4
> C       8           9           10
> D      11          13          14
> E      15            3           8
> F       1             4           5
>
>
> Matrix2
>
>      Apples     Oranges   Pears
> A       5             3           9
> B       3             2            1
> C       3             4            5
> E       8             1            4
> G       3            2             1
>
>
> I cannot use cbind or rbind, because I have different rows in each matrix
> (e.g. - F & D are missing for Matrix2 and G is missing from Matrix1).
>
> What I would like to have in the end is this
>
>      Apples    Oranges    Pears     Apples   Oranges   Pears
> A      5             6            7            5           3           9
> B      5             3            4            3           2            1
> C      8             9            10          3            4           5
> D      11           13           14         NA          NA         NA
> E       15          3              8           8           1            4
> F       1            4             5           NA         NA         NA
> G      NA          NA          NA          3            2           1
>
> I have experimented with the merge() cmd, but my trial and error efforts
> have failed miserably. If anyone knows of a way to combine these matrices
> other than manually editing them together, please let me know.
>
> p.s.
> The way I have organized the matrices is such that they all have the same
> column names. So Matrix 1 and Matrix 2 will have the exact same column names
> - but I want the newly combined matrix to keep the columns separate. So, as
> in my final example, there would be one column titled "Apples" for each
> Matrix that I add in.
>
>
> --
> View this message in context: 
> http://n4.nabble.com/How-to-Merge-based-on-Rows-tp101p101.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.


Re: [R] Variable Combinations in Regression

2010-01-08 Thread David Winsemius


On Jan 8, 2010, at 3:26 PM, Richardson, Patrick wrote:

Let's say I have 8 variables and I want to generate all combinations  
of those variables (In pairs, threes fours, etc) to run in multiple  
linear regression. Is there a built-in function to do that in R?


The formula syntax allows that.

y ~ (x1 + x2 + x3 + x4 + x5)^2   for instance,  would give you all 5  
of the main effects and the ten two way interaction estimates. With  
the "exponent set to three you also get the three way interactions  
(although I have never tried this particular level of dredging.)  
Unless you have scientific arguments for higher level interactions,  
they are a major threat to interpretability and validity as well as a  
threat to convergence.


(With 8 variables you are going to experience a combinatorial  
explosion: 28 two-way terms, 56 3-way, 70 4-way and then down the  
other side of Pascal's triangle.)




Or at a minimum, how could I take those variables and generate all  
possible combinations.


Thank you for any assistance.


--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] solving cubic/quartic equations non-iteratively -- comparisons

2010-01-08 Thread Larry Hotchkiss
Hi,

I'm responding to a post about finding roots of a cubic or quartic equation 
non-iteratively. One obviously could create functions using the explicit 
algebraic solutions. One post on the subject noted that the square-roots in 
those solutions also require iteration, and one post claimed iterative 
solutions are more accurate than the explicit solutions.

This post, however, is about comparative accuracy of (1) the R solve 
functionused in the included post, (2) the R polyroot function, (3) the Matlab 
roots function, (4) the SAS IML polyroot function. I tried the posted 
polynomial:

  -8 + 14*x - 7*x^2 + x^3 = 0

and a repeating-roots example:

  8 - 36*x + 54*x^2 - 27*x^3 = 0

I used Mathematica solutions as the reference:

  (* Posted example *)
  Roots[-8 + 14 x - 7 x^2 + x^3 == 0, x]
  x == 1 || x == 2 || x == 4

  (* Repeating-roots example  *)
  Roots[8 - 36 x + 54 x^2 - 27 x^3 == 0, x]
  
  x == 2/3 || x == 2/3 || x == 2/3

The results indicate that the R polyroot function is the most accurate for 
these examples. The R solve function is quite inaccurate for the 
repeating-roots example. It appears to be single-precision arithmetic on the 
real and imaginary parts. The same appears to be true for the Matlab function 
roots. SAS IML polyroot function appears to use double-precision calculations 
but was not nearly as accurate as the R polyroot function for the 
repeating-roots example.

The syntax and output for these examples are as follows:

 # - #
 Mathematica:

  (* Posted example *)
  Roots[-8 + 14 x - 7 x^2 + x^3 == 0, x]
  x == 1 || x == 2 || x == 4

  (* Repeating-roots example  *)
  Roots[8 - 36 x + 54 x^2 - 27 x^3 == 0, x]
  
  x == 2/3 || x == 2/3 || x == 2/3

 # - #
 R:

>   options(digits=16)
>   library(polynom) 

 # Posted example
>   p <- polynomial(c(-8,14,-7,1))
>   solve(p)
[1] 0.999 2.002 3.997
> 
>   polyroot(c(-8,14,-7,1))
[1] 1-0i 2+0i 4-0i
> 
 # Repeating-roots example
>   lp <- polynomial(c(8,-36, 54, -27))
>   solve(lp)
[1] 0.648437558125-0.03157332198i 0.648437558125+0.03157332198i
[3] 0.703124883749+0.000i
>   polyroot(lp)
[1] 6.670e-01+2e-16i 6.666e-01-8e-17i
[3] 6.664e-01-1e-16i
 
 # - #
 Matlab:

>>  format long
>>  format compact

% Note: Matlab order of polynomial is reverse of R
% Posted example
>>  p = [-8,14,-7,1]; p = p(4:(-1):1)
p = 
1-714-8
>>  roots(p)
ans =
   4.000
   2.004
   0.999

% Repeating-roots example
>>  lp = [8,-36, 54, -27]; lp = lp(4:(-1):1)
lp =
   -2754   -36 8
>>  roots(lp)
ans =
  0.69450738337 + 0.04822149713i
  0.69450738337 - 0.04822149713i
  0.61098523329 
 # - #
 SAS proc IML:
 proc IML;
  * Note: SAS polyroot also uses high-to-low order of the polynomial, reverse
  of R fuctions. *;
  * Posted example *;
   p = {-8 14 -7 1}; p = p[4:1];
   rts = polyroot(p);
   print p rts[format=19.16];

  * Repeating-roots example *;
   lp = {8 -36 54 -27}; lp = lp[4:1];
   rts = polyroot(lp);
   print lp rts[format=19.16];
  quit;
 
  * Output;
   p rts
1  1.1500  0.
   -7  1.7700  0.
   14  4.0700  0.
   -8


   lp rts
  -27  0.6700  0.
   54  0.666526177100  0.
  -36  0.666807156100  0.
8 
 # - #

Larry Hotchkiss





--
Message: 7
Date: Wed, 6 Jan 2010 13:03:14 +0100
From: "Kasper Kristensen" 
Subject: Re: [R] solving cubic/quartic equations non-iteratively
To: 
Cc: r-help@r-project.org
Message-ID:
<88431fcdd055a44ba5eee1ec14e7e151143...@lu-mail-san.dfu.local>
Content-Type: text/plain; charset="iso-8859-1"


Try,

library(polynom)
p <- polynomial(c(-8,14,-7,1))
solve(p)


Kasper

__
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] Online R documentation

2010-01-08 Thread Jim Lemon

On 01/09/2010 12:41 AM, Jonathan Baron wrote:

...
Such a website exists:

http://finzi.psych.upenn.edu

Right near the top is a set of links to (almost) all package
documentation.  Duncan Murdoch helped here by including an option to
build static pages in the R source.

There is also a search engine.

   
It's not the first time I've said it, but Jonathan Baron's search engine 
has always provided answers when my local R help can't. The only change 
I would make is to default to searching R functions only. If I had a 
more gutsy server myself, I would offer an Australian mirror.


Jim

__
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 to Merge based on Rows

2010-01-08 Thread jim holtman
Is this what you want:

> x1$names <- rownames(x1)
> x1
  Apples Oranges Pears names
A  5   6 7 A
B  5   3 4 B
C  8   910 C
D 11  1314 D
E 15   3 8 E
F  1   4 5 F
> x2$names <- rownames(x2)
> x2
  Apples Oranges Pears names
A  5   3 9 A
B  3   2 1 B
C  3   4 5 C
E  8   1 4 E
G  3   2 1 G
> merge(x1, x2, by='names', all=TRUE)
  names Apples.x Oranges.x Pears.x Apples.y Oranges.y Pears.y
1 A5 6   75 3   9
2 B5 3   43 2   1
3 C8 9  103 4   5
4 D   1113  14   NANA  NA
5 E   15 3   88 1   4
6 F1 4   5   NANA  NA
7 G   NANA  NA3 2   1
>


On Fri, Jan 8, 2010 at 4:21 PM, MRKidd  wrote:

>
>  Let's say that I have a bunch of matrices.
>
> They look like this (pardon using fruit for examples, my actual data tables
> are far too enormous):
>
> Matrix1
>
>  Apples   Oranges   Pears
> A   5   6   7
> B   5   3   4
> C   8   9   10
> D  11  13  14
> E  153   8
> F   1 4   5
>
>
> Matrix2
>
>  Apples Oranges   Pears
> A   5 3   9
> B   3 21
> C   3 45
> E   8 14
> G   32 1
>
>
> I cannot use cbind or rbind, because I have different rows in each matrix
> (e.g. - F & D are missing for Matrix2 and G is missing from Matrix1).
>
> What I would like to have in the end is this
>
>  ApplesOrangesPears Apples   Oranges   Pears
> A  5 675   3   9
> B  5 343   21
> C  8 910  34   5
> D  11   13   14 NA  NA NA
> E   15  3  8   8   14
> F   14 5   NA NA NA
> G  NA  NA  NA  32   1
>
> I have experimented with the merge() cmd, but my trial and error efforts
> have failed miserably. If anyone knows of a way to combine these matrices
> other than manually editing them together, please let me know.
>
> p.s.
> The way I have organized the matrices is such that they all have the same
> column names. So Matrix 1 and Matrix 2 will have the exact same column
> names
> - but I want the newly combined matrix to keep the columns separate. So, as
> in my final example, there would be one column titled "Apples" for each
> Matrix that I add in.
>
>
> --
> View this message in context:
> http://n4.nabble.com/How-to-Merge-based-on-Rows-tp101p101.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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[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] A better way to Rank Data that considers "ties"

2010-01-08 Thread Ted Harding
On 08-Jan-10 21:09:08, MRKidd wrote:
> This will start off sounding very easy, but I think it will be
> very complicated.
> 
> Let's say that I have a matrix, which shows the number of apples
> that each person in a group has.
> 
> OriginalMatrix<-matrix(c(2,3,5,4,6),nrow=5,ncol=1,byrow=T,
>   dimnames=list(c("Bob","Frank","Joe","Jim","David"),c("Apples")))
> 
> Apples
> Bob   2
> Frank 3
> Joe   5
> Jim   4
> David 6
> 
> I want to add a third column that shows what each person's rank is
> - e.g. David is number 1 because he has the most apples. 
> 
> So this is what I want:
>  ApplesRank
> Bob   2  5
> Frank 3  4
> Joe   5   2
> Jim   4   3
> David6   1
> 
> I have managed to do this in the following steps:
> Unranked<-rownames(OriginalMatrix)
> Ranked<-names(sort(OriginalMatrix,decreasing=T))
> Matched<-match(Unranked,Ranked)
> NewMatrix<-cbind(OriginalMatrix,Matched)
> 
> This is not acceptable, however, if two people have the same number of
> apples.
> 
> You will get:
> 
> NewMatrix
> 
>ApplesRank
> Bob  2  5
> Frank   2  4
> Joe  5  2
> Jim  4  3
> David   6  1
> 
> Does anyone know of a way to make it so that both Bob and Frank
> will be ranked as fourth (i.e.- tied for last place)?

The following is one way of approaching it (given in primitive form):

  x<-matrix(c(2,2,5,4,6),ncol=1)
  rownames(x)<-c("Bob","Frank","Joe","Jim","David")
  x
  #   [,1]
  # Bob  2
  # Frank2
  # Joe  5
  # Jim  4
  # David6
unique(sort(x))
  # [1] 2 4 5 6
  N <- length(x)
  X <- cbind(x,rep(0,N))
  Vals <- unique(sort(x))
  M <- length(Vals)
  for(i in (1:N)){X[X[,1]==Vals[i],2]<-(M+1-i)}
  X
  #   [,1] [,2]
  # Bob  24
  # Frank24
  # Joe  52
  # Jim  43
  # David61

Maybe this helps!
Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 08-Jan-10   Time: 21:53:21
-- XFMail --

__
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] Singularity problem

2010-01-08 Thread Moohwan Kim
Dear R family

I have a problem with invertibility in a matrix.

m1 <- ar(x, method='mle')

Error in solve.default(res$hessian * length(x)) :
  Lapack routine dgesv: system is exactly singular

How could I avoid this problem?

Best
Moohwan

__
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] A better way to Rank Data that considers "ties"

2010-01-08 Thread Daniel Malter
Type

?rank

in the prompt and look at the ties.method argument.

Best,
Daniel
-
cuncta stricte discussurus
-
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of MRKidd
Sent: Friday, January 08, 2010 4:09 PM
To: r-help@r-project.org
Subject: [R] A better way to Rank Data that considers "ties"


This will start off sounding very easy, but I think it will be very
complicated.

Let's say that I have a matrix, which shows the number of apples that each
person in a group has.


OriginalMatrix<-matrix(c(2,3,5,4,6),nrow=5,ncol=1,byrow=T,dimnames=list(c("B
ob","Frank","Joe","Jim","David"),c("Apples")))

Apples
Bob2
Frank 3
Joe5
Jim4
David 6

I want to add a third column that shows what each person's rank is - e.g.
David is number 1 because he has the most apples. 

So this is what I want:

 ApplesRank
Bob   2  5
Frank 3  4
Joe   5   2
Jim   4   3
David6   1

I have managed to do this in the following steps:
Unranked<-rownames(OriginalMatrix)
Ranked<-names(sort(OriginalMatrix,decreasing=T))
Matched<-match(Unranked,Ranked)
NewMatrix<-cbind(OriginalMatrix,Matched)

This is not acceptable, however, if two people have the same number of
apples.

You will get:

NewMatrix

   ApplesRank
Bob  2  5
Frank   2  4
Joe  5  2
Jim  4  3
David   6  1

Does anyone know of a way to make it so that both Bob and Frank will be
ranked as fourth (i.e.- tied for last place)?
-- 
View this message in context:
http://n4.nabble.com/A-better-way-to-Rank-Data-that-considers-ties-tp1009994
p1009994.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] A better way to Rank Data that considers "ties"

2010-01-08 Thread MRKidd

This will start off sounding very easy, but I think it will be very
complicated.

Let's say that I have a matrix, which shows the number of apples that each
person in a group has.


OriginalMatrix<-matrix(c(2,3,5,4,6),nrow=5,ncol=1,byrow=T,dimnames=list(c("Bob","Frank","Joe","Jim","David"),c("Apples")))

Apples
Bob2
Frank 3
Joe5
Jim4
David 6

I want to add a third column that shows what each person's rank is - e.g.
David is number 1 because he has the most apples. 

So this is what I want:

 ApplesRank
Bob   2  5
Frank 3  4
Joe   5   2
Jim   4   3
David6   1

I have managed to do this in the following steps:
Unranked<-rownames(OriginalMatrix)
Ranked<-names(sort(OriginalMatrix,decreasing=T))
Matched<-match(Unranked,Ranked)
NewMatrix<-cbind(OriginalMatrix,Matched)

This is not acceptable, however, if two people have the same number of
apples.

You will get:

NewMatrix

   ApplesRank
Bob  2  5
Frank   2  4
Joe  5  2
Jim  4  3
David   6  1

Does anyone know of a way to make it so that both Bob and Frank will be
ranked as fourth (i.e.- tied for last place)?
-- 
View this message in context: 
http://n4.nabble.com/A-better-way-to-Rank-Data-that-considers-ties-tp1009994p1009994.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] How to Merge based on Rows

2010-01-08 Thread MRKidd

 Let's say that I have a bunch of matrices.

They look like this (pardon using fruit for examples, my actual data tables
are far too enormous):

Matrix1

  Apples   Oranges   Pears
A   5   6   7
B   5   3   4
C   8   9   10
D  11  13  14 
E  153   8
F   1 4   5


Matrix2

  Apples Oranges   Pears
A   5 3   9
B   3 21
C   3 45
E   8 14
G   32 1


I cannot use cbind or rbind, because I have different rows in each matrix
(e.g. - F & D are missing for Matrix2 and G is missing from Matrix1).

What I would like to have in the end is this

  ApplesOrangesPears Apples   Oranges   Pears
A  5 675   3   9
B  5 343   21
C  8 910  34   5
D  11   13   14 NA  NA NA
E   15  3  8   8   14
F   14 5   NA NA NA
G  NA  NA  NA  32   1

I have experimented with the merge() cmd, but my trial and error efforts
have failed miserably. If anyone knows of a way to combine these matrices
other than manually editing them together, please let me know.

p.s.
The way I have organized the matrices is such that they all have the same
column names. So Matrix 1 and Matrix 2 will have the exact same column names
- but I want the newly combined matrix to keep the columns separate. So, as
in my final example, there would be one column titled "Apples" for each
Matrix that I add in.


-- 
View this message in context: 
http://n4.nabble.com/How-to-Merge-based-on-Rows-tp101p101.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.


Re: [R] how to get perfect fit of lm if response is constant

2010-01-08 Thread Ista Zahn
Just to clarify this point: I don't think the problem is that y is
"perfectly fittable", but that it is constant. Since the variance of a
constant is zero, there is no variance to explain.

-Ista

On Fri, Jan 8, 2010 at 2:32 PM, Jan-Henrik Pötter  wrote:
> Thanks for the answer.
> The situation is that I don't know anything of y a priori. Of course I then 
> would not do a regression on constant y's, but isn't it a problem of 
> stability of the algorithm, if I get an adj RSquare of 0.6788 for
> a least square fit on this type of data? I think lm should give me a correct 
> result even in case of y is perfectly fittable, because the situation is that 
> I never know if my data could become so. If I have to offset y in this case, 
> then my question becomes how noisy do my y's have to be, so that I can rely 
> on the lm result, if I specify the formula y~x without offset. What if my y's 
> become nearly linear (or nearly perfect fittable with another linear model). 
> I think my question now becomes 'how to rely on lm's result if the formula is 
> specified the way y~x without offset? or 'How do I prevent my result to 
> become numerically incorrect if I may get nearly perfect fittable y's'.
>
> Greetings
>
> Henrik
>
>
> -Ursprüngliche Nachricht-
> Von: Peter Ehlers [mailto:ehl...@ucalgary.ca]
> Gesendet: Freitag, 8. Januar 2010 19:44
> An: Jan-Henrik Pötter
> Cc: r-help@r-project.org
> Betreff: Re: [R] how to get perfect fit of lm if response is constant
>
> You need to review the assumptions of linear models:
> y is assumed to be the realization of a random variable,
> not a constant (or, more precisely: there are assumed to
> be deviations that are N(0, sigma^2).
>
> If you 'know' that y is a constant, then you have
> two options:
>
> 1. don't do the regression because it makes no sense;
> 2. if you want to test lm()'s handling of the data:
>
> fm <- lm(y ~ x, data = df, offset = rep(1, nrow(df)))
>
> (or use: offset = y)
>
>  -Peter Ehlers
>
> Jan-Henrik Pötter wrote:
>> Hello.
>>
>> Consider the response-variable of data.frame df is constant, so analytically
>> perfect fit of a linear model is expected. Fitting a regression line using
>> lm result in residuals, slope and std.errors not exactly zero, which is
>> acceptable in some way, but errorneous. But if you use summary.lm it shows
>> inacceptable error propagation in the calculation of the t value and the
>> corresponding p-value for the slope, as well R-Square – just consider the
>> adj R-Square of 0.6788! This result is independent of which mode used for
>> the input vectors. Is there any way to get the perfect fitted regression
>> curve using lm and prevent this error propagation? I consider rounding all
>> values of the lm-object afterwards to somewhat precision as a bad idea.
>> Unfortunately there is no option in lm for calculation precision.
>>
>>
>>
>>> df<-data.frame(x=1:10,y=1)
>>
>>> myl<-lm(y~x,data=df)
>>
>>
>>
>>> myl
>>
>>
>>
>> Call:
>>
>> lm(formula = y ~ x, data = df)
>>
>>
>>
>> Coefficients:
>>
>> (Intercept)            x
>>
>>   1.000e+00    9.463e-18
>>
>>
>>
>>> summary(myl)
>>
>>
>>
>> Call:
>>
>> lm(formula = y ~ x, data = df)
>>
>>
>>
>> Residuals:
>>
>>        Min         1Q     Median         3Q        Max
>>
>> -1.136e-16 -1.341e-17  7.886e-18  2.918e-17  5.047e-17
>>
>>
>>
>> Coefficients:
>>
>>              Estimate Std. Error   t value Pr(>|t|)
>>
>> (Intercept) 1.000e+00  3.390e-17 2.950e+16   <2e-16 ***
>>
>> x           9.463e-18  5.463e-18 1.732e+00    0.122
>>
>> ---
>>
>> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>>
>>
>>
>> Residual standard error: 4.962e-17 on 8 degrees of freedom
>>
>> Multiple R-squared: 0.7145,     Adjusted R-squared: 0.6788
>>
>> F-statistic: 20.02 on 1 and 8 DF,  p-value: 0.002071
>>
>>
>>
>>
>>       [[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.
>
> --
> Peter Ehlers
> University of Calgary
> 403.202.3921
>
> __
> 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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.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.


Re: [R] how to get perfect fit of lm if response is constant

2010-01-08 Thread Jan-Henrik Pötter
Thanks for the answer.
The situation is that I don't know anything of y a priori. Of course I then 
would not do a regression on constant y's, but isn't it a problem of stability 
of the algorithm, if I get an adj RSquare of 0.6788 for 
a least square fit on this type of data? I think lm should give me a correct 
result even in case of y is perfectly fittable, because the situation is that I 
never know if my data could become so. If I have to offset y in this case, then 
my question becomes how noisy do my y's have to be, so that I can rely on the 
lm result, if I specify the formula y~x without offset. What if my y's become 
nearly linear (or nearly perfect fittable with another linear model). I think 
my question now becomes 'how to rely on lm's result if the formula is specified 
the way y~x without offset? or 'How do I prevent my result to become 
numerically incorrect if I may get nearly perfect fittable y's'. 

Greetings

Henrik


-Ursprüngliche Nachricht-
Von: Peter Ehlers [mailto:ehl...@ucalgary.ca] 
Gesendet: Freitag, 8. Januar 2010 19:44
An: Jan-Henrik Pötter
Cc: r-help@r-project.org
Betreff: Re: [R] how to get perfect fit of lm if response is constant

You need to review the assumptions of linear models:
y is assumed to be the realization of a random variable,
not a constant (or, more precisely: there are assumed to
be deviations that are N(0, sigma^2).

If you 'know' that y is a constant, then you have
two options:

1. don't do the regression because it makes no sense;
2. if you want to test lm()'s handling of the data:

fm <- lm(y ~ x, data = df, offset = rep(1, nrow(df)))

(or use: offset = y)

  -Peter Ehlers

Jan-Henrik Pötter wrote:
> Hello.
> 
> Consider the response-variable of data.frame df is constant, so analytically
> perfect fit of a linear model is expected. Fitting a regression line using
> lm result in residuals, slope and std.errors not exactly zero, which is
> acceptable in some way, but errorneous. But if you use summary.lm it shows
> inacceptable error propagation in the calculation of the t value and the
> corresponding p-value for the slope, as well R-Square – just consider the
> adj R-Square of 0.6788! This result is independent of which mode used for
> the input vectors. Is there any way to get the perfect fitted regression
> curve using lm and prevent this error propagation? I consider rounding all
> values of the lm-object afterwards to somewhat precision as a bad idea.
> Unfortunately there is no option in lm for calculation precision. 
> 
>  
> 
>> df<-data.frame(x=1:10,y=1)
> 
>> myl<-lm(y~x,data=df)
> 
>  
> 
>> myl
> 
>  
> 
> Call:
> 
> lm(formula = y ~ x, data = df)
> 
>  
> 
> Coefficients:
> 
> (Intercept)x  
> 
>   1.000e+009.463e-18  
> 
>  
> 
>> summary(myl)
> 
>  
> 
> Call:
> 
> lm(formula = y ~ x, data = df)
> 
>  
> 
> Residuals:
> 
>Min 1Q Median 3QMax 
> 
> -1.136e-16 -1.341e-17  7.886e-18  2.918e-17  5.047e-17 
> 
>  
> 
> Coefficients:
> 
>  Estimate Std. Error   t value Pr(>|t|)
> 
> (Intercept) 1.000e+00  3.390e-17 2.950e+16   <2e-16 ***
> 
> x   9.463e-18  5.463e-18 1.732e+000.122
> 
> ---
> 
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
> 
>  
> 
> Residual standard error: 4.962e-17 on 8 degrees of freedom
> 
> Multiple R-squared: 0.7145, Adjusted R-squared: 0.6788 
> 
> F-statistic: 20.02 on 1 and 8 DF,  p-value: 0.002071
> 
>  
> 
> 
>   [[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.

-- 
Peter Ehlers
University of Calgary
403.202.3921

__
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] Variable Combinations in Regression

2010-01-08 Thread Whit Armstrong
?expand.grid

On Fri, Jan 8, 2010 at 3:26 PM, Richardson, Patrick
 wrote:
> Let's say I have 8 variables and I want to generate all combinations of those 
> variables (In pairs, threes fours, etc) to run in multiple linear regression. 
> Is there a built-in function to do that in R?
>
> Or at a minimum, how could I take those variables and generate all possible 
> combinations.
>
> Thank you for any assistance.
>
> Patrick
>
>
> This email message, including any attachments, is for th...{{dropped:9}}
>
> __
> 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] Arguments of a function

2010-01-08 Thread Lisa

That's what I want. Thank you so much. 
Lisa


Henrique Dallazuanna wrote:
> 
> Try this:
> 
> my.f <- function(a, b) {
>   x1 <- 2 * 3
>   x2 <- 3 / 6
>   x3 <- 4 * 4 / 5 - sqrt(2)
>   y <- get(deparse(substitute(a))) + get(deparse(substitute(b)))
>   return(y)
> }
> 
> my.f(x1, x2)
> 
> On Fri, Jan 8, 2010 at 4:15 PM, Lisa  wrote:
>>
>> Dear all,
>>
>> I have a question about how to set arguments in my own function. For
>> example, I have a function that looks like this:
>>
>> my.f <- function(a = x1, b = x2)
>> {
>>   x1 = equation 1
>>   x2 = equation 2
>>   x3 = equation 3
>>   y = a + b
>> }
>>
>> x1, x2, and x3 are temporary variables (intermediate results) calculated
>> from other variables within the funciton. I want to use two of these
>> three
>> variables to calculate y, and write R script as below:
>>
>> my.f(a = x1, b = x2)
>>
>> or
>>
>> my.f(a = x2, b = x3)
>>
>> The error information shows that: “objects 'x1', 'x2', or 'x3' not
>> found”.
>>
>> Can anybody help me solve this problem? Thanks in advance.
>>
>> Lisa
>>
>> --
>> View this message in context:
>> http://n4.nabble.com/Arguments-of-a-function-tp1009883p1009883.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.
>>
> 
> 
> 
> -- 
> 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.
> 
> 

-- 
View this message in context: 
http://n4.nabble.com/Arguments-of-a-function-tp1009883p1009932.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.


Re: [R] function by: order within subsets

2010-01-08 Thread Gabor Grothendieck
Try ave:

transform(df, v = ave(v, f, FUN = cumsum))


On Fri, Jan 8, 2010 at 1:10 PM, Daniel Murphy  wrote:
> When the 'by' function forms subsets, are the rows in the same order as they
> are in the original data frame?
>
> For example, I want to use 'by' to calculate cumulative sums of a value 'v'
> by date 'd' for different levels of a factor 'f':
>
>>
> df<-data.frame(f=c("A","A","B"),d=as.Date(c("2010-1-1","2010-2-1","2010-1-1")),v=c(100,200,150))
>> df
>  f          d   v
> 1 A 2010-01-01 100
> 2 A 2010-02-01 200
> 3 B 2010-01-01 150
>> do.call(rbind,by(df,df$f,FUN=function(x)
> data.frame(x[1],x[2],cumsum(x[3]
>    f          d   v
> A.1 A 2010-01-01 100
> A.2 A 2010-02-01 300
> B   B 2010-01-01 150
>
> This is exactly what I want, namely, cumulative sums by date.
>
> Can I be sure that the rows within subset A will be arranged in date order
> as they are in the original data frame? I would not want 'by' to randomly
> switch the order and create, for example,
>    f          d   v
> A.1 A 2010-02-01 200
> A.2 A 2010-01-01 300
> B   B 2010-01-01 150
>
> I could force the order of each subset within the FUN of by, adding to the
> execution time. Would that be advised?
>
> Thanks,
>
> Dan
>
>        [[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] Variable Combinations in Regression

2010-01-08 Thread Richardson, Patrick
Let's say I have 8 variables and I want to generate all combinations of those 
variables (In pairs, threes fours, etc) to run in multiple linear regression. 
Is there a built-in function to do that in R?

Or at a minimum, how could I take those variables and generate all possible 
combinations.

Thank you for any assistance.

Patrick


This email message, including any attachments, is for th...{{dropped:9}}

__
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] time series analysis for a time series without a regular frequency

2010-01-08 Thread Gabor Grothendieck
The zoo package supports irregularly spaced time series and if your
create a zoo object z from your data then tt <- as.ts(z) will give you
a ts object, tt.  Since a ts object must be regularly spaced this will
add NAs to ensure that it is.

On Fri, Jan 8, 2010 at 3:05 PM, Erin Hestir  wrote:
> Hello,
>
> I am trying to conduct a time series analysis on historic hydrologic data,
> but I cannot coerce it into class ts because it does not have regular
> sampling intervals (some years have 20 samples, other have 8). Specifically
> I am trying to perform a CUSUM or or other step change detection, but the
> packages all seem to require data as ts.
>
> Is there a way to coerce my data into ts while maintaining all of my
> samples?
>
> Or alternatively, can someone recommend a package that does not require data
> as ts?
>
> Thanks!
>
>
>
> --
> Erin Hestir
> Center for Spatial Technology and Remote Sensing
> University of California Davis
>
>        [[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.


Re: [R] Online R documentation

2010-01-08 Thread Peter Keller


Karl Ove Hufthammer wrote:
> 
> On Fri, 8 Jan 2010 10:03:31 -0500 Jonathan Baron  
> wrote:
>> > In case anybody is looking for ideas in how to improve the above 
>> > site, inclusion of rendered example graphs, similar to the ones at 
>> > "http://www.metaresearch.de/exlib/";, would be nice.
>> 
>> Why should I bother when the site exists!
> 
> Well, I was thinking of better integration with the help pages, e.g., 
> having each image appear right after the code that generated it, having 
> larger images (perhaps at approx. the default window size for graphs in 
> R?), and having all images for a given help page shown on the page, 
> instead of the user having to click on a PDF link to see them.
> 
>> What might be nice is for each site to mirror the other.  I can't find
>> in the web page the email address of the person in charge.  Is it you?
> 
> No. You can find the e-mail address of the author at 
> http://www.metaresearch.de/
> 
> -- 
> Karl Ove Hufthammer
> 
> __
> 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.
> 
> 

There is an extensive graphics gallery which does most, if not all, of this,
at http://bm2.genes.nig.ac.jp/RGM2/index.php?clear=all

It bills itself as the "R Graphical Manual, A collection of R graphics from
all R packages."  It's searchable and filterable by image, function,
package, task view, etc.  Pretty fabulous if you ask me.  At the moment,
it's only updated to 2.9.0.

Peter Keller
-- 
View this message in context: 
http://n4.nabble.com/Online-R-documentation-tp1009656p1009942.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.


Re: [R] Identifying outliers in non-normally distributed data

2010-01-08 Thread Jerry Floren

Thank you Kevin. I'm looking forward to trying your function when I get back
to the office. 

Jerry Floren
Minnesota Department of Agriculture


Kevin Wright-5 wrote:
> 
> Here is a simple function I use.  It uses Median +/- 5.2 * MAD.  If I
> recall, this flags about 1/2000 of values from a true Normal distribution.
> 
> is.outlier = function (x) {
> # See: Davies, P.L. and Gather, U. (1993).
> # "The identification of multiple outliers" (with discussion)
> # J. Amer. Statist. Assoc., 88, 782-801.
> 
> x <- na.omit(x)
> lims <- median(x) + c(-1, 1) * 5.2 * mad(x, constant = 1)
> x < lims[1] | x > lims[2]
> }
> 
> Maybe the function should be called "is.patentable".  I definitely agree
> with Bert's comments.
> 
> Kevin Wright
> 
> 
> 
> On Wed, Dec 30, 2009 at 11:47 AM, Jerry Floren
> wrote:
> 
>>
>> Greetings:
>>
>> I could also use guidance on this topic. I provide manure sample
>> proficiency
>> sets to agricultural labs in the United States and Canada. There are
>> about
>> 65 labs in the program.
>>
>> My data sets are much smaller and typically non-symmetrical with obvious
>> outliers. Usually, there are 30 to 60 sets of data, each with triple
>> replicates (90 to 180 observations).
>>
>> There are definitely outliers caused by the following: reporting in the
>> wrong units, sending in the wrong spreadsheet, entering data in the wrong
>> row, misplacing decimal points, calculation errors, etc. For each
>> analysis,
>> it is common that two to three labs make these types of errors.
>>
>> Since there are replicates, errors like misplaced decimal points are more
>> obvious. However, most of the outlier errors are repeated for all three
>> replicates.
>>
>> I use the median and Median Absolute Deviation (MAD, constant = 1) to
>> flag
>> labs for accuracy. Labs where the average of their three reps deviates
>> more
>> than 2.5 MAD values from the median are flagged for accuracy. With this
>> method, it is not necessary to identify the outliers.
>>
>> A collegue suggested running the data twice. On the first run, outliers
>> more
>> than 4.0 MAD units from the median are removed. On the second run, values
>> exceeding 2.9 times the MAD are flagged for accuracy. I tried this in R
>> with
>> a normally distributed data set of 100,000, and the 4.0 MAD values were
>> nearly identical to the outliers identified with boxplot.
>>
>> With my data set, the flags do not change very much if the data is run
>> one
>> time with the flags set at 2.5 MAD units compared to running the data
>> twice
>> and removing the 4.0 MAD outliers and flagging the second set at 2.9 MAD
>> units. Using either one of these methods might work for you, but I am not
>> sure of the statistical value of these methods.
>>
>> Yours,
>>
>> Jerry Floren
>>
>>
>>
>> Brian G. Peterson wrote:
>> >
>> > John wrote:
>> >> Hello,
>> >>
>> >> I've been searching for a method for identify outliers for quite some
>> >> time now. The complication is that I cannot assume that my data is
>> >> normally distributed nor symmetrical (i.e. some distributions might
>> >> have one longer tail) so I have not been able to find any good tests.
>> >> The Walsh's Test (http://www.statistics4u.info/
>> >> fundsta...liertest.html#), as I understand assumes that the data is
>> >> symmetrical for example.
>> >>
>> >> Also, while I've found some interesting articles:
>> >> http://tinyurl.com/yc7w4oq ("Missing Values, Outliers, Robust
>> >> Statistics & Non-parametric Methods")
>> >> I don't really know what to use.
>> >>
>> >> Any ideas? Any R packages available for this? Thanks!
>> >>
>> >> PS. My data has 1000's of observations..
>> >
>> > Take a look at package 'robustbase', it provides most of the standard
>> > robust
>> > measures and calculations.
>> >
>> > While you didn't say what kind of data you're trying to identify
>> outliers
>> > in,
>> > if it is time series data the function Return.clean in
>> > PerformanceAnalytics may
>> > be useful.
>> >
>> > Regards,
>> >
>> >- Brian
>> >
>> >
>> > --
>> > Brian G. Peterson
>> > http://braverock.com/brian/
>> > Ph: 773-459-4973
>> > IM: bgpbraverock
>> >
>> > __
>> > 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://n4.nabble.com/Identifying-outliers-in-non-normally-distributed-data-tp987921p991062.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.
>>
> 
> 
> 
> -- 
> Kevin Wright
> 
>   [[alte

[R] time series analysis for a time series without a regular frequency

2010-01-08 Thread Erin Hestir
Hello,

I am trying to conduct a time series analysis on historic hydrologic data,
but I cannot coerce it into class ts because it does not have regular
sampling intervals (some years have 20 samples, other have 8). Specifically
I am trying to perform a CUSUM or or other step change detection, but the
packages all seem to require data as ts.

Is there a way to coerce my data into ts while maintaining all of my
samples?

Or alternatively, can someone recommend a package that does not require data
as ts?

Thanks!



-- 
Erin Hestir
Center for Spatial Technology and Remote Sensing
University of California Davis

[[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] Using outer with function predict

2010-01-08 Thread Henrique Dallazuanna
Try this:

outer(x, y, FUN = function(x, y)predict(lm.1, data.frame(x, y)))


On Fri, Jan 8, 2010 at 5:49 PM, Etienne Stockhausen  wrote:
> Hey everybody,
>
> I have a problem with the combination of the commands outer() and predict(). 
> I want to visualize the solutions of a regression modell in a matrix. 
> Therefore I want to use the command predict for a linear modell as the 
> function inside the command outer. I've made a small example:
>
>          x = 1:10
>          y = 11:20
>          z = rnorm(10)
>          lm.1 = lm(z ~ x*y)
>          mat = outer(x,y, predict, lm.1)
>
> That didn't work, but I don't understand why? Isn't it possible to combine 
> these two commands? I hope my intention becomes clear.
> I'm looking forward for any ideas or hints, that might help me.
> I wish everybody a nice weekend.
>
> Best regards
>
> Etienne
> ___
> Preisknaller: WEB.DE DSL Flatrate für nur 16,99 Euro/mtl.!
> http://produkte.web.de/go/02/
>
>
> __
> 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] Using outer with function predict

2010-01-08 Thread Etienne Stockhausen
Hey everybody,

I have a problem with the combination of the commands outer() and predict(). I 
want to visualize the solutions of a regression modell in a matrix. Therefore I 
want to use the command predict for a linear modell as the function inside the 
command outer. I've made a small example:

  x = 1:10
  y = 11:20
  z = rnorm(10)
  lm.1 = lm(z ~ x*y)
  mat = outer(x,y, predict, lm.1) 

That didn't work, but I don't understand why? Isn't it possible to combine 
these two commands? I hope my intention becomes clear. 
I'm looking forward for any ideas or hints, that might help me. 
I wish everybody a nice weekend.

Best regards

Etienne
___
Preisknaller: WEB.DE DSL Flatrate für nur 16,99 Euro/mtl.! 
http://produkte.web.de/go/02/

__
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] plyr: issue with column names when converting one element list to dataframe

2010-01-08 Thread hadley wickham
Hi Mark,

It'll be fixed in the next version of plyr.  If you want to fix it
yourself, inspect the source of list_to_dataframe and change the first
data.frame to as.data.frame.

Hadey

On Wed, Jan 6, 2010 at 8:53 AM, Mark Heckmann  wrote:
> Hadley,
>
> thanks for the quick reply:
>
>> dput(l)
> list(structure(c(0.182198327359618, 0.473715651135006, 0.29689366786141,
> 0.0471923536439665), .Dim = c(1L, 4L), .Dimnames = list("f5_9",
>    c("(0.5,1.5]", "(1.5,2.5]", "(2.5,3.5]", "(3.5,4.5]"
>
> Mark
>
>
> Am 06.01.2010 um 15:48 schrieb hadley wickham:
>
>> Hi Mark,
>>
>> Could you send a the results of dput(l)?  It will make exploration easier.
>>
>> Hadley
>>
>> On Wed, Jan 6, 2010 at 8:07 AM, Mark Heckmann 
>> wrote:
>>>
>>> Hi,
>>>
>>> I have an issue concerning plyr.
>>> I have a list l as output from dlply.
>>>
 l
>>>
>>> $`1`
>>>    (0.5,1.5] (1.5,2.5] (2.5,3.5]  (3.5,4.5]
>>> f5_9 0.2342569  0.465995 0.2518892 0.04785894
>>>
>>> attr(,"split_type")
>>> [1] "data.frame"
>>> attr(,"split_labels")
>>>  f15
>>> 1   1
>>>
>>> When I convert it into a dataframe I get.
>>>
 list_to_dataframe(l)
>>>
>>>  .id X.0.5.1.5. X.1.5.2.5. X.2.5.3.5. X.3.5.4.5.
>>> 1   1  0.2342569   0.465995  0.2518892 0.04785894
>>>
>>> The column labels have names I do not want.
>>> When I do the same using two list elements everything is fine, that is
>>> column names are as desired.
>>>
 l2 <- c(l,l)
 list_to_dataframe(l2)
>>>
>>>  .id (0.5,1.5] (1.5,2.5] (2.5,3.5]  (3.5,4.5]
>>> 1   1 0.2342569  0.465995 0.2518892 0.04785894
>>> 2   1 0.2342569  0.465995 0.2518892 0.04785894
>>>
>>> Does someone know a remedy?
>>>
>>> TIA,
>>> Mark
>>>
>>>
 Mark Heckmann
 Dipl. Wirt.-Ing. cand. Psych.
 Vorstraße 93 B01
 28359 Bremen
 Blog: www.markheckmann.de
 R-Blog: http://ryouready.wordpress.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.
>>>
>>
>>
>>
>> --
>> http://had.co.nz/
>
>



-- 
http://had.co.nz/

__
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] function by: order within subsets

2010-01-08 Thread Henrique Dallazuanna
Try this:

transform(df, v = unlist(with(df, tapply(v, f, cumsum

On Fri, Jan 8, 2010 at 4:10 PM, Daniel Murphy  wrote:
> When the 'by' function forms subsets, are the rows in the same order as they
> are in the original data frame?
>
> For example, I want to use 'by' to calculate cumulative sums of a value 'v'
> by date 'd' for different levels of a factor 'f':
>
>>
> df<-data.frame(f=c("A","A","B"),d=as.Date(c("2010-1-1","2010-2-1","2010-1-1")),v=c(100,200,150))
>> df
>  f          d   v
> 1 A 2010-01-01 100
> 2 A 2010-02-01 200
> 3 B 2010-01-01 150
>> do.call(rbind,by(df,df$f,FUN=function(x)
> data.frame(x[1],x[2],cumsum(x[3]
>    f          d   v
> A.1 A 2010-01-01 100
> A.2 A 2010-02-01 300
> B   B 2010-01-01 150
>
> This is exactly what I want, namely, cumulative sums by date.
>
> Can I be sure that the rows within subset A will be arranged in date order
> as they are in the original data frame? I would not want 'by' to randomly
> switch the order and create, for example,
>    f          d   v
> A.1 A 2010-02-01 200
> A.2 A 2010-01-01 300
> B   B 2010-01-01 150
>
> I could force the order of each subset within the FUN of by, adding to the
> execution time. Would that be advised?
>
> Thanks,
>
> Dan
>
>        [[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.
>



-- 
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] Arguments of a function

2010-01-08 Thread Henrique Dallazuanna
Try this:

my.f <- function(a, b) {
x1 <- 2 * 3
  x2 <- 3 / 6
  x3 <- 4 * 4 / 5 - sqrt(2)
y <- get(deparse(substitute(a))) + get(deparse(substitute(b)))
return(y)
}

my.f(x1, x2)

On Fri, Jan 8, 2010 at 4:15 PM, Lisa  wrote:
>
> Dear all,
>
> I have a question about how to set arguments in my own function. For
> example, I have a function that looks like this:
>
> my.f <- function(a = x1, b = x2)
> {
>   x1 = equation 1
>   x2 = equation 2
>   x3 = equation 3
>   y = a + b
> }
>
> x1, x2, and x3 are temporary variables (intermediate results) calculated
> from other variables within the funciton. I want to use two of these three
> variables to calculate y, and write R script as below:
>
> my.f(a = x1, b = x2)
>
> or
>
> my.f(a = x2, b = x3)
>
> The error information shows that: “objects 'x1', 'x2', or 'x3' not found”.
>
> Can anybody help me solve this problem? Thanks in advance.
>
> Lisa
>
> --
> View this message in context: 
> http://n4.nabble.com/Arguments-of-a-function-tp1009883p1009883.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.
>



-- 
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] Panel order in lattice with xyplot

2010-01-08 Thread Carol

Dear all, 

I am a new user of R  ;-) (I started three months ago) and I am going very
slow….
I am using lattice and am trying to draw a multipanel figure. The problems
are that I am not able to find out how to: 
1. Set the order of the panels.
2. Set the order of the x axes.
:rules:

The codes I am using are: 
 
Benthic<- read.table(file="WWTP 1 WICK 5.txt",header = TRUE)
library(lattice)
 xyplot(Concentration ~ Day | Pharmaceutical,
 layout = c (3,4),
  scales = list(x = list(rot = 45)),
groups= Month, data = Benthic,  main="Wick WWTP",
   xlab =  "Colection time (Days)",
ylab = "Concentration (ng/L)",
  ylim= c(1000,-100),
   auto.key=list(space = "right"),# añade la leyenda
par.settings = simpleTheme(pch=1:2),
panel=function(x,y,...) {
 panel.superpose(x,y,...)
 panel.superpose(x,y,panel.groups="panel.lmline",...)})


Thanks in advance, 
Carol
-- 
View this message in context: 
http://n4.nabble.com/Panel-order-in-lattice-with-xyplot-tp1009866p1009866.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] postscript, greek lellters

2010-01-08 Thread bernardo lagos alvarez
Dear useRs,

How can I, writting the correct greek letter using postscrip or pdf function.

In my  figures appears  only the first letter  (a of alpha, n of nu)
when include the graphs in my .tex doxument. I am using

title( expression(bar(T)(paste(-x,";",alpha))-G(paste(x,";",alpha,",",J
title( expression(bar(T)(paste(-x,";"~alpha))-G(paste(x,";"~alpha,",",J
title( expression(bar(T)(paste(-x,";"*alpha))-G(paste(x,";"*alpha,",",J,
not work.

>sessionInfo()
R version 2.9.0 (2009-04-17)
i386-pc-mingw32

locale:
LC_COLLATE=Spanish_Spain.1252;LC_CTYPE=Spanish_Spain.1252;LC_MONETARY=Spanish_Spain.1252;LC_NUMERIC=C;LC_TIME=Spanish_Spain.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base


Thanks for your help,

Bernardo.

__
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] can´t start help in Win7

2010-01-08 Thread Daniel Victoria
Just installed R 2.10.1 in win7 and when I try to run help.start() firefox will
pop up but display an error saying it could not find the url
http://127.0.0.1:16396/doc/html/index.html and that permission is denied.

Has anyone seen this? How can I fix it?

Thanks
daniel

__
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] A question about the ff package

2010-01-08 Thread OS
Thank you Jens. I will try your solutions and post the solutions/problems I
have.
Cheers
Peter

2010/1/7 Jens Oehlschlägel 

> Peter,
>
> ff objects are not allowed as subscripts to ff objects. You can take
> several routes
>
> 1) use bit objects instead of logical or ff logical. This is fast and takes
> factor 32 less RAM than logicals (BTW bit objects can be coerced to ff via
> as.ff() and as.bit() but they convert to vmode "boolean" (1 bit), not
> "logical" (2 bits). Examples for working with bit are on
> http://ff.r-forge.r-project.org/ff&bit_UseR!2009.pdf
>
> 2) convert your logicals into positive integer subscripts (assuming that
> there are not too many elements selected, as you assume if writing
> bigData[select,]
>
> 3) keep your logical in a ff logical or ff boolean and then do chunked
> looping over both - the ff with the subscripts and the ffdf - and in each
> chunk convert the logical selection to integers, see 2)
>
> HTH
>
>
> Jens Oehlschlägel
>
>
> P.S. you  might want to try the newer version on r-forge. It has several
> improvements but is not yet on CRAN because there is currently some issue
> with snow leopard.
>
>

[[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] function by: order within subsets

2010-01-08 Thread Daniel Murphy
When the 'by' function forms subsets, are the rows in the same order as they
are in the original data frame?

For example, I want to use 'by' to calculate cumulative sums of a value 'v'
by date 'd' for different levels of a factor 'f':

>
df<-data.frame(f=c("A","A","B"),d=as.Date(c("2010-1-1","2010-2-1","2010-1-1")),v=c(100,200,150))
> df
  f  d   v
1 A 2010-01-01 100
2 A 2010-02-01 200
3 B 2010-01-01 150
> do.call(rbind,by(df,df$f,FUN=function(x)
data.frame(x[1],x[2],cumsum(x[3]
f  d   v
A.1 A 2010-01-01 100
A.2 A 2010-02-01 300
B   B 2010-01-01 150

This is exactly what I want, namely, cumulative sums by date.

Can I be sure that the rows within subset A will be arranged in date order
as they are in the original data frame? I would not want 'by' to randomly
switch the order and create, for example,
f  d   v
A.1 A 2010-02-01 200
A.2 A 2010-01-01 300
B   B 2010-01-01 150

I could force the order of each subset within the FUN of by, adding to the
execution time. Would that be advised?

Thanks,

Dan

[[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] Newbie question on precision

2010-01-08 Thread Magnus Torfason

On 1/8/2010 1:29 PM, Magnus Torfason wrote:

Paul Evans wrote:

How can I get R to change the default precision value? For example:

x=0.9
1-x

[1] 0

Is there a way that I can get a non-zero value using some parameter,
or some package?
many thanks.


The 'gmp' package allows calculation with arbitrary precision rationals
(and every finite-digit decimal is a rational).

See a recent post of mine, listing some gmp examples:
http://tolstoy.newcastle.edu.au/R/e9/help/10/01/0579.html


And some more looking uncovered the 'Rmpfr' package, which allows 
arbitrary precision floating point calculations. Example:


> x = mpfr("0.9", precBits=100)
> x
1 'mpfr' number of precision  100   bits
[1] 0.8944
> 1-x
1 'mpfr' number of precision  100   bits
[1] 1.0556923992179579934e-17

It does not store decimals exactly (as a rational would), because the 
exponent is base 2 rather than base 10. However, it has parsing and 
as.string functions that return decimal-formatted strings (whereas the 
bigq class in gmp would require such functions to be written manually). 
I guess for people who are looking for arbitrary precision decimal 
fractions the the choice of these packages becomes a choice of style or 
specific application needs.


Best,
Magnus

__
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] Arguments of a function

2010-01-08 Thread Lisa

Dear all,

I have a question about how to set arguments in my own function. For
example, I have a function that looks like this:

my.f <- function(a = x1, b = x2)
{
   x1 = equation 1
   x2 = equation 2
   x3 = equation 3
   y = a + b   
}

x1, x2, and x3 are temporary variables (intermediate results) calculated
from other variables within the funciton. I want to use two of these three
variables to calculate y, and write R script as below:

my.f(a = x1, b = x2)
 
or 

my.f(a = x2, b = x3)

The error information shows that: “objects 'x1', 'x2', or 'x3' not found”. 

Can anybody help me solve this problem? Thanks in advance.

Lisa

-- 
View this message in context: 
http://n4.nabble.com/Arguments-of-a-function-tp1009883p1009883.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.


Re: [R] Strange behaviour of as.integer()

2010-01-08 Thread Ted Harding
See below.

>> From: r-help-boun...@r-project.org 
>> [mailto:r-help-boun...@r-project.org] On Behalf Of Ulrich Keller
>> Sent: Thursday, January 07, 2010 4:32 AM
>> To: r-help@r-project.org
>> Subject: [R] Strange behaviour of as.integer()
>> 
>> I have encountered a strange behaviour of as.integer() which does not
>> seem correct to me. Sorry if this is just an indication of me not
>> understanding floating point arithmetic.
>> 
>> > .57 * 100
>> [1] 57
>> > .29 * 100
>> [1] 29
>> 
>> So far, so good. But:
>> 
>> > as.integer(.57 * 100)
>> [1] 56
>> > as.integer(.29 * 100)
>> [1] 28
>> 
>> Then again:
>> 
>> > all.equal(.57 * 100, as.integer(57))
>> [1] TRUE
>> > all.equal(.29 * 100, as.integer(29))
>> [1] TRUE
>> 
>> This behaviour is the same in R 2.10.1 (Ubuntu and Windows) and 2.9.2
>> (Windows), all 32 bit versions. Is this really intended?

I would like to add a salutory tail-piece to this correspondence.
It is a simple recursive calculation which, after not many steps,
R will in almost all cases get badly wrong as a result of the
finite binary representation of fractions. (I have posted it before,
some years ago, but it may be worth bringing it back since it shows
very vividly what can go wrong if you do not pay attention to this
aspect of numerical computation).

Working in the interval [0,1], X[n+1] is calculated from x[n]
according to:

  if 0 <= X[n] <= 1/2 then X[n+1] = 2*X[n]
  if 1/2 <= X[n] <= 1 then X[n+1] = 2*(1 - X[n])

X = 2/3 is a fixed point of this, since 2/3 -> 2*(1 - 2/3) = 2/3;
X = 2/5 -> 4/5 -> 2*(1 - 4/5) = 2/5 has period 2;
X = 2/7 -> 4/7 -> 2*(1 - 4/7) = 6/7 -> 2*(1 - 6/7) = 2/7 (period 3)
and so on.

All fractions which are multiples of 1/(2^k) for some k>0 eventually
end up at 0 and stay there. Irrational numbers, mathematically,
never repeat.

However, none of the above periodic numbers 2/(2*m + 1) can be
represented exactly in a finite binary representation, and that is
where the trouble starts. So, in R:

  nextX <- function(x){if(x <= 0.5) (2*x) else (2*(1 - x))}

Now try the fixed point x=2/3:

  i<-0; x<-2/3; while(x>0){i<-(i+1); x<-nextX(x) ; print(c(i,x))}

of which the last few lines are:

  [1] 46.000  0.6640625
  [1] 47.00  0.671875
  [1] 48.0  0.65625
  [1] 49.  0.6875
  [1] 50.000  0.625
  [1] 51.00  0.75
  [1] 52.0  0.5
  [1] 53  1
  [1] 54  0

Similarly try any of the other periodic values, e.g.

  i<-0; x<-2/11; while(x>0){i<-(i+1); x<-nextX(x) ; print(c(i,x))}

They will all halt at x=0 after 50-55 iterations. Similarly
a non-periodic number such as 1/sqrt(2) or 1/pi will also fail.

Thus the results of such calculations will eventually be grossly
wrong. So do not try this kind of calculation in R! -- at any rate
not without adopting special measures. For instance, it would be
possible, for rational x = m/n, to program a function which kept
track of M and N in the rational expression M/N of the result after
each iteration, by working out what M and N would be. Then, at any
iteration, the numerical value of M/N could be computed (to within
the precision used by R) and returned.

This would still give wrong answers for irrational starting numbers,
since they would have to be stored as rational approximations and
then would either end up at 0 or be periodic while the mathematical
result would never repeat, so eventually they would be arbitrarily
far apart (within [0,1]).

Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 08-Jan-10   Time: 18:13:41
-- XFMail --

__
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 to get perfect fit of lm if response is constant

2010-01-08 Thread Peter Ehlers

You need to review the assumptions of linear models:
y is assumed to be the realization of a random variable,
not a constant (or, more precisely: there are assumed to
be deviations that are N(0, sigma^2).

If you 'know' that y is a constant, then you have
two options:

1. don't do the regression because it makes no sense;
2. if you want to test lm()'s handling of the data:

fm <- lm(y ~ x, data = df, offset = rep(1, nrow(df)))

(or use: offset = y)

 -Peter Ehlers

Jan-Henrik Pötter wrote:

Hello.

Consider the response-variable of data.frame df is constant, so analytically
perfect fit of a linear model is expected. Fitting a regression line using
lm result in residuals, slope and std.errors not exactly zero, which is
acceptable in some way, but errorneous. But if you use summary.lm it shows
inacceptable error propagation in the calculation of the t value and the
corresponding p-value for the slope, as well R-Square – just consider the
adj R-Square of 0.6788! This result is independent of which mode used for
the input vectors. Is there any way to get the perfect fitted regression
curve using lm and prevent this error propagation? I consider rounding all
values of the lm-object afterwards to somewhat precision as a bad idea.
Unfortunately there is no option in lm for calculation precision. 

 


df<-data.frame(x=1:10,y=1)



myl<-lm(y~x,data=df)


 


myl


 


Call:

lm(formula = y ~ x, data = df)

 


Coefficients:

(Intercept)x  

  1.000e+009.463e-18  

 


summary(myl)


 


Call:

lm(formula = y ~ x, data = df)

 


Residuals:

   Min 1Q Median 3QMax 

-1.136e-16 -1.341e-17  7.886e-18  2.918e-17  5.047e-17 

 


Coefficients:

 Estimate Std. Error   t value Pr(>|t|)


(Intercept) 1.000e+00  3.390e-17 2.950e+16   <2e-16 ***

x   9.463e-18  5.463e-18 1.732e+000.122


---

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

 


Residual standard error: 4.962e-17 on 8 degrees of freedom

Multiple R-squared: 0.7145, Adjusted R-squared: 0.6788 


F-statistic: 20.02 on 1 and 8 DF,  p-value: 0.002071

 



[[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.


--
Peter Ehlers
University of Calgary
403.202.3921

__
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] Newbie question on precision

2010-01-08 Thread Magnus Torfason

Paul Evans wrote:

How can I get R to change the default precision value? For example:

x=0.9
1-x

[1] 0

Is there a way that I can get a non-zero value using some parameter, or some 
package?
many thanks.


The 'gmp' package allows calculation with arbitrary precision rationals 
(and every finite-digit decimal is a rational).


See a recent post of mine, listing some gmp examples:
http://tolstoy.newcastle.edu.au/R/e9/help/10/01/0579.html

__
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] Newbie question on precision

2010-01-08 Thread jim holtman
FAQ 7.31

The precision of a floating point number is about 16 digits and your 'x' is
at that limit.  If you reduce it, you will see a result:

> x=0.9
> 1-x
[1] 0
> print(1-x, digits=20)
[1] 0
> x=0.99
> print(1-x, digits=20)
[1] 0.00999200722162641
>


On Fri, Jan 8, 2010 at 11:56 AM, Paul Evans  wrote:

> Hi all,
>
> How can I get R to change the default precision value? For example:
> > x=0.9
> > 1-x
> [1] 0
> >
>
>
> Is there a way that I can get a non-zero value using some parameter, or
> some package?
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[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] Newbie question on precision

2010-01-08 Thread Ted Harding
On 08-Jan-10 16:56:25, Paul Evans wrote:
> Hi all,
> How can I get R to change the default precision value? For example:
>> x=0.9
>> 1-x
> [1] 0
> 
> Is there a way that I can get a non-zero value using some parameter,
> or some package?
> many thanks.

The problem here is that, as far as R in concerned, once you have entered
  x=0.9
then x is *exactly* 1. Namely, your x is 1 - 1e-17, and the two things
you need to take note of are:

  .Machine$double.eps
  # [1] 2.220446e-16
  .Machine$double.neg.eps
  # [1] 1.110223e-16

and the descriptions in ?.Machine which say:

  "double.eps: the smallest positive floating-point number 'x'
   such that '1 + x != 1'."

  "double.neg.eps: a small positive floating-point number 'x'
   such that '1 - x != 1'. "

Both of these (in particular "double.neg.eps") are greater
than 1e-17, so your x was stored as 0.

I believe there may be packages which can work to greater precision,
but I have to leave it to others to describe them (if any).

Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 08-Jan-10   Time: 17:39:47
-- XFMail --

__
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] Directory operations

2010-01-08 Thread jim holtman
?list.files
?file.info
?setwd

You can get a list of all the files in a directory (list.files) and then do
a file.info to determine which ones are the directories you want to search.
A list.files on that directory will give you the list of file names that you
can then process.




On Fri, Jan 8, 2010 at 12:41 PM, anupam sinha wrote:

> Dear all,
>  I have this directory structure :
>
> Dir1   Dir2   Dir3  Dir4  .
> A.xml D.xmlG.xml
> B.xml E.xml H.xml
> C.xml F.xml I.xml
>
> Within each of these directories (Dir1, Dir2 etc) there are a num of xml
> files (A.xml, B.xml etc).
>
> What I want to do is to enter into the first directory read all the xml
> files do certain operations come out  of the directory and do the same
> thing
> for another directory. Can anyone help me out ? Thanks in advance for any
> suggestions.
>
> Regards,
>
> Anupam Sinha
>
>[[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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[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] Directory operations

2010-01-08 Thread anupam sinha
Dear all,
  I have this directory structure :

Dir1   Dir2   Dir3  Dir4  .
A.xml D.xmlG.xml
B.xml E.xml H.xml
C.xml F.xml I.xml

Within each of these directories (Dir1, Dir2 etc) there are a num of xml
files (A.xml, B.xml etc).

What I want to do is to enter into the first directory read all the xml
files do certain operations come out  of the directory and do the same thing
for another directory. Can anyone help me out ? Thanks in advance for any
suggestions.

Regards,

Anupam Sinha

[[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] how to flatten a list to the same level?

2010-01-08 Thread Henrique Dallazuanna
Try something about like this:

split(unlist(l), rep(1:length(idx <- rapply(l, length)), idx))

On Fri, Jan 8, 2010 at 1:35 PM, Mark Heckmann  wrote:
> I have a nested list l like:
>
> l <- list(A=c(1,2,3), B=c("a", "b"))
> l <- list(l,l, list(l,l))
>
> I want the list to be unlisted, but not on the lowest level of each
> "branch".
> I want the lowest level of each list branch to remain as it is.
> So unlist or unlist(rec=F) do not work here as the level of nesting may
> differ on the elements.
> The result should look like:
>
> $A
> [1] 1 2 3
>
> $B
> [1] "a" "b"
>
> $A
> [1] 1 2 3
>
> $B
> [1] "a" "b"
>
> $A
> [1] 1 2 3
>
> $B
> [1] "a" "b"
>
> $A
> [1] 1 2 3
>
> $B
> [1] "a" "b"
>
> Any ideas?
> TIA!
>
> Mark
>
>
> –––
> Mark Heckmann
> Dipl. Wirt.-Ing. cand. Psych.
> Vorstraße 93 B01
> 28359 Bremen
> Blog: www.markheckmann.de
> R-Blog: http://ryouready.wordpress.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.
>



-- 
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] Newbie question on precision

2010-01-08 Thread Paul Evans
Hi all,

How can I get R to change the default precision value? For example:
> x=0.9
> 1-x
[1] 0
> 


Is there a way that I can get a non-zero value using some parameter, or some 
package?
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] how to get perfect fit of lm if response is constant

2010-01-08 Thread Jan-Henrik Pötter
Hello.

Consider the response-variable of data.frame df is constant, so analytically
perfect fit of a linear model is expected. Fitting a regression line using
lm result in residuals, slope and std.errors not exactly zero, which is
acceptable in some way, but errorneous. But if you use summary.lm it shows
inacceptable error propagation in the calculation of the t value and the
corresponding p-value for the slope, as well R-Square – just consider the
adj R-Square of 0.6788! This result is independent of which mode used for
the input vectors. Is there any way to get the perfect fitted regression
curve using lm and prevent this error propagation? I consider rounding all
values of the lm-object afterwards to somewhat precision as a bad idea.
Unfortunately there is no option in lm for calculation precision. 

 

> df<-data.frame(x=1:10,y=1)

> myl<-lm(y~x,data=df)

 

> myl

 

Call:

lm(formula = y ~ x, data = df)

 

Coefficients:

(Intercept)x  

  1.000e+009.463e-18  

 

> summary(myl)

 

Call:

lm(formula = y ~ x, data = df)

 

Residuals:

   Min 1Q Median 3QMax 

-1.136e-16 -1.341e-17  7.886e-18  2.918e-17  5.047e-17 

 

Coefficients:

 Estimate Std. Error   t value Pr(>|t|)

(Intercept) 1.000e+00  3.390e-17 2.950e+16   <2e-16 ***

x   9.463e-18  5.463e-18 1.732e+000.122

---

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

 

Residual standard error: 4.962e-17 on 8 degrees of freedom

Multiple R-squared: 0.7145, Adjusted R-squared: 0.6788 

F-statistic: 20.02 on 1 and 8 DF,  p-value: 0.002071

 


[[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] svm

2010-01-08 Thread Amy Hessen

Hi Steve,

 

Thank you very much for your reply. Your code is more readable and obvious than 
mine…
 
Could you please help me in these questions?:
 
1) “Formula” is an alternative to “y” parameter in SVM. is it correct?
 
2) I forgot to remove the “class label” from the dataset besides I gave the 
program the class label in formula parameter but the program works! Could you 
please clarify this point to me?
 
Cheers,
Amy
 

> Date: Wed, 6 Jan 2010 18:44:13 -0500
> Subject: Re: [R] svm
> From: mailinglist.honey...@gmail.com
> To: amy_4_5...@hotmail.com
> CC: r-help@r-project.org
> 
> Hi Amy,
> 
> On Wed, Jan 6, 2010 at 4:33 PM, Amy Hessen  wrote:
> > Hi Steve,
> >
> > Thank you very much for your reply.
> >
> > I’m trying to do something systematic/general in the program so that I can
> > try different datasets without changing much in the program (without knowing
> > the name of the class label that has different name from dataset to
> > another…)
> >
> > Could you please tell me your opinion about this code:-
> >
> > library(e1071)
> >
> > mydata<-read.delim("the_whole_dataset.txt")
> >
> > class_label <- names(mydata)[1]# I’ll always put the
> > class label in the first column.
> >
> > myformula <- formula(paste(class_label,"~ ."))
> >
> > x <- subset(mydata, select = - mydata[, 1])
> >
> > mymodel<-(svm(myformula, x, cross=3))
> >
> > summary(model)
> >
> > 
> 
> Since you're not doing anything funky with the formula, a preference
> of mine is to just skip this way of calling SVM and go "straight" to
> the svm(x,y,...) method:
> 
> R> mydata <- as.matrix(read.delim("the_whole_dataset.txt"))
> R> train.x <- mydata[,-1]
> R> train.y <- mydata[,1]
> 
> R> mymodel <- svm(train.x, train.y, cross=3, type="C-classification")
> ## or
> R> mymodel <- svm(train.x, train.y, cross=3, type="eps-regression")
> 
> As an aside, I also like to be explicit about the type="" parameter to
> tell what I want my SVM to do (regression or classification). If it's
> not specified, the SVM picks which one to do based on whether or not
> your y vector is a vector of factors (does classification), or not
> (does regression)
> 
> > Do I have to the same steps with testingset? i.e. the testing set must not
> > contain the label too? But contains the same structure as the training set?
> > Is it correct?
> 
> I guess you'll want to report your accuracy/MSE/something on your
> model for your testing set? Just load the data in the same way then
> use `predict` to calculate the metric your after. You'll have to have
> the labels for your data to do that, though, eg:
> 
> testdata <- as.matrix(read.delim('testdata.txt'))
> test.x <- testdata[,-1]
> test.y <- testdata[,1]
> preds <- predict(mymodel, test.x)
> 
> Let's assume you're doing classification, so let's report the accuracy:
> 
> acc <- sum(preds == test.y) / length(test.y)
> 
> Does that help?
> -steve
> 
> -- 
> Steve Lianoglou
> Graduate Student: Computational Systems Biology
> | Memorial Sloan-Kettering Cancer Center
> | Weill Medical College of Cornell University
> Contact Info: http://cbio.mskcc.org/~lianos/contact
  
_
[[elided Hotmail spam]]

[[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] Ridge regression

2010-01-08 Thread Eleni Christodoulou
Thanks a lot!
Eleni

On Fri, Jan 8, 2010 at 6:35 PM, Ravi Varadhan  wrote:

>  Yes, you need to have the intercept term when you predict model-based
> response.
>
>
>
> This is what you need:
>
>
>
> * ridge.test=lm.ridge(tey_values~tedata, lambda)*
>
> * *
>
> *   yest <- drop(cbind(1, tedata) %*% coef(ridge.test))*
>
>
>
> Hope this helps,
>
> Ravi.
>
>
> ---
>
> Ravi Varadhan, Ph.D.
>
> Assistant Professor, The Center on Aging and Health
>
> Division of Geriatric Medicine and Gerontology
>
> Johns Hopkins University
>
> Ph: (410) 502-2619
>
> Fax: (410) 614-9625
>
> Email: rvarad...@jhmi.edu
>
> Webpage:
> http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.html
>
>
>
>
> 
>
> *From:* Eleni Christodoulou [mailto:elenic...@gmail.com]
> *Sent:* Friday, January 08, 2010 11:18 AM
> *To:* Ravi Varadhan
> *Cc:* David Winsemius; r-help@r-project.org
>
> *Subject:* Re: [R] Ridge regression
>
>
>
> I am sorry, I just pressed the "send" button by accident before completing
> my e-mail. The yest are the estimated values according to the ridge model.
> Is the way that I calculate them correct? Or should I cut the 
> *+coef(ridge.test)[1]
> *term?
>
> Thanks a lot!
> Eleni
>
> On Fri, Jan 8, 2010 at 6:16 PM, Eleni Christodoulou 
> wrote:
>
> Hello again and Happy 2010!
> I was looking back at this email because I need to do some additional
> processing now. I was thinking that if I take the coef(ans) I get n+1
> coefficients. I guess that the coef(ans)[1] is the constant term... Do I
> need to add it when I calculate the estimated value for the outcome?
> For example, lets say that I have divided my data into training data and
> test data and I have the corresponding observed try_values and tey_values
> (the real values for the samples that belong to the training set and the
> test set respectively)
> Here is my code:
> *
> library(MASS)
>  ridge.test=lm.ridge(tey_values~tedata,lambda)
> est<-list()
> yest<-numeric()
> for(i in 1:length(tey_values)){
> est[[i]]=coef(ridge.test)[-1]*tedata[i,]
> yest[i]=sum(est[[i]])+coef(ridge.test)[1]
> }*
>
>
>
>  On Wed, Dec 2, 2009 at 8:22 PM, Ravi Varadhan  wrote:
>
> The help page clearly states that ans$coef is "not on the original scale
> and
> are for use by the coef method".  You also see that ans$scales gives you
> the
> scales used in the computation of ans$coef.
>
> So, to get coefficients on the original scale, you can either use coef(ans)
> or you can divide ans$coef by ans$scales.
>
>
> X1 <- runif(20)
> X2 <- runif(20)
> Y <- 2 * X1 - 2 * X2 + rnorm(20, sd=0.1)
>
> lam <- 10
> ans1 <- lm.ridge(Y ~ X1 + X2, lambda = lam)
>
> all.equal(ans1$coef / ans1$scales, coef(ans1)[2:3] )
>
> Hope this helps,
>
> Ravi.
>
>
> 
> ---
>
> Ravi Varadhan, Ph.D.
>
> Assistant Professor, The Center on Aging and Health
>
> Division of Geriatric Medicine and Gerontology
>
> Johns Hopkins University
>
> Ph: (410) 502-2619
>
> Fax: (410) 614-9625
>
> Email: rvarad...@jhmi.edu
>
> Webpage:
>
> http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
> tml
>
>
>
>
> 
> 
>
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On
>
> Behalf Of Ravi Varadhan
> Sent: Wednesday, December 02, 2009 12:25 PM
> To: 'David Winsemius'; 'Eleni Christodoulou'
> Cc: r-help@r-project.org
> Subject: Re: [R] Ridge regression
>
> You are right that the ans$coef and coef(ans) are different in ridge
> regression, where `ans' is the object from lm.ridge.  It is the coef(ans)
> that yields the coefficients on the original scale.  ans$coef is the
> coefficient of "X-scaled" and "Y-centered" version.
>
> Here is an example that illustrates the workings of ridge regression.
>
> First let us create some data:
>
> X1 <- runif(20)
> X2 <- runif(20)
> Y <- 2 * X1 - 2 * X2 + rnorm(20, sd=0.1)
>
> lam <- 10
> ans1 <- lm.ridge(Y ~ X1 + X2, lambda = lam)
> ans1$coef
> coef(ans1)
> # Note that these two are different
>
> # Now Let us scale the variables X1 and X2 and center Y
> #
> cY <- scale(Y, scale=FALSE)
> n <- length(Y)
> sX1 <- scale(X1) * sqrt(n/(n-1))
> sX2 <- scale(X2) *  sqrt(n/(n-1))
>
> require(MASS)
>
> lam <- 10
> ans2 <- lm.ridge(cY ~ sX1 + sX2, lambda = lam)
>
> ans2$coef
> coef(ans2)
> # Now, see that the coefficients of sX1 and sX2 are the same
> # This is the connection!
>
> # Armed with this insight, we now compare the ans1$coef with scaled
> coefficients
> #
> ans1$coef
> c(coef(ans1)[2] * sd(X1), coef(ans1)[3] * sd(X2)) * sqrt((n-1)/n)
>
> # Now they are the same!

Re: [R] February 2010***New R Courses*** by XLSolutions Corp at 9 USA Cities: San Francisco, New York, Washington DC, Houston, Boston, Las Vegas, Seattle, etc

2010-01-08 Thread Sue Turner
Greetings Milton,

Our R-PLUS has features of S-PLUS and we use it to teach and those with
laptops without S-PLUS get R-PLUS.
Get a free trial of  R-PLUS at:

www.xlsolutions-corp.com/order

Regards - Sue

>  Original Message 
> Subject: Re: [R] February 2010***New R Courses*** by XLSolutions Corp
> at 9 USA  Cities: San Francisco, New York, Washington DC, Houston,
> Boston, Las Vegas,  Seattle, etc
> From: milton ruser 
> Date: Thu, January 07, 2010 7:29 pm
> To: Sue Turner 
> Cc: r-help@r-project.org
> Dear Sue,
> Happy new your to you too.
> You will offer the course on R or S-Plus? If S-plus is the case, how deal
> with license?
> bests
> milton
> On Wed, Jan 6, 2010 at 3:24 PM, Sue Turner  wrote:
> > Happy New Year !
> >
> > XLSolutions February 2010 R courses schedule is now available online at
> > 9
> > USA cities for with 13 new courses: *** Suggest a future course
> > date/city
> >
> > (1) R-PLUS: A Point-and-Click Approach to R
> > (2) S-PLUS / R : Programming Essentials.
> > (3) R/S+ Fundamentals and Programming Techniques
> > (4) R/S-PLUS Functions by Example.
> > (5) S/R-PLUS Programming 3: Advanced Techniques and Efficiencies.
> > (6) R/S+ System: Advanced Programming.
> > (7) R/S-PLUS Graphics: Essentials.
> > (8) R/S-PLUS Graphics for SAS Users
> > (9) R/S-PLUS Graphical Techniques for Marketing Research.
> > (10) Multivariate Statistical Methods in R/S-PLUS: Practical Research
> > Applications
> > (11) Introduction to Applied Econometrics with R/S-PLUS
> > (12) Exploratory Analysis for Large and Complex Problems in R/S-PLUS
> > (13) Determining Power and Sample Size Using R/S-PLUS.
> > (14) R/S-PLUS: Data Preparation for Data Mining
> > (15) Data Cleaning Techniques in R/S-PLUS
> > (16) R/S-PLUS: Applied Clustering Techniques
> >
> >
> > More on website
> >
> > http://www.xlsolutions-corp.com/rplus.asp
> >
> > Ask for group discount and reserve your seat Now - Earlybird Rates.
> > Payment due after the class! Email Sue Turner:  sue at
> > xlsolutions-corp.com
> >
> > Phone: 206-686-1578
> >
> >
> > Please let us know if you and your colleagues are interested in this
> > class to take advantage of group discount. Register now to secure your
> > seat.
> >
> > Cheers,
> > Elvis Miller, PhD
> > Manager Training.
> > XLSolutions Corporation
> > 206 686 1578
> > www.xlsolutions-corp.com
> > elvis at xlsolutions-corp.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.


Re: [R] Ridge regression

2010-01-08 Thread Ravi Varadhan
Yes, you need to have the intercept term when you predict model-based
response.  

 

This is what you need:

 

 ridge.test=lm.ridge(tey_values~tedata, lambda)

 

   yest <- drop(cbind(1, tedata) %*% coef(ridge.test))

 

Hope this helps,

Ravi.


---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml

 




From: Eleni Christodoulou [mailto:elenic...@gmail.com] 
Sent: Friday, January 08, 2010 11:18 AM
To: Ravi Varadhan
Cc: David Winsemius; r-help@r-project.org
Subject: Re: [R] Ridge regression

 

I am sorry, I just pressed the "send" button by accident before completing
my e-mail. The yest are the estimated values according to the ridge model.
Is the way that I calculate them correct? Or should I cut the
+coef(ridge.test)[1]  term?

Thanks a lot!
Eleni

On Fri, Jan 8, 2010 at 6:16 PM, Eleni Christodoulou 
wrote:

Hello again and Happy 2010!
I was looking back at this email because I need to do some additional
processing now. I was thinking that if I take the coef(ans) I get n+1
coefficients. I guess that the coef(ans)[1] is the constant term... Do I
need to add it when I calculate the estimated value for the outcome?
For example, lets say that I have divided my data into training data and
test data and I have the corresponding observed try_values and tey_values
(the real values for the samples that belong to the training set and the
test set respectively)
Here is my code:

library(MASS)
 ridge.test=lm.ridge(tey_values~tedata,lambda)
est<-list()
yest<-numeric()
for(i in 1:length(tey_values)){
est[[i]]=coef(ridge.test)[-1]*tedata[i,]
yest[i]=sum(est[[i]])+coef(ridge.test)[1] 
}





On Wed, Dec 2, 2009 at 8:22 PM, Ravi Varadhan  wrote:

The help page clearly states that ans$coef is "not on the original scale and
are for use by the coef method".  You also see that ans$scales gives you the
scales used in the computation of ans$coef.

So, to get coefficients on the original scale, you can either use coef(ans)
or you can divide ans$coef by ans$scales.


X1 <- runif(20)
X2 <- runif(20)
Y <- 2 * X1 - 2 * X2 + rnorm(20, sd=0.1)

lam <- 10
ans1 <- lm.ridge(Y ~ X1 + X2, lambda = lam)

all.equal(ans1$coef / ans1$scales, coef(ans1)[2:3] )

Hope this helps,

Ravi.


---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
 
tml







-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On

Behalf Of Ravi Varadhan
Sent: Wednesday, December 02, 2009 12:25 PM
To: 'David Winsemius'; 'Eleni Christodoulou'
Cc: r-help@r-project.org
Subject: Re: [R] Ridge regression

You are right that the ans$coef and coef(ans) are different in ridge
regression, where `ans' is the object from lm.ridge.  It is the coef(ans)
that yields the coefficients on the original scale.  ans$coef is the
coefficient of "X-scaled" and "Y-centered" version.

Here is an example that illustrates the workings of ridge regression.

First let us create some data:

X1 <- runif(20)
X2 <- runif(20)
Y <- 2 * X1 - 2 * X2 + rnorm(20, sd=0.1)

lam <- 10
ans1 <- lm.ridge(Y ~ X1 + X2, lambda = lam)
ans1$coef
coef(ans1)
# Note that these two are different

# Now Let us scale the variables X1 and X2 and center Y
#
cY <- scale(Y, scale=FALSE)
n <- length(Y)
sX1 <- scale(X1) * sqrt(n/(n-1))
sX2 <- scale(X2) *  sqrt(n/(n-1))

require(MASS)

lam <- 10
ans2 <- lm.ridge(cY ~ sX1 + sX2, lambda = lam)

ans2$coef
coef(ans2)
# Now, see that the coefficients of sX1 and sX2 are the same
# This is the connection!

# Armed with this insight, we now compare the ans1$coef with scaled
coefficients
#
ans1$coef
c(coef(ans1)[2] * sd(X1), coef(ans1)[3] * sd(X2)) * sqrt((n-1)/n)

# Now they are the same!

I hope this is clear.

Best,
Ravi.


---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_perso

[R] inclusion of "intercept=FALSE" in regsubsets() in leaps package produces an error

2010-01-08 Thread James C. McGrath
Hello,

I have encountered a problem which may be arising from details of my data and 
or the statistics I am trying to do, or may be arising due to the way leaps 
works internally. Unfortunately, I am not yet savvy enough to tell why.

I can say that this statement works (or at least works to the degree I expect):

b <- regsubsets(FUND~.,data=all, intercept=TRUE, nbest=1, nvmax=8, 
really.big=T, method="forward")

It does produce a warning:

Warning message:
In leaps.setup(x, y, wt = wt, nbest = nbest, nvmax = nvmax, force.in = 
force.in,  :
  2  linear dependencies found

But I can appreciate that and can reduce my dataset to deal with it. However, 
if I use this command:

b <- regsubsets(FUND~.,data=all, intercept=FALSE, nbest=1, nvmax=8, 
really.big=T, method="forward")

I get the following:

Warning message:
In leaps.setup(x, y, wt = wt, nbest = nbest, nvmax = nvmax, force.in = 
force.in,  :
  2  linear dependencies found
> b <- regsubsets(FUND~.,data=all, intercept=FALSE, nbest=1, nvmax=8, 
> really.big=T, method="forward")
Reordering variables and trying again:
Error in if (any(index[force.out] == -1)) stop("Can't force the same variable 
in and out") :
  missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In leaps.setup(x, y, wt = wt, nbest = nbest, nvmax = nvmax, force.in = 
force.in,  :
  1  linear dependencies found
2: In sing$lindep[-1] & force.in :
  longer object length is not a multiple of shorter object length
3: In sing$lindep | c(FALSE, force.out) :
  longer object length is not a multiple of shorter object length

I can understand how the inclusion (or not) of an intercept can impact 
regression significance, but I am not exactly sure how to interpret this 
particular output and what may be going on in the background. Thanks in advance 
for any insights.


James McGrath


[[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] Ridge regression

2010-01-08 Thread Eleni Christodoulou
I am sorry, I just pressed the "send" button by accident before completing
my e-mail. The yest are the estimated values according to the ridge model.
Is the way that I calculate them correct? Or should I cut the
*+coef(ridge.test)[1]
*term?

Thanks a lot!
Eleni

On Fri, Jan 8, 2010 at 6:16 PM, Eleni Christodoulou wrote:

> Hello again and Happy 2010!
> I was looking back at this email because I need to do some additional
> processing now. I was thinking that if I take the coef(ans) I get n+1
> coefficients. I guess that the coef(ans)[1] is the constant term... Do I
> need to add it when I calculate the estimated value for the outcome?
> For example, lets say that I have divided my data into training data and
> test data and I have the corresponding observed try_values and tey_values
> (the real values for the samples that belong to the training set and the
> test set respectively)
> Here is my code:
> *
> library(MASS)
>  ridge.test=lm.ridge(tey_values~tedata,lambda)
> est<-list()
> yest<-numeric()
> for(i in 1:length(tey_values)){
> est[[i]]=coef(ridge.test)[-1]*tedata[i,]
> yest[i]=sum(est[[i]])+coef(ridge.test)[1]
> }*
>
>
>
> On Wed, Dec 2, 2009 at 8:22 PM, Ravi Varadhan  wrote:
>
>> The help page clearly states that ans$coef is "not on the original scale
>> and
>> are for use by the coef method".  You also see that ans$scales gives you
>> the
>> scales used in the computation of ans$coef.
>>
>> So, to get coefficients on the original scale, you can either use
>> coef(ans)
>> or you can divide ans$coef by ans$scales.
>>
>> X1 <- runif(20)
>> X2 <- runif(20)
>> Y <- 2 * X1 - 2 * X2 + rnorm(20, sd=0.1)
>>
>> lam <- 10
>> ans1 <- lm.ridge(Y ~ X1 + X2, lambda = lam)
>>
>> all.equal(ans1$coef / ans1$scales, coef(ans1)[2:3] )
>>
>> Hope this helps,
>> Ravi.
>>
>>
>> 
>> ---
>>
>> Ravi Varadhan, Ph.D.
>>
>> Assistant Professor, The Center on Aging and Health
>>
>> Division of Geriatric Medicine and Gerontology
>>
>> Johns Hopkins University
>>
>> Ph: (410) 502-2619
>>
>> Fax: (410) 614-9625
>>
>> Email: rvarad...@jhmi.edu
>>
>> Webpage:
>>
>> http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
>> tml
>>
>>
>>
>>
>> 
>> 
>>
>>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
>> On
>> Behalf Of Ravi Varadhan
>> Sent: Wednesday, December 02, 2009 12:25 PM
>> To: 'David Winsemius'; 'Eleni Christodoulou'
>> Cc: r-help@r-project.org
>> Subject: Re: [R] Ridge regression
>>
>> You are right that the ans$coef and coef(ans) are different in ridge
>> regression, where `ans' is the object from lm.ridge.  It is the coef(ans)
>> that yields the coefficients on the original scale.  ans$coef is the
>> coefficient of "X-scaled" and "Y-centered" version.
>>
>> Here is an example that illustrates the workings of ridge regression.
>>
>> First let us create some data:
>>
>> X1 <- runif(20)
>> X2 <- runif(20)
>> Y <- 2 * X1 - 2 * X2 + rnorm(20, sd=0.1)
>>
>> lam <- 10
>> ans1 <- lm.ridge(Y ~ X1 + X2, lambda = lam)
>> ans1$coef
>> coef(ans1)
>> # Note that these two are different
>>
>> # Now Let us scale the variables X1 and X2 and center Y
>> #
>> cY <- scale(Y, scale=FALSE)
>> n <- length(Y)
>> sX1 <- scale(X1) * sqrt(n/(n-1))
>> sX2 <- scale(X2) *  sqrt(n/(n-1))
>>
>> require(MASS)
>>
>> lam <- 10
>> ans2 <- lm.ridge(cY ~ sX1 + sX2, lambda = lam)
>>
>> ans2$coef
>> coef(ans2)
>> # Now, see that the coefficients of sX1 and sX2 are the same
>> # This is the connection!
>>
>> # Armed with this insight, we now compare the ans1$coef with scaled
>> coefficients
>> #
>> ans1$coef
>> c(coef(ans1)[2] * sd(X1), coef(ans1)[3] * sd(X2)) * sqrt((n-1)/n)
>>
>> # Now they are the same!
>>
>> I hope this is clear.
>>
>> Best,
>> Ravi.
>>
>>
>> 
>> ---
>>
>> Ravi Varadhan, Ph.D.
>>
>> Assistant Professor, The Center on Aging and Health
>>
>> Division of Geriatric Medicine and Gerontology
>>
>> Johns Hopkins University
>>
>> Ph: (410) 502-2619
>>
>> Fax: (410) 614-9625
>>
>> Email: rvarad...@jhmi.edu
>>
>> Webpage:
>>
>> http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
>> tml
>>
>>
>>
>>
>> 
>> 
>>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
>> On
>> Behalf Of David Winsemius
>> Sent: Wednesday, December 02, 2009 11:04 AM
>> To: Eleni Christodoulou
>> Cc: r-help@r-project.org
>> Subject: Re: [R] Ridge regression
>>
>>
>> On Dec 2, 2009, at 10:42 AM, Eleni 

Re: [R] Ridge regression

2010-01-08 Thread Eleni Christodoulou
Hello again and Happy 2010!
I was looking back at this email because I need to do some additional
processing now. I was thinking that if I take the coef(ans) I get n+1
coefficients. I guess that the coef(ans)[1] is the constant term... Do I
need to add it when I calculate the estimated value for the outcome?
For example, lets say that I have divided my data into training data and
test data and I have the corresponding observed try_values and tey_values
(the real values for the samples that belong to the training set and the
test set respectively)
Here is my code:
*
library(MASS)
 ridge.test=lm.ridge(tey_values~tedata,lambda)
est<-list()
yest<-numeric()
for(i in 1:length(tey_values)){
est[[i]]=coef(ridge.test)[-1]*tedata[i,]
yest[i]=sum(est[[i]])+coef(ridge.test)[1]
}*


On Wed, Dec 2, 2009 at 8:22 PM, Ravi Varadhan  wrote:

> The help page clearly states that ans$coef is "not on the original scale
> and
> are for use by the coef method".  You also see that ans$scales gives you
> the
> scales used in the computation of ans$coef.
>
> So, to get coefficients on the original scale, you can either use coef(ans)
> or you can divide ans$coef by ans$scales.
>
> X1 <- runif(20)
> X2 <- runif(20)
> Y <- 2 * X1 - 2 * X2 + rnorm(20, sd=0.1)
>
> lam <- 10
> ans1 <- lm.ridge(Y ~ X1 + X2, lambda = lam)
>
> all.equal(ans1$coef / ans1$scales, coef(ans1)[2:3] )
>
> Hope this helps,
> Ravi.
>
>
> 
> ---
>
> Ravi Varadhan, Ph.D.
>
> Assistant Professor, The Center on Aging and Health
>
> Division of Geriatric Medicine and Gerontology
>
> Johns Hopkins University
>
> Ph: (410) 502-2619
>
> Fax: (410) 614-9625
>
> Email: rvarad...@jhmi.edu
>
> Webpage:
>
> http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
> tml
>
>
>
>
> 
> 
>
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On
> Behalf Of Ravi Varadhan
> Sent: Wednesday, December 02, 2009 12:25 PM
> To: 'David Winsemius'; 'Eleni Christodoulou'
> Cc: r-help@r-project.org
> Subject: Re: [R] Ridge regression
>
> You are right that the ans$coef and coef(ans) are different in ridge
> regression, where `ans' is the object from lm.ridge.  It is the coef(ans)
> that yields the coefficients on the original scale.  ans$coef is the
> coefficient of "X-scaled" and "Y-centered" version.
>
> Here is an example that illustrates the workings of ridge regression.
>
> First let us create some data:
>
> X1 <- runif(20)
> X2 <- runif(20)
> Y <- 2 * X1 - 2 * X2 + rnorm(20, sd=0.1)
>
> lam <- 10
> ans1 <- lm.ridge(Y ~ X1 + X2, lambda = lam)
> ans1$coef
> coef(ans1)
> # Note that these two are different
>
> # Now Let us scale the variables X1 and X2 and center Y
> #
> cY <- scale(Y, scale=FALSE)
> n <- length(Y)
> sX1 <- scale(X1) * sqrt(n/(n-1))
> sX2 <- scale(X2) *  sqrt(n/(n-1))
>
> require(MASS)
>
> lam <- 10
> ans2 <- lm.ridge(cY ~ sX1 + sX2, lambda = lam)
>
> ans2$coef
> coef(ans2)
> # Now, see that the coefficients of sX1 and sX2 are the same
> # This is the connection!
>
> # Armed with this insight, we now compare the ans1$coef with scaled
> coefficients
> #
> ans1$coef
> c(coef(ans1)[2] * sd(X1), coef(ans1)[3] * sd(X2)) * sqrt((n-1)/n)
>
> # Now they are the same!
>
> I hope this is clear.
>
> Best,
> Ravi.
>
>
> 
> ---
>
> Ravi Varadhan, Ph.D.
>
> Assistant Professor, The Center on Aging and Health
>
> Division of Geriatric Medicine and Gerontology
>
> Johns Hopkins University
>
> Ph: (410) 502-2619
>
> Fax: (410) 614-9625
>
> Email: rvarad...@jhmi.edu
>
> Webpage:
>
> http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
> tml
>
>
>
>
> 
> 
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On
> Behalf Of David Winsemius
> Sent: Wednesday, December 02, 2009 11:04 AM
> To: Eleni Christodoulou
> Cc: r-help@r-project.org
> Subject: Re: [R] Ridge regression
>
>
> On Dec 2, 2009, at 10:42 AM, Eleni Christodoulou wrote:
>
> > Dear list,
> >
> > I have a couple of questions concerning ridge regression. I am using
> > the
> > lm.ridge(...) function in order to fit a model to my microarray data.
> > Thus *model=lm.ridge(...)*
> > I retrieve some coefficients and some scales for each gene. First of
> > all, I
> > would like to ask: the real coefficients of the model are not
> > included in
> > the first argument of the output but in the result of coef(model),
> > am I
> > right?
>
> Not exactly. coef(model) extrac

[R] how to organize a lot of R source files

2010-01-08 Thread Hao Cen
Hi,

I wonder what is a better way to organize a lot of R source files. I have
a lot of utility functions written and store them in several source files
(e.g util1.R, util2.R,..utilN.R). I also have a master file in which the
source command is used to load all the util.R files. When I need to use
the utility functions in a new project, I create a new R file (e.g main.R)
in which I "source" the master file.

The problem with this approach is that anytime a single utility function
is modified, I need to rerun the source command in main.R to load the
master file, which loads all the utility R files via a loop over each
file. Sometimes I have to wait for 10 seconds to get them all loaded.
Sometimes I forget to run the source command. Is there a way in R to 1)
only reload the file changed (like a make utility) when I run source on
all utility files and/or even better 2)  reload the changed utility files,
when I run a command that use one of those utility functions, without the
need for me to source those files.

Not sure if packaging solves this issue because the library command has be
used every time a utility function is modified and in addition the package
has to be rebuilt. I don't worry about sharing the source files at this
moment as I am the only user of those utility files.

This may be a common issue many R users face. I wonder how other R users
solve this issue.

thanks

Jeff

__
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] Online R documentation

2010-01-08 Thread Karl Ove Hufthammer
On Fri, 8 Jan 2010 10:03:31 -0500 Jonathan Baron  
wrote:
> > In case anybody is looking for ideas in how to improve the above 
> > site, inclusion of rendered example graphs, similar to the ones at 
> > "http://www.metaresearch.de/exlib/";, would be nice.
> 
> Why should I bother when the site exists!

Well, I was thinking of better integration with the help pages, e.g., 
having each image appear right after the code that generated it, having 
larger images (perhaps at approx. the default window size for graphs in 
R?), and having all images for a given help page shown on the page, 
instead of the user having to click on a PDF link to see them.

> What might be nice is for each site to mirror the other.  I can't find
> in the web page the email address of the person in charge.  Is it you?

No. You can find the e-mail address of the author at 
http://www.metaresearch.de/

-- 
Karl Ove Hufthammer

__
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 to flatten a list to the same level?

2010-01-08 Thread Mark Heckmann

I have a nested list l like:

l <- list(A=c(1,2,3), B=c("a", "b"))
l <- list(l,l, list(l,l))

I want the list to be unlisted, but not on the lowest level of each  
"branch".

I want the lowest level of each list branch to remain as it is.
So unlist or unlist(rec=F) do not work here as the level of nesting  
may differ on the elements.

The result should look like:

$A
[1] 1 2 3

$B
[1] "a" "b"

$A
[1] 1 2 3

$B
[1] "a" "b"

$A
[1] 1 2 3

$B
[1] "a" "b"

$A
[1] 1 2 3

$B
[1] "a" "b"

Any ideas?
TIA!

Mark


–––
Mark Heckmann
Dipl. Wirt.-Ing. cand. Psych.
Vorstraße 93 B01
28359 Bremen
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.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.


Re: [R] Online R documentation

2010-01-08 Thread Jonathan Baron
On 01/08/10 14:56, Karl Ove Hufthammer wrote:
> On Fri, 8 Jan 2010 08:41:49 -0500 Jonathan Baron  
> wrote:
> > > Many people seem unhappy with the new documentation server because you
> > > need to have R running to access it, and it's not immediately obvious
> > > how to bookmark references so they work long-term. One solution to
> > > this problem is to have a globally available website that provides
> > > access to all package documentation.
> > 
> > Such a website exists:
> > 
> > http://finzi.psych.upenn.edu
> 
> In case anybody is looking for ideas in how to improve the above 
> site, inclusion of rendered example graphs, similar to the ones at 
> "http://www.metaresearch.de/exlib/";, would be nice.

Why should I bother when the site exists!  It is excellent.  I will
make a link to it from my site (finzi).

What might be nice is for each site to mirror the other.  I can't find
in the web page the email address of the person in charge.  Is it you?

And, Hadley, I don't need money to establish a mirror.  I have another
computer I could use for it (which already backs up the main site).
But it uses the same Internet connection (even another outlet in the
same wall plug).  The need for a mirror is partly to protect against
correlated risks (fire in the building, network outages at the
university, terrorist attacks, etc.) through diversification.

Jon

__
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] Creating Table from Boxplot

2010-01-08 Thread David Winsemius


On Jan 8, 2010, at 9:08 AM, Lorenzo Isella wrote:


Dear All,
I know how to use the boxplot()  function to generate a boxplot, but I
would like to (automatically) extract 5 numbers (median and the 4
quantiles) for each column and possibly save them into a convenient  
format.

Can anyone point me to the right direction? I am sure there must be an
automatic way to extract these data which are implicitly used  by  
boxplot().


I think you need to read the "Value" section of the help page for  
boxplot. It that does not answer your question, then come back with  
more specifics.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] fast lm se?

2010-01-08 Thread ivo welch
naive questions---

why is this not part of the standard R distribution?  fast regression is
*not* an obscure need.

why would an se() function not be part of the standard R distribution, given
that coef() can be?

naive suggestion to add to the ?lm text
 "The underlying low level functions, 'lm.fit' for plain, and
 'lm.wfit' for weighted regression fitting."  ADD: These can be
 orders of magnitude faster.

thank you, everyone.

regards,

/iaw


Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)


On Fri, Jan 8, 2010 at 9:08 AM, Dirk Eddelbuettel  wrote:

>
> On 8 January 2010 at 08:35, ivo welch wrote:
> | dear R experts---I am using the coef() function to pick off the
> coefficients
> | from an lm() object.  alas, I also need the standard errors and I need
> them
> | fast.  I know I can do a "summary()" on the object and pick them off this
> | way, but this computes other stuff I do not need.  Or, I can compute (X'
> | X)^(-1) s^2 myself.  Has someone written a fast se() function?
>
> Pages 72 and 73 of my most recent Intro to HPC tutorial [1] use Rcpp to
> access the GNU GSL to do just that: coefficients and covariance matrix of a
> standard y ~ X linear model.
>
> Pages 75 and 76 illustrate how the speed compares to both lm() and lm.fit()
> (hint: it is rather favourable).
>
> Page 74 tells you how to compile this if you use Rcpp (but you'd have to
> insert the slightly longer code from the tutorial document), this is now
> easier using the newest version of the inline package as detailed on my
> blog
> [2] but this has not yet been reflected in a new HPC tutorial.
>
> Hth, Dirk
>
>
> [1] http://dirk.eddelbuettel.com/papers/ismNov2009hpcTutorial.pdf
> [2] http://dirk.eddelbuettel.com/blog/2009/12/20#rcpp_inline_example
>
> --
> Three out of two people have difficulties with fractions.
>

[[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] fast lm se?

2010-01-08 Thread Dirk Eddelbuettel

On 8 January 2010 at 08:35, ivo welch wrote:
| dear R experts---I am using the coef() function to pick off the coefficients
| from an lm() object.  alas, I also need the standard errors and I need them
| fast.  I know I can do a "summary()" on the object and pick them off this
| way, but this computes other stuff I do not need.  Or, I can compute (X'
| X)^(-1) s^2 myself.  Has someone written a fast se() function?

Pages 72 and 73 of my most recent Intro to HPC tutorial [1] use Rcpp to
access the GNU GSL to do just that: coefficients and covariance matrix of a
standard y ~ X linear model.  

Pages 75 and 76 illustrate how the speed compares to both lm() and lm.fit()
(hint: it is rather favourable).

Page 74 tells you how to compile this if you use Rcpp (but you'd have to
insert the slightly longer code from the tutorial document), this is now
easier using the newest version of the inline package as detailed on my blog
[2] but this has not yet been reflected in a new HPC tutorial.

Hth, Dirk


[1] http://dirk.eddelbuettel.com/papers/ismNov2009hpcTutorial.pdf
[2] http://dirk.eddelbuettel.com/blog/2009/12/20#rcpp_inline_example

-- 
Three out of two people have difficulties with fractions.

__
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] Creating Table from Boxplot

2010-01-08 Thread Lorenzo Isella

Dear All,
I know how to use the boxplot()  function to generate a boxplot, but I
would like to (automatically) extract 5 numbers (median and the 4
quantiles) for each column and possibly save them into a convenient format.
Can anyone point me to the right direction? I am sure there must be an
automatic way to extract these data which are implicitly used  by boxplot().
Many thanks

Lorenzo

__
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] Anybody can suggest a better method to build a package while ignoring some functions

2010-01-08 Thread Michael Dewey

At 01:18 06/01/2010, rusers.sh wrote:

Hi,
 Say i have three functions in a new package, a,b and c. I only want the one
function "a" to be exported for use. "b" and  "c" are not very stable.
  If i specify to export all the three functions in the NAMESPACE file
(export(a,b,c)), no errors appeared after checking the package. And i am
sure there should be no errors.
  But if i only export the one function "a" by specifying it in the
NAMESPACE file(export(a)), one error appeared.


Without seeing the text of the functions it is hard to offer advice. 
Try to remove as much as possible from each function until you have a 
minimal reproducible example (as the posting guide asks you).



  See below.
 Error ###
* checking examples ... ERROR
Running examples in 's-Ex.R' failed.
The error most likely occurred in:
> ### * b
>
> flush(stderr()); flush(stdout())
>
> ### Name: b
> ### Title: Compute inverse cosine with angle given in degrees
> ### Aliases: ab
> ### Keywords: array
>
> ### ** Examples
> b(theta=30)
Error: could not find function "acos_d"
Execution halted
  Anybody knows where the problem is and how to solve this? Is there better
method to obtain what i want?
  Thanks

--
-
Jane Chang
Queen's

[[alternative HTML version deleted]]


Michael Dewey
http://www.aghmed.fsnet.co.uk

__
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] Online R documentation

2010-01-08 Thread Hadley Wickham
> http://pledgie.com/campaigns/7707 - here you can donate as much or as
> little as you like to support this project.  You won't pay until the
> total amount has been pledged.

I misread the documentation - do you actually pay right away.  If I
don't reach the $1000, I'll pass on the money to a good cause (either
as a donation to R or to buying Jonathan Baron a new mirror for his
existing search service)

Hadley

-- 
http://had.co.nz/

__
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] Online R documentation

2010-01-08 Thread Hadley Wickham
>> Many people seem unhappy with the new documentation server because you
>> need to have R running to access it, and it's not immediately obvious
>> how to bookmark references so they work long-term. One solution to
>> this problem is to have a globally available website that provides
>> access to all package documentation.
>
> Such a website exists:
>
> http://finzi.psych.upenn.edu
>
> Right near the top is a set of links to (almost) all package
> documentation.  Duncan Murdoch helped here by including an option to
> build static pages in the R source.

Then it needs better publicity - why are people complaining?

> There is also a search engine.
>
> (And this site also backs up several mailing lists and allows those to
> be searched too, although my feeling is that r-help itself is becoming
> less useful, if only because of it is impossible to maintain a high
> ratio of useful information to total when the activity is so great.)
>
> What _I_ need is a mirror site.  This is an old computer.

In that case, I'd happy donate the money to allow you to get a mirror.

Hadley

-- 
http://had.co.nz/

__
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] Online R documentation

2010-01-08 Thread Karl Ove Hufthammer
On Fri, 8 Jan 2010 08:41:49 -0500 Jonathan Baron  
wrote:
> > Many people seem unhappy with the new documentation server because you
> > need to have R running to access it, and it's not immediately obvious
> > how to bookmark references so they work long-term. One solution to
> > this problem is to have a globally available website that provides
> > access to all package documentation.
> 
> Such a website exists:
> 
> http://finzi.psych.upenn.edu

In case anybody is looking for ideas in how to improve the above 
site, inclusion of rendered example graphs, similar to the ones at 
"http://www.metaresearch.de/exlib/";, would be nice.

-- 
Karl Ove Hufthammer

__
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] fast lm se?

2010-01-08 Thread Gabor Grothendieck
See ?display in the arm package.

On Fri, Jan 8, 2010 at 8:35 AM, ivo welch  wrote:
> dear R experts---I am using the coef() function to pick off the coefficients
> from an lm() object.  alas, I also need the standard errors and I need them
> fast.  I know I can do a "summary()" on the object and pick them off this
> way, but this computes other stuff I do not need.  Or, I can compute (X'
> X)^(-1) s^2 myself.  Has someone written a fast se() function?
>
> incidentally, I think this would make a nice addition to the R base.  I
> presume it is not uncommon for a statistician also to want to use the se of
> coef estimates.
>
> pointers appreciated.
>
> regards,
>
> /iaw
> 
> Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)
>
>        [[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.


Re: [R] Fitting chi-squared distribution

2010-01-08 Thread Karl Ove Hufthammer
On Fri, 8 Jan 2010 14:39:34 +0100 Trafim Vanishek  
wrote:
> I would like to ask if there is a simple was in R to fit the chi-squared
> distribution to the empirical data?

Sure. Use the 'fitdistr' function in the 'MASS' package.

-- 
Karl Ove Hufthammer

__
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] fast lm se?

2010-01-08 Thread Liaw, Andy
From: ivo welch
> 
> dear R experts---I am using the coef() function to pick off 
> the coefficients
> from an lm() object.  alas, I also need the standard errors 
> and I need them
> fast.  I know I can do a "summary()" on the object and pick 
> them off this
> way, but this computes other stuff I do not need.  Or, I can 
> compute (X'
> X)^(-1) s^2 myself.  Has someone written a fast se() function?
> 
> incidentally, I think this would make a nice addition to the 
> R base.  I
> presume it is not uncommon for a statistician also to want to 
> use the se of
> coef estimates.

Not sure if this is much faster, but you can try
sqrt(diag(vcov(lm.object))).

Andy

 
> pointers appreciated.
> 
> regards,
> 
> /iaw
> 
> Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)
> 
>   [[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.
> 
Notice:  This e-mail message, together with any attachme...{{dropped:10}}

__
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] Online R documentation

2010-01-08 Thread Jonathan Baron
On 01/08/10 07:15, Hadley Wickham wrote:
> Dear list,
> 
> Many people seem unhappy with the new documentation server because you
> need to have R running to access it, and it's not immediately obvious
> how to bookmark references so they work long-term. One solution to
> this problem is to have a globally available website that provides
> access to all package documentation.

Such a website exists:

http://finzi.psych.upenn.edu

Right near the top is a set of links to (almost) all package
documentation.  Duncan Murdoch helped here by including an option to
build static pages in the R source.

There is also a search engine.

(And this site also backs up several mailing lists and allows those to
be searched too, although my feeling is that r-help itself is becoming
less useful, if only because of it is impossible to maintain a high
ratio of useful information to total when the activity is so great.)

What _I_ need is a mirror site.  This is an old computer.

> I'm happy to have a go at developing this, but I need some money to
> pay for hosting, for my time, and for any help I need getting it
> running efficiently.  To that end, I've set up a pledgie account at
> http://pledgie.com/campaigns/7707 - here you can donate as much or as
> little as you like to support this project.  You won't pay until the
> total amount has been pledged.
> 
> Hadley

Hadley,

If you want to set this up, with the search capability, I can give you
extremely detailed (but probably still now quite adequate)
instructions.

> 
> PS.  If this fundraising initiative is successful and any R-core
> member would like to take over this task, I will happily send the
> money their way.

-- 
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page: http://www.sas.upenn.edu/~baron
Editor: Judgment and Decision Making (http://journal.sjdm.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.


Re: [R] fast lm se?

2010-01-08 Thread Henrique Dallazuanna
You can get SE with this:

coef(summary(your_model))[,'Std. Error']



On Fri, Jan 8, 2010 at 11:35 AM, ivo welch  wrote:
> dear R experts---I am using the coef() function to pick off the coefficients
> from an lm() object.  alas, I also need the standard errors and I need them
> fast.  I know I can do a "summary()" on the object and pick them off this
> way, but this computes other stuff I do not need.  Or, I can compute (X'
> X)^(-1) s^2 myself.  Has someone written a fast se() function?
>
> incidentally, I think this would make a nice addition to the R base.  I
> presume it is not uncommon for a statistician also to want to use the se of
> coef estimates.
>
> pointers appreciated.
>
> regards,
>
> /iaw
> 
> Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)
>
>        [[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.
>



-- 
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] Fitting chi-squared distribution

2010-01-08 Thread Trafim Vanishek
Dear all,

I would like to ask if there is a simple was in R to fit the chi-squared
distribution to the empirical data?

Thanks a lot!

[[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] fast lm se?

2010-01-08 Thread ivo welch
dear R experts---I am using the coef() function to pick off the coefficients
from an lm() object.  alas, I also need the standard errors and I need them
fast.  I know I can do a "summary()" on the object and pick them off this
way, but this computes other stuff I do not need.  Or, I can compute (X'
X)^(-1) s^2 myself.  Has someone written a fast se() function?

incidentally, I think this would make a nice addition to the R base.  I
presume it is not uncommon for a statistician also to want to use the se of
coef estimates.

pointers appreciated.

regards,

/iaw

Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)

[[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] Online R documentation

2010-01-08 Thread Hadley Wickham
Dear list,

Many people seem unhappy with the new documentation server because you
need to have R running to access it, and it's not immediately obvious
how to bookmark references so they work long-term. One solution to
this problem is to have a globally available website that provides
access to all package documentation.

I'm happy to have a go at developing this, but I need some money to
pay for hosting, for my time, and for any help I need getting it
running efficiently.  To that end, I've set up a pledgie account at
http://pledgie.com/campaigns/7707 - here you can donate as much or as
little as you like to support this project.  You won't pay until the
total amount has been pledged.

Hadley

PS.  If this fundraising initiative is successful and any R-core
member would like to take over this task, I will happily send the
money their way.

-- 
http://had.co.nz/

__
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 static HTML help pages in R 2.10.x on Windows

2010-01-08 Thread hadley wickham
> I see. Well, I never lacked any of these capabilities... Please understand 
> that people who use R to do their work may have different objectives than the 
> developers - and they form the majority of R users.

Well how about a documentation system that could look back over your
history and notice that you've been misspelling a function name or
that you've forgotten to load a package, and dynamically recommend a
solution?  Duncan is just trying to give you some example of what the
new system might be used for.  It really is fantastically more
powerful than the previous static solution, but it will take some time
to develop tools to use those capabilities to the fullest.

Think of the new help system as a new freeway - you have to put up
with a lot of delays during construction, but once it's finished
you'll be much better off and you'll wonder how you ever got on
beforehand.

Hadley

-- 
http://had.co.nz/

__
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] Standard errors from a randomization test?

2010-01-08 Thread jjh

Hello-

Is it possible to estimate standard errors for a multiple regression model
using a randomization test approach? I have seen a lot on using the
procedure to get a test statistic, but nothing that talks about getting
actual standard errors. Is this possible? How might I do this in R?

Thank you.
-- 
View this message in context: 
http://n4.nabble.com/Standard-errors-from-a-randomization-test-tp1009613p1009613.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.


Re: [R] Zeilenweiser Plot einer Matrix

2010-01-08 Thread Uwe Ligges



On 08.01.2010 12:18, Oliver Gondring wrote:

Liebe Liste,

bin noch absoluter R-Anfänger und trotz fleißigen Lesens der
Dokumentation noch nicht zur Lösung des folgenden Problems vorgedrungen.

Die Werte einer 2D-Matrix sollen in einem einzigen 2D-Plot dargestellt
werden, in dem jeweils für die Werte einer Zeile ein Graph aus mit
Linien verbundenen Punkten gezeichnet wird. Die Matrix besitzt zwölf
Spalten, die x-Achse soll einfach mit 1:12 indiziert werden. Schön wäre,
wenn die einzelnen Graphen automatisch farblich variiert und mit dem
Zeilennamen beschriftet würden.

Spaltenweise habe ich es mit "matplot" geschafft, aber zeilenweise?
Oder sollte eher die Matrix transponiert werden?


Why not, if it gives the desired result...



Ich bin sicher, dass es nicht mehr als einen Hinweis auf das richtige
Stichwort braucht, denn das Problem erscheint mir im Grunde eher trivial.

>

Vielen Dank für Hinweise in die richtige Richtung!



Please do read the posting guide. This list's language is supposed to be 
English. Note that you achieve a considerable higher probability for an 
answer if everybody can understand what you are asking.


Best,
Uwe Ligges




Mit herzlichem Gruß
Peer

__
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] Building static HTML help pages in R 2.10.x on Windows

2010-01-08 Thread Dieter Menne

Hi, Duncan,


>>If that works, writing up instructions would be a useful contribution. 

It was always a bit of a mess, and after 15 minutes this morning I had to
go. So I hoped someone else would jump the wagon.

 

Dieter

 

 


-- 
View this message in context: 
http://n4.nabble.com/Building-static-HTML-help-pages-in-R-2-10-x-on-Windows-tp977326p1009611.html
Sent from the R help mailing list archive at Nabble.com.

[[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] Building static HTML help pages in R 2.10.x on Windows

2010-01-08 Thread Duncan Murdoch

Dieter Menne wrote:


Duncan Murdoch wrote:
  
What's so hard about leaving an R session running, and using bookmarks 
as Dieter described?





It pollutes my space, and I am a Window-closing maniac, so it won't survive
the next attack.



It might be worth a try to use instsrv and srvany to install the batch as a
server. The resource kit cries out loud when installed on Window 7 for being
a stupid old dinosaur, but in similar case I could still use it.

  


If that works, writing up instructions would be a useful contribution.

Duncan Murdoch

__
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 static HTML help pages in R 2.10.x on Windows

2010-01-08 Thread Duncan Murdoch

Michal Kulich wrote:

On 7.1.2010 20:22, Duncan Murdoch wrote:

  

A more useful example than ls() would be methods().   I think it
would be nice to have a list of methods included in the man page for
a generic function, and links to their pages if they have their own
man pages.  You might want to list all installed methods, with some
sort of highlighting to indicate which ones are already attached, or
perhaps be able to toggle between installed and attached, or
whatever.  None of that is possible with static help, not even a list
of installed methods, because someone might install a new package
that offers some others after the static help has already been built.


I see. Well, I never lacked any of these capabilities... Please understand that people who use R to do their work may have different objectives than the developers - and they form the majority of R users. 

  
Then they should contribute to the development.  I don't owe you 
anything.  You owe us a lot.


Duncan Murdoch


On 07/01/2010 2:16 PM, Kevin Wright wrote:



  
Well, among other things, if my global environment becomes 
cluttered/corrupt/etc and I quit R, then restart R, the links in my

 browser are now dead.
  


  

You weren't following Dieter's instructions, then.



Indeed, but that option is not documented, as far as I know - at least not in 2.10.0. And even if it was, most users would not be able to find it or use it because they have no clue what a port is. 
 
  

I have to close all the tabs and call help to open them again.
Also, the R-supplied java tool for searching help is ancient and 
underwhelming.
  
 
  

Then contribute a new one.



Duncan, if even the quite advanced and computer-proficient users have trouble 
using the dynamic R help and have to resort to some quite complex and cumbersome 
home-made solutions to get back the basic functionality then something is not 
right. It's true that the help system was never a particular strength of R and 
that it needed an overhaul. What worked well in the late 90's with a few dozen 
packages does not work well with >1000 packages. However, 2.10.x does not seem 
to make things better.

The work of the R developers should be widely appreciated and we really do 
appreciate it. The question is whether their effort is extended in the best 
direction... (Imho, that's an issue with most open-source projects and it's 
been much worse with Mozilla than with R).

Just my 2c.

Michal




__
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] Zeilenweiser Plot einer Matrix

2010-01-08 Thread Oliver Gondring

Liebe Liste,

bin noch absoluter R-Anfänger und trotz fleißigen Lesens der
Dokumentation noch nicht zur Lösung des folgenden Problems vorgedrungen.

Die Werte einer 2D-Matrix sollen in einem einzigen 2D-Plot dargestellt
werden, in dem jeweils für die Werte einer Zeile ein Graph aus mit
Linien verbundenen Punkten gezeichnet wird. Die Matrix besitzt zwölf
Spalten, die x-Achse soll einfach mit 1:12 indiziert werden. Schön wäre,
wenn die einzelnen Graphen automatisch farblich variiert und mit dem
Zeilennamen beschriftet würden.

Spaltenweise habe ich es mit "matplot" geschafft, aber zeilenweise?
Oder sollte eher die Matrix transponiert werden?

Ich bin sicher, dass es nicht mehr als einen Hinweis auf das richtige
Stichwort braucht, denn das Problem erscheint mir im Grunde eher trivial.

Vielen Dank für Hinweise in die richtige Richtung!

Mit herzlichem Gruß
Peer

__
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] Print data frame as list including row/column name

2010-01-08 Thread Henrique Dallazuanna
Try this:

 writeLines(do.call(paste, c(as.data.frame.table(as.matrix(x)), sep = ";")))

On Fri, Jan 8, 2010 at 12:03 AM, sugimoto  wrote:
>
> Hi all,
>
> I have the following problem:
> I have a data frame (actually it is a prop.table) which I want to print as a
> list, e.g.:
>          C1  C2  C3
>  R1  0.0  0.0  1.0
>  R2  1.0  0.0  0.0
>  R3  0.0  0.0  0.0
>  R4  0.0  1.0  0.0
>
> should be printed like
> C1;R1;0.0
> C2;R1;0.0
> C3;R1;1.0
> C1;R2;1.0
> C2;R2;0.0
> .
>
> Is there any existing solution out there or could somebody please give me a
> hint on how to solve the problem?
>
> Many thanks in advance,
> I. Sugimoto
> --
> View this message in context: 
> http://n4.nabble.com/Print-data-frame-as-list-including-row-column-name-tp1009409p1009409.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.
>



-- 
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] Bug: more information on a crash

2010-01-08 Thread Christophe Genolini

Hi the list,

In the package KmL (new version, not release yet), the main function 
seems to work correctly but once in a while, R crash (full crash, 
anything link with R is closed and windows ask if it can send a crash 
report). More precisely, when I run it in a loop on 1000 data sets, the 
crash is certain... Is there a way to get more information on what cause 
this?


Christophe

__
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] generate XML

2010-01-08 Thread S Devriese
On 01/07/2010 11:36 AM, robert-mcfad...@o2.pl wrote:
> 
> 
> 
> Dnia 7 stycznia 2010 11:30 S Devriese  napisał(a):
>> you might try
>>
>> # open file connection
>> sink("item1.xml")
>> # print object
>> my.matrix
>> # close file connection
>> sink()
> 
> Unfortunately, It does not code letter appropriate. To #print object it's 
> better to use write.table. But thank you for help.  
> 
> __
> 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.


Mhh, you could have a look at write.matrix in the MASS package, but I'm
afraid that you might have to specify the encoding explicitly (see
?connections, the section on encoding)

__
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 static HTML help pages in R 2.10.x on Windows

2010-01-08 Thread Dieter Menne



Duncan Murdoch wrote:
> 
> What's so hard about leaving an R session running, and using bookmarks 
> as Dieter described?
> 

It pollutes my space, and I am a Window-closing maniac, so it won't survive
the next attack.



It might be worth a try to use instsrv and srvany to install the batch as a
server. The resource kit cries out loud when installed on Window 7 for being
a stupid old dinosaur, but in similar case I could still use it.

Dieter


-- 
View this message in context: 
http://n4.nabble.com/Building-static-HTML-help-pages-in-R-2-10-x-on-Windows-tp977326p1009522.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.