Re: [R] hypergeometric vs fisher.test

2010-08-13 Thread TGS
"or an incompetent"

Such harsh words Peter. You're not making this a friendly environment for 
people to ask questions. Is there a less competent attribute mailing list so 
that some of us don't offend you with our questions?

On Aug 13, 2010, at 2:11 PM, Peter Dalgaard wrote:

Andrea Franceschini wrote:
> I ask the question also because I found this line in Wikipedia:
> "The test (see above) based on the hypergeometric distribution
> (hypergeometric test) is identical to the corresponding one-tailed
> version of Fisher's exact test".
> 
> Is this wrong ?  May I kindly ask a friendly explanation for
> not-experts in statistics ?
> 
> Thx a lot,
> 

You never said you were a non-expert. A question like that might very
well have come from a student, or an incompetent claiming to have found
a bug in fisher.test...

The point was that Fisher's test takes the 2x2 table

a b
c d

and interprets the situation under the null hypothesis as taking a
sample of size a+c from an urn with a+b white balls and c+d black balls.

Once you read the docs for phyper properly (it _is_ tricky to get it
right), you arrive at

> phyper(16,17+181,449+19551,17+449, lower.tail=FALSE)
[1] 3.693347e-06


-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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] Dealing with data

2010-08-13 Thread TGS
But in your comment, it sounded like you were in the realm of ANOVA when you 
made the degrees of freedom comment. I'm not going to get into the theory of 
statistics with you :) I'm just trying to learn R, take it easy. Yes, I 
understand that in the regression problem, the degrees of freedom for 
regression is 1, and in ANOVA, the degrees of freedom for sprays are 5. Thanks.

On Aug 13, 2010, at 12:54 PM, Greg Snow wrote:

If you do as.numeric on InsectSprays and use the result as a predictor in lm, 
then it will only fit 1 degree of freedom, not 5, try it and see.  That is why 
I was asking and giving an alternative that would still use 5 degrees of 
freedom.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-----
> From: TGS [mailto:cran.questi...@gmail.com]
> Sent: Friday, August 13, 2010 1:52 PM
> To: Greg Snow
> Subject: Re: [R] Dealing with data
> 
> P.S. The degrees of freedom for sprays would be 5 and not 1.
> 
> On Aug 13, 2010, at 12:27 PM, Greg Snow wrote:
> 
> So you want 1 degree of freedom for InsectSprays?  You believe that the
> difference between A and B is exactly the same as between B and C which
> is exactly the same as between D and E (etc.)?  that seems an odd
> assumption, but you can get that by using as.numeric (as I and others
> have already stated).
> 
> If on the other hand you want InsectSprays to be treated correctly with
> the correct number of degrees of freedom, but have the output on a
> single line testing the overall effect, then you want to use the aov
> function rather than lm (internally they do the same thing, but the
> default summary output for aov is 1 line per term).
> 
> Hope this helps,
> 
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.s...@imail.org
> 801.408.8111
> 
> 
>> -Original Message-
>> From: TGS [mailto:cran.questi...@gmail.com]
>> Sent: Friday, August 13, 2010 11:51 AM
>> To: Greg Snow
>> Cc: r-help@r-project.org
>> Subject: Re: [R] Dealing with data
>> 
>> # Greg, if R automatically does that then I don't know why it's
>> treating each indicator
>> # as a different regressor. In other words, I am interested in
> treating
>> 'spray' as one
>> # independent variable.
>> #
>> # Erik, which book do you suggest I read? Thanks.
>> 
>> data(InsectSprays)
>> lm(InsectSprays$count ~ 0 + InsectSprays$spray)
>> 
>> On Aug 13, 2010, at 10:34 AM, Greg Snow wrote:
>> 
>> R/S does all of that automatically for you, you do not need to
> manually
>> create the indicator variables.
>> 
>> If you do something like:
>> 
>>> fit <- lm( Sepal.Width ~ Species, data=iris, x=TRUE)
>> 
>> Then look at the matrix actually used:
>> 
>>> fit$x
>> 
>> Or the output:
>> 
>>> summary(fit)
>> 
>> You will see that Species was automatically converted into indicator
>> variables and those were used in the regression.
>> 
>> If you really need the indicator variables yourself, look at the
>> model.matrix function, e.g.:
>> 
>>> model.matrix( ~Species, data=iris )
>> 
>> Or
>> 
>>> model.matrix( ~Species - 1, data=iris )
>> 
>> If you really want 1 for A, 2 for B, etc. then look at as.numeric on
> a
>> factor variable (e.g. as.numeric(iris$Species) ).
>> 
>> Hope this helps,
>> 
>> --
>> Gregory (Greg) L. Snow Ph.D.
>> Statistical Data Center
>> Intermountain Healthcare
>> greg.s...@imail.org
>> 801.408.8111
>> 
>> 
>>> -Original Message-
>>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
>>> project.org] On Behalf Of TGS
>>> Sent: Friday, August 13, 2010 11:22 AM
>>> To: David Winsemius
>>> Cc: r-help@r-project.org
>>> Subject: Re: [R] Dealing with data
>>> 
>>> To clarify, I'd like to create a column of indicators for the
>>> respective letters so that I could maybe do regression on
> indicators,
>>> etc.
>>> 
>>> For instance, "A" gets "1", "B" gets "2", and so on.
>>> 
>>> On Aug 13, 2010, at 10:19 AM, David Winsemius wrote:
>>> 
>>> 
>>> On Aug 13, 2010, at 1:03 PM, TGS wrote:
>>> 
>>>> # how would I code in R to look at the letter of the alphabet
>>>> # in the second column and create a indicator column for the
>>>> # corresponding letter?
>>

Re: [R] Dealing with data

2010-08-13 Thread TGS
# I wasn't trying to do ANOVA. I was simply trying to figure out how regress 
count on sprays (this is after I saw another poster asking an unrelated 
question with the InsectSprays dataset).
# 
# Anyhow, David clarified this but also, thanks for your explanation as well.

rm(list = ls()); sprays <- as.numeric(InsectSprays$spray)

lm(formula = count ~ 0 + spray, data = InsectSprays)
lm(formula = count ~ 0 + sprays, data = InsectSprays)

# besides the point, in the ANOVA problem the degrees of freedom would be 5, 
not 1.

On Aug 13, 2010, at 12:27 PM, Greg Snow wrote:

So you want 1 degree of freedom for InsectSprays?  You believe that the 
difference between A and B is exactly the same as between B and C which is 
exactly the same as between D and E (etc.)?  that seems an odd assumption, but 
you can get that by using as.numeric (as I and others have already stated).

If on the other hand you want InsectSprays to be treated correctly with the 
correct number of degrees of freedom, but have the output on a single line 
testing the overall effect, then you want to use the aov function rather than 
lm (internally they do the same thing, but the default summary output for aov 
is 1 line per term).

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-----
> From: TGS [mailto:cran.questi...@gmail.com]
> Sent: Friday, August 13, 2010 11:51 AM
> To: Greg Snow
> Cc: r-help@r-project.org
> Subject: Re: [R] Dealing with data
> 
> # Greg, if R automatically does that then I don't know why it's
> treating each indicator
> # as a different regressor. In other words, I am interested in treating
> 'spray' as one
> # independent variable.
> #
> # Erik, which book do you suggest I read? Thanks.
> 
> data(InsectSprays)
> lm(InsectSprays$count ~ 0 + InsectSprays$spray)
> 
> On Aug 13, 2010, at 10:34 AM, Greg Snow wrote:
> 
> R/S does all of that automatically for you, you do not need to manually
> create the indicator variables.
> 
> If you do something like:
> 
>> fit <- lm( Sepal.Width ~ Species, data=iris, x=TRUE)
> 
> Then look at the matrix actually used:
> 
>> fit$x
> 
> Or the output:
> 
>> summary(fit)
> 
> You will see that Species was automatically converted into indicator
> variables and those were used in the regression.
> 
> If you really need the indicator variables yourself, look at the
> model.matrix function, e.g.:
> 
>> model.matrix( ~Species, data=iris )
> 
> Or
> 
>> model.matrix( ~Species - 1, data=iris )
> 
> If you really want 1 for A, 2 for B, etc. then look at as.numeric on a
> factor variable (e.g. as.numeric(iris$Species) ).
> 
> Hope this helps,
> 
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.s...@imail.org
> 801.408.8111
> 
> 
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
>> project.org] On Behalf Of TGS
>> Sent: Friday, August 13, 2010 11:22 AM
>> To: David Winsemius
>> Cc: r-help@r-project.org
>> Subject: Re: [R] Dealing with data
>> 
>> To clarify, I'd like to create a column of indicators for the
>> respective letters so that I could maybe do regression on indicators,
>> etc.
>> 
>> For instance, "A" gets "1", "B" gets "2", and so on.
>> 
>> On Aug 13, 2010, at 10:19 AM, David Winsemius wrote:
>> 
>> 
>> On Aug 13, 2010, at 1:03 PM, TGS wrote:
>> 
>>> # how would I code in R to look at the letter of the alphabet
>>> # in the second column and create a indicator column for the
>>> # corresponding letter?
>>> 
>>> data(InsectSprays)
>>> InsectSprays$spray
>> 
>> It's already what most people mean when they say "indicator column",
>> i.e., a factor variable (and not a character vector)  so,  what
> do
>> _you_ mean?
>>> 
>> 
>> 
>> --
>> 
>> David Winsemius, MD
>> 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.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Dealing with data

2010-08-13 Thread TGS
# Greg, if R automatically does that then I don't know why it's treating each 
indicator
# as a different regressor. In other words, I am interested in treating 'spray' 
as one
# independent variable.
# 
# Erik, which book do you suggest I read? Thanks.

data(InsectSprays)
lm(InsectSprays$count ~ 0 + InsectSprays$spray)

On Aug 13, 2010, at 10:34 AM, Greg Snow wrote:

R/S does all of that automatically for you, you do not need to manually create 
the indicator variables.

If you do something like:

> fit <- lm( Sepal.Width ~ Species, data=iris, x=TRUE)

Then look at the matrix actually used:

> fit$x

Or the output:

> summary(fit)

You will see that Species was automatically converted into indicator variables 
and those were used in the regression.

If you really need the indicator variables yourself, look at the model.matrix 
function, e.g.:

> model.matrix( ~Species, data=iris )

Or

> model.matrix( ~Species - 1, data=iris )

If you really want 1 for A, 2 for B, etc. then look at as.numeric on a factor 
variable (e.g. as.numeric(iris$Species) ).

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of TGS
> Sent: Friday, August 13, 2010 11:22 AM
> To: David Winsemius
> Cc: r-help@r-project.org
> Subject: Re: [R] Dealing with data
> 
> To clarify, I'd like to create a column of indicators for the
> respective letters so that I could maybe do regression on indicators,
> etc.
> 
> For instance, "A" gets "1", "B" gets "2", and so on.
> 
> On Aug 13, 2010, at 10:19 AM, David Winsemius wrote:
> 
> 
> On Aug 13, 2010, at 1:03 PM, TGS wrote:
> 
>> # how would I code in R to look at the letter of the alphabet
>> # in the second column and create a indicator column for the
>> # corresponding letter?
>> 
>> data(InsectSprays)
>> InsectSprays$spray
> 
> It's already what most people mean when they say "indicator column",
> i.e., a factor variable (and not a character vector)  so,  what do
> _you_ mean?
>> 
> 
> 
> --
> 
> David Winsemius, MD
> 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.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Dealing with data

2010-08-13 Thread TGS
To clarify, I'd like to create a column of indicators for the respective 
letters so that I could maybe do regression on indicators, etc.

For instance, "A" gets "1", "B" gets "2", and so on.

On Aug 13, 2010, at 10:19 AM, David Winsemius wrote:


On Aug 13, 2010, at 1:03 PM, TGS wrote:

> # how would I code in R to look at the letter of the alphabet
> # in the second column and create a indicator column for the
> # corresponding letter?
> 
> data(InsectSprays)
> InsectSprays$spray

It's already what most people mean when they say "indicator column", i.e., a 
factor variable (and not a character vector)  so,  what do _you_ mean?
> 


-- 

David Winsemius, MD
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.


[R] Dealing with data

2010-08-13 Thread TGS
# how would I code in R to look at the letter of the alphabet
# in the second column and create a indicator column for the
# corresponding letter?

data(InsectSprays)
InsectSprays$spray

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] R 64-bit and Revolution

2010-08-12 Thread TGS
I downloaded their Academic version and installed it on a Windows virtual 
machine (as there is not a Mac version available).

I played around with it a little bit and wasn't overly impressed. I still like 
my current configuration: textmate with R bundle on Mac OSX.

With textmate data entry is a breeze, executing commands is a breeze, and 
dealing with graphics is a breeze. Also, I can easily use textmate's Sweave 
bundle to produce documents.

In short, from the very little that I have tried using Revolution, my current 
configuration beats using Revolution.

I just need to continue working on obtaining the R skills!

On Aug 12, 2010, at 4:12 PM, Lars Bishop wrote:

Dear users,

The company where I work is considering getting a license for Revolution
Enterprise - Windows 64-bit. I'll appreciate for those familiar with the
product if can share your experiences with it? In particular, how does it
compare to the "free" version of R 64-bit?

Thanks in advance.

Regards,
Lars.

[[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] Plotting one dot in a graph

2010-08-12 Thread TGS
# just to clean it up for my own understanding, the "difference" approach as 
you had suggested would be

x <- seq(.2, .3, by = .1)
f1 <- function(x){
x*cos(x)-2*x**2+3*x-1
}
plot(x,f1(x), type = "l")
abline(h = -.1)
abline(v = x[which.min(abs(diff((f1(x) - (-.1))**2)))], lty = 'dotted')
points(x = x[which.min(abs(diff((f1(x) - (-.1))**2)))], y = -.1)

# and the uniroot approach is:

x <- seq(.2, .3, by = .01)
f1 <- function(x){
x*cos(x)-2*x**2+3*x-1
}
f2 <- function(x){
-.1
}
f3 <- function(x){
f1(x) - f2(x)
}
plot(x,f1(x), type = "l")
abline(h = -.1)
abline(v = uniroot(f = f3, interval = c(.2, .3))$root, lty = 'dotted')
points(x = uniroot(f = f3, interval = c(.2, .3))$root, y = -.1)

# Thanks David!


On Aug 12, 2010, at 1:33 PM, David Winsemius wrote:


On Aug 12, 2010, at 4:15 PM, TGS wrote:

> David, I was expecting this to work but how would I specify the vector in 
> "diff()" in order for the following to work?
> 
> x <- seq(.2, .3, by = .01)
> f <- function(x){
>   x*cos(x)-2*x**2+3*x-1
> }
> plot(x,f(x), type = "l")
> abline(h = -.1)
> abline(v = x[which.min(abs(diff(c(-.1, f(x)], lty = 'dotted')

f2 <- function(x) -0.1
f3 <- function(x) f(x) -f2(x)
abline(v=uniroot(f3, c(0.2, 0.3) )$root)
points(x=uniroot(f3, c(0.2, 0.3) )$root, y= -0.1)

If you are going to use the differences, then you probably want to minimize 
either the abs() or the square of the differences.

-- 
David.
> 
> On Aug 12, 2010, at 1:00 PM, David Winsemius wrote:
> 
> 
> On Aug 12, 2010, at 3:54 PM, TGS wrote:
> 
>> Actually I spoke too soon David.
>> 
>> I'm looking for a function that will either tell me which point is the 
>> intersection so that I'd be able to plot a point there.
>> 
>> Or, if I have to solve for the roots in the ways which were demonstrated 
>> yesterday, then would I be able to specify what the horizontal line is, for 
>> instance in the case where y (is-not) 0?
> 
> Isn't the abline h=0 represented mathematically by the equation y=0 and 
> therefore you are solving just for the zeros of "f" (whaich are the same as 
> for (f-0)? If it were something more interesting, like solving the 
> intersection of two polynomials, you would be solving for the  zeros of the 
> difference of the equations. Or maybe I have not understood what you were 
> requesting?
> 
> 
>> 
>> On Aug 12, 2010, at 12:47 PM, David Winsemius wrote:
>> 
>> 
>> On Aug 12, 2010, at 3:43 PM, TGS wrote:
>> 
>>> I'd like to plot a point at the intersection of these two curves. Thanks
>>> 
>>> x <- seq(.2, .3, by = .01)
>>> f <- function(x){
>>> x*cos(x)-2*x**2+3*x-1
>>> }
>>> 
>>> plot(x,f(x), type = "l")
>>> abline(h = 0)
>> 
>> Would this just be the uniroot strategy applied to "f"? You then plot the x 
>> and y values with points()
>> 
> 
>> 
> 
> David Winsemius, MD
> West Hartford, CT
> 
> 

David Winsemius, MD
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] Plotting one dot in a graph

2010-08-12 Thread TGS
I was meaning something like the following:

x <- seq(.2, .3, by = .01)
f <- function(x){
x*cos(x)-2*x**2+3*x-1
}
plot(x,f(x), type = "l")
abline(h = -.1)

But I'm guessing "uniroot" will do this?---I haven't looked far into the 
uniroot function to see if it will solve this.

On Aug 12, 2010, at 1:00 PM, David Winsemius wrote:


On Aug 12, 2010, at 3:54 PM, TGS wrote:

> Actually I spoke too soon David.
> 
> I'm looking for a function that will either tell me which point is the 
> intersection so that I'd be able to plot a point there.
> 
> Or, if I have to solve for the roots in the ways which were demonstrated 
> yesterday, then would I be able to specify what the horizontal line is, for 
> instance in the case where y (is-not) 0?

Isn't the abline h=0 represented mathematically by the equation y=0 and 
therefore you are solving just for the zeros of "f" (whaich are the same as for 
(f-0)? If it were something more interesting, like solving the intersection of 
two polynomials, you would be solving for the  zeros of the difference of the 
equations. Or maybe I have not understood what you were requesting?


> 
> On Aug 12, 2010, at 12:47 PM, David Winsemius wrote:
> 
> 
> On Aug 12, 2010, at 3:43 PM, TGS wrote:
> 
>> I'd like to plot a point at the intersection of these two curves. Thanks
>> 
>> x <- seq(.2, .3, by = .01)
>> f <- function(x){
>>  x*cos(x)-2*x**2+3*x-1
>> }
>> 
>> plot(x,f(x), type = "l")
>> abline(h = 0)
> 
> Would this just be the uniroot strategy applied to "f"? You then plot the x 
> and y values with points()
> 

> 

David Winsemius, MD
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] Plotting one dot in a graph

2010-08-12 Thread TGS
Actually I spoke too soon David.

I'm looking for a function that will either tell me which point is the 
intersection so that I'd be able to plot a point there.

Or, if I have to solve for the roots in the ways which were demonstrated 
yesterday, then would I be able to specify what the horizontal line is, for 
instance in the case where y (is-not) 0?

On Aug 12, 2010, at 12:47 PM, David Winsemius wrote:


On Aug 12, 2010, at 3:43 PM, TGS wrote:

> I'd like to plot a point at the intersection of these two curves. Thanks
> 
> x <- seq(.2, .3, by = .01)
> f <- function(x){
>   x*cos(x)-2*x**2+3*x-1
> }
> 
> plot(x,f(x), type = "l")
> abline(h = 0)

Would this just be the uniroot strategy applied to "f"? You then plot the x and 
y values with points()

-- 

David Winsemius, MD
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] Plotting one dot in a graph

2010-08-12 Thread TGS
Yes, I'm playing around with other things but the "points()" function is what I 
was looking for. Thanks

On Aug 12, 2010, at 12:47 PM, David Winsemius wrote:


On Aug 12, 2010, at 3:43 PM, TGS wrote:

> I'd like to plot a point at the intersection of these two curves. Thanks
> 
> x <- seq(.2, .3, by = .01)
> f <- function(x){
>   x*cos(x)-2*x**2+3*x-1
> }
> 
> plot(x,f(x), type = "l")
> abline(h = 0)

Would this just be the uniroot strategy applied to "f"? You then plot the x and 
y values with points()

-- 

David Winsemius, MD
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.


[R] Plotting one dot in a graph

2010-08-12 Thread TGS
I'd like to plot a point at the intersection of these two curves. Thanks

x <- seq(.2, .3, by = .01)
f <- function(x){
x*cos(x)-2*x**2+3*x-1
}

plot(x,f(x), type = "l")
abline(h = 0)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Error in rowSums

2010-08-12 Thread TGS
Yes, please do as Erik said in the future but here's one way to do it.

(A <- matrix(data = rnorm(n = 9, mean = 0, sd = 1), nrow = 3, ncol = 3, byrow = 
FALSE, dimnames = NULL))
matrix(rowSums(A))

On Aug 12, 2010, at 11:28 AM, Amit Patel wrote:

Hi 

I am trying to calculate the row sums of a matrix i have created
The matrix ( FeaturePresenceMatrix) has been created by

1) Read csv
2) Removing unnecesarry data using [-1:4,] command
3) replacing all the NA values with as.numeric(0) and all others with 
as.numeric 
(1)

When I carry out the command

TotalFeature <- rowrowSums(FeaturePresenceMatrix, na.rm = TRUE)

I get the following error. 

Error in rowSums(FeaturePresenceMatrix, na.rm = TRUE) : 
 'x' must be numeric

Any tips onhow I can get round this?

Thanks in Advance
Amit





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Creating vectors

2010-08-12 Thread TGS
I think I understand your question and the following would produce the result 
you've posted.

(x <- matrix(c(1, 2, 2, 3, 1, 2, 1, 2, 3, 4), nrow=5, byrow=TRUE))

On Aug 12, 2010, at 5:41 AM, clips10 wrote:


Thanks for the help,

I tried to apply this to a vector with two columns, well I suppose it is not
a vector but for instance like this:

   [,1]  [,2]
[1,]1  2
[2,]2  3
[3,]1  2
[4,]1  2
[5,]3 4

and return a vector :

1,2,1,1,3, so that it recognises both columns together.

I tried match(x, unique(x)) as earlier suggested but this returns a vector
of length 10 as opposed to 5, even though unique(x) does remove the repeated
rows.
Sorry if this is confusing, I am trying to do as originally posted but with
2 columns

Thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Creating-vectors-tp2321440p2322646.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] Derivative

2010-08-11 Thread TGS
This following works for me but I still favor the quick and dirty method 
suggested originally by David.

options(scipen = 10)
x <- seq(0,2, by = .01)
f <- expression(5*cos(2*x)-2*x*sin(2*x))
D(f, 'x')
f.prime <- function(x){
-(5 * (sin(2 * x) * 2) + (2 * sin(2 * x) + 2 * x * (cos(2 * x) * 2)))
}
curve(expr = f.prime, from = 1, to = 2, n = 101)
uniroot(f = f.prime, interval = c(1,2), tol = .1)

On Aug 11, 2010, at 10:56 PM, David Winsemius wrote:


On Aug 12, 2010, at 12:49 AM, Dennis Murphy wrote:

> Hi:
> 
> Try the following:
> 
> f <- function(x) 5*cos(2*x)-2*x*sin(2*x)
> curve(f, -5, 5)
> abline(0, 0, lty = 'dotted')
> 
> This shows rather clearly that your function has multiple roots, which isn't
> surprising given that it's a linear combination of sines and cosines. To
> find a specific root numerically, use function uniroot on f, as follows:
> 
>> uniroot(f, c(0, 2))

Except he was asking for the root of the derivative. If the classroom 
assignment allows use of R's limited symbolic differentiation you could try:

> df.dx <- D(expression(5*cos(2*x)-2*x*sin(2*x)), "x")
> df.dx
-(5 * (sin(2 * x) * 2) + (2 * sin(2 * x) + 2 * x * (cos(2 * x) *
   2)))
(Which as one of the examples in the deriv help page notes is not the most 
simple form.)

I was assuming that the OP wanted a solution to:

d( abs(f(x)) )/dt  = 0 in the domain [1,2]

So:
f.df.dx <- function (x) {
eval(parse(text=D(expression(5*cos(2*x)-2*x*sin(2*x)), "x") ) )
   }
#  no abs() but we should be satisfied with either a minimum or a maximum
uniroot(f.df.dx, c(1,2) )

$root
[1] 1.958218267

$f.root
[1] 1.138013788e-05

$iter
[1] 4

$estim.prec
[1] 6.103515625e-05

It doesn't agree with my earlier method and I think this one has a greater 
probablity of being correct. I don't think I needed to take second differences.

-- 
David.

> $root
> [1] 0.6569286
> 
> $f.root
> [1] -0.0001196119
> 
> $iter
> [1] 6
> 
> $estim.prec
> [1] 6.103516e-05
> 
> This catches the root that lies between x = 0 and x = 2. If you want to find
> a set of roots, you can try a loop. Fortunately, since the function is even,
> you really only need to find the roots on one side of zero, since the ones
> on the other side are the same with opposite sign.
> 
> lo <- seq(0, 4.5, by = 1.5)
> hi <-  seq(1.5, 6, by = 1.5)
> roots <- numeric(length(lo))
> 
> for(i in seq_along(lo)) roots[i] <- uniroot(f, c(lo[i], hi[i]))$root
> roots
> 
> See ?uniroot for other options and tolerance settings.
> 
> HTH,
> Dennis
> 
> On Wed, Aug 11, 2010 at 6:21 PM, TGS  wrote:
> 
>> How would I numerically find the x value where the derivative of the
>> function below is zero?
>> 
>> x <- seq(1,2, by = .01)
>> y <- 5*cos(2*x)-2*x*sin(2*x)
>> plot(x,abs(y), type = "l", ylab = "|y|")
> 
-- 

David Winsemius, MD
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.


[R] Derivative

2010-08-11 Thread TGS
How would I numerically find the x value where the derivative of the function 
below is zero?

x <- seq(1,2, by = .01)
y <- 5*cos(2*x)-2*x*sin(2*x)
plot(x,abs(y), type = "l", ylab = "|y|")

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Numerical Methods Course

2010-08-10 Thread TGS
I want to take this numerical methods course where the text is 
http://www.amazon.com/Numerical-Methods-J-Douglas-Faires/dp/0534407617 . The 
instructor recommends MATLAB, but states Fortran, C, Mathematica, or Maple will 
also do the job.

Will R do the job as well?

If not, where do you think it will be lacking in the context of this 
book/course.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Good Book To Work Through This Summer

2010-08-08 Thread TGS
Dear R users,

I'm hoping to get a few suggestions about which books are good to follow along 
and learn R.

I'm hoping to spend the summer going through a good R book as it is applied in 
linear regression.

Thanks!
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Signals and Noise

2010-08-06 Thread TGS
Is there a reference page indicating which packages or functions are available 
in R for the filed of electrical engineering?

I'm not an EE but I've been doing some simulations regarding signals and noise 
and I found the 'tuneR' to be useful. Are there any others?
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Computation Duration Time

2010-08-06 Thread TGS
Is there a way to find out what the computation duration time was to complete 
executing a code chunk?
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.