楼主: lee3100
3579 3

想不通的分段函数; 没搞懂的核光滑>///< [推广有奖]

  • 0关注
  • 0粉丝

高中生

0%

还不是VIP/贵宾

-

威望
0
论坛币
490 个
通用积分
1.0001
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
472 点
帖子
10
精华
0
在线时间
23 小时
注册时间
2009-3-6
最后登录
2021-3-20

楼主
lee3100 在职认证  发表于 2009-6-26 12:14:56 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
想要得到这样的函数:
y =  2x , x<=3;
       5   , else.
code如下:
  1. > y = function(x)
  2. +       { if (x<=3) y=2*x
  3. +         else      y=5}
  4. > curve(y,0,6)
复制代码

Warning message:
In if (x <= 3) y = 2 * x else y = 5 :
  条件的长度大于一,因此只能用其第一元素
这是为什么呢?
----------------------------------------------------
再附加一个核光滑回归问题:^_^
ksmooth函数只能采用box和normal两个核,有没有用biweight的?
对于用GCV方法选取bandwidth,需要单独使用mgcv吗?
ksmooth用法如下:
ksmooth(x, y, kernel = c("box", "normal"), bandwidth = 0.5,
        range.x = range(x),
        n.points = max(100, length(x)), x.points)
-----------------------------------------------------
期待回复ing 谢谢!
二维码

扫码加我 拉你入群

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

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

关键词:分段函数 想不通 function Message warning 函数 分段

回帖推荐

flyingflakesun 发表于3楼  查看完整内容

"if" is not vectorised and "age" is a vector. Try the following test: if(c(TRUE, FALSE)) "TRUE" else "FALSE" You really need to use "ifelse". ifelse(c(TRUE, FALSE), "TRUE", "FALSE") As others have suggested, you might want to look at ?cut. --sundar

本帖被以下文库推荐

沙发
flyingflakesun 发表于 2009-9-13 23:47:02
同问!!!!!!!!!!!!!!!

藤椅
flyingflakesun 发表于 2009-9-14 00:43:03
"if" is not vectorised and "age" is a vector. Try the following test:

if(c(TRUE, FALSE)) "TRUE" else "FALSE"

You really need to use "ifelse".

ifelse(c(TRUE, FALSE), "TRUE", "FALSE")

As others have suggested, you might want to look at ?cut.

--sundar
已有 1 人评分论坛币 热心指数 收起 理由
crystal8832 + 10 + 1 热心帮助其他会员

总评分: 论坛币 + 10  热心指数 + 1   查看全部评分

板凳
flyingflakesun 发表于 2009-9-14 00:43:25
"if" is not vectorised and "age" is a vector. Try the following test:

if(c(TRUE, FALSE)) "TRUE" else "FALSE"

You really need to use "ifelse".

ifelse(c(TRUE, FALSE), "TRUE", "FALSE")

As others have suggested, you might want to look at ?cut.

--sundar

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-5 20:11