This repository was archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregression.R
More file actions
76 lines (60 loc) · 2.11 KB
/
regression.R
File metadata and controls
76 lines (60 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/Rscript --slave
#####
# how to use
#####
usage <- "usage: Rscript regression.R <file-with-input-data.csv>"
### handle command line arguments (i.e. name of data file)
args <- commandArgs(TRUE)
inputfile <- args[1]
options(OutDec= ",")
data <- read.csv2("regressiondata.csv", header=TRUE, na="NA", check.names=FALSE)
# give names of headers
headers <- names(data)
# read dates as date
#data$birthyear <- as.Date(data$birthyear,format = "%m.%d.%Y")
# attach datafile so we can refer to variable names directly
# don't forget to use detach at the end
attach(data)
summary <- summary(data)
crosscorrelation <- cor(data[c(2,3,4,5,6,7,8)], use="complete", method="spearman")
paircorr_exfreq_het_MLD <- cor(data[c(2,6)], use="pairwise", method="spearman")
paircorr_exfreq_het_PK <- cor(data[c(2,7)], use="pairwise", method="spearman")
paircorr_exfreq_het_LAV2 <- cor(data[c(2,8)], use="pairwise", method="spearman")
# pairs(data) # pairwise graphics
model0 = lm(ExFreq ~ LAV2 + PI10 + PAA_Ratio + het_MLD + het_PK + het_LAV2, data=data)
summary(model0)
anova(model0)
ci <- confint(model0, level=0.95) # CIs for model parameters
ci
par(mfrow=c(2,2))
plot(model0)
# Plot shows 1 extreme outlier (No 40), see what happens when we delete that
data2 <- subset(data, PID != 40)
summary <- summary(data2)
crosscorr2 <- cor(data2[c(2,3,4,5,6,7,8)], use="complete", method="spearman")
paircorr2_exfreq_het_MLD <- cor(data2[c(2,6)], use="pairwise", method="spearman")
paircorr2_exfreq_het_PK <- cor(data2[c(2,7)], use="pairwise", method="spearman")
paircorr2_exfreq_het_LAV2 <- cor(data2[c(2,8)], use="pairwise", method="spearman")
model1 = lm(ExFreq ~ LAV2 + PI10 + PAA_Ratio + het_MLD + het_PK + het_LAV2, data=data2)
summary(model1)
anova(model1)
par(mfrow=c(2,2))
plot(model1)
model2 = update(model1, .~.-het_MLD)
summary(model2)
md1 <- anova(model1, model2)
md1
model3 = update(model2, .~.-het_LAV2)
summary(model3)
md2 <- anova(model2, model3)
md2
model4 = update(model3, .~.-PI10)
summary(model4)
md3 <- anova(model3, model4)
md3
model5 = update(model4, .~.-PAA_Ratio)
summary(model5)
md4 <- anova(model4, model5)
md4
### clean up
detach(data)