User Tools

Site Tools


r:multiple_regression

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
r:multiple_regression [2019/11/08 10:59] – [Prediction] hkimscilr:multiple_regression [2020/08/31 12:31] hkimscil
Line 534: Line 534:
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 > </code> > </code>
 +====== e.g. 5 ======
 +<code>
 +#packages we will need to conduct to create and graph our data
 +library(MASS) #create data
 +library(car) #graph data
 +py1 =.6 #Cor between X1 (Practice Time) and Memory Errors
 +py2 =.4 #Cor between X2 (Performance Anxiety) and Memory Errors
 +p12= .3 #Cor between X1 (Practice Time) and X2 (Performance Anxiety)
 +Means.X1X2Y<- c(10,10,10) #set the means of X and Y variables
 +CovMatrix.X1X2Y <- matrix(c(1,p12,py1,
 +                            p12,1,py2,
 +                            py1,py2,1),3,3) # creates the covariate matrix 
 +#build the correlated variables. Note: empirical=TRUE means make the correlation EXACTLY r. 
 +# if we say empirical=FALSE, the correlation would be normally distributed around r
 +set.seed(42)
 +CorrDataT<-mvrnorm(n=100, mu=Means.X1X2Y,Sigma=CovMatrix.X1X2Y, empirical=TRUE)
 +#Convert them to a "Data.Frame" & add our labels to the vectors we created
 +CorrDataT<-as.data.frame(CorrDataT)
 +colnames(CorrDataT) <- c("Practice","Anxiety","Memory")
 +#make the scatter plots
 +scatterplot(Memory~Practice,CorrDataT, smoother=FALSE)
 +scatterplot(Memory~Anxiety,CorrDataT, smoother=FALSE)
 +scatterplot(Anxiety~Practice,CorrDataT, smoother=FALSE)
 +# Pearson Correlations
 +ry1<-cor(CorrDataT$Memory,CorrDataT$Practice)
 +ry2<-cor(CorrDataT$Memory,CorrDataT$Anxiety)
 +r12<-cor(CorrDataT$Anxiety,CorrDataT$Practice)
 +</code>
 +
  
r/multiple_regression.txt · Last modified: 2023/10/19 08:23 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki