[R] switch parameter in MSwM package

2017-03-23 Thread Ashim Kapoor
Dear All,

I am currently trying to use the Markov Switching Models(MSwM) package in
R.I am not sure as to how to use the switch parameter.  From what I
understand, switch is a boolean vector which says what parameters are
regime dependent.

My confusion is that what is the order of the parameters when I say switch
= rep(TRUE,6) ? For instance what are parameters 1/2/3 ?

The first parameter is probably the regime dependent intercept. The last
parameter I think will be regime dependent variance.

Can someone please show me how I can code the following equation?

y_t =mu_{S_t} + Phi_{S_t, 1 } * ( y_{t-1} - mu_{S_{t-1} } )  + sigma_{S_t}
* epsilon_t

where epsilon_t is N(0,1).

Is parameter 2 corresponding to Phi_{S_t,1}  or mu_{S_{t-1}} ?

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] How to change parameter values as a function to time with the package "deSolve"

2017-03-23 Thread David Winsemius

> On Mar 23, 2017, at 2:59 PM, Marine Regis  wrote:
> 
> Hello,
> 
> I am trying to solve an ODE in R using deSolve. With the following code, I 
> expected the parameter �gamma0� takes the values 5 at time step 0, 1, 2, 3, 
> 4, 5, 6, 7, 8, 9 and 10, and 0 otherwise. However, the print(gamma0) shows 
> that �gamma0� stays at 0.
> 
> Here is my ODE:
> 
> param <- c(a = 0.1, b = 1)
> yini <- c(alpha0 = 0, beta0 = 0)
> 
> mod <- function(times, yini, param) {
> 
>  with(as.list(c(yini, parameters)), {
> 
>  gamma0 <- ifelse(times %in% seq(0,10,1), 5, 0)
> 
>  # print(gamma0)
> 
>  dalpha0 <- - a*alpha0 + gamma0
>  dbeta0 <- a*alpha0 - b*beta0
>  return(list(c(dalpha0, dbeta0)))
> 
>  })}
> 
> times <- seq(from = 0, to = 10, by = 1/24)
> out <- ode(func = mod, times = times, y = yini, parms = param)
> plot(out, lwd = 2, xlab = "day")
> 
> 
> What am I doing wrong? Thanks in advance for your help!

When I execute that code I get:

Error in as.list(c(yini, parameters)) : object 'parameters' not found

(The mistake seems fairly obvious when you look are the parameter list for your 
`mod` function.)

Additionally: It's not generally good practice to use `with` inside functions, 
but that's not the problem here.

-- 
David.

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

David Winsemius
Alameda, CA, USA

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

Re: [R] Modeling Time Series with Missing Observations

2017-03-23 Thread David Winsemius
There's also an irts-package "irregular time series"

Sent from my iPhone

> On Mar 23, 2017, at 3:42 PM, John C Frain  wrote:
> 
> Google "arima missing data r"  will bring up several references including
> http://stats.stackexchange.com/questions/104565/how-to-use-auto-arima-to-impute-missing-values.
> There are several other useful results in that search.
> 
> John C Frain
> 3 Aranleigh Park
> Rathfarnham
> Dublin 14
> Ireland
> www.tcd.ie/Economics/staff/frainj/home.html
> mailto:fra...@tcd.ie
> mailto:fra...@gmail.com
> 
>> On 23 March 2017 at 15:42, Jeff Newmiller  wrote:
>> 
>> Even the most basic introduction to R discusses the use of NA for missing
>> data. Injecting values that could be mistaken for actual readings is a
>> dangerous approach. You can use the merge function to introduce missing
>> rows into zoo objects or data frames.
>> --
>> Sent from my phone. Please excuse my brevity.
>> 
>> On March 23, 2017 8:22:47 AM PDT, Paul Bernal 
>> wrote:
>>> Dear all,
>>> 
>>> Hope you are doing well. I am trying to model the historical number of
>>> transits of a particular market segment, but the problem is that I have
>>> missing data.
>>> 
>>> I am working with monthly data, so I have 12 observations per year (in
>>> general). The problem is that, when I bring the data from the database,
>>> the
>>> following happens, for example:
>>> 
>>> January-2000, Feb-2000, Apr-2000, Jun 2000 (I have missing
>>> observations)
>>> 
>>> when I am supposed to have the sequence January-2000, Feb-2000,
>>> Mar-2000,
>>> Apr-2000, May-2000, Jun-2000, etc.
>>> 
>>> How can I model a time series when there are missing months? I was
>>> planning
>>> making up fictional or fake observations with a value of 1 to fill in
>>> the
>>> gaps but not sure if this is a reasonable approach.
>>> 
>>> Any help and/or guidance will be greatly appreciated,
>>> 
>>> Best regards,
>>> 
>>> Paul
>>> 
>>>  [[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.
>> 
> 
>[[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] Modeling Time Series with Missing Observations

2017-03-23 Thread John C Frain
Google "arima missing data r"  will bring up several references including
http://stats.stackexchange.com/questions/104565/how-to-use-auto-arima-to-impute-missing-values.
There are several other useful results in that search.

John C Frain
3 Aranleigh Park
Rathfarnham
Dublin 14
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
mailto:fra...@tcd.ie
mailto:fra...@gmail.com

On 23 March 2017 at 15:42, Jeff Newmiller  wrote:

> Even the most basic introduction to R discusses the use of NA for missing
> data. Injecting values that could be mistaken for actual readings is a
> dangerous approach. You can use the merge function to introduce missing
> rows into zoo objects or data frames.
> --
> Sent from my phone. Please excuse my brevity.
>
> On March 23, 2017 8:22:47 AM PDT, Paul Bernal 
> wrote:
> >Dear all,
> >
> >Hope you are doing well. I am trying to model the historical number of
> >transits of a particular market segment, but the problem is that I have
> >missing data.
> >
> >I am working with monthly data, so I have 12 observations per year (in
> >general). The problem is that, when I bring the data from the database,
> >the
> >following happens, for example:
> >
> >January-2000, Feb-2000, Apr-2000, Jun 2000 (I have missing
> >observations)
> >
> >when I am supposed to have the sequence January-2000, Feb-2000,
> >Mar-2000,
> >Apr-2000, May-2000, Jun-2000, etc.
> >
> >How can I model a time series when there are missing months? I was
> >planning
> >making up fictional or fake observations with a value of 1 to fill in
> >the
> >gaps but not sure if this is a reasonable approach.
> >
> >Any help and/or guidance will be greatly appreciated,
> >
> >Best regards,
> >
> >Paul
> >
> >   [[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.
>

[[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] How to change parameter values as a function to time with the package "deSolve"

2017-03-23 Thread Marine Regis
Hello,

I am trying to solve an ODE in R using deSolve. With the following code, I 
expected the parameter �gamma0� takes the values 5 at time step 0, 1, 2, 3, 4, 
5, 6, 7, 8, 9 and 10, and 0 otherwise. However, the print(gamma0) shows that 
�gamma0� stays at 0.

Here is my ODE:

param <- c(a = 0.1, b = 1)
yini <- c(alpha0 = 0, beta0 = 0)

mod <- function(times, yini, param) {

  with(as.list(c(yini, parameters)), {

  gamma0 <- ifelse(times %in% seq(0,10,1), 5, 0)

  # print(gamma0)

  dalpha0 <- - a*alpha0 + gamma0
  dbeta0 <- a*alpha0 - b*beta0
  return(list(c(dalpha0, dbeta0)))

  })}

times <- seq(from = 0, to = 10, by = 1/24)
out <- ode(func = mod, times = times, y = yini, parms = param)
plot(out, lwd = 2, xlab = "day")


What am I doing wrong? Thanks in advance for your help!
Marine


[[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] (no subject)

2017-03-23 Thread Jim Lemon
Hi Munevver,

Go here:

https://stat.ethz.ch/mailman/listinfo/r-help

which is probably where you subscribed, and

UNSUBSCRIBE

Jim

On Fri, Mar 24, 2017 at 3:55 AM, munevver kaya  wrote:
> Dear Sir/Madam,
> I do not want to receive any email by r-help. Can you delete me in your
> mail list? Thank you.
>
> Sincerely,
> Munevver Basman
>
> [[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 question

2017-03-23 Thread Rui Barradas

Hello,

Please keep this on the list. I'm cc-ing r-help and so should you always.

I got no error, just warning messages. After a long output I got the 
following.


NOTE: HARD MAXIMUM GENERATION LIMIT HIT

Solution Fitness Value: -2.592094e+03

Parameters at the Solution (parameter, gradient):

 X[ 1] :7.390657e-02G[ 1] : 0.00e+00
 X[ 2] :3.193020e-01G[ 2] : 0.00e+00
 X[ 3] :6.826336e-01G[ 3] : 0.00e+00
 X[ 4] :4.481256e-01G[ 4] : 0.00e+00
 X[ 5] :5.325378e-01G[ 5] : 0.00e+00
 X[ 6] :1.512199e-01G[ 6] : 0.00e+00
 X[ 7] :-3.160607e-01   G[ 7] : 0.00e+00
 X[ 8] :-1.762058e-01   G[ 8] : 0.00e+00

Solution Found Generation 6
Number of Generations Run 6

Thu Mar 23 21:26:47 2017
Total run time : 0 hours 0 minutes and 36 seconds
[1]  0.07390657  0.33930201  0.72263362  0.44812561  0.53253780  0.15121993
[7] -0.31606071 -0.17620576
Warning messages:
1: In genoud(obj, nvars, max = TRUE, pop.size = 100, max.generations = 6,  :
  'starting.values' which are outside of the bounds have been provided.
   Continuing, but unexpected behavior can occur with 
'boundary.enforcement!=0'

2: In genoud(obj, nvars, max = TRUE, pop.size = 100, max.generations = 6,  :
  Stopped because hard maximum generation limit was hit.

I cannot reproduce your error message.

Rui Barradas

Em 23-03-2017 02:45, 謝孟珂 escreveu:

Hi, thanks for your help.I run again my code
this is my cold.
run"maxloglik(x1,numcut,Ti,censor,confound,domain2,initial2,0.02)$par_corr"
library(rgenoud)
library(survival)
N=500
ei=rexp(N)
censor=rep(1,N)
x1=runif(N)
x2=runif(N)
x3=runif(N)
truecut=c(0.3,0.6)
dum1=1*(x1>truecut[1] & x1truecut[2])
x_true=cbind(dum1,dum2,x2,x3)
relativerisk<- matrix(log(c(1,1,2,2,
 1.25,1.5,2,2,
 1.5,2.5,2,2,
 1.75,2.5,2,2,
 2,3,2,2,
 3,5,2,2,
 4,7,2,2,
 5,9,2,2,
 6,11,2,2)),ncol=4,byrow = TRUE)
beta_true<-relativerisk[1,]  #I wanna see the effect of different
relativerisk,this way I choose relativerisk[1,]
Ti=exp(x_true%*%beta_true)*ei
confound=cbind(x2,x3)
numcut=3
initial2<-c(0.1303100 ,0.3259150 ,0.6264413,0.47507966 ,-0.03886098
,-0.21062905 ,-0.31606071 ,-0.17620576)
domain2<-matrix(c(rep(c(0.05,0.95),numcut),rep(c(0,5),numcut+dim(confound)[2])),ncol=2,byrow
= TRUE)
loglikfun <- function(beta, formula) {
   beta1 <- coxph(formula, init = beta,
control=list('iter.max'=0))#iteration is zero
   return(beta1$loglik[2])
}
obj <- function(xx){
   cutoff <- xx[1:numcut_global] #cutpoint
   cut_design <-
cut(target_global,breaks=c(0,sort(cutoff)+seq(0,gap_global*(length(cutoff)-1),by=gap_global),target_max),quantile=FALSE,labels=c(0:numcut_global))
   beta <- xx[(numcut+1):nvars]  #coefficients of parameters
   logliks <-
loglikfun(beta,Surv(time_global,censor_global)~cut_design+confound_global)
   return(logliks)
}
maxloglik<-function(target,numcut,time,censor,confound,domain2,initial2,gap){
   time_global<<-time
   censor_global<<-censor
   target_global<<-target
   nvars<<-2*numcut+dim(confound)[2]
   confound_global<<-confound
   numcut_global<<-numcut
   target_max<<-max(target)
   gap_global<<-gap
   ccc<-genoud(obj, nvars, max=TRUE, pop.size=100, max.generations=6,
wait.generations=10,
   hard.generation.limit=TRUE, starting.values=initial2,
MemoryMatrix=TRUE,
   Domains=domain2, solution.tolerance=0.001,
   gr=NULL, boundary.enforcement=2, lexical=FALSE,
gradient.check=TRUE)
   ccc$par_corr<-ccc$par #the coefficients of genoud

ccc$par_corr[1:numcut]<-sort(ccc$par[1:numcut])+seq(0,gap_global*(numcut-1),by=gap_global)
#sort cutpoint
   return(ccc)
}


but I get error message like this
 > maxloglik(x1,numcut,Ti,censor,confound,domain2,initial2,0.02)$par_corr


Thu Mar 23 10:38:27 2017
Domains:
  5.00e-02   <=  X1   <=9.50e-01
  5.00e-02   <=  X2   <=9.50e-01
  5.00e-02   <=  X3   <=9.50e-01
  0.00e+00   <=  X4   <=5.00e+00
  0.00e+00   <=  X5   <=5.00e+00
  0.00e+00   <=  X6   <=5.00e+00
  0.00e+00   <=  X7   <=5.00e+00
  0.00e+00   <=  X8   <=5.00e+00

Data Type: Floating Point
Operators (code number, name, population)
(1) Cloning... 15
(2) Uniform Mutation.. 12
(3) Boundary Mutation. 12
(4) Non-Uniform Mutation.. 12
(5) Polytope Crossover 12
(6) Simple Crossover.. 12
(7) Whole Non-Uniform Mutation 12
(8) Heuristic Crossover... 12
(9) Local-Minimum Crossover... 0

HARD Maximum Number of Generations: 6
Maximum Nonchanging Generations: 10
Population size   : 100
Convergence Tolerance: 1.00e-03

Using the BFGS Derivative Based

Re: [R] correct subset in R

2017-03-23 Thread David Winsemius

> On Mar 23, 2017, at 11:28 AM, Rui Barradas  wrote:
> 
> Hello,
> 
> I would try ?merge, in particular see the arguments by.x and by.y
> 
> Hope this helps,
> 
> Rui Barradas
> 
> Em 23-03-2017 18:19, Elahe chalabi via R-help escreveu:
>> Hi all,
>> I found an answer to the last question I asked in this group and now I want 
>> to have a correct subset of my data:
>> 
>> I have a following df1 which is list of all cities in US and their states:
>> 
>> $ name : Factor w/ 1008 levels "Ackley","Ackworth",..: 1 2 3
>> $ state: Factor w/ 1 level "Iowa": 1 1 1 1 1 1 1 1 1 1 .
>> 
>> the other data frame I have is df2 which is the list of cities I have and I 
>> want to get their state from df1:
>> 
>> $ cities : Factor w/ 547 levels "Afton","Boone","Calmar",...: 1 2 3
>> 
>> 
>> now how should I subset in a way to get related states of $cities from df1?

I think this is the proper use of the `match` function or its derivative `%in%`:

df1[ match(df2$cities, df1$name, no.match=0) , "state"]  # numeric indexing

df1[ df1$name %in% df2$cities , "state"] # logical indexing


Untested since the example is incomplete.

-- 
David

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

David Winsemius
Alameda, CA, USA

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


Re: [R] correct subset in R

2017-03-23 Thread Rui Barradas

Hello,

I would try ?merge, in particular see the arguments by.x and by.y

Hope this helps,

Rui Barradas

Em 23-03-2017 18:19, Elahe chalabi via R-help escreveu:

Hi all,
I found an answer to the last question I asked in this group and now I want to 
have a correct subset of my data:

I have a following df1 which is list of all cities in US and their states:

$ name : Factor w/ 1008 levels "Ackley","Ackworth",..: 1 2 3
$ state: Factor w/ 1 level "Iowa": 1 1 1 1 1 1 1 1 1 1 .

the other data frame I have is df2 which is the list of cities I have and I 
want to get their state from df1:

$ cities : Factor w/ 547 levels "Afton","Boone","Calmar",...: 1 2 3


now how should I subset in a way to get related states of $cities from df1?

Thanks for any help!
Elahe

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

2017-03-23 Thread Elahe chalabi via R-help
Hi all,
I found an answer to the last question I asked in this group and now I want to 
have a correct subset of my data:

I have a following df1 which is list of all cities in US and their states:

$ name : Factor w/ 1008 levels "Ackley","Ackworth",..: 1 2 3 
$ state: Factor w/ 1 level "Iowa": 1 1 1 1 1 1 1 1 1 1 .

the other data frame I have is df2 which is the list of cities I have and I 
want to get their state from df1:

$ cities : Factor w/ 547 levels "Afton","Boone","Calmar",...: 1 2 3 


now how should I subset in a way to get related states of $cities from df1?

Thanks for any help!
Elahe

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

2017-03-23 Thread Peter Dalgaard
The recipe for unsubscribing is in the footer of every r-help message. General 
readers of the list can not do it for you.

-pd

> On 23 Mar 2017, at 17:55 , munevver kaya  wrote:
> 
> Dear Sir/Madam,
> I do not want to receive any email by r-help. Can you delete me in your
> mail list? Thank you.
> 
> Sincerely,
> Munevver Basman
> 
>   [[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.

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

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


[R] (no subject)

2017-03-23 Thread munevver kaya
Dear Sir/Madam,
I do not want to receive any email by r-help. Can you delete me in your
mail list? Thank you.

Sincerely,
Munevver Basman

[[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] "Ordiellipse" in vegan package plot; how to plot sd for individual species

2017-03-23 Thread David L Carlson
Most attachments (including your data and graph) get stripped from mail sent to 
the list. If the data are a plain text file, giving the file an extension of 
.txt will usually let it survive the trip (even if it is a .csv file). Graphics 
will survive if they are .png files. 

If the datasets are not large, use dput(env) and dput(species), and then paste 
the output of those commands into your email message. 

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

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Larsson Emil
Sent: Thursday, March 23, 2017 7:44 AM
To: r-help@r-project.org
Subject: [R] "Ordiellipse" in vegan package plot; how to plot sd for individual 
species

Hi R-Help,



I have been looking for an answer to this question for some time without 
success, so now my hope is that you will distribute it to your email 
subscribers, or direct me to another forum where this question is not off-topic.


I have a dataset with 224 rows (=sites), ca 20 environmental variables, and 
presence/absence data for ca 40 species. TI have done an RDA ordination using 
the vegan package and plotted all species. Now, I want to add standard 
deviation for each species as circles or ellipses.


How can I do this? I tried using "ordiellipse", guided by this similar request 
from 2010 answered by Jari Oksanen:


http://r-sig-ecology.471788.n2.nabble.com/Fwd-R-cca-standard-error-species-td4997341.html


I am close but I cannot make it work. I have attached the dataset (V=variables, 
S= species) and an example sketch of how the final plot should look.


Here is my script so far:


# add environmental and species data separately:

env<-read.delim("clipboard")
attach(env)
str(env)
species<-read.delim("clipboard")
attach(species)?
str(species)

# run RDA command and plot:
mod<-rda(species,env,scale=TRUE)
plot(mod, display = "species")
ordiellipse(mod, groups = rep(1, 224), display="lc", kind ="sd", draw = 
"polygon",
alpha = 127, label = FALSE, show.groups=TRUE, w = NULL, border = NULL, lty = 
NULL, lwd=NULL)





Very grateful for any help.



Best regards,


Emil Larsson
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] argument to 'which' is not logical

2017-03-23 Thread S Ellison
> I'm trying to run the code: inds<-which(c != 0 ), but it gave me error: Error 
> in
> base::which(x, arr.ind, useNames, ...) :   argument to 'which' is not logical

Your coefficients are not a numeric vector. You'll have to sort that out by 
extracting or testing the individual values. A look at your output _tells you_ 
that the object is a sparse matrix of class dgCMatrix . Looking that up would 
tell you that the nonzero elements are in slot x of the object. So it may be 
unnecessary to ask which are zero; maybe you just need c@x (though I also would 
recommend you avoid using common function names as variable names)

If you do need to test elements for zeroes, though, note that '==' and '!=' are 
not usually recommended for comparisons with zero owing to finite numerical 
representation. So that may well be unwise. See the Note in ?'=='.

S Ellison



> Here is code:
> alphas <- seq(0, 1, by=.002)mses <- numeric(501)mins <- numeric(501)maxes
> <- numeric(501)for(i in 1:501){  cvfits <- cv.glmnet(Train2,
> Train$Item_Outlet_Sales, alpha=alphas[i], nfolds=32)  loc <-
> which(cvfits$lambda==cvfits$lambda.min)  maxes[i] <- cvfits$lambda %>%
> max  mins[i] <- cvfits$lambda %>% min  mses[i] <- cvfits$cvm[loc]}`%ni%`<-
> Negate(`%in%`)c<-coef(cvfits,s='lambda.1se',exact=TRUE)inds<-which(c != 0
> ) Here is the c content looks like: > c33 x 1 sparse Matrix of class
> "dgCMatrix"                                           1(Intercept)            
>           7.476895931Item_Fa
> t_Content.Low.Fat         .          Item_Fat_Content.Regular         .       
>    Item_Type
> .Breads                 .          Item_Type.Breakfast              .         
>  Item_Type.Canned
>             0.003430669Item_Type.Dairy                 -
> 0.022579673Item_Type.Frozen.Foods          -
> 0.008216547Item_Type.Fruits.and.Vegetables  .          Item_Type.Hard.Drinks
>          .          Item_Type.Health.and.Hygiene     .          
> Item_Type.Household
>     .          Item_Type.Meat                   .          Item_Type.Others   
>               .          Item
> _Type.Seafood                .          Item_Type.Snack.Foods            .    
>       Item_Type.S
> oft.Drinks            .          Item_Type.Starchy.Foods          .          
> Outlet_Establishm
> ent_Year.1987  -
> 0.345927916Outlet_Establishment_Year.1997   1.692678186Outlet_Establishm
> ent_Year.1998  -
> 2.259508290Outlet_Establishment_Year.1999   .          Outlet_Establishment_Y
> ear.2002  -
> 0.032971913Outlet_Establishment_Year.2004   1.756230495Outlet_Establishm
> ent_Year.2007   .          Outlet_Establishment_Year.2009  -
> 0.549210057Outlet_Size.Medium               0.056897825Outlet_Size.Small
>  -
> 1.706006538Outlet_Location_Type.Tier.3      0.373456218Item_Identifier_Com
> binedFD       .          Item_MRP                         
> 0.505435352Item_Weight
> .          Item_Visibility_MeanRatio       -0.007274202
>   [[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.


***
This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If 
you have received this message in error, please notify the sender 
immediately via +44(0)20 8943 7000 or notify postmas...@lgcgroup.com 
and delete this message and any copies from your computer and network. 
LGC Limited. Registered in England 2991879. 
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] string pattern matching

2017-03-23 Thread Joe Ceradini
Oh, I see the utility of that now. Definitely will be using "term.labels"
(which I was not aware of). Thanks!

On Thu, Mar 23, 2017 at 9:48 AM, William Dunlap  wrote:

> If you are trying to see if one model nested in another then I think
> looking at the 'term.labels' attribute of terms(formula) is the way to
> go.  Most formula-based modelling functions store the output of
> terms(formula) in their output and many supply a method for the terms
> function that extracts that from their output.
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Thu, Mar 23, 2017 at 6:37 AM, Joe Ceradini 
> wrote:
> > Thanks for the additional response, Bill. I did not want to bog down
> > the question with the full context of the function. Briefly, given a
> > set of nested and non-nested regression models, I want to compare AIC
> > (bigger model - smaller model) and do an LRT for all the nested models
> > that differ by a single predictor. All models, nested or not, would
> > also have an AIC value (I am aware of the critiques of mixing p-value
> > hypothesis testing and information criteria). So, not quite
> > MuMIn::dredge. The tricky part, for me, has been doing the comparisons
> > for only the nested models in a set that contains nested and
> > non-nested. I made some progress with the function, so I'll refrain
> > from bugging the list with the whole thing unless (when) I'm stuck
> > again.
> >
> > For those interested in the motivation, I'm running with the idea of
> > trying to flag uninformative parameters which "steal" AIC model
> > weight, and potentially result in a misleading model set, depending
> > how the reader interprets the set.
> > Arnold, T. W. 2010. Uninformative parameters and model selection using
> > Akaike’s information criterion. Journal of Wildlife Management
> > 74:1175–1178.
> > Murtaugh, P. 2014. In defense of P values. Ecology 95:611–617.
> >
> > Joe
> >
> > On Wed, Mar 22, 2017 at 9:11 AM, William Dunlap 
> wrote:
> >> You did not describe the goal of your pattern matching.  Were you trying
> >> to match any string that could be interpreted as an R expression
> containing
> >> X1 and X3 as additive terms?   If so, you could turn the string into a
> one-sided
> >> formula and use the terms() function.  E.g.,
> >>
> >> f <- function(string) {
> >> fmla <- as.formula(paste("~", string))
> >> term.labels <- attr(terms(fmla), "term.labels")
> >> all(c("X1","X3") %in% term.labels)
> >> }
> >>
> >>> f("X3 + X2 + X1")
> >> [1] TRUE
> >>> f("- X3 + X2 + X1")
> >> [1] FALSE
> >>> f("X3 + X2 + log(X1)")
> >> [1] FALSE
> >>> f("X3 + X2 + log(X1) + X1")
> >> [1] TRUE
> >> Bill Dunlap
> >> TIBCO Software
> >> wdunlap tibco.com
> >>
> >>
> >> On Wed, Mar 22, 2017 at 6:39 AM, Joe Ceradini 
> wrote:
> >>> Wow. Thanks to everyone (Jim, Ng Bo Lin, Bert, David, and Ulrik) for
> >>> all the quick and helpful responses. They have given me a better
> >>> understanding of regular expressions, and certainly answered my
> >>> question.
> >>>
> >>> Joe
> >>>
> >>> On Wed, Mar 22, 2017 at 12:22 AM, Ulrik Stervbo <
> ulrik.ster...@gmail.com> wrote:
>  Hi Joe,
> 
>  you could also rethink your pattern:
> 
>  grep("x1 \\+ x2", test, value = TRUE)
> 
>  grep("x1 \\+ x", test, value = TRUE)
> 
>  grep("x1 \\+ x[0-9]", test, value = TRUE)
> 
>  HTH
>  Ulrik
> 
>  On Wed, 22 Mar 2017 at 02:10 Jim Lemon  wrote:
> >
> > Hi Joe,
> > This may help you:
> >
> > test <- c("x1", "x2", "x3", "x1 + x2 + x3")
> > multigrep<-function(x1,x2) {
> >  xbits<-unlist(strsplit(x1," "))
> >  nbits<-length(xbits)
> >  xans<-rep(FALSE,nbits)
> >  for(i in 1:nbits) if(length(grep(xbits[i],x2))) xans[i]<-TRUE
> >  return(all(xans))
> > }
> > multigrep("x1 + x3","x1 + x2 + x3")
> > [1] TRUE
> > multigrep("x1 + x4","x1 + x2 + x3")
> > [1] FALSE
> >
> > Jim
> >
> > On Wed, Mar 22, 2017 at 10:50 AM, Joe Ceradini <
> joecerad...@gmail.com>
> > wrote:
> > > Hi Folks,
> > >
> > > Is there a way to find "x1 + x2 + x3" given "x1 + x3" as the
> pattern?
> > > Or is that a ridiculous question, since I'm trying to find
> something
> > > based on a pattern that doesn't exist?
> > >
> > > test <- c("x1", "x2", "x3", "x1 + x2 + x3")
> > > test
> > > [1] "x1"   "x2"   "x3"   "x1 + x2 + x3"
> > >
> > > grep("x1 + x2", test, fixed=TRUE, value = TRUE)
> > > [1] "x1 + x2 + x3"
> > >
> > >
> > > But what if only have "x1 + x3" as the pattern and still want to
> > > return "x1 + x2 + x3"?
> > >
> > > grep("x1 + x3", test, fixed=TRUE, value = TRUE)
> > > character(0)
> > >
> > > I'm sure this looks like an odd question. I'm trying to build a
> > > function and stuck on this. Rather than dropping the whole
> function on
> > > the list, I thought I'd try one piece I needed help
> with...although I
> >

Re: [R] string pattern matching

2017-03-23 Thread William Dunlap via R-help
If you are trying to see if one model nested in another then I think
looking at the 'term.labels' attribute of terms(formula) is the way to
go.  Most formula-based modelling functions store the output of
terms(formula) in their output and many supply a method for the terms
function that extracts that from their output.
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Mar 23, 2017 at 6:37 AM, Joe Ceradini  wrote:
> Thanks for the additional response, Bill. I did not want to bog down
> the question with the full context of the function. Briefly, given a
> set of nested and non-nested regression models, I want to compare AIC
> (bigger model - smaller model) and do an LRT for all the nested models
> that differ by a single predictor. All models, nested or not, would
> also have an AIC value (I am aware of the critiques of mixing p-value
> hypothesis testing and information criteria). So, not quite
> MuMIn::dredge. The tricky part, for me, has been doing the comparisons
> for only the nested models in a set that contains nested and
> non-nested. I made some progress with the function, so I'll refrain
> from bugging the list with the whole thing unless (when) I'm stuck
> again.
>
> For those interested in the motivation, I'm running with the idea of
> trying to flag uninformative parameters which "steal" AIC model
> weight, and potentially result in a misleading model set, depending
> how the reader interprets the set.
> Arnold, T. W. 2010. Uninformative parameters and model selection using
> Akaike’s information criterion. Journal of Wildlife Management
> 74:1175–1178.
> Murtaugh, P. 2014. In defense of P values. Ecology 95:611–617.
>
> Joe
>
> On Wed, Mar 22, 2017 at 9:11 AM, William Dunlap  wrote:
>> You did not describe the goal of your pattern matching.  Were you trying
>> to match any string that could be interpreted as an R expression containing
>> X1 and X3 as additive terms?   If so, you could turn the string into a 
>> one-sided
>> formula and use the terms() function.  E.g.,
>>
>> f <- function(string) {
>> fmla <- as.formula(paste("~", string))
>> term.labels <- attr(terms(fmla), "term.labels")
>> all(c("X1","X3") %in% term.labels)
>> }
>>
>>> f("X3 + X2 + X1")
>> [1] TRUE
>>> f("- X3 + X2 + X1")
>> [1] FALSE
>>> f("X3 + X2 + log(X1)")
>> [1] FALSE
>>> f("X3 + X2 + log(X1) + X1")
>> [1] TRUE
>> Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com
>>
>>
>> On Wed, Mar 22, 2017 at 6:39 AM, Joe Ceradini  wrote:
>>> Wow. Thanks to everyone (Jim, Ng Bo Lin, Bert, David, and Ulrik) for
>>> all the quick and helpful responses. They have given me a better
>>> understanding of regular expressions, and certainly answered my
>>> question.
>>>
>>> Joe
>>>
>>> On Wed, Mar 22, 2017 at 12:22 AM, Ulrik Stervbo  
>>> wrote:
 Hi Joe,

 you could also rethink your pattern:

 grep("x1 \\+ x2", test, value = TRUE)

 grep("x1 \\+ x", test, value = TRUE)

 grep("x1 \\+ x[0-9]", test, value = TRUE)

 HTH
 Ulrik

 On Wed, 22 Mar 2017 at 02:10 Jim Lemon  wrote:
>
> Hi Joe,
> This may help you:
>
> test <- c("x1", "x2", "x3", "x1 + x2 + x3")
> multigrep<-function(x1,x2) {
>  xbits<-unlist(strsplit(x1," "))
>  nbits<-length(xbits)
>  xans<-rep(FALSE,nbits)
>  for(i in 1:nbits) if(length(grep(xbits[i],x2))) xans[i]<-TRUE
>  return(all(xans))
> }
> multigrep("x1 + x3","x1 + x2 + x3")
> [1] TRUE
> multigrep("x1 + x4","x1 + x2 + x3")
> [1] FALSE
>
> Jim
>
> On Wed, Mar 22, 2017 at 10:50 AM, Joe Ceradini 
> wrote:
> > Hi Folks,
> >
> > Is there a way to find "x1 + x2 + x3" given "x1 + x3" as the pattern?
> > Or is that a ridiculous question, since I'm trying to find something
> > based on a pattern that doesn't exist?
> >
> > test <- c("x1", "x2", "x3", "x1 + x2 + x3")
> > test
> > [1] "x1"   "x2"   "x3"   "x1 + x2 + x3"
> >
> > grep("x1 + x2", test, fixed=TRUE, value = TRUE)
> > [1] "x1 + x2 + x3"
> >
> >
> > But what if only have "x1 + x3" as the pattern and still want to
> > return "x1 + x2 + x3"?
> >
> > grep("x1 + x3", test, fixed=TRUE, value = TRUE)
> > character(0)
> >
> > I'm sure this looks like an odd question. I'm trying to build a
> > function and stuck on this. Rather than dropping the whole function on
> > the list, I thought I'd try one piece I needed help with...although I
> > suspect that this question itself probably does bode well for my
> > function :)
> >
> > Thanks!
> > Joe
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/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] Modeling Time Series with Missing Observations

2017-03-23 Thread Jeff Newmiller
Even the most basic introduction to R discusses the use of NA for missing data. 
Injecting values that could be mistaken for actual readings is a dangerous 
approach. You can use the merge function to introduce missing rows into zoo 
objects or data frames. 
-- 
Sent from my phone. Please excuse my brevity.

On March 23, 2017 8:22:47 AM PDT, Paul Bernal  wrote:
>Dear all,
>
>Hope you are doing well. I am trying to model the historical number of
>transits of a particular market segment, but the problem is that I have
>missing data.
>
>I am working with monthly data, so I have 12 observations per year (in
>general). The problem is that, when I bring the data from the database,
>the
>following happens, for example:
>
>January-2000, Feb-2000, Apr-2000, Jun 2000 (I have missing
>observations)
>
>when I am supposed to have the sequence January-2000, Feb-2000,
>Mar-2000,
>Apr-2000, May-2000, Jun-2000, etc.
>
>How can I model a time series when there are missing months? I was
>planning
>making up fictional or fake observations with a value of 1 to fill in
>the
>gaps but not sure if this is a reasonable approach.
>
>Any help and/or guidance will be greatly appreciated,
>
>Best regards,
>
>Paul
>
>   [[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] Modeling Time Series with Missing Observations

2017-03-23 Thread Paul Bernal
Dear all,

Hope you are doing well. I am trying to model the historical number of
transits of a particular market segment, but the problem is that I have
missing data.

I am working with monthly data, so I have 12 observations per year (in
general). The problem is that, when I bring the data from the database, the
following happens, for example:

January-2000, Feb-2000, Apr-2000, Jun 2000 (I have missing observations)

when I am supposed to have the sequence January-2000, Feb-2000, Mar-2000,
Apr-2000, May-2000, Jun-2000, etc.

How can I model a time series when there are missing months? I was planning
making up fictional or fake observations with a value of 1 to fill in the
gaps but not sure if this is a reasonable approach.

Any help and/or guidance will be greatly appreciated,

Best regards,

Paul

[[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] Can fallback font be specified?

2017-03-23 Thread Jinsong Zhao

Hi there,

I am a Chinese R user. I hope to plot the following code with Chinese in 
one font family, such as SimHei, but English in another font family, 
such as Times New Roman.


plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family = "serif")

In my case, the system default font is "SimSun", so the above code 
fallback "\u4F60\u597D", which is not in the font Times, to SimSun.


If I use:

plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family = "SimHei")

Then The "Hello" will in "SimHei" family, it's not as beautiful as Times.

Is it possible to specify the fallback font family in R? Any hints or 
suggestions?


Thanks in advance.

Best,
Jinsong

> version
   _
platform   x86_64-w64-mingw32
arch   x86_64
os mingw32
system x86_64, mingw32
status
major  3
minor  3.3
year   2017
month  03
day06
svn rev72310
language   R
version.string R version 3.3.3 (2017-03-06)
nickname   Another Canoe

> Sys.getlocale()
[1] "LC_COLLATE=Chinese (Simplified)_China.936;LC_CTYPE=Chinese 
(Simplified)_China.936;LC_MONETARY=Chinese 
(Simplified)_China.936;LC_NUMERIC=C;LC_TIME=Chinese (Simplified)_China.936"


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] "Ordiellipse" in vegan package plot; how to plot sd for individual species

2017-03-23 Thread Larsson Emil
Hi R-Help,



I have been looking for an answer to this question for some time without 
success, so now my hope is that you will distribute it to your email 
subscribers, or direct me to another forum where this question is not off-topic.


I have a dataset with 224 rows (=sites), ca 20 environmental variables, and 
presence/absence data for ca 40 species. TI have done an RDA ordination using 
the vegan package and plotted all species. Now, I want to add standard 
deviation for each species as circles or ellipses.


How can I do this? I tried using "ordiellipse", guided by this similar request 
from 2010 answered by Jari Oksanen:


http://r-sig-ecology.471788.n2.nabble.com/Fwd-R-cca-standard-error-species-td4997341.html


I am close but I cannot make it work. I have attached the dataset (V=variables, 
S= species) and an example sketch of how the final plot should look.


Here is my script so far:


# add environmental and species data separately:

env<-read.delim("clipboard")
attach(env)
str(env)
species<-read.delim("clipboard")
attach(species)?
str(species)

# run RDA command and plot:
mod<-rda(species,env,scale=TRUE)
plot(mod, display = "species")
ordiellipse(mod, groups = rep(1, 224), display="lc", kind ="sd", draw = 
"polygon",
alpha = 127, label = FALSE, show.groups=TRUE, w = NULL, border = NULL, lty = 
NULL, lwd=NULL)





Very grateful for any help.



Best regards,


Emil Larsson
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Extracting time-series data from netCDF file for a defined period using ncdf4 package

2017-03-23 Thread Ben Tupper
Hi,

You problem as stated certainly is puzzling since you have one NCDF file but 
'time units are different'.  I don't know what to make of that.

If you had a simpler case where data are dimensioned as [x,y,t] then you can 
convert dates to index use in ncdf4::ncvar_get()

I would start with a look-up-table of the dates in the file.

lut <- seq(from = as.Date("1850-01-01"), to = as.Date(Sys.Date()), by = 'day')

The use base::findInterval() to convert your start/stop dates to indices. 

mine <- as.Date(c("1971-01-01", "1990-03-01"))

startstop <- findInterval(mine, lut)


Is that at all close to what you seek?
Ben





> On Mar 23, 2017, at 6:07 AM, കുഞ്ഞായി kunjaai  wrote:
> 
> Dear All,
> 
> I am trying to extract a time series  from a netCDF file.
> 
> I want to extract data for the time period  1971-1  to 1990-12-31 only.
> 
> time axis units is  'days since 1850-1-1'
> 
> For one or two files I can use "count" argument,  but I have more than 100
> such files and its time units are different.
> 
> Is there any easy way to extract the particular time period using ncdf4
> package?
> 
> Thank you in advance.
> 
> -- 
> DILEEPKUMAR. R
> J R F, IIT DELHI
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

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

Re: [R] string pattern matching

2017-03-23 Thread Joe Ceradini
Thanks for the additional response, Bill. I did not want to bog down
the question with the full context of the function. Briefly, given a
set of nested and non-nested regression models, I want to compare AIC
(bigger model - smaller model) and do an LRT for all the nested models
that differ by a single predictor. All models, nested or not, would
also have an AIC value (I am aware of the critiques of mixing p-value
hypothesis testing and information criteria). So, not quite
MuMIn::dredge. The tricky part, for me, has been doing the comparisons
for only the nested models in a set that contains nested and
non-nested. I made some progress with the function, so I'll refrain
from bugging the list with the whole thing unless (when) I'm stuck
again.

For those interested in the motivation, I'm running with the idea of
trying to flag uninformative parameters which "steal" AIC model
weight, and potentially result in a misleading model set, depending
how the reader interprets the set.
Arnold, T. W. 2010. Uninformative parameters and model selection using
Akaike’s information criterion. Journal of Wildlife Management
74:1175–1178.
Murtaugh, P. 2014. In defense of P values. Ecology 95:611–617.

Joe

On Wed, Mar 22, 2017 at 9:11 AM, William Dunlap  wrote:
> You did not describe the goal of your pattern matching.  Were you trying
> to match any string that could be interpreted as an R expression containing
> X1 and X3 as additive terms?   If so, you could turn the string into a 
> one-sided
> formula and use the terms() function.  E.g.,
>
> f <- function(string) {
> fmla <- as.formula(paste("~", string))
> term.labels <- attr(terms(fmla), "term.labels")
> all(c("X1","X3") %in% term.labels)
> }
>
>> f("X3 + X2 + X1")
> [1] TRUE
>> f("- X3 + X2 + X1")
> [1] FALSE
>> f("X3 + X2 + log(X1)")
> [1] FALSE
>> f("X3 + X2 + log(X1) + X1")
> [1] TRUE
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Wed, Mar 22, 2017 at 6:39 AM, Joe Ceradini  wrote:
>> Wow. Thanks to everyone (Jim, Ng Bo Lin, Bert, David, and Ulrik) for
>> all the quick and helpful responses. They have given me a better
>> understanding of regular expressions, and certainly answered my
>> question.
>>
>> Joe
>>
>> On Wed, Mar 22, 2017 at 12:22 AM, Ulrik Stervbo  
>> wrote:
>>> Hi Joe,
>>>
>>> you could also rethink your pattern:
>>>
>>> grep("x1 \\+ x2", test, value = TRUE)
>>>
>>> grep("x1 \\+ x", test, value = TRUE)
>>>
>>> grep("x1 \\+ x[0-9]", test, value = TRUE)
>>>
>>> HTH
>>> Ulrik
>>>
>>> On Wed, 22 Mar 2017 at 02:10 Jim Lemon  wrote:

 Hi Joe,
 This may help you:

 test <- c("x1", "x2", "x3", "x1 + x2 + x3")
 multigrep<-function(x1,x2) {
  xbits<-unlist(strsplit(x1," "))
  nbits<-length(xbits)
  xans<-rep(FALSE,nbits)
  for(i in 1:nbits) if(length(grep(xbits[i],x2))) xans[i]<-TRUE
  return(all(xans))
 }
 multigrep("x1 + x3","x1 + x2 + x3")
 [1] TRUE
 multigrep("x1 + x4","x1 + x2 + x3")
 [1] FALSE

 Jim

 On Wed, Mar 22, 2017 at 10:50 AM, Joe Ceradini 
 wrote:
 > Hi Folks,
 >
 > Is there a way to find "x1 + x2 + x3" given "x1 + x3" as the pattern?
 > Or is that a ridiculous question, since I'm trying to find something
 > based on a pattern that doesn't exist?
 >
 > test <- c("x1", "x2", "x3", "x1 + x2 + x3")
 > test
 > [1] "x1"   "x2"   "x3"   "x1 + x2 + x3"
 >
 > grep("x1 + x2", test, fixed=TRUE, value = TRUE)
 > [1] "x1 + x2 + x3"
 >
 >
 > But what if only have "x1 + x3" as the pattern and still want to
 > return "x1 + x2 + x3"?
 >
 > grep("x1 + x3", test, fixed=TRUE, value = TRUE)
 > character(0)
 >
 > I'm sure this looks like an odd question. I'm trying to build a
 > function and stuck on this. Rather than dropping the whole function on
 > the list, I thought I'd try one piece I needed help with...although I
 > suspect that this question itself probably does bode well for my
 > function :)
 >
 > Thanks!
 > Joe
 >
 > __
 > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 > https://stat.ethz.ch/mailman/listinfo/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.
>>
>>
>>
>> --
>> Cooperative Fish and Wildlife Research Unit
>> Zoology and Physiology Dept.
>> University of Wyoming
>> joecerad...@gmail.com / 914.707.8506
>> wyocoopunit.org
>>
>> __
>> R-

Re: [R] Error in leaps.

2017-03-23 Thread John Kane via R-help
Hi Cindy,Welcome to R-help.
Have  a look at the posting guidelines and their suggestion about a minimal 
example. What we  need to help you is some sample data and a "minimal" amount 
of code that illustrates your problem. Someone may be able to guess the problem 
from your errror message but I'd not bet on it.

Have a look at http://adv-r.had.co.nz/Reproducibility.html for some excellent 
suggestions on how to do this. And please supply the data using the dput() 
command. It provides an exact copy of the data on your computer so we know we 
are working with exactly the same data you are.




 

On Thursday, March 23, 2017 6:35 AM, Cindy Wang  
wrote:
 

 Dear All,

I am trying to use the model, Program Evaluation in order to determine the
economic impact of a policy change. While trying to run my own data on
RStudio, using the codes from the paper "An R Package for the Panel
Approach Method for Program Evaluation: Pampe" by Ainhoa Vega-Bayo, I keep
encountering an error that reads:

Error in leaps.setup(x, y, wt = weights, nbest = nbest, nvmax = nvmax,  :
  y and x different lengths

To be honest, I am very new to R so I am not familiar with how it works and
what every thing means, so its been quite a challenge for me to overcome
this error. The packages that I have installed are "Formula", "plm",
"leaps" and "pampe".

If anyone could provide some help and advice on how I could overcome this
error, it would be greatly appreciated.

I am happy to provide more information if needed.

Regards,
Cindy

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

2017-03-23 Thread Ulrik Stervbo
Hi Elahe,

maybe the us.cities() in the maps package is what you look for.

HTH
Ulrik

On Thu, 23 Mar 2017 at 11:34 Elahe chalabi via R-help 
wrote:

> Hi all,
>
> I have a data frame containing serial numbers for US. I also have a column
> showing the city in US, now my question is is there a package in R able to
> get the city in US as input and then return the name of State for that
> city?!
>
> Thanks for any help!
> Elahe
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] Error in leaps.

2017-03-23 Thread Cindy Wang
Dear All,

I am trying to use the model, Program Evaluation in order to determine the
economic impact of a policy change. While trying to run my own data on
RStudio, using the codes from the paper "An R Package for the Panel
Approach Method for Program Evaluation: Pampe" by Ainhoa Vega-Bayo, I keep
encountering an error that reads:

Error in leaps.setup(x, y, wt = weights, nbest = nbest, nvmax = nvmax,  :
  y and x different lengths

To be honest, I am very new to R so I am not familiar with how it works and
what every thing means, so its been quite a challenge for me to overcome
this error. The packages that I have installed are "Formula", "plm",
"leaps" and "pampe".

If anyone could provide some help and advice on how I could overcome this
error, it would be greatly appreciated.

I am happy to provide more information if needed.

Regards,
Cindy

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

2017-03-23 Thread Elahe chalabi via R-help
Hi all,

I have a data frame containing serial numbers for US. I also have a column 
showing the city in US, now my question is is there a package in R able to get 
the city in US as input and then return the name of State for that city?!

Thanks for any help!
Elahe

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Extracting time-series data from netCDF file for a defined period using ncdf4 package

2017-03-23 Thread കുഞ്ഞായി kunjaai
Dear All,

I am trying to extract a time series  from a netCDF file.

I want to extract data for the time period  1971-1  to 1990-12-31 only.

time axis units is  'days since 1850-1-1'

For one or two files I can use "count" argument,  but I have more than 100
such files and its time units are different.

Is there any easy way to extract the particular time period using ncdf4
package?

Thank you in advance.

-- 
DILEEPKUMAR. R
J R F, IIT DELHI

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