Re: [R] Reading multiple files from different folders

2015-08-12 Thread PIKAL Petr
Hi

First you shall move your folders to some other place than c:. Let say

c:\project\country\...

after that you can list folders by ?list.dirs and files by ?list.files.

you can then navigate directories by ?setwd, ?getwd and read files from them.

The exact code depends on what exactly you have and want to do and I wonder if 
anybody can give canned solution for you, especially when your files have 
various origin.

Here is a sample of code reading files from folders, calculating some values, 
plotting some graphs and writing final result.

wd<- getwd()
dirs<-list.dirs()
dirs<-dirs[-1]
n <- length(dirs)
pigm<-gsub("./([[:alnum:]])","\\1", dirs)
vysled <- data.frame(MinFeret=rep(NA, n), ECD = rep(NA, n),
aspect= rep(NA,n), pigment=rep("X", n), stringsAsFactors=F)

for (i in 1:length(dirs)) {

setwd(wd)
setwd(dirs[i])
if(file.exists("Results.xls")) {
velik<-read.delim("Results.xls")
zeros <- which(velik[,c(2,3,7)]<5, arr.ind=T)[,1]
if (length(zeros)>0) velik<-velik[-zeros,]
velik$ecd<-sqrt(4*velik$Area/pi)
velik$aspect<-velik$Feret/velik$MinFeret
velik <- velik[,-1]
maxx<-ceiling(max(velik$ecd)/100)*100

png(paste(pigm[i], "png", sep="."), 800,800)
plot(ecdf(velik$ecd), col=3, main=pigm[i], xlab="Particle size nm",
ylab="Cummulative percentage ECD", xlim=c(0,maxx))
plot(ecdf(velik$MinFeret), col=4, main=pigm[i], xlab="Particle size nm",
ylab="Cummulative percentage MinFeret", xlim=c(0,maxx), add=T)
abline(v=100, h=.5, col="pink", lwd=5)
legend(450, .2, legend=c("ECD", "MinFeret"), fill=3:4)
dev.off()

png(paste(paste(pigm[i], "ECD"), "png", sep="."), 800,800)
plot(ecdf(velik$ecd), col=3, main=pigm[i], xlab="Particle size nm",
ylab="Cummulative percentage ECD", xlim=c(0,maxx))
abline(v=100, h=.5, col="pink", lwd=5)
dev.off()

vysled[i,1:2]<- round(apply(velik[,6:7], 2, median),0)
vysled[i,3]<- round(median(velik[,8]),3)
vysled[i,4] <- pigm[i] } else {
vysled[i,4] <- pigm[i]}
setwd(wd)
write.table(vysled, "vysled.xls", sep="\t", row.names=F, na="")

}

Cheers
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Val
> Sent: Thursday, August 13, 2015 4:37 AM
> To: r-help@r-project.org
> Subject: [R] Reading multiple files from different folders
>
> Hi all,
>
> I have several files in different folders or subdirectories.  Here is
> an example of the data set.
>
> c:\country\state\city.  There might be more than 500 cities.
>
> **
> c:\country\state\city1
> c:\country\state\city2
> .
> .
> .
> c:\country\state\city500
>
> ***
> Cities may keep  the population record either in Excel file or  text
> file  format ( *.xlsx or *.txt)
>
> Each file contains :   first name, last name, address, zip code, etc
>
> I want  to create one data set  from  all the cities  for analysis of
> in interest.
>
> Output should looks  like
>
> country,  state, city, first name, last name, address, zip code,  etc.
>  USA ,NY ,  city1, Alex,John  , 102  st name ,   10004
> ,
>  USA   , NY , city1Martin  , Leno  ,   284
> street
> name  ,  10003 ,
>  .
>  .
>  USA,NY ,  city500,  Ethan , Noah  ,   543  st name ,  10015 ,
>
> Please note that variables  Country, state and city come from the  "
> c:\country\state\city"
>
> I would appreciate your  help me in reading and combing this data sets
>
> 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

Re: [R] add an idx column to the matrix

2015-08-12 Thread PIKAL Petr
Hi

the error is not caused by missing 2

> set.seed(333)
> x<-sample(0:1, 12, rep=T)
> dim(x)<-c(3,4)
> x[2,2]<-NA
> cbind(x, idx=(rowSums(x==2, na.rm=TRUE)>0)*1)
  idx
[1,] 0  1 1 0   0
[2,] 0 NA 0 0   0
[3,] 1  1 0 0   0

As Sarah pointed out, you are the only one observing such error. Without more 
information – at least  structure of your data

see ?str

but preferably part of your data causing error and a code you hardly get any 
sensible advice.

Cheers
Petr
From: Lida Zeighami [mailto:lid.z...@gmail.com]
Sent: Wednesday, August 12, 2015 6:23 PM
To: PIKAL Petr
Subject: Re: [R] add an idx column to the matrix

Dear Petr,

I use your code in a loop function, but in some matrix there isn't any 2 so I 
got the below error:

Error in rowSums(lofGT_met == 2, na.rm = T) :
  'x' must be an array of at least two dimensions

would you please let me know how to correct it?
Thanks,
Lida

On Tue, Aug 11, 2015 at 1:40 AM, PIKAL Petr 
mailto:petr.pi...@precheza.cz>> wrote:
Hi

here is another approach.

> cbind(mydata, idx=(rowSums(mydata==2, na.rm=T)>0)*1)
   X125 X255 X558 X2366 X177 X255.1 idx
aa010NA0  0   0
bb110NA0  1   0
cs212 10  0   1
de010NA0  0   0
gh200 00  0   1

It shall be faster if this is an issue.

Cheers
Petr


> -Original Message-
> From: R-help 
> [mailto:r-help-boun...@r-project.org] On 
> Behalf Of Thierry
> Onkelinx
> Sent: Monday, August 10, 2015 10:29 PM
> To: Lida Zeighami
> Cc: r-help@r-project.org
> Subject: Re: [R] add an idx column to the matrix
>
> Dear Lida,
>
> Here is a solution. Please don't post in HTML. And provide an easy to
> use
> example of the data. E.g. the output of dput(mydata)
>
> set.seed(1234)
> mydata <- matrix(
>   sample(
> c(0, 1, 2, NA),
> size = 30,
> replace = TRUE,
> prob = c(2, 1, 1, 1)
>   ),
>   ncol = 6
> )
>
> idx <- apply(mydata, 1, function(x){any(x == 2)})
> idx[is.na(idx)] <- FALSE
> cbind(mydata, idx)
>
>
>
> 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-08-10 22:11 GMT+02:00 Lida Zeighami 
> mailto:lid.z...@gmail.com>>:
>
> > Hi there,
> >
> > I have a matrix contain 0,1,2, NA elements.
> > I want to add a column to this matrix with name of "idx" . then for
> each
> > row, I should put 1 in this column (idx) if there is at least one 2
> in that
> > row otherwise I should put 0 in this column!
> >
> > for example  mydata:
> >
> >125   255   558   2366   177255
> > aa01   0 NA0 0
> > bb11   0 NA0 1
> > cs 21   2 1   0 0
> > de01   0 NA0 0
> > gh2   0   0 00 0
> >
> >
> > my output should be:
> >
> >
> >125   255   558   2366   177255idx
> > aa01   0 NA0 0  0
> > bb11   0 NA0 1  0
> > cs 21   2 1   0 0 1
> > de01   0 NA0 0  0
> > gh2   0   020 2   1
> >
> > Thank you for your help.
> >
> > [[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.



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 od

Re: [R] Doing PDF OCR with R

2015-08-12 Thread Jeff Newmiller
This code is using R like a command shell... there really is not much chance 
that R is the problem, and this is not a "tesseract" support forum, so this 
seems quite off-topic. 
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On August 12, 2015 10:05:19 PM PDT, Anshuk Pal Chaudhuri 
 wrote:
>Hi All,
>
>I have been trying to do OCR within R (reading PDF data which data as
>scanned image). Have been reading about this @
>http://electricarchaeology.ca/2014/07/15/doing-ocr-within-r/
>
>This a very good post.
>
>Effectively 3 steps:
>
>convert pdf to ppm (an image format)
>convert ppm to tif ready for tesseract (using ImageMagick for convert)
>convert tif to text file
>The effective code for the above 3 steps as per the link post:
>
>lapply(myfiles, function(i){
>  # convert pdf to ppm (an image format), just pages 1-10 of the PDF
>  # but you can change that easily, just remove or edit the
>  # -f 1 -l 10 bit in the line below
>shell(shQuote(paste0("F:/xpdf/bin64/pdftoppm.exe ", i, " -f 1 -l 10 -r
>600 ocrbook")))
>  # convert ppm to tif ready for tesseract
>shell(shQuote(paste0("F:/ImageMagick-6.9.1-Q16/convert.exe *.ppm ", i,
>".tif")))
>  # convert tif to text file
>shell(shQuote(paste0("F:/Tesseract-OCR/tesseract.exe ", i, ".tif ", i,
>" -l eng")))
>  # delete tif file
>  file.remove(paste0(i, ".tif" ))
>  })
>The first two steps are happening fine. (although taking good amount of
>time, for 4 pages of a pdf, but will look into the scalability part
>later, first trying if this works or not)
>
>While running this, the first two steps work fine.
>
>While runinng the 3rd step, i.e
>
>**shell(shQuote(paste0("F:/Tesseract-OCR/tesseract.exe ", i, ".tif ",
>i, " -l eng")))**
>I having this error:
>
>Error: evaluation nested too deeply: infinite recursion /
>options(expressions=)?
>
>Or
>
>Tesseract is crashing.
>
>Any workaround or root cause analysis would be appreciated.
>
>Regards,
>Anshuk Pal Chaudhuri
>
>
>   [[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] Doing PDF OCR with R

2015-08-12 Thread Anshuk Pal Chaudhuri
Hi All,

I have been trying to do OCR within R (reading PDF data which data as scanned 
image). Have been reading about this @ 
http://electricarchaeology.ca/2014/07/15/doing-ocr-within-r/

This a very good post.

Effectively 3 steps:

convert pdf to ppm (an image format)
convert ppm to tif ready for tesseract (using ImageMagick for convert)
convert tif to text file
The effective code for the above 3 steps as per the link post:

lapply(myfiles, function(i){
  # convert pdf to ppm (an image format), just pages 1-10 of the PDF
  # but you can change that easily, just remove or edit the
  # -f 1 -l 10 bit in the line below
  shell(shQuote(paste0("F:/xpdf/bin64/pdftoppm.exe ", i, " -f 1 -l 10 -r 600 
ocrbook")))
  # convert ppm to tif ready for tesseract
  shell(shQuote(paste0("F:/ImageMagick-6.9.1-Q16/convert.exe *.ppm ", i, 
".tif")))
  # convert tif to text file
  shell(shQuote(paste0("F:/Tesseract-OCR/tesseract.exe ", i, ".tif ", i, " -l 
eng")))
  # delete tif file
  file.remove(paste0(i, ".tif" ))
  })
The first two steps are happening fine. (although taking good amount of time, 
for 4 pages of a pdf, but will look into the scalability part later, first 
trying if this works or not)

While running this, the first two steps work fine.

While runinng the 3rd step, i.e

**shell(shQuote(paste0("F:/Tesseract-OCR/tesseract.exe ", i, ".tif ", i, " -l 
eng")))**
I having this error:

Error: evaluation nested too deeply: infinite recursion / options(expressions=)?

Or

Tesseract is crashing.

Any workaround or root cause analysis would be appreciated.

Regards,
Anshuk Pal Chaudhuri


[[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] nls in r

2015-08-12 Thread vidya
Thank you very much Prof.JC Nash

I am still don't understand about that Jacobian. why the model not
approprite. 

Really appreciate
King regards



--
View this message in context: 
http://r.789695.n4.nabble.com/nls-in-r-tp4711012p4711044.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] nls in r

2015-08-12 Thread Jeff Newmiller
This subject is introduced in multivariable calculus, and in more detail in 
some numerical analysis courses. Graphing is one common technique for 
identifying promising search ranges if the number of variables can be reduced 
to one or two. Analytical identification of asymptotes, extrema, and zeros can 
also be employed to set bounds/starting points for searching, but those topics 
are in general completely orthogonal to the topic of this mailing list... which 
is R.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On August 12, 2015 7:41:13 PM PDT, vidya  wrote:
>How can you find that starting value ? is there a trick for that ?.
>
>Really appreciate. Thank you very much. 
>
>
>King Regards
>
>
>
>
>
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/nls-in-r-tp4711012p4711043.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] nls in r

2015-08-12 Thread vidya
How can you find that starting value ? is there a trick for that ?.

Really appreciate. Thank you very much. 


King Regards








--
View this message in context: 
http://r.789695.n4.nabble.com/nls-in-r-tp4711012p4711043.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] Reading multiple files from different folders

2015-08-12 Thread Val
Hi all,

I have several files in different folders or subdirectories.  Here is an
example of the data set.

c:\country\state\city.  There might be more than 500 cities.

**
c:\country\state\city1
c:\country\state\city2
.
.
.
c:\country\state\city500

***
Cities may keep  the population record either in Excel file or  text file
 format ( *.xlsx or *.txt)

Each file contains :   first name, last name, address, zip code, etc

I want  to create one data set  from  all the cities  for analysis of in
interest.

Output should looks  like

country,  state, city, first name, last name, address, zip code,  etc.
 USA ,NY ,  city1, Alex,John  , 102  st name ,   10004 ,
 USA   , NY , city1Martin  , Leno  ,   284 street
name  ,  10003 ,
 .
 .
 USA,NY ,  city500,  Ethan , Noah  ,   543  st name ,  10015 ,

Please note that variables  Country, state and city come from the
 " c:\country\state\city"

I would appreciate your  help me in reading and combing this data sets

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.


Re: [R] nls in r

2015-08-12 Thread dave fournier


I believe that if your try these starting values the sum of squares is 
considerably smaller



a=1.0851e-06
b=1.4596e-01
delta=9.1375e-01

something like SS= 0.005236471 vs  SS= 0.01597071

__
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] Predict Function use with GLM

2015-08-12 Thread Ben Bolker
trisgutt  hotmail.com> writes:

> 
> I am currently using a GLM with Gaussian family to model fish depth~length +
> distance from shore: 
> 
> model1 <- glm(Depth ~ length + distance from shore,
> family=gaussian(link="log"))
> 
> There are no zero depths. I would like to use the above model with the
> predict function in R to generate three lines (with confidence intervals)
> for the depth at size for three distances, say 100 m, 500 m and 1000m.
> Problem is I am unable to figure out how to do this? 
> 
> Any advice / assistance would be gratefully received...
> 
> Thank you
> 
> Tris
> 

Something like:

pp <- expand.grid(distance=c(100,500,1000),
   length=seq(min_depth,max_depth,length.out=51))
## 51 is arbitrary -- you just need enough points to make the curve
## appear smooth

predvals <- predict(model1,newdata=newdata,se.fit=TRUE,type="link")
pp <- transform(pp,est=exp(predvals$fit),
lwr=exp(predvals$fit-1.96*predvals$se),
upr=exp(predvals$fit+1.96*predvals$se))

__
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] String Matching

2015-08-12 Thread Ista Zahn
Hi Kevin,

It's not totally clear to me what the desired output is.

grep(searchString, matchString, ignore.case=FALSE)

told you that searchString is in the first element of matchString.
Isn't that what you want to know? If not, perhaps you can be more
specific about what the desired result is.

Best,
Ista

On Wed, Aug 12, 2015 at 11:51 AM, Kevin Kowitski  wrote:
> Hey everyone,
>
>   I have been having an issue trying to find a specific string of text in a
> log of system messages.  I have tried to use pmatch, match, and some regular
> expressions but all to no avail.
>
> I have a matrix / data.frame (either one, the file outputs a tens of
> thousands of rows with a single column) of strings in the following format
> with different items after INFO:
>  "09:11:57.259 - Assay File Processing Thread - INFO - SolenoidCycleMessage:
> Addr = 0x03 "
>
> as an example I would like to match "SolenoidCycleMessage"
> searchString<-"SolenoidCycleMessage"
> matchString<-"09:11:57.259 - Assay File Processing Thread - INFO -
> SolenoidCycleMessage: Addr = 0x03"
>
>> pmatch(searchString, matchString)
>
> [1] NA
>
>> match(searchString, matchString)
>
> [1] NA
>>
>> match(matchString, searchString)
>
> [1] NA
>>
>> grep(searchString, matchString, ignore.case=FALSE)
>
> [1] 1
>>
>> df<-as.data.frame(c(matchString, string1, string2))
>> df
>
>  c(matchString,
> string1, string2)
> 1 09:11:57.259 - Assay File Processing Thread - INFO - SolenoidCycleMessage:
> Addr = 0x03
> 2
> 23:12:43.22 - Test
> 3
> test
>>
>> grep(searchString, df, ignore.case=FALSE)
>
> integer(0)
>
>> grep(searchString, c(matchString, string1, string2), ignore.case=FALSE)
>
> [1] 1
>
> Doe anyone have some input that could help?
>
> Thanks,
> Kevin
> __
> 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] Predict Function use with GLM

2015-08-12 Thread trisgutt
I am currently using a GLM with Gaussian family to model fish depth~length +
distance from shore: 

model1 <- glm(Depth ~ length + distance from shore,
family=gaussian(link="log"))

There are no zero depths. I would like to use the above model with the
predict function in R to generate three lines (with confidence intervals)
for the depth at size for three distances, say 100 m, 500 m and 1000m.
Problem is I am unable to figure out how to do this? 

Any advice / assistance would be gratefully received...

Thank you

Tris




--
View this message in context: 
http://r.789695.n4.nabble.com/Predict-Function-use-with-GLM-tp4711026.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] nls in r

2015-08-12 Thread ProfJCNash
With package nlmrt, I get a solution, but the Jacobian is essentially
singular, so the model may not be appropriate. You'll need to read the
documentation to learn how to interpret the Jacobian singular values. Or
Chapter 6 of my book "Nonlinear parameter optimization with R tools."

Here's the script. Note nlxb is a little different from nls() and
requires a data frame for the data.

library(stats)
x=c(30:110)
y=c(0.000760289, 0.000800320, 0.000830345, 0.000840353, 0.000860370,
0.000910414, 0.000990490, 0.001090594, 0.001200721, 0.001350912,
0.001531172, 0.001751533, 0.001961923, 0.002192402, 0.002463031,
0.002793899, 0.003185067, 0.003636604, 0.004148594, 0.004721127,
0.005394524, 0.006168989, 0.007014544, 0.007870894, 0.008758242,
0.009656474, 0.010565620, 0.011485709, 0.012396520, 0.013308162,
0.014271353, 0.015326859, 0.016525802, 0.017889059, 0.019447890,
0.021223636, 0.023145810, 0.025174229, 0.027391752, 0.029645106,
0.032337259, 0.035347424, 0.039375125, 0.043575783, 0.048003973,
0.052926206, 0.058307309, 0.064581189, 0.071947231, 0.080494476,
0.089891885, 0.100671526, 0.111971207, 0.124237571, 0.137975539,
0.153629149, 0.171239194, 0.190712664, 0.212079979, 0.235026373,
0.259457493, 0.282867017, 0.307830359, 0.334773680, 0.364001719,
0.395742526, 0.425596389, 0.458391314, 0.494558651, 0.534657357,
0.579354317, 0.616075034, 0.656680256, 0.701804548, 0.752133146,
0.808558032, 0.872226001, 0.944664487, 1.027837007, 1.124484096,
1.238426232)

vdata<- data.frame(x=x, y=y)

a=0.0189
b=0.14328
delta=0.0005

# fit = nls(y ~
a*(exp(b*(x+0.5)))*((delta*b)/((delta*b)+(a*(exp(b*(x+0.5))-1^(0.5),
# start=list(a=a,b=b, delta=delta), trace=TRUE)
# predict(fit)
# plot(x,y,col="red", xlab="Usia",ylab=expression(paste(mu)))
# lines(x,predict(fit), col="blue")
# legend("topleft",
# c(expression(paste(mu)),"Fit"),col=c("red","blue"),lty=1:1)

library(nlmrt)

 vformula <- y ~
a*(exp(b*(x+0.5)))*((delta*b)/((delta*b)+a*(exp(b*(x+0.5))-1)))^(0.5)

fitjn = nlxb(formula= vformula, start=list(a=a,b=b,delta=delta),
trace=TRUE, data=vdata)
fitjn

Best, JN


On 15-08-12 06:37 AM, vidya wrote:
> I get this error 
> Error in numericDeriv(form[[3L]], names(ind), env) : 
>   Missing value or an infinity produced when evaluating the model
> I was replace the starting value but still get error.
> 
> Here is my code:
> library(stats)
> x=c(30:110)
> y=c(0.000760289, 0.000800320, 0.000830345, 0.000840353, 0.000860370,  
> 0.000910414, 0.000990490, 0.001090594, 0.001200721, 0.001350912, 
> 0.001531172, 0.001751533, 0.001961923, 0.002192402, 0.002463031, 
> 0.002793899, 0.003185067, 0.003636604, 0.004148594, 0.004721127, 
> 0.005394524, 0.006168989, 0.007014544, 0.007870894, 0.008758242, 
> 0.009656474, 0.010565620, 0.011485709, 0.012396520, 0.013308162, 
> 0.014271353, 0.015326859, 0.016525802, 0.017889059, 0.019447890, 
> 0.021223636, 0.023145810, 0.025174229, 0.027391752, 0.029645106, 
> 0.032337259, 0.035347424, 0.039375125, 0.043575783, 0.048003973, 
> 0.052926206, 0.058307309, 0.064581189, 0.071947231, 0.080494476, 
> 0.089891885, 0.100671526, 0.111971207, 0.124237571, 0.137975539, 
> 0.153629149, 0.171239194, 0.190712664, 0.212079979, 0.235026373,
> 0.259457493, 0.282867017, 0.307830359, 0.334773680, 0.364001719, 
> 0.395742526, 0.425596389, 0.458391314, 0.494558651, 0.534657357, 
> 0.579354317, 0.616075034, 0.656680256, 0.701804548, 0.752133146, 
> 0.808558032, 0.872226001, 0.944664487, 1.027837007, 1.124484096, 
> 1.238426232)
> 
> a=0.0189
> b=0.14328
> delta=0.0005
> 
> fit = nls(y ~
> a*(exp(b*(x+0.5)))*((delta*b)/((delta*b)+(a*(exp(b*(x+0.5))-1^(0.5), 
> start=list(a=a,b=b, delta=delta))
> predict(fit)
> plot(x,y,col="red", xlab="Usia",ylab=expression(paste(mu)))
> lines(x,predict(fit), col="blue")
> legend("topleft",
> c(expression(paste(mu)),"Fit"),col=c("red","blue"),lty=1:1)
> 
> 
> I really appreciate for the helps. Thank you.
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/nls-in-r-tp4711012.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.


[R] String Matching

2015-08-12 Thread Kevin Kowitski

Hey everyone, 

  I have been having an issue trying to find a specific string of text in a log 
of system messages.  I have tried to use pmatch, match, and some regular 
expressions but all to no avail.  

I have a matrix / data.frame (either one, the file outputs a tens of thousands 
of rows with a single column) of strings in the following format with different 
items after INFO:
 "09:11:57.259 - Assay File Processing Thread - INFO - SolenoidCycleMessage: Addr = 
0x03 "

as an example I would like to match "SolenoidCycleMessage"
searchString<-"SolenoidCycleMessage"
matchString<-"09:11:57.259 - Assay File Processing Thread - INFO - 
SolenoidCycleMessage: Addr = 0x03"


pmatch(searchString, matchString)

[1] NA


match(searchString, matchString)

[1] NA

match(matchString, searchString)

[1] NA

grep(searchString, matchString, ignore.case=FALSE)

[1] 1

df<-as.data.frame(c(matchString, string1, string2))
df

                                                         c(matchString, 
string1, string2)
1 09:11:57.259 - Assay File Processing Thread - INFO - SolenoidCycleMessage: 
Addr = 0x03 
2                                                                      
23:12:43.22 - Test
3                                                                               
     test

grep(searchString, df, ignore.case=FALSE)

integer(0)


grep(searchString, c(matchString, string1, string2), ignore.case=FALSE)

[1] 1

Doe anyone have some input that could help?

Thanks, 
Kevin
__
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] add an idx column to the matrix

2015-08-12 Thread Sarah Goslee
On Wed, Aug 12, 2015 at 2:23 PM, Lida Zeighami  wrote:
> Thanks Sarah,
>
> I use your code in a loop, so each time I have different matrix, means
> lofGT_met changed each time!
> some times I have just one column in matrix so my matrix will be n*1 (the
> number of rows is the same =n)
> do you think it cause the error?

Not if it is really a two-dimensional object. That's why I suggested
you provide a *reproducible example*.

> onecol <- data.frame(aa=c(1, 2, 3, NA))
> onecol
  aa
1  1
2  2
3  3
4 NA
> apply(onecol, 1, function(x)as.numeric(any(x == 2 & !is.na(x
[1] 0 1 0 0

> onecol <- as.vector(onecol[,1])
> onecol
[1]  1  2  3 NA
> apply(onecol, 1, function(x)as.numeric(any(x == 2 & !is.na(x
Error in apply(onecol, 1, function(x) as.numeric(any(x == 2 & !is.na(x :
  dim(X) must have a positive length


>
> On Wed, Aug 12, 2015 at 1:12 PM, Sarah Goslee 
> wrote:
>>
>> On Wed, Aug 12, 2015 at 2:04 PM, Lida Zeighami  wrote:
>> > I applied this code in a loop function but since in some matrices there
>> > isn't any 2, so I got the below error:
>> >
>> > idx<- apply(lofGT_met,1, function(x)as.numeric(any(x==2 & !is.na(x
>> >
>> >
>> > Error in apply(lofGT_met, 1, function(x){(any(x == 2)}) :
>> >   dim(X) must have a positive length
>>
>> That has nothing to do with whether there are any values of 2 in the
>> data frame. The code I suggested can handle that:
>>
>>
>> no2 <- structure(list(X125 = c(0L, 1L, 1L, 0L, 1L), X255 = c(1L, 1L,
>>  1L, 1L, 0L), X558 = c(0L, 0L, 1L, 0L, 0L), X2366 = c(NA, NA,
>>  1L, NA, 0L), X177 = c(0L, 0L, 0L, 0L, 0L), X255.1 = c(0L, 1L,
>>  0L, 0L, 0L)), .Names = c("X125", "X255", "X558", "X2366", "X177",
>>  "X255.1"), class = "data.frame", row.names = c("aa", "bb", "cs",
>>  "de", "gh"))
>>
>> no2
>> apply(no2, 1, function(x)as.numeric(any(x == 2 & !is.na(x
>>
>>
>> > no2
>>X125 X255 X558 X2366 X177 X255.1
>> aa010NA0  0
>> bb110NA0  1
>> cs111 10  0
>> de010NA0  0
>> gh100 00  0
>> > apply(no2, 1, function(x)as.numeric(any(x == 2 & !is.na(x
>> aa bb cs de gh
>>  0  0  0  0  0
>>
>> It also works for rows that are entirely NA. Thus, I'm forced to
>> conclude that there's something odd about lofGT_met, and you'll need
>> to provide more information about that data frame, and a reproducible
>> example, for a solution to be offered.
>>
>> Sarah
>>
>>
>> >
>> > would you please let me know how to correct it?
>> > Thanks
>> >
>> > On Mon, Aug 10, 2015 at 3:27 PM, Sarah Goslee 
>> > wrote:
>> >>
>> >> Easy enough (note that your column names are problematic, though)
>> >>
>> >> > mydata <- structure(list(X125 = c(0L, 1L, 2L, 0L, 2L), X255 = c(1L,
>> >> > 1L,
>> >> + 1L, 1L, 0L), X558 = c(0L, 0L, 2L, 0L, 0L), X2366 = c(NA, NA,
>> >> + 1L, NA, 0L), X177 = c(0L, 0L, 0L, 0L, 0L), X255.1 = c(0L, 1L,
>> >> + 0L, 0L, 0L)), .Names = c("X125", "X255", "X558", "X2366", "X177",
>> >> + "X255.1"), class = "data.frame", row.names = c("aa", "bb", "cs",
>> >> + "de", "gh"))
>> >> > mydata$idx <- apply(mydata, 1, function(x)as.numeric(any(x == 2 &
>> >> > !is.na(x
>> >> > mydata
>> >>X125 X255 X558 X2366 X177 X255.1 idx
>> >> aa010NA0  0   0
>> >> bb110NA0  1   0
>> >> cs212 1  0  0   1
>> >> de010NA0  0   0
>> >> gh200 0  0  0   1
>> >>
>> >> Sarah
>> >>
>> >> On Mon, Aug 10, 2015 at 4:11 PM, Lida Zeighami 
>> >> wrote:
>> >>>
>> >>> Hi there,
>> >>>
>> >>> I have a matrix contain 0,1,2, NA elements.
>> >>> I want to add a column to this matrix with name of "idx" . then for
>> >>> each
>> >>> row, I should put 1 in this column (idx) if there is at least one 2 in
>> >>> that
>> >>> row otherwise I should put 0 in this column!
>> >>>
>> >>> for example  mydata:
>> >>>
>> >>>125   255   558   2366   177255
>> >>> aa01   0 NA0 0
>> >>> bb11   0 NA0 1
>> >>> cs 21   2 1   0 0
>> >>> de01   0 NA0 0
>> >>> gh2   0   0 00 0
>> >>>
>> >>>
>> >>> my output should be:
>> >>>
>> >>>
>> >>>125   255   558   2366   177255idx
>> >>> aa01   0 NA0 0  0
>> >>> bb11   0 NA0 1  0
>> >>> cs 21   2 1   0 0 1
>> >>> de01   0 NA0 0  0
>> >>> gh2   0   020 2   1
>> >>>
>
>

__
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, rep

Re: [R] add an idx column to the matrix

2015-08-12 Thread Lida Zeighami
Thanks Sarah,

I use your code in a loop, so each time I have different matrix, means
lofGT_met changed each time!
some times I have just one column in matrix so my matrix will be n*1 (the
number of rows is the same =n)
do you think it cause the error?


On Wed, Aug 12, 2015 at 1:12 PM, Sarah Goslee 
wrote:

> On Wed, Aug 12, 2015 at 2:04 PM, Lida Zeighami  wrote:
> > I applied this code in a loop function but since in some matrices there
> > isn't any 2, so I got the below error:
> >
> > idx<- apply(lofGT_met,1, function(x)as.numeric(any(x==2 & !is.na(x
> >
> >
> > Error in apply(lofGT_met, 1, function(x){(any(x == 2)}) :
> >   dim(X) must have a positive length
>
> That has nothing to do with whether there are any values of 2 in the
> data frame. The code I suggested can handle that:
>
>
> no2 <- structure(list(X125 = c(0L, 1L, 1L, 0L, 1L), X255 = c(1L, 1L,
>  1L, 1L, 0L), X558 = c(0L, 0L, 1L, 0L, 0L), X2366 = c(NA, NA,
>  1L, NA, 0L), X177 = c(0L, 0L, 0L, 0L, 0L), X255.1 = c(0L, 1L,
>  0L, 0L, 0L)), .Names = c("X125", "X255", "X558", "X2366", "X177",
>  "X255.1"), class = "data.frame", row.names = c("aa", "bb", "cs",
>  "de", "gh"))
>
> no2
> apply(no2, 1, function(x)as.numeric(any(x == 2 & !is.na(x
>
>
> > no2
>X125 X255 X558 X2366 X177 X255.1
> aa010NA0  0
> bb110NA0  1
> cs111 10  0
> de010NA0  0
> gh100 00  0
> > apply(no2, 1, function(x)as.numeric(any(x == 2 & !is.na(x
> aa bb cs de gh
>  0  0  0  0  0
>
> It also works for rows that are entirely NA. Thus, I'm forced to
> conclude that there's something odd about lofGT_met, and you'll need
> to provide more information about that data frame, and a reproducible
> example, for a solution to be offered.
>
> Sarah
>
>
> >
> > would you please let me know how to correct it?
> > Thanks
> >
> > On Mon, Aug 10, 2015 at 3:27 PM, Sarah Goslee 
> > wrote:
> >>
> >> Easy enough (note that your column names are problematic, though)
> >>
> >> > mydata <- structure(list(X125 = c(0L, 1L, 2L, 0L, 2L), X255 = c(1L,
> 1L,
> >> + 1L, 1L, 0L), X558 = c(0L, 0L, 2L, 0L, 0L), X2366 = c(NA, NA,
> >> + 1L, NA, 0L), X177 = c(0L, 0L, 0L, 0L, 0L), X255.1 = c(0L, 1L,
> >> + 0L, 0L, 0L)), .Names = c("X125", "X255", "X558", "X2366", "X177",
> >> + "X255.1"), class = "data.frame", row.names = c("aa", "bb", "cs",
> >> + "de", "gh"))
> >> > mydata$idx <- apply(mydata, 1, function(x)as.numeric(any(x == 2 &
> >> > !is.na(x
> >> > mydata
> >>X125 X255 X558 X2366 X177 X255.1 idx
> >> aa010NA0  0   0
> >> bb110NA0  1   0
> >> cs212 1  0  0   1
> >> de010NA0  0   0
> >> gh200 0  0  0   1
> >>
> >> Sarah
> >>
> >> On Mon, Aug 10, 2015 at 4:11 PM, Lida Zeighami 
> wrote:
> >>>
> >>> Hi there,
> >>>
> >>> I have a matrix contain 0,1,2, NA elements.
> >>> I want to add a column to this matrix with name of "idx" . then for
> each
> >>> row, I should put 1 in this column (idx) if there is at least one 2 in
> >>> that
> >>> row otherwise I should put 0 in this column!
> >>>
> >>> for example  mydata:
> >>>
> >>>125   255   558   2366   177255
> >>> aa01   0 NA0 0
> >>> bb11   0 NA0 1
> >>> cs 21   2 1   0 0
> >>> de01   0 NA0 0
> >>> gh2   0   0 00 0
> >>>
> >>>
> >>> my output should be:
> >>>
> >>>
> >>>125   255   558   2366   177255idx
> >>> aa01   0 NA0 0  0
> >>> bb11   0 NA0 1  0
> >>> cs 21   2 1   0 0 1
> >>> de01   0 NA0 0  0
> >>> gh2   0   020 2   1
> >>>
>

[[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] add an idx column to the matrix

2015-08-12 Thread Sarah Goslee
On Wed, Aug 12, 2015 at 2:04 PM, Lida Zeighami  wrote:
> I applied this code in a loop function but since in some matrices there
> isn't any 2, so I got the below error:
>
> idx<- apply(lofGT_met,1, function(x)as.numeric(any(x==2 & !is.na(x
>
>
> Error in apply(lofGT_met, 1, function(x){(any(x == 2)}) :
>   dim(X) must have a positive length

That has nothing to do with whether there are any values of 2 in the
data frame. The code I suggested can handle that:


no2 <- structure(list(X125 = c(0L, 1L, 1L, 0L, 1L), X255 = c(1L, 1L,
 1L, 1L, 0L), X558 = c(0L, 0L, 1L, 0L, 0L), X2366 = c(NA, NA,
 1L, NA, 0L), X177 = c(0L, 0L, 0L, 0L, 0L), X255.1 = c(0L, 1L,
 0L, 0L, 0L)), .Names = c("X125", "X255", "X558", "X2366", "X177",
 "X255.1"), class = "data.frame", row.names = c("aa", "bb", "cs",
 "de", "gh"))

no2
apply(no2, 1, function(x)as.numeric(any(x == 2 & !is.na(x


> no2
   X125 X255 X558 X2366 X177 X255.1
aa010NA0  0
bb110NA0  1
cs111 10  0
de010NA0  0
gh100 00  0
> apply(no2, 1, function(x)as.numeric(any(x == 2 & !is.na(x
aa bb cs de gh
 0  0  0  0  0

It also works for rows that are entirely NA. Thus, I'm forced to
conclude that there's something odd about lofGT_met, and you'll need
to provide more information about that data frame, and a reproducible
example, for a solution to be offered.

Sarah


>
> would you please let me know how to correct it?
> Thanks
>
> On Mon, Aug 10, 2015 at 3:27 PM, Sarah Goslee 
> wrote:
>>
>> Easy enough (note that your column names are problematic, though)
>>
>> > mydata <- structure(list(X125 = c(0L, 1L, 2L, 0L, 2L), X255 = c(1L, 1L,
>> + 1L, 1L, 0L), X558 = c(0L, 0L, 2L, 0L, 0L), X2366 = c(NA, NA,
>> + 1L, NA, 0L), X177 = c(0L, 0L, 0L, 0L, 0L), X255.1 = c(0L, 1L,
>> + 0L, 0L, 0L)), .Names = c("X125", "X255", "X558", "X2366", "X177",
>> + "X255.1"), class = "data.frame", row.names = c("aa", "bb", "cs",
>> + "de", "gh"))
>> > mydata$idx <- apply(mydata, 1, function(x)as.numeric(any(x == 2 &
>> > !is.na(x
>> > mydata
>>X125 X255 X558 X2366 X177 X255.1 idx
>> aa010NA0  0   0
>> bb110NA0  1   0
>> cs212 1  0  0   1
>> de010NA0  0   0
>> gh200 0  0  0   1
>>
>> Sarah
>>
>> On Mon, Aug 10, 2015 at 4:11 PM, Lida Zeighami  wrote:
>>>
>>> Hi there,
>>>
>>> I have a matrix contain 0,1,2, NA elements.
>>> I want to add a column to this matrix with name of "idx" . then for each
>>> row, I should put 1 in this column (idx) if there is at least one 2 in
>>> that
>>> row otherwise I should put 0 in this column!
>>>
>>> for example  mydata:
>>>
>>>125   255   558   2366   177255
>>> aa01   0 NA0 0
>>> bb11   0 NA0 1
>>> cs 21   2 1   0 0
>>> de01   0 NA0 0
>>> gh2   0   0 00 0
>>>
>>>
>>> my output should be:
>>>
>>>
>>>125   255   558   2366   177255idx
>>> aa01   0 NA0 0  0
>>> bb11   0 NA0 1  0
>>> cs 21   2 1   0 0 1
>>> de01   0 NA0 0  0
>>> gh2   0   020 2   1
>>>

__
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] add an idx column to the matrix

2015-08-12 Thread Lida Zeighami
I applied this code in a loop function but since in some matrices there
isn't any 2, so I got the below error:

idx<- apply(lofGT_met,1, function(x)as.numeric(any(x==2 & !is.na(x


Error in apply(lofGT_met, 1, function(x){(any(x == 2)}) :
  dim(X) must have a positive length

would you please let me know how to correct it?
Thanks

On Mon, Aug 10, 2015 at 3:27 PM, Sarah Goslee 
wrote:

> Easy enough (note that your column names are problematic, though)
>
> > mydata <- structure(list(X125 = c(0L, 1L, 2L, 0L, 2L), X255 = c(1L, 1L,
> + 1L, 1L, 0L), X558 = c(0L, 0L, 2L, 0L, 0L), X2366 = c(NA, NA,
> + 1L, NA, 0L), X177 = c(0L, 0L, 0L, 0L, 0L), X255.1 = c(0L, 1L,
> + 0L, 0L, 0L)), .Names = c("X125", "X255", "X558", "X2366", "X177",
> + "X255.1"), class = "data.frame", row.names = c("aa", "bb", "cs",
> + "de", "gh"))
> > mydata$idx <- apply(mydata, 1, function(x)as.numeric(any(x == 2 & !is.na
> (x
> > mydata
>X125 X255 X558 X2366 X177 X255.1 idx
> aa010NA0  0   0
> bb110NA0  1   0
> cs212 1  0  0   1
> de010NA0  0   0
> gh200 0  0  0   1
>
> Sarah
>
> On Mon, Aug 10, 2015 at 4:11 PM, Lida Zeighami  wrote:
>
>> Hi there,
>>
>> I have a matrix contain 0,1,2, NA elements.
>> I want to add a column to this matrix with name of "idx" . then for each
>> row, I should put 1 in this column (idx) if there is at least one 2 in
>> that
>> row otherwise I should put 0 in this column!
>>
>> for example  mydata:
>>
>>125   255   558   2366   177255
>> aa01   0 NA0 0
>> bb11   0 NA0 1
>> cs 21   2 1   0 0
>> de01   0 NA0 0
>> gh2   0   0 00 0
>>
>>
>> my output should be:
>>
>>
>>125   255   558   2366   177255idx
>> aa01   0 NA0 0  0
>> bb11   0 NA0 1  0
>> cs 21   2 1   0 0 1
>> de01   0 NA0 0  0
>> gh2   0   020 2   1
>>
>> Thank you for your help.
>>
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>

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

2015-08-12 Thread Michael Dewey

Dear Mario

I do not use metasens myself so cannot be of direct help but I have 
looked at your dataset and it does seem rather strange (as you perhaps 
know). You have two quite large studies with very large hazard ratios 
and if we ignore them all the rest of the studies fall on a diagonal 
bacn indicative of extreme small study bias.


One thing you could consider is to use metafor and within it use the hc 
function which uses a different approach due to Henmi and Copas (the 
same Copas).


On 12/08/2015 15:19, petre...@unina.it wrote:

Dear all,

I use R 3.1.1 for Windows (x 64).

I performed a meta-analysis of hazard ratio using the below reported
Dataset and metagen function from package meta.

meta1<-metagen(Dataset$lnHR, Dataset$seHR, sm="HR")

Thereafter, I try to use the copas function from package metasens.

cop1<-copas(meta1)


and I have these 3 warnings:

Warning in sqrt(solve(junk2$hessian + 1e-08)[1, 1]) :
NaN was produced
Warning in sqrt(solve(junk2$hessian + 1e-08)[1, 1]) :
NaN was produced
Warning in sqrt(solve(junk2$hessian + 1e-08)[1, 1]) :
NaN was produced

If I try:
plot (cop1)

  I have:
ERROR:
object "is.relative.effect" not found

Any suggestion is welcome.

The Dataset is:

id Year  lnHR   seHR
1   1 2001 0.6881346 0.06940859
2   2 2001 1.4036430 0.60414338
3   3 2002 0.7419373 0.28897730
4   4 2003 1.5475625 0.45206678
5   5 2003 1.4816046 0.44859666
6   6 2005 0.9162908 0.17166950
7   7 2006 1.2697605 0.34205049
8   8 2009 0.8960880 0.24626434
9   9 2011 1.5040774 0.24683516
10 10 2012 0.4510756 0.17213355
11 11 2008 0.9895412 0.26590857
12 12 2009 2.8094027 0.61304092
13 13 2010 0.9162908 0.21362771
14 14 2011 0.5068176 0.15060408
15 15 2012 3.0027080 0.27239493
16 16 2013 1.9837563 0.55793673
17 17 2013 3.0492730 0.18798657
18 18 2014 1.2974632 0.44759619
19 19 2014 0.8241754 0.39551640
20 20 2014 2.2617631 0.56545281

The code used are:

meta1<-metagen(Dataset$lnHR, Dataset$seHR, sm="HR")


meta1

   HR 95%-CI %W(fixed) %W(random)
1   1.99 [ 1.7369;  2.2800] 42.92   5.99
2   4.07 [ 1.2455; 13.2997]  0.57   3.71
3   2.10 [ 1.1919;  3.7000]  2.48   5.28
4   4.70 [ 1.9378; 11.3998]  1.01   4.47
5   4.40 [ 1.8264; 10.5998]  1.03   4.49
6   2.50 [ 1.7857;  3.5000]  7.02   5.75
7   3.56 [ 1.8209;  6.9599]  1.77   5.03
8   2.45 [ 1.5120;  3.9700]  3.41   5.47
9   4.50 [ 2.7740;  7.2999]  3.39   5.47
10  1.57 [ 1.1204;  2.2000]  6.98   5.75
11  2.69 [ 1.5974;  4.5300]  2.92   5.38
12 16.60 [ 4.9921; 55.1988]  0.55   3.67
13  2.50 [ 1.6447;  3.8000]  4.53   5.60
14  1.66 [ 1.2357;  2.2300]  9.12   5.81
15 20.14 [11.8085; 34.3497]  2.79   5.36
16  7.27 [ 2.4357; 21.6996]  0.66   3.94
17 21.10 [14.5971; 30.4998]  5.85   5.69
18  3.66 [ 1.5223;  8.7999]  1.03   4.49
19  2.28 [ 1.0502;  4.9499]  1.32   4.76
20  9.60 [ 3.1693; 29.0794]  0.65   3.90

Number of studies combined: k=20

  HR   95%-CI   z  p.value
Fixed effect model   2.7148 [2.4833; 2.9679] 21.9628 < 0.0001
Random effects model 3.9637 [2.7444; 5.7247]  7.3426 < 0.0001

Quantifying heterogeneity:
tau^2 = 0.5826; H = 3.56 [3.04; 4.16]; I^2 = 92.1% [89.2%; 94.2%]

Test of heterogeneity:
   Q d.f.  p.value
  240.64   19 < 0.0001

Details on meta-analytical method:
- Inverse variance method
- DerSimonian-Laird estimator for tau^2


cop1<-copas(meta1)


Warning in sqrt(solve(junk2$hessian + 1e-08)[1, 1]) :
NaN was produced


plot (cop1)


ERROR:
object "is.relative.effect" not found

---
Mario Petretta
Associate Professor of Internal Medicine
Department of Translational Medical Sciences
Naples University Federico II Italy




5x1000 AI GIOVANI RICERCATORI
DELL'UNIVERSITÀ DI NAPOLI
Codice Fiscale: 00876220633
www.unina.it/Vademecum5permille

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


--
Michael
http://www.dewey.myzen.co.uk/home.html

__
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 metasens

2015-08-12 Thread petretta

Dear all,

I use R 3.1.1 for Windows (x 64).

I performed a meta-analysis of hazard ratio using the below reported  
Dataset and metagen function from package meta.


meta1<-metagen(Dataset$lnHR, Dataset$seHR, sm="HR")

Thereafter, I try to use the copas function from package metasens.

cop1<-copas(meta1)


and I have these 3 warnings:

Warning in sqrt(solve(junk2$hessian + 1e-08)[1, 1]) :
NaN was produced
Warning in sqrt(solve(junk2$hessian + 1e-08)[1, 1]) :
NaN was produced
Warning in sqrt(solve(junk2$hessian + 1e-08)[1, 1]) :
NaN was produced

If I try:
plot (cop1)

 I have:
ERROR:
object "is.relative.effect" not found

Any suggestion is welcome.

The Dataset is:

   id Year  lnHR   seHR
1   1 2001 0.6881346 0.06940859
2   2 2001 1.4036430 0.60414338
3   3 2002 0.7419373 0.28897730
4   4 2003 1.5475625 0.45206678
5   5 2003 1.4816046 0.44859666
6   6 2005 0.9162908 0.17166950
7   7 2006 1.2697605 0.34205049
8   8 2009 0.8960880 0.24626434
9   9 2011 1.5040774 0.24683516
10 10 2012 0.4510756 0.17213355
11 11 2008 0.9895412 0.26590857
12 12 2009 2.8094027 0.61304092
13 13 2010 0.9162908 0.21362771
14 14 2011 0.5068176 0.15060408
15 15 2012 3.0027080 0.27239493
16 16 2013 1.9837563 0.55793673
17 17 2013 3.0492730 0.18798657
18 18 2014 1.2974632 0.44759619
19 19 2014 0.8241754 0.39551640
20 20 2014 2.2617631 0.56545281

The code used are:

meta1<-metagen(Dataset$lnHR, Dataset$seHR, sm="HR")


meta1

  HR 95%-CI %W(fixed) %W(random)
1   1.99 [ 1.7369;  2.2800] 42.92   5.99
2   4.07 [ 1.2455; 13.2997]  0.57   3.71
3   2.10 [ 1.1919;  3.7000]  2.48   5.28
4   4.70 [ 1.9378; 11.3998]  1.01   4.47
5   4.40 [ 1.8264; 10.5998]  1.03   4.49
6   2.50 [ 1.7857;  3.5000]  7.02   5.75
7   3.56 [ 1.8209;  6.9599]  1.77   5.03
8   2.45 [ 1.5120;  3.9700]  3.41   5.47
9   4.50 [ 2.7740;  7.2999]  3.39   5.47
10  1.57 [ 1.1204;  2.2000]  6.98   5.75
11  2.69 [ 1.5974;  4.5300]  2.92   5.38
12 16.60 [ 4.9921; 55.1988]  0.55   3.67
13  2.50 [ 1.6447;  3.8000]  4.53   5.60
14  1.66 [ 1.2357;  2.2300]  9.12   5.81
15 20.14 [11.8085; 34.3497]  2.79   5.36
16  7.27 [ 2.4357; 21.6996]  0.66   3.94
17 21.10 [14.5971; 30.4998]  5.85   5.69
18  3.66 [ 1.5223;  8.7999]  1.03   4.49
19  2.28 [ 1.0502;  4.9499]  1.32   4.76
20  9.60 [ 3.1693; 29.0794]  0.65   3.90

Number of studies combined: k=20

 HR   95%-CI   z  p.value
Fixed effect model   2.7148 [2.4833; 2.9679] 21.9628 < 0.0001
Random effects model 3.9637 [2.7444; 5.7247]  7.3426 < 0.0001

Quantifying heterogeneity:
tau^2 = 0.5826; H = 3.56 [3.04; 4.16]; I^2 = 92.1% [89.2%; 94.2%]

Test of heterogeneity:
  Q d.f.  p.value
 240.64   19 < 0.0001

Details on meta-analytical method:
- Inverse variance method
- DerSimonian-Laird estimator for tau^2


cop1<-copas(meta1)


Warning in sqrt(solve(junk2$hessian + 1e-08)[1, 1]) :
NaN was produced


plot (cop1)


ERROR:
object "is.relative.effect" not found

---
Mario Petretta
Associate Professor of Internal Medicine
Department of Translational Medical Sciences
Naples University Federico II Italy




5x1000 AI GIOVANI RICERCATORI
DELL'UNIVERSITÀ DI NAPOLI
Codice Fiscale: 00876220633
www.unina.it/Vademecum5permille

__
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] nls in r

2015-08-12 Thread vidya
I get this error 
Error in numericDeriv(form[[3L]], names(ind), env) : 
  Missing value or an infinity produced when evaluating the model
I was replace the starting value but still get error.

Here is my code:
library(stats)
x=c(30:110)
y=c(0.000760289, 0.000800320, 0.000830345, 0.000840353, 0.000860370,  
0.000910414, 0.000990490, 0.001090594, 0.001200721, 0.001350912, 
0.001531172, 0.001751533, 0.001961923, 0.002192402, 0.002463031, 
0.002793899, 0.003185067, 0.003636604, 0.004148594, 0.004721127, 
0.005394524, 0.006168989, 0.007014544, 0.007870894, 0.008758242, 
0.009656474, 0.010565620, 0.011485709, 0.012396520, 0.013308162, 
0.014271353, 0.015326859, 0.016525802, 0.017889059, 0.019447890, 
0.021223636, 0.023145810, 0.025174229, 0.027391752, 0.029645106, 
0.032337259, 0.035347424, 0.039375125, 0.043575783, 0.048003973, 
0.052926206, 0.058307309, 0.064581189, 0.071947231, 0.080494476, 
0.089891885, 0.100671526, 0.111971207, 0.124237571, 0.137975539, 
0.153629149, 0.171239194, 0.190712664, 0.212079979, 0.235026373,
0.259457493, 0.282867017, 0.307830359, 0.334773680, 0.364001719, 
0.395742526, 0.425596389, 0.458391314, 0.494558651, 0.534657357, 
0.579354317, 0.616075034, 0.656680256, 0.701804548, 0.752133146, 
0.808558032, 0.872226001, 0.944664487, 1.027837007, 1.124484096, 
1.238426232)

a=0.0189
b=0.14328
delta=0.0005

fit = nls(y ~
a*(exp(b*(x+0.5)))*((delta*b)/((delta*b)+(a*(exp(b*(x+0.5))-1^(0.5), 
start=list(a=a,b=b, delta=delta))
predict(fit)
plot(x,y,col="red", xlab="Usia",ylab=expression(paste(mu)))
lines(x,predict(fit), col="blue")
legend("topleft",
c(expression(paste(mu)),"Fit"),col=c("red","blue"),lty=1:1)


I really appreciate for the helps. Thank you.



--
View this message in context: 
http://r.789695.n4.nabble.com/nls-in-r-tp4711012.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] Getting previous day data and implementing it for quantstrat

2015-08-12 Thread boredstoog via R-help
Sorry Joshua,
I just want diverse solutions for this answer. Sorry  for causing any
trouble or inconvenience for you. I am withdrawing my question from this
forum.



--
View this message in context: 
http://r.789695.n4.nabble.com/Getting-previous-day-data-and-implementing-it-for-quantstrat-tp4710978p4711014.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] Prepare yourself for careers within Analytics - R & SAS (International Certification)

2015-08-12 Thread Imarticus Learning
IMARTICUS: Are You Ready for a Career in Analytics - R? Click here
to view in your browser
 
LEARN R / SAS & BUILD A CAREER 
IN ANALYTICS WITHIN 60 DAYSImarticus Learning, a leading analytics
learning centre, offers industry endorsed Classroom & Online programs in
technologies such as R and SAS with global certifications.   

ONLINE & CLASSROOM AVAILABLE
 
 = BENEFITS =

   - Global Certifications  - Industry Connect  - Comprehensive Coverage  -
Flexible-Learn Anytime, Anywhere  - Interactive Portal  - Self Paced  -
Curriculum includes: Predictive Analytics, Text Analytics, Data Modelling &
more.  - Experienced Industry Trainers 

 = TOP RECRUITERS =

Accenture   |   Ebay   |   Flipkart   |   MuSigma   |   Amazon   |  
Genpact   |   Infosys   |   HCL   |   IBM   |   Citi Bank Analytics   |  
and more   HOW IT WORKS?
 For More Details Call Our Training
Consultant  Mumbai   Bangalore  Chennai  022 424 22 016/17  080 451 29 914 
044 456 42 123W: www.imarticus.org | E: i...@imarticus.org












This email was sent to r-help@r-project.org (mailto:r-help@r-project.org)
unsubscribe from this list 
(http://mandrillapp.com/track/unsub.php?u=30323212&id=d6f44b007ba745d0930b5fb402764af1.EI9Berli75mp3b3oQvB6UtY8N0M%3D&r=https%3A%2F%2Fmandrillapp.com%2Funsub%3Fmd_email%3Dr-help%2540r-project.org)
[[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] add an idx column to the matrix

2015-08-12 Thread Lida Zeighami
Dear all,
Thank you so much for your helps.
They all works! But I think the Petr solution is the best!

Thanks again.
On Aug 11, 2015 1:40 AM, "PIKAL Petr"  wrote:

> Hi
>
> here is another approach.
>
> > cbind(mydata, idx=(rowSums(mydata==2, na.rm=T)>0)*1)
>X125 X255 X558 X2366 X177 X255.1 idx
> aa010NA0  0   0
> bb110NA0  1   0
> cs212 10  0   1
> de010NA0  0   0
> gh200 00  0   1
>
> It shall be faster if this is an issue.
>
> Cheers
> Petr
>
>
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Thierry
> > Onkelinx
> > Sent: Monday, August 10, 2015 10:29 PM
> > To: Lida Zeighami
> > Cc: r-help@r-project.org
> > Subject: Re: [R] add an idx column to the matrix
> >
> > Dear Lida,
> >
> > Here is a solution. Please don't post in HTML. And provide an easy to
> > use
> > example of the data. E.g. the output of dput(mydata)
> >
> > set.seed(1234)
> > mydata <- matrix(
> >   sample(
> > c(0, 1, 2, NA),
> > size = 30,
> > replace = TRUE,
> > prob = c(2, 1, 1, 1)
> >   ),
> >   ncol = 6
> > )
> >
> > idx <- apply(mydata, 1, function(x){any(x == 2)})
> > idx[is.na(idx)] <- FALSE
> > cbind(mydata, idx)
> >
> >
> >
> > 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-08-10 22:11 GMT+02:00 Lida Zeighami :
> >
> > > Hi there,
> > >
> > > I have a matrix contain 0,1,2, NA elements.
> > > I want to add a column to this matrix with name of "idx" . then for
> > each
> > > row, I should put 1 in this column (idx) if there is at least one 2
> > in that
> > > row otherwise I should put 0 in this column!
> > >
> > > for example  mydata:
> > >
> > >125   255   558   2366   177255
> > > aa01   0 NA0 0
> > > bb11   0 NA0 1
> > > cs 21   2 1   0 0
> > > de01   0 NA0 0
> > > gh2   0   0 00 0
> > >
> > >
> > > my output should be:
> > >
> > >
> > >125   255   558   2366   177255idx
> > > aa01   0 NA0 0  0
> > > bb11   0 NA0 1  0
> > > cs 21   2 1   0 0 1
> > > de01   0 NA0 0  0
> > > gh2   0   020 2   1
> > >
> > > Thank you for your help.
> > >
> > > [[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.
>
> 
> 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 

Re: [R] Unable to pass Object Arguments to UniRoot()

2015-08-12 Thread Bazman76
yeah I found the error pls feel free to delete post!



--
View this message in context: 
http://r.789695.n4.nabble.com/Unable-to-pass-Object-Arguments-to-UniRoot-tp4710938p4711015.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] Getting previous day data and implementing it for quantstrat

2015-08-12 Thread Joshua Ulrich
Please don't cross-post: http://stackoverflow.com/q/31955979/271616

At minimum, tell people that you're cross-posting, so they don't spend
time answering a question that was answered on another forum they do
not follow.

On Tue, Aug 11, 2015 at 7:27 AM, boredstoog via R-help
 wrote:
> I am a newbie and trying to create my own bactesting code after going through
> demo(). I am using a *candle engulfing pattern* strategy and this is the
> formula
>
> buy=(close(1) < close) and (high(1) < high) and (low(1) < low)
> sell=(close(1) > close) and (high(1) > high) and (low(1) > low)
> **(1) represents previous day data*
>
> How should i get previous day data for close,high and open for the previous
> day?
> How should i add indicators,rules and signals to this strategy.
>
> This is my idea first create a signal using sig Formula and then add the
> rules like this
>
> BUYING
> #adding signal
>  strat1<-add.signal(strat1,
>  name="sigFormula",
>  arguments = list(columns=c("Close","High","Low"),
>   formula = "(close(1) < close) and (high(1) < high) and
> (low(1) < low)",
>   label="trigger",
>   cross=TRUE),
>  label="Bullish engulfing")
> #adding rule
> strat1 <- add.rule(strat1, name="ruleSignal",
> arguments=list(sigcol="trigger", sigval=TRUE, orderqty=100,
> ordertype="market", orderside="long", pricemethod="market"), type="enter")
>
> is this correct!
>
> The biggest problem is how i get previous day data for close, high and low
>
>
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Getting-previous-day-data-and-implementing-it-for-quantstrat-tp4710978.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.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.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] simultaneous equation model with endogenous interaction terms

2015-08-12 Thread Arne Henningsen
Dear Janka

On 10 August 2015 at 11:25, Janka Vanschoenwinkel
 wrote:
> Dear list members,
>
> I am building a model such as:
>
> Y1 = Y2*X1 + X2
> Y2 = Y1*X1 + X2

Do you mean the model:

Y1 = b10 + b11 * (Y2*X1) + b12 * X2 + e1

Y2 = b20 + b21 * (Y1*X1) + b22 * X2 + e2

where Y1 and Y2 are two (endogenous) dependent variables, X1 is a
potentially endogenous explanatory variable, X2 is an exogenous
explanatory variable, e1 and e2 are two potentially contemporaneously
correlated error terms, and b10, b11, b12, b20, b21, and b22 are
parameters to be estimated?

> X2 is the exogenous variable
> Z1 is the instrument of Y1
> Z2 is the instrument of Y2
>
> This is a simultaneous equation model. I know how to build a simultaneous
> equation model without interaction terms:
>
> library(systemfit)
> eq1 <- Y1~Y2+X2+Z2
> eq2 <- Y2~Y1+X2+Z1
> inst <- ~X2+Z1+Z2
> system <- list(eq1=eq1, eq2=eq2)
> reg2SLS <-systemfit(system, "2SLS", inst=inst, data=mydata)
> summary(reg2SLS)
>
> I also know how to do a normal 2SLS with interaction terms:
> library(systemfit)
> ivreg(Y1~Y2*X1 | Z2*X1, data= Alldata)
>
> However, I don't know how to deal with the interaction terms in the
> simultaneous equation model.
>
> I am experimenting both with R and STATA to see which formulation gives the
> same result in both softwares, but until know without success.
>
> Could somebody help me with this?

To estimate the above model specification, the following should work:

eq1 <- Y1 ~ I(Y2*X1) + X2
eq2 <- Y2 ~ I(Y1*X1) + X2
inst <- ~ X2 + Z1 + Z2
system <- list( eq1 = eq1, eq2 = eq2 )
reg2SLS <- systemfit( system, "2SLS", inst = inst, data = mydata )

Best regards,
Arne

-- 
Arne Henningsen
http://www.arne-henningsen.name

__
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] Problem with path.expand("~")

2015-08-12 Thread Thierry Onkelinx
Dear Bill,

The culprit was the environment variable HOME which was set to "~".
Changing it to "C:/Users/thierry_onkelinx/Documents" solved the problem.
Thanks for the hint.

Best regards,

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-08-11 17:39 GMT+02:00 William Dunlap :

> In the R GUI the output is
> > path.expand("~")
> [1] "~"
>
> Did you set the environment variable R_USER to something odd like "~"?
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Tue, Aug 11, 2015 at 7:41 AM, Thierry Onkelinx <
> thierry.onkel...@inbo.be> wrote:
>
>> Dear all,
>>
>> I'm puzzled by the behaviour of path.expand("~")
>>
>> In the RStudio IDE the output is
>> > path.expand("~")
>> [1] "C:/Users/thierry_onkelinx/Documents"
>>
>> In the R GUI the output is
>> > path.expand("~")
>> [1] "~"
>>
>> But I'm expecting the same result as in the RStudio IDE. The "Start in"
>> parameter of shortcut to the R GUI has the value
>> "C:\Users\thierry_onkelinx\Documents"
>>
>> The problem is that I use normalizePath("~/analysis"). This
>> yield "C:\\Users\\thierry_onkelinx\\Documents\\analysis" in RStudio
>>
>> It throws an error in the R GUI
>> "C:\\Users\\thierry_onkelinx\\Documents\\~\\analysis"
>> Warning message:
>> In normalizePath(path.expand(path), winslash, mustWork) :
>>   path[1]="~/analysis": Het systeem kan het opgegeven pad niet vinden
>>
>> # sessionInfo() in RStudio
>> R version 3.2.1 (2015-06-18)
>> Platform: x86_64-w64-mingw32/x64 (64-bit)
>> Running under: Windows 7 x64 (build 7601) Service Pack 1
>>
>> locale:
>> [1] LC_COLLATE=Dutch_Belgium.1252  LC_CTYPE=Dutch_Belgium.1252
>>  LC_MONETARY=Dutch_Belgium.1252
>> [4] LC_NUMERIC=C   LC_TIME=Dutch_Belgium.1252
>>
>> attached base packages:
>> [1] stats graphics  grDevices utils datasets  methods   base
>>
>> loaded via a namespace (and not attached):
>> [1] tools_3.2.1fortunes_1.5-2
>>
>> # sessionInfo() from R GUI
>> R version 3.2.1 (2015-06-18)
>> Platform: x86_64-w64-mingw32/x64 (64-bit)
>> Running under: Windows 7 x64 (build 7601) Service Pack 1
>>
>> locale:
>> [1] LC_COLLATE=Dutch_Belgium.1252  LC_CTYPE=Dutch_Belgium.1252
>> [3] LC_MONETARY=Dutch_Belgium.1252 LC_NUMERIC=C
>> [5] LC_TIME=Dutch_Belgium.1252
>>
>> attached base packages:
>> [1] stats graphics  grDevices utils datasets  methods   base
>>
>> loaded via a namespace (and not attached):
>> [1] tools_3.2.1fortunes_1.5-2
>>
>>
>> Best regards,
>>
>> 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
>>
>> [[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.


[R] clusterMap: static vs dynamic scheduling

2015-08-12 Thread Rguy
The clusterMap function provides the following argument
.scheduling = c("static", "dynamic")
The default is "static". When is it advisable to use "dynamic"?

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