[R] A question about for loop

2017-08-17 Thread Moohwan Kim
Dear R users,

I have the following codes:
zeta <- rep(1,8)
n <- 7
for (i in 1:2){
beta <- zeta[1:n+(i-1)*(n+1)]
print(beta)
parm <- zeta[i*(n+1)]
print(parm)
}
###
The output is as follows:
[1] 1 1 1 1 1 1 1
[1] 1
[1] NA NA NA NA NA NA NA
[1] NA
###
The outcome I want to get is:
[1] 1 1 1 1 1 1 1
[1] 1
[1] 1 1 1 1 1 1 1
[1] 1

How could I get the desired outcome?

best,
kmh

[[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] double integral calculation

2011-06-17 Thread Moohwan Kim
a=[0.1,0.2,0.1,0.3,0.4]
b=[0.2,0.3,0.1,0.2,0.5]
c=[1,1,1,1,1]
log(c+a-x*b) where x=unknown scale variable.

int=$$log(c+a-x*b)dadb, where $ denotes integral sign.

Actually, how could I calculate the integral's approximation?
double summation?

best,
moohwan

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


[R] How to include a few selected AR terms

2011-01-30 Thread Moohwan Kim
Dear R family,

I have a quick question.

m3=arima(zt,order=c(6,0,2)) % fit an ARIMA(6,0,2) model to zt.

This equation contains all 6 AR terms plus 1 MA term.
I want to include only AR(2) and MA(1) excluding the other terms.
How could I accomplish it?

best,
moohwan

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


[R] Estimate an initial value for the level series from a return series

2010-08-03 Thread Moohwan Kim
Dear R family,

Today I have a tough question related to the model specification issue.
I obtain two log return series by first differencing the associated
price series each.
Then I produce two filtered log return series.
My objective is to check if there is cointegration relation between the two.
In the process, the level series should be used.
As you guess, I got far away from the original level series because I
twisted (i.e., filtered) the original log returns.
That is, with the filtered returns, I am not able to use the original
level series because its attributes or structures may change in the
middle of the data transformation.
My idea of overcoming the designated problem above is that I have to
recover the level series based on the filtered log returns.
In order to accomplish this task, I must estimate an initial value for
the level series. Actually I have to have two initial values because
there are two series.

My question is as follow:
Given the filtered log return series, is there a reasonable way to
estimate an initial value for the price series?

Best regards
moohwan kim

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


[R] Question about allocMatrix error message

2010-07-21 Thread Moohwan Kim
Dear R family,

I faced a technical problem in r coding.
 #s=t(dev)%*%dev/(nr-1) # dev (100,000 by 2) stands for
deviation from the mean
 #sinv=solve(s)
 #t2=diag(dev%*%sinv%*%t(dev))

I got an error message at t2 statement:
Error in diag(dev %*% si %*% t(dev)) : allocMatrix: too many elements specified

Please let me know if there is a way to overcome this problem.

best
moohwan

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


[R] to remove duplicate values

2010-07-05 Thread Moohwan Kim
Dear R family,

Suppose I have two series.

order value
1  0.52
2  0.23
3  0.43
4  0.21
5  0.32
6  0.32
7  0.32
8  0.32
9  0.32
10 0.12
11 0.46
12 0.09
13 0.32
14 0.25

For these two series, I figured out the way to detect the locations of
duplicate values.
The next thing to do is remove the repeated values except for a value
that would not be next to each other.
In other words, while keeping the 13th value, I want to remove
observations from 6th to 9th.
That is my end goal.

Could you help me reach the goal?

best
moohwan

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


[R] To detect the location of duplicate values

2010-07-05 Thread Moohwan Kim
Dear R family,

I have a question about how to detect some duplicate numeric observations.
Suppose that I have two variables dataset.

order value
1  0.52
2  0.23
3  0.43
4  0.21
5  0.32
6  0.32
7  0.32
8  0.32
9  0.32
10 0.12
11 0.46
12 0.09
13 0.32
14 0.25
;
Could you help me indicate where the duplicate observations in a row
(e.g., 0.32) are?

best,
moohwan

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


[R] Convolution vector to be derived

2010-06-04 Thread Moohwan Kim
Dear R-help,

I want to generate the following outcome using the convolution of two sequences.

x <- c(1,2,3,4,5)
y <- c(6,7,8,9)

The resulting convolution vector is
6
19
40
70
100
94
76
45
When using convolve(), it is hard to produce the result above.
Would you help me out to get that?

Best regards
Moohwan Kim

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


[R] Convolution vector to be derived

2010-06-04 Thread Moohwan Kim
I want to generate the following outcome using convolution of two sequences.

x <- c(1,2,3,4,5)
y <- c(6,7,8,9)

The resulting convolution vector is
6
19
40
70
100
94
76
45
When using convolve(), it is hard to produce the result above.
Would you help me out to get that?

Best regards
Moohwan Kim

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


[R] How to interpret a result based on wmtsa

2010-05-29 Thread Moohwan Kim
Dear R family

I have a question as to how to get an answer I want to derive with the
outcome from R-package, "wmtsa".
My concern is that I want to decide equivalent degrees of freedom
(EDOF) based on the following outcome.

library(wmtsa)
W <- wavMODWT(X, wavelet="s8")
z1 <- wavEDOF(W)
print(z1)
#Intentionally, I do not assign n.levels and specify SDF.

The following is the outcome R gave out:
##
$EDOF1
d1   d2   d3   d4   d5   d6
272462.52504 189076.44195  95736.37691  47830.40918  23593.41513
12409.42279
d7   d8   d9  d10  d11  d12
 5977.28418   2887.81182   1408.06198629.46550368.87030197.00823
   d13  d14  d15
 106.22607 29.75633 14.29115

$EDOF2
 [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA

$EDOF3
d1   d2   d3   d4   d5   d6
2.079385e+05 1.039658e+05 5.197938e+04 2.598619e+04 1.298959e+04
6.491297e+03
d7   d8   d9  d10  d11  d12
3.242148e+03 1.617574e+03 8.052871e+02 3.991436e+02 1.960718e+02
9.453589e+01
   d13  d14  d15
4.376794e+01 1.838397e+01 5.691986e+00

$variance.unbiased
d1   d2   d3   d4   d5   d6
1.940001e+03 9.671358e+02 4.815657e+02 2.402054e+02 1.206654e+02
6.019255e+01
d7   d8   d9  d10  d11  d12
3.021483e+01 1.518668e+01 7.709990e+00 3.859226e+00 1.850228e+00
9.825597e-01
   d13  d14  d15
4.609490e-01 6.416134e-02 1.513369e-02

$n.coeff
  d1 d2 d3 d4 d5 d6 d7 d8 d9d10d11
415877 415863 415835 415779 415667 415443 414995 414099 412307 408723 401555
 d12d13d14d15
387219 358547 301203 186515

#

How could I determine the equivalent degrees of freedom?

It would be great if you give me any suggestion.

best
moohwan

[[alternative HTML version deleted]]

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


[R] how to pick equivalent degrees of freedom in a R package wmtsa

2010-05-26 Thread Moohwan Kim
Dear R family

I have a question as to how to get an answer I want to derive with the
outcome from R-package, "wmtsa".
My concern is that I want to decide equivalent degrees of freedom
(EDOF) based on the following outcome.

library(wmtsa)
W <- wavMODWT(X, wavelet="s8")
z1 <- wavEDOF(W)
print(z1)
#Intentionally, I do not assign n.levels and specify SDF.

The following is the outcome R gave out:
##
$EDOF1
 d1   d2   d3   d4   d5   d6
272462.52504 189076.44195  95736.37691  47830.40918  23593.41513  12409.42279
 d7   d8   d9  d10  d11  d12
 5977.28418   2887.81182   1408.06198629.46550368.87030197.00823
d13  d14  d15
  106.22607 29.75633 14.29115

$EDOF2
 [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA

$EDOF3
 d1   d2   d3   d4   d5   d6
2.079385e+05 1.039658e+05 5.197938e+04 2.598619e+04 1.298959e+04 6.491297e+03
 d7   d8   d9  d10  d11  d12
3.242148e+03 1.617574e+03 8.052871e+02 3.991436e+02 1.960718e+02 9.453589e+01
d13  d14  d15
4.376794e+01 1.838397e+01 5.691986e+00

$variance.unbiased
 d1   d2   d3   d4   d5   d6
1.940001e+03 9.671358e+02 4.815657e+02 2.402054e+02 1.206654e+02 6.019255e+01
 d7   d8   d9  d10  d11  d12
3.021483e+01 1.518668e+01 7.709990e+00 3.859226e+00 1.850228e+00 9.825597e-01
d13  d14  d15
4.609490e-01 6.416134e-02 1.513369e-02

$n.coeff
   d1 d2 d3 d4 d5 d6 d7 d8 d9d10d11
415877 415863 415835 415779 415667 415443 414995 414099 412307 408723 401555
  d12d13d14d15
387219 358547 301203 186515

#

How could I determine the equivalent degrees of freedom?

It would be great if you give me any suggestion.

best
moohwan

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


[R] To correct an error message

2010-05-17 Thread Moohwan Kim
Dear R Family,

I have an error message. I would like to learn how to deal with that.
The orginal series is as follows: I just pick up the first 10 observations.
> dif_transaud[1:10]
 [1]  0.0065880493 -0.0065880490 -0.0131743570  0.0197745715  0.0065889175
 [6]  0.0131813110  0.0065923924 -0.0395587070  0.156455  0.0197693578

Then I transformed them into the following observations.
> dif_transaud_sq <- dif_transaud^2
> lnabsdif_transaud <- 0.5*log(dif_transaud_sq)
> lnabsdif_transaud[1:10]
 [1]  -5.022498  -5.022498  -4.329483  -3.923358  -5.022366  -4.328955
 [7]  -5.021839  -3.229969 -11.065327  -3.923622

Finally, I run the program, which is part of wavelet transform.
> mra.out <- mra(lnabsdif_transaud, filter="la8", n.levels=8,
+   boundary="reflection", fast=TRUE, method="modwt")

However, this triggered an error message.
> Error in FUN(1L[[1L]], ...) : NA/NaN/Inf in foreign function call (arg 1)

I guess there are a few big negative numbers in lnabsdif_transaud.
I was wondering if there is an appropriate way to truncate those
numbers in a reasonable way.

Regards,
Moohwan Kim

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


[R] How to manage an error message about NA/NaN/Inf

2010-05-16 Thread Moohwan Kim
Dear R Family,

I have an error message. I would like to learn how to deal with that.
The orginal series is as follows: I just pick up the first 10 observations.
> dif_transaud[1:10]
 [1]  0.0065880493 -0.0065880490 -0.0131743570  0.0197745715  0.0065889175
 [6]  0.0131813110  0.0065923924 -0.0395587070  0.156455  0.0197693578

Then I transformed them into the following observations.
> dif_transaud_sq <- dif_transaud^2
> lnabsdif_transaud <- 0.5*log(dif_transaud_sq)
> lnabsdif_transaud[1:10]
 [1]  -5.022498  -5.022498  -4.329483  -3.923358  -5.022366  -4.328955
 [7]  -5.021839  -3.229969 -11.065327  -3.923622

Finally, I run the program, which is part of wavelet transform.
> mra.out <- mra(lnabsdif_transaud, filter="la8", n.levels=8,
+   boundary="reflection", fast=TRUE, method="modwt")

However, this triggered an error message.
> Error in FUN(1L[[1L]], ...) : NA/NaN/Inf in foreign function call (arg 1)

I guess there are a few big negative numbers in lnabsdif_transaud.
I was wondering if there is an appropriate way to truncate those
numbers in a reasonable way.

Regards,
Moohwan Kim

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


[R] Singularity problem

2010-01-08 Thread Moohwan Kim
Dear R family

I have a problem with invertibility in a matrix.

m1 <- ar(x, method='mle')

Error in solve.default(res$hessian * length(x)) :
  Lapack routine dgesv: system is exactly singular

How could I avoid this problem?

Best
Moohwan

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


[R] to remove an error with log(zero)

2009-12-17 Thread Moohwan Kim
Dear R family

I have an arbitrary column vector.
1
2
4
0
7
5
0
0
0
9
11
12
When I attempt to take natural logarithm of the series, as you guess
there is an error message. To overcome this problem, my idea is to
replace a zero or zeros in a row with appropriate numbers.
In order to implement it, I need to detect where zeros are.
Then I am going to take the average of two adjacent neighbors. In the
case of zeros in a row, I guess I might apply the above idea
sequentially.

Would you help me out to escape from this jungle?
Thanks in advance.

Best
Moohwan

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


[R] too large dimension problem

2009-12-12 Thread Moohwan Kim
Dear R family

When I run the command below, the error message came up. It seems like
the problem is about computer capacity.
It would be appreciated if anyone could give me a solution.

###
> N <- 415884
> tau <- diag(1, N)[c(N, 1:(N - 1)),]
Error in array(0, c(n, p)) : 'dim' specifies too large an array

Best
Moohwan

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


[R] How to calculte the power of a matrix

2009-12-11 Thread Moohwan Kim
Dear R family

 I have a following question.
 Suppose I have a matrix as follows, for instance:
 tau=
 0 1 0 0 0
 0 0 1 0 0
 0 0 0 1 0
 0 0 0 0 1
 1 0 0 0 0

 I want to calculate (-m) power of tau, for example, m=893.

When I run tau^2, the outcome is just tau.
Any help would be appreciated.

thanks in advance.

best
moohwan

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


[R] How could I find the inverse of a matrix?

2009-12-11 Thread Moohwan Kim
Dear R family

I have a following question.
Suppose I have a matrix as follows, for instance:
tau=
0 0 0 0 1
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0

I want to have the inverse of the above matrix and then add some
exponent to it. That is, I want to calculate tau to the (-m). For
example, m=893.

Thanks in advance

Best regards
Moohwan Kim

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


[R] how to creat a matrix

2009-12-11 Thread Moohwan Kim
Dear R family

  I am attempting to create a matrix. e.g.,
  0 0 0 0 1
  1 0 0 0 0
  0 1 0 0 0
  0 0 1 0 0
  0 0 0 1 0
  How could I write a R program?
  Later I want to extend it to a N by N case.
  Thanks in advance

  best
  Moohwan

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