Erforderliche Pakete laden

library(ppcor)  # Partial- und Semipartialkorrelation

Der Beispiel-Datensatz kann hier heruntergeladen und dann mit der Funktion read.table(file=file.choose(), header=TRUE) in R geladen werden oder mittels untenstehenden Funktion direkt vom Server in R eingelesen werden.

Datensatz einlesen und Variablen spezifizieren

# Datensatz Partial.txt einlesen
data <- read.table(file="https://mmi.psycho.unibas.ch/r-toolbox/data/Partial.txt", header=TRUE)
head(data) # zeigt die ersten 6 Zeilen des Datensatzes
##   CASE TIME PUBS CITS SALARY FEMALE
## 1    1    3   18   50  51876      1
## 2    2    6    3   26  54511      1
## 3    3    3    2   50  53425      1
## 4    4    8   17   34  61863      0
## 5    5    9   11   41  52926      1
## 6    6    6    6   37  47034      0
# Variablen spezifizieren
X <- "CITS"
Y <- "SALARY"
Z <- c("TIME", "PUBS") # zu kontrollierende Variablen

Signifikanztest

# Signifikanztest
data2 <- na.omit(data[,c(X, Y, Z)])
p.cor <- pcor.test(x=data2[,X], y=data2[,Y], z=data2[,Z])
sp.cor <- spcor.test(x=data2[,X], y=data2[,Y], z=data2[,Z])
list(Patrialkorrelation=p.cor, Semipartialkorrelation=sp.cor)
## $Patrialkorrelation
##    estimate      p.value statistic  n gp  Method
## 1 0.4255911 0.0006989033  3.581776 62  2 pearson
## 
## $Semipartialkorrelation
##    estimate     p.value statistic  n gp  Method
## 1 0.3916012 0.001974037  3.241205 62  2 pearson