일련의 서수 변수에서 누락 값 대체를 수행하고 있습니다.쥐를 사용할 때 dim (X)는 양수 길이 여야 함
내가 먼저 데이터 프레임에 읽고 몇 가지 청소 할: 그럼 얻을
# Imputation
imputation<-function(A){
B<-mice(data = A, m = 5, method = "polr", maxit = 50, seed = 500)
C<-complete(B, 'long', include=TRUE) #include=TRUE if include the original dataset with missing values
print(colnames(C))
###pool imputed data
for (i in 4:ncol(C)) {C[,i]<-as.numeric(as.character(C[,i]))}
for (j in 4:ncol(C)) {for (i in 1:159) {if (is.na(C[i,j])) {C[i,j]<-round((C[i+159,j]+C[i+159*2,j]+C[i+159*3,j]+C[i+159*4,j]+C[i+159*5,j])/5)}}}
print(nrow(C)); print(ncol(C))
}
# Quality of life
# Diet group 1 month
seb<-subset(df3, select=c(Patient.Trial.ID, Q32a:Q32j))
missinganalysis(seb)
imputation(seb)
: 함수를, 그리고
dietgp1m<-read.csv(file='1 Month data-diet.csv',header=TRUE,na.strings=c(""," ","NA","."))
for (i in 1:ncol(dietgp1m)) {dietgp1m[,i]<-as.factor(dietgp1m[,i])}
dietgp1m<-dietgp1m[!is.na(dietgp1m$Patient.Trial.ID),]
dietgp1m["count"]<-0
for (i in 1:nrow(dietgp1m)) {dietgp1m$count[i]<-0; for (j in 9:298) {if (!is.na(dietgp1m[i,j])) {dietgp1m$count[i]<-dietgp1m$count[i]+1}}}
dietgp1m<-dietgp1m[dietgp1m$count!=0,]
내가없는 값 전가하는 기능을 만들 수를 데이터 집합을 부분 집합 및 실행 오류 메시지 :
iter imp variable
1 1 Q32a
Error in apply(draws, 2, sum) : dim(X) must have a positive length
Called from: apply(draws, 2, sum)
도와주세요! 고맙습니다!