0

I started R only a bit ago. So I would like to ask you if I am doing t-test right with my purpose.

I have two data set like this.

> head(da1)
LiefertagDeliveryDate Price Hour
1              2015-12-31 28.82    1
25             2015-12-30 42.97    1
49             2015-12-29 43.38    1
73             2015-12-28 48.54    1
97             2015-12-27 46.36    1
121            2015-12-26 42.68    1

And,

> head(sp1)
# A tibble: 6 x 3
    Date  Hour  Price
  <dttm> <chr>  <dbl>
1 2015-12-31     1  16.06
2 2015-12-30     1  28.51
3 2015-12-29     1  20.59
4 2015-12-28     1  27.94
5 2015-12-27     1  13.42
6 2015-12-26     1 -36.07

So basically everyday, from 2015-12-31 down to 2011-01-01 for hour 1. I would like to conduct t.test for those data to compare the average of price for hour 1 in the each data set and see if it is significant.

For this purpose, I conducted,

t.test(da1$Price, sp1$Price, data=rp1, var.equal=TRUE, conf.level = 0.95, 
alternative = 'two.sided', paired=F) 

(For equal variance with 95% confidence level for two sided. not paired because it is two different data) Did I do it right for my purpose? I am very new with R, so I am not really sure if I did good work and since I am a programming beginner, strings and logicals all of that sound very foreign which makes me hard to understand the description in help.

Thank you for your kind advise in advance.

Have a great day people!

S. Jay
  • 141
  • 2
  • 10
  • Programming-wise, though you don't need to supply the "data" argument to the function, since you are directly passing in the vectors `da1$price` and `sp1$price`. In terms of statistics, are you sure that the equal variance assumption is satistified? Have you checked using histograms or by estimating the variance directly? Also, I would avoid using `F` and `T` in your code. These are not reserved variables in R, so if you were to do something odd like `T <- F` this could have disastrous consequences. – alan ocallaghan Jan 05 '18 at 02:24
  • 1
    In spite of your assertion that the values are unpaired, the variables are paired on day (observations on the same day will tend to be related in a way that observations from random days would not). You're also unlikely to have the independence that the test assumes, since you have times series data. How do you get negative price? – Glen_b Jan 05 '18 at 07:21
  • Hello @Glen_b, since it is price for electricity, there are negative prices. So.. must they be paired as you said? – S. Jay Jan 05 '18 at 08:44
  • Yes, I explained they were paired -- and why. Thanks for the information about negative prices. Are they prices in two different markets or something? – Glen_b Jan 06 '18 at 23:20
  • Yes they are from two different financial markets :) – S. Jay Jan 07 '18 at 13:40

0 Answers0