dim(en)
length(en)
en
length(en)
getwd()
?uninstall.packages
?install.packages
.libPaths()
remove.packages('rm')
remove.packages('rms')
remove.packages('Rcurl')
remove.packages('RCurl')
remove.packages('RGoogleDocs')
library(rms)
remove.packages('Design')
remove.packages('Design', lib.loc=2)
remove.packages('Design', lib=.libPaths()[2])
citation()
?install.packages
.libPaths
.libPaths()
update.packages()
update.packages(ask=FALSE)
y=scan()
1162/13
y
1162/14
1920+83
y=scan()
1162/14
y1<-matrix(y, nrow=83, byrow=T)
y1
y2=y1[,2:13]
y2
y3=ts(y2,s=1921,f=12)
y3
plot(y3)
y3
y3=ts(y2,s=1921,f=12)
y2
y3=ts(as.vector(t(y2)),s=1921,f=12)
plot(y3)
attr(y3,'note')='Delta Unimpaired Total Outflow estimated flow in TAF'
note(y3)
y3
str(y3)
attr(y3,'note')
out.wy.taf=y3
?attr
comment(y3)='Delta Unimpaired Total Outflow estimated flow in TAF'
y3
comment(y3)
str(y3)
attr(y3,'note')=NULL
str(y3)
attributes(y3)
ren(y3,out.ui)
rename(y3,out.ui)
?rename
args(rename)
rename(y3,'out.ui')
out.ui
y3
?ren
out.ui=y3
.libPaths()
y=scan()
y1<-matrix(y, nrow=83, byrow=T)
y2<-y1[,2:13]
y3=ts(as.vector(t(y2)),s=1921,f=12)  # TAF/mon
seconds <- c(31, ifelse(leapYear(floor(time(y3), 29, 28))), 31, 30, 31, 	30, 31, 31, 30, 31, 30, 31) * 86400  # sec/mon
y4 <- y3 * 1.2334818 * 10^6/seconds  # m^3/sec
tot.ui <-y4
comment(tot.ui)='Delta Unimpaired Total Inflow estimated flow in m^3/s'
library(wq)
1921 532 3078 4151 6747 4578 5559 3982 4638 3455 1114 543 448 38825 1922 433 547 1704 1561 4551 3553 4671 7783 5618 1508 609 437 32975 1923 489 858 3297 2568 1687 1886 4254 4248 2329 1197 519 467 23799 1924 506 464 551 647 1394 752 1200 1206 476 381 305 292 8174 1925 415 952 1218 1215 6921 2745 4787 4417 2327 955 524 417 26893 1926 452 579 790 985 4308 2081 4692 2446 994 513 361 333 18534 1927 386 2525 2499 3006 8887 4603 6102 4930 3517 1206 542 433 38636 1928 444 1722 1372 1786 2670 7594 4623 3426 1305 638 413 370 26363 1929 376 590 774 740 1424 1535 1887 2762 1580 587 321 323 12899 1930 315 338 2947 1910 2389 3636 3093 2589 1745 629 376 359 20326 1931 376 516 440 957 914 1403 1385 1295 578 323 278 269 8734 1932 365 441 2453 1907 2873 3042 3173 4700 3302 1116 466 341 24179 1933 332 354 479 875 728 2287 2263 2707 2729 695 360 317 14126 1934 347 393 1355 1843 2041 2231 1817 1203 720 373 295 277 12895 1935 347 1000 954 2679 2095 3017 7899 5459 3269 942 469 356 28486 1936 432 444 599 4316 7946 3562 4679 4265 2
667 975 453 360 30698 1937 360 364 526 693 3881 4727 4760 5742 2758 885 414 338 25448 1938 445 2080 6227 2532 8476 11254 7632 8801 5943 2148 838 573 56949 1939 671 733 925 928 1018 2316 2578 1641 783 445 342 363 12743 1940 478 397 782 5232 8182 8262 5676 4404 2140 756 454 422 37185 1941 490 712 4654 6171 7634 6798 6395 6887 3942 1750 750 563 46746 1942 563 776 4764 6127 7426 3040 5895 5738 4865 1830 735 542 42301 1943 542 1309 2392 6818 3943 7592 5159 4207 2606 1195 625 482 36870 1944 519 562 638 967 1972 2689 2237 3796 2007 939 458 374 17158 1945 449 1461 1859 1328 5858 2942 3408 4383 2970 1149 544 406 26757 1946 760 1630 6445 3473 1712 2899 4085 4153 1917 825 506 418 28823 1947 502 1098 1316 728 2002 3126 2603 2275 1292 520 387 357 16206 1948 785 673 574 2232 850 2115 5469 5252 3768 1058 519 446 23741 1949 459 564 791 650 1194 4775 3861 3844 1695 572 412 359 19176 1950 380 468 495 2471 3673 3074 4472 4240 2364 796 440 399 23272 1951 1112 6151 8162 5104 4621 3515 3295 3692 1778 768 496 416 39110 1952 562 1
147 4698 6166 5699 5622 7571 8733 5240 2337 881 614 49270 1953 541 590 2674 7295 1924 2713 3885 3945 3824 1562 652 550 30155 1954 542 972 931 2953 3779 4672 5584 3726 1628 768 528 480 26563 1955 481 917 1729 1719 1210 1541 2349 3679 2072 698 438 402 17235 1956 407 700 12861 10914 5472 3905 4159 6072 3965 1716 750 579 51500 1957 725 688 688 959 3405 4258 2793 4526 2751 877 526 537 22733 1958 1035 993 1999 3332 11031 7005 9068 7891 4814 1857 898 651 50574 1959 591 614 662 2737 3586 2365 2595 2034 1170 577 423 613 17967 1960 461 428 525 1078 4311 3929 2890 2706 1453 564 409 389 19143 1961 424 854 1645 1087 2652 2369 2356 2455 1356 533 448 395 16574 1962 428 657 1442 1067 5706 3226 4497 3531 2775 993 495 394 25211 1963 3289 862 2397 2288 6175 2839 7470 5884 3005 1321 656 538 36724 1964 667 2053 1020 2121 1248 1389 2225 2781 1735 639 419 364 16661 1965 439 1165 11827 8139 2881 2426 6105 4406 3115 1488 932 528 43451 1966 521 1791 1393 2685 2150 3048 3875 2849 1010 554 433 406 20715 1967 397 1648 3969 5156 3301 53
51 5602 7709 6313 2927 901 564 43838 1968 592 626 1045 2185 4869 3214 2541 2438 1209 609 571 447 20346 1969 573 1051 2427 11585 7524 5190 7039 8688 5062 2054 816 588 52597 1970 735 758 4274 14518 4095 4211 2196 3168 2160 903 566 476 38060 1971 571 2449 4706 4107 2287 4710 4027 4747 3737 1349 641 552 33883 1972 606 782 1549 1702 2206 3879 2918 2975 1653 629 443 521 19863 1973 686 1565 2314 6152 5719 4722 3842 5434 2498 846 562 508 34848 1974 748 5696 5003 9239 2793 8408 6549 5423 3612 1530 752 576 50329 1975 599 699 1032 1247 4363 6612 3798 6271 4553 1382 709 619 31884 1976 1024 1013 887 740 1035 1559 1536 1592 659 460 550 479 11534 1977 447 455 415 551 537 626 769 1004 812 402 357 426 6801 1978 384 547 2336 8440 5035 7308 5922 5643 4257 1889 741 860 43362 1979 470 600 613 2009 3183 4021 3272 5175 1949 776 482 423 22973 1980 759 1069 1722 9461 8608 5115 3838 4277 3252 1893 655 597 41246 1981 530 498 1112 2187 2153 3170 2701 2367 1107 517 408 381 17131 1982 699 5345 7248 5282 7482 6704 11259 6854 3802 1874 87
2 945 58366 1983 1524 2707 5593 6732 9754 15829 6917 8852 8321 4095 1571 961 72856 1984 990 5158 9764 3954 3039 3851 2982 4113 2237 991 582 527 38188 1985 735 2335 1518 1045 1663 2089 3284 2422 1121 515 419 536 17682 1986 588 891 1566 3324 16847 9878 4057 4218 2943 1073 558 659 46602 1987 621 487 602 918 1903 3253 1996 1657 704 448 359 350 13298 1988 400 546 2148 2511 1238 1491 1740 1784 1029 490 343 299 14019 1989 355 1239 927 1093 1208 7732 4144 2538 1344 584 380 509 22053 1990 864 669 527 1588 1161 2190 2042 1982 1386 543 337 314 13603 1991 358 388 386 414 534 3713 2346 2727 1796 638 341 313 13954 1992 542 491 574 732 3355 2582 2564 1495 622 562 321 309 14149 1993 472 445 1804 6509 4868 7288 5191 5939 4197 1522 654 494 39383 1994 563 522 1025 954 1701 1840 1842 2061 912 392 296 348 12456 1995 423 720 1405 12012 4103 14359 7253 8916 6290 3816 1246 729 61272 1996 562 548 2152 3499 8459 5740 4860 6485 2758 1147 628 509 37347 1997 605 1523 9291 17253 3973 2963 3078 3306 1811 764 596 522 45685 1998 631 1160 1
594 7229 11637 7019 6298 7259 7807 3759 1262 827 56482 1999 812 1656 2269 3297 6387 4888 4135 4998 3005 1090 694 606 33837 2000 622 831 752 3177 7542 5266 4217 4211 2085 838 603 597 30741 2001 657 626 747 1052 1999 3001 2417 2813 801 518 422 407 15460 2002 444 1103 3308 3743 2251 3121 3442 3141 1653 617 498 439 23760 2003 549 1243 2394 3486 3809 4035 3854 4338 2629 881 545 465 28228
Av
y1<-matrix(y, nrow=83, byrow=T)
y2<-y1[,2:13]
y3=ts(as.vector(t(y2)),s=1921,f=12)  # TAF/mon
seconds <- c(31, ifelse(leapYear(floor(time(y3), 29, 28))), 31, 30, 31, 	30, 31, 31, 30, 31, 30, 31) * 86400  # sec/mon
y4 <- y3 * 1.2334818 * 10^6/seconds  # m^3/sec
tot.ui <-y4
comment(tot.ui)='Delta Unimpaired Total Inflow estimated flow in m^3/s'
seconds <- c(31, ifelse(leapYear(floor(time(y3))), 29, 28), 31, 30, 31, 	30, 31, 31, 30, 31, 30, 31) * 86400  # sec/mon
y4 <- y3 * 1.2334818 * 10^6/seconds  # m^3/sec
y=scan()
y1<-matrix(y, nrow=83, byrow=T)
y2<-y1[,2:13]
y3=ts(as.vector(t(y2)),s=1921,f=12)  # TAF/mon
seconds <- c(31, ifelse(leapYear(floor(time(y3))), 29, 28), 31, 30, 31, 	30, 31, 31, 30, 31, 30, 31) * 86400  # sec/mon
y4 <- y3 * 1.2334818 * 10^6/seconds  # m^3/sec
length(y3)
length(seconds)
/Users/alanjassby/RPackages/wq_package/wqSupport/inDevelopment/nhx/ammFrac.R
ammFrac <-#
function(pH, t, S, pHscale = c('total', 'free')) {#
#
	## adj 10/16/09 4:05 PM#
	## Estimates fraction of total ammonium in un-ionized form (Clegg and Whitfield 1995). Valid for -2 to 40°C, 0 to 40 salinity.#
	## Inputs:#
	## pH, pH measurement#
	## t, temperature (deg C)#
	## S, salinity (PSS)#
	## pHscale, scale on which pH is measured#
	## Output:#
	## un-ionized fraction#
	#
	## Check input.#
	pHscale = match.arg(pHscale)#
	#
	## Empirical constants#
	a <- c(0.0500616, -9.412696, -2.029559e-7, -0.0142372, 1.46041e-5, 3.730005, 7.1047e-5, -0.0229021, -5.521278e-7, 1.95413e-4)#
	b <- c(0.04203362, -11.24742, -13.64160, 1.176949, -0.02860785, 545.4834, -0.1462507, 0.009022648, -1.471361e-4, 10.54250, 0.004669309, -1.691742e-4, -0.5677934, -2.354039e-5, 0.009698623)#
	#
	## Calculate dissociation constant, depending on pH scale#
	T = t + 273.15#
	pKaT = 9.244605 - 2729.33*(1/298.15 - 1/T)	#
	if (identical(pHscale, 'free')) {#
		pKaStar = pKaT + (a[1] + a[2]/T + a[3]*T^2)*S^.5 + (a[4] + a[5]*T + a[6]/T)*S + (a[7] + a[8]/T)*S^2 + (a[9] + a[10]/T)* S^3#
	} else {#
		pKaStar = pKaT + (b[1] + b[2]/T)*S^.25 + (b[3] + b[4]*T^.5 + b[5]*T + b[6]/T)*S^.5 + (b[7] + b[8]*T^.5 + b[9]*T +b[10]/T)*S^1.5 + (b[11] + b[12]*T^.5 + b[13]/T)*S^2 + (b[14] + b[15]/T)*S^2.5	#
	}#
	#
	## Calculate ammonium fraction.#
	H = 10^(-pH)#
	K = 10^(-pKaStar)#
	1/(1+H/K)#
}
ph = c(8, 8, 8, 7.8)
temp = c(10 , 25, 25, 25)
sal = c(0, 0, 35, 35)
round(ammFrac(ph, temp, sal), 4)  # 0.0183 0.0539 0.0556 0.0358
round(ammFrac(ph, temp, sal, 'free'), 4)  # 0.0183 0.0539 0.0440 0.0282
a <- c(0.0500616, -9.412696, -2.029559e-7, -0.0142372, 1.46041e-5, 3.730005, 7.1047e-5, -0.0229021, -5.521278e-7, 1.95413e-4)
	b <- c(0.04203362, -11.24742, -13.64160, 1.176949, -0.02860785, 545.4834, -0.1462507, 0.009022648, -1.471361e-4, 10.54250, 0.004669309, -1.691742e-4, -0.5677934, -2.354039e-5, 0.009698623)
	
	## Calculate dissociation constant, depending on pH scale
	T = t + 273.15
	pKaT = 9.244605 - 2729.33*(1/298.15 - 1/T)	
	if (identical(pHscale, 'free')) {
		pKaStar = pKaT + (a[1] + a[2]/T + a[3]*T^2)*S^.5 + (a[4] + a[5]*T + a[6]/T)*S + (a[7] + a[8]/T)*S^2 + (a[9] + a[10]/T)* S^3
	} else {
		pKaStar = pKaT + (b[1] + b[2]/T)*S^.25 + (b[3] + b[4]*T^.5 + b[5]*T + b[6]/T)*S^.5 + (b[7] + b[8]*T^.5 + b[9]*T +b[10]/T)*S^1.5 + (b[11] + b[12]*T^.5 + b[13]/T)*S^2 + (b[14] + b[15]/T)*S^2.5	
	}
		pKaStar = pKaT + (b[1] + b[2]/T)*S^.25 + (b[3] + b[4]*T^.5 + b[5]*T + b[6]/T)*S^.5 + (b[7] + b[8]*T^.5 + b[9]*T +b[10]/T)*S^1.5 + (b[11] + b[12]*T^.5 + b[13]/T)*S^2 + (b[14] + b[15]/T)*S^2.5
ammFrac <-
function(pH, t, S, pHscale = c('total', 'free')) {

	## adj 10/16/09 4:05 PM
	## Estimates fraction of total ammonium in un-ionized form (Clegg and Whitfield 1995). Valid for -2 to 40°C, 0 to 40 salinity.
	## Inputs:
	## pH, pH measurement
	## t, temperature (deg C)
	## S, salinity (PSS)
	## pHscale, scale on which pH is measured
	## Output:
	## un-ionized fraction
	
	## Check input.
	pHscale = match.arg(pHscale)
	
	## Empirical constants
	a <- c(0.0500616, -9.412696, -2.029559e-7, -0.0142372, 1.46041e-5, 3.730005, 7.1047e-5, -0.0229021, -5.521278e-7, 1.95413e-4)
	b <- c(0.04203362, -11.24742, -13.64160, 1.176949, -0.02860785, 545.4834, -0.1462507, 0.009022648, -1.471361e-4, 10.54250, 0.004669309, -1.691742e-4, -0.5677934, -2.354039e-5, 0.009698623)
	
	## Calculate dissociation constant, depending on pH scale
	T = t + 273.15
	pKaT = 9.244605 - 2729.33*(1/298.15 - 1/T)	
	if (identical(pHscale, 'free')) {
		pKaStar = pKaT + (a[1] + a[2]/T + a[3]*T^2)*S^.5 + (a[4] + a[5]*T + a[6]/T)*S + (a[7] + a[8
]/T)*S^2 + (a[9] + a[10]/T)* S^3
	} else {
		pKaStar = pKaT + (b[1] + b[2]/T)*S^.25 + (b[3] + b[4]*T^.5 + b[5]*T + b[6]/T)*S^.5 + (b[7] + b[8]*T^.5 + b[9]*T +b[10]/T)*S^1.5 + (b[11] + b[12]*T^.5 + b[13]/T)*S^2 + (b[14] + b[15]/T)*S^2.5	
	}
	browser()
	## Calculate ammonium fraction.
	H = 10^(-pH)
	K = 10^(-pKaStar)
	1/(1+H/K)
}
round(ammFrac(ph, temp, sal, 'free'), 4)  # 0.0183 0.0539 0.0440 0.0282
pKaStar
pKaStar*1.05
pKaStar=pKaStar*1.05
0
?
?browser
c
round(ammFrac(ph, temp, sal, 'free'), 4)  # 0.0183 0.0539 0.0440 0.0282
c
round(ammFrac(ph, temp, sal, 'free'), 4)  # 0.0183 0.0539 0.0440 0.0282
pKaStar=pKaStar*1.0001
c
round(ammFrac(ph, temp, sal, 'free'), 4)  # 0.0183 0.0539 0.0440 0.0282
pKaStar=pKaStar*1.01
c
round(ammFrac(ph, temp, sal, 'free'), 4)  # 0.0183 0.0539 0.0440 0.0282
pKaStar
10^(-pKaStar)
10^(-pKaStar*1.05)
c
round(ammFrac(ph, temp, sal, 'free'), 4)  # 0.0183 0.0539 0.0440 0.0282
n
pH
H
n
H
n
K
1/(1+H/K)
1/(1+H/(1.05*K))
c
x=rnorm(100)
ecdf(x,plot=T)
?ecdf
plot(ecdf(x))
library(zoo)
d <- read.csv('~/Documents/Cascade/CascadeIndicatorsAnnualMeans.csv')
d1 <- d[, seq(1, 48, 2)]
d2 <- d[, seq(2, 48, 2)]
ans <- matrix(nrow=130, ncol=24)
for (i in 1:24)
    ans[match(d1[, i], 1970:2099, nomatch=0), i] <- na.trim(d2[, i], sides='right')
t1 <- ts(ans, s=1970)
colnames(t1) <- tolower(colnames(d2))
plot(t1[, 1:10])
write.table(t1, '../data/CascadeIndicatorsAnnualMeansTs.csv', sep=',', row.names=F)
library(zyp)
dat <- as.data.frame(t(t1))
ans <- zyp.trend.dataframe(dat, metadata.cols=0, method='yuepilon', conf.intervals=T)
ans1 <- ans[, c(1,2,4,6,8)]
ans1
?zyp
library(zoo)
d <- read.csv('~/Documents/Cascade/CascadeIndicatorsAnnualMeans.csv')
d1 <- d[, seq(1, 48, 2)]
d2 <- d[, seq(2, 48, 2)]
ans <- matrix(nrow=130, ncol=24)
for (i in 1:24)
    ans[match(d1[, i], 1970:2099, nomatch=0), i] <- na.trim(d2[, i], sides='right')
t1 <- ts(ans, s=1970)
colnames(t1) <- tolower(colnames(d2))
plot(t1[, 1:10])
write.table(t1, '../data/CascadeIndicatorsAnnualMeansTs.csv', sep=',', row.names=F)
t1
library(zyp)
dat <- as.data.frame(t(t1))
ans <- zyp.trend.dataframe(dat, metadata.cols=0, method='yuepilon', conf.intervals=T)
ans1 <- ans[, c(1,2,4,6,8)]
ans1
t1 <- ts(ans, s=2010)
colnames(t1) <- tolower(colnames(d2))
d <- read.csv('~/Documents/Cascade/CascadeIndicatorsAnnualMeans.csv')
d1 <- d[, seq(1, 48, 2)]
d2 <- d[, seq(2, 48, 2)]
ans <- matrix(nrow=130, ncol=24)
for (i in 1:24)
    ans[match(d1[, i], 1970:2099, nomatch=0), i] <- na.trim(d2[, i], sides='right')
t1 <- ts(ans, s=2010)
colnames(t1) <- tolower(colnames(d2))
dat <- as.data.frame(t(t1))
ans <- zyp.trend.dataframe(dat, metadata.cols=0, method='yuepilon', conf.intervals=T)
ans1 <- ans[, c(1,2,4,6,8)]
ans1
ans
library(coda)
library(rjags)
library(wq)
library(plyr)
library(ggplot2)
?install.packages
.libPaths
.libPaths()
remove.packages('RGtks2')
remove.packages('RGtk2')
remove.packages('RGtk2Extras')
remove.packages('gWidgetsRGtk2')
getOption()
getOptions()
getOption('repos')
options()
install.packages(cs(RGtk2, RGtk2Extras, gWidgetsRGtk2))
library(formatR)
formatR()
remove.packages('formatR')
install.packages(cs(formatR))
library(zoo)
d <- read.csv('~/Documents/Cascade/CascadeIndicatorsAnnualMeans.csv')
d1 <- d[, seq(1, 48, 2)]
d2 <- d[, seq(2, 48, 2)]
ans <- matrix(nrow=130, ncol=24)
for (i in 1:24)
    ans[match(d1[, i], 1970:2099, nomatch=0), i] <- na.trim(d2[, i], sides='right')
t1 <- ts(ans, s=1970)
colnames(t1) <- tolower(colnames(d2))
t1
t2 <- window(t1, s=2010)
head(t2)
t2
i <- 1
binom.test(sum(t2[, i] > t2[, i+1]), 90)
plot(t2[, 1:2])
b1 <- binom.test(sum(t2[, i] > t2[, i+1]), 90)
names(b1)
summary(b1)
b1[[8]]
binom.test
signs <- matrix(ncol=2, nrow=12)
signs
seq(1, 23, 2)
   b1 <- binom.test(sum(t2[, i] > t2[, i+1]), 90)
class(b1)
dim(b1)
b1[1]
   signs[(i + 1)/2, ] <- c(b1[['estimate']], b1[['p.value']])
signs
b1
for (i in seq(1, 23, 2)) {
   b1 <- binom.test(sum(t2[, i] > t2[, i+1]), 90)
   signs[(i + 1)/2, ] <- c(b1[['estimate']], b1[['p.value']])
}
signs
colnames(signs) <- c('estimate', 'p.value')
rownames(signs) <- colnames(t2)[seq(1, 23, 2)]
signs
rownames(signs) <- gsub('.a2', '', colnames(t2)[seq(1, 23, 2)])
signs
d <- data.frame(signs, varis = rownames(signs))
d
str(d)
d <- data.frame(signs, varis = reorder(rownames(signs), estimate, mean))
d <- data.frame(signs)
d1 <- transform(d, varis = reorder(rownames(signs), estimate, mean)
d1 <- transform(d, varis = reorder(rownames(signs), estimate, mean))
d1
str(d1)
require(ggplot2)
ggplot(d1, aes(x=estimate, y=varis, shape = p.value<0.05)) +
    geom_vline(xintercept=0, colour='grey50', size=0.25) +
    geom_point(size=5) +
   scale_shape_manual(expression(paste(italic(p), "-value")), values =
	c(`FALSE` = 1, `TRUE` = 16), breaks = c(FALSE, TRUE), labels =
	c("> 0.05", "< 0.05")) +
    labs(list(x='Probability A2 > B1', y='')) +
    theme_bw()
ggplot(d1, aes(x=estimate, y=varis, shape = p.value<0.05)) +
    geom_vline(xintercept=.5, colour='grey50', size=0.25) +
    geom_point(size=5) +
   scale_shape_manual(expression(paste(italic(p), "-value")), values =
	c(`FALSE` = 1, `TRUE` = 16), breaks = c(FALSE, TRUE), labels =
	c("> 0.05", "< 0.05")) +
    labs(list(x='Probability A2 > B1', y='')) +
    theme_bw()
ggplot(d1, aes(x=estimate, y=varis, shape = p.value<0.05)) +
    geom_vline(xintercept=.5, colour='grey50', size=0.25) +
    geom_point(size=5) +
   scale_shape_manual(expression(paste(italic(p), "-value")), values =
	c(`FALSE` = 1, `TRUE` = 16), breaks = c(FALSE, TRUE), labels =
	c("> 0.05", "< 0.05")) +
    labs(list(x='Estimate', y='')) +
    theme_bw()
library(zoo)
d <- read.csv('~/Documents/Cascade/CascadeIndicatorsAnnualMeans.csv')
d1 <- d[, seq(1, 48, 2)]
d2 <- d[, seq(2, 48, 2)]
ans <- matrix(nrow=130, ncol=24)
for (i in 1:24)
    ans[match(d1[, i], 1970:2099, nomatch=0), i] <- na.trim(d2[, i], sides='right')
t1 <- ts(ans, s=1970)
colnames(t1) <- tolower(colnames(d2))
plot(t1[, 1:10])
write.table(t1, '~/Documents/Cascade/CascadeIndicatorsAnnualMeansTs.csv', sep=',', row.names=F)

###################################################
### MK trends with AR1 correction if necessary
###################################################
library(zyp)
t2 <- window(t1, s=2010)
dat <- as.data.frame(t(t2))
ans <- zyp.trend.dataframe(dat, metadata.cols=0, method='yuepilon', conf.intervals=T)
ans1 <- ans[, c(1,2,4,6,8)]

###################################################
### Plot tau
###################################################
## Prepare data frame
ans2 <- transform(ans, varis = gsub('.a2', '', rownames(ans)), scen = factor(rep(c('a2', 'b1'), 12), labels = c
('scenario A2', 'scenario B1')))
ans2 <- transform(ans2, varis = gsub('.b1', '', varis))
ans2 <- transform(ans2, varis = reorder(varis, tau, mean))
ans2 <- transform(ans2, varis = factor(varis, labels = c('Sediments\n(decreasing supply)', 'Snowmelt', 'Sediments\n(constant supply)', 'Unimpaired flow', 'Floodplain', 'Precipitation', 'Groundwater ', 'Salinity', 'Sacramento River\ntemperature', 'Delta temperature', 'Air temperature', 'Sea level')))
## Plot
require(ggplot2)
ggplot(ans2, aes(x=tau, y=varis, colour = sig<0.05)) +
   geom_vline(xintercept=0, colour='grey50', size=0.25) +
   geom_point(size=5) +
#   scale_shape_manual(expression(paste(italic(p), "-value")), values =
#   c(`FALSE` = 1, `TRUE` = 16), breaks = c(FALSE, TRUE), labels =
#   c("> 0.05", "< 0.05")) +
   scale_colour_manual(expression(paste(italic(p), "-value")), values =
   c(`FALSE` = "#1B9E77", `TRUE` = "#D95F02"), breaks = c(FALSE,
   TRUE), labels = c("> 0.05", "< 0.05")) +
   geom_segment(aes(xend=0, yend=varis)) +
   facet_wrap(~scen
, ncol=2) +
   labs(list(x='Rank correlation with time', y='')) +
   theme_bw()
install.packages('googleVis')
library(gogleVis)
library(googleVis)
library(googleVis)#
Fruits ## Example data#
M <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year")#
plot(M)
?googleVis
demo(googleVis)
source("/Users/alanjassby/RPackages/wq_package/initialize.R",echo=TRUE)
example(layOut)
examples(layOut)
chl27 = sfbayChla[, 's27']
g1 <- plotTsTile(chl27, legend.title = 'Chl log-anomaly', 
    square=FALSE)
g2 <- seasonTrend(chl27, plot = TRUE, legend = FALSE)
g3 <- plotSeason(chl27, num = 3, ylab = expression(paste('Chl-', italic(a), ', ', mu*g~L^{-1})))
## quartz("", 9, 6)  # e.g., on mac os x, or:
## grid.newpage()  # to re-use existing plot window
layOut(list(g1, 1, 1:6), list(g3, 2, 1:5), list(g2, 2, 6:7))
g2 <- seasonTrend(chl27, plot = TRUE, miss = FALSE)
layOut(list(g1, 1, 1:6), list(g3, 2, 1:5), list(g2, 2, 6:7))
seasontrend
seasonTrend
g2 <- seasonTrend(chl27, plot = TRUE, legend = TRUE)
layOut(list(g1, 1, 1:6), list(g3, 2, 1:5), list(g2, 2, 6:7))
layOut(list(g1, 1, 1:6), list(g2, 2, 7:10), list(g3, 2, 1:10))
layOut(list(g1, 1, 1:6), list(g2, 1, 7:10), list(g3, 2, 1:10))
layOut(list(g1, 1, 1:7), list(g2, 1, 8:10), list(g3, 2, 1:10))
quartz("", 9, 6)
layOut(list(g1, 1, 1:7), list(g2, 1, 8:10), list(g3, 2, 1:10))
## quartz("", 10, 5)  # e.g., on mac os x, or:
layOut(list(g1, 1, 1:7), list(g2, 1, 8:10), list(g3, 2, 1:10))
quartz("", 10, 5)
layOut(list(g1, 1, 1:7), list(g2, 1, 8:10), list(g3, 2, 1:10))
grid.newpage()
layOut(list(g1, 1, 1:6), list(g2, 1, 7:10), list(g3, 2, 1:8))
quartz("", 10, 8)
layOut(list(g1, 1, 1:6), list(g2, 1, 7:10), list(g3, 2:3, 1:8))
grid.newpage()
layOut(list(g1, 1:2, 1:6), list(g2, 1:2, 7:10), list(g3, 3:5, 1:8))
quartz("", 10, 6)
layOut(list(g1, 1:2, 1:6), list(g2, 1:2, 7:10), list(g3, 3:5, 1:8))
y <- sfbayChla
y1 <- tsSub(y, seas = c(1:7, 9:11))  # Aug and Dec often missing
y2 <- aggregate(y1, 1, mean, na.rm=FALSE)
mannKen(y)
mannKen(y, plot=TRUE)
mannKen(y2)
mannKen(y1)
getwd()
Sweave("/Users/alanjassby/RPackages/wq_package/wq/inst/doc/wq-package.Rnw")
warnings()
getwd()
setwd("/Users/alanjassby/RPackages/wq_package/wq/inst/doc/")
Sweave("/Users/alanjassby/RPackages/wq_package/wq/inst/doc/wq-package.Rnw")
eofNum
