Re: [R] Reg: Frequency in declaring time series data

2023-01-16 Thread Rui Barradas

Às 20:52 de 16/01/2023, Upananda Pani escreveu:

Hi Rui,

Thank you so much for your help. As I have to fit a Markov Switching Model
using  MSwM package.

May I know whether i can convert from zoo object to a time series object.

As I have to use several packages which uses ts so I am not able to decide
how to do it.

Grateful to you for your help and support.

With sincere regards,
Upananda

On Tue, 17 Jan, 2023, 01:40 Rui Barradas,  wrote:


Às 16:39 de 16/01/2023, Upananda Pani escreveu:

Dear All,

I have a time series daily data with date are stored ( %dd-%mm-%yy

format )

from 22-01-20 to 03-08-21. In total I have 560 observations. I am using

the

following command to declare as a time series object. Here the the data

set

is 7 days a week.
oil <- read_xlsx("crudefinal.xlsx")
pricet=ts(oil$price, start = c(2020, 22), freq = 365)
roilt=ts(diff(log(oil$price))*100,start=c(2020,22), freq=365)

Shall I have to declare the dates here?  I want to know also if it is a 5
day trading a week, how to declare the frequency.

Looking forward to your reply

Regards,
Upananda Pani

Looking forward to your suggestions.

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

Hello,

Package zoo is the best way of having dates in a time series. The
package comes with several vignettes that can get you started quickly.
See the difference between classes ts and zoo below.

# make up some test data
oil <- data.frame(price = cumsum(rnorm(560)))
oil$date <- seq(as.Date("2020-01-22"), by = "1 day", length.out = 560)

# base R
pricet <- ts(oil$price, start = c(2020, 22), freq = 365)
time(pricet)
index(pricet)
plot(pricet)

#---

library(zoo)
library(ggplot2)

pricez <- zoo(oil$price, order.by = oil$date)
time(pricez)
index(pricez)
autoplot(pricez)

vignette(package = "zoo")


Hope this helps,

Rui Barradas






Hello,

Please always cc the R-Help list.

I have no experience with package MSwM but according to the

vignette("example", package = "MSwM")

you first fit a regression model, say 'mod', and then fit an 
Autoregressive Markov Switching Model to mod. You don't need a time 
series, only a regression fit.


Hope this helps,

Rui Barradas

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

2023-01-16 Thread Upananda Pani
Dear Members,



Greetings! I would like to know how to create the lag variable for my data.



# Load data and create time series object 

oil <- read_xlsx("crudefinal.xlsx")



pricet=ts(oil$price, start = c(2020, 22), frequency = 365)

roilt=ts(diff(log(oil$price))*100,start=c(2020,22),freq=365)



# Fit MSW model 

roilt.lag0 = window(roilt,start=c(2020,23),end=c(2021,215),freq=365) # get
al the lags right

roilt.lag1 = window(roilt,start=c(2020,22),end=c(2021,214),freq=365)

roilt.lag2 = window(roilt,start=c(2020,20),end=c(2021,213),freq=365)

roilt.lag3 = window(roilt,start=c(2020,20),end=c(2021,212),freq=365)

roilt.lag4 = window(roilt,start=c(2020,19),end=c(2021,211),freq=365)



I am getting error (length is not matching), while creating lag. I will
grateful to you if you can tell me where  I am making mistakes.



Regards,

Upananda Pani

[[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] Reg: Frequency in declaring time series data

2023-01-16 Thread Rui Barradas

Às 16:39 de 16/01/2023, Upananda Pani escreveu:

Dear All,

I have a time series daily data with date are stored ( %dd-%mm-%yy format )
from 22-01-20 to 03-08-21. In total I have 560 observations. I am using the
following command to declare as a time series object. Here the the data set
is 7 days a week.
oil <- read_xlsx("crudefinal.xlsx")
pricet=ts(oil$price, start = c(2020, 22), freq = 365)
roilt=ts(diff(log(oil$price))*100,start=c(2020,22), freq=365)

Shall I have to declare the dates here?  I want to know also if it is a 5
day trading a week, how to declare the frequency.

Looking forward to your reply

Regards,
Upananda Pani

Looking forward to your suggestions.

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

Hello,

Package zoo is the best way of having dates in a time series. The 
package comes with several vignettes that can get you started quickly.

See the difference between classes ts and zoo below.

# make up some test data
oil <- data.frame(price = cumsum(rnorm(560)))
oil$date <- seq(as.Date("2020-01-22"), by = "1 day", length.out = 560)

# base R
pricet <- ts(oil$price, start = c(2020, 22), freq = 365)
time(pricet)
index(pricet)
plot(pricet)

#---

library(zoo)
library(ggplot2)

pricez <- zoo(oil$price, order.by = oil$date)
time(pricez)
index(pricez)
autoplot(pricez)

vignette(package = "zoo")


Hope this helps,

Rui Barradas

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

2023-01-16 Thread Upananda Pani
Dear All,

I have a time series daily data with date are stored ( %dd-%mm-%yy format )
from 22-01-20 to 03-08-21. In total I have 560 observations. I am using the
following command to declare as a time series object. Here the the data set
is 7 days a week.
oil <- read_xlsx("crudefinal.xlsx")
pricet=ts(oil$price, start = c(2020, 22), freq = 365)
roilt=ts(diff(log(oil$price))*100,start=c(2020,22), freq=365)

Shall I have to declare the dates here?  I want to know also if it is a 5
day trading a week, how to declare the frequency.

Looking forward to your reply

Regards,
Upananda Pani

Looking forward to your suggestions.

[[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] Printing special characters

2023-01-16 Thread Rui Barradas

Às 10:15 de 16/01/2023, Martin Maechler escreveu:

Rui Barradas
 on Mon, 16 Jan 2023 08:46:43 + writes:


 > Às 08:31 de 16/01/2023, Jeff Newmiller escreveu:
 >> Use the Cairo PDF device?
 >>
 >> On January 16, 2023 12:18:48 AM PST, Dennis Fisher
 >>  wrote:
 >>> R 4.2.2 OS X
 >>>
 >>> Colleagues
 >>>
 >>> A file that I have read includes strings like this:
 >>> "EVENT ≥ 30 sec" When I include the string in a graphic
 >>> using: mtext(STRING, …)  it appears as: "EVENT ... 30
 >>> sec"
 >>>
 >>> Is there a simple work-around (short of reformatting all
 >>> the strings, then using plotmath)?
 >>>
 >>> Dennis
 >>>
 >>> Dennis Fisher MD P < (The "P Less Than" Company) Phone /
 >>> Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.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.
 >>
 > Hello,

 > I had no problems with

 > X11()
 > plot(1,1, pch = "")
 > text(1, 1, "EVENT ≥ 30 sec")
 > #dev.off()

Yes, for me too.
X11() *is*  by default the "X11cairo" device and that works, the
same as the "Cairo PDF" device that Jeff mentioned above.

Indeed,
   cairo_pdf("utf8-ex.pdf")  # works nicely

whereas  pdf("utf8-ex.pdf") does not {for me, with default font
families etc}, but rather shows the "..." instead.

*and* gives warnings during the plot
   conversion failure on 'EVENT ≥ 30 sec' in 'mbcsToSbcs': dot substituted for 

   conversion failure on 'EVENT ≥ 30 sec' in 'mbcsToSbcs': dot substituted for 
<89>
   conversion failure on 'EVENT ≥ 30 sec' in 'mbcsToSbcs': dot substituted for 


BTW, a simple one liner for testing is

plot(1, type="n", axes=FALSE, main = "EVENT ≥ 30 sec")

Note that help(pdf)  contains

See Also:

 pdfFonts, pdf.options, embedFonts, Devices, postscript.

 cairo_pdf and (on macOS only) quartz for other devices that
 can produce PDF.

 More details of font families and encodings and especially
 handling text in a non-Latin-1 encoding and embedding fonts can be
 found in

 Paul Murrell and Brian Ripley (2006).  “Non-standard fonts in
 PostScript and PDF graphics.” _R News_, *6*(2), 41-47.
 .

-
Martin

 > Hope this helps,
 > Rui Barradas

Hello,

I can confrim this behavior with cairo_pdf(), it works as expected 
printing "EVENT ≥ 30 sec".

But with pdf() I get an equal sign "EVENT = 30 sec" and no errors.
Full code:



cairo_pdf("~/Temp/cairo_pdf_utf8-ex.pdf")  # works
plot(1,1, pch = "")
text(1, 1, "EVENT ≥ 30 sec")
dev.off()
# null device
#   1

pdf("~/Temp/pdf_utf8-ex.pdf")  # prints "=", no warnings
plot(1,1, pch = "")
text(1, 1, "EVENT ≥ 30 sec")
dev.off()
# null device
#   1

sessionInfo()
# R version 4.2.1 (2022-06-23 ucrt)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 22621)
#
# Matrix products: default
#
# locale:
# [1] LC_COLLATE=Portuguese_Portugal.utf8  LC_CTYPE=Portuguese_Portugal.utf8
# [3] LC_MONETARY=Portuguese_Portugal.utf8 LC_NUMERIC=C
# [5] LC_TIME=Portuguese_Portugal.utf8
#
# attached base packages:
# [1] stats graphics  grDevices utils datasets  methods   base
#
# loaded via a namespace (and not attached):
# [1] compiler_4.2.1
#


Also, nice trick to print the text as plot title, I will remember that 
one-liner.


Hope this helps,

Rui Barradas

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

2023-01-16 Thread Martin Maechler
> Rui Barradas 
> on Mon, 16 Jan 2023 08:46:43 + writes:

> Às 08:31 de 16/01/2023, Jeff Newmiller escreveu:
>> Use the Cairo PDF device?
>> 
>> On January 16, 2023 12:18:48 AM PST, Dennis Fisher
>>  wrote:
>>> R 4.2.2 OS X
>>> 
>>> Colleagues
>>> 
>>> A file that I have read includes strings like this:
>>> "EVENT ≥ 30 sec" When I include the string in a graphic
>>> using: mtext(STRING, …)  it appears as: "EVENT ... 30
>>> sec"
>>> 
>>> Is there a simple work-around (short of reformatting all
>>> the strings, then using plotmath)?
>>> 
>>> Dennis
>>> 
>>> Dennis Fisher MD P < (The "P Less Than" Company) Phone /
>>> Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.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.
>> 
> Hello,

> I had no problems with

> X11()
> plot(1,1, pch = "") 
> text(1, 1, "EVENT ≥ 30 sec")
> #dev.off()

Yes, for me too.
X11() *is*  by default the "X11cairo" device and that works, the
same as the "Cairo PDF" device that Jeff mentioned above.

Indeed,
  cairo_pdf("utf8-ex.pdf")  # works nicely

whereas  pdf("utf8-ex.pdf") does not {for me, with default font
families etc}, but rather shows the "..." instead.

*and* gives warnings during the plot
  conversion failure on 'EVENT ≥ 30 sec' in 'mbcsToSbcs': dot substituted for 

  conversion failure on 'EVENT ≥ 30 sec' in 'mbcsToSbcs': dot substituted for 
<89>
  conversion failure on 'EVENT ≥ 30 sec' in 'mbcsToSbcs': dot substituted for 


BTW, a simple one liner for testing is

   plot(1, type="n", axes=FALSE, main = "EVENT ≥ 30 sec")

Note that help(pdf)  contains

   See Also:

pdfFonts, pdf.options, embedFonts, Devices, postscript.

cairo_pdf and (on macOS only) quartz for other devices that
can produce PDF.

More details of font families and encodings and especially
handling text in a non-Latin-1 encoding and embedding fonts can be
found in

Paul Murrell and Brian Ripley (2006).  “Non-standard fonts in
PostScript and PDF graphics.” _R News_, *6*(2), 41-47.
.

-
Martin

> Hope this helps,
> Rui Barradas

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

2023-01-16 Thread PIKAL Petr
Hallo Dennis

Is the STRING in R still containing **≥** character?
Or it was converted during reading to R to ...?

What dput(STRING) result i?
 
Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Dennis Fisher
> Sent: Monday, January 16, 2023 9:19 AM
> To: r-help@r-project.org
> Subject: [R] Printing special characters
> 
> R 4.2.2
> OS X
> 
> Colleagues
> 
> A file that I have read includes strings like this:
>   "EVENT ≥ 30 sec"
> When I include the string in a graphic using:
>   mtext(STRING, …)
> it appears as:
>   "EVENT ... 30 sec"
> 
> Is there a simple work-around (short of reformatting all the strings, then 
> using
> plotmath)?
> 
> Dennis
> 
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone / Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Printing special characters

2023-01-16 Thread Rui Barradas

Às 08:31 de 16/01/2023, Jeff Newmiller escreveu:

Use the Cairo PDF device?

On January 16, 2023 12:18:48 AM PST, Dennis Fisher  wrote:

R 4.2.2
OS X

Colleagues

A file that I have read includes strings like this:
"EVENT ≥ 30 sec"
When I include the string in a graphic using:
mtext(STRING, …)
it appears as:
"EVENT ... 30 sec"

Is there a simple work-around (short of reformatting all the strings, then 
using plotmath)?

Dennis

Dennis Fisher MD
P < (The "P Less Than" Company)
Phone / Fax: 1-866-PLessThan (1-866-753-7784)
www.PLessThan.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.



Hello,

I had no problems with


X11()
plot(1,1, pch = "")
text(1, 1, "EVENT ≥ 30 sec")
#dev.off()


Hope this helps,

Rui Barradas

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

2023-01-16 Thread Eric Berger
How about  just 'EVENT > 30 sec' or 'EVENT > 29 sec' ?


On Mon, Jan 16, 2023 at 10:19 AM Dennis Fisher  wrote:

> R 4.2.2
> OS X
>
> Colleagues
>
> A file that I have read includes strings like this:
> "EVENT ≥ 30 sec"
> When I include the string in a graphic using:
> mtext(STRING, …)
> it appears as:
> "EVENT ... 30 sec"
>
> Is there a simple work-around (short of reformatting all the strings, then
> using plotmath)?
>
> Dennis
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.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.
>

[[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] Printing special characters

2023-01-16 Thread Jeff Newmiller
Use the Cairo PDF device?

On January 16, 2023 12:18:48 AM PST, Dennis Fisher  wrote:
>R 4.2.2
>OS X
>
>Colleagues
>
>A file that I have read includes strings like this:
>   "EVENT ≥ 30 sec"
>When I include the string in a graphic using:
>   mtext(STRING, …)
>it appears as:
>   "EVENT ... 30 sec"
>
>Is there a simple work-around (short of reformatting all the strings, then 
>using plotmath)?
>
>Dennis
>
>Dennis Fisher MD
>P < (The "P Less Than" Company)
>Phone / Fax: 1-866-PLessThan (1-866-753-7784)
>www.PLessThan.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.

-- 
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] Printing special characters

2023-01-16 Thread Dennis Fisher
R 4.2.2
OS X

Colleagues

A file that I have read includes strings like this:
"EVENT ≥ 30 sec"
When I include the string in a graphic using:
mtext(STRING, …)
it appears as:
"EVENT ... 30 sec"

Is there a simple work-around (short of reformatting all the strings, then 
using plotmath)?

Dennis

Dennis Fisher MD
P < (The "P Less Than" Company)
Phone / Fax: 1-866-PLessThan (1-866-753-7784)
www.PLessThan.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.