Академический Документы
Профессиональный Документы
Культура Документы
> read.csv("binary.csv")
admit gre gpa rank
1 0 380 3.61 3
2 1 660 3.67 3
3 1 800 4.00 1
4 1 640 3.19 4
5 0 520 2.93 4
6 1 760 3.00 2
7 1 560 2.98 1
8 0 400 3.08 2
9 1 540 3.39 3
10 0 700 3.92 2
11 0 800 4.00 4
12 0 440 3.22 1
13 1 760 4.00 1
14 0 700 3.08 2
15 1 700 4.00 1
16 0 480 3.44 3
17 0 780 3.87 4
18 0 360 2.56 3
19 0 800 3.75 2
20 1 540 3.81 1
21 0 500 3.17 3
22 1 660 3.63 2
23 0 600 2.82 4
24 0 680 3.19 4
25 1 760 3.35 2
26 1 800 3.66 1
27 1 620 3.61 1
28 1 520 3.74 4
29 1 780 3.22 2
30 0 520 3.29 1
31 0 540 3.78 4
32 0 760 3.35 3
33 0 600 3.40 3
34 1 800 4.00 3
35 0 360 3.14 1
36 0 400 3.05 2
37 0 580 3.25 1
38 0 520 2.90 3
39 1 500 3.13 2
40 1 520 2.68 3
41 0 560 2.42 2
42 1 580 3.32 2
43 1 600 3.15 2
44 0 500 3.31 3
45 0 700 2.94 2
46 1 460 3.45 3
47 1 580 3.46 2
48 0 500 2.97 4
49 0 440 2.48 4
50 0 400 3.35 3
51 0 640 3.86 3
52 0 440 3.13 4
53 0 740 3.37 4
54 1 680 3.27 2
55 0 660 3.34 3
56 1 740 4.00 3
57 0 560 3.19 3
58 0 380 2.94 3
59 0 400 3.65 2
60 0 600 2.82 4
61 1 620 3.18 2
62 0 560 3.32 4
63 0 640 3.67 3
64 1 680 3.85 3
65 0 580 4.00 3
66 0 600 3.59 2
67 0 740 3.62 4
68 0 620 3.30 1
69 0 580 3.69 1
70 0 800 3.73 1
71 0 640 4.00 3
72 0 300 2.92 4
73 0 480 3.39 4
74 0 580 4.00 2
75 0 720 3.45 4
76 0 720 4.00 3
77 0 560 3.36 3
78 1 800 4.00 3
79 0 540 3.12 1
80 1 620 4.00 1
81 0 700 2.90 4
82 0 620 3.07 2
83 0 500 2.71 2
84 0 380 2.91 4
85 1 500 3.60 3
86 0 520 2.98 2
87 0 600 3.32 2
88 0 600 3.48 2
89 0 700 3.28 1
90 1 660 4.00 2
91 0 700 3.83 2
92 1 720 3.64 1
93 0 800 3.90 2
94 0 580 2.93 2
95 1 660 3.44 2
96 0 660 3.33 2
97 0 640 3.52 4
98 0 480 3.57 2
99 0 700 2.88 2
100 0 400 3.31 3
101 0 340 3.15 3
102 0 580 3.57 3
103 0 380 3.33 4
104 0 540 3.94 3
105 1 660 3.95 2
106 1 740 2.97 2
107 1 700 3.56 1
108 0 480 3.13 2
109 0 400 2.93 3
110 0 480 3.45 2
111 0 680 3.08 4
112 0 420 3.41 4
113 0 360 3.00 3
114 0 600 3.22 1
115 0 720 3.84 3
116 0 620 3.99 3
117 1 440 3.45 2
118 0 700 3.72 2
119 1 800 3.70 1
120 0 340 2.92 3
121 1 520 3.74 2
122 1 480 2.67 2
123 0 520 2.85 3
124 0 500 2.98 3
125 0 720 3.88 3
126 0 540 3.38 4
127 1 600 3.54 1
128 0 740 3.74 4
129 0 540 3.19 2
130 0 460 3.15 4
131 1 620 3.17 2
132 0 640 2.79 2
133 0 580 3.40 2
134 0 500 3.08 3
135 0 560 2.95 2
136 0 500 3.57 3
137 0 560 3.33 4
138 0 700 4.00 3
139 0 620 3.40 2
140 1 600 3.58 1
141 0 640 3.93 2
142 1 700 3.52 4
143 0 620 3.94 4
144 0 580 3.40 3
145 0 580 3.40 4
146 0 380 3.43 3
147 0 480 3.40 2
148 0 560 2.71 3
149 1 480 2.91 1
150 0 740 3.31 1
151 1 800 3.74 1
152 0 400 3.38 2
153 1 640 3.94 2
154 0 580 3.46 3
155 0 620 3.69 3
156 1 580 2.86 4
157 0 560 2.52 2
158 1 480 3.58 1
159 0 660 3.49 2
160 0 700 3.82 3
161 0 600 3.13 2
162 0 640 3.50 2
163 1 700 3.56 2
164 0 520 2.73 2
165 0 580 3.30 2
166 0 700 4.00 1
167 0 440 3.24 4
168 0 720 3.77 3
169 0 500 4.00 3
170 0 600 3.62 3
171 0 400 3.51 3
172 0 540 2.81 3
173 0 680 3.48 3
174 1 800 3.43 2
175 0 500 3.53 4
176 1 620 3.37 2
177 0 520 2.62 2
178 1 620 3.23 3
179 0 620 3.33 3
180 0 300 3.01 3
181 0 620 3.78 3
182 0 500 3.88 4
183 0 700 4.00 2
184 1 540 3.84 2
185 0 500 2.79 4
186 0 800 3.60 2
187 0 560 3.61 3
188 0 580 2.88 2
189 0 560 3.07 2
190 0 500 3.35 2
191 1 640 2.94 2
192 0 800 3.54 3
193 0 640 3.76 3
194 0 380 3.59 4
195 1 600 3.47 2
196 0 560 3.59 2
197 0 660 3.07 3
198 1 400 3.23 4
199 0 600 3.63 3
200 0 580 3.77 4
201 0 800 3.31 3
202 1 580 3.20 2
203 1 700 4.00 1
204 0 420 3.92 4
205 1 600 3.89 1
206 1 780 3.80 3
207 0 740 3.54 1
208 1 640 3.63 1
209 0 540 3.16 3
210 0 580 3.50 2
211 0 740 3.34 4
212 0 580 3.02 2
213 0 460 2.87 2
214 0 640 3.38 3
215 1 600 3.56 2
216 1 660 2.91 3
217 0 340 2.90 1
218 1 460 3.64 1
219 0 460 2.98 1
220 1 560 3.59 2
221 0 540 3.28 3
222 0 680 3.99 3
223 1 480 3.02 1
224 0 800 3.47 3
225 0 800 2.90 2
226 1 720 3.50 3
227 0 620 3.58 2
228 0 540 3.02 4
229 0 480 3.43 2
230 1 720 3.42 2
231 0 580 3.29 4
232 0 600 3.28 3
233 0 380 3.38 2
234 0 420 2.67 3
235 1 800 3.53 1
236 0 620 3.05 2
237 1 660 3.49 2
238 0 480 4.00 2
239 0 500 2.86 4
240 0 700 3.45 3
241 0 440 2.76 2
242 1 520 3.81 1
243 1 680 2.96 3
244 0 620 3.22 2
245 0 540 3.04 1
246 0 800 3.91 3
247 0 680 3.34 2
248 0 440 3.17 2
249 0 680 3.64 3
250 0 640 3.73 3
[ reached getOption("max.print") -- omitted 150 rows ]
> adm=read.csv("binary.csv")
> head(adm)
admit gre gpa rank
1 0 380 3.61 3
2 1 660 3.67 3
3 1 800 4.00 1
4 1 640 3.19 4
5 0 520 2.93 4
6 1 760 3.00 2
> adm$rank=factor(adm$rank)
> str(adm)
'data.frame': 400 obs. of 4 variables:
$ admit: int 0 1 1 1 0 1 1 0 1 0 ...
$ gre : int 380 660 800 640 520 760 560 400 540 700 ...
$ gpa : num 3.61 3.67 4 3.19 2.93 3 2.98 3.08 3.39 3.92 ...
$ rank : Factor w/ 4 levels "1","2","3","4": 3 3 1 4 4 2 1 2 3 2 ...
> ?xtabs
> xtabs(~admit+rank,data=adm)
rank
admit 1 2 3 4
0 28 97 93 55
1 33 54 28 12
> ?glm
> logitm=glm(admit~gre+gpa+rank,data=adm,family="binomial")
> summary(logitm)
Call:
glm(formula = admit ~ gre + gpa + rank, family = "binomial",
data = adm)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.6268 -0.8662 -0.6388 1.1490 2.0790
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -3.989979 1.139951 -3.500 0.000465 ***
gre 0.002264 0.001094 2.070 0.038465 *
gpa 0.804038 0.331819 2.423 0.015388 *
rank2 -0.675443 0.316490 -2.134 0.032829 *
rank3 -1.340204 0.345306 -3.881 0.000104 ***
rank4 -1.551464 0.417832 -3.713 0.000205 ***
---
Signif. codes: 0 �***� 0.001 �**� 0.01 �*� 0.05 �.� 0.1 � � 1
> coef1=exp(coef(logitm))
> coef1
(Intercept) gre gpa rank2 rank3 rank4
0.0185001 1.0022670 2.2345448 0.5089310 0.2617923 0.2119375
> coef2=coef1/(1+coef1)
> coef2
(Intercept) gre gpa rank2 rank3 rank4
0.01816406 0.50056611 0.69083749 0.33727915 0.20747653 0.17487497
> install.packages("quantmod")
Installing package into �C:/Users/Priyanshu/Documents/R/win-library/3.5�
(as �lib� is unspecified)
also installing the dependencies �xts�, �zoo�, �TTR�, �curl�
There are binary versions available but the source versions are later:
binary source needs_compilation
xts 0.10-2 0.11-0 TRUE
zoo 1.8-2 1.8-3 TRUE
as.Date, as.Date.numeric
This message is shown once per session and may be disabled by setting
options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
This message is shown once per session and may be disabled by setting
options("getSymbols.yahoo.warning"=FALSE).
[1] "NSEI"
Warning message:
^NSEI contains missing values. Some functions will not work if objects contain
missing values in the middle of the series. Consider using na.omit(), na.approx(),
na.fill(), etc to remove or replace them.
> head(NSEI)
NSEI.Open NSEI.High NSEI.Low NSEI.Close NSEI.Volume NSEI.Adjusted
2011-01-03 6177.45 6178.55 6147.20 6157.60 0 6157.60
2011-01-04 6172.75 6181.05 6124.40 6146.35 0 6146.35
2011-01-05 6141.35 6141.35 6062.35 6079.80 0 6079.80
2011-01-06 6107.00 6116.15 6022.30 6048.25 0 6048.25
2011-01-07 6030.90 6051.20 5883.60 5904.60 0 5904.60
2011-01-10 5901.30 5907.25 5740.95 5762.85 0 5762.85
>
> tail(NSEI)
NSEI.Open NSEI.High NSEI.Low NSEI.Close NSEI.Volume NSEI.Adjusted
2018-07-09 10838.30 10860.35 10807.15 10852.90 183600 10852.90
2018-07-10 10902.75 10956.90 10876.65 10947.25 197000 10947.25
2018-07-11 10956.40 10976.65 10923.00 10948.30 222300 10948.30
2018-07-12 11006.95 11078.30 10999.65 11023.20 248300 11023.20
2018-07-13 11056.90 11071.35 10999.75 11018.90 0 11018.90
2018-07-16 11018.95 11019.50 10926.25 10936.85 210500 10936.85
> tail(Ad(NSEI))
NSEI.Adjusted
2018-07-09 10852.90
2018-07-10 10947.25
2018-07-11 10948.30
2018-07-12 11023.20
2018-07-13 11018.90
2018-07-16 10936.85
> nifret=diff(log(Ad(NSEI)))*100
> symbols=c("INFY.NS","RELIANCE.NS","PIDI.NS")
> getSymbols(symbols,from="2011-01-01")
Warning: PIDI.NS download failed; trying again.
Error: PIDI.NS download failed after two attempts. Error message:
HTTP error 404.
In addition: Warning messages:
1: INFY.NS contains missing values. Some functions will not work if objects contain
missing values in the middle of the series. Consider using na.omit(), na.approx(),
na.fill(), etc to remove or replace them.
2: RELIANCE.NS contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using na.omit(),
na.approx(), na.fill(), etc to remove or replace them.
> symbols=c("INFY.NS","RELIANCE.NS","PIDILITIND.NS")
> getSymbols(symbols,from="2011-01-01")
[1] "INFY.NS" "RELIANCE.NS" "PIDILITIND.NS"
Warning messages:
1: INFY.NS contains missing values. Some functions will not work if objects contain
missing values in the middle of the series. Consider using na.omit(), na.approx(),
na.fill(), etc to remove or replace them.
2: RELIANCE.NS contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using na.omit(),
na.approx(), na.fill(), etc to remove or replace them.
3: PIDILITIND.NS contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using na.omit(),
na.approx(), na.fill(), etc to remove or replace them.
> infy.ret=diff(log(Ad(INFY.NS)))
> rel.ret=diff(log(Ad(RELIANCE.NS)))
> pid.ret=diff(log(Ad(PIDILITIND.NS)))
> dataDaily=na.omit(merge(infy.ret,rel.ret,pid.ret),join="inner")
> reg=list()
> for (i in 1:3){}
> for (i in 1:3){
+ reg[[i]]=lm(dataDaily[,i]~dataDaily[,4])
+ }
Error in `[.xts`(dataDaily, , 4) : subscript out of bounds
> for (i in 1:3){
+ reg[[i]]=lm(dataDaily[,i]~dataDaily[,3])
+ }
> sapply(reg,coef)
[,1] [,2] [,3]
(Intercept) 0.0003279766 0.0002626985 -1.61326e-18
dataDaily[, 3] 0.1062612039 0.2087807023 1.00000e+00