Re: [R] meta-question about R

2014-04-24 Thread mark

On 04/23/14 23:22, William Dunlap wrote:

Aren't those files support for named semaphores (made with sem_open())?
Packages like BH and RSQLite contain calls to sem_open.   Is your long-running
R process using such a package?

I don't think you would want to delete those files, but perhaps you can look 
into
whatever R package creates them and see if you can modify the code to give
them better names and then add those names to rkhunter's whitelist.


You don't seem to understand what I'm asking. I have zero intention of 
deleting those files. I'm sure that my user's long-running job is creating 
them. What I'm asking is if ANYONE HERE knows if there is some configuration 
file, or command inside R, that would tell R, whatever package it's using (I 
assume that all packages inherit from the top-level process), when it creates 
files in /dev/shm, to name them something that I can use with wildcards in 
rkhunter's configuration file so that rkhunter ignores them.


mark




-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf
Of Jim Lemon
Sent: Wednesday, April 23, 2014 2:18 PM
To: m.r...@5-cent.us
Cc: r-help@r-project.org
Subject: Re: [R] meta-question about R

On 04/23/2014 11:58 PM, m.r...@5-cent.us wrote:

This really isn't about R, but configuring R. We're running R 3.0.2-1, the
current default package, on CentOS 6.5 On a long-running job, R is
creating files in /dev/shm: each set of three files are named (8 hex
digits)-(4 hex digits)-(4 hex digits)-(4 hex digits)-(12 hex digits), and
then sem.(same as the name)_counter_mutex, and (same as the name)_counter.

For example,
156d23b0-9e67-46e2-afab-14a648252890
156d23b0-9e67-46e2-afab-14a648252890_counter
sem.156d23b0-9e67-46e2-afab-14a648252890_counter_mutex

Is there some way to configure R to add a prefix, say, to each of these
files? We're running rkhunter (rootkit hunter) for security, and it
complains about suspicious files, and I'd like some way to be able to tell
it to, say, ignore R_temp.whatever


Hi mark,
I assume that the problem is to identify the files in /dev/shm, not to
simply change your R code to tack the prefix onto the files as it
produces them. As your hexadecimal digits are probably randomly
generated, the solution may be to identify all the files that have
"_counter_mutex" in the name, then chip off the appropriate bits to get
the troublesome first name.

filenames<-list.files(pattern="_counter_mutex")
# function to return the two other filenames
strip_fn<-function(x) {
   f2<-substr(x,5,nchar(x)-6)
   f1<-substr(f2,1,nchar(f2)-8)
   return(c(f1,f2))
}
# get all the filenames
filenames<-c(filenames,unlist(sapply(filenames,strip_fn)))
# stick on the prefix
newfilenames<-paste("R_temp",filenames,sep=".")
# create the commands
fnmove<-paste("mv",filenames,newfilenames)
# move the filenames
for(fn in 1:length(fnmove)) system(fnmove[fn])

Warning - I haven't tested the last bit of this, but it should work.
There is probably some really neat string of heiroglyphs in a regular
expression that will do this as well.

Jim

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




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


[R] Creating a flat legend 'grob' for lattice xyplot

2011-07-27 Thread Mark
Hi,

I want my xyplot legend to be flat, not tall, and there seems to be no way
for xyplot's auto.key and key elements to do this: I tried many, many
permutations of what I could find in the archives and reading the
documentation.  If there there's a way to make it flat, please tell me what
the magic incantation is.

Here's a simple example of what I like to see.  The xyplot will be a
multi-panelled one with a single,
flat legend below.  It seems the xyplot's legend element is the way to go --
the option I haven't tried because I don't know what or how to create a grob
of this kind.  Where to start?

xyplot(1~1)
legend(0.15,-0.125,
bty='n',pch=rep(c(15,17),2),col=c('brown','green','blue','red'),ncol=4,
  legend=c('How','to make','this into', 'a grob?'))

Thanks!



--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-a-flat-legend-grob-for-lattice-xyplot-tp3699235p3699235.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Creating a flat legend 'grob' for lattice xyplot

2011-07-27 Thread Mark
Hi Marcus,

That's almost it!  So ncol and column do the same thing in different
functions... gah!

Because my real use of xyplot I override the default plotting colors and
character, autokey doesn't 'know' this, so they don't match.

So the addition of the par.settings element is needed (from another e-mail):

xyplot(1~1,
auto.key=list(
bty='n',
columns=4,  
text=c('How','to make','this into', 'a grob?'),
space="top")
par.settings=simpleTheme(pch=rep(c(15,17),2),col=c('brown','green','blue','red')
)

My legend is flat and color coordinated now.

Thank you very much!


--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-a-flat-legend-grob-for-lattice-xyplot-tp3699235p3699351.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Help with R

2011-07-28 Thread mark

   1.  How can I plot the entire tree produced by rpart?

   2.  How can I submit a vector of values to a tree produced by rpart and have
   it make an assignment?

   Mark

   
   

References

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


[R] help with rpart

2011-07-28 Thread mark
1. How can I plot the entire tree produced by rpart?

2. How can I submit a vector of values to a tree produced by rpart and
have
it make an assignment?

Mark


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


[R] help with plot.rpart

2011-07-29 Thread mark

   Ã  data=read.table("http://statcourse.com/research/boston.csv";, , sep=",",
   header = TRUE)

   Ã  library(rpart)

   Ã  fit=rpart (MV~ CRIM+ZN+INDUS+CHAS+NOX+RM+AGE+DIS+RAD+TAX+ PT+B+LSTAT)

   Please: Show me the tree.

   Mark

    Original Message 
   Subject: Re: [R] help with rpart
   From: "Stephen Milborrow" <[1]mi...@sonic.net>
   Date: Fri, July 29, 2011 7:54 am
   To: <[2]m...@statcourse.com>
   Cc: <[3]sarah.gos...@gmail.com>
   Mark, check out my rpart.plot package. See also the PDF vignette that comes
   with the package.
   Steve
   [4]www.milbo.users.sonic.net
   --
   Message: 69
   Date: Thu, 28 Jul 2011 16:10:35 -0400
   From: Sarah Goslee <[5]sarah.gos...@gmail.com>
   To: [6]m...@statcourse.com
   Cc: [7]r-help@r-project.org
   Subject: Re: [R] help with rpart
   Message-ID:
   <[8]CAM_vjukbUphEmRDs231LpiZwS7xdKMMK3_7s5mz=ydttvht...@mail.gmail.com>
   Content-Type: text/plain; charset=ISO-8859-1
   Why repost after receiving a reply? Reposting is unnecessary. If the
   first reply was unsatisfactory, why? More detail in your question
   leads to a more useful and informative reply.
   Just in case you didn't get it:
   On Thu, Jul 28, 2011 at 11:52 AM, <[9]m...@statcourse.com> wrote:
   > 1. How can I plot the entire tree produced by rpart?
   What is plot() not doing that you need?
   > 2. How can I submit a vector of values to a tree produced by rpart and
   > have
   > it make an assignment?
   What is predict() not doing that you need?
   --
   Sarah Goslee
   [10]http://www.functionaldiversity.org

References

   1. mailto:mi...@sonic.net
   2. mailto:m...@statcourse.com
   3. mailto:sarah.gos...@gmail.com
   4. http://www.milbo.users.sonic.net/
   5. mailto:sarah.gos...@gmail.com
   6. mailto:m...@statcourse.com
   7. mailto:r-help@r-project.org
   8. mailto:CAM_vjukbUphEmRDs231LpiZwS7xdKMMK3_7s5mz=ydttvht...@mail.gmail.com
   9. mailto:m...@statcourse.com
  10. http://www.functionaldiversity.org/
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with predict.rpart

2011-07-29 Thread mark
   data=read.table("http://statcourse.com/research/boston.csv";, ,
sep=",", header = TRUE)
   library(rpart)
   fit=rpart (MV~ CRIM+ZN+INDUS+CHAS+NOX+RM+AGE+DIS+RAD+TAX+
PT+B+LSTAT) 
predict(fit,data[4,])

plot only reveals part of the tree in contrast to the results on obtains
with CART or C5

 Original Message 
Subject: Re: [R] help with rpart
From: Sarah Goslee 
Date: Fri, July 29, 2011 7:48 am
To: m...@statcourse.com
Cc: r-help@r-project.org

Mark,

The R-help list is not telepathic. I asked entirely reasonable follow-up
questions intended to elicit from you a more extensive explanation of
your problem.

On Fri, Jul 29, 2011 at 10:26 AM,  wrote:
> 1. I did not receive your reply, which, not incidentally, does not address
> either of my questions.

Nor did you address mine, except to repeat them with more exclamation
marks.

> 2. I wish to plot.rpart the entire tree!  How can I do this?


What do you want to see that plot() does not show?
library(rpart)
fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis)
par(mfrow=c(1,2), xpd=NA) # otherwise on some devices the text is
clipped
plot(fit)
text(fit, use.n=TRUE)

You want the "whole tree" - what is missing? That's the entire tree as
shown by print(fit).


> 3. I wish to predict.rpart the appropriate assignment for a single vector of
> observations using the tree produced by rpart. How can I do this?

newdata <- data.frame(Age=c(18, 22), Number=c(3,4), Start=c(15, 15))
predict(fit, newdata = newdata, type="class")

This seems to me to provide the predicted class information for new
data.
What do you want that predict() is not providing?

> Can anyone be of practical assistance?

Of course. But we need to know *what you want*.
A minimal reproducible example is handy, and I've now provided one
for you because I'm feeling generous.

> Mark
>
>  Original Message 
> Subject: Re: [R] help with rpart
> From: Sarah Goslee 
> Date: Thu, July 28, 2011 1:10 pm
> To: m...@statcourse.com
> Cc: r-help@r-project.org
>
> Why repost after receiving a reply? Reposting is unnecessary. If the
> first reply was unsatisfactory, why? More detail in your question
> leads to a more useful and informative reply.
>
> Just in case you didn't get it:
>
> On Thu, Jul 28, 2011 at 11:52 AM,  wrote:
>> 1. How can I plot the entire tree produced by rpart?
>
> What is plot() not doing that you need?
>
>> 2. How can I submit a vector of values to a tree produced by rpart and
>> have
>> it make an assignment?
>
> What is predict() not doing that you need?
>

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


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


Re: [R] help with plot.rpart

2011-07-29 Thread mark

   Your plot only shows part of the tree provided by print(fit).

   I would like to plot the entire tree.

    Original Message 
   Subject: Re: [R] help with plot.rpart
   From: Joshua Wiley <[1]jwiley.ps...@gmail.com>
   Date: Fri, July 29, 2011 8:25 am
   To: [2]m...@statcourse.com
   Cc: [3]r-help@r-project.org
   Mark,
   The below is not directly reproducible. There is no "MV" or "PT"
   variable in the dataset you reference. I am assuming you meant:
   dat <- read.table("http://statcourse.com/research/boston.csv";, ,
   sep=",", header = TRUE)
   fit ><- rpart(MEDV ~ CRIM + ZN + INDUS + CHAS + NOX + RM + AGE + DIS +
   RAD + TAX + PTRATIO + B + LSTAT, data = dat)
   plot(fit)
   which creates the plot I attached.
   Cheers,
   Josh
   On Fri, Jul 29, 2011 at 8:11 AM, ><[4]m...@statcourse.com> wrote:
   >
   >Ã  data=read.table("http://statcourse.com/research/boston.csv";, ,
   sep=",",
   >   header = TRUE)
   >
   >   Ã  library(rpart)
   >
   >   Ã  fit=rpart (MV~ CRIM+ZN+INDUS+CHAS+NOX+RM+AGE+DIS+RAD+TAX+ PT+B+LSTAT)
   >
   >   Please: Show me the tree.
   >
   >   Mark
   >
   >    Original Message 
   >   Subject: Re: [R] help with rpart
   >   From: "Stephen Milborrow" <[1][5]mi...@sonic.net>
   >   Date: Fri, July 29, 2011 7:54 am
   >   To: <[2][6]m...@statcourse.com>
   >   Cc: <[3][7]sarah.gos...@gmail.com>
   >   Mark, check out my rpart.plot package. See also the PDF vignette that
   comes
   >   with the package.
   >   Steve
   >   [4][8]www.milbo.users.sonic.net
   >   --
   >   Message: 69
   >   Date: Thu, 28 Jul 2011 16:10:35 -0400
   >   From: Sarah Goslee <[5][9]sarah.gos...@gmail.com>
   >   To: [6][10]m...@statcourse.com
   >   Cc: [7][11]r-help@r-project.org
   >   Subject: Re: [R] help with rpart
   >   Message-ID:
   >
   <[8][12]CAM_vjukbUphEmRDs231LpiZwS7xdKMMK3_7s5mz=ydttvht...@mail.gmail.com>
   >   Content-Type: text/plain; charset=ISO-8859-1
   >   Why repost after receiving a reply? Reposting is unnecessary. If the
   >   first reply was unsatisfactory, why? More detail in your question
   >   leads to a more useful and informative reply.
   >   Just in case you didn't get it:
   >   On Thu, Jul 28, 2011 at 11:52 AM, <[9][13]m...@statcourse.com> wrote:
   >   > 1. How can I plot the entire tree produced by rpart?
   >   What is plot() not doing that you need?
   >   > 2. How can I submit a vector of values to a tree produced by rpart and
   >   > have
   >   > it make an assignment?
   >   What is predict() not doing that you need?
   >   --
   >   Sarah Goslee
   >   [10][14]http://www.functionaldiversity.org
   >
   > References
   >
   >   1. [15]mailto:mi...@sonic.net
   >   2. [16]mailto:m...@statcourse.com
   >   3. [17]mailto:sarah.gos...@gmail.com
   >   4. [18]http://www.milbo.users.sonic.net/
   >   5. [19]mailto:sarah.gos...@gmail.com
   >   6. [20]mailto:m...@statcourse.com
   >   7. [21]mailto:r-help@r-project.org
   >   8.
   [22]mailto:CAM_vjukbUphEmRDs231LpiZwS7xdKMMK3_7s5mz=ydttvht...@mail.gmail.co
   m
   >   9. [23]mailto:m...@statcourse.com
   >  10. [24]http://www.functionaldiversity.org/
   > __
   > [25]R-help@r-project.org mailing list
   > [26]https://stat.ethz.ch/mailman/listinfo/r-help
   > PLEASE do read the posting guide
   [27]http://www.R-project.org/posting-guide.html
   > and provide commented, minimal, self-contained, reproducible code.
   >
   --
   Joshua Wiley
   Ph.D. Student, Health Psychology
   University of California, Los Angeles
   [28]https://joshuawiley.com/

References

   1. http://jwiley.ps...@gmail.com/
   2. mailto:m...@statcourse.com
   3. mailto:r-help@r-project.org
   4. mailto:m...@statcourse.com
   5. mailto:mi...@sonic.net
   6. mailto:m...@statcourse.com
   7. mailto:sarah.gos...@gmail.com
   8. http://www.milbo.users.sonic.net/
   9. mailto:sarah.gos...@gmail.com
  10. mailto:m...@statcourse.com
  11. mailto:r-help@r-project.org
  12. mailto:CAM_vjukbUphEmRDs231LpiZwS7xdKMMK3_7s5mz=ydttvht...@mail.gmail.com
  13. mailto:m...@statcourse.com
  14. http://www.functionaldiversity.org/
  15. mailto:mi...@sonic.net
  16. mailto:m...@statcourse.com
  17. mailto:sarah.gos...@gmail.com
  18. http://www.milbo.users.sonic.net/
  19. mailto:sarah.gos...@gmail.com
  20. mailto:m...@statcourse.com
  21. mailto:r-help@r-project.org
  22. mailto:CAM_vjukbUphEmRDs231LpiZwS7xdKMMK3_7s5mz=ydttvht...@mail.gmail.com
  23. mailto:m...@statcourse.com
  24. http://www.functionaldiversity.org/
  25. mailto:R-help@r-project.org
  26. https://stat.ethz

[R] rpart, resolution

2011-07-29 Thread mark
Thank you for all your help.  The unexpected solution to my predict()
problem was to use the Misc menu and remove all objects before
proceeding further.  The final digits of the trees continue to be
clipped but I can live with that.

Mark


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


[R] PCA in r

2011-12-22 Thread Mark
Hello
Would anyone be able to direct me to information on how to perform a 
straightforward Principal Components Analysis in r?  Including the data file 
set-up?  

I'm rather new to r and not having much luck.
I'm pretty certain I have the data entered into the txt file properly but when 
I try to follow some of the examples online I receive a number of errors in r 
that I don't understand.
Any help would be greatly appreciated.
thanks
Mark

[[alternative HTML version deleted]]

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


[R] glm(quasipoisson) with non-integer response

2008-04-17 Thread Mark
Hi,

I have count data that have been meddled with enough to make them non 
integers. Using glm(poisson) returns a "non integer" error but 
glm(quasipoisson) does not. Just wondering if anyone knows if I am 
violating the assumptions of a quasipoisson error structure by using 
these non-integer response data?

Thanks! I'd welcome your thoughts and/or references...

Mark

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


[R] Please help me to produce smoothed contour plots

2008-10-01 Thread Mark
Please help me to produce smoothed contour plots.

I have dependent data generated at regular intervals of two independent
variables and would like to produce smoothed contour plots - I cannot get
interp (alima) to produce cubic interpolations of the data, only linear
ones. I'm interested in smoothing as the data generation process is
stochastic and produces small variations which I'd rather 'smooth' away. I
cannot spot what is different about my data from the examples in (akima)
which prevents this working.

here is an example of my data:
> x
   0  50 100 150 200 250 300 350 400 450 500   0  50 100 150 200 250 300 350
400
 [21] 450 500   0  50 100 150 200 250 300 350 400 450 500   0  50 100 150
200 250 300
 [41] 350 400 450 500   0  50 100 150 200 250 300 350 400 450 500   0  50
100 150 200
 [61] 250 300 350 400 450 500   0  50 100 150 200 250 300 350 400 450 500
0  50 100
 [81] 150 200 250 300 350 400 450 500   0  50 100 150 200 250 300 350 400
450 500   0
[101]  50 100 150 200 250 300 350 400 450 500   0  50 100 150 200 250 300
350 400 450
[121] 500
> y
  [1] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.05 0.05 0.05
0.05 0.05
 [17] 0.05 0.05 0.05 0.05 0.05 0.05 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10
0.10 0.10
 [33] 0.10 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.20 0.20
0.20 0.20
 [49] 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.25 0.25 0.25 0.25 0.25 0.25 0.25
0.25 0.25
 [65] 0.25 0.25 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.35
0.35 0.35
 [81] 0.35 0.35 0.35 0.35 0.35 0.35 0.35 0.35 0.40 0.40 0.40 0.40 0.40 0.40
0.40 0.40
 [97] 0.40 0.40 0.40 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45
0.50 0.50
[113] 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50
> zz
  [1] 105136  98444  95021  79375  72532  64392  57819  44413  40610  26083
18077
 [12]  96188  87863  80205  69503  61000  50387  44306  33432  22958  17575
10892
 [23]  88402  75263  65109  63717  50998  39837  28576  25960  17531
8510   5733
 [34]  70806  59245  53970  46113  38455  30492  23836  17870  10954
5218   2266
 [45]  68272  58610  47854  34834  32363  24238  19236  11789   6206
2515   2141
 [56]  58448  47706  43001  39592  22840  18264  11564   6292   2915
2228   2090
 [67]  55817  47680  38460  31693  21331  13161   8050   3162   2302
2120   1990
 [78]  54078  43720  32828  22618  17039   8524   4846   2392   2154
2068   2008
 [89]  47459  39734  29525  21325  10602   6406   3525   2207   2062
2014   1952
[100]  47630  34965  28452  18966   8386   5726   2351   2145   2052
1999   1960
[111]  42173  34339  27449  16743   9643   2866   2208   2096   2018
1937   1886

[[alternative HTML version deleted]]

[[alternative HTML version deleted]]

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


[R] cubic bivariate interpolation on regular grid

2008-10-01 Thread Mark
Please help me to produce smoothed contour plots.

I have dependent data generated at regular intervals of two independent
variables and would like to produce smoothed contour plots - I cannot get
interp (alima) to produce cubic interpolations of the data, only linear
ones. I'm interested in smoothing as the data generation process is
stochastic and produces small variations which I'd rather 'smooth' away. I
cannot spot what is different about my data from the examples in (akima)
which prevents this working.

here is an example of my data:
> x
   0  50 100 150 200 250 300 350 400 450 500   0  50 100 150 200 250 300 350
400
 [21] 450 500   0  50 100 150 200 250 300 350 400 450 500   0  50 100 150
200 250 300
 [41] 350 400 450 500   0  50 100 150 200 250 300 350 400 450 500   0  50
100 150 200
 [61] 250 300 350 400 450 500   0  50 100 150 200 250 300 350 400 450 500
0  50 100
 [81] 150 200 250 300 350 400 450 500   0  50 100 150 200 250 300 350 400
450 500   0
[101]  50 100 150 200 250 300 350 400 450 500   0  50 100 150 200 250 300
350 400 450
[121] 500
> y
  [1] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.05 0.05 0.05
0.05 0.05
 [17] 0.05 0.05 0.05 0.05 0.05 0.05 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10
0.10 0.10
 [33] 0.10 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.20 0.20
0.20 0.20
 [49] 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.25 0.25 0.25 0.25 0.25 0.25 0.25
0.25 0.25
 [65] 0.25 0.25 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.35
0.35 0.35
 [81] 0.35 0.35 0.35 0.35 0.35 0.35 0.35 0.35 0.40 0.40 0.40 0.40 0.40 0.40
0.40 0.40
 [97] 0.40 0.40 0.40 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45
0.50 0.50
[113] 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50
> zz
  [1] 105136  98444  95021  79375  72532  64392  57819  44413  40610  26083
18077
 [12]  96188  87863  80205  69503  61000  50387  44306  33432  22958  17575
10892
 [23]  88402  75263  65109  63717  50998  39837  28576  25960  17531
8510   5733
 [34]  70806  59245  53970  46113  38455  30492  23836  17870  10954
5218   2266
 [45]  68272  58610  47854  34834  32363  24238  19236  11789   6206
2515   2141
 [56]  58448  47706  43001  39592  22840  18264  11564   6292   2915
2228   2090
 [67]  55817  47680  38460  31693  21331  13161   8050   3162   2302
2120   1990
 [78]  54078  43720  32828  22618  17039   8524   4846   2392   2154
2068   2008
 [89]  47459  39734  29525  21325  10602   6406   3525   2207   2062
2014   1952
[100]  47630  34965  28452  18966   8386   5726   2351   2145   2052
1999   1960
[111]  42173  34339  27449  16743   9643   2866   2208   2096   2018
1937   1886

[[alternative HTML version deleted]]

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


[R] add labelled contour lines to filled.contour plot

2008-10-01 Thread Mark
Is it possible to add labelled contour lines to filled.contour plot ?

[[alternative HTML version deleted]]

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


Re: [R] Learning advanced R

2018-03-13 Thread Mark Leeds
See Hadley's advanced R along Thomas Mailund's books. I haven't gone
through them carefully but they both
seem  (from what I've looked at ) to be the best ones for that. Mentions of
others are appreciated.




On Tue, Mar 13, 2018 at 5:26 PM, Nik Tuzov  wrote:

>
> Hello:
>
> Could you please suggest the best way to become an "advanced" R programmer.
> I went through "R for dummies" by de Vries and Meys and I can see two ways
> to proceed:
>
> 1) Get a more advanced textbook. E.g. could you recommend Gentleman,
> "R for Bioinformatics"?
>
> 2) Because textbooks are limited and become obsolete fast, I can focus on
> learning state-of-the-art packages,
> but for that I need to find a list of most useful general purpose packages
> (foreach, doParallel, etc) that is
> updated in real time. Does such list exist?
>
> Your recommendations are very welcome.
>
> Thanks,
> Nik
>
> __
> 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] Hacked

2018-04-17 Thread Fowler, Mark
Just an observation. I have not seen the spam you are discussing. Possibly it 
is specific to gmail addresses?

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luis Puerto
Sent: April 17, 2018 4:11 PM
To: Peter Langfelder
Cc: R-Help ML R-Project; Neotropical bat risk assessments
Subject: Re: [R] Hacked

Hi! 

This happened to me also! I just got a spam email just after posting and then 
in following days I got obnoxious spam emails in my spam filter. As the others, 
I think that there is some kind of bot subscribed to the list, but also perhaps 
a spider or crawler monitoring the R-Help archive and getting email addresses 
there. Nabble is a possibility too. 

> On 17 Apr 2018, at 21:50, Peter Langfelder  wrote:
> 
> I got some spam emails after my last post to the list, and the emails 
> did not seem to go through r-help. The spammers may be subscribed to 
> the r-help, or they get the poster emails from some of the web copies 
> of this list (nabble or similar).
> 
> Peter
> 
> On Tue, Apr 17, 2018 at 11:37 AM, Ulrik Stervbo  
> wrote:
>> I asked the moderators about it. This is the reply
>> 
>> "Other moderators have looked into this a bit and may be able to shed 
>> more light on it. This is a "new" tactic where the spammers appear to 
>> reply to the r-help post. They are not, however, going through the r-help 
>> server.
>> 
>> It also seems that this does not happen to everyone.
>> 
>> I am not sure how you can automatically block the spammers.
>> 
>> Sorry I cannot be of more help."
>> 
>> --Ulrik
>> 
>> Jeff Newmiller  schrieb am Di., 17. Apr. 
>> 2018,
>> 14:59:
>> 
>>> Likely a spammer has joined the mailing list and is auto-replying to 
>>> posts made to the list. Unlikely that the list itself has been 
>>> "hacked". Agree that it is obnoxious.
>>> 
>>> On April 17, 2018 5:01:10 AM PDT, Neotropical bat risk assessments < 
>>> neotropical.b...@gmail.com> wrote:
 Hi all,
 
 Site has been hacked?
 Bad SPAM arriving
 
 __
 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.
>>> 
>>> --
>>> Sent from my phone. Please excuse my brevity.
>>> 
>>> __
>>> 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-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-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] Hacked

2018-04-17 Thread Mark Leeds
Hi All: I lately get a lot more spam-porn type emails lately also but I
don't know if they are due to me being on
the R-list.



On Tue, Apr 17, 2018 at 5:09 PM, Rui Barradas  wrote:

> Hello,
>
> Nor do I, no gmail, also got spam.
>
> Rui Barradas
>
> On 4/17/2018 8:34 PM, Ding, Yuan Chun wrote:
>
>> No, I do not use gmail, still got dirty spam email twice.
>>
>> -Original Message-
>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Fowler,
>> Mark
>> Sent: Tuesday, April 17, 2018 12:32 PM
>> To: Luis Puerto; Peter Langfelder
>> Cc: R-Help ML R-Project; Neotropical bat risk assessments
>> Subject: Re: [R] Hacked
>>
>> [Attention: This email came from an external source. Do not open
>> attachments or click on links from unknown senders or unexpected emails.]
>>
>>
>>
>>
>>
>> Just an observation. I have not seen the spam you are discussing.
>> Possibly it is specific to gmail addresses?
>>
>> -Original Message-
>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luis
>> Puerto
>> Sent: April 17, 2018 4:11 PM
>> To: Peter Langfelder
>> Cc: R-Help ML R-Project; Neotropical bat risk assessments
>> Subject: Re: [R] Hacked
>>
>> Hi!
>>
>> This happened to me also! I just got a spam email just after posting and
>> then in following days I got obnoxious spam emails in my spam filter. As
>> the others, I think that there is some kind of bot subscribed to the list,
>> but also perhaps a spider or crawler monitoring the R-Help archive and
>> getting email addresses there. Nabble is a possibility too.
>>
>> On 17 Apr 2018, at 21:50, Peter Langfelder 
>>> wrote:
>>>
>>> I got some spam emails after my last post to the list, and the emails
>>> did not seem to go through r-help. The spammers may be subscribed to
>>> the r-help, or they get the poster emails from some of the web copies
>>> of this list (nabble or similar).
>>>
>>> Peter
>>>
>>> On Tue, Apr 17, 2018 at 11:37 AM, Ulrik Stervbo 
>>> wrote:
>>>
>>>> I asked the moderators about it. This is the reply
>>>>
>>>> "Other moderators have looked into this a bit and may be able to shed
>>>> more light on it. This is a "new" tactic where the spammers appear to
>>>> reply to the r-help post. They are not, however, going through the
>>>> r-help server.
>>>>
>>>> It also seems that this does not happen to everyone.
>>>>
>>>> I am not sure how you can automatically block the spammers.
>>>>
>>>> Sorry I cannot be of more help."
>>>>
>>>> --Ulrik
>>>>
>>>> Jeff Newmiller  schrieb am Di., 17. Apr.
>>>> 2018,
>>>> 14:59:
>>>>
>>>> Likely a spammer has joined the mailing list and is auto-replying to
>>>>> posts made to the list. Unlikely that the list itself has been
>>>>> "hacked". Agree that it is obnoxious.
>>>>>
>>>>> On April 17, 2018 5:01:10 AM PDT, Neotropical bat risk assessments <
>>>>> neotropical.b...@gmail.com> wrote:
>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>> Site has been hacked?
>>>>>> Bad SPAM arriving
>>>>>>
>>>>>> __
>>>>>> 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.
>>>>>>
>>>>>
>>>>> --
>>>>> Sent from my phone. Please excuse my brevity.
>>>>>
>>>>> __
>>>>> 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]]
>>>>
>>>> __
>

Re: [R] Hacked

2018-04-18 Thread Fowler, Mark
Seems it must be the R-list. A horde of ‘solicitation’ emails began arriving 
about 27 minutes after I posted about not seeing any! Had left work by that 
time, so did not encounter them until now.

From: Mark Leeds [mailto:marklee...@gmail.com]
Sent: April 18, 2018 12:33 AM
To: Rui Barradas
Cc: Ding, Yuan Chun; Fowler, Mark; Luis Puerto; Peter Langfelder; R-Help ML 
R-Project; Neotropical bat risk assessments
Subject: Re: [R] Hacked

Hi All: I lately get a lot more spam-porn type emails lately also but I don't 
know if they are due to me being on
the R-list.


On Tue, Apr 17, 2018 at 5:09 PM, Rui Barradas 
mailto:ruipbarra...@sapo.pt>> wrote:
Hello,

Nor do I, no gmail, also got spam.

Rui Barradas

On 4/17/2018 8:34 PM, Ding, Yuan Chun wrote:
No, I do not use gmail, still got dirty spam email twice.

-Original Message-
From: R-help 
[mailto:r-help-boun...@r-project.org<mailto:r-help-boun...@r-project.org>] On 
Behalf Of Fowler, Mark
Sent: Tuesday, April 17, 2018 12:32 PM
To: Luis Puerto; Peter Langfelder
Cc: R-Help ML R-Project; Neotropical bat risk assessments
Subject: Re: [R] Hacked

[Attention: This email came from an external source. Do not open attachments or 
click on links from unknown senders or unexpected emails.]





Just an observation. I have not seen the spam you are discussing. Possibly it 
is specific to gmail addresses?

-Original Message-
From: R-help 
[mailto:r-help-boun...@r-project.org<mailto:r-help-boun...@r-project.org>] On 
Behalf Of Luis Puerto
Sent: April 17, 2018 4:11 PM
To: Peter Langfelder
Cc: R-Help ML R-Project; Neotropical bat risk assessments
Subject: Re: [R] Hacked

Hi!

This happened to me also! I just got a spam email just after posting and then 
in following days I got obnoxious spam emails in my spam filter. As the others, 
I think that there is some kind of bot subscribed to the list, but also perhaps 
a spider or crawler monitoring the R-Help archive and getting email addresses 
there. Nabble is a possibility too.
On 17 Apr 2018, at 21:50, Peter Langfelder 
mailto:peter.langfel...@gmail.com>> wrote:

I got some spam emails after my last post to the list, and the emails
did not seem to go through r-help. The spammers may be subscribed to
the r-help, or they get the poster emails from some of the web copies
of this list (nabble or similar).

Peter

On Tue, Apr 17, 2018 at 11:37 AM, Ulrik Stervbo 
mailto:ulrik.ster...@gmail.com>> wrote:
I asked the moderators about it. This is the reply

"Other moderators have looked into this a bit and may be able to shed
more light on it. This is a "new" tactic where the spammers appear to
reply to the r-help post. They are not, however, going through the r-help 
server.

It also seems that this does not happen to everyone.

I am not sure how you can automatically block the spammers.

Sorry I cannot be of more help."

--Ulrik

Jeff Newmiller mailto:jdnew...@dcn.davis.ca.us>> 
schrieb am Di., 17. Apr.
2018,
14:59:
Likely a spammer has joined the mailing list and is auto-replying to
posts made to the list. Unlikely that the list itself has been
"hacked". Agree that it is obnoxious.

On April 17, 2018 5:01:10 AM PDT, Neotropical bat risk assessments <
neotropical.b...@gmail.com<mailto:neotropical.b...@gmail.com>> wrote:
Hi all,

Site has been hacked?
Bad SPAM arriving

__
R-help@r-project.org<mailto: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.

--
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org<mailto: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<mailto: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<mailto: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<mailto:R-help@r-project.org> mailing list -- To 
UNSUBSCRIBE and more, s

[R] Aggregate counts of observations with times surrounding a time?

2017-05-15 Thread Mark Noworolski
I have a data frame that has a set of observed dwell times at a set of
locations. The metadata for the locations includes things that have varying
degrees of specificity. I'm interested in tracking the number of people
present at a given time in a given store, type of store, or zip code.

Here's an example of some sample data (here st=start_time, and et=end_time):
data.frame(st=seq(1483360938,by=1700,length=10),et=seq(1483362938,by=1700,length=10),store=c(rep("gap",5),rep("starbucks",5)),zip=c(94000,94000,94100,94100,94200,94000,94000,94100,94100,94200),store_id=seq(50,59))
   st et store   zip store_id
1  1483360938 1483362938   gap 94000   50
2  1483362638 1483364638   gap 94000   51
3  1483364338 1483366338   gap 94100   52
4  1483366038 1483368038   gap 94100   53
5  1483367738 1483369738   gap 94200   54
6  1483369438 1483371438 starbucks 94000   55
7  1483371138 1483373138 starbucks 94000   56
8  1483372838 1483374838 starbucks 94100   57
9  1483374538 1483376538 starbucks 94100   58
10 1483376238 1483378238 starbucks 94200   59

I'd like to be able to:
a) create aggretages of the number of people present in each store_id at a
given time
b) create aggregates of the number of people present - grouped by zip or
store

I expect to be rolling up to hour or half hour buckets, but I don't think I
should have to decide this up front and be able to do something clever to
be able to use ggplot + some other library to plot the time evolution of
this information, rolled up the way I want.

Any clever solutions? I've trolled stackoverflow and this email list.. to
no avail - but I'm willing to acknowledge I may have missed something.

[[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] package to fit mixtures of student-t distributions

2017-06-29 Thread Mark Leeds
Hi: The R package below may be of use to you.

https://journal.r-project.org/archive/2009-1/RJournal_2009-1_Ardia+et+al.pdf


On Thu, Jun 29, 2017 at 12:15 PM, Ranjan Maitra  wrote:

> Would package "teigen" help?
>
> Ranjan
>
> On Thu, 29 Jun 2017 14:41:34 +0200 vare vare via R-help <
> r-help@r-project.org> wrote:
>
> > Hello!
> >
> > I am new to R (before used python exclusively and would actually call
> the R solution for this issue inside a python notebook, hope that doesn’t
> disqualify me right of the batch).
> >
> > Right now I am  looking for a piece of software  to fit a 1D data sample
> to a mixture of t-distributions.
> >
> > I searched quite a while already and it seems to be that this is a
> somehwat obscure endeavor as most search results turn up for mixture of
> gaussians (what I am not interested here).
> >
> > The most promising candidates so far are the "AdMit" and "MitSEM" R
> packages. However I do not know R and find the description of these
> packages rather comlple and it seems their core objective is not the
> fitting of mixtures of t’s but instead use this as a step to accomplish
> something else.
> >
> > This is in a nutshell what I want the software to accomplish:
> >
> > Fitting a mixture of t-distributions to some data and estimate the
> "location" "scale" and "degrees of freedom" for each.
> >
> > I hope someone can point me to a simple package, I can’t believe that
> this is such an obscure use case.
> >
> > Thanks!
> >
> > __
> > 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.
>
> --
> Important Notice: This mailbox is ignored: e-mails are set to be deleted
> on receipt. Please respond to the mailing list if appropriate. For those
> needing to send personal or professional e-mail, please use appropriate
> addresses.
>
> __
> 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] Please help(urgent) - How to simulate transactional data for reliability/survival analysis

2017-07-04 Thread Mark Sharp
A small example data set that illustrates your question will be of great value 
to those trying to help. This appears to be a transformation that you are 
wanting to do (timestamp to units of time) so a data representing what you have 
(dput() is handy for this) and one representing what you want to have with any 
guidance regarding how to use the other columns in you data set (e.g., the 
event(0/1)).

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jul 4, 2017, at 7:02 AM, Sunny Singha  
> wrote:
>
> Thanks Boris and Bret,
> I was successful in simulating granular/transactional data.
> Now I need some guidance to transform the same data in format acceptable
> for survival analysis i.e below format:
>
> pump_id | event_episode_no. | event(0/1) | start | stop | time_to_dropout
>
> The challenge I'm experience is to generate the 'start' and 'stop' in units
> of minutes/days from single column of 'Timestamp' which is
> the column from transactional/granular data based on condition tagged in
> separate column, 'event 0/1, (i.e event ).
>
> Please guide how to do such transformation in 'R'.
>
> Regards,
> Sandeep
>
>
>
> On Wed, Jun 28, 2017 at 2:51 PM, Boris Steipe 
> wrote:
>
>> In principle what you need to do is the following:
>>
>> - break down the time you wish to simulate into intervals.
>> - for each interval, and each failure mode, determine the probability of
>> an event.
>>   Determining the probability is the fun part, where you make your domain
>>   knowledge explicit and include all the factors into your model:
>> cumulative load,
>>   failure history, pressure, temperature, phase of the moon ...
>> - once you have a probability of failure, use the runif() function to
>> give you
>>   a uniformly distributed random number in [0, 1]. If the number is
>> smaller than
>>   your failure probability, accept the failure event, and record it.
>> - Repeat many times.
>>
>> Hope this helps.
>> B.
>>
>>
>>
>>
>>> On Jun 27, 2017, at 10:58 AM, sandeep Rana  wrote:
>>>
>>> Hi friends,
>>> I haven't done such a simulation before and any help would be greatly
>> appreciated. I need your guidance.
>>>
>>> I need to simulate end to end data for Reliability/survival analysis of
>> a Pump ,with correlation in place, that is at 'Transactional level' or at
>> the granularity of time-minutes, where each observation is a reading
>> captured via Pump's sensors each minute.
>>> Once transactional data is prepared I Then need to summarise above data
>> for reliability/ survival analysis.
>>>
>>> To begin with below is the transactional data format that i want prepare:
>>> Pump-id| Timestamp | temp | vibration | suction pressure| discharge
>> pressure | Flow
>>>
>>> Above transactional data has to be prepared with below failure modes
>>> Defects :
>>> (1)Cavitation – very high in frequency but low impact
>>> (2)Bearing Damage – very low in frequency but high impact
>>> (3)Worn Shaft – medium frequency but medium impact
>>>
>>> I have used survsim package but that's not what I need here.
>>> Please help and guide.
>>>
>>> Regards,
>>> Sandeep
>>>
>>> __
>>> 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.
>>
>
> [[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.

CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
transmitted, may contain privileged and confidential information and is 
intended solely for the exclusive use of the individual or entity to whom it is 
addre

Re: [R] Please help(urgent) - How to simulate transactional data for reliability/survival analysis

2017-07-05 Thread Mark Sharp
I am trying to figure out the algorithm you are using to calculate 
event_episodes, event_status, and start_minutes.

Where does the 129600 come from?

Why is the start(minutes) 0 for the last row instead of 40?

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jul 5, 2017, at 1:03 AM, Sunny Singha  
> wrote:
>
> Mark,
> Below is the sampled simulated granular data format for pumps for
> trial period of 3 months that I need to transform for survival
> analysis:
> 3 months = (60*24*90) minutes i.e 129600 minutes
>
> pump_id timingsevents   vibration temprature flow
> pump1 01-07-2017 00:00   03.44369.6   139.806
> pump1 01-07-2017 00:10   10.50145.27 140.028
> pump1 01-07-2017 00:20   02.03152.9   137.698
> pump1 01-07-2017 00:30   02.26760.12 139.054
> pump1 01-07-2017 00:40   12.26760.12 139.054
> pump1 01-07-2017 00:50   02.26760.12 139.054
> pump2 01-07-2017 00:00   03.44369.6   139.806
> pump2 01-07-2017 00:10   00.50145.27 140.028
> pump2 01-07-2017 00:20   02.03152.9   137.698
> pump2 01-07-2017 00:30   02.26760.12 139.054
> pump2 01-07-2017 00:40   12.26760.12 139.054
> pump2 01-07-2017 00:50   02.26760.12 139.054
>
> The above data set records observations and timings where 'pumps'
> experienced failure, tagged as '1' in column 'events'.
> In the above granular dataset the pump1 experiences 2 "event episodes."
>
> Below is the desired transformed format. the covariates in this data
> set will have the mean value:
> pump_id  event_episodes  event_status  start(minutes)
> stop(minutes)
> pump1  1 1
>  0   10
> pump1  2 1
> 10  40
> pump1  3 0
> 40  129600
> pump2  1 1
>  0   40
> pump2  2 0
>  0   129600
> .
> .
>
> The 'start' and 'stop' columns are evaluated from the 'timings'
> columns. I need help in performing such transformation in 'R'.
> Please guide and help.
>
> Regards,
> Sandeep
>
> On Wed, Jul 5, 2017 at 7:26 AM, Mark Sharp  wrote:
>> A small example data set that illustrates your question will be of great 
>> value to those trying to help. This appears to be a transformation that you 
>> are wanting to do (timestamp to units of time) so a data representing what 
>> you have (dput() is handy for this) and one representing what you want to 
>> have with any guidance regarding how to use the other columns in you data 
>> set (e.g., the event(0/1)).
>>
>> Mark
>> R. Mark Sharp, Ph.D.
>> msh...@txbiomed.org
>>
>>
>>
>>
>>
>>> On Jul 4, 2017, at 7:02 AM, Sunny Singha  
>>> wrote:
>>>
>>> Thanks Boris and Bret,
>>> I was successful in simulating granular/transactional data.
>>> Now I need some guidance to transform the same data in format acceptable
>>> for survival analysis i.e below format:
>>>
>>> pump_id | event_episode_no. | event(0/1) | start | stop | time_to_dropout
>>>
>>> The challenge I'm experience is to generate the 'start' and 'stop' in units
>>> of minutes/days from single column of 'Timestamp' which is
>>> the column from transactional/granular data based on condition tagged in
>>> separate column, 'event 0/1, (i.e event ).
>>>
>>> Please guide how to do such transformation in 'R'.
>>>
>>> Regards,
>>> Sandeep
>>>
>>>
>>>
>>> On Wed, Jun 28, 2017 at 2:51 PM, Boris Steipe 
>>> wrote:
>>>
>>>> In principle what you need to do is the following:
>>>>
>>>> - break down the time you wish to simulate into intervals.
>>>> - for each interval, and each failure mode, determine the probability of
>>>> an event.
>>>>  Determining the probability is the fun part, where you make your domain
>>>>  knowledge explicit and include all the factors into your mode

[R] metRology package

2017-07-12 Thread mark . hogue
I'm having trouble with a simple application with metRology. I need to 
estimate the uncertainty of the density thickness of seven sheets of film. 
This is calculated from measurements of mass, length and width of 
rectangular samples of film.

It's not too hard to calculate the whole thing with a little Monte Carlo 
loop. I get about 0.07 with this:

#sample area
L<-5*2.54 #cm
W<-8*2.54 #cm
#sample mass
m<-0.2543*1000 #mg
#uncertainties
L.u<-(1/16)*2.54 #cm (nearest 16th inch)
W.u<-(1/16)*2.54 #cm 
m.u<-0.006*1000 #mg scale calibration data 

denth<-c(0,0,0)
singth<-c(0,0,0)
for(i in 1:1e5) {
  #denth[i]<-7*dt+sum(rnorm(7,0,dt.u))
  for(j in 1:7)
 singth[j]<-(m+rnorm(1,0,m.u))/((L+rnorm(1,0,L.u))*(W+rnorm(1,0,W.u)))
  denth[i]<-sum(singth)
}
sd(denth) #0.07279882

Now with the metRology package, I get a much higher number, which is 
actually the seven times the uncertainty of one layer:

require(metRology)
d.set<-list(mass=m,Length=L,Width=W)
d.set.u<-list(m.u,L.u,W.u)

dent<-expression(7*(mass/(Length*Width)))
uncert(obj=dent, x=d.set, u=d.set.u, method="GUM")

I've tried other ways of defining the expression and every method option. 
I suspect the expression is the problem area, but if so, I really need to 
know how to get it right for harder problems. Thanks in advance for any 
suggestions.

- Mark

[[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] Loading Rcmdr

2017-07-24 Thread Mark Sharp
Jack,

I do not use Rcmdr, but I installed the binary package version 2.3-2. It came 
right up when I then ran the following at the prompt (console output is 
appended without edits):
> sessionInfo();library("Rcmdr");sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: 
/Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: 
/Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

loaded via a namespace (and not attached):
[1] compiler_3.4.1
Loading required package: splines
Loading required package: RcmdrMisc
Loading required package: car
Loading required package: sandwich

Rcmdr Version 2.3-2

R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: 
/Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: 
/Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] Rcmdr_2.3-2 RcmdrMisc_1.0-5 sandwich_2.3-4  car_2.1-5

loaded via a namespace (and not attached):
 [1] zoo_1.8-0   lattice_0.20-35 tcltk_3.4.1 
colorspace_1.3-2
 [5] htmltools_0.3.6 mgcv_1.8-17 base64enc_0.1-3 relimp_1.0-5
 [9] survival_2.41-3 rlang_0.1.1.9000e1071_1.6-8 nloptr_1.0.4
[13] foreign_0.8-69  RColorBrewer_1.1-2  readxl_1.0.0plyr_1.8.4
[17] stringr_1.2.0   MatrixModels_0.4-1  cellranger_1.1.0munsell_0.4.3
[21] gtable_0.2.0htmlwidgets_0.9 latticeExtra_0.6-28 knitr_1.16
[25] SparseM_1.77class_7.3-14quantreg_5.33   pbkrtest_0.4-7
[29] parallel_3.4.1  htmlTable_1.9   Rcpp_0.12.12acepack_1.4.1
[33] tcltk2_1.2-11   scales_0.4.1backports_1.1.0 checkmate_1.8.3
[37] Hmisc_4.0-3 abind_1.4-5 lme4_1.1-13 gridExtra_2.2.1
[41] ggplot2_2.2.1   digest_0.6.12   stringi_1.1.5   grid_3.4.1
[45] tools_3.4.1 magrittr_1.5lazyeval_0.2.0  tibble_1.3.3
[49] Formula_1.2-2   cluster_2.0.6   MASS_7.3-47 Matrix_1.2-10
[53] data.table_1.10.4   minqa_1.2.4 rpart_4.1-11nnet_7.3-12
[57] nlme_3.1-131compiler_3.4.1
> R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jul 24, 2017, at 6:17 PM, Jack Talley  wrote:
>
> With the lastest version of R 3.4.1 I have not been able to loard Rcmdr.
> Advice please.
>
> Thank you,
>
> Jack Talley, PhD
>
> [[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.

CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:10}}

__
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] How to concatenate in R

2017-08-02 Thread Mark Sharp
You will need to understand dataframes and how to add those together. Use the 
help system by typing ?rbind at the console prompt. There are numerous examples 
to be found with a simple web search.

Robert Kabacoff has a great book and website the provides examples and 
explanation at http://www.statmethods.net/management/merging.html

Look at the readxl package. You may want to start with 
http://readxl.tidyverse.org.

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Aug 2, 2017, at 6:06 AM, Swain, Subrat  wrote:
>
>
> Hi,
>
> I have 6 excel files, I want to concatenate all and create one excel files, 
> How to program that in R.(I need the code)
>
> Kind regards,
>
> SUBRAT SWAIN
>
> IMPORTANT NOTICE:
> The information in this email (and any attachments) is confidential. If you 
> are not the intended recipient, you must not use or disseminate the 
> information. If you have received this email in error, please immediately 
> notify me by "Reply" command and permanently delete the original and any 
> copies or printouts thereof. Although this email and any attachments are 
> believed to be free of any virus or other defect that might affect any 
> computer system into which it is received and opened, it is the 
> responsibility of the recipient to ensure that it is virus free and no 
> responsibility is accepted by American International Group, Inc. or its 
> subsidiaries or affiliates either jointly or severally, for any loss or 
> damage arising in any way from its use.
>
> [[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.

CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:10}}

__
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] by() subset by factor gives unexpected results

2017-08-05 Thread Mark Leeds
Putting answer here for future posterity. Didn't send to R-help initially
because I wasn't sure
what OP wanted. I guessed right.  Sorry for confusion in thread.


GUESSING THAT YOU WANT IS BELOW
#===

i <- data.frame(x=c(1,2,3), y=c(0,0,0), B=c("red","blue","blue"),
stringsAsFactors = FALSE)
j <- data.frame(x=c(1,2,3), y=c(1,1,1), B=c('red','blue','green'),
stringsAsFactors = FALSE)

plot(0, 0, type="n", xlim=c(0,4), ylim=c(0,1))
points(i$x, i$y, col = i$B)
points(j$x, j$y, col = j$B)

On Sat, Aug 5, 2017 at 5:59 AM, Myles English 
wrote:

>
> The answer was (thanks to Mark Leeds) to do with the use of a factor
> instead of a vector.
>
> on [2017-08-05] at 08:57 Myles English writes:
>
> > I am having trouble understanding how the 'by' function works.  Using
> > this bit of code:
> >
> > i <- data.frame(x=c(1,2,3), y=c(0,0,0), B=c("red","blue","blue"))
> > j <- data.frame(x=c(1,2,3), y=c(1,1,1), B=c('red','blue','green'))
>
> The use of I() prevents conversion to a factor:
>
> i <- data.frame(x=c(1,2,3), y=c(0,0,0), B=I(c("red","blue","blue")))
> j <- data.frame(x=c(1,2,3), y=c(1,1,1), B=I(c('red','blue','green')))
>
> > plot(0, 0, type="n", xlim=c(0,4), ylim=c(0,1))
> > by(i, i$B, function(s){ points(s$x, s$y, col=s$B) })
> > by(j, j$B, function(s){ points(s$x, s$y, col=s$B) })
> >
> > I would have expected the point at (1,1) to be coloured red.  When
> > plotted, this row is indeed red:
> >
> >> i[1,]
> >   x y   B
> > 1 1 0 red
> >
> > however, this next point is green on the plot even though I would like
> > it to be red:
> >
> >> j[1,]
> >   x y   B
> > 1 1 1 red
> >
> > How can I achieve that?
> >
> > Myles
>
>

[[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] Error in setwd("dir") :

2017-08-05 Thread mark . hogue

Did you put the directory in quotes with forward slashes? Please show
command used.

Sent from my iPhone

> On Aug 5, 2017, at 1:10 PM, ? ?  wrote:
>
> Hello, I got some of the R source code and not being able to Run it in
> RStudio.
> I get the error:
>
> Error in setwd("dir") :
>  cannot change working directory
>
>
> I have gone through forums but nothing seemed relevant to my issue.
> What bugs me the most is the ("dir") that the error shows, is of  those
who
> wrote the source code and not mine(it still sees the directory of their
> computer, even though, I have changed all the directories).
> When I write getwd(), it dispalys my "dir".
> Does anyone have any ideas on what's going on here?
> Thank you
>
>
> --
> Greg Lyukshin
>
>[[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] Package nleqslv ERROR

2017-08-09 Thread Mark Sharp
Santi,


In the second line of your function you have the following:
f <- numeric(length(x))

This sets the length of this numeric vector (i.e., "f") to the length of the 
vector "x".
Later, inside the function you assign to values to 4 elements of the vector "f".
This assumes that "f" is at least 4 element in length.

However, you define "startx" to be a numeric vector of length 2 with
startx <- c(16350, 1.33)
which you then use as the argument to the function "fun" (bad name for a 
function, by the way, as it is not descriptive).

Thus, when "x" inside your function gets the value of "startx" it becomes a 
numeric vector of length 2, which is then used to set the length of the numeric 
vector "f". As soon as the function tries to assign a value to f[3], R 
correctly throws an informative error.

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Aug 9, 2017, at 3:56 PM, Santi Burone  wrote:
>
> Dear all,
> I am relatively new to R and have had some difficulty in understanding an 
> error i get when running a code to solve a system of non-linear equations, 
> with four equations and two variables.
>
> This is my code:
>
> ALPHA <- c(-0.0985168033402, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4)
> BETA <- c(-0.0985168033402, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4)
> GAMMA <- c(0.3940672148378, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4)
> MEA <- 3
> MIA <- 1
> MAA <- 5
> DEA <- 0.385
> fun <- function(x)  {
>  f <- numeric(length(x))
>  f[1] <-   1*x[1] - 
> MEA*((0.5*((MIA-MEA)^2))^(-BETA[1+j]))*((0.5*((MAA-MEA)^2))^(-ALPHA[1+i]))*((DEA)^(-GAMMA[1+k]*((12^0.5)^(-GAMMA[1+k])))/(((0.5)^(-BETA[1+j]-ALPHA[1+i]))*(((1-1*x[2])/(2))^(-BETA[1+j]))*(((-1+1*x[2])/(2))^(-ALPHA[1+i]))*(2*(1*x[2]-1)^(-GAMMA[1+k]^(1/(-1-BETA[1+j]-ALPHA[1+i]-1.5*GAMMA[1+k]))
>  f[2] <-   1*x[1] - 
> (((MAA*((0.5*((MIA+MAA)^(2)))^(-BETA[1+j]))*((DEA)^(-GAMMA[1+k])))*((12^0.5)^(-GAMMA[1+k])))/((1*x[2])*(2^(-BETA[1+j]-GAMMA[1+k]))*((1*x[2]-1)^(-GAMMA[1+k]))*1-1*x[2])^2)/2)^(-BETA[1+j]^(1/(1-2*BETA[1+j]-1.5*(GAMMA[1+k])))
>  f[3] <-   1*x[1] - 
> (((MIA*((0.5*((MIA+MAA)^(2)))^(-ALPHA[1+i]))*((DEA)^(-GAMMA[1+k])))*((12^0.5)^(-GAMMA[1+k])))/((2-1*x[2])*(2^(-ALPHA[1+i]-GAMMA[1+k]))*((1*x[2]-1)^(-GAMMA[1+k]))*-1+1*x[2])^2)/2)^(-ALPHA[1+i]^(1/(1-2*ALPHA[1+i]-1.5*(GAMMA[1+k])))
>  f[4] <- 1*x[2] > 1
>  f
>
> }
>
> Result <- matrix(0,nrow=9*9*9,ncol=6)
> startx<-c(16350, 1.33)
> indx <- 1
> for (i in 1:9) {
>  for (j in 1:9) {
>for (k in 1:9) {
>  f.startx <- fun(startx)
>  if(anyNA(f.startx)) {
>Result[indx,1:3] <- NA
>  } else {
>z <- nleqslv(startx,fun)
>Result[indx,1:3] <- c(z$termcd,z$x)
>  }
>  Result[indx,4:6] <- c(i,j,k)
>  indx <- indx+1
>}
>  }
> }
>
>
> The error i get when solving for specific values of ALPHA, BETA and GAMMA, 
> not using the loop is:
>
> Error in nleqslv(xstart, fun) : Length of fn result <> length of x!
>
> I had already solved this problem useing ALPHA, BETA and GAMMA as X[1], X[2] 
> and X[3] and being X[1] and X[2] of this system  given values, in that case 
> for the first values of alpha beta and gamma given here the solution was 
> (16350, 1.33).
> I dont understand what’s the error i get here, as i know the system as a 
> unique solution. "What’s the meaning of Length of fn result <> length of x!"?
>
> Thanks in advance!
> Santiago.
> [[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.

CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
transmitted, may contain privileged and confidential information and is 
intended solely for the exclusive use of the individual or entity to whom it is 
addressed. If you are not the intended recipient, you are hereby notified that 
any review, dissemination, distribution or copying of this e-mail and/or 
attachments is strictly prohibited. If you have received this e-mail in error, 
please immediately notify the sender stating that this transmission was 
misdirected; return the e-mail to sender; destroy all paper copies and delete 
all electronic copies from your system without disclosing its contents.
__
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] Comparing 2 dale columns

2017-08-23 Thread Mark Sharp
Patrick,

## Run the following script an notice the different values of the dataframe 
"data" in each instance.

# I understand you have done something like the following:
data <- data.frame(COL1 = c("6/1/14", "7/1/14"),
   COL2 = c("5/1/15", "5/1/15"), stringsAsFactors = FALSE)
data$Date_Flag <- ifelse(data$COL2 > data$COL1, 0,1)
data
data$COL2 <- as.Date(as.character(data$COL2, format = "%y/%m/%d"))
data$COL1 <- as.Date(as.character(data$COL1, format = "%y/%m/%d"))
data$Date_Flag <- ifelse(data$COL2 > data$COL1, 0,1)
data

# What you may want instead is the following:
data <- data.frame(COL1 = c("6/1/14", "7/1/14"),
   COL2 = c("5/1/15", "5/1/15"), stringsAsFactors = FALSE)
data
## strptime() converts the character vector to POSIXct so you do not necessarily
## need the as.Date. However, they are not the same and you may need the Date
## class.
data$COL2 <- as.Date(strptime(data$COL2, format = "%m/%d/%y"))
data$COL1 <- as.Date(strptime(data$COL1, format = "%m/%d/%y"))
data
data$Date_Flag <- ifelse(data$COL2 > data$COL1, 0,1)
data


R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Aug 23, 2017, at 9:53 AM, Patrick Casimir  wrote:
>
> data$Date_Flag <- ifelse(data$COL2 > data$COL1, 0,1)
>
>
> COL1   COL2
> 6/1/14 5/1/15
> 7/1/14 5/1/15
>
>
> data$COL2<- as.Date(as.character(data$COL2, format="%y/%m/%d"))
> data$COL1<- as.Date(as.character(data$COL1, format="%y/%m/%d"))
>

CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:10}}

__
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] Interesting behavior of lm() with small, problematic data sets

2017-09-05 Thread mark . hogue
Tim,

I think what you're seeing is 
https://en.wikipedia.org/wiki/Loss_of_significance.

Cheers,

Mark



From:   "Glover, Tim" 
To: "r-help@r-project.org" 
Date:   09/05/2017 11:37 AM
Subject:[R] Interesting behavior of lm() with small, problematic 
data sets
Sent by:"R-help" 



I've recently come across the following results reported from the lm() 
function when applied to a particular type of admittedly difficult data. 
When working with
small data sets (for instance 3 points) with the same response for 
different predicting variable, the resulting slope estimate is a 
reasonable approximation of the expected 0.0, but the p-value of that 
slope estimate is a surprising value.  A reproducible example is included 
below, along with the output of the summary of results

# example code
x <- c(1,2,3)
y <- c(1,1,1)

#above results in{ (1,1) (2,1) (3,1)} data set to regress

new.rez <- lm (y ~ x) # regress constant y on changing x)
summary(new.rez) # display results of regression

 end of example code

Results:

Call:
lm(formula = y ~ x)

Residuals:
 1  2  3
 5.906e-17 -1.181e-16  5.906e-17

Coefficients:
  Estimate Std. Errort value Pr(>|t|)
(Intercept)  1.000e+00  2.210e-16  4.525e+15   <2e-16 ***
x   -1.772e-16  1.023e-16 -1.732e+000.333
---
Signif. codes:  0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1

Residual standard error: 1.447e-16 on 1 degrees of freedom
Multiple R-squared:  0.7794,Adjusted R-squared:  0.5589
F-statistic: 3.534 on 1 and 1 DF,  p-value: 0.3112

Warning message:
In summary.lm(new.rez) : essentially perfect fit: summary may be 
unreliable


##

There is a warning that the summary may be unreliable sue to the 
essentially perfect fit, but a p-value of 0.3112 doesn?t seem reasonable.
As a side note, the various r^2 values seem odd too.







Tim Glover
Senior Scientist II (Geochemistry, Statistics), Americas - Environment & 
Infrastructure, Amec Foster Wheeler
271 Mill Road, Chelmsford, Massachusetts, USA 01824-4105
T +01 978 692 9090  D +01 978 392 5383  M +01 850 445 5039
tim.glo...@amecfw.com  amecfw.com


This message is the property of Amec Foster Wheeler plc and/or its 
subsidiaries and/or affiliates and is intended only for the named 
recipient(s). Its contents (including any attachments) may be 
confidential, legally privileged or otherwise protected from disclosure by 
law. Unauthorised use, copying, distribution or disclosure of any of it 
may be unlawful and is strictly prohibited. We assume no responsibility to 
persons other than the intended named recipient(s) and do not accept 
liability for any errors or omissions which are a result of email 
transmission. If you have received this message in error, please notify us 
immediately by reply email to the sender and confirm that the original 
message and any attachments and copies have been destroyed and deleted 
from your system. If you do not wish to receive future unsolicited 
commercial electronic messages from us, please forward this email to: 
unsubscr...@amecfw.com and include ?Unsubscribe? in the subject line. If 
applicable, you will continue to receive invoices, project communications 
and similar factual, non-commercial electronic communications.

Please click http://amecfw.com/email-disclaimer for notices and company 
information in relation to emails originating in the UK, Italy or France.

__
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] email threads chronology

2016-05-30 Thread Fowler, Mark
Hi all,

I'm seeing the natural sequencing of email threads getting corrupted. For 
example, a May 26 thread on subject 'Shaded areas in R' would have been 
initiated by an email at 6:58am. However I did not get that email until 1:48pm, 
preceded by 3 replies to the post. Trivial but irritating. The preceding 
replies suggest this is something going on at my end, perhaps related to 
network security. I'm curious what might be causing it, and if there is 
something I can do about it - short of contacting IT staff, which is more 
irritating than the corrupted threads.

Mark Fowler
Population Ecology Division
Bedford Inst of Oceanography
Dept Fisheries & Oceans
Dartmouth NS Canada
B2Y 4A2
Tel. (902) 426-3529
Fax (902) 426-9710
Email mark.fow...@dfo-mpo.gc.ca<mailto:mark.fow...@dfo-mpo.gc.ca>



[[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] Assign value to plot variable name (make.group functions)

2016-06-13 Thread Mark Fingerle
Dear all,

In order to create plots comparing two measurements I am using the "xyplot" and 
"make.groups" functions (see script example below).
Now I would like to assign a value to the variable names in the plot. Meaning: 
In the beginning of my script I assign a name(value) to a variable (for 
example:  ID1 <- Name1). Now I would like to use this variable to name the plot 
variables.

Maybe easier to understand using an example:

Script:

pdf("REP_Chess.pdf")
scChess1=xyplot( x = ObjErrorX~Image, data=make.groups("ID1"=Chess1, 
"ID2"=Chess2),
 pch=16 ,main="Chess - Object Error X [mm]", auto.key=T, 
groups=which, scales=list(relation="free",
  
y=list(rot=0), x=list(rot=45), abbreviate = TRUE),

print(scChess1, split=c(1,1,1,1), more=False)
dev.off()

I would like to assign a value to ID1, so that this value is shown on the plot 
labels after it is printed.
Something like : ID1 <- Name1 , and Name1 is shown in the plots.


Thank you very much in advance.

Cheers
Mark Fingerle



[[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] function for over dispersed poisson regression in the setting of a random effects model

2016-06-26 Thread Mark Podolsky
Hi John,

The Gamlss.mx <http://gamlss.mx/> package can accommodate variables that follow 
negative binomial (and other) distributions in multilevel models.

Mark


> On Jun 25, 2016, at 11:00 PM, John Sorkin  wrote:
> 
> Is there a function that will run a model appropriate for over dispersed data 
> (such as a negative binomial or quasipoisson)
> with a random effects (or mixed effects) model in R? GLMER will not accept:  
> family=quasipoisson(link="log") or
> family=negbinomial(link="log") 
> 
> I want to run something like the following:
> fit0 <- glmer(Fall ~ 
> Group+(1|PID)+offset(log(TimeYrs)),family=quasipoisson(link="log"),data=data)
> Thank  you
> John
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and 
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing) 
> 
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:16}}

__
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] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread Mark Leeds
Hi Jermiah: another possibly faster way would be to use a kalman filtering
framework. I forget the details but duncan and horne have a paper which
shows how a regression can be re-computed each time a new data point is
added .I
forget if they handle taking one off of the back also which is what you
need.

The paper at the link below isn't the paper I'm talking about but it's
reference[1] in that paper. Note that this suggestion might not be a better
approach  than the various approaches already suggested so I wouldn't go
this route unless you're very interested.


Mark

https://www.le.ac.uk/users/dsgp1/COURSES/MESOMET/ECMETXT/recurse.pdf






On Thu, Jul 21, 2016 at 4:28 PM, Gabor Grothendieck  wrote:

> I would be careful about making assumptions regarding what is faster.
> Performance tends to be nonintuitive.
>
> When I ran rollapply/lm, rollapply/fastLm and roll_lm on the example
> you provided rollapply/fastLm was three times faster than roll_lm.  Of
> course this could change with data of different dimensions but it
> would be worthwhile to do actual benchmarks before making assumptions.
>
> I also noticed that roll_lm did not give the same coefficients as the
> other two.
>
> set.seed(1)
> library(zoo)
> library(RcppArmadillo)
> library(roll)
> z <- zoo(matrix(rnorm(10), ncol = 2))
> colnames(z) <- c("y", "x")
>
> ## rolling regression of width 4
> library(rbenchmark)
> benchmark(fastLm = rollapplyr(z, width = 4,
>  function(x) coef(fastLm(cbind(1, x[, 2]), x[, 1])),
>  by.column = FALSE),
>lm = rollapplyr(z, width = 4,
>  function(x) coef(lm(y ~ x, data = as.data.frame(x))),
>  by.column = FALSE),
>roll_lm =  roll_lm(coredata(z[, 1, drop = F]), coredata(z[, 2, drop =
> F]), 4,
>  center = FALSE))[1:4]
>
>
>  test replications elapsed relative
> 1  fastLm  1000.221.000
> 2  lm  1000.723.273
> 3 roll_lm  1000.642.909
>
> On Thu, Jul 21, 2016 at 3:45 PM, jeremiah rounds
>  wrote:
> >  Thanks all.  roll::roll_lm was essentially what I wanted.   I think
> maybe
> > I would prefer it to have options to return a few more things, but it is
> > the coefficients, and the remaining statistics you might want can be
> > calculated fast enough from there.
> >
> >
> > On Thu, Jul 21, 2016 at 12:36 PM, Achim Zeileis <
> achim.zeil...@uibk.ac.at>
> > wrote:
> >
> >> Jeremiah,
> >>
> >> for this purpose there are the "roll" and "RcppRoll" packages. Both use
> >> Rcpp and the former also provides rolling lm models. The latter has a
> >> generic interface that let's you define your own function.
> >>
> >> One thing to pay attention to, though, is the numerical reliability.
> >> Especially on large time series with relatively short windows there is a
> >> good chance of encountering numerically challenging situations. The QR
> >> decomposition used by lm is fairly robust while other more
> straightforward
> >> matrix multiplications may not be. This should be kept in mind when
> writing
> >> your own Rcpp code for plugging it into RcppRoll.
> >>
> >> But I haven't check what the roll package does and how reliable that
> is...
> >>
> >> hth,
> >> Z
> >>
> >>
> >> On Thu, 21 Jul 2016, jeremiah rounds wrote:
> >>
> >> Hi,
> >>>
> >>> A not unusual task is performing a multiple regression in a rolling
> window
> >>> on a time-series.A standard piece of advice for doing in R is
> >>> something
> >>> like the code that follows at the end of the email.  I am currently
> using
> >>> an "embed" variant of that code and that piece of advice is out there
> too.
> >>>
> >>> But, it occurs to me that for such an easily specified matrix operation
> >>> standard R code is really slow.   rollapply constantly returns to R
> >>> interpreter at each window step for a new lm.   All lm is at its heart
> is
> >>> (X^t X)^(-1) * Xy,  and if you think about doing that with Rcpp in
> rolling
> >>> window you are just incrementing a counter and peeling off rows (or
> >>> columns
> >>> of X and y) of a particular window size, and following that up with
> some
> >>> matrix multiplication in a loop.   The psuedo-code for that Rcpp
> >>> practically writes itself and you might want a wrapper of something
> like:
> >>> rolling_lm (y=y, x=x, width=4).
> >>>
>

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread Mark Leeds
Hi Jeremiah: I think I wasn't that clear. I'm not suggesting  the kalman
filter to deal with time varying coefficients. As Roy pointed out, one can
use the kalman filter to do regular regression where one "sees" a new data
point as each time unit passes. It can be assumed that the coefficients do
not vary ( basically by having no variance in the system equation ).

The problem as I see it, is that Duncan and Horn's approach ( and Roy
alluded
to this problem also ), only deals with adding one point at a time to the
front of the data set.  It doesn't handle the fact that you want to drop
the nth observation and everything older than that observation  also.

don't know how easy it would be  to modify their approach to deal with the
fact that you are using a moving window rather than just adding one point
at a time.

The main point I wanted to get across here is that I was not suggesting the
KF as a way to handle varying coefficients. You can assume that they're
fixed and still use it. See the reference I pointed out for more on this
approach and my apologies for the confusion.
















On Thu, Jul 21, 2016 at 5:43 PM, jeremiah rounds 
wrote:

> I agree that when appropriate Kalman Filter/Smoothing the higher-quality
> way to go about estimating a time-varying coefficient (given that is what
> they do),  and I have noted that both the R package "dlm" and the function
> "StructTS" handle these problems quickly.  I am working on that in
> parallel.
>
> One of the things I am unsure about with Kalman Filters is how to estimate
> variance parameters when the process is unusual in some way that isn't in
> the model and it is not feasible to adjust the model by-hand.  dlm's dlmMLE
> seems to produce non-sense (not because of the author's work but because of
> assumptions).  At least with moving window regressions after the unusual
> event is past your window the influence of that event is gone.That
> isn't really a question for this group it is more about me reading more.
> When I get that "how to handle all the strange things big data throws at
> you" worked out for Kalman Filters, I will go back to those because I
> certainly like what I see when everything is right.  There is a plethora of
> related topics right?  Bayesian Model Averaging, G-ARCH models for
> heteroscedasticity, etc.
>
> Anyway... roll::roll_lm, cheers!
>
> Thanks,
> Jeremiah
>
>
>
> On Thu, Jul 21, 2016 at 2:08 PM, Mark Leeds  wrote:
>
>> Hi Jermiah: another possibly faster way would be to use a kalman
>> filtering framework. I forget the details but duncan and horne have a paper
>> which shows how a regression can be re-computed each time a new data point
>> is added .I
>> forget if they handle taking one off of the back also which is what you
>> need.
>>
>> The paper at the link below isn't the paper I'm talking about but it's
>> reference[1] in that paper. Note that this suggestion might not be a better
>> approach  than the various approaches already suggested so I wouldn't go
>> this route unless you're very interested.
>>
>>
>> Mark
>>
>> https://www.le.ac.uk/users/dsgp1/COURSES/MESOMET/ECMETXT/recurse.pdf
>>
>>
>>
>>
>>
>>
>> On Thu, Jul 21, 2016 at 4:28 PM, Gabor Grothendieck <
>> ggrothendi...@gmail.com> wrote:
>>
>>> I would be careful about making assumptions regarding what is faster.
>>> Performance tends to be nonintuitive.
>>>
>>> When I ran rollapply/lm, rollapply/fastLm and roll_lm on the example
>>> you provided rollapply/fastLm was three times faster than roll_lm.  Of
>>> course this could change with data of different dimensions but it
>>> would be worthwhile to do actual benchmarks before making assumptions.
>>>
>>> I also noticed that roll_lm did not give the same coefficients as the
>>> other two.
>>>
>>> set.seed(1)
>>> library(zoo)
>>> library(RcppArmadillo)
>>> library(roll)
>>> z <- zoo(matrix(rnorm(10), ncol = 2))
>>> colnames(z) <- c("y", "x")
>>>
>>> ## rolling regression of width 4
>>> library(rbenchmark)
>>> benchmark(fastLm = rollapplyr(z, width = 4,
>>>  function(x) coef(fastLm(cbind(1, x[, 2]), x[, 1])),
>>>  by.column = FALSE),
>>>lm = rollapplyr(z, width = 4,
>>>  function(x) coef(lm(y ~ x, data = as.data.frame(x))),
>>>  by.column = FALSE),
>>>roll_lm =  roll_lm(coredata(z[, 1, drop = F]), coredata(z[, 2, drop =
>>> F]), 4,
>>> 

Re: [R] How to connect Microsoft Sql server from R studio using freeTDS instead of RODBC package

2016-08-29 Thread Mark Sharp
Manu,

Read the first paragraph under section "1 ODBC Concepts" of 
https://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf. This 
describes the relationship among the various parts of the technical stack that 
allows connectivity to the database system via ODBC. One of the points made is 
that RODBC uses an ODBC driver (e.g., Actual Technologies, Easysoft and 
OpenLink).

I use the driver from Actual Technologies on Mac OS, but many others have used 
freeTDS. I had trouble with freeTDS years ago and decided my time was worth the 
minor cost of using the commercial product from Actual Technologies.

The driver you use is computer OS specific while RODBC is not.

It is also convenient to use an ODBC manager, which is typically a graphical 
application used to create and manage the configuration files used by the ODBC 
driver.

Mark

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org

> On Aug 28, 2016, at 11:53 PM, Manohar Reddy  wrote:
>
> Hi,
>
>
>
>   Can anyone guide me how to connect the Microsoft Sql server 2012/14 from
> R studio using freeTDS package instead of RODBC ,I can able to connect the
> MS Sql server from R studio using RODBC.
>
>  Actually my requirement is I have developed webpage/report using Shiny
> package then I was deployed it on Shinyapps.io ,but after deploying I’m
> encountering error like “”ERROR: *first argument is not an open RODBC
> channel*” ,based on this error message I did searched in google and found
> that we need to use freeTDS drivers instead of RODBC but I found some
> articles regarding freeTDS but it’s not useful for me.
>
>
>
> I was eagerly waiting for solution from someone since last month, but not
> yet and this issue is not allowing me to further .Can anyone please help me
> out me(how to install freeTDS and how to configure it) on same.
>
>
>
> My environment details :
>
>
>
>Os : windows 8
>
>R version 3.3.1 (2016-06-21)
>
>
>
> Thanks in Advance .
>
> Manu.
>
> [[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.







CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
transmitted, may contain privileged and confidential information and is 
intended solely for the exclusive use of the individual or entity to whom it is 
addressed. If you are not the intended recipient, you are hereby notified that 
any review, dissemination, distribution or copying of this e-mail and/or 
attachments is strictly prohibited. If you have received this e-mail in error, 
please immediately notify the sender stating that this transmission was 
misdirected; return the e-mail to sender; destroy all paper copies and delete 
all electronic copies from your system without disclosing its contents.
__
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] How to connect Microsoft Sql server from R studio using freeTDS instead of RODBC package

2016-08-29 Thread Mark Sharp
Manu,

I believe you are mistaken regarding using freeTDS instead of RODBC. 
shinyapps.io apparently has freeTDS drivers already installed. I am guessing 
that either you have not configured your connections string 
(odbcDriverConnect("driver = FreeTDS; ...")) correctly or your database server 
has a firewall rule that is not allowing a connection from shinyapps.io.

However, please note, I have not used shinyapps.io and am making these guesses 
based on my experience with RODBC and the documentation I have read. You will 
want to find someone with shinyapps.io experience.

Mark

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org

On Aug 29, 2016, at 12:26 PM, Manohar Reddy  wrote:
>
> Hi Mark,
>
>
>   Thank you so much for reply, using exiting ODBC drivers I will make a 
> connection  to sql server and it’s working fine in my local, but as per 
> shinyapps.io I need to use freeTDS drivers instead RODBC ,so that I may not 
> encounter the any issue .For me here challenging work is how to install 
> freeTDS on my machine and how to configure it?
>
>
>  Is there any drivers/way that can i  make a connection to sql server and 
> I shouldn’t encounter the issue after deploying application on shinyapps.io.
>
>
> Thanks,Manu.
>
>
> On Mon, Aug 29, 2016 at 9:35 PM, Mark Sharp  wrote:
> Manu,
>
> Read the first paragraph under section "1 ODBC Concepts" of 
> https://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf. This 
> describes the relationship among the various parts of the technical stack 
> that allows connectivity to the database system via ODBC. One of the points 
> made is that RODBC uses an ODBC driver (e.g., Actual Technologies, Easysoft 
> and OpenLink).
>
> I use the driver from Actual Technologies on Mac OS, but many others have 
> used freeTDS. I had trouble with freeTDS years ago and decided my time was 
> worth the minor cost of using the commercial product from Actual Technologies.
>
> The driver you use is computer OS specific while RODBC is not.
>
> It is also convenient to use an ODBC manager, which is typically a graphical 
> application used to create and manage the configuration files used by the 
> ODBC driver.
>
> Mark
>
> R. Mark Sharp, Ph.D.
> Director of Primate Records Database
> Southwest National Primate Research Center
> Texas Biomedical Research Institute
> P.O. Box 760549
> San Antonio, TX 78245-0549
> Telephone: (210)258-9476
> e-mail: msh...@txbiomed.org
>
> > On Aug 28, 2016, at 11:53 PM, Manohar Reddy  wrote:
> >
> > Hi,
> >
> >
> >
> >   Can anyone guide me how to connect the Microsoft Sql server 2012/14 from
> > R studio using freeTDS package instead of RODBC ,I can able to connect the
> > MS Sql server from R studio using RODBC.
> >
> >  Actually my requirement is I have developed webpage/report using Shiny
> > package then I was deployed it on Shinyapps.io ,but after deploying I’m
> > encountering error like “”ERROR: *first argument is not an open RODBC
> > channel*” ,based on this error message I did searched in google and found
> > that we need to use freeTDS drivers instead of RODBC but I found some
> > articles regarding freeTDS but it’s not useful for me.
> >
> >
> >
> > I was eagerly waiting for solution from someone since last month, but not
> > yet and this issue is not allowing me to further .Can anyone please help me
> > out me(how to install freeTDS and how to configure it) on same.
> >
> >
> >
> > My environment details :
> >
> >
> >
> >Os : windows 8
> >
> >R version 3.3.1 (2016-06-21)
> >
> >
> >
> > Thanks in Advance .
> >
> > Manu.
> >
> > [[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.
>
>
>
>
>
>
>
> CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
> transmitted, may contain privileged and confidential information and is 
> intended solely for the exclusive use of the individual or entity to whom it 
> is addressed. If you are not the intended recipient, you are hereby notified 
> that any review, dissemination, distribution or copying of this e-ma

Re: [R] How to connect Microsoft Sql server from R studio using freeTDS instead of RODBC package

2016-08-30 Thread Mark Sharp
Manu,

As far as I can tell you have not taken the advice from Wim Jansen, who gave 
you guidance on how to specify the freetds driver in your connection function. 
I do not think you need the unixodbc. In my experience having too much is as 
bad as not having enough.


R. Mark Sharp, Ph.D.
Director Primate Records Database
Southwest National Primate Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX. 78245-0549
(210)258-9476
msh...@txbiomed.org<mailto:msh...@txbiomed.org>

On Aug 30, 2016, at 07:05, Manohar Reddy 
mailto:manu.redd...@gmail.com>> wrote:

Hi Mark,

  Thanks,as per your suggestion and based on below link, I�m trying to connect 
my remote server but while connecting I have encountered attached error, can 
you please look in that and help out me.

  Link : https://groups.google.com/forum/#!topic/shinyapps-users/hs4bQHsk9JU

 Note :


1.   I tired without freeTDS versions also though nolock

2.   We have set it my remote sql server like by default it will allow all 
the connections.


Thnaks,Manu.

On Tue, Aug 30, 2016 at 12:53 AM, Mark Sharp 
mailto:msh...@txbiomed.org>> wrote:
Manu,

I believe you are mistaken regarding using freeTDS instead of RODBC. 
shinyapps.io<http://shinyapps.io> apparently has freeTDS drivers already 
installed. I am guessing that either you have not configured your connections 
string (odbcDriverConnect("driver = FreeTDS; ...")) correctly or your database 
server has a firewall rule that is not allowing a connection from 
shinyapps.io<http://shinyapps.io>.

However, please note, I have not used shinyapps.io<http://shinyapps.io> and am 
making these guesses based on my experience with RODBC and the documentation I 
have read. You will want to find someone with shinyapps.io<http://shinyapps.io> 
experience.

Mark

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org<mailto:msh...@txbiomed.org>

On Aug 29, 2016, at 12:26 PM, Manohar Reddy 
mailto:manu.redd...@gmail.com>> wrote:
>
> Hi Mark,
>
>
>   Thank you so much for reply, using exiting ODBC drivers I will make a 
> connection  to sql server and it�s working fine in my local, but as per 
> shinyapps.io<http://shinyapps.io> I need to use freeTDS drivers instead RODBC 
> ,so that I may not encounter the any issue .For me here challenging work is 
> how to install freeTDS on my machine and how to configure it?
>
>
>  Is there any drivers/way that can i  make a connection to sql server and 
> I shouldn�t encounter the issue after deploying application on 
> shinyapps.io<http://shinyapps.io>.
>
>
> Thanks,Manu.
>
>
> On Mon, Aug 29, 2016 at 9:35 PM, Mark Sharp 
> mailto:msh...@txbiomed.org>> wrote:
> Manu,
>
> Read the first paragraph under section "1 ODBC Concepts" of 
> https://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf. This 
> describes the relationship among the various parts of the technical stack 
> that allows connectivity to the database system via ODBC. One of the points 
> made is that RODBC uses an ODBC driver (e.g., Actual Technologies, Easysoft 
> and OpenLink).
>
> I use the driver from Actual Technologies on Mac OS, but many others have 
> used freeTDS. I had trouble with freeTDS years ago and decided my time was 
> worth the minor cost of using the commercial product from Actual Technologies.
>
> The driver you use is computer OS specific while RODBC is not.
>
> It is also convenient to use an ODBC manager, which is typically a graphical 
> application used to create and manage the configuration files used by the 
> ODBC driver.
>
> Mark
>
> R. Mark Sharp, Ph.D.
> Director of Primate Records Database
> Southwest National Primate Research Center
> Texas Biomedical Research Institute
> P.O. Box 760549
> San Antonio, TX 78245-0549
> Telephone: (210)258-9476
> e-mail: msh...@txbiomed.org<mailto:msh...@txbiomed.org>
>
> > On Aug 28, 2016, at 11:53 PM, Manohar Reddy 
> > mailto:manu.redd...@gmail.com>> wrote:
> >
> > Hi,
> >
> >
> >
> >   Can anyone guide me how to connect the Microsoft Sql server 2012/14 from
> > R studio using freeTDS package instead of RODBC ,I can able to connect the
> > MS Sql server from R studio using RODBC.
> >
> >  Actually my requirement is I have developed webpage/report using Shiny
> > package then I was deployed it on Shinyapps.io<http://shinyapps.io> ,but 
> > after deploying I�m
> > encountering error like ��ERROR: *first argument is not an open RODBC
> > channel*� ,based on this error message I di

Re: [R] 0 rows> (or 0-length row.names)

2016-08-30 Thread Mark Sharp
What do you get from
str(SFDC$case_age)

Mark

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Aug 30, 2016, at 11:24 AM, Shivi Bhatia  wrote:
>
> I know this question has been asked zillion times but even after consulting
> Stack Overflow & other forum cant figure out the reason.
>
> I have one var in my data-set names case age. This variable is numeric as:
>
> class(SFDC$case_age)
>
> *numeric*
>
> however it throws this error:
>
> <0 rows> (or 0-length row.names)
> As checked this only happens either there is some space at the end of the
> variable name, or there are no values whereas this is a numeric variable
> with no missing values and has a total of 5400 observations.
>
> This var has a range from 0 to 240 in number of days for case variable
> hence i need to do a logarithm transformation & make it use in the model.
> Total unique obs are around 1500.
>
> Please advice.
>
> [[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.

CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:10}}

__
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] 0 rows> (or 0-length row.names)

2016-08-30 Thread Mark Sharp
Shivi,

Can you show the code that throws the error?
<0 rows> (or 0-length row.names)

Of course as always a reproducible sample would be great. Perhaps you can make 
a small subset of the data and use dput() to provide a defined object.

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org

> On Aug 30, 2016, at 11:38 AM, Shivi Bhatia  wrote:
>
> Hi Mark,
>
> It gives me num [1:5083]. I have used head also to see first 10 obs:
>
> head(SFDC$case_age,10)
>  [1] 24.84  0.05 13.38  0.15 11.11  4.16  8.13  0.07  3.61  0.00
>
> Thanks.
>
> On Tue, Aug 30, 2016 at 10:05 PM, Mark Sharp  wrote:
> What do you get from
> str(SFDC$case_age)
>
> Mark
>
> R. Mark Sharp, Ph.D.
> Director of Primate Records Database
> Southwest National Primate Research Center
> Texas Biomedical Research Institute
> P.O. Box 760549
> San Antonio, TX 78245-0549
> Telephone: (210)258-9476
> e-mail: msh...@txbiomed.org
>
>
>
>
>
>
>
> > On Aug 30, 2016, at 11:24 AM, Shivi Bhatia  wrote:
> >
> > I know this question has been asked zillion times but even after consulting
> > Stack Overflow & other forum cant figure out the reason.
> >
> > I have one var in my data-set names case age. This variable is numeric as:
> >
> > class(SFDC$case_age)
> >
> > *numeric*
> >
> > however it throws this error:
> >
> > <0 rows> (or 0-length row.names)
> > As checked this only happens either there is some space at the end of the
> > variable name, or there are no values whereas this is a numeric variable
> > with no missing values and has a total of 5400 observations.
> >
> > This var has a range from 0 to 240 in number of days for case variable
> > hence i need to do a logarithm transformation & make it use in the model.
> > Total unique obs are around 1500.
> >
> > Please advice.
> >
> > [[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.
>
> CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
> transmitted, may contain privileged and confidential information and is 
> intended solely for the exclusive use of the individual or entity to whom it 
> is addressed. If you are not the intended recipient, you are hereby notified 
> that any review, dissemination, distribution or copying of this e-mail and/or 
> attachments is strictly prohibited. If you have received this e-mail in 
> error, please immediately notify the sender stating that this transmission 
> was misdirected; return the e-mail to sender; destroy all paper copies and 
> delete all electronic copies from your system without disclosing its contents.
>




CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:10}}

__
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] 0 rows> (or 0-length row.names)

2016-08-30 Thread Mark Sharp
Shivi,

It is likely that William knows what you are trying to do because of his 
considerable experience, but I am not able to figure it out from what you have 
written. You have apparently sent the output from something like 
dput(SFDC[1:50, ]), but I still do not know what you did to get the error.

I successfully assigned the structure you sent to the name SFDC and nothing 
seems amiss.


Mark

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Aug 30, 2016, at 12:32 PM, Shivi Bhatia  wrote:
>
> Hi William/ Mark,
>
> I am using WOE & IV (weight of evidence) reduce the number of independent
> vars.
> I have read this data as a csv file.
> reproducible example for your reference please:
>
> structure(list(date = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 14L,
> 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
>
... truncated
> __
> 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.

CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:10}}

__
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] 0 rows> (or 0-length row.names)

2016-08-30 Thread Mark Sharp
Shivi,

What package(s) are you using. What functions are you using. How are you 
calling the functions. A reproducible sample has all of the actual code needed 
to create a representative error. There are multiple packages you could be 
using to look at weight of evidence and information value. For example, there 
is a WOE function in the Information package and a woe function in the woe 
package.

Mark
On Aug 30, 2016, at 2:15 PM, Shivi Bhatia 
mailto:shivipm...@gmail.com>> wrote:

Hi Mark,
What i understand, probably when i run the WOE & IV to check significant 
variables that is where i get this error. Thanks for your assistance Mark 
really appreciate i will look into some other measure on this.

On Wed, Aug 31, 2016 at 12:35 AM, Mark Sharp 
mailto:msh...@txbiomed.org>> wrote:
Shivi,

It is likely that William knows what you are trying to do because of his 
considerable experience, but I am not able to figure it out from what you have 
written. You have apparently sent the output from something like 
dput(SFDC[1:50, ]), but I still do not know what you did to get the error.

I successfully assigned the structure you sent to the name SFDC and nothing 
seems amiss.


Mark

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org<mailto:msh...@txbiomed.org>







> On Aug 30, 2016, at 12:32 PM, Shivi Bhatia 
> mailto:shivipm...@gmail.com>> wrote:
>
> Hi William/ Mark,
>
> I am using WOE & IV (weight of evidence) reduce the number of independent
> vars.
> I have read this data as a csv file.
> reproducible example for your reference please:
>
> structure(list(date = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 14L,
> 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
>
... truncated
> __
> R-help@r-project.org<mailto: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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.

CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:23}}

__
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] 0 rows> (or 0-length row.names)

2016-08-31 Thread Mark Sharp
Shivi,

Looking at the help from ?WOE, ?WOETable, and ?IV, your Y vector in all cases 
is to be categorical and it is numeric.

Mark


R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org


On Aug 31, 2016, at 5:37 AM, Shivi Bhatia  wrote:
>
> These are the packages i am using:
> library(woe)  #WEIGHT OF EVIDENCE
> library(InformationValue)  #INFORMATION VALUE
>
> The syntax used is :
> WOE(X=SFDC1$log_caseage, Y=SFDC1$survey)
> WOETable(X=SFDC1$case_age, Y=SFDC1$survey)
> IV(X=SFDC1$case_age, Y=SFDC1$survey)
>
> On Wed, Aug 31, 2016 at 12:54 AM, Mark Sharp  wrote:
> Shivi,
>
> What package(s) are you using. What functions are you using. How are you 
> calling the functions. A reproducible sample has all of the actual code 
> needed to create a representative error. There are multiple packages you 
> could be using to look at weight of evidence and information value. For 
> example, there is a WOE function in the Information package and a woe 
> function in the woe package.
>
> Mark
>
>> On Aug 30, 2016, at 2:15 PM, Shivi Bhatia  wrote:
>>
>> Hi Mark,
>> What i understand, probably when i run the WOE & IV to check significant 
>> variables that is where i get this error. Thanks for your assistance Mark 
>> really appreciate i will look into some other measure on this.
>>
>> On Wed, Aug 31, 2016 at 12:35 AM, Mark Sharp  wrote:
>> Shivi,
>>
>> It is likely that William knows what you are trying to do because of his 
>> considerable experience, but I am not able to figure it out from what you 
>> have written. You have apparently sent the output from something like 
>> dput(SFDC[1:50, ]), but I still do not know what you did to get the error.
>>
>> I successfully assigned the structure you sent to the name SFDC and nothing 
>> seems amiss.
>>
>>
>> Mark
>>
>> R. Mark Sharp, Ph.D.
>> Director of Primate Records Database
>> Southwest National Primate Research Center
>> Texas Biomedical Research Institute
>> P.O. Box 760549
>> San Antonio, TX 78245-0549
>> Telephone: (210)258-9476
>> e-mail: msh...@txbiomed.org
>>
>>
>>
>>
>>
>>
>>
>> > On Aug 30, 2016, at 12:32 PM, Shivi Bhatia  wrote:
>> >
>> > Hi William/ Mark,
>> >
>> > I am using WOE & IV (weight of evidence) reduce the number of independent
>> > vars.
>> > I have read this data as a csv file.
>> > reproducible example for your reference please:
>> >
>> > structure(list(date = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 14L,
>> > 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
>> >
>> ... truncated
>> > __
>> > 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.
>>
>> CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
>> transmitted, may contain privileged and confidential information and is 
>> intended solely for the exclusive use of the individual or entity to whom it 
>> is addressed. If you are not the intended recipient, you are hereby notified 
>> that any review, dissemination, distribution or copying of this e-mail 
>> and/or attachments is strictly prohibited. If you have received this e-mail 
>> in error, please immediately notify the sender stating that this 
>> transmission was misdirected; return the e-mail to sender; destroy all paper 
>> copies and delete all electronic copies from your system without disclosing 
>> its contents.
>
> CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
> transmitted, may contain privileged and confidential information and is 
> intended solely for the exclusive use of the individual or entity to whom it 
> is addressed. If you are not the intended recipient, you are hereby notified 
> that any review, dissemination, distribution or copying of this e-mail and/or 
> attachments is strictly prohibited. If you have received this e-mail in 
> error, please immediately notify the sender stating that this transmission 
> was misdirected; return the e-mail to sender; destroy all paper copies and 
> delete all electronic copies from your system without disclosing its contents.
>

CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:10}}

__
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 a code in R

2016-09-05 Thread Mark Sharp
Erika,

You have failed to supply reproducible code. I do not all that is missing, but 
a glance shows that you did not include the code to load the foreach package or 
a definition of the objects named comb and b.

It is very likely you will receive assistance if you can follow the posting 
guide http://www.R-project.org/posting-guide.html


Mark

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Sep 5, 2016, at 1:25 PM, Erika Rocío Espinosa Balbuena 
>  wrote:
>
> Hi,
>
> I am working with this code:
>
> forecast_nal<-data.frame()
> out<-vector()
> x<-foreach(i=1:nrow(comb)) %do%
> {
>
> s<-comb[i,'prod_id']
>
> #Familia+Sumbarca+prod_id
> #Serie
>
> bcomb1<-b
> bcomb1<-subset(bcomb1,bcomb1$prod_id == s & bcomb1$year <= 2015)
> bcomb1<-arrange(bcomb1,year,week)
> a<-bcomb1[1:1,'week']
> d<-bcomb1[1:1,'year']
> f<-nrow(bcomb1)
> h<-bcomb1[f:f,'year']
> j<-bcomb1[f:f,'week']
> bcomb1<-bcomb1[,c(6)]
>
> if (length(bcomb1)<=10 || h=="2014" || (h=="2015" && j<=48))
> {
> out[i]<-s
> }
> else
> {
>   y <- ts(bcomb1, frequency=52, start=c(d, a))
> ##Casos
>
> if (length(y)<=60)
> {
>
> v<-auto.arima(y)
> v<-arimaorder(v)
> fit <- arima(y, order = v ,method="ML")
>  fca <- forecast(fit, h = 16)
> dates <- attr(forecast_nal$mean, "tsp")
> datecol <- seq(from=dates[1], to=dates[2], by=1/dates[3])
> fct<-cbind.data.frame(s,datecol,Point=fca$mean)
> forecast_nal<- rbind.data.frame(forecast_nal,fct)
> }
> else
> {
>
> fit <- tbats(y)
> fcb <- forecast(fit, h = 16)
> dates <- attr(forecast_nal$mean, "tsp")
> datecol <- seq(from=dates[1], to=dates[2], by=1/dates[3])
> fct<-cbind.data.frame(s,datecol,Point=fcb$mean)
>forecast_nal<- rbind.data.frame(forecast_nal,fct)
> }
> }
> }
> But I am getting this error:
>
> Error in `[<-.ts`(`*tmp*`, ri, value = c(26656.136365833, 26750.9374514082,
> :
>  only replacement of elements is allowed
>
> Can someone help me with this?
>
> Thanks
>
>
> --
> Erika Rocío Espinosa Balbuena
>
> [[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.


CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
transmitted, may contain privileged and confidential information and is 
intended solely for the exclusive use of the individual or entity to whom it is 
addressed. If you are not the intended recipient, you are hereby notified that 
any review, dissemination, distribution or copying of this e-mail and/or 
attachments is strictly prohibited. If you have received this e-mail in error, 
please immediately notify the sender stating that this transmission was 
misdirected; return the e-mail to sender; destroy all paper copies and delete 
all electronic copies from your system without disclosing its contents.
__
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 a code in R

2016-09-07 Thread Mark Sharp
Erika,

The code you sent is missing some matching braces. For example, see this pair 
of lines:

forecast_nal <- rbind.data.frame(forecast_nal, fct)
}

I do not see a left brace anywhere before this right brace.



Without the content of the data structures datos, calendar and espejo from the 
three files, we will not be able to reproduce your code. Often you can use only 
a small subset of the data and reproduce a problem, but only you will be able 
to find out how much of the data are sufficient to reproduce the problem.

You could start by trying to produce the problem with a minimum amount of data. 
Try something along these lines:

datos <- read.csv("C:/Users/ErikaRocío/Documents/Curso
  R/FCST_YEAR_WEEK_PROD_NAC.csv")
b <- data.frame(datos)[1:10, ]

calendar <-
  read.csv("C:/Users/ErikaRocío/Documents/Curso R/cat_sem.csv")
forecast_date <- calendar[1:10, c(8, 9, 14, 10)]

espejo <-
  read.csv("C:/Users/ErikaRocío/Documents/Curso R/cat_prod.csv")[1:10, ]

Then use these short versions of the dataframes in the rest of your code and 
see if you get the same error. You will likely have to play with the number of 
rows in each dataframe to fine the smallest number that will work. When you 
discover the smallest dataframes that recreate the error, you can send us the 
output from dput() as shown below:


datos <- read.csv("C:/Users/ErikaRocío/Documents/Curso
  R/FCST_YEAR_WEEK_PROD_NAC.csv")
b <- data.frame(datos)
dput(b[1:10, ])

calendar <-
  read.csv("C:/Users/ErikaRocío/Documents/Curso R/cat_sem.csv")
forecast_date <- calendar[, c(8, 9, 14, 10)]
dput(forecast_date[1:10, ])

espejo <-
  read.csv("C:/Users/ErikaRocío/Documents/Curso R/cat_prod.csv")
dput(espejo[1:10, ])






R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Sep 7, 2016, at 9:45 AM, Erika Rocío Espinosa Balbuena 
>  wrote:
>
> Hi,
>
> Sorry, how can I review on line, but here is the complete code:
>
>
> ##Librerias
> library(stats)
> library(base)
> library(dplyr)
> library(timeDate)
> library(zoo)
> library(forecast)
> #library(parallel)
> library(foreach)
> library(iterators)
> #library(doParallel)
> #library(snow)
> #library(doSNOW)
> library(reshape2)
> library(pryr)
> #library(rpivotTable)
>
>
> #numCores <- detectCores()
> #cl <- makeCluster(numCores)
>
>
>
> ###NACIONAL###
> #setwd("C:/RealMetrics/02_Aplicaciones/RM_SCM_DRM/RTools/Erika_Test")
>
> #write.csv(out, file="C:/Users/ErikaRocío/Documents/Curso R/nuevos.csv")
> #rpivotTable(forecast_nal,rows="Familia","Submarca","prod_id",col="s",
> aggregatorName="sum",vals="Point.Forecast")
>
> ##Lectura de datos
> #datos<-read.csv("FCST_YEAR_WEEK_PROD_NAC.csv")
> datos<-read.csv("C:/Users/ErikaRocío/Documents/Curso
> R/FCST_YEAR_WEEK_PROD_NAC.csv")
> b<-data.frame(datos)
>
> calendar<-read.csv("C:/Users/ErikaRocío/Documents/Curso R/cat_sem.csv")
> forecast_date<-calendar[,c(8,9,14,10)]
>
> espejo<-read.csv("C:/Users/ErikaRocío/Documents/Curso R/cat_prod.csv")
>
> ##Subbases
> #Combinaciones
> comb<-b[,c(3,4,5)]
> comb<-comb %>% distinct
> g<-seq(1,nrow(comb),by=1)
> dates <- attr(fca$mean, "tsp")
> datecol <- seq(from=dates[1], to=dates[2], by=1/dates[3])
> fct<-cbind.data.frame(s,datecol,Point=fca$mean)
> forecast_nal<- rbind.data.frame(forecast_nal,fct)
> }
> else
> {
>
> fit <- tbats(y)
> fcb <- forecast(fit, h = 16)
> dates <- attr(fcb$mean, "tsp")
> datecol <- seq(from=dates[1], to=dates[2], by=1/dates[3])
> fct<-cbind.data.frame(s,datecol,Point=fcb$mean)
>forecast_nal<- rbind.data.frame(forecast_nal,fct)
> }
> }
> }
>
>
> 2016-09-07 9:00 GMT-05:00 PIKAL Petr :
>
>> Hi
>>
>>
>>
>> see in line
>>
>>
>>
>> *From:* Erika Rocío Espinosa Balbuena [mailto:erika...@gmail.com]
>> *Sent:* Tuesday, September 6, 2016 10:52 PM
>> *To:* PIKAL Petr 
>> *Cc:* r-help@r-project.org
>> *Subject:* Re: [R] Help with a code in R
>>
>>
>>
>> Hi Erika
>>
>>
>>
>> Yes the objetcs have the same structure, and forecast_nal is the variable
>> where I a trying to keep all the results of the forecast but I get the
>> error that it
>>
>>
>>
>> How did you check? Can you prove it?
>>
>&

Re: [R] Have help list filters changed recently

2016-09-09 Thread Mark Leeds
Hi Bert: I saw that and let it through. I am not the one to ask but as far
as I know,
the filtering has not changed.


On Thu, Sep 8, 2016 at 8:35 PM, Bert Gunter  wrote:

> To all:
>
> r-help has been holding up a lot of my recent messages: Have there
> been any changes to help list filters that caused this? Is there
> something I'm doing wrong? -- I have made no changes  that I am aware
> of. Here's what I get:
>
> Your mail to 'R-help' with the subject
>
> Re: [R] with and evaluation [for example]
>
> Is being held until the list moderator can review it for approval.
>
> The reason it is being held:
>
> The message headers matched a filter rule
>
>
> Best,
> Bert
>
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
> __
> 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] Drill down reports in R

2016-09-13 Thread Mark Sharp
Manu,

With pure R, you can simply write a link in the parent document to a child 
document you have created. Alternative, and likely better, solutions could be 
based on AJAX, but I do not think you are going to do that all within R.

Mark
> On Sep 13, 2016, at 11:11 AM, Manohar Reddy  wrote:
>
> Hi Jhon,
>
>
>
> Thanks for responding my email ,actually my requirement is I have Orders
> and related tables and now I need to generate a report something looks like
> below whenever user click on “+” that report will be expanded .I know it is
> possible in SSRS (SQl Server Reporting Services) but now my requirement is
> I need to generate that kind of report in R.
>
>
>
> If we look at screen shot (or PFA) almost 100244 order exists  8 times
> ,now I want to generate the report whenever user clicks on order 100244 and
> it needs to be expand and need to display the cost of all the products and
> what are the products they were purchased on this orderID .
>
>
>
> Note: in backend I did using Group by (sql) but I don’t know how to present
> in this report.
>
>
>
>
>
> Hi Marc,
>
>
>
>   Thanks,Currently I’m creating reports  using shinyapps only ,I have
> checked out throghly with shinyapps but I didn’t find any solution,is there
> any alternative way that I can use to genarate the drill down report.
>
>
>
> Manu.
>
> On Tue, Sep 13, 2016 at 8:33 PM, Marc Schwartz  wrote:
>
>> Hi,
>>
>> Generally "drilldown" reports require a dynamic GUI that supports widgets
>> that generate the data queries behind the scenes in response to user
>> input/clicks and then updated the display dynamically with the additional
>> data/content.
>>
>> This would be more typical of business oriented reporting/OLAP tools like
>> Cognos, Business Objects, Crystal Reports, etc.
>>
>> The first thing that came to mind is RStudio's Shiny, which I do not use,
>> but their gallery seems to have some possibilities:
>>
>>  http://shiny.rstudio.com/gallery/
>>
>> Regards,
>>
>> Marc Schwartz
>>
>>
>>> On Sep 13, 2016, at 9:48 AM, John Kane  wrote:
>>>
>>> It is not really clear what you want but have a look at ?subset perhaps.
>>>
>>> John Kane
>>> Kingston ON Canada
>>>
>>>
>>>> -Original Message-
>>>> From: manu.redd...@gmail.com
>>>> Sent: Tue, 13 Sep 2016 16:16:05 +0530
>>>> To: r-help@r-project.org
>>>> Subject: [R] Drill down reports in R
>>>>
>>>> Hi,
>>>>
>>>>
>>>>
>>>> How to generate “Drill down reports ”  (like please refer below url) in
>>>> R
>>>> using any package ? I did lot of research in google but I didn’t found
>>>> suitable link .
>>>>
>>>> Can anyone help how to do that in R ?
>>>>
>>>>
>>>>
>>>> url :  http://bhushan.extreme-advice.com/drilldown-report-in-ssrs/
>>>>
>>>>
>>>>
>>>> Thanks in Advance !
>>>>
>>>> Manu.
>>
>>
>
>
> --
>
>
> Thanks,
> Manohar Reddy P
> +91-9705302062.
> __
> 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.

CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
transmitted, may contain privileged and confidential information and is 
intended solely for the exclusive use of the individual or entity to whom it is 
addressed. If you are not the intended recipient, you are hereby notified that 
any review, dissemination, distribution or copying of this e-mail and/or 
attachments is strictly prohibited. If you have received this e-mail in error, 
please immediately notify the sender stating that this transmission was 
misdirected; return the e-mail to sender; destroy all paper copies and delete 
all electronic copies from your system without disclosing its contents.
__
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] Closed list?

2016-09-29 Thread Mark Sharp
Its not closed. Have you read the posting guide?

Mark

R. Mark Sharp, Ph.D.
msh...@txbiomed.org<mailto:msh...@txbiomed.org>





On Sep 29, 2016, at 1:38 PM, Joysn71 
mailto:joys...@gmail.com>> wrote:

Hello,

a few weeks ago i subscribed to this list and afterwards i send a question. I 
got a reply that my post needs moderator approval. It never happened.
Then i wrote to the list owners address. No reply.

How can i proceed?

Thanks in advance,
Joysn

__
R-help@r-project.org<mailto: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.

CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:13}}

__
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] Closed list?

2016-09-29 Thread Mark Leeds
someone who moderates the list, myself included, may have mistakened it for
spam and rejected it. In that case, it never got to the list.



On Thu, Sep 29, 2016 at 4:53 PM, Duncan Murdoch 
wrote:

> On 29/09/2016 2:38 PM, Joysn71 wrote:
>
>> Hello,
>>
>> a few weeks ago i subscribed to this list and afterwards i send a
>> question. I got a reply that my post needs moderator approval. It never
>> happened.
>> Then i wrote to the list owners address. No reply.
>>
>> How can i proceed?
>>
>
> I see a post from you with subject "[R] Architect from Open Analytics" on
> Sept 10.  No responses to it; I guess nobody else uses that package.
>
> 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/posti
> ng-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] Closed list?

2016-09-29 Thread Mark Leeds
my bad david. thanks for info.

On Fri, Sep 30, 2016 at 12:37 AM, David Winsemius 
wrote:

>
> > On Sep 29, 2016, at 8:57 PM, Mark Leeds  wrote:
> >
> > someone who moderates the list, myself included, may have mistakened it
> for
> > spam and rejected it. In that case, it never got to the list.
> >
>
> I think the post was accepted and the poster just doesn't realize it:
>
> https://stat.ethz.ch/pipermail/r-help/2016-September/441702.html
>
> (I think I was the one who approved it two weeks+ ago.)
>
> --
> David.
> >
> >
> > On Thu, Sep 29, 2016 at 4:53 PM, Duncan Murdoch <
> murdoch.dun...@gmail.com>
> > wrote:
> >
> >> On 29/09/2016 2:38 PM, Joysn71 wrote:
> >>
> >>> Hello,
> >>>
> >>> a few weeks ago i subscribed to this list and afterwards i send a
> >>> question. I got a reply that my post needs moderator approval. It never
> >>> happened.
> >>> Then i wrote to the list owners address. No reply.
> >>>
> >>> How can i proceed?
> >>>
> >>
> >> I see a post from you with subject "[R] Architect from Open Analytics"
> on
> >> Sept 10.  No responses to it; I guess nobody else uses that package.
> >>
> >> 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/posti
> >> ng-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.
>
> David Winsemius
> Alameda, CA, USA
>
>

[[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] Predictions on training set shorter than training set

2015-04-23 Thread Mark Drummond
Hi all,

Given a simple logistic regression on a training data set using glm,
the number of predicted values is less than the number of observations
in the training set:

> fit.train.pred <- predict(fit, type = "response")
> nrow(train)
[1] 62660
> length(fit.train.pred)
[1] 58152
>

As a relative newcomer, I've run lots of simple glm, CART etc. models
but this is the first time I have seen this happen.

Is this a common issue and is there a fix? An option to predict() perhaps?

-- 
Cheers, Mark

Mark Drummond
m...@markdrummond.ca

When I get sad, I stop being sad and be Awesome instead. TRUE STORY.

__
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] knittr: non-numeric argument to binary operator

2015-04-26 Thread Mark Drummond
knittr is giving me the above error. The code it is failing on is
multiplying two numeric features of a data frame. I can run the code
by hand and it works fine, but when I try to knit my document, knittr
chokes on the same line.

When kitting:

Quitting from lines 161-175 (RepData_PeerAssessment2.Rmd)
Error in storm_data$PROPDMG * storm_data$property_damage_cost_factor :
  non-numeric argument to binary operator
Calls:  ... handle -> withCallingHandlers -> withVisible ->
eval -> eval
Execution halted

Running the same lines manually (CTRL+Enter) from the .Rmd file:

> storm_data$total_damage <-
+ (storm_data$PROPDMG * storm_data$property_damage_cost_factor) +
+ (storm_data$CROPDMG * storm_data$crop_damage_cost_factor)
> str(storm_data$total_damage)
 num [1:902297] 25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ...
>

Call me baffled. Any pointers are greatly appreciated at this point.

-- 
Cheers, Mark

Mark Drummond
m...@markdrummond.ca

When I get sad, I stop being sad and be Awesome instead. TRUE STORY.

__
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] knittr: non-numeric argument to binary operator

2015-04-26 Thread Mark Drummond
Thanks all for the responses. As Murphy would have it, after posting
my query I found the problem. I had a function defined that did some
value mapping and I had a stray line of code in the function. Actually
a legitimate line of code that was just in the wrong place.

Cheers,
Mark


On Sun, Apr 26, 2015 at 5:39 PM, Jeff Newmiller
 wrote:
> Not reproducible [1], so any response likely to be a guess. However, you 
> likely have not put everything that is in your interactive environment into 
> the knitr document, so you are not working with the same data in those two 
> environments.
>
> [1] 
> http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
> ---
> 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 April 26, 2015 1:41:32 PM PDT, Mark Drummond  wrote:
>>knittr is giving me the above error. The code it is failing on is
>>multiplying two numeric features of a data frame. I can run the code
>>by hand and it works fine, but when I try to knit my document, knittr
>>chokes on the same line.
>>
>>When kitting:
>>
>>Quitting from lines 161-175 (RepData_PeerAssessment2.Rmd)
>>Error in storm_data$PROPDMG * storm_data$property_damage_cost_factor :
>>  non-numeric argument to binary operator
>>Calls:  ... handle -> withCallingHandlers -> withVisible ->
>>eval -> eval
>>Execution halted
>>
>>Running the same lines manually (CTRL+Enter) from the .Rmd file:
>>
>>> storm_data$total_damage <-
>>+ (storm_data$PROPDMG * storm_data$property_damage_cost_factor) +
>>+ (storm_data$CROPDMG * storm_data$crop_damage_cost_factor)
>>> str(storm_data$total_damage)
>> num [1:902297] 25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ...
>>>
>>
>>Call me baffled. Any pointers are greatly appreciated at this point.
>



-- 
Cheers, Mark

Mark Drummond
m...@markdrummond.ca

When I get sad, I stop being sad and be Awesome instead. TRUE STORY.

__
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 making Loop

2015-05-02 Thread Mark Sharp
Fazal,

I am not sure what you want, but I have guessed. I have tried to provide a 
straight forward simplistic solution.

If you examine the intermediate results, I think what is being done will be 
clear.

Mark

Michael Dewey’s suggestion to look at merge is excellent. You may also need to 
look at the other functions used below. All are commonly used.

# Code follows
set.seed(1) # ensures you get the same results
id <- paste0("id_", 1:10) # I did not want to copy down your Ids so I made them 
up.
small_dataframe <- data.frame(unique_sample_id = id, 
  g_1 = character(length(id)), 
  g_2 = character(length(id)))
# Making up some genotypes for g_1_table and g_2_table
g_1_table <- 
  data.frame(unique_sample_id = sample(id, length(id), replace = FALSE),
 cond = sample(c("M", "N/M"), length(id), replace = TRUE, 
prob = c(0.5, 0.5)))
g_2_table <- 
  data.frame(unique_sample_id = sample(id, length(id), replace = FALSE),
 cond = sample(c("M", "N/M"), length(id), replace = TRUE, 
prob = c(0.5, 0.5)))

new_dataframe <- merge(small_dataframe, g_1_table, by = "unique_sample_id")
names(new_dataframe) <- 
  c("unique_sample_id", "g_1", "g_2", "g_1_cond")
new_dataframe <- merge(new_dataframe, g_2_table, by = "unique_sample_id")
names(new_dataframe) <- 
  c("unique_sample_id", "g_1", "g_2", "g_1_cond", 
"g_2_cond")
new_dataframe$g_1_emoticon <- ifelse(new_dataframe$g_1_cond == "M",
":-)", "No")
new_dataframe$g_2_emoticon <- ifelse(new_dataframe$g_2_cond == "M",
":-)", "No")
new_dataframe

# End of code
# Output of last line of code.
   unique_sample_id g_1 g_2 g_1_cond g_2_cond g_1_emoticon g_2_emoticon
1  id_1M  N/M  :-)   No
2 id_10  N/M  N/M   No   No
3  id_2MM  :-)  :-)
4  id_3  N/MM   No  :-)
5  id_4  N/M  N/M   No   No
6  id_5M  N/M  :-)   No
7  id_6M  N/M  :-)   No
8  id_7  N/MM   No  :-)
9  id_8  N/MM   No  :-)
10 id_9MM  :-)  :-)


> On May 1, 2015, at 3:05 PM, Hadi Fazal  wrote:
> 
> Hi everyone, 
> I am a real beginner to R and have probably a very naive issue. I've a small 
> data frame with three columns: Unique Sample ID, Gene 1 and Gene 2 (the 
> columns on Gene1 and Gene2 are empty). I have two separate tables for the 
> genes which contain the Unique Subject ID in one column and information on 
> whether the gene is mutated or not in that particular subject (M, N/M) in 
> another column called (Condition). I want to make a loop which can read the 
> Unique Subject ID from my data frame, then look up for the same ID in the two 
> tables and depending on whether the gene is mutated (M)/not mutated (N/M), 
> inserts Yes like emoticon / No (N) in the appropriate gene column 
> (Gene1/Gene2) for each Subject ID.
> If anyone can help, I would really appreciate
> Thanks in advance
> 
> Fazal,
> __
> 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] best way to handle database connections from within a package

2015-05-29 Thread Mark Sharp
I would simply separate the database connect and disconnect functions from the 
query functions. 

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On May 28, 2015, at 12:18 PM, Luca Cerone  wrote:
> 
> Dear all,
> I am writing a package that is a collection of queries to be run
> against a postgresql database,
> so that the users do not have to worry about the structure of the database.
> 
> In my package I import dbDriver, dbUnloadDriver, dbConnect,
> dbDisconnect from the package DBI
> and dbGetQuery from the package RPostgreSQL.
> 
> All the function in a function in my package have the same structure:
> 
> getFancyData <- function( from, to) {
>on.exit( dbDisconnect(con), add=TRUE)
>on.exit( dbUnloadDriver(drv), add=TRUE)
>drv <- dbDriver("PostgreSQL")
>con <- dbConnect(drv,
> user=pkguser,
> host=pkghost,
> password=pkgpassword,
> port = pkgport)
> 
>query <- sprintf("select * from fancyTable where dt between '%s'
> and '%s'", from, to)
>res <- dbGetQuery(con,query)
>return(res)
> }
> 
> The various access details are read from an encrypted profile that the
> user has to
> create when she installs the package.
> 
> Such functions work perfectly fine, but I have to replicate a lot of
> times loading and unloading the driver and connecting and
> disconnecting from the database.
> 
> I am wondering if there is a better way to do this job, like loading
> the driver and opening the connection only once when the package is
> loaded. However I have to make sure that
> if R crashes or the code where the function is called contains an
> error then the connection
> with the database is closed. How would you implement this?
> 
> 
> Also how would you write a functional that would at least allow me to
> avoid replicating
> the boilerplate code to load and unload the drivers?
> 
> I am thinking something on the lines of:
> 
> querybuild <- function(query, )
>on.exit( dbDisconnect(con), add=TRUE)
>on.exit( dbUnloadDriver(drv), add=TRUE)
>query <- sprintf(query, ... )
>res <- dbSendQuery(query)
>return(res)
> }
> 
> and then define
> 
> getFancyData <- function(from, to) querybuild("select * from
> fancyTable where dt between '%s' and '%s'", from, to)
> 
> Do you see a better way?
> 
> Thanks a lot in advance for your help and advice on this!
> 
> Cheers,
> Luca
> 
> __
> 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] Toronto CRAN mirror 403 error?

2015-05-29 Thread Mark Drummond
I've been getting a 403 when I try pulling from the Toronto CRAN mirror
today.

http://cran.utstat.utoronto.ca/

Is there a contact list for mirror managers?

-- 
Cheers, Mark

*Mark Drummond*
m...@markdrummond.ca

When I get sad, I stop being sad and be Awesome instead. TRUE STORY.

[[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] Toronto CRAN mirror 403 error?

2015-05-30 Thread Mark Drummond
I am using another mirror. Just being a good net.citizen.

On Fri, May 29, 2015 at 11:03 PM, Jeff Newmiller 
wrote:

> This is why there are mirrors. You don't have to wait for them or tell
> them to do their jobs.
> ---
> 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 May 29, 2015 7:12:56 PM PDT, Mark Drummond 
> wrote:
> >I've been getting a 403 when I try pulling from the Toronto CRAN mirror
> >today.
> >
> >http://cran.utstat.utoronto.ca/
> >
> >Is there a contact list for mirror managers?
>
>


-- 
Cheers, Mark

*Mark Drummond*
m...@markdrummond.ca

When I get sad, I stop being sad and be Awesome instead. TRUE STORY.

[[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] Toronto CRAN mirror 403 error?

2015-05-30 Thread Mark Drummond
> It's possible that the mirror manager is unaware of this, and might like
> to be informed.  I know him, and will send an email.
>
> Duncan Murdoch

Thanks Duncan.


-- 
Cheers, Mark

__
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] source code for dbeta

2015-06-07 Thread Mark Sharp
Varun,

If you type dbeta at the command line you get the R source, which in this case 
tells you that the code is calling a compiled source. This is indicated by the 
line 

See the following. 
> dbeta
function (x, shape1, shape2, ncp = 0, log = FALSE) 
{
if (missing(ncp)) 
.Call(C_dbeta, x, shape1, shape2, log)
else .Call(C_dnbeta, x, shape1, shape2, ncp, log)
}



Compiled code in a package

If you want to view compiled code in a package, you will need to 
download/unpack the package source. The installed binaries are not sufficient. 
A package's source code is available from the same CRAN (or CRAN compatible) 
repository that the package was originally installed from. The 
download.packages() function can get the package source for you.

Extracted from 
http://stackoverflow.com/questions/19226816/how-can-i-view-the-source-code-for-a-function

Mark


R. Mark Sharp, Ph.D.
msh...@txbiomed.org


> On Jun 7, 2015, at 4:31 AM, Varun Sinha  wrote:
> 
> Hi,
> 
> I am trying to find the source code for dbeta function.
> 
> I tried edit(dbeta) and this is what I got:
>> edit(dbeta)
> function (x, shape1, shape2, ncp = 0, log = FALSE)
> {
>if (missing(ncp))
>.Call(C_dbeta, x, shape1, shape2, log)
>else .Call(C_dnbeta, x, shape1, shape2, ncp, log)
> }
> 
> 
> It looks like it is calling calling C_dbeta, but I'm not sure. If it does,
> how do I find it's source code?
> 
> Thank you!
> Varun
> 
>   [[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] source code for dbeta

2015-06-07 Thread Mark Sharp
Varun,

I apologize. I hit send before completing.

Look at the source document in the link I provided. dbeta is part of the stats 
package, which is part of the core R system and I do not think it is available 
as a standalone package. The linked document provides instructions for finding 
base R compiled code.

Mark

R. Mark Sharp, Ph.D.
msh...@txbiomed.org
> On Jun 7, 2015, at 5:11 PM, Mark Sharp  wrote:
> 
> Varun,
> 
> If you type dbeta at the command line you get the R source, which in this 
> case tells you that the code is calling a compiled source. This is indicated 
> by the line 
> 
> See the following. 
>> dbeta
> function (x, shape1, shape2, ncp = 0, log = FALSE) 
> {
>if (missing(ncp)) 
>.Call(C_dbeta, x, shape1, shape2, log)
>else .Call(C_dnbeta, x, shape1, shape2, ncp, log)
> }
> 
> 
> 
> Compiled code in a package
> 
> If you want to view compiled code in a package, you will need to 
> download/unpack the package source. The installed binaries are not 
> sufficient. A package's source code is available from the same CRAN (or CRAN 
> compatible) repository that the package was originally installed from. The 
> download.packages() function can get the package source for you.
> 
> Extracted from 
> http://stackoverflow.com/questions/19226816/how-can-i-view-the-source-code-for-a-function
> 
> Mark
> 
> 
> R. Mark Sharp, Ph.D.
> msh...@txbiomed.org
> 
> 
>> On Jun 7, 2015, at 4:31 AM, Varun Sinha  wrote:
>> 
>> Hi,
>> 
>> I am trying to find the source code for dbeta function.
>> 
>> I tried edit(dbeta) and this is what I got:
>>> edit(dbeta)
>> function (x, shape1, shape2, ncp = 0, log = FALSE)
>> {
>>   if (missing(ncp))
>>   .Call(C_dbeta, x, shape1, shape2, log)
>>   else .Call(C_dnbeta, x, shape1, shape2, ncp, log)
>> }
>> 
>> 
>> It looks like it is calling calling C_dbeta, but I'm not sure. If it does,
>> how do I find it's source code?
>> 
>> Thank you!
>> Varun
>> 
>>  [[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-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] problems editing R console

2015-06-07 Thread Mark Sharp
Rosa,

See save() and load() functions for background. However, I suspect you will 
want to do something as described in the article in this link 
http://www.fromthebottomoftheheap.net/2012/04/01/saving-and-loading-r-objects/


Mark



R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org



> On Jun 7, 2015, at 5:58 PM, Rosa Oliveira  wrote:
> 
> Dear Mark,
> 
> 
> I’ll try to explain better.
> 
> Imagine I write:
> 
> library(foreign)
> library(nlme)
> 
> set.seed(1000)
> n.sample<-1 #sample size
> M <- 5
> DP_x <- 2
> x <- rnorm(n.sample,M,DP_x)
> p <- pnorm(-3+x)  
> y <- rbinom(n.sample,1,p)
> dp_erro <- 0.01
> erro <- rnorm(n.sample,0,dp_erro)
> x.erro <- x+erro
> 
> but with a function, with 2000 simulations. 
> I save my “output” and I get X.erro in a .txt file. (text edit file).
> 
> I do another setting with DP_x=3 and save, and so on.
> 
> For some reason I realize I’ve done my simulation the wrong way and I have to 
> apply a correction, for example:
> 
> x.erro = 1.4X+erro, i.e. in the truth I could use my first X and erro values 
> in each setting, but as it is in a .txt file I can’t use them any more. Is 
> there a way to save the results in a  format that I can use the values? Just 
> apply my corrections and don’t have to do the 2000 simulations for each 
> setting again?
> 
> My problem is that the function I use takes 3 days running, and just 500 
> simulations :(
> 
> Best,
> RO
> 
> 
> Atenciosamente,
> Rosa Oliveira
> 
> -- 
> 
>  
> 
> Rosa Celeste dos Santos Oliveira, 
> 
> E-mail: rosit...@gmail.com
> Tlm: +351 939355143 
> Linkedin: https://pt.linkedin.com/in/rosacsoliveira
> ____
> "Many admire, few know"
> Hippocrates
> 
>> On 07 Jun 2015, at 23:03, Mark Sharp  wrote:
>> 
>> I cannot understand your request as stated. Can you provide a small example?
>> 
>> Mark
>> 
>> R. Mark Sharp, Ph.D.
>> msh...@txbiomed.org
>> 
>>> On Jun 7, 2015, at 2:49 PM, Rosa Oliveira  wrote:
>>> 
>>> Dear all,
>>> 
>>> I’m doing simulations on R, and as my code is being changed and improved I 
>>> need to, sometimes, work in finished simulations, i.e, 
>>> 
>>> After my simulation is  over I need to settle another setting.
>>> The problem is that I need to get back to the previous result.
>>> 
>>> When I save the result it saves as txt, so I can’t edit that result any 
>>> more.
>>> 
>>> Imagine I save a setting and save the mean, nonetheless, in another setting 
>>> the mean as problems, so I have to ask the median.
>>> 
>>> As I have to have the same statistics to all settings, nowadays I have to 
>>> run my first setting again.
>>> 
>>> My advisor told me that I could save another way so I can “edit” my first 
>>> result. Is it possible?
>>> 
>>> I tried to save as "save my workplace", … but after I don’t know what to do 
>>> with it.
>>> 
>>> Can you please help me?
>>> I know is a naive question, but I have to go through this every 3 days 
>>> (time each simulation takes long). And my work is being delayed :(
>>> 
>>> 
>>> Best,
>>> RO
>>> 
>>> 
>>> 
>>> Atenciosamente,
>>> Rosa Oliveira
>>> 
>>> -- 
>>> 
>>> 
>>> 
>>> Rosa Celeste dos Santos Oliveira, 
>>> 
>>> E-mail: rosit...@gmail.com
>>> Tlm: +351 939355143 
>>> Linkedin: https://pt.linkedin.com/in/rosacsoliveira
>>> 
>>> "Many admire, few know"
>>> Hippocrates
>>> 
>>> __
>>> 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] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline

2015-06-08 Thread Mark Sharp
John,

I like using stringr or stringi for this type of thing. stringi is written in C 
and faster so I now typically use it. You can also use base functions. The main 
trick is the handy names() function.

> example <- data.frame("Col 1 A" = 1:3, "Col 1 B" = letters[1:3])
> example
  Col.1.A Col.1.B
1   1   a
2   2   b
3   3   c
> library(stringi)
> names(example) <- stri_replace_all_fixed(names(example), ".", "_")
> example
  Col_1_A Col_1_B
1   1   a
2   2   b
3   3   c

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Jun 8, 2015, at 9:15 AM, John Sorkin  wrote:
> 
> I am reading a csv file. The column headers have spaces in them. The spaces 
> are replaced by a period. I want to replace the space by another character 
> (e.g. the underline) rather than the period. Can someone tell me how to 
> accomplish this?Thank you,
> John
> 
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and 
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing) 
> 
> 
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:12}}

__
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] create a dummy variables for companies with complete history.

2015-06-24 Thread Mark Sharp
Giacomo,

Please include some representative data. It is not clear why your offset of 4 
(z$cod[i - 4]) is going to be an accurate surrogate for complete data.

Since I do not have your data set or its true structure I am having to guess.
# make 5 copies of 200 companies
companies <- paste0(rep(LETTERS[1:4], 5, each = 50), rep(1:50, 5))
companies <- companies[order(companies)]
years <- rep(1:5, 200)
z <- data.frame(cod = companies, year = years,
revenue = round(rnorm(1000, mean = 10, sd = 1)))
# trim this down to the 728 rows you have by pulling out records at random
set.seed(1) # so that you can repeat these results
z <- z[sample.int(1000, 728), ]
z <- z[order(z$cod, z$year), ]

#No matter how you order these data, your offset approach will not tell you 
which companies have full records.
> head(z, 10)
   cod year revenue
1   A11  112192
2   A12  105840
4   A14  112357
5   A15   91772
7  A102  102601
8  A103  105183
11 A111  101269
12 A112  100719
14 A114   86138
15 A115  105044

#You can do something like the following.

counts <- table(z$cod)
complete <- names(counts[as.integer(counts) == 5])
# It is probably better to keep the dummy variable inside the dataframe.
z$complete <- ifelse(z$cod %in% complete, TRUE, FALSE)

> head(z, 20)
   cod year revenue complete
1   A11  112192FALSE
2   A12  105840FALSE
4   A14  112357FALSE
5   A15   91772FALSE
7  A102  102601FALSE
8  A103  105183FALSE
11 A111  101269FALSE
12 A112  100719FALSE
14 A114   86138FALSE
15 A115  105044FALSE
20 A125   95872FALSE
21 A131   78513 TRUE
22 A132   90502 TRUE
23 A133  108683 TRUE
24 A134  110711 TRUE
25 A135   87842 TRUE
28 A143   99939FALSE
30 A145  111289FALSE
31 A151  100930FALSE
32 A152   93765FALSE
> 
Do not use HTML. Use plain text. The character string "//" is not a comment 
indicator in R. Do not use attach(). It does not do anything in your example, 
but it is poor practice. Always write out TRUE and FALSE
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jun 24, 2015, at 1:26 PM, giacomo begnis  wrote:
> 
> Hi, I have a dataset  (728 obs) containing three variables code of a company, 
> year and revenue. Some companies have a complete history of 5 years, others 
> have not a complete history (for instance observations for three or four 
> years).I would like to determine the companies with a complete history using 
> a dummy variables.I have written the following program but there is somehting 
> wrong because the dummy variable that I have create is always equal to 
> zero.Can somebody help me?Thanks, gm
> 
> z<-read.table(file="c:/Rp/cddat.txt", sep="", header=T)
> attach(z)
> n<-length(z$cod)  // number of obs dataset
> 
> d1<-numeric(n)   // dummy variable
> 
> for (i in 5:n)  {
>if (z$cod[i]==z$cod[i-4]) // cod is the code of a company  
>{ d1[i]<=1} else { d1[i]<=0}  // d1=1 for a company with 
> complete history, d1=0 if the history is not complete  }d1
> When I run the program d1 is always equal to zero. Why?
> Once I have create the dummy variable with subset I obtains the code of the 
> companies with a complete history and finally with a merge  I determine a 
> panel of companies with a complete history.But how to determine correctly 
> d1?My best regards, gm
> 
> 
> 
>   [[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] question

2015-07-03 Thread Mark Sharp
Lida,

I expect that there is a better way to solve your problem than the process you 
propose.

However, something like this may do what you want.

###
## met <- read.csv("your_met_file”)
## Since I do not have your file a made a small 5*1 character vector.
met <- c("glycine_imp",
"Nacetylglycine_imp",
"sarcosine_imp",
"dimethylglycine_imp",
"betaine_imp")

for (i in seq_along(met)) {
  my_formula <- paste0(met[i], "~egfr_v1_ckdepi+pc1+pc2+pc3+V1AGE01+GENDER")
  prep <- Scores(Z=metalofGT, formula = my_formula)
  save(prep, file = paste0("prep", i))
}
###

Mark


R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org

> On Jul 2, 2015, at 11:48 AM, Lida Zeighami  wrote:
> 
> Thank you so much for replying me!
> for better understanding my problem, I explain my problem more:
> 
> I have a 682*1 matrix called "met" , the first 5 rows similar below:
> 
>> rownames(met)[1:5]
> 
> [1]  "glycine_imp"
> [2]  "Nacetylglycine_imp"
> [3]  "sarcosine_imp"
> [4]  "dimethylglycine_imp"
> [5]  "betaine_imp"
> 
> and I have a function in R that each time use one of the row names of "met"
> matrix and create a new object file and I should save the objects!
> 
> my function is  "
> Scores(Z=metalofGT,formula="met[i]~egfr_v1_ckdepi+pc1+pc2+pc3+V1AGE01+GENDER")
> " that each time just I should change the met[i] and replace by row names
> "met" one by one and for each of them I should rename the function and
> after that I should save each object!
> for example for first row of "met" I have
> 
>>  prep1<- 
>> Scores(Z=metalofGT,formula="glycine_imp~egfr_v1_ckdepi+pc1+pc2+pc3+V1AGE01+GENDER")
> #creat the object file for first row and called prep1###
> 
>>  save(prep1, file="prep1.RData", compress="bzip2")  ##save the
> object file as "prep1.RData"#
> 
> I should do this process for 682 row names of "met" matrix and at the end I
> should have"prep1.RData"  ,   "prep2.RData"   , "prep3.RData"
> 
> so, would you please help me how to do it?
> 
> Many Thanks,
> Ati
> 
> On Wed, Jul 1, 2015 at 1:07 PM, Lida Zeighami  wrote:
> 
>> I have 682 variables in a data frame , and a function that  I should feed
>> 682 variables in this function one by one and each time save the file as a
>> special name!
>> for emaple:
>> my data frame file includes 682 names :
>> 1  aaa
>> 2  bbb
>> 3  dfdsfg
>> 4 fghh
>> .
>> 
>> 682 fgfhg
>> and a function like prep(Z, aaa, .) and each time I should change the
>> variable name in this function and read the variable from the data frame
>> and each time I should save the file as a special name such as:
>> 
>> prep1<- prep(z, aaa,...)
>> prep2<- prep(z, bbb,...)
>> prep3<- prep(z, dfdsfg,..)
>> Prep4<- prep(z, fghh,...)
>> 
>> How can I use loop function in R to that?
>> 
>> Thanks
>> 
> 
>   [[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] question

2015-07-06 Thread Mark Sharp
Lida,

Please send the code that you ran. It is almost certain that you have a vector 
being formed that is the wrong length. There should be only one vector that you 
use to increment through the loop and that is the character vector formed when 
you read in your_met_file to form the met character vector.

Mark
R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Jul 6, 2015, at 9:05 AM, Lida Zeighami  wrote:
> 
> Hi Mark,
> 
> Thank you so much for your help.
> 
> I run your code and it works great for 5*1 character vector but if I run it 
> for 682*1 character vector it has some error like this:
> 
> Error in model.frame.default(formula = formula, ...) : 
>   variable lengths differ (found for 'egfr_v1_ckdepi')
> 
> Would you please let me know what's the reason is?
> 
> Many Thanks,
> Lida
> 
> On Fri, Jul 3, 2015 at 11:38 PM, Mark Sharp  wrote:
> Lida,
> 
> I expect that there is a better way to solve your problem than the process 
> you propose.
> 
> However, something like this may do what you want.
> 
> ###
> ## met <- read.csv("your_met_file”)
> ## Since I do not have your file a made a small 5*1 character vector.
> met <- c("glycine_imp",
> "Nacetylglycine_imp",
> "sarcosine_imp",
> "dimethylglycine_imp",
> "betaine_imp")
> 
> for (i in seq_along(met)) {
>   my_formula <- paste0(met[i], "~egfr_v1_ckdepi+pc1+pc2+pc3+V1AGE01+GENDER")
>   prep <- Scores(Z=metalofGT, formula = my_formula)
>   save(prep, file = paste0("prep", i))
> }
> ###
> 
> Mark
> 
> 
> R. Mark Sharp, Ph.D.
> Director of Primate Records Database
> Southwest National Primate Research Center
> Texas Biomedical Research Institute
> P.O. Box 760549
> San Antonio, TX 78245-0549
> Telephone: (210)258-9476
> e-mail: msh...@txbiomed.org
> 
> > On Jul 2, 2015, at 11:48 AM, Lida Zeighami  wrote:
> >
> > Thank you so much for replying me!
> > for better understanding my problem, I explain my problem more:
> >
> > I have a 682*1 matrix called "met" , the first 5 rows similar below:
> >
> >> rownames(met)[1:5]
> >
> > [1]  "glycine_imp"
> > [2]  "Nacetylglycine_imp"
> > [3]  "sarcosine_imp"
> > [4]  "dimethylglycine_imp"
> > [5]  "betaine_imp"
> >
> > and I have a function in R that each time use one of the row names of "met"
> > matrix and create a new object file and I should save the objects!
> >
> > my function is  "
> > Scores(Z=metalofGT,formula="met[i]~egfr_v1_ckdepi+pc1+pc2+pc3+V1AGE01+GENDER")
> > " that each time just I should change the met[i] and replace by row names
> > "met" one by one and for each of them I should rename the function and
> > after that I should save each object!
> > for example for first row of "met" I have
> >
> >>  prep1<- 
> >> Scores(Z=metalofGT,formula="glycine_imp~egfr_v1_ckdepi+pc1+pc2+pc3+V1AGE01+GENDER")
> > #creat the object file for first row and called prep1###
> >
> >>  save(prep1, file="prep1.RData", compress="bzip2")  ##save the
> > object file as "prep1.RData"#
> >
> > I should do this process for 682 row names of "met" matrix and at the end I
> > should have"prep1.RData"  ,   "prep2.RData"   , "prep3.RData"
> >
> > so, would you please help me how to do it?
> >
> > Many Thanks,
> > Ati
> >
> > On Wed, Jul 1, 2015 at 1:07 PM, Lida Zeighami  wrote:
> >
> >> I have 682 variables in a data frame , and a function that  I should feed
> >> 682 variables in this function one by one and each time save the file as a
> >> special name!
> >> for emaple:
> >> my data frame file includes 682 names :
> >> 1  aaa
> >> 2  bbb
> >> 3  dfdsfg
> >> 4 fghh
> >> .
> >>
> >> 682 fgfhg
> >> and a function like prep(Z, aaa, .) and each time I should change the
> >> variable name in this function and read the variable from the data frame
> >> and each time I should save the file as a special name such as:
> >>
> >> prep1<- prep(z, aaa,...)
> >> prep2<- prep(z, bbb,...)
> >> prep3<- prep(z, dfdsfg,..)
> >> Prep4<- prep(z, fghh,...)
> >>
> >> How can I use loop function in R to that?
> >>
> >> Thanks
> >>
> >
> >   [[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] norm's book

2015-07-08 Thread Mark Leeds
Hi All: In case anyone is interested,  Norm's new book, "parallel computing
for data science" is out on amazon.  It already got raving reviews from
Dave Giles  who runs a popular econometrics blog.


Mark

[[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] R 3.1.2 : arima.sim(model=list(ma=0.5), n=250, innov=rnorm(250, mean=0, sd=0.1)) versus arima.sim(model=list(ma=0.5), n=250, mean=0, sd=0.1) => only the first element is not identical !

2015-07-11 Thread Mark Leeds
Hi Fabian: I think one would say that that is not a bug. I looked at the
details of arima.sim ( using debug(arima.sim) )
 and there are two different series that are created inside the function.
one is called innov and the other is start.innov. start.innov is
used to create a burn in period for the constructed series.

in your test1 call, you are not  supplying arguments for what should be
used for the innovations associated with start.innov which is used for the
burn in period. So, arima.sim  uses the defaults of mean = 0 and sd = 1.0.
For your test2 call, you do provide them ( so they are used for both innov
and start.innov )  and you use  sd = 0.1 So, for test2,  the values  for
the burn in period end up being different from the ones in test1.

Below, I made a test3 that can be used to get the same values as test2. In
short, by specifiying the innov call EXACTLY in test1, you're letting
arima.sim use the default arguments for the start.innov call so that's why
they're different.


#
 ##undebug(arima.sim)

set.seed(123);
test1 <- arima.sim(model=list(ma=0.5), n =
250,innov=rnorm(250,mean=0,sd=0.1))
print(head(test1))

set.seed(123);
test2 <- arima.sim(model=list(ma=0.5), n=250, mean=0, sd=0.1)
print(head(test2))

set.seed(123);
test3 <- arima.sim(model=list(ma=0.5), innov = rnorm(250,mean=0, sd=0.1), n
= 250, mean=0, sd=0.1)
print(head(test3))

On Sat, Jul 11, 2015 at 3:46 AM, Fabien Tarrade 
wrote:

> Dear all,
>
> When doing a DataCamp tutorial with R I find the following observation
> that using 2 different syntax for "arima.sim" give different answer for the
> first element
>
> If I use the the function using the list of argument describe in the help
> manual :
> arima.sim(model=list(ma=0.5),n=250,innov=rnorm(250,mean=0,sd=0.1))
>
> or if I use the following syntax use in a DataCamp example :
>
> arima.sim(model=list(ma=0.5), n=250, mean=0, sd=0.1) it is accepted by
> DataCamp
>
> I don't find exactly the same results. The reason is that even if the seed
> is the same in both cases the first element is not identical while it
> should be (it doesn't mean that the results is wrong, maybe for the first
> element the seed is not propagated correctly)
>
> here the results of the difference using the same seed (only the first
> element is different using the 2 different syntaxes) :
>
>   [1] -0.252214  0.00  0.00  0.00  0.00  0.00
> 0.00  0.00  0.00  0.00
>  [11]  0.00  0.00  0.00  0.00  0.00 0.00
> 0.00  0.00  0.00  0.00
>
>
> here the code to reproduce this feature :
>
> set.seed(123);
> test1 <- 0.05 +
> arima.sim(model=list(ma=0.5),n=250,innov=rnorm(250,mean=0,sd=0.1))
> set.seed(123);
> test2 <- 0.05 + arima.sim(model=list(ma=0.5), n=250, mean=0, sd=0.1)
>
> test1-test2
>
> I am using R 3.1.2 GUI 1.65 Mavericks build (6833) on Mac (I guess arima
> come with stats which is included in R (?))
> The DataCamp team ask me to report to you about this observation on this
> mailing list. If you want me to fill a bug report some R bug tracking
> system, let me know
>
> Please tell me if this is the wrong list and which other information do
> you need from R and how to get then (compiler, version of some R packages
> ...)
>
>
> Hope this help
> Thanks
> Cheers
> Fabien
> --
> Dr Fabien Tarrade
>
> Quantitative Analyst - Data Scientist - Researcher
>
> Senior data analyst specialised in the modelling, processing and
> statistical treatment of data.
> PhD in Physics, 10 years of experience as researcher at the forefront of
> international scientific research.
> Fascinated by finance and data modelling.
>
> Geneva, Switzerland
>
> Email : cont...@fabien-tarrade.eu 
> Phone : www.fabien-tarrade.eu 
> Phone : +33 (0)6 14 78 70 90
>
> LinkedIn  Twitter <
> https://twitter.com/fabtar> Google <
> https://plus.google.com/+FabienTarradeProfile/posts> Facebook <
> https://www.facebook.com/fabien.tarrade.eu> Google
>  Xing  >
> __
> 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] write.table with append=T after using cat on same file

2015-07-27 Thread Mark Sharp
I do not get an error with R-3.2.1 on Mac OS. You may have done something prior 
to this code so that perhaps F is not FALSE or T is not TRUE.

R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jul 27, 2015, at 3:32 PM, Waichler, Scott R  
> wrote:
> 
> Hi, 
> 
> For years I've been writing text to the beginning of files with cat(append=F) 
> , then following that text with data written by write.table(append=T).  It is 
> now giving me an error message.  I'm using R-3.1.2.  What gives?
> 
> df <- data.frame(x = 1, y = 1:10, z = 10:1)
> cat(file="junk.txt", sep="", "# An introductory note.\n")
> write.table(df, file="junk.txt", sep=",", append=T, quote=F, row.names=F, 
> col.names=F)
> 
> Error in file(file, ifelse(append, "a", "w")) : invalid 'open' argument
> 
> Thanks,
> Scott Waichler
> Pacific Northwest National Laboratory
> Richland, WA  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.

__
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] Reading Json data

2015-07-27 Thread Mark Sharp
Mayukh,

I think you are missing an argument to paste() and a right parenthesis 
character.

Try 
json_data <- fromJSON(paste(readLines(json_file), collapse = " "))

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jul 27, 2015, at 3:41 PM, Mayukh Dass  wrote:
> 
> Hello,
> 
> I am trying to read a set of json files containing tweets using the
> following code:
> 
> json_data <- fromJSON(paste(readLines(json_file))
> 
> Unfortunately, it only reads the first record on the file. For example, in
> the file below, it only reads the first record starting with "id":"tag:
> search.twitter.com,2005:3318539389". What is the best way to retrieve these
> records? I have 20 such json files with varying number of tweets in it.
> Thank you in advance.
> 
> Best,
> Mayukh
> 
> {"id":"tag:search.twitter.com
> ,2005:3318539389","objectType":"activity","actor":{"objectType":"person","id":"id:
> twitter.com:2859421","link":"http://www.twitter.com/meetjenn","displayName":"Jenn","postedTime":"2007-01-29T17:06:00.000Z","image":"06-19-07_2010.jpg","summary":"I
> say 'like' a lot. I fall down a lot. I walk into everything. Love Pgh Pens,
> NE Pats, Fundraising, Dogs & History. Craft Beer & Running
> Novice.","links":[{"href":"http://meetjenn.tumblr.com","rel":"me"}],"friendsCount":0,"followersCount":0,"listedCount":0,"statusesCount":0,"twitterTimeZone":"Eastern
> Time (US &
> Canada)","verified":false,"utcOffset":"0","preferredUsername":"meetjenn","languages":["en"],"location":{"objectType":"place","displayName":"Pgh/Philajersey"},"favoritesCount":0},"verb":"post","postedTime":"2009-08-15T00:00:12.000Z","generator":{"displayName":"tweetdeck","link":"
> http://twitter.com
> "},"provider":{"objectType":"service","displayName":"Twitter","link":"
> http://www.twitter.com"},"link":";
> http://twitter.com/meetjenn/statuses/3318539389","body":"Cool story about
> the man who created the @Starbucks logo. Additional link at the bottom on
> how it came to be:  http://bit.ly/16bOJk
> ","object":{"objectType":"note","id":"object:search.twitter.com,2005:3318539389","summary":"Cool
> story about the man who created the @Starbucks logo. Additional link at the
> bottom on how it came to be:  http://bit.ly/16bOJk","link":";
> http://twitter.com/meetjenn/statuses/3318539389
> ","postedTime":"2009-08-15T00:00:12.000Z"},"twitter_entities":{"urls":[{"expanded_url":null,"indices":[111,131],"url":"
> http://bit.ly/16bOJk
> "}],"hashtags":[],"user_mentions":[{"id":null,"name":null,"indices":[41,51],"screen_name":"@Starbucks","id_str":null}]},"retweetCount":0,"gnip":{"matching_rules":[{"value":"Starbucks","tag":null}]}}
> {"id":"tag:search.twitter.com
> ,2005:3318543260","objectType":"activity","actor":{"objectType":"person","id":"id:
> twitter.com:61595468","link":"http://www.twitter.com/FastestFood","displayName":"FastFood
> Bob","postedTime":"2009-01-30T20:51:10.000Z","image":"","summary":"Just A
> little food for
> thought","links":[{"href":"http://www.TeamSantilli.com","rel":"me"}],"friendsCount":0,"followersCount":0,"listedCount":0,"statusesCount":0,"twitterTimeZone":"Pacific
> Time (US &
> Canada)","verified":false,"utcOffset":"0","preferredUsername":"FastestFood","languages":["en"],"location":{"objectType":"place","displayName":"eating
> some
> thoughts"},"favoritesCount":0},"verb":"post","postedTime":"2009-08-15T00:00:23.000Z","generator":{"displayName":"oauth:17","link":"
> http://twitter.com
> "},"provider":{"objectType":"service","displayName":"Twitter","link":"
> http://www.twitter.com"},"link":";
> http://twitter.com/FastestFood/statuses/3318543260","body":"Oregon Biz
> Report » How Starbucks saved millions. Oregon closures ...
> http://u.mavrev.com/02bdj","object":{"objectType":"note","id":"object:
> search.twitter.com,2005:3318543260","summary":"Oregon Biz Report » How
> Starbucks saved millions. Oregon closures ... http://u.mavrev.com/02bdj
> ","link":"http://twitter.com/FastestFood/statuses/3318543260
> ","postedTime":"2009-08-15T00:00:23.000Z"},"twitter_entities":{"urls":[{"expanded_url":null,"indices":[70,95],"url":"
> http://u.mavrev.com/02bdj
> "}],"hashtags":[],"user_mentions":[]},"retweetCount":0,"gnip":{"matching_rules":[{"value":"Starbucks","tag":null}]}}
> {"info":{"message":"Replay Request
> Completed","sent":"2015-02-18T00:05:15+00:00","activity_count":2}}
> 
>   [[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] R command to open a file "browser" on Windows and Mac?

2015-08-03 Thread Mark Sharp
Set your path with setwd(“my_path”) and then use file.choose().

You could have gotten this information sooner with a simple online search.

Mark
R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Aug 3, 2015, at 10:19 AM, Jonathan Greenberg  wrote:
> 
> Folks:
> 
> Is there an easy function to open a finder window (on mac) or windows
> explorer window (on windows) given an input folder?  A lot of times I want
> to be able to see via a file browser my working directory.  Is there a good
> R hack to do this?
> 
> --j
> 
>   [[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] Reading Json data

2015-08-10 Thread Mark Sharp
Mayukh,

I apologize for taking so long to get back to your problem. I expect you may 
have found the solution. If so I would be interested. I have developed a hack 
to solve the problem, but I expect if someone knew how to handle JSON objects 
or even text parsing better they could develop a more elegant solution. 

As I understand the problem, your text file has more than one JSON object in 
text form. There are three. The first two are very similar and the last is a 
trailer indication what was done, when it was done and the number of JSON 
objects sent. The problem is that fromJSON() only pulls off the first of the 
JSON objects. 

I have defined three helper functions to separate the JSON objects, read them 
in, and store them in a list.

library(RJSONIO)
library(stringi, quietly = TRUE)
#library(jsonlite) # also works

#' Returns dataframe with ordered locations of the matching braces.
#'
#' There is almost certainly a better function to do this. 
#' @param txt character vector of length one having 0 or more matching braces.
#' @import stringi
#' @examples 
#' library(rmsutilityr)
#' match_braces("{123{456{78}9}10}")
#' @export
match_braces <- function(txt) {
  txt <- txt[1] # just in the case of having more than one element
  left <- stri_locate_all_regex(txt, "\\{")[[1]][ , 1]
  right <- stri_locate_all_regex(txt, "\\}")[[1]][ , 2]
  len <- length(left)
  braces <- data.frame(left = rep(0, len), right = rep(0, len))
  for (i in seq_along(right)) {
for (j in rev(seq_along(left))) {
  if (left[j] < right[i] & left[j] != 0) {
braces$left[i] <- left[j]
braces$right[i] <- right[i]
left[j] <- 0
break
  }
}
  }
  braces[order(braces$left), ]
}

#' Returns a list containing two objects in the text of a character vector 
#' of length one: (1) object = the first json object found and (2) remainder = 
#' the remaining text.
#' 
#'  Properly formed messages are assumed. Error checking is non-existent.
#' @param json_txt character vector of length one having one or more JSON
#' objects in character form.
#' @import stringi
#' @export
get_first_json_message <- function(json_txt) {
  len <- stri_length(json_txt)
  braces <- match_braces(json_txt)
  if (braces$right[1] + 1 > len) {
remainder <- ""
  } else {
remainder <- stri_trim_both(stri_sub(json_txt, braces$right[1] + 1))
  }
  list(object = stri_sub(json_txt, braces$left[1], to = braces$right[1]),
   remainder = remainder)
}
#' Returns list of lists made by call to fromJSON()

#' @param json_txt character vector of length 1 having one or more
#' JSON objects in text form.
#' @import stringi
#' @export
get_json_list <- function (json_txt) {
  t_json_txt <- json_txt
  i <- 0
  json_list <- list()
  repeat{
i <- i + 1
message_remainder <- get_first_json_message(t_json_txt)
json_list[i] <- list(fromJSON(message_remainder$object))
if (message_remainder$remainder == "")
  break
    t_json_txt <- message_remainder$remainder
  }
  json_list
}

json_file <- "../data/json_file.txt"
json_txt <- stri_trim_both(stri_c(readLines(json_file), collapse = " "))
json_list <- get_json_list(json_txt)
length(json_list)


R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Jul 27, 2015, at 5:16 PM, Mark Sharp  wrote:
> 
> Mayukh,
> 
> I think you are missing an argument to paste() and a right parenthesis 
> character.
> 
> Try 
> json_data <- fromJSON(paste(readLines(json_file), collapse = " "))
> 
> Mark
> R. Mark Sharp, Ph.D.
> msh...@txbiomed.org
> 
> 
> 
> 
> 
>> On Jul 27, 2015, at 3:41 PM, Mayukh Dass  wrote:
>> 
>> Hello,
>> 
>> I am trying to read a set of json files containing tweets using the
>> following code:
>> 
>> json_data <- fromJSON(paste(readLines(json_file))
>> 
>> Unfortunately, it only reads the first record on the file. For example, in
>> the file below, it only reads the first record starting with "id":"tag:
>> search.twitter.com,2005:3318539389". What is the best way to retrieve these
>> records? I have 20 such json files with varying number of tweets in it.
>> Thank you in advance.
>> 
>> Best,
>> Mayukh
>> 
>> {"id":"tag:search.twitter.com
>> ,2005:3318539389","objectType":"activity","actor":{"objectType":"person","id":"id:

Re: [R] New to R

2014-12-15 Thread Mark Sharp
I would recommend finding some tutorials on line in areas that you enjoy, read 
http://r-bloggers.com every day, find introductory texts in the statistical 
areas of interest, and study some texts on R programming. I really enjoyed The 
Art of R Programming: A Tour of Statistical Software Design by Norman Matloff. 
For a bit more depth I like Hadley Wickham's Advanced R book 
(http://adv-r.had.co.nz).

Mark Sharp

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org

> On Dec 15, 2014, at 5:12 AM, Lalitha Kristipati 
>  wrote:
>
> Hi
>
> I'm learning R language from  past  one month .As R is used highly for data 
> analysis ,mining and modeling ,I want to know few real time examples in R in 
> order to make my learning  fun filled and practical .Any quick suggestions  
> are appreciated .
>
>
>
> Regards,
> Lalitha Kristipati
> Associate Software Engineer
>
>
>
>
> 
> Disclaimer:  This message and the information contained herein is proprietary 
> and confidential and subject to the Tech Mahindra policy statement, you may 
> review the policy at http://www.techmahindra.com/Disclaimer.html externally 
> http://tim.techmahindra.com/tim/disclaimer.html internally within 
> TechMahindra.
> 
>
>
>   [[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.



NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

__
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] regular expression question

2015-01-12 Thread Mark Leeds
Hi All: I have a regular expression problem. If a character string ends
with "rhofixed" or "norhofixed", I want that part of the string to be
removed. If it doesn't end with either of those two endings, then the
result should be the same as the original. Below doesn't work for the
second case. I know why but not how to fix it. I lookrd st friedl's book
and I bet it's in there somewhere but I can't find it. Thanks.

s <- c("lngimbintrhofixed","lngimbnointnorhofixed","test")

result <- sub("^(.*)([n.*|r.*].*)$","\\1",s)

 print(result)
[1] "lngimbint" "lngimbnointno" "test"

[[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] Plot residuals against standard normal distribution

2015-02-02 Thread Hall, Mark
Since you are plotting densities, check out the sm package.  It has been
over a year or so since I've used it, but there was a setting on the
univariate densities to check the data against a normal distribution.

Best, MEH



On Mon, Feb 2, 2015 at 2:42 PM, Mikael Olai Milhøj 
wrote:

> Hi,
>
> I'm having trouble trying to plot the density of the residuals against the
> standard normal distribution N(0,1). (I'm trying to see if my residuals are
> well-behaved).
>
> I know hwo to calculate the standardized residuals (I guess that there may
> be a simple way using a R function) and then plot this by using the density
> function
>
> y<-(model$residuals-mean(model$residuals))/sd(model$residuals)
> plot(density(y))
>
> But I don't know how to add the N(0,1) curve. Any suggestions? Thanks in
> advance
>
>
> /Mikael
>
> [[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.
>



-- 
Mark E. Hall, PhD
Assistant Field Manager, Black Rock Field Office
Winnemucca District Office
775-623-1529.

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

2015-02-17 Thread Mark Sharp
Alexandra,

According to the documentation (?readLines), readLines returns a character 
vector with one line from the file being read in each element of the vector. 
You can put the character vector from each file (as represented by a year 
designation in your example) in a separate list element. You want to count the 
elements in the list starting at 1 not 2000. The integers from years[i] get 
converted to strings in sprintf in the code below.

years <- 2000:2003
Data <- list(length(years))

for (i in seq_along(years)){
#script for downloading each year
Data[i] = readLines(sprintf('file/%s',years[i]))
}
# Data[1] will have the character vector made up of the lines in 'file/2000'.

Mark

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Feb 17, 2015, at 12:15 PM, Alexandra Catena  wrote:
>
> Hi,
>
> I need help with a for loop and printing data.  I want to loop through a
> few years and print the data from each year stacked on top of each other.
> For example,
>
> for (i in 2000:2003){
> #script for downloading each year
> Data = readLines(sprintf('file/%4i,i))
> }
>
> It only prints out the data from the last year.  Also, I tried
>
> Data[i] =  readLines(sprintf('file/%4i,i))
>
> but it says:
>
> "number of items to replace is not a multiple of replacement length"
>
> How do I get it to not replace each year of data? I have R version 2.15.1
>
> Thanks,
> Alexandra
>
>   [[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.


NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

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

2015-02-17 Thread Mark Sharp
Alexandra,

According to the documentation (?readLines), readLines returns a character 
vector with one line from the file being read in each element of the vector. 
You can put the character vector from each file (as represented by a year 
designation in your example) in a separate list element. You want to count the 
elements in the list starting at 1 not 2000. The integers from years[i] get 
converted to strings in sprintf in the code below.

years <- 2000:2003
Data <- list(length(years))

for (i in seq_along(years)){
   #script for downloading each year
   Data[i] = readLines(sprintf('file/%s',years[i]))
}
# Data[1] will have the character vector made up of the lines in 'file/2000'.

Mark

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Feb 17, 2015, at 12:15 PM, Alexandra Catena  wrote:
>
> Hi,
>
> I need help with a for loop and printing data.  I want to loop through a
> few years and print the data from each year stacked on top of each other.
> For example,
>
> for (i in 2000:2003){
> #script for downloading each year
> Data = readLines(sprintf('file/%4i,i))
> }
>
> It only prints out the data from the last year.  Also, I tried
>
> Data[i] =  readLines(sprintf('file/%4i,i))
>
> but it says:
>
> "number of items to replace is not a multiple of replacement length"
>
> How do I get it to not replace each year of data? I have R version 2.15.1
>
> Thanks,
> Alexandra
>
>   [[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. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org








NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

__
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] Best Mac for R

2015-02-25 Thread Mark Sharp
For what I do, which does not require a lot of parallel work, the high end iMac 
was faster and much less expensive than the Mac Pro.

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Feb 25, 2015, at 1:50 PM, Dan Murphy  wrote:
>
> I am possibly in the market for a new laptop. Predominantly a Windows
> user, I owned a macbook pro 10 years ago and am considering going that
> route again. Does the standard advice still hold: Get the most
> powerful processor (i7), most ram (16GB), and largest internal storage
> (512GB), if affordable?
> thanks,
> dan
>
> __
> 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.


NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

__
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] rms package: error with Glm

2015-03-02 Thread Mark Seeto
Dear R-help,

I'm getting an error with Glm (from the rms package) when the
equivalent model using glm does not give an error. This is using rms
4.3-0 in R 3.1.1.

An example is shown below. I have set the seed value, but the error is
not specific to this seed value.

Thanks for any help anyone can give.

Mark Seeto

#
library(rms)

set.seed(1)

n <- 100  # sample size

beta0 <- 3.7
beta1 <- 1.5
beta2 <- 0.9
beta3 <- 0.5

rate.x1 <- 2
mean.x2 <- 1
sd.x2 <- 2

nu <- 1.3

d <- data.frame(x1 = rexp(n, rate = rate.x1),
x2 = rnorm(n, mean.x2, sd.x2))

d$y <- rgamma(n, shape = nu,
  rate = nu/exp(beta0 + beta1*d$x1 + beta2*d$x2 + beta3*d$x2^2))

glm(y ~ x1 + x2 + I(x2^2), family = Gamma(link=log), data=d)  # No error

Glm(y ~ x1 + pol(x2, 2), family = Gamma(link=log), data=d)  # Error shown below

## Error in glm.fit(x = X[, "Intercept", drop = FALSE], y = Y, weights
= weights,  :
##   NA/NaN/Inf in 'x'
## In addition: Warning message:
## step size truncated due to divergence

__
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] Extract year from date

2015-03-08 Thread Mark Sharp
Make the question reproducible (I used dput after getting the data into a 
dataframe). 
You need to provide a date of origin for the as.Date function.
Try lubridate package.

library(lubridate)
wells <- structure(list(ID = structure(c(3L, 3L, 2L, 1L, 3L, 2L, 3L, 1L, 
 1L, 2L, 3L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L), .Label = 
c("BC-0002", 
 "BC-0003", "BC-0004"), class = "factor"), Date = c(41163L, 41255L, 
 41345L, 41351L, 41355L, 41438L, 41438L, 41443L, 41521L, 41522L, 
 41522L, 41627L, 41627L, 41634L, 41703L, 41703L, 41710L, 41795L, 
 41795L, 41801L, 41905L, 41905L, 41906L), DepthtoWater_bgs = c(260.6, 
 261.65, 166.58, 317.85, 262.15, 167.55, 265.45, 317.25, 321.25, 
 168.65, 266.15, 168.95, 265.25, 312.31, 169.25, 265.05, 313.01, 
 168.85, 266.95, 330.41, 169.75, 267.75, 321.01), test = 3:25, 
 test2 = 1:23), .Names = c("ID", "Date", "DepthtoWater_bgs", 
 "test", "test2"), class = "data.frame", row.names = c("1", "2", 
 "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", 
 "15", "16", "17", "18", "19", "20", "21", "22", "23"))

wells$year <- year(as.Date(wells$Date, origin = '1900-1-1'))
head(wells$year)

Mark

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org



> On Mar 8, 2015, at 12:50 AM, Steve Archambault  wrote:
> 
> Hi all,
> 
> I am trying in vain to create a new object "Year" in my data frame from
> existing Date data. I have tried many different approaches, but can't seem
> to get it to work. Here is an example of some code I tried.
> 
> date1<- as.Date(wells$Date,"%m/%d/%Y")
> wells$year<-as.numeric(format(date1, "%Y"))
> 
> I am starting with data that looks like this.
> 
>ID  Date DepthtoWater_bgs test test2
> 1  BC-0004 41163   260.603 1
> 2  BC-0004 41255   261.654 2
> 3  BC-0003 41345   166.585 3
> 4  BC-0002 41351   317.856 4
> 5  BC-0004 41355   262.157 5
> 6  BC-0003 41438   167.558 6
> 7  BC-0004 41438   265.459 7
> 8  BC-0002 41443   317.25   10 8
> 9  BC-0002 41521   321.25   11 9
> 10 BC-0003 41522   168.65   1210
> 11 BC-0004 41522   266.15   1311
> 12 BC-0003 41627   168.95   1412
> 13 BC-0004 41627   265.25   1513
> 14 BC-0002 41634   312.31   1614
> 15 BC-0003 41703   169.25   1715
> 16 BC-0004 41703   265.05   1816
> 17 BC-0002 41710   313.01   1917
> 18 BC-0003 41795   168.85   2018
> 19 BC-0004 41795   266.95   2119
> 20 BC-0002 41801   330.41   2220
> 21 BC-0003 41905   169.75   2321
> 22 BC-0004 41905   267.75   2422
> 23 BC-0002 41906   321.01   2523
> 
> Any help would be greatly appreciated!
> 
> -Steve
> Sent from my iPhone
> 
> __
> 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] glmnet: converting coefficients back to original scale

2015-03-19 Thread Mark Seeto
Dear R-help,

I'm having trouble understanding how glmnet converts its coefficient
estimates back to the original scale. Here's an example with ridge
regression:


library(glmnet)
set.seed(1)

n <- 20  # sample size

d <- data.frame(x1 = rnorm(n, 1, 1), x2 = rnorm(n, 10, 2), y = rnorm(n, 1, 2))

# Sample means
mx1 <- mean(d$x1)
mx2 <- mean(d$x2)
my <- mean(d$y)

# Scaling factors ("1/n standard deviations")
sx1 <- sd(d$x1)*sqrt((n - 1)/n)
sx2 <- sd(d$x2)*sqrt((n - 1)/n)
sy <- sd(d$y)*sqrt((n - 1)/n)

# Scaled variables
d$x1s <- (d$x1 - mx1)/sx1
d$x2s <- (d$x2 - mx2)/sx2
d$ys <- (d$y - my)/sy

lam <- 0.5  # lambda value

# Using scaled variables (same result for standardize=TRUE and
standardize=FALSE)
glmnet1 <- glmnet(as.matrix(d[, c("x1s", "x2s")]), d$ys, alpha=0, lambda = lam)

# Using unscaled variables
glmnet2 <- glmnet(as.matrix(d[, c("x1", "x2")]), d$y, alpha=0, lambda=lam)

coef(glmnet2)
## s0
## (Intercept)  2.5658491
## x1   0.3471199
## x2  -0.1703715

# I want to calculate the glmnet2 coef estimates from the glmnet1 coef
estimates.
# The following attempts are based on rearrangement of
# (y - my)/sy = beta1*(x1 - mx1)/sx1 + beta2*(x2 - mx2)/sx2

my - coef(glmnet1)["x1s", "s0"]*mx1*sy/sx1 - coef(glmnet1)["x2s",
"s0"]*mx2*sy/sx2
# 2.430971
# Not the same as coef(glmnet2)["(Intercept)", "s0"]

coef(glmnet1)["x1s", "s0"]*sy/sx1
# 0.3096897
# Not the same as coef(glmnet2)["x1", "s0"]

coef(glmnet1)["x2s", "s0"]*sy/sx2
# -0.1524043
# Not the same as coef(glmnet2)["x2", "s0"]

##

I can apply a similar method (with centring of y instead of
standardisation) to successfully get the coefficient estimates on the
original scale given by lm.ridge in the MASS package. I would
appreciate any help anyone can give on where I'm going wrong with
glmnet.

Thanks,
Mark

__
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] glmnet: converting coefficients back to original scale

2015-04-04 Thread Mark Seeto
Thanks for your reply Mehmet. I've found that the problem was that I
didn't scale the lambda value. My original example did not follow the
instruction not to give a single lambda value, but that in itself
wasn't the problem. Example shown below.

library(glmnet)
library(MASS)

set.seed(1)
n <- 20

d <- data.frame(x1 = rnorm(n, 1, 1),
x2 = rnorm(n, 10, 2),
y = rnorm(n, 1, 2))

# Sample means
mx1 <- mean(d$x1)
mx2 <- mean(d$x2)
my <- mean(d$y)

# Scaling factors
sx1 <- sd(d$x1)*sqrt((n-1)/n)
sx2 <- sd(d$x2)*sqrt((n-1)/n)
sy <- sd(d$y)*sqrt((n-1)/n)

# Scaled variables
d$x1s <- (d$x1 - mx1)/sx1
d$x2s <- (d$x2 - mx2)/sx2
d$ys <- (d$y - my)/sy

# Centred y
d$yc <- d$y - my

lam <- 1  # lambda value for lm.ridge

lmr1 <- lm.ridge(y ~ x1 + x2, data=d, lambda=lam)
lmr2 <- lm.ridge(yc ~ x1s + x2s, data=d, lambda=lam)

coef(lmr1)

my - coef(lmr2)["x1s"]*mx1/sx1 - coef(lmr2)["x2s"]*mx2/sx2
# same as coef(lmr1)[1]

coef(lmr2)["x1s"]/sx1  # same as coef(lmr1)["x1"]
coef(lmr2)["x2s"]/sx2  # same as coef(lmr1)["x2"]

glmnet1 <- glmnet(as.matrix(d[, c("x1", "x2")]), d[, "y"], alpha=0)
glmnet2 <- glmnet(as.matrix(d[, c("x1s", "x2s")]), d[, "ys"], alpha=0)

# Note: glmnet1$lambda is glmnet2$lambda*sy

ind <- 80  # index of lambda values to look at

coef(glmnet1)[, ind]

my - coef(glmnet2)["x1s", ind]*mx1*sy/sx1 -
  coef(glmnet2)["x2s", ind]*mx2*sy/sx2
# same as coef(glmnet1)["(Intercept)", ind]

coef(glmnet2)["x1s", ind]*sy/sx1
# same as coef(glmnet1)["x1", ind]

coef(glmnet2)["x2s", ind]*sy/sx2
# same as coef(glmnet1)["x2", ind]


On Sat, Apr 4, 2015 at 6:03 AM, Suzen, Mehmet  wrote:
> This is interesting, can you post your lm.ridge solution as well?  I
> suspect in glmnet, you need to use model.matrix with intercept, that
> could be the reason.
>
> -m

__
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] F-test where the coefficients in the H_0 is nonzero

2018-08-09 Thread Mark Leeds
Hi: the F-test is a joint hypothesis ( I never used that function from the
car package but it sounds like it is )  and the t-statistics
that come  out of a  regression are "conditional" in the sense that they
test the significance of one coefficient given the other so you wouldn't
expect the two outputs to be the same.




On Thu, Aug 9, 2018 at 4:58 AM, John  wrote:

> Hi,
>
>I try to run the same f-test by lm (with summary) and the function
> "linearHypothesis" in car package. Why are the results (p-values for the
> f-test) different?
>
>
> > df1<-data.frame(x=c(2,3,4), y=c(7,6,8))
> > lm1<-lm(y~x, df1)
> > lm1
>
> Call:
> lm(formula = y ~ x, data = df1)
>
> Coefficients:
> (Intercept)x
> 5.5  0.5
>
> > summary(lm1)
>
> Call:
> lm(formula = y ~ x, data = df1)
>
> Residuals:
>123
>  0.5 -1.0  0.5
>
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept)5.500  2.693   2.0430.290
> x  0.500  0.866   0.5770.667
>
> Residual standard error: 1.225 on 1 degrees of freedom
> Multiple R-squared:   0.25, Adjusted R-squared:   -0.5
> F-statistic: 0. on 1 and 1 DF,  p-value: 0.6667
>
> > linearHypothesis(lm1, c("(Intercept)=0", "x=0"))
> Linear hypothesis test
>
> Hypothesis:
> (Intercept) = 0
> x = 0
>
> Model 1: restricted model
> Model 2: y ~ x
>
>   Res.Df   RSS Df Sum of Sq  F Pr(>F)
> 1  3 149.0
> 2  1   1.5  2 147.5 49.167 0.1003
>
> 2018-08-03 13:54 GMT+08:00 Annaert Jan :
>
> > You can easily test linear restrictions using the function
> > linearHypothesis() from the car package.
> > There are several ways to set up the null hypothesis, but a
> > straightforward one here is:
> >
> > > library(car)
> > > x <- rnorm(10)
> > > y <- x+rnorm(10)
> > > linearHypothesis(lm(y~x), c("(Intercept)=0", "x=1"))
> > Linear hypothesis test
> >
> > Hypothesis:
> > (Intercept) = 0
> > x = 1
> >
> > Model 1: restricted model
> > Model 2: y ~ x
> >
> >   Res.Df RSS Df Sum of Sq  F Pr(>F)
> > 1 10 10.6218
> > 2  8  9.0001  21.6217 0.7207 0.5155
> >
> >
> > Jan
> >
> > From: R-help  on behalf of John <
> > miao...@gmail.com>
> > Date: Thursday, 2 August 2018 at 10:44
> > To: r-help 
> > Subject: [R] F-test where the coefficients in the H_0 is nonzero
> >
> > Hi,
> >
> >I try to run the regression
> >y = beta_0 + beta_1 x
> >and test H_0: (beta_0, beta_1) =(0,1) against H_1: H_0 is false
> >I believe I can run the regression
> >(y-x) = beta_0 +beta_1‘ x
> >and do the regular F-test (using lm functio) where the hypothesized
> > coefficients are all zero.
> >
> >Is there any function in R that deal with the case where the
> > coefficients are nonzero?
> >
> > John
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > mailto: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.
>

[[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] R Data

2019-02-14 Thread Fowler, Mark
Hi Spencer,

The an1 syntax is adding regression coefficients (or NAs where a regression 
could not be done) to the downloaded and processed data, which ends up a 
matrix. The cbind function adds the regression coefficients to the last column 
of the matrix (i.e. bind the columns of the inputs in the order given). Simple 
example below. Not actually any need for the separate cbind commands, could 
have just used an1=cbind(an,p,t). The cbind function expects all the columns to 
be of the same length, hence the use of the tryCatch function to capture NA's 
for failed regression attempts, ensuring that p and t correspond row by row 
with the matrix.

 x=seq(1,5)
 y=seq(6,10)
 z=seq(1,5)
xyz=cbind(x,y,z)
xyz
   x  y z
[1,] 1  6 1
[2,] 2  7 2
[3,] 3  8 3
[4,] 4  9 4
[5,] 5 10 5
dangs=rep(NA,5)
xyzd=cbind(xyz,dangs)
xyzd
 x  y z dangs
[1,] 1  6 1NA
[2,] 2  7 2NA
[3,] 3  8 3NA
[4,] 4  9 4NA
[5,] 5 10 5NA

-Original Message-
From: R-help  On Behalf Of Spencer Brackett
Sent: February 14, 2019 12:32 AM
To: R-help ; Sarah Goslee ; 
Caitlin Gibbons ; Jeff Newmiller 

Subject: [R] R Data

Hello everyone,

The following is a portion of coding that a colleague sent. Given my lack of 
experience in R, I am not quite sure what the significance of the following 
arguments. Could anyone help me translate? For context, I am aware of the 
downloading portion of the script... library(data.table) etc., but am not 
familiar with the portion pertaining to an1 .

library(data.table)
anno = as.data.frame(fread(file =
"/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt", sep ="\t", 
header = T)) meth = read.table(file = 
"/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/27K/GBM.txt", sep  ="\t", header = 
T, row.names = 1) meth = as.matrix(meth) """ the loop just formats the 
methylation column names to match format"""
colnames(meth) = sapply(colnames(meth), function(i){
  c1 = strsplit(i,split = '.', fixed = T)[[1]]
  c1[4] = paste(strsplit(c1[4],split = "",fixed = T)[[1]][1:2],collapse =
"")
  paste(c1,collapse = ".")
})
exp = read.table(file =
"/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/RNAseq/GBM.txt", sep = "\t", 
header = T, row.names = 1) exp = as.matrix(exp) c = 
intersect(colnames(exp),colnames(meth))
exp = exp[,c]
meth = meth[,c]
m = apply(meth, 1, function(i){
  log2(i/(1-i))
})
m = t(as.matrix(m))
an = anno[anno$probe %in% rownames(m),]
an = an[an$gene %in% rownames(exp),]
an = an[an$location %in% c("TSS200","TSS1500"),]

p = apply(an,1,function(i){
  tryCatch(summary(lm(exp[as.character(i[2]),] ~ 
m[as.character(i[1]),]))$coefficient[2,4], error= function(e)NA)
})
t = apply(an,1,function(i){
  tryCatch(summary(lm(exp[as.character(i[2]),] ~ 
m[as.character(i[1]),]))$coefficient[2,3], error= function(e)NA)
})
an1 =cbind(an,p)
an1 = cbind(an1,t)
an1$q = p.adjust(as.numeric(an1$p))
summary(lm(exp["MAOB",] ~ m["cg00121904",]$coefficient[2,c(3:4)]
###

[[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] R Data

2019-02-14 Thread Fowler, Mark
I am not sure I would use the word ‘accounted’, more like discounted (tossed 
out).

From: Spencer Brackett 
Sent: February 14, 2019 9:21 AM
To: Fowler, Mark 
Cc: R-help ; Sarah Goslee ; 
Caitlin Gibbons ; Jeff Newmiller 

Subject: Re: R Data

Mr. Fowler,

Thank you! This information is most helpful. So from my understanding, I can 
use the regression coefficients shown (via the coding I originally sent, to 
generate a continuous distribution with what is essentially a line of best fit? 
The data added here had some 30,000 variables (it is genomic data from TCGA), 
does this mean that any none NA data is being accounted for in said 
distribution?

Best,

Spencer Brackett



On Thursday, February 14, 2019, Fowler, Mark 
mailto:mark.fow...@dfo-mpo.gc.ca>> wrote:
Hi Spencer,

The an1 syntax is adding regression coefficients (or NAs where a regression 
could not be done) to the downloaded and processed data, which ends up a 
matrix. The cbind function adds the regression coefficients to the last column 
of the matrix (i.e. bind the columns of the inputs in the order given). Simple 
example below. Not actually any need for the separate cbind commands, could 
have just used an1=cbind(an,p,t). The cbind function expects all the columns to 
be of the same length, hence the use of the tryCatch function to capture NA's 
for failed regression attempts, ensuring that p and t correspond row by row 
with the matrix.

 x=seq(1,5)
 y=seq(6,10)
 z=seq(1,5)
xyz=cbind(x,y,z)
xyz
   x  y z
[1,] 1  6 1
[2,] 2  7 2
[3,] 3  8 3
[4,] 4  9 4
[5,] 5 10 5
dangs=rep(NA,5)
xyzd=cbind(xyz,dangs)
xyzd
 x  y z dangs
[1,] 1  6 1NA
[2,] 2  7 2NA
[3,] 3  8 3NA
[4,] 4  9 4NA
[5,] 5 10 5NA

-Original Message-
From: R-help 
mailto:r-help-boun...@r-project.org>> On Behalf 
Of Spencer Brackett
Sent: February 14, 2019 12:32 AM
To: R-help mailto:r-help@r-project.org>>; Sarah Goslee 
mailto:sarah.gos...@gmail.com>>; Caitlin Gibbons 
mailto:bioprogram...@gmail.com>>; Jeff Newmiller 
mailto:jdnew...@dcn.davis.ca.us>>
Subject: [R] R Data

Hello everyone,

The following is a portion of coding that a colleague sent. Given my lack of 
experience in R, I am not quite sure what the significance of the following 
arguments. Could anyone help me translate? For context, I am aware of the 
downloading portion of the script... library(data.table) etc., but am not 
familiar with the portion pertaining to an1 .

library(data.table)
anno = as.data.frame(fread(file =
"/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt", sep ="\t", 
header = T)) meth = read.table(file = 
"/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/27K/GBM.txt", sep  ="\t", header = 
T, row.names = 1) meth = as.matrix(meth) """ the loop just formats the 
methylation column names to match format"""
colnames(meth) = sapply(colnames(meth), function(i){
  c1 = strsplit(i,split = '.', fixed = T)[[1]]
  c1[4] = paste(strsplit(c1[4],split = "",fixed = T)[[1]][1:2],collapse =
"")
  paste(c1,collapse = ".")
})
exp = read.table(file =
"/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/RNAseq/GBM.txt", sep = "\t", 
header = T, row.names = 1) exp = as.matrix(exp) c = 
intersect(colnames(exp),colnames(meth))
exp = exp[,c]
meth = meth[,c]
m = apply(meth, 1, function(i){
  log2(i/(1-i))
})
m = t(as.matrix(m))
an = anno[anno$probe %in% rownames(m),]
an = an[an$gene %in% rownames(exp),]
an = an[an$location %in% c("TSS200","TSS1500"),]

p = apply(an,1,function(i){
  tryCatch(summary(lm(exp[as.character(i[2]),] ~ 
m[as.character(i[1]),]))$coefficient[2,4], error= function(e)NA)
})
t = apply(an,1,function(i){
  tryCatch(summary(lm(exp[as.character(i[2]),] ~ 
m[as.character(i[1]),]))$coefficient[2,3], error= function(e)NA)
})
an1 =cbind(an,p)
an1 = cbind(an1,t)
an1$q = p.adjust(as.numeric(an1$p))
summary(lm(exp["MAOB",] ~ m["cg00121904",]$coefficient[2,c(3:4)]
###

[[alternative HTML version deleted]]

__
R-help@r-project.org<mailto: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] color palettes

2014-08-08 Thread Mark Knecht
?rainbow
?col2rgb

rainbow(8)
col2rgb(rainbow(8)[5])

col2rgb(rainbow(8)[5])[1]
col2rgb(rainbow(8)[5])[2]
col2rgb(rainbow(8)[5])[3]

On Fri, Aug 8, 2014 at 6:26 AM, carol white  wrote:
> Hi,
> Is there any way to take one color of each color family from a color palettes 
> like rainbow? For ex, if there are different blues differentiated by 
> intensity, hue etc, taking one of them. In this case, when using rainbow(n), 
> then how to select 1 color of each family, for ex 1 blue, 1 red etc? It 
> doesn't matter which intensity, hue etc is taken as long as 1 color from each 
> family is taken.
>
>
> Thanks
>
> Carol
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] hadley's book

2014-08-21 Thread Mark Leeds
I have a feeling hadley's book will be quite popular so just a heads up
that it
can now be pre-ordered on amazon.

[[alternative HTML version deleted]]

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


Re: [R] ANY ONE HERE PLZ Urgent

2014-08-28 Thread Mark Sharp
If you use the lubridate package, this is very easy.
See the help file for month() within lubridate for more examples.

library(lubridate)
x <- now()
month(x)
month(x, label = TRUE)
month(x, label = TRUE, abbr = FALSE)
as.character(month(x, label = TRUE, abbr = FALSE))

When you run the above your get the following.

> library(lubridate)
> x <- now()
> month(x)
[1] 8
> month(x, label = TRUE)
[1] Aug
Levels: Jan < Feb < Mar < Apr < May < Jun < Jul < Aug < Sep < Oct < Nov < Dec
> month(x, label = TRUE, abbr = FALSE)
[1] August
12 Levels: January < February < March < April < May < June < July < ... < 
December
> as.character(month(x, label = TRUE, abbr = FALSE))
[1] "August"

Mark

On Aug 28, 2014, at 5:33 AM, arun  wrote:

> Try:
>
> format(as.Date("05/07/2014", "%m/%d/%Y"), "%m")
> #[1] "05"
>
> #or
> strptime("05/07/2014", "%m/%d/%Y")$mon+1
> #[1] 5
>
>
>
> A.K.
>
>
> How to extract a Month from Date object?
>
> almost 13 peoples visited my Question with out replying in New to R , i have 
> task yaar
>
>
>
> don't mind plz could you HELP ME
>
> How to extract a Month from Date object?
>
> as.month("05/07/2014", format = "%m")
>
> tried wityh this
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

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


Re: [R] R-tool - OS compatibility help

2014-08-29 Thread Mark Sharp
See
http://cran.r-project.org/
On Aug 28, 2014, at 11:41 PM, Ravi Kumar Rupakula wrote:

> Dear Support,
>
> Please let us know Windows 2008R2 OS compatibility for "R" tool is available 
> or not?
> If available, please let us know the details.
> --
> RaviKumar Rupakula | HP: +65-98537306 | Email: 
> r...@websynergies.biz | Web Synergies (S) Pte 
> Ltd
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

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


[R] hadley's book

2014-09-29 Thread Mark Leeds
Just a heads up to list: I don't know about other book sites but,  on U.S
Amazon, Hadley's Advanced R book is no longer in pre-order mode. You can
purchase the book now without pre-ordering it.

   Mark

[[alternative HTML version deleted]]

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


[R] reading in hexadecimal data - not working with data ending in E

2014-10-08 Thread mark . hogue
I am trying to read in data from an instrument that is recorded in 
hexadecimal format. Using either: 

y.hex <- read.table(file="hex.data", as.is=TRUE) 

or 

y.hex <- read.table(file="hex.data", text=TRUE) 

gets all the data in just fine except points like `055E` or `020E`. In 
these cases, the E is stripped so I get just 055 or 020. 

The question is how should this data be imported to avoid the E-ending 
problem? 

(By the way, my follow-up is to convert this data using, `y <- 
strtoi(y.hex, 16L)`) 

Thanks for any suggestions, 

Mark Hogue 
[[alternative HTML version deleted]]

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


Re: [R] reading in hexadecimal data - not working with data ending in E

2014-10-09 Thread mark . hogue
Thanks to all for your help. The colClasses option did do the trick. 


[[alternative HTML version deleted]]

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


Re: [R] Getting the most recent dates in a new column from dates in four columns using the dplyr package (mutate verb)

2014-11-10 Thread Mark Sharp
Pradip,

mutate() works on the entire column as a vector so that you find the maximum of 
the entire data set.

I am almost certain there is some nice way to handle this, but the sapply() 
function is a standard approach.

max() does not want a dataframe thus the use of unlist().

Using your definition of data1:

data3 <- data1
data3$oidflag <- as.Date(sapply(seq_along(data3$id), function(row) {
  if (all(is.na(unlist(data1[row, -1] {
max_d <- NA
  } else {
max_d <- max(unlist(data1[row, -1]), na.rm = TRUE)
  }
  max_d}),
  origin = "1970-01-01")

data3
  idmrjdatecocdateinhdatehaldateoidflag
1  1 2004-11-04 2008-07-18 2005-07-07 2007-11-07 2008-07-18
2  2   
3  3 2009-10-242011-10-132011-10-13
4  4 2007-10-10  2007-10-10
5  5 2006-09-01 2005-08-10   2006-09-01
6  6 2007-09-04 2011-10-05   2011-10-05
7  7 2005-10-25   2011-11-04 2011-11-04



R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org





NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

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


Re: [R] range () does not remove NA's with complete.cases() for dates (dplyr/mutate)

2014-11-10 Thread Mark Sharp
Pradip,

For some reason mutate is not setting the is.NA value for the new column. Note 
the output below using your data structures.

> ## It looks at first as if the second element of both columns are NA.
> data2$mrjdate[2]
[1] NA
> data2$oiddate[2]
[1] NA
> ## for convenience
> mrj <- data2$mrjdate[2]
> oid <- data2$oiddate[2]
> mode(mrj)
[1] "numeric"
> mode(oid)
[1] "numeric"
> str(mrj)
 Date[1:1], format: NA
> str(oid)
 Date[1:1], format: NA
> class(mrj)
[1] "Date"
> class(oid)
[1] "Date"
> ## But note:
> identical(mrj, oid)
[1] FALSE
> all.equal(mrj, oid)
[1] "'is.NA' value mismatch: 0 in current 1 in target"
## functioning code
data2$mrjdate[2]
data2$oiddate[2]
mrj <- data2$mrjdate[2]
oid <- data2$oiddate[2]
mode(mrj)
mode(oid)
str(mrj)
str(oid)
class(mrj)
class(oid)
# But note:
identical(mrj, oid)
all.equal(mrj, oid)

## This ugly solution does not have the problem.
> data3 <- data1
> data3$oiddate <- as.Date(sapply(seq_along(data3$id), function(row) {
+   if (all(is.na(unlist(data1[row, -1] {
+ max_d <- NA
+   } else {
+ max_d <- max(unlist(data1[row, -1]), na.rm = TRUE)
+   }
+   max_d}),
+   origin = "1970-01-01")
>
> range(data3$mrjdate[complete.cases(data3$mrjdate)])
[1] "2004-11-04" "2009-10-24"
> range(data3$cocdate[complete.cases(data3$cocdate)])
[1] "2005-08-10" "2011-10-05"
> range(data3$inhdate[complete.cases(data3$inhdate)])
[1] "2005-07-07" "2011-10-13"
> range(data3$haldate[complete.cases(data3$haldate)])
[1] "2007-11-07" "2011-11-04"
> range(data3$oiddate[complete.cases(data3$oiddate)])
[1] "2006-09-01" "2011-11-04"
>
Working code below.

data3 <- data1
data3$oiddate <- as.Date(sapply(seq_along(data3$id), function(row) {
  if (all(is.na(unlist(data1[row, -1] {
max_d <- NA
  } else {
max_d <- max(unlist(data1[row, -1]), na.rm = TRUE)
  }
  max_d}),
  origin = "1970-01-01")

range(data3$mrjdate[complete.cases(data3$mrjdate)])
range(data3$cocdate[complete.cases(data3$cocdate)])
range(data3$inhdate[complete.cases(data3$inhdate)])
range(data3$haldate[complete.cases(data3$haldate)])
range(data3$oiddate[complete.cases(data3$oiddate)])


On Nov 10, 2014, at 10:10 AM, Muhuri, Pradip (SAMHSA/CBHSQ) wrote:

> Hello,
>
> The range() with complete.cases() removes NA's for the date variables that 
> are read from a data frame.  However, the issue is that the same function 
> does not remove NA's for the other date variable that is created using the 
> dplyr/mutate().  The console and the reproducible example are given below. 
> Any advice how to resolve this issue would be appreciated.
>
> Thanks,
>
> Pradip Muhuri
>
>
> #  cut and pasted from the R console 
>
> idmrjdatecocdateinhdatehaldateoiddate
> 1  1 2004-11-04 2008-07-18 2005-07-07 2007-11-07 2008-07-18
> 2  2   
> 3  3 2009-10-242011-10-132011-10-13
> 4  4 2007-10-10  2007-10-10
> 5  5 2006-09-01 2005-08-10   2006-09-01
> 6  6 2007-09-04 2011-10-05   2011-10-05
> 7  7 2005-10-25   2011-11-04 2011-11-04
>>
>> # range of dates
>>
>> range(data2$mrjdate[complete.cases(data2$mrjdate)])
> [1] "2004-11-04" "2009-10-24"
>> range(data2$cocdate[complete.cases(data2$cocdate)])
> [1] "2005-08-10" "2011-10-05"
>> range(data2$inhdate[complete.cases(data2$inhdate)])
> [1] "2005-07-07" "2011-10-13"
>> range(data2$haldate[complete.cases(data2$haldate)])
> [1] "2007-11-07" "2011-11-04"
>> range(data2$oiddate[complete.cases(data2$oiddate)])
> [1] NA   "2011-11-04"
>
>
>   reproducible code #
>
> library(dplyr)
> library(lubridate)
> library(zoo)
> # data object - description of the
>
> temp <- "id  mrjdate cocdate inhdate haldate
> 1 2004-11-04 2008-07-18 2005-07-07 2007-11-07
> 2 NA NA NA NA
> 3 2009-10-24 NA 2011-10-13 NA
> 4 2007-10-10 NA NA NA
> 5 2006-09-01 2005-08-10 NA NA
> 6 2007-09-04 2011-10-05 NA NA
> 7 2005-10-25 NA NA 2011-11-04"
>
> # read the data object
>
> data1 <- read.table(textConnection(temp),
>colClasses=c("character", "Date", "Date", "Date", "Date"),
>header=TRUE, as.is=TRUE
>)
>
>
> # create a new column
>
> data2 <- data1 %>%
> rowwise() %>%
>  mutate(oiddate=as.Date(max(mrjdate,cocdate, inhdate, haldate,
>   na.rm=TRUE), 
> origin='1970-01-01'))
>
> # print records
>
> print (data2)
>
> # range of dates
>
> range(data2$mrjdate[complete.cases(data2$mrjdate)])
> range(data2$cocdate[complete.cases(data2$cocdate)])
> range(data2$inhdate[complete.cases(data2$inhdate)])
> range(data2$haldate[complete.cases(data2$haldate)])
> range(data2$oiddate[complete.cases(data2$oiddate)])
>
>
>
>
>
> Pradip K. Muhuri, PhD
> SAMHSA/CBHSQ
> 1 Choke 

Re: [R] Error: (list) object cannot be coerced to type double; on running the following code in R ver 3.1.2

2014-11-11 Thread Mark Sharp
Aditya,

Please use plan text. HTML is not handled correctly.

Within your last statement it appears you are trying to find the sum of a 
logical vector - is.na(). This is what is causing the error.

My guess is that you want to count the number of elements in the second column 
that are not NA values. You probably want the following for your last line. 
(See ?sum).

nummk <- length(vbm[ !is.na(vbm[ , 2], 2])
## or
nummk <- nrow(vbm[!is.na(vbm[ , 2], ])

## The is.na(vbm[ ,2]) returns a logical vector (for example c(FALSE, TRUE, 
TRUE))

Mark

R. Mark Sharp, Ph.D.
Director Primate Records Database
Southwest National Primate Research Center
Director of Scientific Computing
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Office telephone: (210)258-9476 (is forwarded to mobile telephone; message are 
captured into e-mail.)
Mobile telephone: (210) 218-2868




On Nov 11, 2014, at 3:05 AM, Aditya Singh wrote:

setwd("C:/Documents and 
Settings/Administrator/Desktop/Coursera/specdata/specdata")temp=list.files(pattern="*.csv")myfiles=lapply(temp,read.delim)summk=0nummk=0for
 (i in 1:10) {  vb=data.frame(myfiles[i])  vbm=as.double(vb)  
summk=sum(vbm[,2])  nummk=length(vbm[,2]) - sum(is.na(vbm[,2]))}
Aditya

[[alternative HTML version deleted]]

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



NOTICE: This E-Mail (including attachments) is confidential and may be legally 
privileged. It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521. If you are not the intended recipient, you are hereby notified 
that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited. Please reply to the sender that you have 
received this message in error, then delete it.

[[alternative HTML version deleted]]

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


[R] see rcurl contents before they're sent?

2014-11-20 Thread Mark Miller
I am trying to use the R / solr integration from
https://github.com/datadolphyn/R/blob/master/r_solr_integration.R

I have the query function working, but I'm having trouble with the post
functions, which uses rcurl.

Is it possible to see the string that rcurl is going to send to a webserver
(instead of, or in addition to send it to the server?)

thanks,
Mark

[[alternative HTML version deleted]]

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


Re: [R] C project within R function

2014-11-21 Thread Mark Sharp
Diogo,

For a gentle introduction to package creation see Hadley Wickham's book in 
progress on the subject at http://r-pkgs.had.co.nz. This site is particularly 
accessible if you use RStudio, but is not dependent on its use.

I use very simple packages that are not designed to be used by others to 
organize my work because it is the easiest way to structure projects that use 
many functions. As Duncan has stated, it is the only reasonable way to use C, 
FORTRAN, or C++ subroutines and functions.

Mark
> On Nov 21, 2014, at 6:52 PM, Duncan Murdoch  wrote:
>
> On 21/11/2014, 3:02 PM, Diogo André Alagador wrote:
>> Hi all,
>>
>>
>>
>> I need some assistance regarding the use of C project (set of programming
>> files)  as R functions in Windows OS.
>>
>> By now I really would like to avoid package-building.
>>
>> What are the steps to undergo or where can I check to perform that
>> successfully?
>>
>
> Sorry, but your constraint (no package building) is irrational.  By
> *far* the easiest way to do this is to write a package.
>
> Duncan Murdoch
>
>>
>>
>> Thanks in advance,
>>
>> My best regards,
>>
>> Diogo Alagador
>>
>> <http://www.cibioue.uevora.pt/9-uncategorised/185-dr-diogo-alagador>
>> http://www.cibioue.uevora.pt/9-uncategorised/185-dr-diogo-alagador
>>
>> CIBIO/UE - Research Center in Biodiversity and Genetic Resources, University
>> of �vora, Portugal
>>
>>
>>
>>
>>  [[alternative HTML version deleted]]
>>
>>
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

R. Mark Sharp, Ph.D.
msh...@txbiomed.org






NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Presentation tables in R (knitr)

2014-11-25 Thread Mark Sharp
Tom,

If you are wanting PDF as your output, are you wanting to use LaTeX or Markdown 
with knitr. LaTeX will give you more options. You have not shown an attempt to 
use either for your table construction. Can you define what you mean by pretty? 
Is it the underscores in the column names that are the problem?

Mark
> On Nov 25, 2014, at 2:12 PM, Tom Wright  wrote:
>
> Hi,
> This problem has me stumped so I thought I'd ask the experts. I'm trying
> to create a pretty summary table of some data (which patients have had
> what tests at what times). Ideally I'd like to knitr this into a pretty
> PDF for presentation.
> If anyone has pointers I'll be grateful.
>
> require(tables)
> require(reshape2)
>
> data<-data.frame('ID'=paste0('pat',c(rep(1,8),rep(2,8))),
> 'Time'=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4),
> 'Eye'=rep(c('OS','OS','OD','OD'),4),
> 'Measure'=rep(c('Height','Weight'),8))
>
> tabular(Measure~factor(ID)*factor(Time)*factor(Eye),data)
> #All levels of Time are repeated for all IDs, I'd prefer to just show
> the relevant times.
>
> tabular(Measure~factor(ID)*Time*factor(Eye),data)
> #Time is getting collapsed by ID
>
> data$value=1
> dcast(data,Measure~ID+Time+Eye)
> #close but not very pretty
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

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


Re: [R] Rodbc retrieve data

2015-08-19 Thread Mark Sharp
Diaz,

paste() and paste0() will work here. paste0() defaults to "" between character 
vector elements and paste() defaults to " " (single blank character) between 
character vector elements. See ?paste.

I do not recall, but you may have to escape the "&" symbol, but that is another 
topic.

Try this.

title (main = paste0("Mapa de los dblinks del entorno: ", dbName),sub="Luis 
Diaz -
Emergencies & improvments")

Mark
P.S. Spelling correction - "improvements"

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Aug 19, 2015, at 7:11 AM, Diaz Garcia, Luis Carlos  
> wrote:
> 
> Hi every one
> first I would like to introduce myself, as I'm new here.
> I'm Luis from Barcelona, I'm Oracle dba and I need to create some nice
> graphs.
> So, I was looking for a solution and I saw R...
> 
> I think it's a good tool to make the task I need.
> 
> So here is the task: I need to get all the dblink from one database and draw
> the result of the query.
> The dblink will have the origin database name, the destination, the name of
> the link the type too.
> So I look into the R doc and I saw the way to get the data from my database:
> 
> library("RODBC")
> con <- odbcConnect("DPL03", uid="myuser", pwd="mypass",believeNRows=FALSE )
> dbName <- sqlQuery(con, "SELECT instance_name from v$instance",errors=FALSE)
> 
> Now I have dbName with one value, the name of my instance, but I don't know
> how to insert this data into this:
> 
> plot.new()
> title (main ="Map of the dbLinks of the database",sub="Luis Diaz -
> Emergencies & improvments")
> 
> 
> As you see, I create a screen to plot where I'll draw shapes and lines but
> the first issue is to insert here the name of my instance, but I can't.
> I try to concatenate like this:
> 
> title (main ="Mapa de los dblinks del entorno: " + dbName ,sub="Luis Diaz -
> Emergencies & improvments")
> 
> 
> But I have an error, and if I use print(dbName) the value is printed but
> outside of the plot.new() screen.
> Some one can help ?
> Thanks in advance !
> 
> Cheers
> 
> __
> 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] [R-pkgs] New packages on CRAN: googleAuthR and searchConsoleR

2015-08-31 Thread Mark Edmondson
Hi R package users,

You may be interested in these two new packages now available on CRAN:

*googleAuthR* lets you easily authenticate with Google OAuth2 APIs and make
your own packages with them.  It also is multi-user Shiny compatible, so
you can publish your apps and users can work with their own data.  With
Google APIs including Gmail, Google Predict and Google Drive this offers
access to some nice resources.

*searchConsoleR* is the first package released using googleAuthR, working
with the Google Search Console.  This data includes what keywords people
have used to find your website.

Hope they are of interest, do let me know what you build with them!
Yours sincerely,
Mark

[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
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] SSD vs RAM upgrade

2015-09-14 Thread Mark Sharp
John,

Unless you are doing something very unusual (such as using a database to keep 
intermediate results) SSD hardware will have no affect on R being memory bound. 
According to the behavior you described, you need RAM. 

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org




> On Sep 14, 2015, at 10:44 AM, Kulas, John T.  wrote:
> 
> I have several lab computers that frequently lag/crash with R apparently due 
> to low RAM (they're all 8 GB)
> 
> I put in a request to up the RAM to 32 GB on a few, but my tech support is 
> suggesting an SSD harddrive upgrade instead of the increased RAM.
> 
> Any suggestions on the better approach (SSD harddrive vs increased RAM to 
> help R chug along)?
> 
> Thanks much - John
> 
>   [[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.


  1   2   3   4   5   6   7   8   9   10   >