Ich habe alle Variablen in einer Matrix kombiniert und möchte Zeile für Zeile eine Simulation durchführen. Aber ich fand heraus, der Code funktioniert nur für neun Proben und nicht alle von ihnen (45). Ich habe versucht, die Schleife iteriert aber wegen dieser zwei Linien, so Problem auftritt.R [Gamma-Verteilungsskala-Parameter und t-Test]
#minus the population mean to ensure the true of null hypo
gamma1<-gamma1-16/9*all_combine1[ss,4]
gamma2<-gamma2-16/9
kann jemand pls help .... bitte
#For gamma disribution with equal skewness 1.5
#to evaluate the same R function on many different sets of data
library(parallel)
nSims<-100 #number of simulation
alpha<-0.05 #significance level
#set nrow =nsims because wan storing every p-value simulated
matrix3_equal <-matrix(0,nrow=nSims,ncol=3)
matrix4_unequal<-matrix(0,nrow=nSims,ncol=3)
matrix5_mann <-matrix(0,nrow=nSims,ncol=3)
#set empty vector of length to store p-value
equal3<-c(rep(0,nrow(all_combine1)))
unequal4<-c(rep(0,nrow(all_combine1)))
mann5<-c(rep(0,nrow(all_combine1)))
#for gamma distribution with equal skewness
# to ensure the reproducity of the result
#here we declare the random seed generator
set.seed(1)
## Put the samples sizes into matrix then use a loop for sample sizes
sample_sizes<-matrix(c(10,10,10,25,25,25,25,50,25,100,50,25,50,100,100,25,100,100),
nrow=2)
#shape parameter for both gamma distribution for equal skewness
shp<-rep(16/9,each=45)
#scale parameter for sample 1
#scale paramter for sample 2 set as constant 1
scp1<-c(1,1.5,2,2.5,3)
scp1<-rep(scp1,9)
#create a matrix combining the forty five cases of combination of sample sizes,shape and scale parameter
all_combine1 <- cbind(rep(sample_sizes[1,], 5),rep(sample_sizes[2,],5),shp,scp1)
# name the column samples 1 and 2 and standard deviation
colnames(all_combine1) <- c("m", "n","sp(skewness1.5)","scp1")
##for the samples sizes into matrix then use a loop for sample sizes
# this loop steps through the all_combine matrix
for(ss in 1:nrow(all_combine1))
{
#generate samples from the first column and second column
m<-all_combine1[ss,1]
n<-all_combine1[ss,2]
for (sim in 1:nSims)
{
#generate 2 random samples from gamma distribution with equal skewness
gamma1<-rgamma(m,16/9,all_combine1[ss,4])
gamma2<-rgamma(n,16/9,1)
#minus the population mean to ensure the true of null hypo
gamma1<-gamma1-16/9*all_combine1[ss,4]
gamma2<-gamma2-16/9
#extract p-value out and store every p-value into matrix
matrix3_equal[sim,1]<-t.test(gamma1,gamma2,var.equal=TRUE)$p.value
matrix4_unequal[sim,2]<-t.test(gamma1,gamma2,var.equal=FALSE)$p.value
matrix5_mann[sim,3] <-wilcox.test(gamma1,gamma2)$p.value
}
##store the result
equal3[ss]<- sum(matrix3_equal[,1]<=alpha)
unequal4[ss]<-sum(matrix4_unequal[,2]<=alpha)
mann5[ss]<- sum(matrix5_mann[,3]<=alpha)
}
Das ist mein result.Clearly es laufen nicht erfolgreich für jeden loop.TT
m n sp(skewness1.5) scp1 equal3 unequal4 mann5
[1,] 10 10 1.777778 1.0 9 9 6
[2,] 10 25 1.777778 1.5 94 93 95
[3,] 25 25 1.777778 2.0 100 100 100
[4,] 25 50 1.777778 2.5 100 100 100
[5,] 25 100 1.777778 3.0 100 100 100
[6,] 50 25 1.777778 1.0 3 8 6
[7,] 50 100 1.777778 1.5 100 100 100
[8,] 100 25 1.777778 2.0 100 100 100
[9,] 100 100 1.777778 2.5 100 100 100
[10,] 10 10 1.777778 3.0 100 100 100
[11,] 10 25 1.777778 1.0 3 4 6
[12,] 25 25 1.777778 1.5 99 99 100
[13,] 25 50 1.777778 2.0 100 100 100
[14,] 25 100 1.777778 2.5 100 100 100
[15,] 50 25 1.777778 3.0 100 100 100
[16,] 50 100 1.777778 1.0 3 4 1
[17,] 100 25 1.777778 1.5 100 100 100
[18,] 100 100 1.777778 2.0 100 100 100
[19,] 10 10 1.777778 2.5 100 100 100
[20,] 10 25 1.777778 3.0 100 100 100
[21,] 25 25 1.777778 1.0 4 3 5
[22,] 25 50 1.777778 1.5 100 99 100
[23,] 25 100 1.777778 2.0 100 100 100
[24,] 50 25 1.777778 2.5 100 100 100
[25,] 50 100 1.777778 3.0 100 100 100
[26,] 100 25 1.777778 1.0 8 9 10
[27,] 100 100 1.777778 1.5 100 100 100
[28,] 10 10 1.777778 2.0 100 100 100
[29,] 10 25 1.777778 2.5 100 100 100
[30,] 25 25 1.777778 3.0 100 100 100
[31,] 25 50 1.777778 1.0 2 3 2
[32,] 25 100 1.777778 1.5 100 100 100
[33,] 50 25 1.777778 2.0 100 100 100
[34,] 50 100 1.777778 2.5 100 100 100
[35,] 100 25 1.777778 3.0 100 100 100
[36,] 100 100 1.777778 1.0 7 7 5
[37,] 10 10 1.777778 1.5 88 87 90
[38,] 10 25 1.777778 2.0 100 100 100
[39,] 25 25 1.777778 2.5 100 100 100
[40,] 25 50 1.777778 3.0 100 100 100
[41,] 25 100 1.777778 1.0 7 7 6
[42,] 50 25 1.777778 1.5 100 100 100
[43,] 50 100 1.777778 2.0 100 100 100
[44,] 100 25 1.777778 2.5 100 100 100
[45,] 100 100 1.777778 3.0 100 100 100
Habe gerade bemerkt, dass nur der Skalierungsparameter 1 läuft !!! Versuchen herauszufinden, warum –