-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb24136
commit 730bf2e
Showing
8 changed files
with
67 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
Package: gendata | ||
Type: Package | ||
Title: Generate and modify synthetic datasets | ||
Version: 1.0 | ||
Date: 2014-05-07 | ||
Title: Generate and Modify Synthetic Datasets | ||
Version: 1.1 | ||
Date: 2015-02-27 | ||
Author: Francis Huang <flh3@hotmail.com> | ||
Maintainer: Francis Huang <flh3@hotmail.com> | ||
Description: Set of functions to create datasets using a correlation matrix. | ||
License: GPL-3 | ||
Suggests: psych | ||
Packaged: 2014-05-08 11:52:56 UTC; huangf | ||
Packaged: 2015-03-01 00:27:32 UTC; huangf | ||
NeedsCompilation: no | ||
Repository: CRAN | ||
Date/Publication: 2014-05-08 15:00:04 | ||
Date/Publication: 2015-03-01 08:20:17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
7195afc887c32881466e57af6b4ed44d *DESCRIPTION | ||
d24062a9da5bf317849a4f9f55c7425b *DESCRIPTION | ||
df390c53434517b304ac5db487184641 *NAMESPACE | ||
342f1ce5c35aeb3cf31f40751e358665 *R/dtrans.R | ||
f4f8cedfa2020bf348b967e67aba1b87 *R/genmvnorm.R | ||
095100e3b3da1f45b3598b24015efb31 *R/genmvnorm.R | ||
01ef3ab6e2a122c3c91d6870bc17a2e6 *R/recalib.R | ||
4cbd5ff37108a8c4cd99a19946511f89 *R/revcode.R | ||
67874b9ff91c1fd314102a5dc00cf566 *man/dtrans.Rd | ||
7ad81a8b5b71270c0033a82d41998a13 *man/gendata-package.Rd | ||
63f2bee019b17a527c52d9a5d84d6862 *man/genmvnorm.Rd | ||
0e7981599f1f44e390fb28f645fde363 *man/recalib.Rd | ||
72fe602011db9615eb043cb9a50193b6 *man/revcode.Rd | ||
ee03b3f57121283e65077055b925d2e7 *man/dtrans.Rd | ||
fba3faa2ba40f50b4a7edaa14e4320ff *man/gendata-package.Rd | ||
2e045b7357aa5e2ed17cb27a065962a0 *man/genmvnorm.Rd | ||
c1b548f7156dc9fcc7e51e5d55100240 *man/recalib.Rd | ||
a0f1851ab48c58d59a1ec40b87589faa *man/revcode.Rd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,50 @@ | ||
|
||
#################### | ||
genmvnorm<-function(cor,k,n,seed=F){ | ||
if(require("psych")!=T){ | ||
print("installing 'psych' package") | ||
install.packages("psych") | ||
require(psych)} | ||
if(seed != F){set.seed(seed)} | ||
if(is.matrix(cor)==F){ | ||
x<-length(cor) | ||
if(x != (k*(k-1)/2) ){stop("STOP: wrong correlation table")} | ||
cr.cor<-matrix(NA,k,k) | ||
diag(cr.cor)<-1 | ||
cr.cor[lower.tri(cr.cor)]<-cor | ||
cr.cor[upper.tri(cr.cor)]<-t(cr.cor)[upper.tri(cr.cor)] | ||
fit<-principal(cr.cor,rotate=F,nfactors=k)} | ||
|
||
if(is.matrix(cor)==T){ #if a correlation matrix was used | ||
fit<-principal(cor,rotate=F,nfactors=k) | ||
} | ||
|
||
l<-fit$loadings[1:k,1:k] | ||
f<-matrix(nrow=k,l) | ||
dim(f) | ||
ma<-matrix(nrow=n,ncol=k) | ||
for (i in 1:k){ | ||
ma[,i]<-rnorm(n) | ||
|
||
|
||
if(is.matrix(cor)==F){ | ||
x<-length(cor) | ||
if(x != (k*(k-1)/2) ){stop("STOP: wrong correlation table")} | ||
|
||
cr.cor<-matrix(NA,k,k) | ||
diag(cr.cor)<-1 | ||
cr.cor[lower.tri(cr.cor)]<-cor | ||
cr.cor[upper.tri(cr.cor)]<-t(cr.cor)[upper.tri(cr.cor)] | ||
|
||
e<-eigen(cr.cor) | ||
L<-e$values #placing the eigenvalues in V | ||
Vm<-matrix(0,nrow=k,ncol=k) #creating a k x k matrix. | ||
diag(Vm)<-L #putting the eigenvalues on the diagonals | ||
Vm #check-- matrix with eigenvalues | ||
e$vectors #these are the eigenvectors | ||
l<-e$vectors %*% sqrt(Vm) #these are the loadings | ||
} | ||
|
||
if(is.matrix(cor)==T){ #if a correlation matrix was used | ||
|
||
e<-eigen(cor) | ||
L<-e$values #placing the eigenvalues in V | ||
Vm<-matrix(0,nrow=k,ncol=k) #creating a k x k matrix. | ||
diag(Vm)<-L #putting the eigenvalues on the diagonals | ||
Vm #check-- matrix with eigenvalues | ||
e$vectors #these are the eigenvectors | ||
l<-e$vectors %*% sqrt(Vm) #these are the loadings | ||
|
||
} | ||
|
||
if(seed != F){set.seed(seed)} | ||
f<-matrix(nrow=k,l) | ||
#dim(f) | ||
ma<-matrix(nrow=n,ncol=k) | ||
for (i in 1:k){ | ||
ma[,i]<-rnorm(n) | ||
} | ||
tma<-t(ma) | ||
sol<-f %*% tma | ||
sol<-t(sol) | ||
|
||
data<-data.frame(sol) | ||
return(data) | ||
|
||
} | ||
tma<-t(ma) | ||
sol<-f %*% tma | ||
sol<-t(sol) | ||
|
||
data<-data.frame(sol) | ||
return(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters