楼主: howtowrite
1472 2

[Splus与R初级班] Help me please [推广有奖]

  • 0关注
  • 1粉丝

VIP

已卖:376份资源

本科生

33%

还不是VIP/贵宾

-

威望
0
论坛币
4008 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
849 点
帖子
67
精华
0
在线时间
66 小时
注册时间
2007-1-28
最后登录
2011-4-22

楼主
howtowrite 发表于 2009-10-30 07:49:55 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
  My teacher gave the R language as follows
p1=130
p2=113
set1=seq(2,402,10)
result=matrix(0,1,8)
for (n1 in set1){
rv1=matrix(0,100,1)
rv2=matrix(0,100,1)
for (j in 1:100)  {

x=mvrnorm(n=n1,rep(0,p1),diag(1,p1))
y=mvrnorm(n=n1,rep(0,p2),diag(1,p2))

num1=sum((t(y)%*%x)^2)
den1=sqrt(sum((x%*%t(x))^2)%*%sum((y%*%t(y))^2))
V1=(x%*%t(x))-diag(diag(x%*%t(x)))
W1=(y%*%t(y))-diag(diag(y%*%t(y)))
V2=matrix(V1,length(V1),1)
W2=matrix(W1,length(W1),1)
num2=t(V2)%*%W2
den2=sqrt((t(V2)%*%V2)%*%(t(W2)%*%W2))

rv1[j]=num1/den1
rv2[j]=num2/den2
}
rv3=(p1%*%p2)/sqrt((p1^2+(n1+1)%*%p1)*(p2^2+(n1+1)%*%p2))
result=rbind(result,cbind(n1,mean(rv1),min(rv1),max(rv1),rv3,mean(rv2),min(rv2),max(rv2)))
}
result=result[-1,]
result
cbind(seq(2,402,10),result[,5]-result[,2])
x1=result[,1]

plot(x1, result[,2], type='l', col="red")
points(x1, result[,3], type='l', col="red")
points(x1, result[,4], type='l', col="red")
plot(x1, result[,6], type='l',ylim=c(-1,1), xlim=c(0,500), col="red")
points(x1, result[,7], type='l',ylim=c(-1,1), xlim=c(0,500), col="red")
points(x1, result[,8], type='l',ylim=c(-1,1), xlim=c(0,500), col="red")
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:please Lease ease Help plea Help please

沙发
howtowrite 发表于 2009-10-30 07:55:38
I can't understand  some places as follows:
1)for (n1 in set1)    and  for (j in 1:100)
2)x=mvrnorm(n=n1,rep(0,p1),diag(1,p1))
3)diag(diag(x%*%t(x))
4)rbind(result,cbind(n1,mean(rv1),min(rv1),max(rv1),rv3,mean(rv2),min(rv2),max(rv2)))
5)cbind(seq(2,402,10),result[,5]-result[,2])

藤椅
ruiqwy 发表于 2009-10-30 13:22:51
1)first ,set1=c(  2  12  22  32  42  52  62  72  82  92 102 112 122 132 142 152 162 172 182 192 202 212 222 232 242 252 262 272 282 292 302 312 322 332 342 352 362 372 382 392 402)
for (n1 in set1)  means that n1 pick one value from 2 to 402 in set1 every time ,this is a loop.
2)x=mvrnorm(n=n1,rep(0,p1),diag(1,p1))
   this command to generate n1 mulitvariate nomal distribution random variable. the mean are zero. the deviation are 1.
3) x%*%t(x) menas xx',diag(x%*%t(x)) means extract the diagonal values of matrix xx',
diag(diag(x%*%t(x)) means generate a unit matrix with the diagonal values of matrix xx'

4)rbind() means  combine vector by row,cbind()menas combine vector by col.

all the commands above ,you can run these in your Rconsole to make deeply understand.
R is the second language for me!Using R is standing on the shoulders of giants!   Let\'s use R together!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-26 00:34