Related
I am a newbie in R. Now, I want to create a matrix, and then extract 20 random Numbers from each of these three uniform distributions: U(0.6,0.8), U(0.0001,0.0003), U(100,110), and place them in the first three columns of the matrix, with each column corresponding to a uniform distribution. Then 20 random Numbers are extracted from each of the two normal distributions: N(7750,0.01), N(12,0.4), and placed in the last two columns of the matrix. My program is as follows, but can only achieve uniform distribution of random numbers, cannot achieve the first three columns are uniform distribution, the last two columns are the normal distribution of random numbers, How can I change it?
input <-5 # variable input
xinput <- 20 #sampling number
range <- matrix(c(0.60,0.80,
0.0001,0.0003,
100,110,
7700,8000,
10,15,
),nrow=input,ncol=2,byrow=TRUE)
range
rangeresult <- matrix(0, nrow=xinput, ncol=input)# empty matrix for latter data
rangeresult
##uniform distribution
for (i in 1:input){
set.seed(456+i) # make results reproducible
rangeresult[,i] <- runif(xinput,range[i,1],range[i,2])
}
Perhaps try this
cbind(
u1 = runif(20L, 0.6, 0.8),
u2 = runif(20L, 0.0001, 0.0003),
u3 = runif(20L, 100, 110),
n1 = rnorm(20L, 7750, 0.01),
n2 = rnorm(20L, 12, 0.4)
)
Output
u1 u2 u3 n1 n2
[1,] 0.7558480 0.0002851074 101.7209 7749.988 11.75270
[2,] 0.7807589 0.0002600877 104.9278 7749.998 11.67970
[3,] 0.7480385 0.0001562960 109.5744 7749.979 11.84603
[4,] 0.6283492 0.0001408027 108.9455 7749.999 12.00459
[5,] 0.7666862 0.0002485003 106.4735 7750.002 12.58783
[6,] 0.6354397 0.0001042544 107.0999 7749.982 12.36555
[7,] 0.7340912 0.0002507386 109.7052 7749.994 11.75111
[8,] 0.7220797 0.0001173221 105.7116 7749.995 11.35322
[9,] 0.6956138 0.0001478050 104.6444 7750.004 11.68879
[10,] 0.6146491 0.0001238944 108.5946 7750.006 12.78417
[11,] 0.7436676 0.0002492057 107.6073 7750.003 11.80814
[12,] 0.7916866 0.0001927277 100.1949 7750.016 12.16362
[13,] 0.7701075 0.0002236796 103.9207 7750.007 11.82555
[14,] 0.7151522 0.0001528767 101.0997 7749.996 11.75938
[15,] 0.6866158 0.0002872521 100.7036 7750.018 11.36261
[16,] 0.6106267 0.0001278512 105.8946 7749.986 11.81682
[17,] 0.6537794 0.0002875799 104.2015 7750.007 11.56224
[18,] 0.6095022 0.0001534366 108.9352 7749.993 12.22691
[19,] 0.7156714 0.0001303851 107.7274 7749.995 12.01923
[20,] 0.6397735 0.0002706792 109.6200 7749.986 12.01927
matrix(
c(runif(20, .6, .8),
runif(20, .0001, .0003),
runif(20, 100, 110),
rnorm(20, 7750, .01),
rnorm(20, 12, .4)),
ncol=5)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.6303004 0.0002700728 102.6577 7750.008 12.10271
#> [2,] 0.7611678 0.0001594420 106.2736 7750.001 11.95071
#> [3,] 0.7217263 0.0002726162 105.9933 7749.993 12.16880
#> [4,] 0.7873636 0.0001409666 109.9674 7750.016 11.58212
#> [5,] 0.7329912 0.0002504620 105.8886 7750.005 11.62768
#> [6,] 0.6775068 0.0002546660 109.9630 7750.000 11.75542
#> [7,] 0.6927353 0.0001217041 105.5130 7750.004 12.46987
#> [8,] 0.7889347 0.0001849753 105.8204 7750.002 11.96011
#> [9,] 0.7555766 0.0001712631 104.6053 7750.013 12.77534
#> [10,] 0.6225500 0.0001441519 101.4559 7750.011 11.62323
#> [11,] 0.6004412 0.0002862156 100.7426 7750.015 12.34398
#> [12,] 0.7896445 0.0001871342 103.5566 7750.002 11.18040
#> [13,] 0.7995510 0.0002998966 101.2008 7750.005 11.79095
#> [14,] 0.7271423 0.0001385434 108.3129 7750.006 11.85577
#> [15,] 0.7990341 0.0001868429 102.3255 7749.974 12.00426
#> [16,] 0.7711383 0.0001362412 108.1071 7749.995 11.62242
#> [17,] 0.7168780 0.0001821163 103.0949 7750.021 12.35856
#> [18,] 0.7197489 0.0002015831 109.4623 7749.981 11.46613
#> [19,] 0.7006335 0.0001257633 100.9744 7750.001 12.03066
#> [20,] 0.7503335 0.0002953110 102.1582 7749.989 12.54394
My question is related to this one here, which unfortunately has not been responded. I'm trying to automatically annotate text next to highlighted communities on a plot. An intermediate step is to understand how nodes are placed on a plot.
G <- make_graph('zachary')
l <- layout_with_fr(G)
l
A layout is a matrix with rows representing nodes and columns representing the x and y plot parameters.
[,1] [,2]
[1,] 2.8510654 -2.2404898
[2,] 2.7183497 -1.1815130
[3,] 3.1429205 0.1117099
[4,] 1.5585372 -1.0743325
[5,] 2.2808632 -4.2035479
[6,] 2.1698198 -5.0526766
[7,] 1.4938068 -4.6975884
[8,] 1.9710816 -1.4672218
[9,] 3.5407035 0.5407852
[10,] 2.2222909 1.9079805
[11,] 3.0784642 -4.5828448
[12,] 4.4115351 -4.1057462
[13,] 0.6002378 -2.2432049
[14,] 2.5010525 -0.1563341
[15,] 4.8914673 4.1417759
[16,] 3.2053338 3.9212694
[17,] 1.1825200 -6.4099021
[18,] 3.7155897 -2.8354432
[19,] 3.8272351 4.2660906
[20,] 3.8636487 -0.5671906
[21,] 2.7302411 3.3998888
[22,] 1.6084374 -2.7407388
[23,] 4.3432855 3.8101278
[24,] 5.9392042 2.2364929
[25,] 6.9980077 0.2389222
[26,] 7.1608499 1.1360134
[27,] 6.0171481 4.0279067
[28,] 5.4996627 1.0367163
[29,] 4.4961257 0.9434659
[30,] 5.5987563 3.2314488
[31,] 2.9958404 1.2022317
[32,] 5.1188900 0.2919268
[33,] 4.1088296 2.5032294
[34,] 4.1686534 2.1339884
But the x, y coordinates of the plot go from -1 to 1, unlike the min-max coordinates in the layout matrix. So how is plot(G, layout = l) reading the layout matrix?
The according to the source, the plot method for objects of class igraph simply rescales the matrix from -1 to 1.
library(igraph)
set.seed(3)
l <- layout_with_fr(G)
[,1] [,2]
[1,] -2.283 0.658
[2,] -1.289 -0.108
[3,] 0.146 1.012
[4,] -1.523 1.601
#... with 30 more rows.
plot(G,layout = l)
maxs <- apply(l, 2, max)
mins <- apply(l, 2, min)
ll <- scale(l, center=(maxs+mins)/2, scale=(maxs-mins)/2)
ll
[,1] [,2]
[1,] -0.2422 -0.1051
[2,] -0.0704 -0.3821
[3,] 0.1775 0.0228
[4,] -0.1108 0.2357
#... with 30 more rows.
plot(G,layout = ll)
Note that the actual rescaling is performed with igraph::norm_coords:
igraph::norm_coords(l)
[,1] [,2]
[1,] -0.2422 -0.1051
[2,] -0.0704 -0.3821
[3,] 0.1775 0.0228
[4,] -0.1108 0.2357
#... with 30 more rows.
I have generated an Auto Arima model.
The model specification of the output is as shown below :-
ts_regr_auto_new_objects[[1]]$model
$phi
[1] 0.7543751 -0.6873447 0.5583951
$theta
[1] 0.06711257 0.66005781 0.18953643
$Delta
numeric(0)
$Z
[1] 1 0 0 0
$a
[1] -2755.5419 -301.0682 -1891.6939 -266.0682
$P
[,1] [,2] [,3] [,4]
[1,] 0 0.000000e+00 0.000000e+00 0.000000e+00
[2,] 0 -6.938894e-18 -2.775558e-17 -8.673617e-18
[3,] 0 -2.775558e-17 1.110223e-16 2.775558e-17
[4,] 0 -8.673617e-18 2.775558e-17 6.938894e-18
$T
[,1] [,2] [,3] [,4]
[1,] 0.7543751 1 0 0
[2,] -0.6873447 0 1 0
[3,] 0.5583951 0 0 1
[4,] 0.0000000 0 0 0
$V
[,1] [,2] [,3] [,4]
[1,] 1.00000000 0.067112571 0.66005781 0.18953643
[2,] 0.06711257 0.004504097 0.04429818 0.01272028
[3,] 0.66005781 0.044298176 0.43567631 0.12510500
[4,] 0.18953643 0.012720277 0.12510500 0.03592406
$h
[1] 0
$Pn
[,1] [,2] [,3] [,4]
[1,] 1.00000000 0.067112571 0.66005781 0.18953643
[2,] 0.06711257 0.004504097 0.04429818 0.01272028
[3,] 0.66005781 0.044298176 0.43567631 0.12510500
[4,] 0.18953643 0.012720277 0.12510500 0.03592406
The model summary is as shown below :-
summary(ts_regr_auto_new_objects[[1]])
Series: histmodellingdataxtsobjects[[i]]$usage
Regression with ARIMA(3,0,3) errors
Coefficients:
ar1 ar2 ar3 ma1 ma2 ma3 intercept temp new_wday_ind S1.365 C1.365 S1.7 C1.7
0.7544 -0.6873 0.5584 0.0671 0.6601 0.1895 20148.1783 -255.7988 1002.2502 4591.0172 -1603.2133 242.1379 -378.4656
s.e. 0.1216 0.1551 0.0991 0.1285 0.1186 0.0742 530.3229 24.0099 190.2674 437.2782 393.9352 104.1117 129.0343
sigma^2 estimated as 1263859: log likelihood=-3244.91
AIC=6517.82 AICc=6518.96 BIC=6573.17
Training set error measures:
ME RMSE MAE MPE MAPE MASE ACF1
Training set -0.311974 1105.072 803.1194 -0.3683012 5.199148 0.7109852 -0.00255312
Can anyone show me how do I calculate the 'p value' and 't' statistic values for the various parameter estimates from the given standard errors?
Best regards
Deepak
I want to simulate some time series data with mean = 0 but varying:
Mathematically, moving average process of order one, MA(1) is presented as
$$x_t=\mu+\varepsilon_{t}+\theta_{1}\varepsilon_{t-1}$$
$x_t$ is the MA(1) process
$\mu$ is the mean which can be zero in my case (just like intercept in regression equation)
$\varepsilon_{t}$ is the error term
$\theta_{1}$ is a constant which need be specified (in my case, a varying number in between +-1). Example: in simple regression equation of $x=a+b*x_{i}$, $theta$ is like the $b$
Number N = 15, 20, 30, 50, 100, 200.
Standard Deviation SD=1, 4, 9, 16, 25.
and theta value \theta = +-0.2, +-0.4, +-0.6, +-0.8, +-0.9, +-0.95, +-0.99
set.seed(123)
# here I am only using first sample size 15
n <- 15
# white noise:
wnsd1<-ts(rnorm(n, mean=0, sd=1^2))
wnsd4<-ts(rnorm(n, mean=0, sd=2^2))
wnsd9<-ts(rnorm(n, mean=0, sd=3^2))
wnsd16<-ts(rnorm(n, mean=0, sd=4^2))
wnsd25<-ts(rnorm(n, mean=0, sd=5^2))
# initialise the first two values:
ma1 <- wnsd1[1:2]
# loop through and create the 3:15th values:
for(i in 3:n){
# here I only use when SD=1
ma1[i] <- wnsd1[i - 1] * 0.2 + wnsd1[i]
}
#turn them into time series, and for the last two, "integrate" them via cumulative sum
ma1 <- ts(ma1)
I want a mature way of varying the sample size N, the standard deviation SD and the estimate of MA(1) \theta
Here's an OK way. Note, I do not know how phi is used as it wasn't explicitly in the code. If you modify your code, I would try to address it.
N <- c(15L, 20L)
SD = c(1, 2)^2
phi = c(0.2, 0.4)
set.seed(123)
res <- lapply(N,
function(n)
lapply(SD,
function(s.d.) {
wn <- ts(rnorm(n, 0, s.d.))
ar1 <- ma1 <- arma11 <- arma22 <- vector('numeric', n)
ar1 <- ma1 <- arma11 <- arma22 <- wn[1:2]
for (i in 3:n) {
ar1[i] <- ar1[i - 1] * 0.2 + wn[i]
ma1[i] <- wn[i - 1] * 2.8000 + wn[i]
arma11[i] <- arma11[i - 1] * 0.2 + wn[i - 1] * 2.80003769654 + wn[i]
arma22[i] <- arma22[i - 1] * 0.862537 + arma22[i - 2] * (-0.3) + 0.2 * wn[i - 1] - 0.3 * wn[i -
2] + wn[i]
}
#turn them into time series, and for the last two, "integrate" them via cumulative sum
return(data.frame(ar1 = ts(ar1),
ma1 = ts(ma1),
arma11 = ts(arma11),
arima111 = ts(cumsum(arma11)),
arima222 = ts(cumsum(cumsum(arma22)))
))
}))
res <- setNames(lapply(res, setNames, paste('SD', SD, sep = '_')), paste('n', N, sep = '_'))
res
Result - truncated to only one combination:
$n_15
$n_15$SD_1
ar1 ma1 arma11 arima111 arima222
1 -0.5604756 -0.56047565 -0.56047565 -0.56047565 -0.5604756
2 -0.2301775 -0.23017749 -0.23017749 -0.79065314 -1.3511288
3 1.5126728 0.91421134 0.86816717 0.07751403 -0.4913603
4 0.3730430 4.43489167 4.60858386 4.68609790 2.3123144
5 0.2038963 0.32671123 1.24843066 5.93452856 5.9733306
6 1.7558443 2.07707065 2.32676165 8.26129021 11.5104337
7 0.8120851 5.26309817 5.72851515 13.98980536 19.1736717
8 -1.1026442 0.02550414 1.17122455 15.16102991 26.4205560
9 -0.9073817 -4.22902431 -3.99482709 11.16620282 31.5923395
10 -0.6271383 -2.36884996 -3.16784126 7.99836155 34.8956636
11 1.0986541 -0.02377172 -0.65735677 7.34100478 38.5509080
12 0.5795447 3.78724286 3.65581765 10.99682243 43.8085632
13 0.5166804 1.40825017 2.13942726 13.13624969 50.4482906
14 0.2140188 1.23284278 1.66074334 14.79699303 57.8822760
15 -0.5130374 -0.24592953 0.08622331 14.88321634 64.9327807
Edit: This approach is similar but uses explicit for loops instead of lapply and only returns the ma variable:
N <- c(15L, 20L)
SD = c(1, 2) ^ 2
phi = c(0.2, 0.4)
res <- vector('list', length(N))
names(res) <- paste('N', N, sep = '_')
set.seed(123L)
for (i in seq_along(N)){
res[[i]] <- vector('list', length(SD))
names(res[[i]]) <- paste('SD', SD, sep = '_')
ma <- matrix(NA_real_, nrow = N[i], ncol = length(phi))
for (j in seq_along(SD)){
wn <- rnorm(N[i], mean = 0, sd = SD[j])
ma[1:2, ] <- wn[1:2]
for (k in 3:N[i]){
ma[k, ] <- wn[k - 1L] * phi + wn[k]
}
colnames(ma) <- paste('ma_theta', phi, sep = '_')
res[[i]][[j]] <- ma
}
}
res
$N_15
$N_15$SD_1
ma_theta_0.2 ma_theta_0.4
[1,] 0.68374552 0.68374552
[2,] -0.06082195 -0.06082195
[3,] 0.62079632 0.60863193
[4,] 1.46210976 1.58870190
[5,] 0.27439361 0.54149714
[6,] 1.01901666 1.02047467
[7,] -0.98492231 -0.78141058
[8,] -0.95929125 -1.19697805
[9,] 1.37489682 1.23057594
[10,] 0.68123152 0.98507506
[11,] -1.97674523 -1.90126763
[12,] -1.77448202 -2.18492658
[13,] -0.47358851 -0.74639600
[14,] 0.82562320 0.78546700
[15,] 0.07127263 0.24442851
$N_15$SD_4
ma_theta_0.2 ma_theta_0.4
[1,] 2.4967499 2.4967499
[2,] 3.8360215 3.8360215
[3,] 7.4514236 8.2186279
[4,] 1.5609108 2.8977547
[5,] -0.1631142 -0.1183009
[6,] -7.0545350 -7.0961205
[7,] -1.0052795 -2.4078694
[8,] -2.2079382 -2.1284761
[9,] -4.3535184 -4.8109984
[10,] -1.4988326 -2.2780403
[11,] 3.9158477 3.7719227
[12,] -7.1590394 -6.3470849
[13,] -3.3033159 -4.8975147
[14,] 0.1247257 -0.2170977
[15,] -3.4795205 -3.3862106
$N_20
$N_20$SD_1
ma_theta_0.2 ma_theta_0.4
[1,] 0.33390294 0.3339029
[2,] 0.41142992 0.4114299
[3,] 0.04924982 0.1315358
[4,] -2.47250543 -2.4791127
[5,] 2.07827851 1.5850989
[6,] 0.30899237 0.8232840
[7,] 0.61013343 0.5690736
[8,] 0.40400515 0.5342438
[9,] 1.07942653 1.1341798
[10,] 1.02259409 1.2275287
[11,] -0.04626128 0.1172706
[12,] 0.33620914 0.2942505
[13,] -0.86977528 -0.7941417
[14,] 0.66784124 0.4787595
[15,] -0.28965374 -0.1182691
[16,] 2.32456569 2.2323580
[17,] -1.16769422 -0.6843396
[18,] -0.79419702 -1.1244068
[19,] 0.73258241 0.6397850
[20,] 0.67520852 0.8402845
$N_20$SD_4
ma_theta_0.2 ma_theta_0.4
[1,] -2.35792415 -2.35792415
[2,] -3.98712297 -3.98712297
[3,] -0.21952177 -1.01694637
[4,] 0.05835091 0.17393147
[5,] -7.17257088 -7.18401681
[6,] -1.29402072 -2.72624571
[7,] 0.78856212 0.81620297
[8,] 0.85108984 1.00327409
[9,] -4.08028705 -3.94050594
[10,] 1.06051948 0.21650585
[11,] 5.89518717 6.27609379
[12,] 2.92780172 4.03065783
[13,] -4.17736476 -3.81237564
[14,] -2.65105266 -3.55952343
[15,] 1.03589810 0.68738173
[16,] -2.31129963 -2.03441673
[17,] -9.14822185 -9.66585835
[18,] 1.81088621 0.08476914
[19,] -2.61050979 -1.90310913
[20,] -2.95782317 -3.62140526
I have a function which applied on a vector of lenght 5 returns a matrix with 4 rows and 5 columns. Then I want to use apply() in order to call my function again on each row of the results matrix and obtain matrix with 16 (4*4) rows and 5 columns. Unfortuneately apply() combines the results into 4x20 matrix. How is it possible to change that without using lists?
matrixFromVector = function(x){
return(rbind(x*rnorm(1,1,.01),x*rnorm(1,1,.01),x*rnorm(1,1,.1),x*rnorm(1,1,.01))) }
a = matrixFromVector(1:5)
t(a)
[,1] [,2] [,3] [,4]
[1,] 1.008391 1.005974 1.077223 0.9865611
[2,] 2.016782 2.011947 2.154445 1.9731222
[3,] 3.025173 3.017921 3.231668 2.9596833
[4,] 4.033565 4.023894 4.308890 3.9462444
[5,] 5.041956 5.029868 5.386113 4.9328055
After applying my function to each row of a I would like to have
[1,] [2,] [3,] [4,] [5,]
[1,] 1.0242459 2.0484917 3.0727376 4.0969835 5.1212293
[2,] 0.9999314 1.9998629 2.9997943 3.9997257 4.9996572
[3,] 1.0836573 2.1673146 3.2509719 4.3346292 5.4182865
[4,] 1.0005137 2.0010275 3.0015412 4.0020550 5.0025687
[5,] 1.0314108 2.0628216 3.0942323 4.1256431 5.1570539
[6,] 0.9995248 1.9990496 2.9985744 3.9980992 4.9976239
[7,] 1.0908017 2.1816034 3.2724051 4.3632069 5.4540086
[8,] 0.9801833 1.9603667 2.9405500 3.9207333 4.9009166
[9,] 0.9697334 1.9394669 2.9092003 3.8789338 4.8486672
[10,] 0.8484190 1.6968380 2.5452570 3.3936760 4.2420950
[11,] 0.9120351 1.8240703 2.7361054 3.6481405 4.5601756
[12,] 0.9596908 1.9193816 2.8790724 3.8387632 4.7984540
[13,] 1.0226757 2.0453515 3.0680272 4.0907030 5.1133787
[14,] 1.0069771 2.0139543 3.0209314 4.0279085 5.0348857
[15,] 1.0748773 2.1497545 3.2246318 4.2995090 5.3743863
[16,] 0.9841864 1.9683728 2.9525592 3.9367456 4.9209319
Instead I got
apply(a,1,matrixFromVector)
[,1] [,2] [,3] [,4]
[1,] 1.0262524 1.0237143 1.074673 0.9885002
[2,] 0.9990472 1.0189053 1.062644 0.9965570
[3,] 0.9464976 0.8973152 1.138847 0.8639614
[4,] 1.0063561 1.0080947 1.080825 1.0033793
[5,] 2.0525048 2.0474286 2.149346 1.9770004
[6,] 1.9980944 2.0378107 2.125288 1.9931140
[7,] 1.8929952 1.7946303 2.277693 1.7279229
[8,] 2.0127121 2.0161895 2.161650 2.0067587
[9,] 3.0787573 3.0711429 3.224019 2.9655005
[10,] 2.9971416 3.0567160 3.187933 2.9896710
[11,] 2.8394929 2.6919455 3.416540 2.5918843
[12,] 3.0190682 3.0242842 3.242475 3.0101380
[13,] 4.1050097 4.0948572 4.298693 3.9540007
[14,] 3.9961888 4.0756214 4.250577 3.9862280
[15,] 3.7859905 3.5892607 4.555386 3.4558457
[16,] 4.0254242 4.0323789 4.323300 4.0135174
[17,] 5.1312621 5.1185715 5.373366 4.9425009
[18,] 4.9952359 5.0945267 5.313221 4.9827850
[19,] 4.7324881 4.4865759 5.694233 4.3198072
[20,] 5.0317803 5.0404736 5.404125 5.0168967
or
apply(a,1,function(x) t(matrixFromVector(x)))
[,1] [,2] [,3] [,4]
[1,] 1.0242459 0.9999314 1.0836573 1.0005137
[2,] 2.0484917 1.9998629 2.1673146 2.0010275
[3,] 3.0727376 2.9997943 3.2509719 3.0015412
[4,] 4.0969835 3.9997257 4.3346292 4.0020550
[5,] 5.1212293 4.9996572 5.4182865 5.0025687
[6,] 1.0314108 0.9995248 1.0908017 0.9801833
[7,] 2.0628216 1.9990496 2.1816034 1.9603667
[8,] 3.0942323 2.9985744 3.2724051 2.9405500
[9,] 4.1256431 3.9980992 4.3632069 3.9207333
[10,] 5.1570539 4.9976239 5.4540086 4.9009166
[11,] 0.9697334 0.8484190 0.9120351 0.9596908
[12,] 1.9394669 1.6968380 1.8240703 1.9193816
[13,] 2.9092003 2.5452570 2.7361054 2.8790724
[14,] 3.8789338 3.3936760 3.6481405 3.8387632
[15,] 4.8486672 4.2420950 4.5601756 4.7984540
[16,] 1.0226757 1.0069771 1.0748773 0.9841864
[17,] 2.0453515 2.0139543 2.1497545 1.9683728
[18,] 3.0680272 3.0209314 3.2246318 2.9525592
[19,] 4.0907030 4.0279085 4.2995090 3.9367456
[20,] 5.1133787 5.0348857 5.3743863 4.9209319
We can loop over the rows using lapply and then do this
do.call(rbind, lapply(seq_len(nrow(a)), function(i) matrixFromVector(a[i,])))
Or we place the output in a list using apply and then do the rbind
do.call(rbind, do.call(c, apply(a, 1, function(x) list(matrixFromVector(x)))))
why not
apply(t(a), 1, matrixFromVector)
or
apply(a, 2, matrixFromVector)