我正在做R中的逻辑回归.有人可以澄清运行这两行的区别是什么?
1. glm(Response ~ Temperature, data=temp,
family = binomial(link="logit"))
2. glm(cbind(Response, n - Response) ~ Temperature,
data=temp, family =binomial, Ntrials=n)
Run Code Online (Sandbox Code Playgroud)
数据如下所示:(注意:响应是二进制.0 =死1 =不死)
Response Temperature
0 24.61
1 39.61
1 39.50
0 22.71
0 21.61
1 39.70
1 36.73
1 33.32
0 21.73
1 49.61
Run Code Online (Sandbox Code Playgroud) 我是曲线拟合的初学者,Stackoverflow上的几个帖子对我很有帮助.
我尝试使用正弦曲线拟合我的数据lm,nls但两种方法都显示出一种奇怪的拟合,如下所示.谁能指出我哪里出错了.我怀疑与时间有关,但无法做到正确.我的数据可以从这里访问.

data <- read.table(file="900days.txt", header=TRUE, sep="")
time<-data$time
temperature<-data$temperature
#lm fitting
xc<-cos(2*pi*time/366)
xs<-sin(2*pi*time/366)
fit.lm<-lm(temperature~xc+xs)
summary(fit.lm)
plot(temp~time, data=data, xlim=c(1, 900))
par(new=TRUE)
plot(fit.lm$fitted, type="l", col="red", xlim=c(1, 900), pch=19, ann=FALSE, xaxt="n",
yaxt="n")
#nls fitting
fit.nls<-nls(temp~C+alpha*sin(W*time+phi),
start=list(C=27.63415, alpha=27.886, W=0.0652, phi=14.9286))
summary(fit.nls)
plot(fit.nls$fitted, type="l", col="red", xlim=c(1, 900), pch=19, ann=FALSE, xaxt="n",
axt="n")
Run Code Online (Sandbox Code Playgroud) 我有一个rasterstack(5个栅格图层)实际上是一个时间序列栅格.
r <- raster(nrow=20, ncol=200)
s <- stack( sapply(1:5, function(i) setValues(r, rnorm(ncell(r), i, 3) )) )
s
class : RasterStack
dimensions : 20, 200, 4000, 5 (nrow, ncol, ncell, nlayers)
resolution : 1.8, 9 (x, y)
extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
names : layer.1, layer.2, layer.3, layer.4, layer.5
min values : -9.012146, -9.165947, -9.707269, -7.829763, -5.332007
max values : 11.32811, 11.97328, 15.99459, 15.66769, 16.72236
Run Code Online (Sandbox Code Playgroud)
我的目标是绘制每个像素并探索它们随时间的行为.
如何将每个像素与x,y坐标一起提取并绘制时间序列曲线?
我在R(glm)中运行逻辑回归.然后我设法绘制结果.我的代码如下:
temperature.glm = glm(Response~Temperature, data=mydata,family=binomial)
plot(mydata$Temperature,mydata$Response, ,xlab="Temperature",ylab="Probability of Response")
curve(predict(temperature.glm,data.frame(Temperature=x),type="resp"),add=TRUE, col="red")
points(mydata$Temperature,fitted(temperature.glm),pch=20)
title(main="Response-Temperature with Fitted GLM Logistic Regression Line")
Run Code Online (Sandbox Code Playgroud)
我的问题是:
型号:
SET 1
(Intercept) -88.4505
Temperature 2.9677
SET 2
(Intercept) -88.585533
Temperature 2.972168
Run Code Online (Sandbox Code Playgroud)
mydata 在2列和~700行中.
Response Temperature
1 29.33
1 30.37
1 29.52
1 29.66
1 29.57
1 30.04
1 30.58
1 30.41
1 29.61
1 30.51
1 30.91
1 30.74
1 29.91
1 29.99
1 29.99
1 29.99
1 29.99
1 29.99
1 29.99
1 …Run Code Online (Sandbox Code Playgroud) 如何将像素值添加到绘图中?我可以通过使用获取值,click()但我希望它出现在图中。
library(raster)
r <- raster(nrow=3, ncol=3)
r[] <- 1:ncell(r)
plot(r)
click(r)
Run Code Online (Sandbox Code Playgroud)

library(raster)
img <- list.files(pattern='*.img')
stack <- stack(img)
Run Code Online (Sandbox Code Playgroud)
上面的代码应该工作,但尽管有我的文件夹中的*.IMG文件,我也有*img.xml和*img.aux.xml文件.如何重写我的代码以便它只堆叠*.img文件?
day <- c(seq(1, 10592, by = 1))
Run Code Online (Sandbox Code Playgroud)
如何将"日"改为1982年1月1日至2010年12月31日的朱利安日期格式.
提前致谢.