[R] regex sub with specified number of characters

2015-10-06 Thread Johannes Radinger
Hi

I'd like to remove a leading "3" if my number is 7 digits long, if it is
only 6 I don't want to anything.
I think this should be possible with a 1-liner using sub() but I am not
sure how to define the number of characters following the leading one.

For example my vector:

a <- c(3593857,384723,4395843,3398374)

with sub("^3","",a) I also remove the leading from the second element which
is only 6 digits long. So how to restrict that using sub? The final result
should be

a <- c(593857,384723,4395843,398374)

Any suggestions?

Best regards,
Johannes

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] regex sub with specified number of characters

2015-10-06 Thread Ivan Calandra

Hi Johannes,

Not sure if this can be done with sub() only, but combining it with 
ifelse() apparently does what you want:

ifelse(nchar(a)==7, sub("^3","",a), a)

HTH,
Ivan

--
Ivan Calandra, PhD
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
ivan.calan...@univ-reims.fr
https://www.researchgate.net/profile/Ivan_Calandra

Le 06/10/15 16:38, Johannes Radinger a écrit :

Hi

I'd like to remove a leading "3" if my number is 7 digits long, if it is
only 6 I don't want to anything.
I think this should be possible with a 1-liner using sub() but I am not
sure how to define the number of characters following the leading one.

For example my vector:

a <- c(3593857,384723,4395843,3398374)

with sub("^3","",a) I also remove the leading from the second element which
is only 6 digits long. So how to restrict that using sub? The final result
should be

a <- c(593857,384723,4395843,398374)

Any suggestions?

Best regards,
Johannes

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] regex sub with specified number of characters

2015-10-06 Thread Marc Schwartz

> On Oct 6, 2015, at 9:38 AM, Johannes Radinger  
> wrote:
> 
> Hi
> 
> I'd like to remove a leading "3" if my number is 7 digits long, if it is
> only 6 I don't want to anything.
> I think this should be possible with a 1-liner using sub() but I am not
> sure how to define the number of characters following the leading one.
> 
> For example my vector:
> 
> a <- c(3593857,384723,4395843,3398374)
> 
> with sub("^3","",a) I also remove the leading from the second element which
> is only 6 digits long. So how to restrict that using sub? The final result
> should be
> 
> a <- c(593857,384723,4395843,398374)
> 
> Any suggestions?
> 
> Best regards,
> Johannes


Hi,

> gsub("^3([0-9]{6})$", "\\1", a)
[1] "593857"  "384723"  "4395843" "398374" 

or

> sub("^3([0-9]{6})$", "\\1", a)
[1] "593857"  "384723"  "4395843" "398374" 


If the source begins with a 3 followed by 6 digits only from 0 to 9, it will 
return the 6 digits part of the regex within the parens.

Otherwise, the source is returned unchanged.

See ?regex

Regards,

Marc Schwartz

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 Bug in R

2015-10-06 Thread David L Carlson
There is a simple way to get closer to how a floating point number is stored in 
R with dput():

> dput(min(dataset$gpa))
1.8997615814
> dput(dataset$gpa[290])
1.8997615814

So you can see, the minimum is not 1.9, just very close to 1.9.

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rolf Turner
Sent: Tuesday, October 6, 2015 3:53 AM
To: Berend Hasselman
Cc: r-help@r-project.org; Neverstop
Subject: Re: [R] Strange Bug in R

On 06/10/15 21:28, Berend Hasselman wrote:
>
>> On 6 Oct 2015, at 09:24, Neverstop  wrote:
>>
>> Hi all.
>> I don't understand why R works this way:
>>> rm(list=ls())
>>> require(foreign)
>>> dataset <- read.dta("http://www.ats.ucla.edu/stat/data/ologit.dta;)
>>> min(dataset$gpa)
>> [1] 1.9
>>> min(dataset$gpa)>=1.90
>> [1] FALSE
>>> min(dataset$gpa)>=1.9
>> [1] FALSE
>>> min(dataset$gpa)>1.89
>> [1] TRUE
>> Shouldn't I get 3 TRUEs?
>> Am I missing something?
>> Thank you.
>>
>>
>
> See R FAQ 7.31  in https://cran.r-project.org/doc/FAQ/R-FAQ.html
> It should provide clarification for your puzzlement.

Not really.  The problem is one of the precision to which a floating 
point number is *printed* rather than one of the way that floating point 
numbers are *calculated*.  Hence it is not an instance of the 
counter-intuitive nature of floating point arithmetic.  I.e. you could 
have numbers a and b that were calculated and stored to *infinite* 
precision, appear to be equal when printed to some default number of 
significant figures, but are not actually equal.

The problems are related and both involve having some understanding of 
floating point numbers, but they are not the same problem.

cheers,

Rolf Turner

-- 
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] regex sub with specified number of characters

2015-10-06 Thread David Winsemius

On Oct 6, 2015, at 7:38 AM, Johannes Radinger wrote:

> Hi
> 
> I'd like to remove a leading "3" if my number is 7 digits long, if it is
> only 6 I don't want to anything.
> I think this should be possible with a 1-liner using sub() but I am not
> sure how to define the number of characters following the leading one.
> 
> For example my vector:
> 
> a <- c(3593857,384723,4395843,3398374)
> 
> with sub("^3","",a) I also remove the leading from the second element which
> is only 6 digits long. So how to restrict that using sub? The final result
> should be
> 
> a <- c(593857,384723,4395843,398374)

Use a wild-card capture class of the correct length:

> sub("^3(.{6})$", "\\1", a)
[1] "593857"  "384723"  "4395843" "398374" 

> 
>   [[alternative HTML version deleted]]

It doesn't affect this post but you are requested to post in plain text.

-- 

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 implementation on windows server

2015-10-06 Thread Duncan Murdoch

On 06/10/2015 1:25 PM, Sharique Alam wrote:

Hi Team,

We are required to install r on a windows server

Request you to kindly help us in below queries:

1> Pre requisite for installing R if any


There are none.

2> Do we have to install R and R studio both


R Studio is a separate product; it is a front end for R.  If your users 
want it, you'll need to install it separately.

3> Users also want to utilize shiny package ,so do we only need to install
shiny package or will have to install shiny server also and configure it


Shiny is a package within R.  I don't think it requires R Studio, though 
they're by the same people and work together well.  The server is 
optional --- it will allow your users to make their Shiny applications 
available to others.  If your users want that, it's a separate install.  
The company that produced RStudio and Shiny also runs a service hosting 
Shiny applications; it's free for small demos, but you would pay for 
heavier use.


Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] apply regression to an array

2015-10-06 Thread Adrienne Wootten
Almost forgot that function lmfunc is this:

lmfunc = function(valist,input){
  fitted.values(lm(valist~input))
}

A


On Tue, Oct 6, 2015 at 2:41 PM, Adrienne Wootten  wrote:

> FYI I did try something like this:
>
> test = apply(test3,c(1,2),lmfunc,input=t)
>
> but that gives me an array that is 10 rows by 5 columns by 5 slices, and I
> need it to keep the same dimensions as test3 (5x5x10)
>
> A
>
> On Tue, Oct 6, 2015 at 1:42 PM, Adrienne Wootten 
> wrote:
>
>> R-Helpers,
>>
>> I've seen some similar threads about this question online, but not quite
>> what I'm looking for.  I apologize in advance if someone's already answered
>> this and I just can't find it online.
>>
>> Say that I have an array like test3 in the little example code I have
>> below:
>>
>> test1 = array(rep(1:10,each = 25),dim=c(5,5,10))
>> test2 = array(rnorm(250,0,0.35),dim=c(5,5,10))
>> test3 = test1+test2 # array with 5 rows, 5 columns, 10 slices
>>
>> time=1:10
>>
>> Where the dimensions are x, y, and time.  What I'd like to do is run a
>> regression (for the sake of this example, say lm) on each x,y in time.  So
>> for a single cell the formula might be test3[1,1,]~time, but I'd like to
>> that for all cells.  The only way I can immediately think of is to use a
>> loop, but I'm wondering if there's a way to do this without a loop.
>> Perhaps with tapply?
>>
>> I'm actually doing a fourth order regression with a much larger array,
>> but this simple example illustrates the question I have.
>>
>> Many thanks for the help! Sorry if someone's already answered this and I
>> can't find it.
>>
>> Adrienne
>>
>> --
>> Adrienne Wootten
>> Graduate Research Assistant
>> State Climate Office of North Carolina
>> Department of Marine, Earth and Atmospheric Sciences
>> North Carolina State University
>>
>
>
>
> --
> Adrienne Wootten
> Graduate Research Assistant
> State Climate Office of North Carolina
> Department of Marine, Earth and Atmospheric Sciences
> North Carolina State University
>



-- 
Adrienne Wootten
Graduate Research Assistant
State Climate Office of North Carolina
Department of Marine, Earth and Atmospheric Sciences
North Carolina State University

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] apply regression to an array

2015-10-06 Thread Adrienne Wootten
FYI I did try something like this:

test = apply(test3,c(1,2),lmfunc,input=t)

but that gives me an array that is 10 rows by 5 columns by 5 slices, and I
need it to keep the same dimensions as test3 (5x5x10)

A

On Tue, Oct 6, 2015 at 1:42 PM, Adrienne Wootten  wrote:

> R-Helpers,
>
> I've seen some similar threads about this question online, but not quite
> what I'm looking for.  I apologize in advance if someone's already answered
> this and I just can't find it online.
>
> Say that I have an array like test3 in the little example code I have
> below:
>
> test1 = array(rep(1:10,each = 25),dim=c(5,5,10))
> test2 = array(rnorm(250,0,0.35),dim=c(5,5,10))
> test3 = test1+test2 # array with 5 rows, 5 columns, 10 slices
>
> time=1:10
>
> Where the dimensions are x, y, and time.  What I'd like to do is run a
> regression (for the sake of this example, say lm) on each x,y in time.  So
> for a single cell the formula might be test3[1,1,]~time, but I'd like to
> that for all cells.  The only way I can immediately think of is to use a
> loop, but I'm wondering if there's a way to do this without a loop.
> Perhaps with tapply?
>
> I'm actually doing a fourth order regression with a much larger array, but
> this simple example illustrates the question I have.
>
> Many thanks for the help! Sorry if someone's already answered this and I
> can't find it.
>
> Adrienne
>
> --
> Adrienne Wootten
> Graduate Research Assistant
> State Climate Office of North Carolina
> Department of Marine, Earth and Atmospheric Sciences
> North Carolina State University
>



-- 
Adrienne Wootten
Graduate Research Assistant
State Climate Office of North Carolina
Department of Marine, Earth and Atmospheric Sciences
North Carolina State University

[[alternative HTML version deleted]]

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


[R] variance of beta using prop.odds function in timereg package

2015-10-06 Thread lspirk
Hi all,

I am trying to calculate the variance-covariance matrix for parameter Beta
under the null (Ho) using the "prop.odds" function in the timereg package.

For the Cox PH model, I used the "vcov" function and did the following:

cox <- coxph(Surv(time, censor) ~ x, iter = 0, init = 0, data = dat)
sig2 <- vcov(cox)

However, this vcov() does not work with the object created from "prop.odds".

Is there something similar I can do to get this value from a prop.odds
model?

Thanks for the help!



--
View this message in context: 
http://r.789695.n4.nabble.com/variance-of-beta-using-prop-odds-function-in-timereg-package-tp4713220.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 Bug in R

2015-10-06 Thread Neverstop
Hi all.
I don't understand why R works this way:
> rm(list=ls())
> require(foreign)
> dataset <- read.dta("http://www.ats.ucla.edu/stat/data/ologit.dta;)
> min(dataset$gpa)
[1] 1.9
> min(dataset$gpa)>=1.90
[1] FALSE
> min(dataset$gpa)>=1.9
[1] FALSE
> min(dataset$gpa)>1.89
[1] TRUE
Shouldn't I get 3 TRUEs?
Am I missing something?
Thank you.




--
View this message in context: 
http://r.789695.n4.nabble.com/Strange-Bug-in-R-tp4713175.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] apply regression to an array

2015-10-06 Thread Adrienne Wootten
Bill,

Thanks a bunch that works great!

A

On Tue, Oct 6, 2015 at 2:56 PM, William Dunlap  wrote:

> Since the model matrix, cbind(1,time) is the same for all your
> response variables,
> you can calculate this on one call to lm, but you have to rearrange the
> response
> values so that each x,y set is in one column.  I think the following
> function does it:
>
> f <- function (time, y)
> {
> stopifnot(length(dim(y)) == 3, dim(y)[3] == length(time))
> yMatrix <- matrix(aperm(y, c(3, 1, 2)), dim(y)[3])
> fit <- lm(yMatrix ~ time)
> aperm(array(fitted.values(fit), dim(y)[c(3, 1, 2)]), c(2,
> 3, 1))
> }
>
> E.g.,
> > fitted.values(lm(test1[2,5,]~time))
>  1  2  3  4  5  6  7  8  9 10
>  1  2  3  4  5  6  7  8  9 10
> > f(time, test1)[2,5,]
>  [1]  1  2  3  4  5  6  7  8  9 10
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Tue, Oct 6, 2015 at 10:42 AM, Adrienne Wootten 
> wrote:
> > R-Helpers,
> >
> > I've seen some similar threads about this question online, but not quite
> > what I'm looking for.  I apologize in advance if someone's already
> answered
> > this and I just can't find it online.
> >
> > Say that I have an array like test3 in the little example code I have
> below:
> >
> > test1 = array(rep(1:10,each = 25),dim=c(5,5,10))
> > test2 = array(rnorm(250,0,0.35),dim=c(5,5,10))
> > test3 = test1+test2 # array with 5 rows, 5 columns, 10 slices
> >
> > time=1:10
> >
> > Where the dimensions are x, y, and time.  What I'd like to do is run a
> > regression (for the sake of this example, say lm) on each x,y in time.
> So
> > for a single cell the formula might be test3[1,1,]~time, but I'd like to
> > that for all cells.  The only way I can immediately think of is to use a
> > loop, but I'm wondering if there's a way to do this without a loop.
> > Perhaps with tapply?
> >
> > I'm actually doing a fourth order regression with a much larger array,
> but
> > this simple example illustrates the question I have.
> >
> > Many thanks for the help! Sorry if someone's already answered this and I
> > can't find it.
> >
> > Adrienne
> >
> > --
> > Adrienne Wootten
> > Graduate Research Assistant
> > State Climate Office of North Carolina
> > Department of Marine, Earth and Atmospheric Sciences
> > North Carolina State University
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>



-- 
Adrienne Wootten
Graduate Research Assistant
State Climate Office of North Carolina
Department of Marine, Earth and Atmospheric Sciences
North Carolina State University

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] cut - strange NA as output

2015-10-06 Thread Hermann Norpois
Hello,

why do I get NA for the following:

cut (x, seq (0, max(x), by=1), label=FALSE)
 [1] 1322 1175 1155 1149 1295 1173 1289 1197   NA 1129

dput (x)
c(1321.55376901374, 1174.35657200935, 1154.02042504008, 1148.60981925942,
1294.6166388941, 1172.45806806869, 1288.31933914639, 1196.26080041462,
1355.88836502166, 1128.09901883228)

Thanks
Hermann

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] cut - strange NA as output

2015-10-06 Thread William Dunlap
Because
  > tail(seq(0, max(x), by=1))
  [1] 1350 1351 1352 1353 1354 1355
  > tail(seq(0, ceiling(max(x)), by=1))
  [1] 1351 1352 1353 1354 1355 1356
and max(x)=1355.88836502166 is beyond the range
of the former.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Oct 6, 2015 at 12:20 PM, Hermann Norpois  wrote:
> Hello,
>
> why do I get NA for the following:
>
> cut (x, seq (0, max(x), by=1), label=FALSE)
>  [1] 1322 1175 1155 1149 1295 1173 1289 1197   NA 1129
>
> dput (x)
> c(1321.55376901374, 1174.35657200935, 1154.02042504008, 1148.60981925942,
> 1294.6166388941, 1172.45806806869, 1288.31933914639, 1196.26080041462,
> 1355.88836502166, 1128.09901883228)
>
> Thanks
> Hermann
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] cut - strange NA as output

2015-10-06 Thread Olivier Crouzet
Hi,

On Tue, 6 Oct 2015 21:20:13 +0200
Hermann Norpois  wrote:

> Hello,
> 
> why do I get NA for the following:
> 
> cut (x, seq (0, max(x), by=1), label=FALSE)
>  [1] 1322 1175 1155 1149 1295 1173 1289 1197   NA 1129

The NA comes from your max value and it's due to your seq(0, max(x),
by = 1) creating a sequence that will stop BEFORE your decimal max
(x)... Therefore the element of x which equals 1355.888 is not part of
the allowed outputs of cut().

Are you sure you would not rather use either round (x) or ceiling
(x)? Not sure however what you really want from this...

Olivier.

> 
> dput (x)
> c(1321.55376901374, 1174.35657200935, 1154.02042504008,
> 1148.60981925942, 1294.6166388941, 1172.45806806869,
> 1288.31933914639, 1196.26080041462, 1355.88836502166,
> 1128.09901883228)
> 
> Thanks
> Hermann
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented,
> minimal, self-contained, reproducible code.


-- 
  Olivier Crouzet, PhD
  Laboratoire de Linguistique -- EA3827
  Université de Nantes
  Chemin de la Censive du Tertre - BP 81227
  44312 Nantes cedex 3
  France

 phone:(+33) 02 40 14 14 05 (lab.)
   (+33) 02 40 14 14 36 (office)
 fax:  (+33) 02 40 14 13 27
 e-mail:   olivier.crou...@univ-nantes.fr

  http://www.lling.univ-nantes.fr/

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] cut - strange NA as output

2015-10-06 Thread Marc Schwartz

> On Oct 6, 2015, at 2:20 PM, Hermann Norpois  wrote:
> 
> Hello,
> 
> why do I get NA for the following:
> 
> cut (x, seq (0, max(x), by=1), label=FALSE)
> [1] 1322 1175 1155 1149 1295 1173 1289 1197   NA 1129
> 
> dput (x)
> c(1321.55376901374, 1174.35657200935, 1154.02042504008, 1148.60981925942,
> 1294.6166388941, 1172.45806806869, 1288.31933914639, 1196.26080041462,
> 1355.88836502166, 1128.09901883228)
> 
> Thanks
> Hermann


> max(x)
[1] 1355.888

> range(seq(0, max(x), by = 1))
[1]0 1355


max(x) is outside (above) the range of the integer sequence of break points for 
cut() that you specified above. Thus, when cut() gets to the 9th element in x, 
the value is undefined.

> cut (x, seq(0, max(x) + 1, by = 1), label=FALSE)
 [1] 1322 1175 1155 1149 1295 1173 1289 1197 1356 1129

or

> cut (x, seq(0, ceiling(max(x)), by = 1), label=FALSE)
 [1] 1322 1175 1155 1149 1295 1173 1289 1197 1356 1129


Both of the above approaches will increment the sequence 0:max(x) to 1356:

> range(seq(0, max(x) + 1, by = 1))
[1]0 1356

> range(seq(0, ceiling(max(x)), by = 1))
[1]0 1356


Regards,

Marc Schwartz

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


Re: [R] help with problem

2015-10-06 Thread David L Carlson
You have a warning, not an error. The command ran but there was a problem with 
the .csv or .txt file. 

You should have a partial data set in R. Try using the str() function to see 
what variables and what rows were read. Adding the fill=TRUE argument to 
read.table() will pad incomplete rows with blanks, but you should check the 
data to make sure you have what you were expecting.

Without the data it is impossible to be sure, but you may have an incomplete 
line at the end of your data file. Use a text editor to look at your data so 
see if the last line is incomplete. 

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Marco Otoya 
Chavarria
Sent: Tuesday, October 6, 2015 10:15 AM
To: r-help@r-project.org
Subject: [R] help with problem

*When i tried to read a table i**n .csv or .txt format R i get the
following message and give some problem in orden to run the data o
make test, etc*

*Warning message*

*In read.table(file = file, header = header, sep =";")
*>*  incomplete final line found by readTableHeader on 'test.csv*

*I tried Uninstall R and Excel, and install again but the problem doesnt fix.*

*Regard*

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] vector graphics

2015-10-06 Thread Adams, Jean
Perhaps the discussion at this link will be helpful ...
http://stackoverflow.com/questions/9555889/producing-a-vector-graphics-image-i-e-metafile-in-r-suitable-for-printing-in

Jean

On Tue, Oct 6, 2015 at 9:42 AM, Ivan Calandra 
wrote:

> Dear useRs,
>
> A colleague of mine is having a problem with graphic devices. The goal is
> to save into a vector graphic format that can be edited with Illustrator
> CS4.
>
> On my Mac (Snow Leopard), I use RSvgDevice::devSVG() and it works fine.
> But on her Windows Vista computer, I cannot find an alternative.>
> sessionInfo()
> R version 3.2.2 (2015-08-14)
> Platform: i386-w64-mingw32/i386 (32-bit)
> Running under: Windows Vista (build 6002) Service Pack 2
>
> I have tried:
> - pdf(): I cannot dissociate the graphical elements (no problem with text)
> - cairo_pdf(): the text is replaced by symbols
> - cairo_ps(): fine except that the text is not text but object (it is then
> a bit troublesome, as any text modification requires the text to be
> completely rewritten)
> - svg(): the graphic is completely screwed up (it seems to be a scaling
> problem, with symbols and letters all very large and superposed)
> - RSvgDevice cannot be installed on the Windows machine, neither as binary
> nor from source.
>
> Is there any other device that could work? If not, is it a matter of
> settings? So, basically, what can I do?
>
> Thank you in advance,
> Ivan
>
> --
> Ivan Calandra, PhD
> University of Reims Champagne-Ardenne
> GEGENAA - EA 3795
> CREA - 2 esplanade Roland Garros
> 51100 Reims, France
> +33(0)3 26 77 36 89
> ivan.calan...@univ-reims.fr
> https://www.researchgate.net/profile/Ivan_Calandra
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] apply regression to an array

2015-10-06 Thread David Winsemius

On Oct 6, 2015, at 10:42 AM, Adrienne Wootten wrote:

> R-Helpers,
> 
> I've seen some similar threads about this question online, but not quite
> what I'm looking for.  I apologize in advance if someone's already answered
> this and I just can't find it online.
> 
> Say that I have an array like test3 in the little example code I have below:
> 
> test1 = array(rep(1:10,each = 25),dim=c(5,5,10))
> test2 = array(rnorm(250,0,0.35),dim=c(5,5,10))
> test3 = test1+test2 # array with 5 rows, 5 columns, 10 slices
> 
> time=1:10
> 
> Where the dimensions are x, y, and time.  What I'd like to do is run a
> regression (for the sake of this example, say lm) on each x,y in time.  So
> for a single cell the formula might be test3[1,1,]~time, but I'd like to
> that for all cells.  The only way I can immediately think of is to use a
> loop, but I'm wondering if there's a way to do this without a loop.
> Perhaps with tapply?

 Would not be expecting a 5x5x10 results since you are using the last dimension 
to calculate a two parameters for each row and col. Why not use a loop? Doing 
it with an index is just a a disguised loop:

apply( test3, 1:2, function(x) coef(lm(x~time) ) ) # iterates over rows and 
cols.
# results is 5 x 5 x2

> 
> I'm actually doing a fourth order regression with a much larger array, but
> this simple example illustrates the question I have.
> 
> Many thanks for the help! Sorry if someone's already answered this and I
> can't find it.
> 
> Adrienne
> 
> -- 
> Adrienne Wootten
> Graduate Research Assistant
> State Climate Office of North Carolina
> Department of Marine, Earth and Atmospheric Sciences
> North Carolina State University
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] count by category

2015-10-06 Thread Thierry Onkelinx
Here is a solution using dplyr.

dataset <- data.frame(
  region = rep(1:2, c(6, 1)),
  city = rep(1:2, c(5, 2)),
  town = rep(1:2, c(4, 3)),
  district = rep(1:3, c(2, 2, 3))
)
library(dplyr)
dataset %>%
  group_by(region) %>%
  mutate(n.region = n()) %>%
  group_by(city, add = TRUE) %>%
  mutate(n.city = n()) %>%
  group_by(town, add = TRUE) %>%
  mutate(n.town = n()) %>%
  group_by(district, add = TRUE) %>%
  mutate(n.district = n())


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2015-10-06 6:32 GMT+02:00 PIKAL Petr :

> Hi
>
> there are maybe better solutions but I would use ave with length function
> for each column separately to add new column.
>
> See ?ave
>
> Cheers
> Petr
>
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Val
> > Sent: Tuesday, October 06, 2015 1:01 AM
> > To: r-help@r-project.org
> > Subject: [R] count by category
> >
> > Hi All,
> >
> > I have a data set ( region,  city,  town and district). The data looks
> > like region, city, town, district
> > 1  1  1  1
> > 1  1  1  2
> > 1  1  1  3
> > 1  1  2  1
> > 1  1  2  2
> > 1  2  1  1
> >
> > I want the  counts for   region, city and town.  Here region 1 has 6
> > records, city 1 has 5 records and city 2 has 1 record. Similarly, town
> > 1 has 3 records and town 2 has 2  and so  on.
> > Desired out put to a file
> > 1  1  1  1  6 5 3
> > 1  1  1  2  6 5 3
> > 1  1  1  3  6 5 3
> > 1  1  2  1  6 5 2
> > 1  1  2  2  6 5 2
> > 1  2  3  1  6 1 1
> >
> > Thank you in advance
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> > guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> 
> Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou
> určeny pouze jeho adresátům.
> Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě
> neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie
> vymažte ze svého systému.
> Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email
> jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
> Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi
> či zpožděním přenosu e-mailu.
>
> V případě, že je tento e-mail součástí obchodního jednání:
> - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření
> smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
> - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout;
> Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany
> příjemce s dodatkem či odchylkou.
> - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve
> výslovným dosažením shody na všech jejích náležitostech.
> - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za
> společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn
> nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto
> emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich
> existence je adresátovi či osobě jím zastoupené známá.
>
> This e-mail and any documents attached to it may be confidential and are
> intended only for its intended recipients.
> If you received this e-mail by mistake, please immediately inform its
> sender. Delete the contents of this e-mail with all attachments and its
> copies from your system.
> If you are not the intended recipient of this e-mail, you are not
> authorized to use, disseminate, copy or disclose this e-mail in any manner.
> The sender of this e-mail shall not be liable for any possible damage
> caused by modifications of the e-mail or by delay with transfer of the
> email.
>
> In case that this e-mail forms part of business dealings:
> - the sender reserves the right to end negotiations about entering into a
> contract in any time, for any reason, and without stating any reasoning.
> - if the e-mail contains an offer, the recipient is entitled to
> immediately accept such offer; The sender of this e-mail (offer) excludes
> any acceptance of the offer on the part of the recipient containing any
> amendment or variation.
> - the sender 

Re: [R] count by category

2015-10-06 Thread Jim Lemon
Hi Val,
You can even get a graphic illustration of this quite easily:

library(plotrix)
sizetree(dataset)

Jim


On Tue, Oct 6, 2015 at 10:00 AM, Val  wrote:

> Hi All,
>
> I have a data set ( region,  city,  town and district). The data looks like
> region, city, town, district
> 1  1  1  1
> 1  1  1  2
> 1  1  1  3
> 1  1  2  1
> 1  1  2  2
> 1  2  1  1
>
> I want the  counts for   region, city and town.  Here region 1 has 6
> records, city 1 has 5 records and city 2 has 1 record. Similarly, town 1
> has 3 records and town 2 has 2  and so  on.
> Desired out put to a file
> 1  1  1  1  6 5 3
> 1  1  1  2  6 5 3
> 1  1  1  3  6 5 3
> 1  1  2  1  6 5 2
> 1  1  2  2  6 5 2
> 1  2  3  1  6 1 1
>
> Thank you in advance
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 Bug in R

2015-10-06 Thread Rolf Turner

On 06/10/15 20:24, Neverstop wrote:

Hi all.
I don't understand why R works this way:

rm(list=ls())
require(foreign)
dataset <- read.dta("http://www.ats.ucla.edu/stat/data/ologit.dta;)
min(dataset$gpa)

[1] 1.9

min(dataset$gpa)>=1.90

[1] FALSE

min(dataset$gpa)>=1.9

[1] FALSE

min(dataset$gpa)>1.89

[1] TRUE
Shouldn't I get 3 TRUEs?


No.


Am I missing something?


Comprehension of significant digits and the storage of floating point 
numbers.


Try:

   print(min(dataset$gpa),digits=10)

Please don't refer to phenomena as "bugs" unless you are really sure 
that they are not simply instances of things that you don't understand.
R was designed and written by very clever people and has been used, 
tested and pushed to its limits by a wide variety of users for over 20 
years.  It is highly improbable that you would stumble upon a real bug 
in such a simple context.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 Bug in R

2015-10-06 Thread Berend Hasselman

> On 6 Oct 2015, at 09:24, Neverstop  wrote:
> 
> Hi all.
> I don't understand why R works this way:
>> rm(list=ls())
>> require(foreign)
>> dataset <- read.dta("http://www.ats.ucla.edu/stat/data/ologit.dta;)
>> min(dataset$gpa)
> [1] 1.9
>> min(dataset$gpa)>=1.90
> [1] FALSE
>> min(dataset$gpa)>=1.9
> [1] FALSE
>> min(dataset$gpa)>1.89
> [1] TRUE
> Shouldn't I get 3 TRUEs?
> Am I missing something?
> Thank you.
> 
> 

See R FAQ 7.31  in https://cran.r-project.org/doc/FAQ/R-FAQ.html
It should provide clarification for your puzzlement.

Berend


> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Strange-Bug-in-R-tp4713175.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 Bug in R

2015-10-06 Thread Rolf Turner

On 06/10/15 21:28, Berend Hasselman wrote:



On 6 Oct 2015, at 09:24, Neverstop  wrote:

Hi all.
I don't understand why R works this way:

rm(list=ls())
require(foreign)
dataset <- read.dta("http://www.ats.ucla.edu/stat/data/ologit.dta;)
min(dataset$gpa)

[1] 1.9

min(dataset$gpa)>=1.90

[1] FALSE

min(dataset$gpa)>=1.9

[1] FALSE

min(dataset$gpa)>1.89

[1] TRUE
Shouldn't I get 3 TRUEs?
Am I missing something?
Thank you.




See R FAQ 7.31  in https://cran.r-project.org/doc/FAQ/R-FAQ.html
It should provide clarification for your puzzlement.


Not really.  The problem is one of the precision to which a floating 
point number is *printed* rather than one of the way that floating point 
numbers are *calculated*.  Hence it is not an instance of the 
counter-intuitive nature of floating point arithmetic.  I.e. you could 
have numbers a and b that were calculated and stored to *infinite* 
precision, appear to be equal when printed to some default number of 
significant figures, but are not actually equal.


The problems are related and both involve having some understanding of 
floating point numbers, but they are not the same problem.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

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


Re: [R] help with problem

2015-10-06 Thread Sarah Goslee
http://stackoverflow.com/questions/5990654/incomplete-final-line-warning-when-trying-to-read-a-csv-file-into-r

On Tue, Oct 6, 2015 at 11:14 AM, Marco Otoya Chavarria
 wrote:
> *When i tried to read a table i**n .csv or .txt format R i get the
> following message and give some problem in orden to run the data o
> make test, etc*
>
> *Warning message*
>
> *In read.table(file = file, header = header, sep =";")
> *>*  incomplete final line found by readTableHeader on 'test.csv*
>
> *I tried Uninstall R and Excel, and install again but the problem doesnt fix.*
>
> *Regard*
>

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Getting monthly mean

2015-10-06 Thread Sarah Goslee
There are various tools available; searching for netcdf on rseek.org
or browsing CRAN will get you quite a few.

Meanwhile this might help you get started:
http://disc.sci.gsfc.nasa.gov/recipes/?q=recipes/How-to-Read-Data-in-netCDF-Format-with-R

Sarah

On Tue, Oct 6, 2015 at 11:31 AM, timilsina
 wrote:
> Hi all,
>
> How can I get the monthly means from netcdf files using R? If there is any
> examples already on web resources? Please share with me.
>
>
>
> Regards,
> Amit
>
>


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] R implementation on windows server

2015-10-06 Thread Sharique Alam
Hi Team,

We are required to install r on a windows server

Request you to kindly help us in below queries:

1> Pre requisite for installing R if any
2> Do we have to install R and R studio both
3> Users also want to utilize shiny package ,so do we only need to install
shiny package or will have to install shiny server also and configure it

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] apply regression to an array

2015-10-06 Thread William Dunlap
Since the model matrix, cbind(1,time) is the same for all your
response variables,
you can calculate this on one call to lm, but you have to rearrange the response
values so that each x,y set is in one column.  I think the following
function does it:

f <- function (time, y)
{
stopifnot(length(dim(y)) == 3, dim(y)[3] == length(time))
yMatrix <- matrix(aperm(y, c(3, 1, 2)), dim(y)[3])
fit <- lm(yMatrix ~ time)
aperm(array(fitted.values(fit), dim(y)[c(3, 1, 2)]), c(2,
3, 1))
}

E.g.,
> fitted.values(lm(test1[2,5,]~time))
 1  2  3  4  5  6  7  8  9 10
 1  2  3  4  5  6  7  8  9 10
> f(time, test1)[2,5,]
 [1]  1  2  3  4  5  6  7  8  9 10


Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Oct 6, 2015 at 10:42 AM, Adrienne Wootten  wrote:
> R-Helpers,
>
> I've seen some similar threads about this question online, but not quite
> what I'm looking for.  I apologize in advance if someone's already answered
> this and I just can't find it online.
>
> Say that I have an array like test3 in the little example code I have below:
>
> test1 = array(rep(1:10,each = 25),dim=c(5,5,10))
> test2 = array(rnorm(250,0,0.35),dim=c(5,5,10))
> test3 = test1+test2 # array with 5 rows, 5 columns, 10 slices
>
> time=1:10
>
> Where the dimensions are x, y, and time.  What I'd like to do is run a
> regression (for the sake of this example, say lm) on each x,y in time.  So
> for a single cell the formula might be test3[1,1,]~time, but I'd like to
> that for all cells.  The only way I can immediately think of is to use a
> loop, but I'm wondering if there's a way to do this without a loop.
> Perhaps with tapply?
>
> I'm actually doing a fourth order regression with a much larger array, but
> this simple example illustrates the question I have.
>
> Many thanks for the help! Sorry if someone's already answered this and I
> can't find it.
>
> Adrienne
>
> --
> Adrienne Wootten
> Graduate Research Assistant
> State Climate Office of North Carolina
> Department of Marine, Earth and Atmospheric Sciences
> North Carolina State University
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Installing pre-compiled R in Linux

2015-10-06 Thread Sasikumar Kandhasamy
Hi,

I have downloaded the pre-compiled version of R package:
r-base-core(3.2.2-1) for i386 platform. Unzipped the package under my tmp
directory (/tmp). The directories "et"c and "usr" got created with binaries
R and Rscript under /tmp/usr/bin/.

Executing the R (/tmp/usr/bin/R) or Rscript (/tmp/usr/bin/Rscipt) reports
the below error,

./usr/bin/R
 ./usr/bin/R: line 238:
/usr/lib/R/etc/ldpaths: No such file or directory
ERROR: R_HOME ('/usr/lib/R') not found

How to reconfigure the R environment variables? Because, i tried setting
the R_HOME directory to "/tmp/usr/lib/R" but still not working.

The Linux version i am using is  2.6.32. Please help me with the steps to
install the R correctly. Thanks.

Regards
Sasi

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Measure the frequencies of pairs in a matrix

2015-10-06 Thread Boris Steipe
Since order is not important to you, you can order your pairs (e.g. decreasing) 
before compiling the frequencies.
But I don't understand the second part about values "that do not appear in the 
matrix". Do you mean you want to assess all combinations? If that's the case I 
would think about a hash table or other indexed data structure, rather than 
iterating through a matrix.


B.



On Oct 6, 2015, at 4:59 PM, Hermann Norpois  wrote:

> Hello,
> 
> I have a matrix mat (see dput(mat))
> 
>> mat
>  [,1] [,2]
> [1,]56
> [2,]65
> [3,]54
> [4,]55
> 
> 
> I want the frequencies of the pairs in a new matrix, whereas the
> combination 5 and 6 is the same as 6 and 5 (see the first two rows of mat).
> In other words: What is the probability of each combination (each row)
> ignoring the order in the combination. As a result I would like to have a
> matrix that includes rows and cols 0, 1, 2 ... max (mat) that do not appear
> in my matrix.
> 
> dput (mat)
> structure(c(5, 6, 5, 5, 4, 3, 6, 7, 4, 7, 5, 5, 5, 5, 6, 5, 5,
> 4, 3, 6, 7, 4, 7, 5, 5, 5, 6, 5, 4, 5, 5, 7, 5, 6, 3, 5, 6, 7,
> 6, 6, 5, 4, 5, 5, 7, 5, 6, 3, 5, 6, 7, 6), .Dim = c(26L, 2L))
> 
> Thanks
> Hermann
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Installing pre-compiled R in Linux

2015-10-06 Thread Michael Hannon
It's very likely that there is already an R package for your linux
system, and, if so, you'd probably be well-served to use that one.
You've given us the version of the kernel you're using (not a recent
one, BTW), but what linux distribution are you using?

-- Mike


On Tue, Oct 6, 2015 at 3:59 PM, Sasikumar Kandhasamy  wrote:
> Hi,
>
> I have downloaded the pre-compiled version of R package:
> r-base-core(3.2.2-1) for i386 platform. Unzipped the package under my tmp
> directory (/tmp). The directories "et"c and "usr" got created with binaries
> R and Rscript under /tmp/usr/bin/.
>
> Executing the R (/tmp/usr/bin/R) or Rscript (/tmp/usr/bin/Rscipt) reports
> the below error,
>
> ./usr/bin/R
>  ./usr/bin/R: line 238:
> /usr/lib/R/etc/ldpaths: No such file or directory
> ERROR: R_HOME ('/usr/lib/R') not found
>
> How to reconfigure the R environment variables? Because, i tried setting
> the R_HOME directory to "/tmp/usr/lib/R" but still not working.
>
> The Linux version i am using is  2.6.32. Please help me with the steps to
> install the R correctly. Thanks.
>
> Regards
> Sasi
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Result error using the function

2015-10-06 Thread Adams, Jean
I have simplified your function.  And I have transposed your results such
that resulting metrics are in columns rather than rows.  So, it's not
exactly what you were after, but perhaps you will find it useful.

monthly_summary <- function(dt, r, tol=1E-6) {
  # number of days with above tol by year and month
  mt1 <- tapply(dt[, "Amount"] > tol, dt[, c("Month", "Year")], sum)
  # mean number of days with above tol by month
  mn <- apply(mt1, 1, mean)
  # proportion of days with above tol by year and month
  pd1 <- tapply(dt[, "Amount"] > tol, dt[, c("Month", "Year")], mean)
  # mean proportion of days with above tol by month
  mnp <- apply(mt1, 1, mean)
  # inverse of this proportion
  lambda <- 1/mnp
  cbind(mt1, mn, lambda)
}

m_sum <- monthly_summary(J1, 2)
m_sum

Jean


On Tue, Oct 6, 2015 at 1:33 AM, smart hendsome 
wrote:

> Hi R-users,
>
>
> I am new to R.  I try to code using the function in R as below:
>  monthly_summary <- function(dt,r)
> {  tol <- 1E-6
>mn  <- vector(length=12, mode="numeric")
>lambda  <- vector(length=12, mode="numeric")
>ag  <- aggregate(dt[,4] > tol, list (dt[,2], dt[,1]), sum)
>names(ag) <- c("Year", "Month","Amount")
>mt1 <- matrix(ag[,3],nrow=r,ncol=12,byrow=T)
>rownames(mt1) <- 1950:1951
>colnames(mt1) <- c("Jan","Feb","Mar","Apr","May","June","July",
>  "Aug","Sept","Oct","Nov","Dec")
>
>   for (i in 1:ncol(mt1))
>   {
>   {  xi <- mt1[,i]
>  mn[i]  <- mean(xi)## calc mean
>   }
>
>   if  (mt1[,c(1,3,5,7,8,10,12)])
>   {
>lambda[i]  <- (31/mn[i])   ## calc lambda
> for month with 31 days
>   }
>   else if  (mt1[,2])
>{
>lambda[i]  <- (28/mn[i])## calc lambda
> for month with 28 days
>}
>else
>{
>   lambda[i]  <- (30/mn[i])  ## calc lambda
> for month with 30 days
>}
>
>   ## result
>   mt1 <- round(mt1, 0)
>   mn <-   round(mn, 3)
>   lambda <- round(lambda, 3)
>
> }
>   comb <- rbind(mt1, mn = mn, lambda = lambda)
> }
>
> ## call function
> m_sum <- monthly_summary(J1,2); m_sum
>
> The problems are:
> 1)the value of count rain in decimals
> 2) the value lambda is wrong3)i dont know how to account the leap years in
> february
> Anyone can help me?
> I also provide my data using dput(). Thanks so much.
> structure(list(Year = c(1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 

Re: [R] Strange Bug in R

2015-10-06 Thread Pascal Oettli
Hello,

1) Please don't put rm(list=ls()) in a script you submit to this list.
This is considered as bad manner.

2) Please read 
https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
and http://stackoverflow.com/a/9508558/3710546

Regards,
Pascal

On Tue, Oct 6, 2015 at 4:24 PM, Neverstop  wrote:
> Hi all.
> I don't understand why R works this way:
>> rm(list=ls())
>> require(foreign)
>> dataset <- read.dta("http://www.ats.ucla.edu/stat/data/ologit.dta;)
>> min(dataset$gpa)
> [1] 1.9
>> min(dataset$gpa)>=1.90
> [1] FALSE
>> min(dataset$gpa)>=1.9
> [1] FALSE
>> min(dataset$gpa)>1.89
> [1] TRUE
> Shouldn't I get 3 TRUEs?
> Am I missing something?
> Thank you.
>
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Strange-Bug-in-R-tp4713175.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Pascal Oettli
Project Scientist
JAMSTEC
Yokohama, Japan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Measure the frequencies of pairs in a matrix

2015-10-06 Thread Hermann Norpois
Hello,

I have a matrix mat (see dput(mat))

> mat
  [,1] [,2]
 [1,]56
 [2,]65
 [3,]54
 [4,]55
 

 I want the frequencies of the pairs in a new matrix, whereas the
combination 5 and 6 is the same as 6 and 5 (see the first two rows of mat).
In other words: What is the probability of each combination (each row)
ignoring the order in the combination. As a result I would like to have a
matrix that includes rows and cols 0, 1, 2 ... max (mat) that do not appear
in my matrix.

 dput (mat)
structure(c(5, 6, 5, 5, 4, 3, 6, 7, 4, 7, 5, 5, 5, 5, 6, 5, 5,
4, 3, 6, 7, 4, 7, 5, 5, 5, 6, 5, 4, 5, 5, 7, 5, 6, 3, 5, 6, 7,
6, 6, 5, 4, 5, 5, 7, 5, 6, 3, 5, 6, 7, 6), .Dim = c(26L, 2L))

Thanks
Hermann

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Bug in auglag?

2015-10-06 Thread Ravi Varadhan
Dear Rainer,
This is NOT a bug in auglag.  I already mentioned that auglag() can work with 
infeasible starting values, which also implies that the function must be 
evaluable at infeasible values.  A simple solution to your problem would be to 
fix up your objective function such that it evaluates to `Inf' or some large 
value, when the parameter values are not in the constrained domain.  
constrOptim.nl() is a barrier method so it forces the initial value and the 
subsequent iterates to be feasible.
Best,
Ravi

From: Rainer M Krug 
Sent: Tuesday, October 6, 2015 9:20 AM
To: Ravi Varadhan
Cc: 'r-help@r-project.org'
Subject: Bug in auglag?

Hi Ravi,

I would like come back to your offer. I have a problem which possibly is
caused by a bug or by something I don't understand:

My function to be minimised is executed even when an element in hin() is
negative.

My hin looks as follow:

--8<---cut here---start->8---
hinMahat <- function(x, hauteur, na, zjoint, y, LAI, ...) {
if (x[1] < 0) {
cat(names(list(...)), "\n")
cat(..., "\n")
cat(x, "|", hauteur, LAI, y, "\n")
}

h <- rep(NA, 8)
if (!missing(na)) {
x <- c(na, x )
}
if (!missing(y)) {
x <- c(x, y)
}
if (!missing(zjoint)) {
x <- c(x[1], zjoint, x[2])
}

##
dep <- hauteur * (0.05 + LAI^0.02 / 2) + (x[3] - 1)/20
h[1] <- dep
h[2] <- hauteur - dep
## if (h[2]==0) {
## h[2] <- -1
## }
##
z0 <- hauteur * (0.23 + LAI^0.25 / 10) + (x[3] - 1)/67
h[3] <- z0
## if (h[3]==0) {
## h[3] <- -1
## }
h[4] <- hauteur - z0
##
h[5] <- x[1]
##
h[6] <- x[2]
h[7] <- hauteur - x[2]
##
h[8] <- hauteur - dep - z0
if (any(h<=0)) {
cat(h, "\n")
cat("\n")
}
return(h)
}
--8<---cut here---end--->8---

the x contains up to three elements: c(na=, zjoint=, y=) and I fit these
three, unless one or two are specified explicitely.

The values going into hin are:

,
| ... (z  u ua za z0sol )
| 3 11 17 23 29 37 0.315 0.422 0.458 0.556 1.567 1.747 1.747 37 0.001
|
| x(na, zjoint): -8.875735 24.51316
| hauteur: 28
| na:  8.1
| y:   3
|
| the resulting hin() is:
| 16.09815 11.90185 11.19352 16.80648 -8.875735 24.51316 3.486843 0.708335
`


Which is negative in element 5 as x[2]=na is negative.

So I would expect that the function fn is not evaluated. But it is, and
raises an error:

,
| Error in wpLELMahat(z = z, ua = ua, na = ifelse(missing(na), par[1], na),  :
|   na has to be larger or equal than zero!
`

Is this a misunderstanding on my part, or is it an error in the function
auglag?


Below is the function which is doing the minimisation.

If I replace auglag() with constrOptim.nl(), the optimisation is working
as expected.

So I think this is a bug in auglag?

Let me know if you need further information.

Cheers,

Rainer

--8<---cut here---start->8---
fitAuglag.wpLEL.mahat.single <- function(
 z,
 u,
 LAI,
 initial = c(na=9, zjoint=0.2*2, y=3),
 na, zjoint, y,
 h  = 28,
 za = 37,
 z0sol  = 0.001,
 hin,
 ...
 ) {
if (missing(hin)) {
hin <- hinMahat
}

wpLELMin <- function(par, na, zjoint, y, z, u, ua, hauteur, za, z0sol, LAI) 
{
result <- NA
try({
p <- wpLELMahat(
z  = z,
ua = ua,
na = ifelse(missing(na), par[1], na),
zjoint = ifelse(missing(zjoint), par[2], zjoint),
h  = hauteur,
za = za,
z0sol  = z0sol,
LAI= LAI,
y  = ifelse(missing(y), par[3], y)
)
result <- sum( ( (p$u - u)^2 ) / length(u) )
},
silent = FALSE
)
## cat("From wpLELMin", par, "\n")
return( result )
}

ua <- u[length(u)]
result <- list()
result$method <- "fitAuglag.wpLEL.mahat.single"
result$initial <-  initial
result$dot <- list(...)
result$z <- z
result$u <- u

result$fit <- auglag(
par = initial,
fn= wpLELMin,
hin   = hin,
na = na,
zjoint = zjoint,
y  = y,
##
z = z,
u = u,
ua= ua,
hauteur = h,
za= za,
z0sol = z0sol,
LAI   = LAI,
...
)
  

Re: [R] cut - strange NA as output

2015-10-06 Thread Hermann Norpois
Thanks this was very helpful.

@Olivier Crouzet: Yes, round (x) would do the job but it was a principal
confusion ...

2015-10-06 21:57 GMT+02:00 Marc Schwartz :

>
> > On Oct 6, 2015, at 2:20 PM, Hermann Norpois  wrote:
> >
> > Hello,
> >
> > why do I get NA for the following:
> >
> > cut (x, seq (0, max(x), by=1), label=FALSE)
> > [1] 1322 1175 1155 1149 1295 1173 1289 1197   NA 1129
> >
> > dput (x)
> > c(1321.55376901374, 1174.35657200935, 1154.02042504008, 1148.60981925942,
> > 1294.6166388941, 1172.45806806869, 1288.31933914639, 1196.26080041462,
> > 1355.88836502166, 1128.09901883228)
> >
> > Thanks
> > Hermann
>
>
> > max(x)
> [1] 1355.888
>
> > range(seq(0, max(x), by = 1))
> [1]0 1355
>
>
> max(x) is outside (above) the range of the integer sequence of break
> points for cut() that you specified above. Thus, when cut() gets to the 9th
> element in x, the value is undefined.
>
> > cut (x, seq(0, max(x) + 1, by = 1), label=FALSE)
>  [1] 1322 1175 1155 1149 1295 1173 1289 1197 1356 1129
>
> or
>
> > cut (x, seq(0, ceiling(max(x)), by = 1), label=FALSE)
>  [1] 1322 1175 1155 1149 1295 1173 1289 1197 1356 1129
>
>
> Both of the above approaches will increment the sequence 0:max(x) to 1356:
>
> > range(seq(0, max(x) + 1, by = 1))
> [1]0 1356
>
> > range(seq(0, ceiling(max(x)), by = 1))
> [1]0 1356
>
>
> Regards,
>
> Marc Schwartz
>
>

[[alternative HTML version deleted]]

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


Re: [R] help with problem

2015-10-06 Thread Sarah Hardy
It's possible that you have some invisible characters in the last line(s)
of the csv file.
You can use a text editor as Davis suggested or in Excel delete a bunch of
the blank rows after the end of the data rows.
If that doesn't work cut-and paste the rows you do want into a fresh
spreadsheet.

Sarah


On Tue, Oct 6, 2015 at 4:59 PM, David L Carlson  wrote:

> You have a warning, not an error. The command ran but there was a problem
> with the .csv or .txt file.
>
> You should have a partial data set in R. Try using the str() function to
> see what variables and what rows were read. Adding the fill=TRUE argument
> to read.table() will pad incomplete rows with blanks, but you should check
> the data to make sure you have what you were expecting.
>
> Without the data it is impossible to be sure, but you may have an
> incomplete line at the end of your data file. Use a text editor to look at
> your data so see if the last line is incomplete.
>
> -
> David L Carlson
> Department of Anthropology
> Texas A University
> College Station, TX 77840-4352
>
>
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Marco
> Otoya Chavarria
> Sent: Tuesday, October 6, 2015 10:15 AM
> To: r-help@r-project.org
> Subject: [R] help with problem
>
> *When i tried to read a table i**n .csv or .txt format R i get the
> following message and give some problem in orden to run the data o
> make test, etc*
>
> *Warning message*
>
> *In read.table(file = file, header = header, sep =";")
> *>*  incomplete final line found by readTableHeader on 'test.csv*
>
> *I tried Uninstall R and Excel, and install again but the problem doesnt
> fix.*
>
> *Regard*
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Sarah Hardy, PhD
Associate Professor of Mathematics
University of Maine Farmington
207-778-7124Office: Brinkman 100

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] extract all dataframes from list

2015-10-06 Thread maicel
Hello List, I have list of named dataframe. How can I extract all dataframes
from this list? The dataframe names should be the same of the original list.
May I use the lapply function?

Thanks for your help. Best regards,
Maicel Monzon, MD
National Center of Clinical Trials
Havana, Cuba




--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

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


[R] Error Correction Model under Cointegration

2015-10-06 Thread Preetam Pal
Hi All,

I have a time series y_t and 2  other time series x1_t and x2t as regressors. I 
know that these 3 series are cointegrated via the Johansen tests. Hence I want 
to implement an error correction model with 1 lag for each variable (i.e. Lag 
y, lag x1 and lag x2) for projection purposes (suppose, I have future values 
for the regressors).
Is there an R function I can use for this ECM model usage? Note that manually 
it is a bit challenging to pull off because the RHS of this model would have a 
lagged residual term, for which we have no future observations.

Any help here would be appreciated.

Regards,
Preetam
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Result error using the function

2015-10-06 Thread smart hendsome
Hi R-users,


I am new to R.  I try to code using the function in R as below:
 monthly_summary <- function(dt,r)
{  tol <- 1E-6
   mn  <- vector(length=12, mode="numeric")
   lambda  <- vector(length=12, mode="numeric")
   ag  <- aggregate(dt[,4] > tol, list (dt[,2], dt[,1]), sum)
   names(ag) <- c("Year", "Month","Amount")
   mt1 <- matrix(ag[,3],nrow=r,ncol=12,byrow=T)
   rownames(mt1) <- 1950:1951
   colnames(mt1) <- c("Jan","Feb","Mar","Apr","May","June","July",
                 "Aug","Sept","Oct","Nov","Dec")

  for (i in 1:ncol(mt1))
  {
  {  xi <- mt1[,i]
 mn[i]  <- mean(xi)    ## calc mean
  }
 
  if  (mt1[,c(1,3,5,7,8,10,12)]) 
  {
   lambda[i]  <- (31/mn[i])   ## calc lambda for 
month with 31 days
  }
  else if  (mt1[,2])
   {
   lambda[i]  <- (28/mn[i])    ## calc lambda for 
month with 28 days
   }
   else
   {
  lambda[i]  <- (30/mn[i])  ## calc lambda for 
month with 30 days
   }
 
  ## result
  mt1 <- round(mt1, 0)
  mn <-   round(mn, 3)
  lambda <- round(lambda, 3)
  
}  
  comb <- rbind(mt1, mn = mn, lambda = lambda)
}

## call function
m_sum <- monthly_summary(J1,2); m_sum

The problems are:
1)the value of count rain in decimals 
2) the value lambda is wrong3)i dont know how to account the leap years in 
february
Anyone can help me?
I also provide my data using dput(). Thanks so much.
structure(list(Year = c(1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1951L, 
1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 
1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 
1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 
1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 
1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 
1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 
1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 
1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 
1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 
1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 
1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 
1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 1951L, 
1951L, 1951L, 

Re: [R] Quantile Regression without intercept

2015-10-06 Thread Roger Koenker

> On Oct 6, 2015, at 8:32 AM, Lorenz, David  wrote:
> 
> Thanks for the details, I suspected something like that.
> I think that begs the question: what is the meaning of quantile regression 
> through the origin? If the tau=.5 line does not pass through 1/2 the data how 
> do I interpret the line?

As an estimate of the conditional median (quantile) function when constrained 
to pass through
the origin… as with least squares fitting without an intercept, you do this at 
your peril.
> 
> 
> On Tue, Oct 6, 2015 at 8:03 AM, Roger Koenker  wrote:
> 
> > On Oct 6, 2015, at 7:58 AM, Lorenz, David  wrote:
> >
> > Did you verify that the correct percentages were above/below the regression
> > lines? I did a quick check and for example did not consistently get 50% of
> > the observed response values greater than the tau=.5 line. I did when I
> > included the nonzero intercept term.
> 
> Your "correct percentages" are only correct when you have an intercept in the 
> model,
> without an intercept there is no gradient condition to ensure that.
> >
> >
> >
> >> Date: Mon, 5 Oct 2015 21:14:04 +0530
> >> From: Preetam Pal 
> >> To: stephen sefick 
> >> Cc: "r-help@r-project.org" 
> >> Subject: Re: [R] Quantile Regression without intercept
> >> Message-ID: <56129a41.025f440a.b1cf4.f...@mx.google.com>
> >> Content-Type: text/plain; charset="UTF-8"
> >>
> >> Yes..it works.  Thanks ??
> >>
> >> -Original Message-
> >> From: "stephen sefick" 
> >> Sent: ?05-?10-?2015 09:01 PM
> >> To: "Preetam Pal" 
> >> Cc: "r-help@r-project.org" 
> >> Subject: Re: [R] Quantile Regression without intercept
> >>
> >> I have never used this, but does the formula interface work like lm? Y~X-1?
> >>
> >>
> >> On Mon, Oct 5, 2015 at 10:27 AM, Preetam Pal 
> >> wrote:
> >>
> >> Hi guys,
> >>
> >> Can you instruct me please how to run quantile regression without the
> >> intercept term? I only know about the rq function under quantreg package,
> >> but it automatically uses an intercept model. Icant change that, it seems.
> >>
> >> I have numeric data on Y variable (Gdp) and 2 X variables (Hpa and
> >> Unemployment). Their sizes are 125 each.
> >>
> >> Appreciate your help with this.
> >>
> >> Regards,
> >> Preetam
> >>[[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >>
> >>
> >>
> >>
> >>
> >> --
> >>
> >> Stephen Sefick
> >> **
> >> Auburn University
> >> Biological Sciences
> >> 331 Funchess Hall
> >> Auburn, Alabama
> >> 36849
> >> **
> >> sas0...@auburn.edu
> >> http://www.auburn.edu/~sas0025
> >> **
> >>
> >> Let's not spend our time and resources thinking about things that are so
> >> little or so large that all they really do for us is puff us up and make us
> >> feel like gods.  We are mammals, and have not exhausted the annoying little
> >> problems of being mammals.
> >>
> >>-K. Mullis
> >>
> >> "A big computer, a complex algorithm and a long time does not equal
> >> science."
> >>
> >>  -Robert Gentleman
> >>[[alternative HTML version deleted]]
> >>
> >>
> >>
> >>
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 in auglag?

2015-10-06 Thread Rainer M Krug
Hi Ravi,

I would like come back to your offer. I have a problem which possibly is
caused by a bug or by something I don't understand:

My function to be minimised is executed even when an element in hin() is
negative.

My hin looks as follow:

--8<---cut here---start->8---
hinMahat <- function(x, hauteur, na, zjoint, y, LAI, ...) {
if (x[1] < 0) {
cat(names(list(...)), "\n")
cat(..., "\n")
cat(x, "|", hauteur, LAI, y, "\n")
}

h <- rep(NA, 8)
if (!missing(na)) {
x <- c(na, x )
}
if (!missing(y)) {
x <- c(x, y)
}
if (!missing(zjoint)) {
x <- c(x[1], zjoint, x[2])
}

##
dep <- hauteur * (0.05 + LAI^0.02 / 2) + (x[3] - 1)/20
h[1] <- dep
h[2] <- hauteur - dep
## if (h[2]==0) {
## h[2] <- -1
## }
##
z0 <- hauteur * (0.23 + LAI^0.25 / 10) + (x[3] - 1)/67
h[3] <- z0
## if (h[3]==0) {
## h[3] <- -1
## }
h[4] <- hauteur - z0
##
h[5] <- x[1]
##
h[6] <- x[2]
h[7] <- hauteur - x[2]
##
h[8] <- hauteur - dep - z0
if (any(h<=0)) {
cat(h, "\n")
cat("\n")
}
return(h)
}
--8<---cut here---end--->8---

the x contains up to three elements: c(na=, zjoint=, y=) and I fit these
three, unless one or two are specified explicitely.

The values going into hin are:

,
| ... (z  u ua za z0sol )
| 3 11 17 23 29 37 0.315 0.422 0.458 0.556 1.567 1.747 1.747 37 0.001 
| 
| x(na, zjoint): -8.875735 24.51316
| hauteur: 28
| na:  8.1
| y:   3 
| 
| the resulting hin() is:
| 16.09815 11.90185 11.19352 16.80648 -8.875735 24.51316 3.486843 0.708335 
`


Which is negative in element 5 as x[2]=na is negative.

So I would expect that the function fn is not evaluated. But it is, and
raises an error:

,
| Error in wpLELMahat(z = z, ua = ua, na = ifelse(missing(na), par[1], na),  : 
|   na has to be larger or equal than zero!
`

Is this a misunderstanding on my part, or is it an error in the function
auglag?


Below is the function which is doing the minimisation.

If I replace auglag() with constrOptim.nl(), the optimisation is working
as expected.

So I think this is a bug in auglag?

Let me know if you need further information.

Cheers,

Rainer

--8<---cut here---start->8---
fitAuglag.wpLEL.mahat.single <- function(
 z,
 u,
 LAI,
 initial = c(na=9, zjoint=0.2*2, y=3),
 na, zjoint, y,
 h  = 28,
 za = 37,
 z0sol  = 0.001,
 hin,
 ...
 ) {
if (missing(hin)) {
hin <- hinMahat
}

wpLELMin <- function(par, na, zjoint, y, z, u, ua, hauteur, za, z0sol, LAI) 
{
result <- NA
try({
p <- wpLELMahat(
z  = z,
ua = ua,
na = ifelse(missing(na), par[1], na), 
zjoint = ifelse(missing(zjoint), par[2], zjoint),
h  = hauteur,
za = za,
z0sol  = z0sol,
LAI= LAI,
y  = ifelse(missing(y), par[3], y)
)
result <- sum( ( (p$u - u)^2 ) / length(u) )
},
silent = FALSE
)
## cat("From wpLELMin", par, "\n")
return( result )
}

ua <- u[length(u)]
result <- list()
result$method <- "fitAuglag.wpLEL.mahat.single"
result$initial <-  initial
result$dot <- list(...)
result$z <- z
result$u <- u

result$fit <- auglag(
par = initial,
fn= wpLELMin,
hin   = hin,
na = na, 
zjoint = zjoint, 
y  = y,
##
z = z,
u = u,
ua= ua,
hauteur = h,
za= za,
z0sol = z0sol,
LAI   = LAI,
...
)
result$wp <- wpLELMahat(
z  = z,
ua = ua,
na = ifelse ( missing(na), result$fit$par["na"], na),
zjoint = ifelse ( missing(zjoint), result$fit$par["zjoint"], zjoint),
h  = h,
za = za,
z0sol  = z0sol,
LAI= LAI,
y  = ifelse ( missing(y), result$fit$par["y"], y)
)

class(result) <- c(class(result), "wpLELFit")
return(result)
}
#+end_src--8<---cut here---end--->8---



Ravi Varadhan  writes:

> I would recommend that you use auglag() rather than constrOptim.nl()
> in the package "alabama."  It is a better 

Re: [R] Quantile Regression without intercept

2015-10-06 Thread Lorenz, David
Thanks for the details, I suspected something like that.
I think that begs the question: what is the meaning of quantile regression
through the origin? If the tau=.5 line does not pass through 1/2 the data
how do I interpret the line?


On Tue, Oct 6, 2015 at 8:03 AM, Roger Koenker  wrote:

>
> > On Oct 6, 2015, at 7:58 AM, Lorenz, David  wrote:
> >
> > Did you verify that the correct percentages were above/below the
> regression
> > lines? I did a quick check and for example did not consistently get 50%
> of
> > the observed response values greater than the tau=.5 line. I did when I
> > included the nonzero intercept term.
>
> Your "correct percentages" are only correct when you have an intercept in
> the model,
> without an intercept there is no gradient condition to ensure that.
> >
> >
> >
> >> Date: Mon, 5 Oct 2015 21:14:04 +0530
> >> From: Preetam Pal 
> >> To: stephen sefick 
> >> Cc: "r-help@r-project.org" 
> >> Subject: Re: [R] Quantile Regression without intercept
> >> Message-ID: <56129a41.025f440a.b1cf4.f...@mx.google.com>
> >> Content-Type: text/plain; charset="UTF-8"
> >>
> >> Yes..it works.  Thanks ??
> >>
> >> -Original Message-
> >> From: "stephen sefick" 
> >> Sent: ?05-?10-?2015 09:01 PM
> >> To: "Preetam Pal" 
> >> Cc: "r-help@r-project.org" 
> >> Subject: Re: [R] Quantile Regression without intercept
> >>
> >> I have never used this, but does the formula interface work like lm?
> Y~X-1?
> >>
> >>
> >> On Mon, Oct 5, 2015 at 10:27 AM, Preetam Pal 
> >> wrote:
> >>
> >> Hi guys,
> >>
> >> Can you instruct me please how to run quantile regression without the
> >> intercept term? I only know about the rq function under quantreg
> package,
> >> but it automatically uses an intercept model. Icant change that, it
> seems.
> >>
> >> I have numeric data on Y variable (Gdp) and 2 X variables (Hpa and
> >> Unemployment). Their sizes are 125 each.
> >>
> >> Appreciate your help with this.
> >>
> >> Regards,
> >> Preetam
> >>[[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >>
> >>
> >>
> >>
> >>
> >> --
> >>
> >> Stephen Sefick
> >> **
> >> Auburn University
> >> Biological Sciences
> >> 331 Funchess Hall
> >> Auburn, Alabama
> >> 36849
> >> **
> >> sas0...@auburn.edu
> >> http://www.auburn.edu/~sas0025
> >> **
> >>
> >> Let's not spend our time and resources thinking about things that are so
> >> little or so large that all they really do for us is puff us up and
> make us
> >> feel like gods.  We are mammals, and have not exhausted the annoying
> little
> >> problems of being mammals.
> >>
> >>-K. Mullis
> >>
> >> "A big computer, a complex algorithm and a long time does not equal
> >> science."
> >>
> >>  -Robert Gentleman
> >>[[alternative HTML version deleted]]
> >>
> >>
> >>
> >>
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Quantile Regression without intercept

2015-10-06 Thread peter dalgaard
To wit:

> y <- rnorm(100, 10)
> x <- 1:100
> sum(resid(lm(y~x)))
[1] 1.047773e-15
> sum(resid(lm(y~x-1)))
[1] 243.0583

and replicating this should convince you that the mean residual really is not 
zero in the severely misspecified model with no intercept. (This has to do with 
the fact that residuals for small x will be positive but have little leverage 
on the slope of the regression line.) 

With a correctly specified model, the theoretical mean residual is in fact 
zero, but it won't be exactly zero for any individual fit. Try e.g.

> x <- 1:100
> r <- replicate(1, {y <- rnorm(100, x); mean(resid(lm(y~x-1)))})
> hist(r)

-pd

On 06 Oct 2015, at 15:38 , Roger Koenker  wrote:

> 
>> On Oct 6, 2015, at 8:32 AM, Lorenz, David  wrote:
>> 
>> Thanks for the details, I suspected something like that.
>> I think that begs the question: what is the meaning of quantile regression 
>> through the origin? If the tau=.5 line does not pass through 1/2 the data 
>> how do I interpret the line?
> 
> As an estimate of the conditional median (quantile) function when constrained 
> to pass through
> the origin… as with least squares fitting without an intercept, you do this 
> at your peril.
>> 
>> 
>> On Tue, Oct 6, 2015 at 8:03 AM, Roger Koenker  wrote:
>> 
>>> On Oct 6, 2015, at 7:58 AM, Lorenz, David  wrote:
>>> 
>>> Did you verify that the correct percentages were above/below the regression
>>> lines? I did a quick check and for example did not consistently get 50% of
>>> the observed response values greater than the tau=.5 line. I did when I
>>> included the nonzero intercept term.
>> 
>> Your "correct percentages" are only correct when you have an intercept in 
>> the model,
>> without an intercept there is no gradient condition to ensure that.

[snip]

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Quantile Regression without intercept

2015-10-06 Thread Lorenz, David
Did you verify that the correct percentages were above/below the regression
lines? I did a quick check and for example did not consistently get 50% of
the observed response values greater than the tau=.5 line. I did when I
included the nonzero intercept term.



> Date: Mon, 5 Oct 2015 21:14:04 +0530
> From: Preetam Pal 
> To: stephen sefick 
> Cc: "r-help@r-project.org" 
> Subject: Re: [R] Quantile Regression without intercept
> Message-ID: <56129a41.025f440a.b1cf4.f...@mx.google.com>
> Content-Type: text/plain; charset="UTF-8"
>
> Yes..it works.  Thanks ??
>
> -Original Message-
> From: "stephen sefick" 
> Sent: ?05-?10-?2015 09:01 PM
> To: "Preetam Pal" 
> Cc: "r-help@r-project.org" 
> Subject: Re: [R] Quantile Regression without intercept
>
> I have never used this, but does the formula interface work like lm? Y~X-1?
>
>
> On Mon, Oct 5, 2015 at 10:27 AM, Preetam Pal 
> wrote:
>
> Hi guys,
>
> Can you instruct me please how to run quantile regression without the
> intercept term? I only know about the rq function under quantreg package,
> but it automatically uses an intercept model. Icant change that, it seems.
>
> I have numeric data on Y variable (Gdp) and 2 X variables (Hpa and
> Unemployment). Their sizes are 125 each.
>
> Appreciate your help with this.
>
> Regards,
> Preetam
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
>
>
> --
>
> Stephen Sefick
> **
> Auburn University
> Biological Sciences
> 331 Funchess Hall
> Auburn, Alabama
> 36849
> **
> sas0...@auburn.edu
> http://www.auburn.edu/~sas0025
> **
>
> Let's not spend our time and resources thinking about things that are so
> little or so large that all they really do for us is puff us up and make us
> feel like gods.  We are mammals, and have not exhausted the annoying little
> problems of being mammals.
>
> -K. Mullis
>
> "A big computer, a complex algorithm and a long time does not equal
> science."
>
>   -Robert Gentleman
> [[alternative HTML version deleted]]
>
>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Bug in auglag?

2015-10-06 Thread Rainer M Krug
Please ignore - list members - accidentally CCd.

Rainer


Rainer M Krug  writes:

> Hi Ravi,
>
> I would like come back to your offer. I have a problem which possibly is
> caused by a bug or by something I don't understand:
>
> My function to be minimised is executed even when an element in hin() is
> negative.
>
> My hin looks as follow:
>
> hinMahat <- function(x, hauteur, na, zjoint, y, LAI, ...) {
> if (x[1] < 0) {
> cat(names(list(...)), "\n")
> cat(..., "\n")
> cat(x, "|", hauteur, LAI, y, "\n")
> }
>
> h <- rep(NA, 8)
> if (!missing(na)) {
> x <- c(na, x )
> }
> if (!missing(y)) {
> x <- c(x, y)
> }
> if (!missing(zjoint)) {
> x <- c(x[1], zjoint, x[2])
> }
> 
> ##
> dep <- hauteur * (0.05 + LAI^0.02 / 2) + (x[3] - 1)/20
> h[1] <- dep
> h[2] <- hauteur - dep
> ## if (h[2]==0) {
> ## h[2] <- -1
> ## }
> ##
> z0 <- hauteur * (0.23 + LAI^0.25 / 10) + (x[3] - 1)/67
> h[3] <- z0
> ## if (h[3]==0) {
> ## h[3] <- -1
> ## }
> h[4] <- hauteur - z0
> ##
> h[5] <- x[1]
> ##
> h[6] <- x[2]
> h[7] <- hauteur - x[2]
> ##
> h[8] <- hauteur - dep - z0
> if (any(h<=0)) {
> cat(h, "\n")
> cat("\n")
> }
> return(h)
> }
>
> the x contains up to three elements: c(na=, zjoint=, y=) and I fit these
> three, unless one or two are specified explicitely.
>
> The values going into hin are:
>
> ,
> | ... (z  u ua za z0sol )
> | 3 11 17 23 29 37 0.315 0.422 0.458 0.556 1.567 1.747 1.747 37 0.001 
> | 
> | x(na, zjoint): -8.875735 24.51316
> | hauteur: 28
> | na:  8.1
> | y:   3 
> | 
> | the resulting hin() is:
> | 16.09815 11.90185 11.19352 16.80648 -8.875735 24.51316 3.486843 0.708335 
> `
>
>
> Which is negative in element 5 as x[2]=na is negative.
>
> So I would expect that the function fn is not evaluated. But it is, and
> raises an error:
>
> ,
> | Error in wpLELMahat(z = z, ua = ua, na = ifelse(missing(na), par[1], na),  
> : 
> |   na has to be larger or equal than zero!
> `
>
> Is this a misunderstanding on my part, or is it an error in the function
> auglag?
>
>
> Below is the function which is doing the minimisation.
>
> If I replace auglag() with constrOptim.nl(), the optimisation is working
> as expected.
>
> So I think this is a bug in auglag?
>
> Let me know if you need further information.
>
> Cheers,
>
> Rainer
>
> --8<---cut here---start->8---
> fitAuglag.wpLEL.mahat.single <- function(
>  z,
>  u,
>  LAI,
>  initial = c(na=9, zjoint=0.2*2, y=3),
>  na, zjoint, y,
>  h  = 28,
>  za = 37,
>  z0sol  = 0.001,
>  hin,
>  ...
>  ) {
> if (missing(hin)) {
> hin <- hinMahat
> }
>
> wpLELMin <- function(par, na, zjoint, y, z, u, ua, hauteur, za, z0sol, 
> LAI) {
> result <- NA
> try({
> p <- wpLELMahat(
> z  = z,
> ua = ua,
> na = ifelse(missing(na), par[1], na), 
> zjoint = ifelse(missing(zjoint), par[2], zjoint),
> h  = hauteur,
> za = za,
> z0sol  = z0sol,
> LAI= LAI,
> y  = ifelse(missing(y), par[3], y)
> )
> result <- sum( ( (p$u - u)^2 ) / length(u) )
> },
> silent = FALSE
> )
> ## cat("From wpLELMin", par, "\n")
> return( result )
> }
>
> ua <- u[length(u)]
> result <- list()
> result$method <- "fitAuglag.wpLEL.mahat.single"
> result$initial <-  initial
> result$dot <- list(...)
> result$z <- z
> result$u <- u
>
> result$fit <- auglag(
> par = initial,
> fn= wpLELMin,
> hin   = hin,
> na = na, 
> zjoint = zjoint, 
> y  = y,
> ##
> z = z,
> u = u,
> ua= ua,
> hauteur = h,
> za= za,
> z0sol = z0sol,
> LAI   = LAI,
> ...
> )
> result$wp <- wpLELMahat(
> z  = z,
> ua = ua,
> na = ifelse ( missing(na), result$fit$par["na"], na),
> zjoint = ifelse ( missing(zjoint), result$fit$par["zjoint"], zjoint),
> h  = h,
> za = za,
> z0sol  = z0sol,
> LAI= LAI,
> y  = ifelse ( missing(y), result$fit$par["y"], y)
> )
> 
> 

Re: [R-es] Europa

2015-10-06 Thread miguel.angel.rodriguez.muinos
Hola Javier.

El tema de la protección de datos de carácter personal es bastante
complejo (y más si lo extiendes entre países).

Veamos un resumen grosso modo (y algo inexacto)

Cada país tiene su propia legislación sobre datos personale. Cuando
estás trabajando con datos que identifiquen a personas DEBES cumplir las
leyes del país a donde pertenecen esos datos. Hoy en día, el
"alojamiento físico" de los datos puede trascender al país de donde son
originarios y (aunque cada país tiene su legislación que puede decir
otra cosa), por norma general, esos datos deben seguir teniendo el mismo
nivel de seguridad que en origen. En la Unión Europea eso es más
sencillo porque la legislación, en materia de protección de datos, de
los paìses miembros es similar (y están desarrollando una única y que
estará por encima de la de los países -y las invalidará-). El problema
viene cuando esos datos se alojan en países que no tienen el mismo
"nivel legal" (para este caso). Para ello se ha creado el acuerdo de
Puerto Franco que dice qué países tienen el mismo nivel de legislación
(de protección de datos) que la Unión Europea. Ese es el caso de países
como EEUU (USA). Aunque, como bien comentas en tu correo, parece que eso
ya no es así puesto que no son capaces de garantizar el mismo nivel de
seguridad que en la Unión Europea.

Resumiendo: Si tratas con datos que vulneren la intimidad de las
personas tendrás que adaptarte a las normas legales del país
correspondiente y si los transfieres al extranjero tendrás que seguir
cumpliendo con la legislación correspondiente.

NOTA: No sólo se ha de cumplir la legislación vigente en origen y
destino, si no también "por el camino" (en los envíos, transmisiones,
copias, ...)

Mi recomendación es:
- Tener clara la legislación que corresponda a cada país y cumplirla
- Intentar anonimizar los datos con los que se trabaja (siempre que sea
posible)

Este tema, como te dije, es muy extenso y complejo como para resumir en
un mail pero creo que con esto ya tienes por dónde empezar.


Un Saludo,
Miguel.


El 06/10/2015 a las 15:32, Javier Rubén Marcuzzi escribió:
> Estimados
>
> Les consulto por lo siguiente aunque no es 100 % R, si tiene que ver con la 
> fuente de datos para R.
>
> Hoy vi el siguiente artículo: 
> http://www.xataka.com/privacidad/la-ue-anula-el-safe-harbour-las-tecnologicas-no-podran-llevar-libremente-datos-de-europeos-a-eeuu
>
> Últimamente estoy poco en R porque estoy preparando código para ordenar en un 
> servidor los datos para ser analizados en R, ¿debería colocar en servidor en 
> Europa?, ¿Debería analizar en Europa?, ¿Podría cruzar información entre 
> naciones? Por ejemplo el ICAR para las evaluaciones genéticas expresa algunas 
> normas, en la parte estadística hay un MACE, en pocas palabras, se crean 
> correlaciones entre el BLUP de cada evaluación. O ¿Qué pasa si junto datos de 
> pacientes donde se utiliza un fármaco para evaluar a respuesta de los 
> individuos ante la “patología”?,
>
> ¿Qué reglamento debo usar?, ¿Qué tipo de base de datos?, ¿Encriptación?, 
> ¿Dónde conviene radicar la empresa para analizar los datos? (en mi caso sería 
> sencillo porque tengo ciudadanía Argentina, Italiana y el título se valida en 
> España sin inconvenientes).
>
> En otras palabras, ¿Cómo R salta las fronteras para analizar datos?. ¿Alguna 
> sugerencia?
>
> Javier Rubén Marcuzzi
> Técnico en Industrias Lácteas
> Veterinario
>
>   [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es

--
Miguel Ángel Rodríguez Muíños
Asesoramento en Informática
Servizo de Epidemioloxía
Dirección Xeral de Innovación e Xestión da Saúde Pública
Consellería de Sanidade
Xunta de Galicia
http://dxsp.sergas.es






Nota: A información contida nesta mensaxe e os seus posibles documentos 
adxuntos é privada e confidencial e está dirixida únicamente ó seu 
destinatario/a. Se vostede non é o/a destinatario/a orixinal desta mensaxe, por 
favor elimínea. A distribución ou copia desta mensaxe non está autorizada.

Nota: La información contenida en este mensaje y sus posibles documentos 
adjuntos es privada y confidencial y está dirigida únicamente a su 
destinatario/a. Si usted no es el/la destinatario/a original de este mensaje, 
por favor elimínelo. La distribución o copia de este mensaje no está autorizada.

See more languages: http://www.sergas.es/aviso-confidencialidad
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Quantile Regression without intercept

2015-10-06 Thread Roger Koenker

> On Oct 6, 2015, at 7:58 AM, Lorenz, David  wrote:
> 
> Did you verify that the correct percentages were above/below the regression
> lines? I did a quick check and for example did not consistently get 50% of
> the observed response values greater than the tau=.5 line. I did when I
> included the nonzero intercept term.

Your "correct percentages" are only correct when you have an intercept in the 
model,
without an intercept there is no gradient condition to ensure that.
> 
> 
> 
>> Date: Mon, 5 Oct 2015 21:14:04 +0530
>> From: Preetam Pal 
>> To: stephen sefick 
>> Cc: "r-help@r-project.org" 
>> Subject: Re: [R] Quantile Regression without intercept
>> Message-ID: <56129a41.025f440a.b1cf4.f...@mx.google.com>
>> Content-Type: text/plain; charset="UTF-8"
>> 
>> Yes..it works.  Thanks ??
>> 
>> -Original Message-
>> From: "stephen sefick" 
>> Sent: ?05-?10-?2015 09:01 PM
>> To: "Preetam Pal" 
>> Cc: "r-help@r-project.org" 
>> Subject: Re: [R] Quantile Regression without intercept
>> 
>> I have never used this, but does the formula interface work like lm? Y~X-1?
>> 
>> 
>> On Mon, Oct 5, 2015 at 10:27 AM, Preetam Pal 
>> wrote:
>> 
>> Hi guys,
>> 
>> Can you instruct me please how to run quantile regression without the
>> intercept term? I only know about the rq function under quantreg package,
>> but it automatically uses an intercept model. Icant change that, it seems.
>> 
>> I have numeric data on Y variable (Gdp) and 2 X variables (Hpa and
>> Unemployment). Their sizes are 125 each.
>> 
>> Appreciate your help with this.
>> 
>> Regards,
>> Preetam
>>[[alternative HTML version deleted]]
>> 
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>> 
>> 
>> 
>> 
>> 
>> 
>> --
>> 
>> Stephen Sefick
>> **
>> Auburn University
>> Biological Sciences
>> 331 Funchess Hall
>> Auburn, Alabama
>> 36849
>> **
>> sas0...@auburn.edu
>> http://www.auburn.edu/~sas0025
>> **
>> 
>> Let's not spend our time and resources thinking about things that are so
>> little or so large that all they really do for us is puff us up and make us
>> feel like gods.  We are mammals, and have not exhausted the annoying little
>> problems of being mammals.
>> 
>>-K. Mullis
>> 
>> "A big computer, a complex algorithm and a long time does not equal
>> science."
>> 
>>  -Robert Gentleman
>>[[alternative HTML version deleted]]
>> 
>> 
>> 
>> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 Bug in R

2015-10-06 Thread Neverstop
Thank you all very much for the explanations!



--
View this message in context: 
http://r.789695.n4.nabble.com/Strange-Bug-in-R-tp4713175p4713182.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] help with problem

2015-10-06 Thread Marco Otoya Chavarria
*When i tried to read a table i**n .csv or .txt format R i get the
following message and give some problem in orden to run the data o
make test, etc*

*Warning message*

*In read.table(file = file, header = header, sep =";")
*>*  incomplete final line found by readTableHeader on 'test.csv*

*I tried Uninstall R and Excel, and install again but the problem doesnt fix.*

*Regard*

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Polygon shade

2015-10-06 Thread bgnumis bgnum
Hi All,

I want to shade the area below "f" variable and it doesn´t draw:

plot(z$Dateh[nn:length(z$Dateh)],f,type="l",col="black", xlab="Time",
ylab="Line")
grid()
polygon(c(1, 1:st, st),c(0, f, 0), col = "blue")

st is the length of f.

But if I plot

plot(f,type="l",col="black", xlab="Time", ylab="Correlation")
grid()
polygon(c(1, 1:st, st),c(0, f, 0), col = "blue")

But the axis doesn´t refect the date labels.

¿What should I do in the first code to achive it draws the blue?

¿If not? How can I ommit the axis in the scond code and to add the
z$Dateh[nn:length(z$Dateh)?

Hope someone can help me.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Getting monthly mean

2015-10-06 Thread timilsina
Hi all,

How can I get the monthly means from netcdf files using R? If there is any
examples already on web resources? Please share with me.



Regards,
Amit



--
View this message in context: 
http://r.789695.n4.nabble.com/Getting-monthly-mean-tp4713209.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] vector graphics

2015-10-06 Thread Ivan Calandra

Dear useRs,

A colleague of mine is having a problem with graphic devices. The goal 
is to save into a vector graphic format that can be edited with 
Illustrator CS4.


On my Mac (Snow Leopard), I use RSvgDevice::devSVG() and it works fine.
But on her Windows Vista computer, I cannot find an alternative.> 
sessionInfo()

R version 3.2.2 (2015-08-14)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows Vista (build 6002) Service Pack 2

I have tried:
- pdf(): I cannot dissociate the graphical elements (no problem with text)
- cairo_pdf(): the text is replaced by symbols
- cairo_ps(): fine except that the text is not text but object (it is 
then a bit troublesome, as any text modification requires the text to be 
completely rewritten)
- svg(): the graphic is completely screwed up (it seems to be a scaling 
problem, with symbols and letters all very large and superposed)
- RSvgDevice cannot be installed on the Windows machine, neither as 
binary nor from source.


Is there any other device that could work? If not, is it a matter of 
settings? So, basically, what can I do?


Thank you in advance,
Ivan

--
Ivan Calandra, PhD
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
ivan.calan...@univ-reims.fr
https://www.researchgate.net/profile/Ivan_Calandra

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


[R] apply regression to an array

2015-10-06 Thread Adrienne Wootten
R-Helpers,

I've seen some similar threads about this question online, but not quite
what I'm looking for.  I apologize in advance if someone's already answered
this and I just can't find it online.

Say that I have an array like test3 in the little example code I have below:

test1 = array(rep(1:10,each = 25),dim=c(5,5,10))
test2 = array(rnorm(250,0,0.35),dim=c(5,5,10))
test3 = test1+test2 # array with 5 rows, 5 columns, 10 slices

time=1:10

Where the dimensions are x, y, and time.  What I'd like to do is run a
regression (for the sake of this example, say lm) on each x,y in time.  So
for a single cell the formula might be test3[1,1,]~time, but I'd like to
that for all cells.  The only way I can immediately think of is to use a
loop, but I'm wondering if there's a way to do this without a loop.
Perhaps with tapply?

I'm actually doing a fourth order regression with a much larger array, but
this simple example illustrates the question I have.

Many thanks for the help! Sorry if someone's already answered this and I
can't find it.

Adrienne

-- 
Adrienne Wootten
Graduate Research Assistant
State Climate Office of North Carolina
Department of Marine, Earth and Atmospheric Sciences
North Carolina State University

[[alternative HTML version deleted]]

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