1KA_F2F/admin/survey/modules/mod_EVOLI/R/SPSS_rekodiranje.R
2020-08-14 13:36:36 +02:00

369 lines
12 KiB
R

recode.data <- podatki
# Èe imaš veè kot 3 manjkajoèe vrednosti test ni veljaven (vse spremeni v missing).
# èe so manj kot 3 manjkajoèe, potem njihove vrednosti spremeni v 2.
for (i in names(recode.data[,14:141])) {
missing <- sum(is.na(recode.data[,14:141]))
if (missing > 3) {
recode.data[,14:141] <- NA
} else if (missing > 1 & missing < 3) {recode.data[i] <- 2
}
}
# Recode variables from var00001 to var00128
for (i in 14:ncol(recode.data)) recode.data[, i] <- recode(recode.data[, i], "4 = 1 ; 2 = 3 ; 3 = 2 ; 1 = 4")
recode.data[ , c("var00016","var00032","var00048","var00064","var00080","var00096","var00112","var00128")] <-
lapply(recode.data[ ,c("var00016","var00032","var00048","var00064","var00080","var00096","var00112","var00128")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1"))
recode.data$af_raw <- recode.data$var00016 + recode.data$var00032 + recode.data$var00048 +
recode.data$var00064 + recode.data$var00080 + recode.data$var00096 + recode.data$var00112+ recode.data$var00128
for (i in 1:length(recode.data$af_raw)) {
if (recode.data$af_raw[i] <= 11 ) {recode.data$af[i] = 1
} else if (recode.data$af_raw[i] >=29) {recode.data$af[i] = -1
} else if (recode.data$af_raw[i] > 11 & recode.data$af_raw[i] < 29) {recode.data$af[i]=0}
}
#SA
recode.data[ , c("var00001","var00033","var00065","var00097")] <-
lapply(recode.data[ ,c("var00001","var00033","var00065","var00097")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$sa <- recode.data$var00001 + recode.data$var00017 +
recode.data$var00033 + recode.data$var00049 + recode.data$var00065 +
recode.data$var00081 + recode.data$var00097+ recode.data$var00113+ recode.data$af
#ES .
recode.data[ , c("var00002","var00034","var00066","var00082","var00114")] <-
lapply(recode.data[ ,c("var00002","var00034","var00066","var00082","var00114")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$es <- recode.data$var00002 + recode.data$var00018 +
recode.data$var00034 + recode.data$var00050 + recode.data$var00066 +
recode.data$var00082 + recode.data$var00098+ recode.data$var00114 + recode.data$af
# OB
recode.data[ , c("var00003","var00019","var00051","var00083","var00115")] <-
lapply(recode.data[ ,c("var00003","var00019","var00051","var00083","var00115")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$ob = recode.data$var00003 + recode.data$var00019 +
recode.data$var00035 + recode.data$var00051 + recode.data$var00067 +
recode.data$var00083 + recode.data$var00099+ recode.data$var00115 + recode.data$af
#SE .
recode.data[ , c("var00020","var00052","var00084","var00116")] <-
lapply(recode.data[ ,c("var00020","var00052","var00084","var00116")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$se = recode.data$var00004 + recode.data$var00020 +
recode.data$var00036 + recode.data$var00052 + recode.data$var00068 +
recode.data$var00084 + recode.data$var00100+ recode.data$var00116 + recode.data$af
#######
# SM .
recode.data[ , c("var00005","var00037","var00069","var00101")] <-
lapply(recode.data[ ,c("var00005","var00037","var00069","var00101")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$sm = recode.data$var00005 + recode.data$var00021 +
recode.data$var00037 + recode.data$var00053 + recode.data$var00069 +
recode.data$var00085 + recode.data$var00101 + recode.data$var00117 + recode.data$af
# IC .
recode.data[ , c("var00022","var00054","var00086","var00118")] <-
lapply(recode.data[ ,c("var00022","var00054","var00086","var00118")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$ic = recode.data$var00006 + recode.data$var00022 +
recode.data$var00038 + recode.data$var00054 + recode.data$var00070 +
recode.data$var00086 + recode.data$var00102 + recode.data$var00118 + recode.data$af
# SR .
recode.data[ , c("var00007","var00039","var00071","var00103")] <-
lapply(recode.data[ ,c("var00007","var00039","var00071","var00103")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$sr = recode.data$var00007 + recode.data$var00023 +
recode.data$var00039 + recode.data$var00055 + recode.data$var00071 +
recode.data$var00087 + recode.data$var00103 + recode.data$var00119 + recode.data$af
# AD
recode.data[ , c("var00024","var00056","var00088","var00120")] <-
lapply(recode.data[ ,c("var00024","var00056","var00088","var00120")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$ad = recode.data$var00008 + recode.data$var00024 + recode.data$var00040 +
recode.data$var00056 + recode.data$var00072 + recode.data$var00088 +
recode.data$var00104 + recode.data$var00120 + recode.data$af
#PS .
recode.data[ , c("var00009","var00041","var00073","var00105","var00121")] <-
lapply(recode.data[ ,c("var00009","var00041","var00073","var00105","var00121")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$ps = recode.data$var00009 + recode.data$var00025 + recode.data$var00041 +
recode.data$var00057 + recode.data$var00073 + recode.data$var00089 +
recode.data$var00105 + recode.data$var00121 + recode.data$af
#####################
# OP
recode.data[ , c("var00010","var00042","var00058","var00090","var00122")] <-
lapply(recode.data[ ,c("var00010","var00042","var00058","var00090","var00122")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$op = recode.data$var00010 + recode.data$var00026 + recode.data$var00042 +
recode.data$var00058 + recode.data$var00074 + recode.data$var00090 +
recode.data$var00106 + recode.data$var00122 + recode.data$af
# AC .
recode.data[ , c("var00027","var00059","var00091","var00123")] <-
lapply(recode.data[ ,c("var00027","var00059","var00091","var00123")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$ac = recode.data$var00011 + recode.data$var00027 + recode.data$var00043 +
recode.data$var00059 + recode.data$var00075 + recode.data$var00091 +
recode.data$var00107 + recode.data$var00123 + recode.data$af
# CO .
recode.data[ , c("var00012","var00028","var00060","var00076","var00108","var00124")] <-
lapply(recode.data[ ,c("var00012","var00028","var00060","var00076","var00108","var00124")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$co = recode.data$var00012 + recode.data$var00028 + recode.data$var00044 +
recode.data$var00060 + recode.data$var00076 + recode.data$var00092 +
recode.data$var00108 + recode.data$var00124 + recode.data$af
###########################################
# EM .
recode.data[ , c("var00013","var00045","var00077","var00093","var00125")] <-
lapply(recode.data[ ,c("var00013","var00045","var00077","var00093","var00125")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$em = recode.data$var00013 + recode.data$var00029 + recode.data$var00045 +
recode.data$var00061 + recode.data$var00077 + recode.data$var00093 +
recode.data$var00109 + recode.data$var00125 + recode.data$af
#########################
# IR .
recode.data[ , c("var00030","var00062","var00094","var00126")] <-
lapply(recode.data[ ,c("var00030","var00062","var00094","var00126")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$ir = recode.data$var00014 + recode.data$var00030 + recode.data$var00046 +
recode.data$var00062 + recode.data$var00078 + recode.data$var00094 +
recode.data$var00110 + recode.data$var00126 + recode.data$af
# GO .
recode.data[ , c("var00015","var00031","var00063","var00079","var00111","var00127")] <-
lapply(recode.data[ ,c("var00015","var00031","var00063","var00079","var00111","var00127")] ,
FUN = function(x) recode(x, "1=4;2=3;3=2;4=1;else=NA"))
recode.data$go = recode.data$var00015 + recode.data$var00031 + recode.data$var00047 +
recode.data$var00063 + recode.data$var00079 + recode.data$var00095 +
recode.data$var00111 + recode.data$var00127 + recode.data$af
###########################################
recode.data$saw = round(((recode.data$sa + recode.data$es + recode.data$ob + recode.data$se)/4),0)
recode.data$sma = round(((recode.data$sm +recode.data$ic + recode.data$sr + recode.data$ad + recode.data$ps)/5 ),0)
recode.data$smo = round(((recode.data$op +recode.data$ac + recode.data$co)/3),0)
recode.data$soa = round(recode.data$em,0)
recode.data$ssk = round(((recode.data$ir + recode.data$go)/2),0)
# Total EQ-scoring .
###############
recode.data$totaleq = recode.data$sa + recode.data$es + recode.data$ob + recode.data$se +
recode.data$sm + recode.data$ic + recode.data$sr + recode.data$ad + recode.data$ps +
recode.data$op + recode.data$ac + recode.data$co + recode.data$em + recode.data$ir + recode.data$go
# Skupni dosežek.
#### SINTAKSA 2: PEQM Recode #####
#SAR
recode.data[ c("sar")] <-
lapply(recode.data[ c("sa")] ,
FUN = function(x) recode(x, "lo:21=1;22:23=2;24=3;25=5;26=6;27=7;28=8;29:30=9;31:hi=10"))
# ESR
recode.data[ c("esr")] <-
lapply(recode.data[ c("es")] ,
FUN = function(x) recode(x, "lo:21=1;22=2;23=3;24=4;25=5;26=6;27=7;28=8;29:30=9;31:hi=10"))
# OBR
recode.data[ c("obr")] <-
lapply(recode.data[ c("ob")] ,
FUN = function(x) recode(x, "lo:20=1;21=2;22=3;23=4;24=5;25=6;26=7;27=8;28=9;29:hi=10"))
# SER
recode.data[ c("ser")] <-
lapply(recode.data[ c("se")] ,
FUN = function(x) recode(x, "lo:20=1;21=2;22=3;23=4;24=5;25=6;26=7;27=8;28=9;29:hi=10"))
# SMR
recode.data[ c("smr")] <-
lapply(recode.data[ c("sm")] ,
FUN = function(x) recode(x, "lo:19=1;20=2;21=3;22=4;23=5;24=6;25=7;26=8;27=9;28:hi=10"))
# ICR
recode.data[ c("icr")] <-
lapply(recode.data[ c("ic")] ,
FUN = function(x) recode(x, "lo:19=1;20:21=2;22=3;23=4;24=5;25=6;26=7;27=8;28=9;29:hi=10"))
# SRR
recode.data[ c("srr")] <-
lapply(recode.data[ c("sr")] ,
FUN = function(x) recode(x, "lo:21=1;22=2;23=3;24=4;25=5;26=6;27=7;28=8;29=9;30:hi=10"))
# ADR
recode.data[ c("adr")] <-
lapply(recode.data[ c("ad")] ,
FUN = function(x) recode(x, "lo:22=1;23=2;24=3;25=4;26=5;27=6;28=7;29=8;30=9;31:hi=10"))
# PSR
recode.data[ c("psr")] <-
lapply(recode.data[ c("ps")] ,
FUN = function(x) recode(x, "lo:21=1;22=2;23=3;24=4;25=5;26=6;27=7;28=8;29=9;30:hi=10"))
# OPR
recode.data[ c("opr")] <-
lapply(recode.data[ c("op")] ,
FUN = function(x) recode(x, "lo:21=1;22:23=2;24=3;25=4;26=5;27=6;28=7;29=8;30=9;31:hi=10"))
# ACR
recode.data[ c("acr")] <-
lapply(recode.data[ c("ac")] ,
FUN = function(x) recode(x, "lo:21=1;22=2;23=3;24=4;25=5;26=6;27=7;28=8;29=9;30:hi=10"))
# COR
recode.data[ c("cor")] <-
lapply(recode.data[ c("co")] ,
FUN = function(x) recode(x, "lo:22=1;23:24=2;25=3;26=4;27=5;28=6;29=7;30=8;31=9;32:hi=10"))
# EMR
recode.data[ c("emr")] <-
lapply(recode.data[ c("em")] ,
FUN = function(x) recode(x, "lo:21=1;22=2;23=3;24=4;25=5;26=6;27=7;28=8;29=9;30:hi=10"))
# IRR
recode.data[ c("irr")] <-
lapply(recode.data[ c("ir")] ,
FUN = function(x) recode(x, "lo:21=1;22=2;23=3;24=4;25=5;26=6;27=7;28=8;29=9;30:hi=10"))
# GOR
recode.data[ c("gor")] <-
lapply(recode.data[ c("go")] ,
FUN = function(x) recode(x, "lo:23=1;24=2;25=3;26=4;27=5;28=6;29=7;30=8;31=9;32:hi=10"))
# SAW
recode.data[ c("saw")] <-
lapply(recode.data[ c("saw")] ,
FUN = function(x) recode(x, "lo:20=1;21=2;22=3;23=4;24=5;25=6;26=7;27=8;28=9;29:hi=10"))
# SMA
recode.data[ c("sma")] <-
lapply(recode.data[ c("sma")] ,
FUN = function(x) recode(x, "lo:20=1;21=2;22=3;23=4;24=5;25=6;26=7;27=8;28=9;29:hi=10"))
# SMO
recode.data[ c("smo")] <-
lapply(recode.data[ c("smo")] ,
FUN = function(x) recode(x, "lo:21=1;22=2;23=3;24=4;25=5;26=6;27=7;28=8;29=9;30:hi=10"))
# SOA
recode.data[ c("soa")] <-
lapply(recode.data[ c("soa")] ,
FUN = function(x) recode(x, "lo:21=1;22=2;23=3;24=4;25=5;26=6;27=7;28=8;29=9;30:hi=10"))
# SSK
recode.data[ c("ssk")] <-
lapply(recode.data[ c("ssk")] ,
FUN = function(x) recode(x, "lo:22=1;23=2;24=3;25=4;26=5;27=6;28=7;29=8;30=9;31:hi=10"))
recode.data$totaleq = (((recode.data$totaleq - 381.36) / 36.46) * 20) + 100
recode.data$totaleq <- round(recode.data$totaleq, 0)
podatki <- recode.data