How to print and save simulated data?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to print and save simulated data?

wanfairos
This post has NOT been accepted by the mailing list yet.
Dear members;

I have one problem to display my simulated data. Basically, I've generated a set of rnorm (std.norm.mat)and rnbinom (gen.data) data to test on the performance of FE Poisson model estimates using a panel data. These sets of data generated were simulated for 10 times. My problem is I cannot print out the list of data generated for all 10 simulated sets of data. When I try to print all data I got 10 Warning messages:1:ie: In my.data[i] <- gen.data : number of items to replace is not a multiple of replacement length.

Really appreciate if anybody could help me a.s.a.p. Thank you in advance.

## -----------------------------------------------------
##Setting Parameter Value
## -----------------------------------------------------

num.i <- 5
num.t <- 2

eta.param <- 4
beta.param <- 1.5
gamma.param <- 1
lambda.param <- 1
rho.param <- 0.0

ind.int <- as.factor(rep(1:num.i,rep(num.t,num.i)))
cov.mat <- matrix(c(1,rho.param^2,rho.param,rho.param^2,1,rho.param,
rho.param,rho.param,1),ncol=3,byrow=T)

svd.decomp <- svd(cov.mat)
sqrt.decomp <- svd.decomp$u %*% diag(sqrt(svd.decomp$d))

sim.size <- 10
my.results <- rep(9999,sim.size)
my.data<-rep(9999,sim.size)
## -----------------------------------------------------
##Generate data
## -----------------------------------------------------

for(i in 1: sim.size){

std.norm.mat <- matrix(rnorm(15),ncol=3)
norm.mat <- std.norm.mat %*% t(sqrt.decomp)
mean.mat <- eta.param * exp(norm.mat %*%      
matrix(c(beta.param,0,0,beta.param,gamma.param,gamma.param), ncol=2,byrow=T))

##-----------------------------------------------------
## Reparameterise for the negative binomial
## ----------------------------------------------------
r.param <- lambda.param
p.param <- lambda.param/(lambda.param + mean.mat)

gen.data <- matrix(rnbinom(num.i * num.t, r.param,p.param),ncol=2)

##----------------------------------------------------
## Fiting a poisson regression
##----------------------------------------------------

model.results <- glm(c(t(gen.data)) ~ -1 + ind.int + c(t(norm.mat[,1:2])), family="poisson")
my.results[i] <- model.results$coefficients[101]
my.data[i]<-gen.data
}

Warning messages:
1: In my.data[i] <- gen.data :
  number of items to replace is not a multiple of replacement length
2: In my.data[i] <- gen.data :
  number of items to replace is not a multiple of replacement length
3: In my.data[i] <- gen.data :
  number of items to replace is not a multiple of replacement length
4: In my.data[i] <- gen.data :
  number of items to replace is not a multiple of replacement length
5: In my.data[i] <- gen.data :
  number of items to replace is not a multiple of replacement length
6: In my.data[i] <- gen.data :
  number of items to replace is not a multiple of replacement length
7: In my.data[i] <- gen.data :
  number of items to replace is not a multiple of replacement length
8: In my.data[i] <- gen.data :
  number of items to replace is not a multiple of replacement length
9: In my.data[i] <- gen.data :
  number of items to replace is not a multiple of replacement length
10: In my.data[i] <- gen.data :
  number of items to replace is not a multiple of replacement length
Reply | Threaded
Open this post in threaded view
|

Re: How to print and save simulated data?

Dieter Menne
wanfairos wrote
Dear members;

I have one problem to display my simulated data. Basically, I've generated a set of rnorm (std.norm.mat)and rnbinom (gen.data) data to test on the performance of FE Poisson model estimates

... Long self-contained example shorted

my.data<-rep(9999,sim.size)

for(i in 1: sim.size){
...
gen.data <- matrix(rnbinom(num.i * num.t, r.param,p.param),ncol=2)

my.data[i]<-gen.data
}
gen.data is a matrix with to columns, my.data a vector. You should assign the results to a list or do some sort of cbind, depending on what you need.

Dieter


Reply | Threaded
Open this post in threaded view
|

Re: How to print and save simulated data?

Dieter Menne
In reply to this post by wanfairos
wanfairos wrote
Dear members;

I have one problem to display my simulated data. Basically, I've generated a set of rnorm (std.norm.mat)and rnbinom (gen.data) data to test on the performance of FE Poisson model estimates

... Long self-contained example shorted

my.data<-rep(9999,sim.size)

for(i in 1: sim.size){
...
gen.data <- matrix(rnbinom(num.i * num.t, r.param,p.param),ncol=2)

my.data[i]<-gen.data
}
gen.data is a matrix with to columns, my.data a vector. You should assign the results to a list or do some sort of cbind, depending on what you need.

Dieter


Reply | Threaded
Open this post in threaded view
|

Re: How to print and save simulated data?

Dieter Menne
In reply to this post by wanfairos
wanfairos wrote
I have one problem to display my simulated data. Basically, I've generated a set of rnorm (std.norm.mat)and rnbinom (gen.data) data to test on the performance of FE Poisson model estimates

... Long self-contained example shorted

my.data<-rep(9999,sim.size)

for(i in 1: sim.size){
...
gen.data <- matrix(rnbinom(num.i * num.t, r.param,p.param),ncol=2)

my.data[i]<-gen.data
}
gen.data is a matrix with to columns, my.data a vector. You should assign the results to a list or do some sort of cbind, depending on what you need.

Dieter


Reply | Threaded
Open this post in threaded view
|

Re: How to print and save simulated data?

Dieter Menne
In reply to this post by wanfairos
wanfairos wrote
I have one problem to display my simulated data. Basically, I've generated a set of rnorm (std.norm.mat)and rnbinom (gen.data) data to test on the performance of FE Poisson model estimates

... Long self-contained example shorted

my.data<-rep(9999,sim.size)

for(i in 1: sim.size){
...
gen.data <- matrix(rnbinom(num.i * num.t, r.param,p.param),ncol=2)

my.data[i]<-gen.data
}
gen.data is a matrix with to columns, my.data a vector. You should assign the results to a list or do some sort of cbind, depending on what you need.

Dieter