Re: [R] Identifying columns with specific character

2018-04-18 Thread Rui Barradas

Hello,

To the OP:
The dollar sign is a meta character, so it must be escaped, that is what 
was wrong with your code. The right regular expression would be


grepl("\\$", x)

When a regular expression doesn't work, try reading the help page ?regex.

Another good source you can try is

https://regex101.com


Hope this helps,

Rui Barradas

On 4/18/2018 11:19 PM, Jim Lemon wrote:

Hi Farnoosh,
Perhaps this will help:

drop_dollar<-function(x) return(as.numeric(as.character(gsub("\\$","",x
sapply(My.Data,drop_dollar)

Jim

On Thu, Apr 19, 2018 at 7:23 AM, Farnoosh Sheikhi via R-help
 wrote:

Hello,
I have a data frame with 400 columns and wanted to filter character columns with "$" in it.For example: >  x <- c("$5", 
"$89", "$10", "$34")  >  y <- c(1:4)>  My.Data <- data.frame (x,y)> My.Datax y1  $5 12 $89 23 $10 34 
$34 4
I want to detect the columns with $ and remove the $ from the selected columns.I have tried apply(My.Data, 2, 
function (x) any(grepl("$", x))) but it's not really working.Or:  apply(My.Data, 2, 
function(x){x<-gsub("\\$", "", x)}) works but it turns all the columns to a factor.
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-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 write a loop to repetitive jobs

2018-04-18 Thread jim holtman
Try this:


result <- lapply(71:75, function(x){
# use 'paste0' to add the number to the file name
input <-
read.csv(paste0("C:/Awork/geneAssociation/removed8samples/neuhausen",
x,
"/seg.pr3.csv")
, head=TRUE
)
input$id <- paste0("sn", x)
input  # return the input
})

result <- do.call(rbind, result)  # combine dataframes together
​


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

On Mon, Apr 16, 2018 at 1:54 PM, Ding, Yuan Chun  wrote:

> Hi All..,
>
> I need to do the following repetitive jobs:
>
> seg71 <- 
> read.csv("C:/Awork/geneAssociation/removed8samples/neuhausen71/seg.pr3.csv",
> head=T)
> seg71$id <-"sn71"
>
> seg72 <- 
> read.csv("C:/Awork/geneAssociation/removed8samples/neuhausen72/seg.pr3.csv",
> head=T)
> seg72$id <-"sn72"
>
> seg73 <- 
> read.csv("C:/Awork/geneAssociation/removed8samples/neuhausen73/seg.pr3.csv",
> head=T)
> seg73$id <-"sn73"
>
> seg74 <- 
> read.csv("C:/Awork/geneAssociation/removed8samples/neuhausen74/seg.pr3.csv",
> head=T)
> seg74$id <-"sn74"
>
> seg75 <- 
> read.csv("C:/Awork/geneAssociation/removed8samples/neuhausen75/seg.pr3.csv",
> head=T)
> seg75$id <-"sn75"
>
> seg <- rbind (seg71, seg72, seg73, seg74, seg75)
>
> I want to write a loop to do it;
>
> For ( d in 71:75) {
>   Dir<-paste("C:/Awork/geneAssociation/removed8samples/neuhausen", i,
> sep="")
>   setwd(Dir)
> ..
> then I do not know how to create objects seg71 to seg75;  in SAS, it would
> be  seg&d;
>
> I like R, but not good at R.
>
> Can you help me?
>
> Thank you,
>
> Ding
>
>
> -
> -SECURITY/CONFIDENTIALITY WARNING-
> This message (and any attachments) are intended solely...{{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] Identifying columns with specific character

2018-04-18 Thread Jeff Newmiller
Your message came through all messed up because you did not tell your email 
program to use plain text format. This at best delays a responds and at worst 
prevents us from understanding your question as you intended.

1) The columns became factors when you created the data frame because you did 
not include the stringsAsFactors=FALSE argument. The apply function does NOT 
turn the columns to factors. 

2) Your use of "x <-" in your apply function is misleading, though not 
destructive. Just omit that assignment. 

dta2 <- apply(My.Data, 2, function (x) gsub("\\$", "", x)))

On April 18, 2018 4:23:09 PM CDT, Farnoosh Sheikhi via R-help 
 wrote:
>Hello,
>I have a data frame with 400 columns and wanted to filter character
>columns with "$" in it.For example: >  x <- c("$5", "$89", "$10",
>"$34")  >  y <- c(1:4)>  My.Data <- data.frame (x,y)> My.Data    x y1 
>$5 12 $89 23 $10 34 $34 4
>I want to detect the columns with $ and remove the $ from the selected
>columns.I have tried apply(My.Data, 2, function (x) any(grepl("$", x)))
>but it's not really working.Or:  apply(My.Data, 2,
>function(x){x<-gsub("\\$", "", x)}) works but it turns all the columns
>to a factor.
>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.

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


Re: [R] Identifying columns with specific character

2018-04-18 Thread Jim Lemon
Hi Farnoosh,
Perhaps this will help:

drop_dollar<-function(x) return(as.numeric(as.character(gsub("\\$","",x
sapply(My.Data,drop_dollar)

Jim

On Thu, Apr 19, 2018 at 7:23 AM, Farnoosh Sheikhi via R-help
 wrote:
> Hello,
> I have a data frame with 400 columns and wanted to filter character columns 
> with "$" in it.For example: >  x <- c("$5", "$89", "$10", "$34")  >  y <- 
> c(1:4)>  My.Data <- data.frame (x,y)> My.Datax y1  $5 12 $89 23 $10 34 
> $34 4
> I want to detect the columns with $ and remove the $ from the selected 
> columns.I have tried apply(My.Data, 2, function (x) any(grepl("$", x))) but 
> it's not really working.Or:  apply(My.Data, 2, function(x){x<-gsub("\\$", "", 
> x)}) works but it turns all the columns to a factor.
> 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] Identifying columns with specific character

2018-04-18 Thread Farnoosh Sheikhi via R-help
Hello,
I have a data frame with 400 columns and wanted to filter character columns 
with "$" in it.For example: >  x <- c("$5", "$89", "$10", "$34")  >  y <- 
c(1:4)>  My.Data <- data.frame (x,y)> My.Data    x y1  $5 12 $89 23 $10 34 $34 4
I want to detect the columns with $ and remove the $ from the selected 
columns.I have tried apply(My.Data, 2, function (x) any(grepl("$", x))) but 
it's not really working.Or:  apply(My.Data, 2, function(x){x<-gsub("\\$", "", 
x)}) works but it turns all the columns to a factor.
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.


Re: [R] merge two data frame based on equal and unequal comparisons

2018-04-18 Thread Ding, Yuan Chun
HI All,

I found that other R users experienced the same problem when using sqldf 
package. An expert provided solution, adding "method="raw" at the end as below, 
one or more of the columns in my data.frame are of class "AsIs" ( I don't know 
what it is) .  When sqldf retrieves the result from SQLite it will be numeric 
or character and since it was originally of class AsIs,  it tries to convert it 
back but R provides no as.AsIs,  so it fails; use method = "raw", so sqldf will 
not try to convert  the results from the database.

DMRlog2pbde47DMS <- sqldf("select * from DMR_log2pbde47 as a left join 
DMS_log2pbde47 as b 
   on a.chrom = b.chromo and a.start <= b.MAPINFO and 
a.end >= b.MAPINFO", method = "raw" )



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ding, Yuan Chun
Sent: Wednesday, April 18, 2018 10:38 AM
To: r-help@r-project.org
Subject: [R] merge two data frame based on equal and unequal comparisons

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





Dear R users,

I need to merge two data frames based on both equal and unequal comparisons.  
The "sqldf" package used to work well , but today, I cannot resolve the 
following error by reinstallation of the sqldf package.   Can anyone suggest a 
different way to perform this kind of merge function?

Thank you,

Ding

> DMRlog2pbde47DMS <- sqldf("select * from DMR_log2pbde47 as a left join 
> DMS_log2pbde47 as b
+on a.chrom = b.chromosome and a.start <= 
+ b.MAPINFO and a.end >= b.MAPINFO" )
Error in get(as.character(FUN), mode = "function", envir = envir) :
  object 'as.AsIs' of mode 'function' was not found



-
-SECURITY/CONFIDENTIALITY WARNING-
This message (and any attachments) are intended solely f...{{dropped:9}}

__
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 replace numeric value in the column contains Text (Factor)?

2018-04-18 Thread Marna Wagley
Hi David and Jeff,
Both ways worked for my table. it helped me a lot (I was really struggling
on it to change the values and thinking to do manually). You are great.
Thank you

On Wed, Apr 18, 2018 at 11:13 AM, David L Carlson  wrote:

> The simplest would be to convert precip to character and then back to a
> factor if you really want it to be a factor. This will also remove the
> levels that no longer exist.
>
> str(dat)
> # 'data.frame':   5 obs. of  3 variables:
> #  $ Sites : Factor w/ 5 levels "Site1","Site2",..: 1 2 3 4 5
> #  $ temp  : num  14 15 12 12.5 17
> #  $ precip: Factor w/ 5 levels "15","34","high",..: 3 4 5 2 1
>
> dat$precip <- as.character(dat$precip)
> dat[4:5, 3] <-"20"
> dat$precip <- factor(dat$precip)
>
> str(dat)
> # 'data.frame':   5 obs. of  3 variables:
> #  $ Sites : Factor w/ 5 levels "Site1","Site2",..: 1 2 3 4 5
> #  $ temp  : num  14 15 12 12.5 17
> #  $ precip: Factor w/ 4 levels "20","high","low",..: 2 3 4 1 1
>
> 
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
>
> -Original Message-
> From: R-help  On Behalf Of Marna Wagley
> Sent: Wednesday, April 18, 2018 12:56 PM
> To: r-help mailing list 
> Subject: [R] How to replace numeric value in the column contains Text
> (Factor)?
>
> Hi R user,
> Would you mind to help me on how I can change a value in a specific column
> and row in a big table? but the column of the table is a factor (not
> numeric).
> Here is an example. I want to change dat[4:5,3]<-"20" but it generated NA>
> do you have any suggestions for me?
>
> dat<-structure(list(Sites = structure(1:5, .Label = c("Site1", "Site2",
> "Site3", "Site4", "Site5"), class = "factor"), temp = c(14, 15, 12, 12.5,
> 17), precip = structure(c(3L, 4L, 5L, 2L, 1L), .Label = c("15", "34",
> "high", "low", "medium"), class = "factor")), .Names = c("Sites", "temp",
> "precip"), class = "data.frame", row.names = c(NA, -5L
> ))
> > dat[4:5, 3] <-"20"
> Warning message:
> In `[<-.factor`(`*tmp*`, iseq, value = c("20", "20")) :
>   invalid factor level, NA generated
> 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.
>

[[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] How to replace numeric value in the column contains Text (Factor)?

2018-04-18 Thread David L Carlson
The simplest would be to convert precip to character and then back to a factor 
if you really want it to be a factor. This will also remove the levels that no 
longer exist.

str(dat)
# 'data.frame':   5 obs. of  3 variables:
#  $ Sites : Factor w/ 5 levels "Site1","Site2",..: 1 2 3 4 5
#  $ temp  : num  14 15 12 12.5 17
#  $ precip: Factor w/ 5 levels "15","34","high",..: 3 4 5 2 1

dat$precip <- as.character(dat$precip)
dat[4:5, 3] <-"20"
dat$precip <- factor(dat$precip)

str(dat)
# 'data.frame':   5 obs. of  3 variables:
#  $ Sites : Factor w/ 5 levels "Site1","Site2",..: 1 2 3 4 5
#  $ temp  : num  14 15 12 12.5 17
#  $ precip: Factor w/ 4 levels "20","high","low",..: 2 3 4 1 1


David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-Original Message-
From: R-help  On Behalf Of Marna Wagley
Sent: Wednesday, April 18, 2018 12:56 PM
To: r-help mailing list 
Subject: [R] How to replace numeric value in the column contains Text (Factor)?

Hi R user,
Would you mind to help me on how I can change a value in a specific column and 
row in a big table? but the column of the table is a factor (not numeric).
Here is an example. I want to change dat[4:5,3]<-"20" but it generated NA> do 
you have any suggestions for me?

dat<-structure(list(Sites = structure(1:5, .Label = c("Site1", "Site2", 
"Site3", "Site4", "Site5"), class = "factor"), temp = c(14, 15, 12, 12.5, 17), 
precip = structure(c(3L, 4L, 5L, 2L, 1L), .Label = c("15", "34", "high", "low", 
"medium"), class = "factor")), .Names = c("Sites", "temp", "precip"), class = 
"data.frame", row.names = c(NA, -5L
))
> dat[4:5, 3] <-"20"
Warning message:
In `[<-.factor`(`*tmp*`, iseq, value = c("20", "20")) :
  invalid factor level, NA generated
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] How to replace numeric value in the column contains Text (Factor)?

2018-04-18 Thread Jeff Newmiller
I would recommend that you avoid converting (or letting R convert for you) your 
textual data values into factors until you have finished doing this kind of 
modification.

You can restore the column to character data type either re-reading it with the 
stringsAsFactors=FALSE option to read.table/read.csv functions, or by 
converting it:

dat[[ 3 ]] <- as.character( dat[[ 3 ]] )

and then your replacement will work.


On April 18, 2018 12:55:40 PM CDT, Marna Wagley  wrote:
>Hi R user,
>Would you mind to help me on how I can change a value in a specific
>column
>and row in a big table? but the column of the table is a factor (not
>numeric).
>Here is an example. I want to change dat[4:5,3]<-"20" but it generated
>NA>
>do you have any suggestions for me?
>
>dat<-structure(list(Sites = structure(1:5, .Label = c("Site1", "Site2",
>"Site3", "Site4", "Site5"), class = "factor"), temp = c(14, 15,
>12, 12.5, 17), precip = structure(c(3L, 4L, 5L, 2L, 1L), .Label =
>c("15",
>"34", "high", "low", "medium"), class = "factor")), .Names = c("Sites",
>"temp", "precip"), class = "data.frame", row.names = c(NA, -5L
>))
>> dat[4:5, 3] <-"20"
>Warning message:
>In `[<-.factor`(`*tmp*`, iseq, value = c("20", "20")) :
>  invalid factor level, NA generated
>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.

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


[R] How to replace numeric value in the column contains Text (Factor)?

2018-04-18 Thread Marna Wagley
Hi R user,
Would you mind to help me on how I can change a value in a specific column
and row in a big table? but the column of the table is a factor (not
numeric).
Here is an example. I want to change dat[4:5,3]<-"20" but it generated NA>
do you have any suggestions for me?

dat<-structure(list(Sites = structure(1:5, .Label = c("Site1", "Site2",
"Site3", "Site4", "Site5"), class = "factor"), temp = c(14, 15,
12, 12.5, 17), precip = structure(c(3L, 4L, 5L, 2L, 1L), .Label = c("15",
"34", "high", "low", "medium"), class = "factor")), .Names = c("Sites",
"temp", "precip"), class = "data.frame", row.names = c(NA, -5L
))
> dat[4:5, 3] <-"20"
Warning message:
In `[<-.factor`(`*tmp*`, iseq, value = c("20", "20")) :
  invalid factor level, NA generated
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] merge two data frame based on equal and unequal comparisons

2018-04-18 Thread Ding, Yuan Chun
Dear R users,

I need to merge two data frames based on both equal and unequal comparisons.  
The "sqldf" package used to work well , but today, I cannot resolve the 
following error by reinstallation of the sqldf package.   Can anyone suggest a 
different way to perform this kind of merge function?

Thank you,

Ding

> DMRlog2pbde47DMS <- sqldf("select * from DMR_log2pbde47 as a left join 
> DMS_log2pbde47 as b
+on a.chrom = b.chromosome and a.start <= b.MAPINFO 
and a.end >= b.MAPINFO" )
Error in get(as.character(FUN), mode = "function", envir = envir) :
  object 'as.AsIs' of mode 'function' was not found



-
-SECURITY/CONFIDENTIALITY WARNING-
This message (and any attachments) are intended solely f...{{dropped:22}}

__
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] Event-triggered change in value with a time-delay

2018-04-18 Thread David Winsemius

> On Apr 18, 2018, at 1:04 AM, Hannah Meredith  wrote:
> 
> Hello,
> 
> I am solving a set of ODEs using deSolve and have run into a problem I
> would appreciate some advice on. One of the parameters (m) in the ODEs
> changes between two states when one of the variables (D) crosses a
> threshold (D_T) for the first time in either direction. Additionally, when
> the variable crosses the threshold (either by increasing or decreasing),
> there is a time delay (delay) before the parameter shifts values.

I think you migh not have fully reviewed the available functions in that 
package. Doing an sos::findFn-search on ODE's with time delay brings up help 
pages for the `dede` function in deSolve. 

For the conditional value of the within regime-fixed parameter `m`, couldn't 
you just use this:

... + m*(6.8+ 3.2*(D < D_T))

Caveat: very lightly tested in your toy example, which did generate a result 
where D cross that threshold without blowing up.

-- 

David.


> 
> Toy model:
> # define parameters
> P <- c(m = 10,
>   R_1 = 0.5,
>   R_2 = 0.1,
>   D_0 = 50,
>   D_T = 5,
>   delay = 3
> )
> # set initial values
> y_0 <- c(D = 0, Y = 1)
> 
> # set timesteps
> times <- seq(0, 100, length = 101)
> 
> # define function
> bit <- function(t,y,parms){
>  with(as.list(c(parms,y)),{
> 
> 
># How I would implement the change if there was no time delay
># m <- ifelse(D>=D_T, m*.68, m)
> 
># Option 1: nested if statements with time delay
># if (D >= D_T) {
>#   t_start1 <- t + delay
>#   if (t >= t_start1){
># m <- 6.8
>#   }
># }
># if (D < D_T) {
>#   t_start2<- t + delay
>#   if (t >= t_start2){
># m <- 10
>#   }
># }
> 
> 
>dD <- D_0 * (R_1 / (R_1 - R_2)) * (-R_2 * exp(-R_2 * t) + R_1 *
> exp(-R_1 * t))
>dY <- Y + m;
>res <- c(dD, dY)
>list(res, m = m)
>  })
> }
> 
> 
> # Solve model
> library(deSolve)
> out <- ode(y = y_0, times = times, func = bit, parms = P)
> out.df <- as.data.frame(out)
> ~~
> I have come up with a number of ideas, but I either haven't been able to
> get them to work or don't know if R has a command for it:
> 
> 1. Nested "if" statements with something to track time (as shown above).
> One issue here is* t-start *is redefined with each time step in the ode
> solver so *t* never reaches *t_start +delay*.
> 
> 2. Event triggered changes. From the examples I have found (link
>  p.
> 24-25), the time at which the event happens is either pre-set or occurs at
> a root of the ODE.  Also- would this strategy require multiple events? One
> event in which the variable crossing the threshold triggers a timer,
> another for the timer triggering the parameter change?
> 
> 3. Lagvalue. This might take care of the time lag component, but I am still
> struggling to understand (1) how lagvalue works and (2) how to integrate
> both the threshold and timer components.
> 
>   if ( D < D_T )
> m<- ifelse(lagvalue(t-delay)<=0, 6.8, 10)
>   end
> 
> 4. Sigmoidal function. Someone suggested this to me earlier, but I am not
> sure how this would work. Is it possible to have a sigmoidal function that
> switches repeatedly between two states (as opposed to the characteristic S
> curve that transitions once from one state to another)?
> 
> 5. Mathmematica has a WhenEvent function- is there something similar in R?
> 
> 
> Thank you for your time and any tips you might have!
> 
>   [[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

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

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


Re: [R] Problem with regression line

2018-04-18 Thread CHATTON Anne via R-help
Hi Gerrit!
Thank you so much! I mistakenly reversed the order of the variables of the 
regression. Actually what I meant to write was: lm(BloodPressure ~ Age).
Best,
Anne

-Message d'origine-
De : Gerrit Eichner [mailto:gerrit.eich...@math.uni-giessen.de] 
Envoyé : mercredi 18 avril 2018 16:08
À : CHATTON Anne; r-help@R-project.org
Objet : Re: [R] Problem with regression line

Hi, Anne,

assign Age and Bloodpressure in the correct order to the axes in your call to 
plot as in:

plot(y = Age, x = BloodPressure)
abline(SimpleLinearReg1)


  Hth  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
http://www.uni-giessen.de/eichner
-


Am 18.04.2018 um 15:26 schrieb CHATTON Anne via R-help:
> Hello,
> 
> I am trying to graph a regression line using the followings:
> 
> Age <- c(39, 47, 45, 47, 65, 46, 67, 42, 67, 56, 64, 56, 59, 34, 42, 
> 48, 45, 17, 20, 19, 36, 50, 39, 21, 44, 53, 63, 29, 25, 69) 
> BloodPressure <- c(144, 220, 138, 145, 162, 142, 170, 124, 158, 154, 
> 162, 150, 140, 110, 128, 130, 135, 114, 116, 124, 136, 142, 120, 120, 
> 160, 158, 144, 130, 125, 175) SimpleLinearReg1=lm(Age ~ BloodPressure)
> summary(SimpleLinearReg1)
> eq = paste0("y = ", round(coeff[2],1), "*x ", round(coeff[1],1)) 
> plot(Age, BloodPressure, pch = 16, cex = 1.3, col = "blue", main = eq, 
> xlab = "Age (Year)", ylab = "Blood Pressure (mmHg)") 
> abline(SimpleLinearReg1, col="red")
> mean(Age)
> mean(BloodPressure)
> abline(h=142.53, col="green")
> abline(v=45.13, col="green")
> 
> But I cannot get the regression line. Can anybody tell me what's wrong with 
> the codes ? I would appreciate very much. Thanks for any help.
> 
> Anne
> 
>   [[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.
> 


-- 

  Best regards  --  Gerrit
  Best regards  --  Gerrit Eichner
  Hth  --  Gerrit
  Viele Grüße  --  Gerrit
  Viele Grüße  --  Gerrit Eichner
  Viele Grüße  --  GE
  Freundliche Grüße  --  Gerrit Eichner
  Freundliche Grüße  --  GE
  Grüße  --  Gerrit
  Grüße  --  Gerrit Eichner
  Grüße  --  GE
  Gruß  --  G

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
http://www.uni-giessen.de/eichner
-
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with regression line

2018-04-18 Thread David L Carlson
To expand on Eik Vettorazzi's answer:

Don't use html emails. When the mailing list converts it to plain text, it 
often re-wraps lines so that your code becomes jumbled.

First, you did not define coeff. You need to add

coeff <- coef(SimpleLinearReg1)

Second, you should use the formula you used for the regression in the plot 
command or the correct order (plot uses the first variable as the x-axis and 
the second variable as the y-axis while the formula specification uses the 
variable on the left of the tilde (~) as the y-axis and the variable on the 
right of the tilde as the x-axis. Your regression predicts age (response) from 
blood pressure (explanatory) so abline() assumes age is on the y-axis and blood 
pressure is on the x-axis, but you reversed that so the line is "plotted", but 
it is outside the plot window. 

Either change the regression formula to BloodPressure~Age (which makes more 
sense than predicting age from blood pressure) or change the plot command to 
plot(BloodPressure, Age, ...) and change the xlab to ylab and ylab to xlab).


David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-Original Message-
From: R-help  On Behalf Of Eik Vettorazzi
Sent: Wednesday, April 18, 2018 9:25 AM
To: CHATTON Anne ; r-help@R-project.org
Subject: Re: [R] Problem with regression line

Hi Anne,
I would suggest to change the linear model to lm(BloodPressure~Age), as this 
model makes more sense in biological means (you would assume that age 
influences pressure, not vice versa) and also obeys the statistical assumption 
of weak exogeneity, that age can be measured without error, at least compared 
to error-prone bp measures.

Cheers

Am 18.04.2018 um 16:07 schrieb Gerrit Eichner:
> Hi, Anne,
> 
> assign Age and Bloodpressure in the correct order to the axes in your 
> call to plot as in:
> 
> plot(y = Age, x = BloodPressure)
> abline(SimpleLinearReg1)
> 
> 
>  Hth  --  Gerrit
> 
> -
> Dr. Gerrit Eichner   Mathematical Institute, Room 212 
> gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
> Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany 
> http://www.uni-giessen.de/eichner
> -
> 
> 
> Am 18.04.2018 um 15:26 schrieb CHATTON Anne via R-help:
>> Hello,
>>
>> I am trying to graph a regression line using the followings:
>>
>> Age <- c(39, 47, 45, 47, 65, 46, 67, 42, 67, 56, 64, 56, 59, 34, 42, 
>> 48, 45, 17, 20, 19, 36, 50, 39, 21, 44, 53, 63, 29, 25, 69) 
>> BloodPressure <- c(144, 220, 138, 145, 162, 142, 170, 124, 158, 154, 
>> 162, 150, 140, 110, 128, 130, 135, 114, 116, 124, 136, 142, 120, 120, 
>> 160, 158, 144, 130, 125, 175) SimpleLinearReg1=lm(Age ~ 
>> BloodPressure)
>> summary(SimpleLinearReg1)
>> eq = paste0("y = ", round(coeff[2],1), "*x ", round(coeff[1],1)) 
>> plot(Age, BloodPressure, pch = 16, cex = 1.3, col = "blue", main = 
>> eq, xlab = "Age (Year)", ylab = "Blood Pressure (mmHg)") 
>> abline(SimpleLinearReg1, col="red")
>> mean(Age)
>> mean(BloodPressure)
>> abline(h=142.53, col="green")
>> abline(v=45.13, col="green")
>>
>> But I cannot get the regression line. Can anybody tell me what's 
>> wrong with the codes ? I would appreciate very much. Thanks for any help.
>>
>> Anne
>>
>> [[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.
>>
> 
> 

--
Eik Vettorazzi

Department of Medical Biometry and Epidemiology University Medical Center 
Hamburg-Eppendorf

Martinistrasse 52
building W 34
20246 Hamburg

Phone: +49 (0) 40 7410 - 58243
Fax:   +49 (0) 40 7410 - 57790
Web: www.uke.de/imbe
--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Martina Saurin (komm.) 
_

SAVE PAPER - THINK BEFORE PRINTING
__
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-

Re: [R] Problem with regression line

2018-04-18 Thread Eik Vettorazzi
Hi Anne,
I would suggest to change the linear model to lm(BloodPressure~Age), as
this model makes more sense in biological means (you would assume that
age influences pressure, not vice versa) and also obeys the statistical
assumption of weak exogeneity, that age can be measured without error,
at least compared to error-prone bp measures.

Cheers

Am 18.04.2018 um 16:07 schrieb Gerrit Eichner:
> Hi, Anne,
> 
> assign Age and Bloodpressure in the correct order
> to the axes in your call to plot as in:
> 
> plot(y = Age, x = BloodPressure)
> abline(SimpleLinearReg1)
> 
> 
>  Hth  --  Gerrit
> 
> -
> Dr. Gerrit Eichner   Mathematical Institute, Room 212
> gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
> Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
> http://www.uni-giessen.de/eichner
> -
> 
> 
> Am 18.04.2018 um 15:26 schrieb CHATTON Anne via R-help:
>> Hello,
>>
>> I am trying to graph a regression line using the followings:
>>
>> Age <- c(39, 47, 45, 47, 65, 46, 67, 42, 67, 56, 64, 56, 59, 34, 42,
>> 48, 45,
>> 17, 20, 19, 36, 50, 39, 21, 44, 53, 63, 29, 25, 69)
>> BloodPressure <- c(144, 220, 138, 145, 162, 142, 170, 124, 158, 154, 162,
>> 150, 140, 110, 128, 130, 135, 114, 116, 124, 136, 142, 120, 120, 160,
>> 158,
>> 144, 130, 125, 175)
>> SimpleLinearReg1=lm(Age ~ BloodPressure)
>> summary(SimpleLinearReg1)
>> eq = paste0("y = ", round(coeff[2],1), "*x ", round(coeff[1],1))
>> plot(Age, BloodPressure, pch = 16, cex = 1.3, col = "blue",
>> main = eq, xlab = "Age (Year)", ylab = "Blood Pressure (mmHg)")
>> abline(SimpleLinearReg1, col="red")
>> mean(Age)
>> mean(BloodPressure)
>> abline(h=142.53, col="green")
>> abline(v=45.13, col="green")
>>
>> But I cannot get the regression line. Can anybody tell me what's wrong
>> with the codes ? I would appreciate very much. Thanks for any help.
>>
>> Anne
>>
>> [[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.
>>
> 
> 

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistrasse 52
building W 34
20246 Hamburg

Phone: +49 (0) 40 7410 - 58243
Fax:   +49 (0) 40 7410 - 57790
Web: www.uke.de/imbe
--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Martina Saurin (komm.)
_

SAVE PAPER - THINK BEFORE PRINTING
__
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] Reasons to Use R in a Public Administrations and Ideas for a Short Training

2018-04-18 Thread David L Carlson
Courses are good for people who are motivated to learn. It sounds like you need 
to generate the motivation first. Why not develop 4 - 5 case study examples? 
Kinds of analyses currently performed on Excel that would be easier to 
replicate and repeat using simple R scripts so that you are showing how it 
would be done in Excel and then how it would be done in R structuring the code 
so that running a similar analysis requires only minor adjustments in contrast 
to Excel which might involve copying formula blocks into a new spreadsheet tab 
or creating templates that fail and are hard to debug.


David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-Original Message-
From: R-help  On Behalf Of Lorenzo Isella
Sent: Wednesday, April 18, 2018 8:47 AM
To: r-help@r-project.org
Subject: [R] Reasons to Use R in a Public Administrations and Ideas for a Short 
Training

Dear All,
Ages ago I posted to this mailing list asking for advice about to evangelize 
the use of R in an international public administration where the fact that R is 
free is not a decisive factor (actually its being "freeware" may even be seen 
negatively). After a long time, I think it is worthwhile asking the question 
again and see what suggestions other users have.

Another question related to that: let's say you have the possibility to give a 
short course (most likely short of 10 hours) to people who are not trained in 
statistics (people with a background in international relations or political 
scientists frustrated at Excel and who sometimes have to do a number of 
repetitive tasks). How would you formulate a short training to make them not R 
proficient users, but aware and looking forward to learning more about R?
Any suggestion and/or pointer to online resources is appreciated.
Many thanks

Lorenzo

__
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] Problem with regression line

2018-04-18 Thread Gerrit Eichner

Hi, Anne,

assign Age and Bloodpressure in the correct order
to the axes in your call to plot as in:

plot(y = Age, x = BloodPressure)
abline(SimpleLinearReg1)


 Hth  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
http://www.uni-giessen.de/eichner
-


Am 18.04.2018 um 15:26 schrieb CHATTON Anne via R-help:

Hello,

I am trying to graph a regression line using the followings:

Age <- c(39, 47, 45, 47, 65, 46, 67, 42, 67, 56, 64, 56, 59, 34, 42, 48, 45,
17, 20, 19, 36, 50, 39, 21, 44, 53, 63, 29, 25, 69)
BloodPressure <- c(144, 220, 138, 145, 162, 142, 170, 124, 158, 154, 162,
150, 140, 110, 128, 130, 135, 114, 116, 124, 136, 142, 120, 120, 160, 158,
144, 130, 125, 175)
SimpleLinearReg1=lm(Age ~ BloodPressure)
summary(SimpleLinearReg1)
eq = paste0("y = ", round(coeff[2],1), "*x ", round(coeff[1],1))
plot(Age, BloodPressure, pch = 16, cex = 1.3, col = "blue",
main = eq, xlab = "Age (Year)", ylab = "Blood Pressure (mmHg)")
abline(SimpleLinearReg1, col="red")
mean(Age)
mean(BloodPressure)
abline(h=142.53, col="green")
abline(v=45.13, col="green")

But I cannot get the regression line. Can anybody tell me what's wrong with the 
codes ? I would appreciate very much. Thanks for any help.

Anne

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




--

 Best regards  --  Gerrit
 Best regards  --  Gerrit Eichner
 Hth  --  Gerrit
 Viele Grüße  --  Gerrit
 Viele Grüße  --  Gerrit Eichner
 Viele Grüße  --  GE
 Freundliche Grüße  --  Gerrit Eichner
 Freundliche Grüße  --  GE
 Grüße  --  Gerrit
 Grüße  --  Gerrit Eichner
 Grüße  --  GE
 Gruß  --  G

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
http://www.uni-giessen.de/eichner

__
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-18 Thread Ted Harding
Not necessarily. The R-help archives are publicly accessible,
with a "sort by date" option. So if someone sets up a web=page
monitor which reports back when new messages appear there
(at the bpottom end), then their email addresses are readily
copied (subject to " at " --> "@".

Once they have the address then anything can happen!

Best wishes,
Ted (eagerly awaiting attempted seduction ... ).

On Wed, 2018-04-18 at 10:36 +, Fowler, Mark wrote:
> 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] 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 
> 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> 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 po

Re: [R] nMDS with R: missing values

2018-04-18 Thread David L Carlson
I'm not sure how you are incorporating time period into your data structure. 
Typically we are looking at plots or assemblages as the rows and taxa as the 
columns. Time period adds a third dimension that could be added as blocks of 
rows. For example, depending on the resolution of your data, one approach would 
be to have up to 8 rows for each locality: Loc1.1000, Loc1.2000, . . . 
Loc1.8000. If a locality did not have certain millennia represented you would 
just leave them out.

David C

-Original Message-
From: Jessie Woodbridge  
Sent: Wednesday, April 18, 2018 3:42 AM
To: David L Carlson 
Subject: RE: nMDS with R: missing values

Dear Prof Carlson,

Thank you for your reply. I'm using 'vegan' with 'vegdist' and 'bray'. I have a 
selection of datasets that cover different time periods (converted to 
z-scores), so a record that starts 5000 years ago would have missing data 
before this date when other records cover the last 8000 years. I need to build 
into the nMDS the fact that this isn't a zero score, but reflects absence of 
data. In the results it seems that datasets that cover the same time periods 
are being grouped together because they have zero values at the same times. I 
hope that makes sense. Any suggestions would be greatly appreciated.

There is no regular pattern to the position of the missing values, so I can't 
remove certain rows or columns. Thank you for the suggestion of using dist() 
and na.rm=TRUE. I will try using these approaches.

Kind regards,

Jessie


Dr Jessie Woodbridge
Geography, Earth and Environmental Sciences B416, Portland Square, University 
of Plymouth, UK
01752 585920
Leverhulme Trust-funded ‘Changing the face of the Mediterranean’ project 
Leverhulme Trust-funded Deforesting Europe project

-Original Message-
From: David L Carlson 
Sent: 17 April 2018 21:13
To: Jessie Woodbridge ; r-help@r-project.org
Subject: RE: nMDS with R: missing values

I think you will have to provide some more information. What function/package 
are you using for nMDS (eg. isoMDS in MASS, monoMDS in vegan)? What 
function/package are you using to compute your distance/dissimilarities (eg. 
dist in stats, vegdist in vegan)?

Zero represents absence. It is not a missing value, so that part of your 
question is not clear.

The dist() function computes distance ignoring missing values if they are 
properly represented as NAs in the data. The vegdist() function does this if 
na.rm=TRUE.

The results will be affected by how much data is missing. It would be useful to 
know if the missing values are concentrated in particular rows or columns so 
that eliminating a few rows and columns could substantially reduce the 
percentage of missing values.


David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352


0-Original Message-
From: R-help  On Behalf Of Jessie Woodbridge
Sent: Tuesday, April 17, 2018 2:05 PM
To: r-help@r-project.org
Subject: [R] nMDS with R: missing values

Dear All,

I was wondering whether anyone might be able to provide some advice with an 
nMDS / R problem. I’m trying to run nMDS on a dataset that contains many 
missing values and was wondering how I can account for the missing values when 
running nMDS? It seems as though the data are being grouped depending on where 
the zero values appear. Any suggestions greatly appreciated. Thank you very 
much in advance.

Apologies if this message isn’t relevant to you.

Kind regards,

Jessie


[http://www.plymouth.ac.uk/images/email_footer.gif]

This email and any files with it are confidential and intended solely for the 
use of the recipient to whom it is addressed. If you are not the intended 
recipient then copying, distribution or other use of the information contained 
is strictly prohibited and you should not rely on it. If you have received this 
email in error please let the sender know immediately and delete it from your 
system(s). Internet emails are not necessarily secure. While we take every 
care, Plymouth University accepts no responsibility for viruses and it is your 
responsibility to scan emails and their attachments. Plymouth University does 
not accept responsibility for any changes made after it was sent. Nothing in 
this email or its attachments constitutes an order for goods or services unless 
accompanied by an official order form.
__
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.

[http://www.plymouth.ac.uk/images/email_footer.gif]

This email and any files with it are confidential and intended solely fo

[R] Reasons to Use R in a Public Administrations and Ideas for a Short Training

2018-04-18 Thread Lorenzo Isella

Dear All,
Ages ago I posted to this mailing list asking for advice about to
evangelize the use of R in an international public
administration where the fact that R is free is not a decisive factor
(actually its being "freeware" may even be seen negatively). After a
long time, I think it is worthwhile asking the question again and see
what suggestions other users have.

Another question related to that: let's say you have the possibility
to give a short course (most likely short of 10 hours) to people
who are not trained in statistics (people with a background in
international relations or political scientists frustrated at Excel
and who sometimes have to do a number of repetitive tasks). How would
you formulate a short training to make them not R proficient users,
but aware and looking forward to learning more about R?
Any suggestion and/or pointer to online resources is appreciated.
Many thanks

Lorenzo

__
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] Problem with regression line

2018-04-18 Thread CHATTON Anne via R-help
Hello,

I am trying to graph a regression line using the followings:

Age <- c(39, 47, 45, 47, 65, 46, 67, 42, 67, 56, 64, 56, 59, 34, 42, 48, 45,
17, 20, 19, 36, 50, 39, 21, 44, 53, 63, 29, 25, 69)
BloodPressure <- c(144, 220, 138, 145, 162, 142, 170, 124, 158, 154, 162,
150, 140, 110, 128, 130, 135, 114, 116, 124, 136, 142, 120, 120, 160, 158,
144, 130, 125, 175)
SimpleLinearReg1=lm(Age ~ BloodPressure)
summary(SimpleLinearReg1)
eq = paste0("y = ", round(coeff[2],1), "*x ", round(coeff[1],1))
plot(Age, BloodPressure, pch = 16, cex = 1.3, col = "blue",
main = eq, xlab = "Age (Year)", ylab = "Blood Pressure (mmHg)")
abline(SimpleLinearReg1, col="red")
mean(Age)
mean(BloodPressure)
abline(h=142.53, col="green")
abline(v=45.13, col="green")

But I cannot get the regression line. Can anybody tell me what's wrong with the 
codes ? I would appreciate very much. Thanks for any help.

Anne

[[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] mgcv::gamm error when combining random smooths and correlation/autoregressive term

2018-04-18 Thread Mathew Guilfoyle
I am having difficulty fitting a mgcv::gamm model that includes both a random 
smooth term (i.e. 'fs' smooth) and autoregressive errors.  Standard smooth 
terms with a factor interaction using the 'by=' option work fine.  Both on my 
actual data and a toy example (below) I am getting the same error so am 
inclined to wonder if this is either a bug or a model that gamm is simply 
unable to fit?

Any insight or suggestions would be much appreciated.

M


Example:

library('mgcv')
set.seed(1)
df = data.frame(index=rep(1:10,5), x=runif(50,0,1), subject = 
as.factor(sort(rep(1:5,10

# random intercept
m1 = gamm(x~s(index), random=list(subject=~1), data=df, method = 'REML')

#factor interaction, random intercept, AR errors
m2 = gamm(x~s(index, by=subject), random=list(subject=~1), 
correlation=corAR1(form=~index|subject), data=df, method = 'REML')

#factor interaction, random intercept and slope, AR errors
m3 = gamm(x~s(index, by=subject), random=list(subject=~index), 
correlation=corAR1(form=~index|subject), data=df, method = 'REML')

#random smooth on its own works ok
m4 = gamm(x~s(index, subject, bs='fs'), data=df, method = 'REML')


#combination of 'fs' smooth and AR term generates the error: "Error in 
matrix(0, size.cg[i], size.cg[i]) : object 'size.cg' not found"
#the grouping term ( |subject ) is redundant in corAR1 as the mgcv 
documentation indicates that gamm will assume the grouping 
#from the random smooth term; the same error happens irrespective of whether 
the grouping is included in corAR1 or not.

m5 = gamm(x~s(index, subject, bs='fs'), 
correlation=corAR1(form=~index|subject), data=df, method = 'REML')__
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] Understanding which

2018-04-18 Thread Ashim Kapoor
Dear Jeff and Eric,

Okay and many thanks.
Best Regards,
Ashim

On Wed, Apr 18, 2018 at 4:56 PM, Jeff Newmiller 
wrote:

> Look at
>
> which(x>100)
>
> This is a zero-length vector. The negative of nothing is nothing, not a
> list of all possible index values.
>
> Do you want
>
> x[ !( x > 100 ) ]
>
> ?
>
> On April 18, 2018 6:13:30 AM CDT, Ashim Kapoor 
> wrote:
> >Dear All,
> >
> >Here is a reprex:
> >
> >> x<- 1:100
> >> x[-which(x>100)]
> >integer(0)
> >
> >In words, I am finding out which indices correspond to values in x
> >which
> >are  greater than  100 ( there are no such items ) . Then I remove
> >those
> >indices. I should get back the x that I started with since there are no
> >items in x which are bigger than 100 . Instead, it is returning an
> >empty
> >vector.
> >
> >Why is this ? What am I misunderstanding?
> >
> >Best Regards,
> >Ashim
> >
> >   [[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.
>
> --
> Sent from my phone. Please excuse my brevity.
>

[[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] Understanding which

2018-04-18 Thread Jeff Newmiller
Look at

which(x>100)

This is a zero-length vector. The negative of nothing is nothing, not a list of 
all possible index values.

Do you want

x[ !( x > 100 ) ]

?

On April 18, 2018 6:13:30 AM CDT, Ashim Kapoor  wrote:
>Dear All,
>
>Here is a reprex:
>
>> x<- 1:100
>> x[-which(x>100)]
>integer(0)
>
>In words, I am finding out which indices correspond to values in x
>which
>are  greater than  100 ( there are no such items ) . Then I remove
>those
>indices. I should get back the x that I started with since there are no
>items in x which are bigger than 100 . Instead, it is returning an
>empty
>vector.
>
>Why is this ? What am I misunderstanding?
>
>Best Regards,
>Ashim
>
>   [[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.

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


Re: [R] Understanding which

2018-04-18 Thread Eric Berger
Here's a hint:

> y <- which(x>100)
> identical(y,y)
# TRUE
> identical(y,-y)
# TRUE

The '-' is misleading - it is absorbed into the empty y, leaving the
request x[y] to be x for an empty set of indices.

HTH,
Eric



On Wed, Apr 18, 2018 at 2:13 PM, Ashim Kapoor  wrote:

> Dear All,
>
> Here is a reprex:
>
> > x<- 1:100
> > x[-which(x>100)]
> integer(0)
>
> In words, I am finding out which indices correspond to values in x which
> are  greater than  100 ( there are no such items ) . Then I remove those
> indices. I should get back the x that I started with since there are no
> items in x which are bigger than 100 . Instead, it is returning an empty
> vector.
>
> Why is this ? What am I misunderstanding?
>
> Best Regards,
> Ashim
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] Understanding which

2018-04-18 Thread Ashim Kapoor
Dear All,

Here is a reprex:

> x<- 1:100
> x[-which(x>100)]
integer(0)

In words, I am finding out which indices correspond to values in x which
are  greater than  100 ( there are no such items ) . Then I remove those
indices. I should get back the x that I started with since there are no
items in x which are bigger than 100 . Instead, it is returning an empty
vector.

Why is this ? What am I misunderstanding?

Best Regards,
Ashim

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

[R] Event-triggered change in value with a time-delay

2018-04-18 Thread Hannah Meredith
Hello,

I am solving a set of ODEs using deSolve and have run into a problem I
would appreciate some advice on. One of the parameters (m) in the ODEs
changes between two states when one of the variables (D) crosses a
threshold (D_T) for the first time in either direction. Additionally, when
the variable crosses the threshold (either by increasing or decreasing),
there is a time delay (delay) before the parameter shifts values.

Toy model:
# define parameters
P <- c(m = 10,
   R_1 = 0.5,
   R_2 = 0.1,
   D_0 = 50,
   D_T = 5,
   delay = 3
)
# set initial values
y_0 <- c(D = 0, Y = 1)

# set timesteps
times <- seq(0, 100, length = 101)

# define function
bit <- function(t,y,parms){
  with(as.list(c(parms,y)),{


# How I would implement the change if there was no time delay
# m <- ifelse(D>=D_T, m*.68, m)

# Option 1: nested if statements with time delay
# if (D >= D_T) {
#   t_start1 <- t + delay
#   if (t >= t_start1){
# m <- 6.8
#   }
# }
# if (D < D_T) {
#   t_start2<- t + delay
#   if (t >= t_start2){
# m <- 10
#   }
# }


dD <- D_0 * (R_1 / (R_1 - R_2)) * (-R_2 * exp(-R_2 * t) + R_1 *
exp(-R_1 * t))
dY <- Y + m;
res <- c(dD, dY)
list(res, m = m)
  })
}


# Solve model
library(deSolve)
out <- ode(y = y_0, times = times, func = bit, parms = P)
out.df <- as.data.frame(out)
~~
I have come up with a number of ideas, but I either haven't been able to
get them to work or don't know if R has a command for it:

1. Nested "if" statements with something to track time (as shown above).
One issue here is* t-start *is redefined with each time step in the ode
solver so *t* never reaches *t_start +delay*.

2. Event triggered changes. From the examples I have found (link
 p.
24-25), the time at which the event happens is either pre-set or occurs at
a root of the ODE.  Also- would this strategy require multiple events? One
event in which the variable crossing the threshold triggers a timer,
another for the timer triggering the parameter change?

3. Lagvalue. This might take care of the time lag component, but I am still
struggling to understand (1) how lagvalue works and (2) how to integrate
both the threshold and timer components.

   if ( D < D_T )
 m<- ifelse(lagvalue(t-delay)<=0, 6.8, 10)
   end

4. Sigmoidal function. Someone suggested this to me earlier, but I am not
sure how this would work. Is it possible to have a sigmoidal function that
switches repeatedly between two states (as opposed to the characteristic S
curve that transitions once from one state to another)?

5. Mathmematica has a WhenEvent function- is there something similar in R?


Thank you for your time and any tips you might have!

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